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

Implementation of the TVirtualMCApplication. More...

#include <MCApplication.h>

Inheritance diagram for VMC::Gflash::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 ()
 
void ReadEvent (Int_t i)
 
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 SetVerboseLevel (Int_t verboseLevel)
 
DetectorConstructionGetDetectorConstruction () const
 
SensitiveDetectorGetCalorimeterSD () const
 
PrimaryGeneratorGetPrimaryGenerator () const
 

Private Member Functions

 MCApplication (const MCApplication &origin)
 
void RegisterStack () const
 
void ComputeEventStatistics () const
 

Private Attributes

TMCRootManager * fRootManager
 Root manager.
 
Int_t fEventNo
 Event counter.
 
TMCVerbose fVerbose
 VMC verbose helper.
 
Ex03MCStackfStack
 VMC stack.
 
DetectorConstructionfDetConstruction
 Dector construction.
 
SensitiveDetectorfSensitiveDetector
 Calorimeter SD.
 
PrimaryGeneratorfPrimaryGenerator
 Primary generator.
 
Bool_t fIsMaster
 If is on master thread.
 
TStopwatch * fEventTimer
 Event timer.
 

Detailed Description

Implementation of the TVirtualMCApplication.

Geant4 gflash example adapted to Virtual Monte Carlo.

Date
28/10/2015
Author
I. Hrivnacova; IPN, Orsay

Definition at line 47 of file MCApplication.h.

Constructor & Destructor Documentation

◆ MCApplication() [1/3]

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

Standard constructor

Parameters
nameThe MC application name
titleThe MC application description

Definition at line 48 of file MCApplication.cxx.

49 : TVirtualMCApplication(name, title),
50 fRootManager(0),
51 fEventNo(0),
52 fVerbose(0),
53 fStack(0),
57 fIsMaster(kTRUE)
58 {
59 /// Standard constructor
60 /// \param name The MC application name
61 /// \param title The MC application description
62
63 // Create a user stack
64 fStack = new Ex03MCStack(1000);
65
66 // Create detector construction
67 fDetConstruction = new DetectorConstruction();
68
69 // Create a calorimeter SD
70 fSensitiveDetector = new SensitiveDetector("Calorimeter");
71
72 // Create a primary generator
73 fPrimaryGenerator = new PrimaryGenerator(fStack);
74 }
Implementation of the TVirtualMCStack interface.
Definition Ex03MCStack.h:36
Bool_t fIsMaster
If is on master thread.
Int_t fEventNo
Event counter.
TMCRootManager * fRootManager
Root manager.
DetectorConstruction * fDetConstruction
Dector construction.
TMCVerbose fVerbose
VMC verbose helper.
Ex03MCStack * fStack
VMC stack.
PrimaryGenerator * fPrimaryGenerator
Primary generator.
SensitiveDetector * fSensitiveDetector
Calorimeter SD.

◆ MCApplication() [2/3]

VMC::Gflash::MCApplication::MCApplication ( )

Default constructor

Definition at line 103 of file MCApplication.cxx.

105 fRootManager(0),
106 fEventNo(0),
107 fStack(0),
111 fIsMaster(kTRUE)
112 {
113 /// Default constructor
114 }

◆ ~MCApplication()

VMC::Gflash::MCApplication::~MCApplication ( )
virtual

Destructor

Definition at line 117 of file MCApplication.cxx.

118 {
119 /// Destructor
120
121 // cout << "MCApplication::~MCApplication " << this << endl;
122
123 delete fRootManager;
124 delete fStack;
125 if (fIsMaster) delete fDetConstruction;
126 delete fSensitiveDetector;
127 delete fPrimaryGenerator;
128 delete gMC;
129
130 // cout << "Done MCApplication::~MCApplication " << this << endl;
131 }

◆ MCApplication() [3/3]

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

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

Parameters
originThe source MC application

Definition at line 77 of file MCApplication.cxx.

78 : TVirtualMCApplication(origin.GetName(), origin.GetTitle()),
79 fRootManager(0),
80 fEventNo(0),
81 fVerbose(origin.fVerbose),
82 fStack(0),
83 fDetConstruction(origin.fDetConstruction),
86 fIsMaster(kFALSE)
87 {
88 /// Copy constructor for cloning application on workers (in multithreading
89 /// mode) \param origin The source MC application
90
91 // Create new user stack
92 fStack = new Ex03MCStack(1000);
93
94 // Create a calorimeter SD
95 fSensitiveDetector = new SensitiveDetector(*(origin.fSensitiveDetector));
96
97 // Create a primary generator
99 new PrimaryGenerator(*(origin.fPrimaryGenerator), fStack);
100 }

