VMC Examples Version 6.6
Loading...
Searching...
No Matches
VMC::TR::MCApplication Class Reference

Implementation of the TVirtualMCApplication. More...

#include <MCApplication.h>

Inheritance diagram for VMC::TR::MCApplication:

Public Member Functions

 MCApplication (const char *name, const char *title)
 
 MCApplication ()
 
virtual ~MCApplication ()
 
void InitMC (const char *setup)
 
void RunMC (Int_t nofEvents)
 
void FinishRun ()
 
virtual TVirtualMCApplicationCloneForWorker () const
 
virtual void InitOnWorker ()
 
virtual void FinishRunOnWorker ()
 
virtual void ConstructGeometry ()
 
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 SetPrintModulo (Int_t value)
 
void SetVerboseLevel (Int_t verboseLevel)
 
void SetControls (Bool_t isConstrols)
 
void SetField (Double_t bz)
 
DetectorConstructionGetDetectorConstruction () const
 
SensitiveDetectorGetSensitiveDetector () const
 
PrimaryGeneratorGetPrimaryGenerator () const
 
void SetOldGeometry (Bool_t oldGeometry=kTRUE)
 

Private Member Functions

 MCApplication (const MCApplication &origin)
 
void RegisterStack () const
 
void BookHisto () 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.
 
DetectorConstructionfDetConstruction
 Dector construction.
 
SensitiveDetectorfSensitiveDetector
 Absorber SD.
 
PrimaryGeneratorfPrimaryGenerator
 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
18/12/2015
Author
I. Hrivnacova; IPN, Orsay

Definition at line 44 of file MCApplication.h.

Constructor & Destructor Documentation

◆ MCApplication() [1/3]

VMC::TR::MCApplication::MCApplication ( const char * name,
const char * title )

Standard constructor

Parameters
nameThe MC application name
titleThe MC application description

Definition at line 51 of file MCApplication.cxx.

52 : TVirtualMCApplication(name, title),
53 fRootManager(0),
54 fPrintModulo(1),
55 fEventNo(0),
56 fVerbose(0),
57 fStack(0),
61 fMagField(0),
62 fOldGeometry(kFALSE),
63 fIsControls(kFALSE),
64 fIsMaster(kTRUE)
65 {
66 /// Standard constructor
67 /// \param name The MC application name
68 /// \param title The MC application description
69
70 // Create a user stack
71 fStack = new Ex03MCStack(1000);
72
73 // Create detector construction
74 fDetConstruction = new DetectorConstruction();
75
76 // Create a calorimeter SD
77 fSensitiveDetector = new SensitiveDetector("Absorber");
78
79 // Create a primary generator
80 fPrimaryGenerator = new PrimaryGenerator(fStack);
81
82 // Constant magnetic field (in kiloGauss)
83 fMagField = new TGeoUniformMagField();
84 }
Implementation of the TVirtualMCStack interface.
Definition Ex03MCStack.h:36
Ex03MCStack * fStack
VMC stack.
Bool_t fOldGeometry
Option for geometry definition.
Int_t fPrintModulo
The event modulus number to be printed.
Bool_t fIsControls
Option to activate special controls.
Bool_t fIsMaster
If is on master thread.
SensitiveDetector * fSensitiveDetector
Absorber SD.
PrimaryGenerator * fPrimaryGenerator
Primary generator.
TMCVerbose fVerbose
VMC verbose helper.
TGeoUniformMagField * fMagField
Magnetic field.
TMCRootManager * fRootManager
Root manager.
Int_t fEventNo
Event counter.
DetectorConstruction * fDetConstruction
Dector construction.

◆ MCApplication() [2/3]

VMC::TR::MCApplication::MCApplication ( )

Default constructor

Definition at line 121 of file MCApplication.cxx.

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

◆ ~MCApplication()

VMC::TR::MCApplication::~MCApplication ( )
virtual

Destructor

Definition at line 139 of file MCApplication.cxx.

