VMC Examples Version 6.8
Loading...
Searching...
No Matches
Ex03MCApplication Class Reference

Implementation of the TVirtualMCApplication. More...

#include <Ex03MCApplication.h>

Inheritance diagram for Ex03MCApplication:

Public Member Functions

 Ex03MCApplication (const char *name, const char *title)
 Ex03MCApplication ()
virtual ~Ex03MCApplication ()
void InitMC (const char *setup)
void RunMC (Int_t nofEvents)
void FinishRun ()
void ReadEvent (Int_t i)
virtual TVirtualMCApplicationCloneForWorker () const
virtual void InitOnWorker ()
virtual void FinishRunOnWorker ()
virtual void ConstructGeometry ()
virtual void InitGeometry ()
virtual void AddParticles ()
virtual void AddIons ()
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 SetPrintModulo (Int_t value)
void SetVerboseLevel (Int_t verboseLevel)
void SetControls (Bool_t isConstrols)
void SetField (Double_t bz)
Ex03DetectorConstructionGetDetectorConstruction () const
Ex03CalorimeterSDGetCalorimeterSD () const
Ex03PrimaryGeneratorGetPrimaryGenerator () const
void SetOldGeometry (Bool_t oldGeometry=kTRUE)

Private Member Functions

 Ex03MCApplication (const Ex03MCApplication &origin)
void RegisterStack () const

Private Attributes

TMCRootManager * fRootManager
 Root manager.
Int_t fPrintModulo
 The event modulus number to be printed.
Int_t fEventNo
 Event counter.
TMCVerbose fVerbose
 VMC verbose helper.
Ex03MCStackfStack
 VMC stack.
Ex03DetectorConstructionfDetConstruction
 Dector construction.
Ex03CalorimeterSDfCalorimeterSD
 Calorimeter SD.
Ex03PrimaryGeneratorfPrimaryGenerator
 Primary generator.
TGeoUniformMagField * fMagField
 Magnetic field.
Bool_t fOldGeometry
 Option for geometry definition.
Bool_t fIsControls
 Option to activate special controls.
Bool_t fIsMaster
 If is on master thread.

Detailed Description

Implementation of the TVirtualMCApplication.

Date
06/03/2003
Author
I. Hrivnacova; IPN, Orsay

Definition at line 39 of file Ex03MCApplication.h.

Constructor & Destructor Documentation

◆ Ex03MCApplication() [1/3]

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

Standard constructor

Parameters
nameThe MC application name
titleThe MC application description

Definition at line 44 of file Ex03MCApplication.cxx.

45 : TVirtualMCApplication(name, title),
46 fRootManager(0),
47 fPrintModulo(1),
48 fEventNo(0),
49 fVerbose(0),
50 fStack(0),
54 fMagField(0),
55 fOldGeometry(kFALSE),
56 fIsControls(kFALSE),
57 fIsMaster(kTRUE)
58{
59 /// Standard constructor
60 /// \param name The MC application name
61 /// \param title The MC application description
62
63 cout << "--------------------------------------------------------------"
64 << endl;
65 cout << " VMC Example E03" << endl;
66 cout << "--------------------------------------------------------------"
67 << endl;
68
69 // Create a user stack
70 fStack = new Ex03MCStack(1000);
71
72 // Create detector construction
73 fDetConstruction = new Ex03DetectorConstruction();
74
75 // Create a calorimeter SD
76 fCalorimeterSD = new Ex03CalorimeterSD("Calorimeter", fDetConstruction);
77
78 // Create a primary generator
79 fPrimaryGenerator = new Ex03PrimaryGenerator(fStack);
80
81 // Constant magnetic field (in kiloGauss)
82 fMagField = new TGeoUniformMagField();
83}
Int_t fPrintModulo
The event modulus number to be printed.
TGeoUniformMagField * fMagField
Magnetic field.
Bool_t fIsControls
Option to activate special controls.
TMCVerbose fVerbose
VMC verbose helper.
Bool_t fIsMaster
If is on master thread.
Ex03PrimaryGenerator * fPrimaryGenerator
Primary generator.
Ex03MCStack * fStack
VMC stack.
Ex03CalorimeterSD * fCalorimeterSD
Calorimeter SD.
Ex03DetectorConstruction * fDetConstruction
Dector construction.
Bool_t fOldGeometry
Option for geometry definition.
Int_t fEventNo
Event counter.
TMCRootManager * fRootManager
Root manager.
Ex03PrimaryGenerator * fPrimaryGenerator
Primary generator.
Ex03bCalorimeterSD * fCalorimeterSD
Calorimeter SD.
TGeoUniformMagField * fMagField
Magnetic field.
Ex03DetectorConstruction * fDetConstruction
Dector construction.
Ex03MCStack * fStack
VMC stack.