Member Function Documentation

◆ InitMC()

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

236 {
237 /// Initialize MC.
238 /// The selection of the concrete MC is done in the macro.
239 /// \param setup The name of the configuration macro
240
241 fVerbose.InitMC();
242
243 if (TString(setup) != "") {
244 gROOT->LoadMacro(setup);
245 gInterpreter->ProcessLine("Config()");
246 if (!gMC) {
247 Fatal(
248 "InitMC", "Processing Config() has failed. (No MC is instantiated.)");
249 }
250 }
251
252// MT support available from root v 5.34/18
253#if ROOT_VERSION_CODE >= 336402
254 // Create Root manager
255 if (!gMC->IsMT()) {
256 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
257 // fRootManager->SetDebug(true);
258 }
259#else
260 // Create Root manager
261 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
262 // fRootManager->SetDebug(true);
263#endif
264
265 gMC->SetStack(fStack);
266 gMC->Init();
267 gMC->BuildPhysics();
268
270 }

◆ RunMC()

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

Run MC.

Parameters
nofEventsNumber of events to be processed

Definition at line 273 of file MCApplication.cxx.

274 {
275 /// Run MC.
276 /// \param nofEvents Number of events to be processed
277
278 fVerbose.RunMC(nofEvents);
279
280 gMC->ProcessRun(nofEvents);
281 FinishRun();
282 }

◆ FinishRun()

void VMC::Gflash::MCApplication::FinishRun ( )

Finish MC run.

Definition at line 285 of file MCApplication.cxx.

286 {
287 /// Finish MC run.
288
289 fVerbose.FinishRun();
290 // cout << "MCApplication::FinishRun: " << endl;
291 if (fRootManager) {
292 fRootManager->WriteAll();
293 fRootManager->Close();
294 }
295 }

◆ ReadEvent()

void VMC::Gflash::MCApplication::ReadEvent ( Int_t i)

Read i -th event and prints hits.

Parameters
iThe number of event to be read

Definition at line 329 of file MCApplication.cxx.

330 {
331 /// Read \em i -th event and prints hits.
332 /// \param i The number of event to be read
333
336 fRootManager->ReadEvent(i);
337 }

◆ CloneForWorker()

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

Definition at line 298 of file MCApplication.cxx.

299 {
300 return new MCApplication(*this);
301 }

◆ InitOnWorker()

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

Definition at line 304 of file MCApplication.cxx.

305 {
306 // cout << "MCApplication::InitForWorker " << this << endl;
307
308 // Create Root manager
309 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
310 // fRootManager->SetDebug(true);
311
312 // Set data to MC
313 gMC->SetStack(fStack);
314
316 }

◆ FinishRunOnWorker()

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

Definition at line 319 of file MCApplication.cxx.

320 {
321 // cout << "MCApplication::FinishWorkerRun: " << endl;
322 if (fRootManager) {
323 fRootManager->WriteAll();
324 fRootManager->Close();
325 }
326 }

◆ ConstructGeometry()

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

341 {
342 /// Construct geometry using detector contruction class.
343 /// The detector contruction class is using TGeo functions or
344 /// TVirtualMC functions (if oldGeometry is selected)
345
346 fVerbose.ConstructGeometry();
347
349 }

◆ InitGeometry()

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

Initialize geometry

Definition at line 352 of file MCApplication.cxx.

353 {
354 /// Initialize geometry
355
356 fVerbose.InitGeometry();
357
359 }

◆ GeneratePrimaries()

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

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

Definition at line 362 of file MCApplication.cxx.

363 {
364 /// Fill the user stack (derived from TVirtualMCStack) with primary
365 /// particles.
366
367 fVerbose.GeneratePrimaries();
368
369 TVector3 origin;
371 }
virtual void GeneratePrimaries(const TVector3 &worldSize)

◆ BeginEvent()

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

User actions at beginning of event

Definition at line 374 of file MCApplication.cxx.

375 {
376 /// User actions at beginning of event
377
378 fVerbose.BeginEvent();
379
380 // Clear TGeo tracks (if filled)
381 if (TString(gMC->GetName()) == "TGeant3TGeo" &&
382 gGeoManager->GetListOfTracks() && gGeoManager->GetTrack(0) &&
383 ((TVirtualGeoTrack*)gGeoManager->GetTrack(0))->HasPoints()) {
384
385 gGeoManager->ClearTracks();
386 // if (gPad) gPad->Clear();
387 }
388
389 fEventNo++;
390 cout << " Start generating event Nr " << fEventNo << endl;
391
392 // start timer
393 fEventTimer = new TStopwatch();
394 fEventTimer->Start();
395 }
TStopwatch * fEventTimer
Event timer.

