VMC Examples Version 6.6
Loading...
Searching...
No Matches
Ex06MCApplication Class Reference

Implementation of the TVirtualMCApplication. More...

#include <Ex06MCApplication.h>

Inheritance diagram for Ex06MCApplication:

Public Member Functions

 Ex06MCApplication (const char *name, const char *title)
 
 Ex06MCApplication ()
 
virtual ~Ex06MCApplication ()
 
void InitMC (const char *setup)
 
void RunMC (Int_t nofEvents)
 
virtual TVirtualMCApplicationCloneForWorker () const
 
virtual void InitOnWorker ()
 
virtual void Merge (TVirtualMCApplication *localMCApplication)
 
virtual void ConstructGeometry ()
 
virtual void ConstructOpGeometry ()
 
virtual void InitGeometry ()
 
virtual void GeneratePrimaries ()
 
virtual void BeginEvent ()
 
virtual void BeginPrimary ()
 
virtual void PreTrack ()
 
virtual void Stepping ()
 
virtual void PostTrack ()
 
virtual void FinishPrimary ()
 
virtual void FinishEvent ()
 
void FinishRun ()
 
void SetVerboseLevel (Int_t verboseLevel)
 
Ex06PrimaryGeneratorGetPrimaryGenerator () const
 
void SetOldGeometry (Bool_t oldGeometry=kTRUE)
 
void SetTestStackPopper (Bool_t option=kFALSE)
 

Static Public Member Functions

static Ex06MCApplicationInstance ()
 

Private Member Functions

 Ex06MCApplication (const Ex06MCApplication &origin)
 
void GenerateFeedback (Int_t nofPhotons, TLorentzVector momentum)
 

Private Attributes

Int_t fGammaCounter
 Optical photons counter.
 
Int_t fFeedbackCounter
 Feedback photons counter.
 
Int_t fRunGammaCounter
 Optical photons counter2.
 
Int_t fRunFeedbackCounter
 Feedback photons counter2.
 
TMCVerbose fVerbose
 VMC verbose helper.
 
Ex03MCStackfStack
 VMC stack.
 
TVirtualMagFieldfMagField
 The magnetic field.
 
Ex06DetectorConstructionfDetConstruction
 Dector construction.
 
Ex06PrimaryGeneratorfPrimaryGenerator
 Primary generator.
 
Bool_t fOldGeometry
 Option for geometry definition.
 
Bool_t fTestStackPopper
 Option for stack popper test.
 
Bool_t fIsMaster
 If is on master thread.
 

Detailed Description

Implementation of the TVirtualMCApplication.

Date
16/05/2005
Author
I. Hrivnacova; IPN, Orsay

Definition at line 37 of file Ex06MCApplication.h.

Constructor & Destructor Documentation

◆ Ex06MCApplication() [1/3]

Ex06MCApplication::Ex06MCApplication ( const char * name,
const char * title )

Standard constructor

Parameters
nameThe MC application name
titleThe MC application description

Definition at line 40 of file Ex06MCApplication.cxx.

41 : TVirtualMCApplication(name, title),
46 fVerbose(0),
47 fStack(0),
48 fMagField(0),
51 fOldGeometry(kFALSE),
52 fTestStackPopper(kFALSE),
53 fIsMaster(kTRUE)
54{
55 /// Standard constructor
56 /// \param name The MC application name
57 /// \param title The MC application description
58
59 // Create a user stack
60 fStack = new Ex03MCStack(1000);
61
62 // create magnetic field (with zero value)
63 fMagField = new TGeoUniformMagField();
64
65 // Create detector construction
67
68 // Create a primary generator
70}
Implementation of the TVirtualMCStack interface.
Definition Ex03MCStack.h:36
The detector construction (via TGeo )
Bool_t fTestStackPopper
Option for stack popper test.
Int_t fFeedbackCounter
Feedback photons counter.
TVirtualMagField * fMagField
The magnetic field.
Int_t fRunGammaCounter
Optical photons counter2.
Int_t fRunFeedbackCounter
Feedback photons counter2.
Bool_t fIsMaster
If is on master thread.
Int_t fGammaCounter
Optical photons counter.
Ex06DetectorConstruction * fDetConstruction
Dector construction.
Bool_t fOldGeometry
Option for geometry definition.
Ex03MCStack * fStack
VMC stack.
Ex06PrimaryGenerator * fPrimaryGenerator
Primary generator.
TMCVerbose fVerbose
VMC verbose helper.
The primary generator.