140 {
141 /// Destructor
142
143 // cout << "MCApplication::~MCApplication " << this << endl;
144
145 delete fRootManager;
146 delete fStack;
147 if (fIsMaster) delete fDetConstruction;
148 delete fSensitiveDetector;
149 delete fPrimaryGenerator;
150 delete fMagField;
151 delete gMC;
152
153 // cout << "Done MCApplication::~MCApplication " << this << endl;
154 }

◆ MCApplication() [3/3]

VMC::TR::MCApplication::MCApplication ( const MCApplication & origin)
private

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

Parameters
originThe source MC application

Definition at line 87 of file MCApplication.cxx.

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

Member Function Documentation

◆ InitMC()

void VMC::TR::MCApplication::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 188 of file MCApplication.cxx.

189 {
190 /// Initialize MC.
191 /// The selection of the concrete MC is done in the macro.
192 /// \param setup The name of the configuration macro
193
194 fVerbose.InitMC();
195
196 if (TString(setup) != "") {
197 gROOT->LoadMacro(setup);
198 gInterpreter->ProcessLine("Config()");
199 if (!gMC) {
200 Fatal(
201 "InitMC", "Processing Config() has failed. (No MC is instantiated.)");
202 }
203 }
204
205// MT support available from root v 5.34/18
206#if ROOT_VERSION_CODE >= 336402
207 // Create Root manager
208 if (!gMC->IsMT()) {
209 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
210 // fRootManager->SetDebug(true);
211 }
212#else
213 // Create Root manager
214 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
215 // fRootManager->SetDebug(true);
216#endif
217 // Cretae histograms
218 BookHisto();
219
220 gMC->SetStack(fStack);
221 gMC->SetMagField(fMagField);
222 gMC->Init();
223 gMC->BuildPhysics();
224
226 }

◆ RunMC()

void VMC::TR::MCApplication::RunMC ( Int_t nofEvents)

Run MC.

Parameters
nofEventsNumber of events to be processed

Definition at line 229 of file MCApplication.cxx.

230 {
231 /// Run MC.
232 /// \param nofEvents Number of events to be processed
233
234 fVerbose.RunMC(nofEvents);
235
236 gMC->ProcessRun(nofEvents);
237 FinishRun();
238 }

◆ FinishRun()

void VMC::TR::MCApplication::FinishRun ( )

Finish MC run.

Definition at line 241 of file MCApplication.cxx.

242 {
243 /// Finish MC run.
244
245 fVerbose.FinishRun();
246 // cout << "MCApplication::FinishRun: " << endl;
247
248 // print run statisctics
249 cout << " ================== run summary =====================" << endl;
250 cout << " End of Run TotNbofEvents = " << fEventNo << endl;
251
252 cout << " Mean energy deposit in absorber = " << fHistograms[0]->GetMean()
253 << " +-" << fHistograms[0]->GetRMS() << " MeV " << endl;
254
255 cout << " Total number of XTR gammas = " << fHistograms[1]->GetEntries()
256 << endl;
257
258 cout << " Total number of all gammas = " << fHistograms[2]->GetEntries()
259 << endl;
260
261 if (fRootManager) {
262 fRootManager->WriteAll();
263 fRootManager->Close();
264 }
265 }
std::vector< TH1D * > fHistograms

◆ CloneForWorker()

TVirtualMCApplication * VMC::TR::MCApplication::CloneForWorker ( ) const
virtual

Definition at line 268 of file MCApplication.cxx.

269 {
270 return new MCApplication(*this);
271 }

◆ InitOnWorker()

void VMC::TR::MCApplication::InitOnWorker ( )
virtual

Definition at line 274 of file MCApplication.cxx.

275 {
276 // cout << "MCApplication::InitForWorker " << this << endl;
277
278 // Create Root manager
279 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
280 // fRootManager->SetDebug(true);
281
282 // Set data to MC
283 gMC->SetStack(fStack);
284 gMC->SetMagField(fMagField);
285
287 }

◆ FinishRunOnWorker()

void VMC::TR::MCApplication::FinishRunOnWorker ( )
virtual

Definition at line 290 of file MCApplication.cxx.

291 {
292 // cout << "MCApplication::FinishWorkerRun: " << endl;
293 if (fRootManager) {
294 fRootManager->WriteAll();
295 fRootManager->Close();
296 }
297 }

◆ ConstructGeometry()

void VMC::TR::MCApplication::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 300 of file MCApplication.cxx.

301 {
302 /// Construct geometry using detector contruction class.
303 /// The detector contruction class is using TGeo functions or
304 /// TVirtualMC functions (if oldGeometry is selected)
305
306 fVerbose.ConstructGeometry();
307
309 }

◆ InitGeometry()

void VMC::TR::MCApplication::InitGeometry ( )
virtual

Initialize geometry

Definition at line 312 of file MCApplication.cxx.

313 {
314 /// Initialize geometry
315
316 fVerbose.InitGeometry();
317
319 }

◆ GeneratePrimaries()

void VMC::TR::MCApplication::GeneratePrimaries ( )
virtual

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

Definition at line 322 of file MCApplication.cxx.

323 {
324 /// Fill the user stack (derived from TVirtualMCStack) with primary
325 /// particles.
326
327 fVerbose.GeneratePrimaries();
328
330 }

◆ BeginEvent()

void VMC::TR::MCApplication::BeginEvent ( )
virtual

User actions at beginning of event

Definition at line 333 of file MCApplication.cxx.

334 {
335 /// User actions at beginning of event
336
337 fVerbose.BeginEvent();
338
339 // Clear TGeo tracks (if filled)
340 if (TString(gMC->GetName()) == "TGeant3TGeo" &&
341 gGeoManager->GetListOfTracks() && gGeoManager->GetTrack(0) &&
342 ((TVirtualGeoTrack*)gGeoManager->GetTrack(0))->HasPoints()) {
343
344 gGeoManager->ClearTracks();
345 // if (gPad) gPad->Clear();
346 }
347
348 fEventNo++;
349 if (fEventNo % fPrintModulo == 0) {
350 cout << "\n---> Begin of event: " << fEventNo << endl;
351 }
352 }

◆ BeginPrimary()

void VMC::TR::MCApplication::BeginPrimary ( )
virtual

User actions at beginning of a primary track.

Definition at line 355 of file MCApplication.cxx.

356 {
357 /// User actions at beginning of a primary track.
358
359 fVerbose.BeginPrimary();
360 }

◆ PreTrack()

void VMC::TR::MCApplication::PreTrack ( )
virtual

User actions at beginning of each track. Fill spectra.

Definition at line 363 of file MCApplication.cxx.

364 {
365 /// User actions at beginning of each track.
366 /// Fill spectra.
367
368 fVerbose.PreTrack();
369
370 // Gamma
371 if (gMC->TrackPid() == kGamma) {
372 // XTR gammas
373 Int_t creatorProcess = fStack->GetCurrentTrack()->GetUniqueID();
374
375// Available since 6.07/03 and 5.34/35
376// kpTransitionRadiation = 49
377#if ((ROOT_VERSION_CODE >= ROOT_VERSION(6, 7, 3)) || \
378 ((ROOT_VERSION_CODE <= ROOT_VERSION(6, 0, 0)) && \
379 (ROOT_VERSION_CODE >= ROOT_VERSION(5, 34, 35))))
380 if (creatorProcess == kPTransitionRadiation) {
381#else
382 if (creatorProcess == kPNull) {
383#endif
384 fHistograms[1]->Fill(gMC->Etot() * 1e+03);
385 }
386 fHistograms[2]->Fill(gMC->Etot() * 1e+03);
387 }
388
389 // Secondary e-
390 if (gMC->TrackPid() == kElectron &&
392
393 fHistograms[3]->Fill((gMC->Etot() - gMC->TrackMass()) * 1e+03);
394 }
395 }
virtual TParticle * GetCurrentTrack() const
virtual Int_t GetCurrentParentTrackNumber() const