◆ Ex03MCApplication() [2/3]

Ex03MCApplication::Ex03MCApplication ( )

Default constructor

Definition at line 120 of file Ex03MCApplication.cxx.

121 : TVirtualMCApplication(),
122 fRootManager(0),
123 fPrintModulo(1),
124 fEventNo(0),
125 fStack(0),
129 fMagField(0),
130 fOldGeometry(kFALSE),
131 fIsControls(kFALSE),
132 fIsMaster(kTRUE)
133{
134 /// Default constructor
135}

◆ ~Ex03MCApplication()

Ex03MCApplication::~Ex03MCApplication ( )
virtual

Destructor

Definition at line 138 of file Ex03MCApplication.cxx.

139{
140 /// Destructor
141
142 // cout << "Ex03MCApplication::~Ex03MCApplication " << this << endl;
143
144 delete fRootManager;
145 delete fStack;
146 if (fIsMaster) delete fDetConstruction;
147 delete fCalorimeterSD;
148 delete fPrimaryGenerator;
149 delete fMagField;
150 delete gMC;
151
152 // cout << "Done Ex03MCApplication::~Ex03MCApplication " << this << endl;
153}
Bool_t fIsMaster
If is on master thread.
TMCRootManager * fRootManager
Root manager.

◆ Ex03MCApplication() [3/3]

Ex03MCApplication::Ex03MCApplication ( const Ex03MCApplication & origin)
private

Copy constructor for cloning application on workers (in multithreading mode)

Parameters
originThe source MC application

Definition at line 86 of file Ex03MCApplication.cxx.

87 : TVirtualMCApplication(origin.GetName(), origin.GetTitle()),
88 fRootManager(0),
90 fEventNo(0),
91 fVerbose(origin.fVerbose),
92 fStack(0),
96 fMagField(0),
98 fIsMaster(kFALSE)
99{
100 /// Copy constructor for cloning application on workers (in multithreading
101 /// mode) \param origin The source MC application
102
103 // Create new user stack
104 fStack = new Ex03MCStack(1000);
105
106 // Create a calorimeter SD
108 new Ex03CalorimeterSD(*(origin.fCalorimeterSD), fDetConstruction);
109
110 // Create a primary generator
112 new Ex03PrimaryGenerator(*(origin.fPrimaryGenerator), fStack);
113
114 // Constant magnetic field (in kiloGauss)
115 fMagField = new TGeoUniformMagField(origin.fMagField->GetFieldValue()[0],
116 origin.fMagField->GetFieldValue()[1], origin.fMagField->GetFieldValue()[2]);
117}

Member Function Documentation

◆ InitMC()

void Ex03MCApplication::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 175 of file Ex03MCApplication.cxx.