◆ Ex06MCApplication() [2/3]

Ex06MCApplication::Ex06MCApplication ( )

Default constructor

Definition at line 104 of file Ex06MCApplication.cxx.

106 fGammaCounter(0),
110 fVerbose(0),
111 fStack(0),
112 fMagField(0),
115 fOldGeometry(kFALSE),
116 fTestStackPopper(kFALSE),
117 fIsMaster(kTRUE)
118{
119 /// Default constructor
120}

◆ ~Ex06MCApplication()

Ex06MCApplication::~Ex06MCApplication ( )
virtual

Destructor

Definition at line 123 of file Ex06MCApplication.cxx.

124{
125 /// Destructor
126
127 // cout << "Ex06MCApplication::~Ex06MCApplication " << this << endl;
128
129 delete fStack;
130 delete fMagField;
131 if (fIsMaster) delete fDetConstruction;
132 delete fPrimaryGenerator;
133 delete gMC;
134
135 // cout << "Done Ex06MCApplication::~Ex06MCApplication " << this << endl;
136}

◆ Ex06MCApplication() [3/3]

Ex06MCApplication::Ex06MCApplication ( const Ex06MCApplication & origin)
private

Copy constructor (for clonig on worker thread in MT mode).

Parameters
originThe source object (on master).

Definition at line 73 of file Ex06MCApplication.cxx.

74 : TVirtualMCApplication(origin.GetName(), origin.GetTitle()),
79 fVerbose(origin.fVerbose),
80 fStack(0),
81 fMagField(0),
86 fIsMaster(kFALSE)
87{
88 /// Copy constructor (for clonig on worker thread in MT mode).
89 /// \param origin The source object (on master).
90
91 // Create a user stack
92 fStack = new Ex03MCStack(1000);
93
94 // create magnetic field (with zero value)
95 // TODO: check copying
96 fMagField = new TGeoUniformMagField();
97
98 // Create a primary generator
101}

Member Function Documentation

◆ Instance()

Ex06MCApplication * Ex06MCApplication::Instance ( )
inlinestatic
Returns
The singleton instance

Definition at line 105 of file Ex06MCApplication.h.

106{
107 return (Ex06MCApplication*)(TVirtualMCApplication::Instance());
108}
Implementation of the TVirtualMCApplication.

◆ InitMC()

void Ex06MCApplication::InitMC ( const char * setup)

Initialize MC. The selection of the concrete MC is done in the macro.

Parameters
setupThe name of the configuration macro

Definition at line 143 of file Ex06MCApplication.cxx.

144{
145 /// Initialize MC.
146 /// The selection of the concrete MC is done in the macro.
147 /// \param setup The name of the configuration macro
148
149 fVerbose.InitMC();
150
151 if (TString(setup) != "") {
152 gROOT->LoadMacro(setup);
153 gInterpreter->ProcessLine("Config()");
154 if (!gMC) {
155 Fatal(
156 "InitMC", "Processing Config() has failed. (No MC is instantiated.)");
157 }
158 }
159
160 gMC->SetStack(fStack);
161 gMC->SetMagField(fMagField);
162 gMC->Init();
163 gMC->BuildPhysics();
164}

◆ RunMC()

void Ex06MCApplication::RunMC ( Int_t nofEvents)

Run MC.

Parameters
nofEventsNumber of events to be processed

Definition at line 167 of file Ex06MCApplication.cxx.

168{
169 /// Run MC.
170 /// \param nofEvents Number of events to be processed
171
172 fVerbose.RunMC(nofEvents);
173
174 gMC->ProcessRun(nofEvents);
175
176 FinishRun();
177}

◆ CloneForWorker()

TVirtualMCApplication * Ex06MCApplication::CloneForWorker ( ) const
virtual

Definition at line 180 of file Ex06MCApplication.cxx.

181{
182 return new Ex06MCApplication(*this);
183}

◆ InitOnWorker()

void Ex06MCApplication::InitOnWorker ( )
virtual

Definition at line 186 of file Ex06MCApplication.cxx.

187{
188 // cout << "Ex06MCApplication::InitForWorker " << this << endl;
189
190 // Set data to MC
191 gMC->SetStack(fStack);
192 gMC->SetMagField(fMagField);
193}