◆ Stepping()

void VMC::TR::MCApplication::Stepping ( )
virtual

User actions at each step

Definition at line 398 of file MCApplication.cxx.

399 {
400 /// User actions at each step
401
402 // Work around for Fluka VMC, which does not call
403 // MCApplication::PreTrack()
404 //
405 // cout << "MCApplication::Stepping" << this << endl;
406 static Int_t trackId = 0;
407 if (TString(gMC->GetName()) == "TFluka" &&
408 gMC->GetStack()->GetCurrentTrackNumber() != trackId) {
409 fVerbose.PreTrack();
410 trackId = gMC->GetStack()->GetCurrentTrackNumber();
411 }
412
413 fVerbose.Stepping();
414
416 }

◆ PostTrack()

void VMC::TR::MCApplication::PostTrack ( )
virtual

User actions after finishing of each track

Definition at line 419 of file MCApplication.cxx.

420 {
421 /// User actions after finishing of each track
422
423 fVerbose.PostTrack();
424 }

◆ FinishPrimary()

void VMC::TR::MCApplication::FinishPrimary ( )
virtual

User actions after finishing of a primary track

Definition at line 427 of file MCApplication.cxx.

428 {
429 /// User actions after finishing of a primary track
430
431 fVerbose.FinishPrimary();
432 }

◆ FinishEvent()

void VMC::TR::MCApplication::FinishEvent ( )
virtual

User actions after finishing of an event

Definition at line 435 of file MCApplication.cxx.

436 {
437 /// User actions after finishing of an event
438
439 fVerbose.FinishEvent();
440
441 // Geant3 + TGeo
442 // (use TGeo functions for visualization)
443 // if ( TString(gMC->GetName()) == "TGeant3TGeo") {
444
445 // // Draw volume
446 // gGeoManager->SetVisOption(0);
447 // gGeoManager->SetTopVisible();
448 // gGeoManager->GetTopVolume()->Draw();
449
450 // // Draw tracks (if filled)
451 // // Available when this feature is activated via
452 // // gMC->SetCollectTracks(kTRUE);
453 // if ( gGeoManager->GetListOfTracks() &&
454 // gGeoManager->GetTrack(0) &&
455 // ((TVirtualGeoTrack*)gGeoManager->GetTrack(0))->HasPoints() ) {
456
457 // gGeoManager->DrawTracks("/*"); // this means all tracks
458 // }
459 // }
460
461 // Fill Edep histogram in MeV
462 // cout << "Filling in h0 " <<
463 // fSensitiveDetector->GetHit(0)->GetEdep()*1e+03 << endl;
464 fHistograms[0]->Fill(fSensitiveDetector->GetEdep() * 1e+03);
465
466 fRootManager->Fill();
467
468 if (fEventNo % fPrintModulo == 0) {
470 }
471
473 fStack->Reset();
474 }
Double_t GetEdep() const
Return energy deposit.
virtual void Print(Option_t *option="") const

◆ SetPrintModulo()

void VMC::TR::MCApplication::SetPrintModulo ( Int_t value)
inline

Set the event modulus number to be printed

Parameters
valueThe new event modulus number value

Definition at line 112 of file MCApplication.h.

112{ fPrintModulo = value; }

◆ SetVerboseLevel()

void VMC::TR::MCApplication::SetVerboseLevel ( Int_t verboseLevel)
inline

Set verbosity

Parameters
verboseLevelThe new verbose level value

Definition at line 116 of file MCApplication.h.

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

◆ SetControls()

void VMC::TR::MCApplication::SetControls ( Bool_t isControls)
inline

Switch on/off special process controls

Parameters
isControlsIf true, special process controls setting is activated

Definition at line 155 of file MCApplication.h.

156{
157 fIsControls = isControls;
158}

◆ SetField()

void VMC::TR::MCApplication::SetField ( Double_t bz)
inline

Definition at line 123 of file MCApplication.h.

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

◆ GetDetectorConstruction()

DetectorConstruction * VMC::TR::MCApplication::GetDetectorConstruction ( ) const
inline
Returns
The detector construction

Definition at line 129 of file MCApplication.h.

130{
131 return fDetConstruction;
132}

◆ GetSensitiveDetector()

SensitiveDetector * VMC::TR::MCApplication::GetSensitiveDetector ( ) const
inline
Returns
The calorimeter sensitive detector

Definition at line 135 of file MCApplication.h.

136{
137 return fSensitiveDetector;
138}

◆ GetPrimaryGenerator()

PrimaryGenerator * VMC::TR::MCApplication::GetPrimaryGenerator ( ) const
inline
Returns
The primary generator

Definition at line 141 of file MCApplication.h.

142{
143 return fPrimaryGenerator;
144}

◆ SetOldGeometry()

void VMC::TR::MCApplication::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 148 of file MCApplication.h.

149{
150 fOldGeometry = oldGeometry;
151}

◆ RegisterStack()

void VMC::TR::MCApplication::RegisterStack ( ) const
private

Register stack in the Root manager.

Definition at line 161 of file MCApplication.cxx.

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

◆ BookHisto()

void VMC::TR::MCApplication::BookHisto ( ) const
private

Create histograms

Definition at line 172 of file MCApplication.cxx.

173 {
174 /// Create histograms
175
176 fHistograms.push_back(new TH1D("1", "Edep", 100, 0., 0.1));
177 fHistograms.push_back(new TH1D("2", "XTR Gamma spectrum", 100, 0., 0.1));
178 fHistograms.push_back(
179 new TH1D("3", "Secondary Gamma spectrum", 100, 0., 0.1));
180 fHistograms.push_back(new TH1D("4", "Secondary e- spectrum", 100, 0., 0.1));
181 }

Member Data Documentation

◆ fRootManager

TMCRootManager* VMC::TR::MCApplication::fRootManager
mutableprivate

Root manager.

Definition at line 92 of file MCApplication.h.

◆ fPrintModulo

Int_t VMC::TR::MCApplication::fPrintModulo
private

The event modulus number to be printed.

Definition at line 93 of file MCApplication.h.

◆ fEventNo

Int_t VMC::TR::MCApplication::fEventNo
private

Event counter.

Definition at line 94 of file MCApplication.h.

◆ fVerbose

TMCVerbose VMC::TR::MCApplication::fVerbose
private

VMC verbose helper.

Definition at line 95 of file MCApplication.h.

◆ fStack

Ex03MCStack* VMC::TR::MCApplication::fStack
private

VMC stack.

Definition at line 96 of file MCApplication.h.

◆ fDetConstruction

DetectorConstruction* VMC::TR::MCApplication::fDetConstruction
private

Dector construction.

Definition at line 97 of file MCApplication.h.

◆ fSensitiveDetector

SensitiveDetector* VMC::TR::MCApplication::fSensitiveDetector
private

Absorber SD.

Definition at line 98 of file MCApplication.h.

◆ fPrimaryGenerator

PrimaryGenerator* VMC::TR::MCApplication::fPrimaryGenerator
private

Primary generator.

Definition at line 99 of file MCApplication.h.

◆ fMagField

TGeoUniformMagField* VMC::TR::MCApplication::fMagField
private

Magnetic field.

Definition at line 100 of file MCApplication.h.

◆ fOldGeometry

Bool_t VMC::TR::MCApplication::fOldGeometry
private

Option for geometry definition.

Definition at line 101 of file MCApplication.h.

◆ fIsControls

Bool_t VMC::TR::MCApplication::fIsControls
private

Option to activate special controls.

Definition at line 102 of file MCApplication.h.

◆ fIsMaster

Bool_t VMC::TR::MCApplication::fIsMaster
private

If is on master thread.

Definition at line 103 of file MCApplication.h.


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