176{
177 /// Initialize MC.
178 /// The selection of the concrete MC is done in the macro.
179 /// \param setup The name of the configuration macro
180
181 fVerbose.InitMC();
182
183 if (TString(setup) != "") {
184 gROOT->LoadMacro(setup);
185 gInterpreter->ProcessLine("Config()");
186 if (!gMC) {
187 Fatal(
188 "InitMC", "Processing Config() has failed. (No MC is instantiated.)");
189 }
190 }
191
192// MT support available from root v 5.34/18
193#if ROOT_VERSION_CODE >= 336402
194 // Create Root manager
195 if (!gMC->IsMT()) {
196 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
197 // fRootManager->SetDebug(true);
198 }
199#else
200 // Create Root manager
201 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
202 // fRootManager->SetDebug(true);
203#endif
204
205 gMC->SetStack(fStack);
206 gMC->SetMagField(fMagField);
207 gMC->Init();
208 gMC->BuildPhysics();
209
211}
TMCVerbose fVerbose
VMC verbose helper.

◆ RunMC()

void Ex03MCApplication::RunMC ( Int_t nofEvents)

Run MC.

Parameters
nofEventsNumber of events to be processed

Definition at line 214 of file Ex03MCApplication.cxx.

215{
216 /// Run MC.
217 /// \param nofEvents Number of events to be processed
218
219 fVerbose.RunMC(nofEvents);
220
221 gMC->ProcessRun(nofEvents);
222 FinishRun();
223}

◆ FinishRun()

Finish MC run.

Definition at line 226 of file Ex03MCApplication.cxx.

227{
228 /// Finish MC run.
229
230 fVerbose.FinishRun();
231 // cout << "Ex03MCApplication::FinishRun: " << endl;
232 if (fRootManager) {
233 fRootManager->WriteAll();
234 fRootManager->Close();
235 }
236}

◆ ReadEvent()

Read i -th event and prints hits.

Parameters
iThe number of event to be read

Definition at line 273 of file Ex03MCApplication.cxx.

274{
275 /// Read \em i -th event and prints hits.
276 /// \param i The number of event to be read
277
278 if ( ! fRootManager ) {
279 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kRead);
280 }
281
282 fCalorimeterSD->Register();
284 fRootManager->ReadEvent(i);
285}

◆ CloneForWorker()

Definition at line 239 of file Ex03MCApplication.cxx.

240{
241 return new Ex03MCApplication(*this);
242}

◆ InitOnWorker()

Definition at line 245 of file Ex03MCApplication.cxx.

246{
247 // cout << "Ex03MCApplication::InitForWorker " << this << endl;
248
249 // Create Root manager
250 Int_t threadRank = 1;
251 // The real thread rank will be set in MCRootManager
252 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite, threadRank);
253 // fRootManager->SetDebug(true);
254
255 // Set data to MC
256 gMC->SetStack(fStack);
257 gMC->SetMagField(fMagField);
258
260}

◆ FinishRunOnWorker()

Definition at line 263 of file Ex03MCApplication.cxx.

264{
265 // cout << "Ex03MCApplication::FinishWorkerRun: " << endl;
266 if (fRootManager) {
267 fRootManager->WriteAll();
268 fRootManager->Close();
269 }
270}

◆ ConstructGeometry()

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

Definition at line 288 of file Ex03MCApplication.cxx.

289{
290 /// Construct geometry using detector contruction class.
291 /// The detector contruction class is using TGeo functions or
292 /// TVirtualMC functions (if oldGeometry is selected)
293
294 fVerbose.ConstructGeometry();
295
296 if (!fOldGeometry) {
297 fDetConstruction->ConstructMaterials();
298 fDetConstruction->ConstructGeometry();
299 // TGeoManager::Import("geometry.root");
300 // gMC->SetRootGeometry();
301 }
302 else {
303 Ex03DetectorConstructionOld detConstructionOld;
304 detConstructionOld.ConstructMaterials();
305 detConstructionOld.ConstructGeometry();
306 }
307}
Bool_t fOldGeometry
Option for geometry definition.

◆ InitGeometry()

Initialize geometry

Definition at line 310 of file Ex03MCApplication.cxx.

311{
312 /// Initialize geometry
313
314 fVerbose.InitGeometry();
315
316 fDetConstruction->SetCuts();
317
318 if (fIsControls) fDetConstruction->SetControls();
319
320 fCalorimeterSD->Initialize();
321}
Bool_t fIsControls
Option to activate special controls.