◆ Merge()

void Ex06MCApplication::Merge ( TVirtualMCApplication * localMCApplication)
virtual

Definition at line 196 of file Ex06MCApplication.cxx.

197{
198 // cout << "Ex06MCApplication::Merge " << this << endl;
199
200 Ex06MCApplication* ex06LocalMCApplication =
201 static_cast<Ex06MCApplication*>(localMCApplication);
202
203 fRunGammaCounter += ex06LocalMCApplication->fRunGammaCounter;
204 fRunFeedbackCounter += ex06LocalMCApplication->fRunFeedbackCounter;
205}

◆ ConstructGeometry()

void Ex06MCApplication::ConstructGeometry ( )
virtual

Construct geometry using detector contruction class. The detector contruction class is using TGeo functions or TVirtualMC functions (if oldGeometry is selected)

Definition at line 208 of file Ex06MCApplication.cxx.

209{
210 /// Construct geometry using detector contruction class.
211 /// The detector contruction class is using TGeo functions or
212 /// TVirtualMC functions (if oldGeometry is selected)
213
214 fVerbose.ConstructGeometry();
215
216 // Cannot use Root geometry if not supported with
217 // selected MC
218 if (!fOldGeometry && !gMC->IsRootGeometrySupported()) {
219 cerr << "Selected MC does not support TGeo geometry" << endl;
220 cerr << "Exiting program" << endl;
221 exit(1);
222 }
223
224 if (!fOldGeometry) {
225 cout << "Geometry will be defined via TGeo" << endl;
228 }
229 else {
230 cout << "Geometry will be defined via VMC" << endl;
231 Ex06DetectorConstructionOld detConstructionOld;
232 detConstructionOld.ConstructMaterials();
233 detConstructionOld.ConstructGeometry();
234 }
235}
The detector construction (via TGeo )

◆ ConstructOpGeometry()

void Ex06MCApplication::ConstructOpGeometry ( )
virtual

Define material optical properties

Definition at line 238 of file Ex06MCApplication.cxx.

239{
240 /// Define material optical properties
241
242 fVerbose.ConstructGeometry();
243
245}

◆ InitGeometry()

void Ex06MCApplication::InitGeometry ( )
virtual

Initialize geometry

Definition at line 248 of file Ex06MCApplication.cxx.

249{
250 /// Initialize geometry
251
252 fVerbose.InitGeometry();
253}

◆ GeneratePrimaries()

void Ex06MCApplication::GeneratePrimaries ( )
virtual

Fill the user stack (derived from TVirtualMCStack) with primary particles.

Definition at line 256 of file Ex06MCApplication.cxx.

257{
258 /// Fill the user stack (derived from TVirtualMCStack) with primary particles.
259
260 fVerbose.GeneratePrimaries();
261
263}

◆ BeginEvent()

void Ex06MCApplication::BeginEvent ( )
virtual

User actions at beginning of event

Definition at line 266 of file Ex06MCApplication.cxx.

267{
268 /// User actions at beginning of event
269
270 fVerbose.BeginEvent();
271
272 fGammaCounter = 0;
274}

◆ BeginPrimary()

void Ex06MCApplication::BeginPrimary ( )
virtual

User actions at beginning of a primary track

Definition at line 277 of file Ex06MCApplication.cxx.

278{
279 /// User actions at beginning of a primary track
280
281 fVerbose.BeginPrimary();
282}

◆ PreTrack()

void Ex06MCApplication::PreTrack ( )
virtual

User actions at beginning of each track

Definition at line 285 of file Ex06MCApplication.cxx.

286{
287 /// User actions at beginning of each track
288
289 fVerbose.PreTrack();
290
291 if (gMC->TrackPid() == 50000050) {
294 }
295 if (gMC->TrackPid() == 50000051) {
298 }
299}

◆ Stepping()

void Ex06MCApplication::Stepping ( )
virtual

User actions at each step

Definition at line 302 of file Ex06MCApplication.cxx.