◆ BeginPrimary()

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

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 398 of file MCApplication.cxx.

399 {
400 /// User actions at beginning of a primary track.
401 /// If test for user defined decay is activated,
402 /// the primary track ID is printed on the screen.
403
404 fVerbose.BeginPrimary();
405 }

◆ PreTrack()

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

409 {
410 /// User actions at beginning of each track
411 /// If test for user defined decay is activated,
412 /// the decay products of the primary track (K0Short)
413 /// are printed on the screen.
414
415 fVerbose.PreTrack();
416 }

◆ Stepping()

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

User actions at each step

Definition at line 419 of file MCApplication.cxx.

420 {
421 /// User actions at each step
422
423 // Work around for Fluka VMC, which does not call
424 // MCApplication::PreTrack()
425 //
426 // cout << "MCApplication::Stepping" << this << endl;
427 static Int_t trackId = 0;
428 if (TString(gMC->GetName()) == "TFluka" &&
429 gMC->GetStack()->GetCurrentTrackNumber() != trackId) {
430 fVerbose.PreTrack();
431 trackId = gMC->GetStack()->GetCurrentTrackNumber();
432 }
433
434 fVerbose.Stepping();
435
437 }

◆ PostTrack()

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

User actions after finishing of each track

Definition at line 440 of file MCApplication.cxx.

441 {
442 /// User actions after finishing of each track
443
444 fVerbose.PostTrack();
445 }

◆ FinishPrimary()

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

User actions after finishing of a primary track

Definition at line 448 of file MCApplication.cxx.

449 {
450 /// User actions after finishing of a primary track
451
452 fVerbose.FinishPrimary();
453 }

◆ FinishEvent()

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

User actions after finishing of an event

Definition at line 456 of file MCApplication.cxx.

457 {
458 /// User actions after finishing of an event
459
460 // VMC
461
462 fVerbose.FinishEvent();
463
464 fRootManager->Fill();
465 // The application code
466
467 fEventTimer->Stop();
468 cout << endl;
469 cout << "******************************************";
470 cout << endl;
471 cout << "Elapsed Time: " << endl;
472 fEventTimer->Print();
473 cout << endl;
474 cout << "******************************************" << endl;
475 // TO DO
476 // fDtime+=fTimerIntern.GetRealElapsed();
477
479
481
482 fStack->Reset();
483 }

◆ SetVerboseLevel()

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

Set verbosity

Parameters
verboseLevelThe new verbose level value

Definition at line 107 of file MCApplication.h.

108{
109 fVerbose.SetLevel(verboseLevel);
110}

◆ GetDetectorConstruction()

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

Definition at line 113 of file MCApplication.h.

114{
115 return fDetConstruction;
116}

◆ GetCalorimeterSD()

SensitiveDetector * VMC::Gflash::MCApplication::GetCalorimeterSD ( ) const
inline
Returns
The calorimeter sensitive detector

Definition at line 119 of file MCApplication.h.

120{
121 return fSensitiveDetector;
122}

◆ GetPrimaryGenerator()

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

Definition at line 125 of file MCApplication.h.

126{
127 return fPrimaryGenerator;
128}

◆ RegisterStack()

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

Register stack in the Root manager.

Definition at line 138 of file MCApplication.cxx.

139 {
140 /// Register stack in the Root manager.
141
142 if (fRootManager) {
143 // cout << "MCApplication::RegisterStack: " << endl;
144 fRootManager->Register("stack", "Ex03MCStack", &fStack);
145 }
146 }

◆ ComputeEventStatistics()

void VMC::Gflash::MCApplication::ComputeEventStatistics ( ) const
private

Compute event statisics

Definition at line 149 of file MCApplication.cxx.

150 {
151 /// Compute event statisics
152
153 cout << " ------ ExGflashEventAction::End of event nr. " << fEventNo
154 << " -----" << endl;
155
156 TClonesArray* hitsCollection = fSensitiveDetector->GetHitsCollection();
157
158 // Hits in sensitive Detector
159 int n_hit = hitsCollection->GetEntriesFast();
160 cout << " " << n_hit << " hits are stored in HitsCollection " << endl;
161
162 // Get (x,y,z) of vertex of initial particles
163 TVector3 vertexPosition = fPrimaryGenerator->GetVertexPosition();
164 TVector3 vertexDirection = fPrimaryGenerator->GetVertexDirection();
165
166 // ExGflashEventAction: Magicnumber
167 // Should be retrieved from detector construction
168 Double_t energyincrystal[100];
169 for (Int_t i = 0; i < 100; i++) energyincrystal[i] = 0.;
170
171 // For all Hits in sensitive detector
172 Double_t totE = 0;
173 for (Int_t i = 0; i < n_hit; i++) {
174 Hit* hit = static_cast<Hit*>(hitsCollection->At(i));
175
176 Double_t estep = hit->GetEdep();
177 if (estep > 0) {
178 totE += estep;
179 Int_t num = hit->GetCrystalNum();
180 energyincrystal[num] += estep;
181 // cout << " Crystal Nummer " << num << endl;
182
183 TVector3 hitpos = hit->GetPos();
184 TVector3 l(hitpos);
185 // distance from shower start
186 l = l - vertexPosition;
187 // projection on shower axis = longitudinal profile
188 TVector3 longitudinal(l);
189 // shower profiles (Radial)
190 TVector3 radial(vertexPosition.Cross(l));
191 }
192 }
193
194 // Find crystal with maximum energy
195 Double_t max = 0;
196 Int_t index = 0;
197 for (Int_t i = 0; i < 100; i++) {
198 // cout << i <<" " << energyincrystal[i] << G4endl;
199 if (max < energyincrystal[i]) {
200 max = energyincrystal[i];
201 index = i;
202 }
203 }
204 // cout << " NMAX " << index << G4endl;
205
206 // 3x3 matrix of crystals around the crystal with the maximum energy deposit
207 Double_t e3x3 = energyincrystal[index] + energyincrystal[index + 1] +
208 energyincrystal[index - 1] + energyincrystal[index - 10] +
209 energyincrystal[index - 9] + energyincrystal[index - 11] +
210 energyincrystal[index + 10] + energyincrystal[index + 11] +
211 energyincrystal[index + 9];
212
213 // 5x5 matrix of crystals around the crystal with the maximum energy deposit
214 Double_t e5x5 = energyincrystal[index] + energyincrystal[index + 1] +
215 energyincrystal[index - 1] + energyincrystal[index + 2] +
216 energyincrystal[index - 2] + energyincrystal[index - 10] +
217 energyincrystal[index - 9] + energyincrystal[index - 11] +
218 energyincrystal[index - 8] + energyincrystal[index - 12] +
219 energyincrystal[index + 10] + energyincrystal[index + 11] +
220 energyincrystal[index + 9] + energyincrystal[index + 12] +
221 energyincrystal[index + 8];
222
223 cout << " e1 " << energyincrystal[index] << " e3x3 " << e3x3
224 << " e5x5 " << e5x5 << " GeV" << endl;
225
226 cout << " Total energy deposited in the calorimeter: " << totE << " (GeV)"
227 << endl;
228 }
TVector3 GetVertexPosition() const
Return the Vertex position.
TVector3 GetVertexDirection() const
Return the Vertex direction.
TClonesArray * GetHitsCollection() const
Return the hits collection.

Member Data Documentation

◆ fRootManager

TMCRootManager* VMC::Gflash::MCApplication::fRootManager
mutableprivate

Root manager.

Definition at line 90 of file MCApplication.h.

◆ fEventNo

Int_t VMC::Gflash::MCApplication::fEventNo
private

Event counter.

Definition at line 91 of file MCApplication.h.

◆ fVerbose

TMCVerbose VMC::Gflash::MCApplication::fVerbose
private

VMC verbose helper.

Definition at line 92 of file MCApplication.h.

◆ fStack

Ex03MCStack* VMC::Gflash::MCApplication::fStack
private

VMC stack.

Definition at line 93 of file MCApplication.h.

◆ fDetConstruction

DetectorConstruction* VMC::Gflash::MCApplication::fDetConstruction
private

Dector construction.

Definition at line 94 of file MCApplication.h.

◆ fSensitiveDetector

SensitiveDetector* VMC::Gflash::MCApplication::fSensitiveDetector
private

Calorimeter SD.

Definition at line 95 of file MCApplication.h.

◆ fPrimaryGenerator

PrimaryGenerator* VMC::Gflash::MCApplication::fPrimaryGenerator
private

Primary generator.

Definition at line 96 of file MCApplication.h.

◆ fIsMaster

Bool_t VMC::Gflash::MCApplication::fIsMaster
private

If is on master thread.

Definition at line 97 of file MCApplication.h.

◆ fEventTimer

TStopwatch* VMC::Gflash::MCApplication::fEventTimer
private

Event timer.

Definition at line 98 of file MCApplication.h.


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