◆ AddParticles()

Example of user defined particle with user defined decay mode

Definition at line 324 of file Ex03MCApplication.cxx.

325{
326 /// Example of user defined particle with user defined decay mode
327
328 fVerbose.AddParticles();
329
330 // Define particle
331 gMC->DefineParticle(1000020050, "He5", kPTHadron, 5.03427, 2.0, 0.002, "Ion",
332 0.0, 0, 1, 0, 0, 0, 0, 0, 5, kFALSE);
333
334 // Define the 2 body phase space decay for He5
335 Int_t mode[6][3];
336 Float_t bratio[6];
337
338 for (Int_t kz = 0; kz < 6; kz++) {
339 bratio[kz] = 0.;
340 mode[kz][0] = 0;
341 mode[kz][1] = 0;
342 mode[kz][2] = 0;
343 }
344 bratio[0] = 100.;
345 mode[0][0] = kNeutron; // neutron (2112)
346 mode[0][1] = 1000020040; // alpha
347
348 gMC->SetDecayMode(1000020050, bratio, mode);
349
350 // Overwrite a decay mode already defined in MCs
351 // Kaon Short: 310 normally decays in two modes
352 // pi+, pi- 68.61 %
353 // pi0, pi0 31.39 %
354 // and we force only the mode pi0, pi0
355
356 Int_t mode2[6][3];
357 Float_t bratio2[6];
358
359 for (Int_t kz = 0; kz < 6; kz++) {
360 bratio2[kz] = 0.;
361 mode2[kz][0] = 0;
362 mode2[kz][1] = 0;
363 mode2[kz][2] = 0;
364 }
365 bratio2[0] = 100.;
366 mode2[0][0] = kPi0; // pi0 (111)
367 mode2[0][1] = kPi0; // pi0 (111)
368
369 gMC->SetDecayMode(kK0Short, bratio2, mode2);
370}

◆ AddIons()

void Ex03MCApplication::AddIons ( )
virtual

Example of user defined ion

Definition at line 373 of file Ex03MCApplication.cxx.

374{
375 /// Example of user defined ion
376
377 fVerbose.AddIons();
378
379 gMC->DefineIon("MyIon", 34, 70, 12, 0.);
380}

◆ GeneratePrimaries()

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

Definition at line 383 of file Ex03MCApplication.cxx.

384{
385 /// Fill the user stack (derived from TVirtualMCStack) with primary particles.
386
387 fVerbose.GeneratePrimaries();
388
389 TVector3 origin(fDetConstruction->GetWorldSizeX(),
390 fDetConstruction->GetCalorSizeYZ(), fDetConstruction->GetCalorSizeYZ());
391
392 fPrimaryGenerator->GeneratePrimaries(origin);
393}

◆ BeginEvent()

User actions at beginning of event

Definition at line 396 of file Ex03MCApplication.cxx.

397{
398 /// User actions at beginning of event
399
400 fVerbose.BeginEvent();
401
402 // Clear TGeo tracks (if filled)
403 if (TString(gMC->GetName()) == "TGeant3TGeo" &&
404 gGeoManager->GetListOfTracks() && gGeoManager->GetTrack(0) &&
405 ((TVirtualGeoTrack*)gGeoManager->GetTrack(0))->HasPoints()) {
406
407 gGeoManager->ClearTracks();
408 // if (gPad) gPad->Clear();
409 }
410
411 fEventNo++;
412 if (fEventNo % fPrintModulo == 0) {
413 cout << "\n---> Begin of event: " << fEventNo << endl;
414 // ??? How to do this in VMC
415 // HepRandom::showEngineStatus();
416 }
417}
Int_t fPrintModulo
The event modulus number to be printed.
Int_t fEventNo
Event counter.

◆ BeginPrimary()

User actions at beginning of a primary track. If test for user defined decay is activated, the primary track ID is printed on the screen.

Definition at line 420 of file Ex03MCApplication.cxx.

421{
422 /// User actions at beginning of a primary track.
423 /// If test for user defined decay is activated,
424 /// the primary track ID is printed on the screen.
425
426 fVerbose.BeginPrimary();
427
428 if (fPrimaryGenerator->GetUserDecay()) {
429 cout << " Primary track ID = " << fStack->GetCurrentTrackNumber() << endl;
430 }
431}

◆ PreTrack()

void Ex03MCApplication::PreTrack ( )
virtual

User actions at beginning of each track If test for user defined decay is activated, the decay products of the primary track (K0Short) are printed on the screen.

Definition at line 434 of file Ex03MCApplication.cxx.

435{
436 /// User actions at beginning of each track
437 /// If test for user defined decay is activated,
438 /// the decay products of the primary track (K0Short)
439 /// are printed on the screen.
440
441 fVerbose.PreTrack();
442
443 // print info about K0Short decay products
444 if (fPrimaryGenerator->GetUserDecay()) {
445 Int_t parentID = fStack->GetCurrentParentTrackNumber();
446
447 if (parentID >= 0 &&
448 fStack->GetParticle(parentID)->GetPdgCode() == kK0Short &&
449 fStack->GetCurrentTrack()->GetUniqueID() == kPDecay) {
450 // The production process is saved as TParticle unique ID
451 // via Ex03MCStack
452
453 cout << " Current track " << fStack->GetCurrentTrack()->GetName()
454 << " is a decay product of Parent ID = "
455 << fStack->GetCurrentParentTrackNumber() << endl;
456 }
457 }
458}

◆ Stepping()

void Ex03MCApplication::Stepping ( )
virtual

User actions at each step

Definition at line 461 of file Ex03MCApplication.cxx.

462{
463 /// User actions at each step
464
465 // Work around for Fluka VMC, which does not call
466 // MCApplication::PreTrack()
467 //
468
469 static Int_t trackId = 0;
470 if (TString(gMC->GetName()) == "TFluka" &&
471 gMC->GetStack()->GetCurrentTrackNumber() != trackId) {
472 fVerbose.PreTrack();
473 trackId = gMC->GetStack()->GetCurrentTrackNumber();
474 }
475
476 fVerbose.Stepping();
477
478 fCalorimeterSD->ProcessHits();
479}

◆ PostTrack()

void Ex03MCApplication::PostTrack ( )
virtual

User actions after finishing of each track

Definition at line 482 of file Ex03MCApplication.cxx.

483{
484 /// User actions after finishing of each track
485
486 fVerbose.PostTrack();
487}

◆ FinishPrimary()

User actions after finishing of a primary track

Definition at line 490 of file Ex03MCApplication.cxx.

491{
492 /// User actions after finishing of a primary track
493
494 fVerbose.FinishPrimary();
495
496 if (fPrimaryGenerator->GetUserDecay()) {
497 cout << endl;
498 }
499}

◆ FinishEvent()

User actions after finishing of an event

Definition at line 502 of file Ex03MCApplication.cxx.

503{
504 /// User actions after finishing of an event
505
506 fVerbose.FinishEvent();
507
508 // Geant3 + TGeo
509 // (use TGeo functions for visualization)
510 if (TString(gMC->GetName()) == "TGeant3TGeo") {
511
512 // Draw volume
513 gGeoManager->SetVisOption(0);
514 gGeoManager->SetTopVisible();
515 gGeoManager->GetTopVolume()->Draw();
516
517 // Draw tracks (if filled)
518 // Available when this feature is activated via
519 // gMC->SetCollectTracks(kTRUE);
520 if (gGeoManager->GetListOfTracks() && gGeoManager->GetTrack(0) &&
521 ((TVirtualGeoTrack*)gGeoManager->GetTrack(0))->HasPoints()) {
522
523 gGeoManager->DrawTracks("/*"); // this means all tracks
524 }
525 }
526
527 fRootManager->Fill();
528
529 if (fEventNo % fPrintModulo == 0) fCalorimeterSD->PrintTotal();
530
531 fCalorimeterSD->EndOfEvent();
532
533 fStack->Reset();
534}

◆ SetPrintModulo()

void Ex03MCApplication::SetPrintModulo ( Int_t value)
inline

Set the event modulus number to be printed

Parameters
valueThe new event modulus number value

Definition at line 109 of file Ex03MCApplication.h.

110{
111 fPrintModulo = value;
112}

◆ SetVerboseLevel()

void Ex03MCApplication::SetVerboseLevel ( Int_t verboseLevel)
inline

Set verbosity

Parameters
verboseLevelThe new verbose level value

Definition at line 116 of file Ex03MCApplication.h.

117{
118 fVerbose.SetLevel(verboseLevel);
119}

◆ SetControls()

void Ex03MCApplication::SetControls ( Bool_t isControls)
inline

Switch on/off special process controls

Parameters
isControlsIf true, special process controls setting is activated

Definition at line 156 of file Ex03MCApplication.h.

157{
158 fIsControls = isControls;
159}

◆ SetField()

void Ex03MCApplication::SetField ( Double_t bz)
inline

Definition at line 123 of file Ex03MCApplication.h.

124{
125 fMagField->SetFieldValue(0., 0., bz);
126}

◆ GetDetectorConstruction()

Returns
The detector construction

Definition at line 130 of file Ex03MCApplication.h.

131{
132 return fDetConstruction;
133}

◆ GetCalorimeterSD()

Returns
The calorimeter sensitive detector

Definition at line 136 of file Ex03MCApplication.h.

137{
138 return fCalorimeterSD;
139}

◆ GetPrimaryGenerator()

Returns
The primary generator

Definition at line 142 of file Ex03MCApplication.h.

143{
144 return fPrimaryGenerator;
145}

◆ SetOldGeometry()

void Ex03MCApplication::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 149 of file Ex03MCApplication.h.

150{
151 fOldGeometry = oldGeometry;
152}

◆ RegisterStack()

void Ex03MCApplication::RegisterStack ( ) const
private

Register stack in the Root manager.

Definition at line 160 of file Ex03MCApplication.cxx.

161{
162 /// Register stack in the Root manager.
163
164 if (fRootManager) {
165 // cout << "Ex03MCApplication::RegisterStack: " << endl;
166 fRootManager->Register("stack", "Ex03MCStack", &fStack);
167 }
168}

Member Data Documentation

◆ fRootManager

TMCRootManager* Ex03MCApplication::fRootManager
mutableprivate

Root manager.

Definition at line 89 of file Ex03MCApplication.h.

◆ fPrintModulo

The event modulus number to be printed.

Definition at line 90 of file Ex03MCApplication.h.

◆ fEventNo

Event counter.

Definition at line 91 of file Ex03MCApplication.h.

◆ fVerbose

TMCVerbose Ex03MCApplication::fVerbose
private

VMC verbose helper.

Definition at line 92 of file Ex03MCApplication.h.

◆ fStack

VMC stack.

Definition at line 93 of file Ex03MCApplication.h.

◆ fDetConstruction

Dector construction.

Definition at line 94 of file Ex03MCApplication.h.

◆ fCalorimeterSD

Calorimeter SD.

Definition at line 95 of file Ex03MCApplication.h.

◆ fPrimaryGenerator

Primary generator.

Definition at line 96 of file Ex03MCApplication.h.

◆ fMagField

TGeoUniformMagField* Ex03MCApplication::fMagField
private

Magnetic field.

Definition at line 97 of file Ex03MCApplication.h.

◆ fOldGeometry

Option for geometry definition.

Definition at line 98 of file Ex03MCApplication.h.

◆ fIsControls

Option to activate special controls.

Definition at line 99 of file Ex03MCApplication.h.

◆ fIsMaster

If is on master thread.

Definition at line 100 of file Ex03MCApplication.h.


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