303{
304 /// User actions at each step
305
306 fVerbose.Stepping();
307
308 // Work around for Fluka VMC, which does not call
309 // MCApplication::PreTrack()
310 //
311 static Int_t trackId = 0;
312 if (TString(gMC->GetName()) == "TFluka" &&
313 gMC->GetStack()->GetCurrentTrackNumber() != trackId) {
314
315 fVerbose.PreTrack();
316 trackId = gMC->GetStack()->GetCurrentTrackNumber();
317 if (gMC->TrackPid() == 50000050) fGammaCounter++;
318 if (gMC->TrackPid() == 50000051) fFeedbackCounter++;
319 }
320
321 if (!fTestStackPopper) return;
322
323 // Stack popper test
324 // Add 1 feedback photon (50000051, fixed momentum) when a charged track
325 // enters TANK and 3 feedback photons (momentum in opposite direction to
326 // parent photon)
327 // when a photon is stopped in TANK
328
329 // Charged particles entering in TANK
330 TString volName = gMC->CurrentVolName();
331 if (volName != "TANK") return;
332
333 if ((gMC->TrackCharge() != 0.) && (gMC->IsTrackEntering())) {
334 // 1 keV
335 Double_t energy = 1e-06;
336 // TLorentzVector momentum(energy, 0., 0., energy);
337 // workaround for a problem in Geant4 11 in G4OpBoundaryProcess
338 TLorentzVector momentum(
339 energy, 0.1 * energy, 0.1 * energy, 0.98994949 * energy);
340 GenerateFeedback(1, momentum);
341 }
342
343 if ((gMC->TrackPid() == 50000050) && (gMC->Edep() > 0.)) {
344 TLorentzVector momentum;
345 gMC->TrackMomentum(momentum);
346 momentum = -1. * momentum;
347 GenerateFeedback(3, momentum);
348 }
349}
void GenerateFeedback(Int_t nofPhotons, TLorentzVector momentum)

◆ PostTrack()

void Ex06MCApplication::PostTrack ( )
virtual

User actions after finishing of each track

Definition at line 378 of file Ex06MCApplication.cxx.

379{
380 /// User actions after finishing of each track
381
382 fVerbose.PostTrack();
383}

◆ FinishPrimary()

void Ex06MCApplication::FinishPrimary ( )
virtual

User actions after finishing of a primary track

Definition at line 386 of file Ex06MCApplication.cxx.

387{
388 /// User actions after finishing of a primary track
389
390 fVerbose.FinishPrimary();
391}

◆ FinishEvent()

void Ex06MCApplication::FinishEvent ( )
virtual

User actions after finishing of an event

Definition at line 394 of file Ex06MCApplication.cxx.

395{
396 /// User actions after finishing of an event
397
398 fVerbose.FinishEvent();
399
400 // Geant3 + TGeo
401 // (use TGeo functions for visualization)
402 if (TString(gMC->GetName()) == "TGeant3TGeo") {
403
404 // Draw volume
405 gGeoManager->SetVisOption(0);
406 gGeoManager->SetTopVisible();
407 gGeoManager->GetTopVolume()->Draw();
408
409 // Draw tracks (if filled)
410 // Available when this feature is activated via
411 // gMC->SetCollectTracks(kTRUE);
412 if (gGeoManager->GetListOfTracks() && gGeoManager->GetTrack(0) &&
413 ((TVirtualGeoTrack*)gGeoManager->GetTrack(0))->HasPoints()) {
414
415 gGeoManager->DrawTracks("/*"); // this means all tracks
416 }
417 }
418
419 cout << "Number of optical photons produced in this event : " << fGammaCounter
420 << endl;
421
422 if (fTestStackPopper) {
423 cout << "Number of feedback photons produced in this event : "
424 << fFeedbackCounter << endl;
425 }
426 fStack->Reset();
427}

◆ FinishRun()

void Ex06MCApplication::FinishRun ( )

User actions after finishing of a run

Definition at line 430 of file Ex06MCApplication.cxx.

431{
432 /// User actions after finishing of a run
433
434 fVerbose.FinishRun();
435
436 cout << "Number of optical photons produced in this run : "
437 << fRunGammaCounter << endl;
438
439 if (fTestStackPopper) {
440 cout << "Number of feedback photons produced in this run : "
441 << fRunFeedbackCounter << endl;
442 }
443}

◆ SetVerboseLevel()

void Ex06MCApplication::SetVerboseLevel ( Int_t verboseLevel)
inline

Set verbosity

Parameters
verboseLevelThe new verbose level value

Definition at line 112 of file Ex06MCApplication.h.

113{
114 fVerbose.SetLevel(verboseLevel);
115}

◆ GetPrimaryGenerator()

Ex06PrimaryGenerator * Ex06MCApplication::GetPrimaryGenerator ( ) const
inline
Returns
The primary generator

Definition at line 118 of file Ex06MCApplication.h.

119{
120 return fPrimaryGenerator;
121}

◆ SetOldGeometry()

void Ex06MCApplication::SetOldGeometry ( Bool_t oldGeometry = kTRUE)
inline

Switch on/off the old geometry definition (via VMC functions)

Parameters
oldGeometryIf true, geometry definition via VMC functions

Definition at line 125 of file Ex06MCApplication.h.

126{
127 fOldGeometry = oldGeometry;
128}

◆ SetTestStackPopper()

void Ex06MCApplication::SetTestStackPopper ( Bool_t option = kFALSE)
inline

Switch on/off the stack popper test

Parameters
optionstack popper test activation option

Definition at line 132 of file Ex06MCApplication.h.

133{
134 fTestStackPopper = option;
135}

◆ GenerateFeedback()

void Ex06MCApplication::GenerateFeedback ( Int_t nofPhotons,
TLorentzVector momentum )
private

Generate FeedBack photons for the current particle.

Definition at line 352 of file Ex06MCApplication.cxx.

354{
355 /// Generate FeedBack photons for the current particle.
356
357 for (Int_t i = 0; i < nofPhotons; ++i) {
358 // same position as the parent track
359 TLorentzVector position;
360 gMC->TrackPosition(position);
361 // Feedback photon
362 Int_t pdgEncoding = 50000051;
363 // Fixed polarization
364 Double_t polarization[3];
365 polarization[0] = 0.3;
366 polarization[1] = 0.4;
367 polarization[2] = 0.866025403784438597;
368
369 Int_t ntrack;
370 gMC->GetStack()->PushTrack(1, gMC->GetStack()->GetCurrentTrackNumber(),
371 pdgEncoding, momentum.X(), momentum.Y(), momentum.Z(), momentum.T(),
372 position.X(), position.Y(), position.Z(), position.T(), polarization[0],
373 polarization[1], polarization[2], kPFeedBackPhoton, ntrack, 1.0, 0);
374 }
375}

Member Data Documentation

◆ fGammaCounter

Int_t Ex06MCApplication::fGammaCounter
private

Optical photons counter.

Definition at line 86 of file Ex06MCApplication.h.

◆ fFeedbackCounter

Int_t Ex06MCApplication::fFeedbackCounter
private

Feedback photons counter.

Definition at line 87 of file Ex06MCApplication.h.

◆ fRunGammaCounter

Int_t Ex06MCApplication::fRunGammaCounter
private

Optical photons counter2.

Definition at line 88 of file Ex06MCApplication.h.

◆ fRunFeedbackCounter

Int_t Ex06MCApplication::fRunFeedbackCounter
private

Feedback photons counter2.

Definition at line 89 of file Ex06MCApplication.h.

◆ fVerbose

TMCVerbose Ex06MCApplication::fVerbose
private

VMC verbose helper.

Definition at line 90 of file Ex06MCApplication.h.

◆ fStack

Ex03MCStack* Ex06MCApplication::fStack
private

VMC stack.

Definition at line 91 of file Ex06MCApplication.h.

◆ fMagField

TVirtualMagField* Ex06MCApplication::fMagField
private

The magnetic field.

Definition at line 92 of file Ex06MCApplication.h.

◆ fDetConstruction

Ex06DetectorConstruction* Ex06MCApplication::fDetConstruction
private

Dector construction.

Definition at line 93 of file Ex06MCApplication.h.

◆ fPrimaryGenerator

Ex06PrimaryGenerator* Ex06MCApplication::fPrimaryGenerator
private

Primary generator.

Definition at line 94 of file Ex06MCApplication.h.

◆ fOldGeometry

Bool_t Ex06MCApplication::fOldGeometry
private

Option for geometry definition.

Definition at line 95 of file Ex06MCApplication.h.

◆ fTestStackPopper

Bool_t Ex06MCApplication::fTestStackPopper
private

Option for stack popper test.

Definition at line 96 of file Ex06MCApplication.h.

◆ fIsMaster

Bool_t Ex06MCApplication::fIsMaster
private

If is on master thread.

Definition at line 97 of file Ex06MCApplication.h.


The documentation for this class was generated from the following files: