VMC Examples Version 6.8
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 }
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.

104 : TVirtualMCApplication(),
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 331 of file MCApplication.cxx.

332 {
333 /// Read \em i -th event and prints hits.
334 /// \param i The number of event to be read
335
336 if ( ! fRootManager ) {
337 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kRead);
338 }
339
340 fSensitiveDetector->Register();
342 fRootManager->ReadEvent(i);
343 }

◆ 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 Int_t threadRank = 1;
310 // The real thread rank will be set in MCRootManager
311 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite, threadRank);
312 // fRootManager->SetDebug(true);
313
314 // Set data to MC
315 gMC->SetStack(fStack);
316
318 }

◆ FinishRunOnWorker()

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

Definition at line 321 of file MCApplication.cxx.

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

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

347 {
348 /// Construct geometry using detector contruction class.
349 /// The detector contruction class is using TGeo functions or
350 /// TVirtualMC functions (if oldGeometry is selected)
351
352 fVerbose.ConstructGeometry();
353
354 fDetConstruction->Construct();
355 }

◆ InitGeometry()

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

Initialize geometry

Definition at line 358 of file MCApplication.cxx.

359 {
360 /// Initialize geometry
361
362 fVerbose.InitGeometry();
363
364 fSensitiveDetector->Initialize();
365 }

◆ GeneratePrimaries()

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

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

Definition at line 368 of file MCApplication.cxx.

369 {
370 /// Fill the user stack (derived from TVirtualMCStack) with primary
371 /// particles.
372
373 fVerbose.GeneratePrimaries();
374
375 TVector3 origin;
376 fPrimaryGenerator->GeneratePrimaries(origin);
377 }

◆ BeginEvent()

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

User actions at beginning of event

Definition at line 380 of file MCApplication.cxx.

381 {
382 /// User actions at beginning of event
383
384 fVerbose.BeginEvent();
385
386 // Clear TGeo tracks (if filled)
387 if (TString(gMC->GetName()) == "TGeant3TGeo" &&
388 gGeoManager->GetListOfTracks() && gGeoManager->GetTrack(0) &&
389 ((TVirtualGeoTrack*)gGeoManager->GetTrack(0))->HasPoints()) {
390
391 gGeoManager->ClearTracks();
392 // if (gPad) gPad->Clear();
393 }
394
395 fEventNo++;
396 cout << " Start generating event Nr " << fEventNo << endl;
397
398 // start timer
399 fEventTimer = new TStopwatch();
400 fEventTimer->Start();
401 }
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 404 of file MCApplication.cxx.

405 {
406 /// User actions at beginning of a primary track.
407 /// If test for user defined decay is activated,
408 /// the primary track ID is printed on the screen.
409
410 fVerbose.BeginPrimary();
411 }

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

415 {
416 /// User actions at beginning of each track
417 /// If test for user defined decay is activated,
418 /// the decay products of the primary track (K0Short)
419 /// are printed on the screen.
420
421 fVerbose.PreTrack();
422 }

◆ Stepping()

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

User actions at each step

Definition at line 425 of file MCApplication.cxx.

426 {
427 /// User actions at each step
428
429 // Work around for Fluka VMC, which does not call
430 // MCApplication::PreTrack()
431 //
432 // cout << "MCApplication::Stepping" << this << endl;
433 static Int_t trackId = 0;
434 if (TString(gMC->GetName()) == "TFluka" &&
435 gMC->GetStack()->GetCurrentTrackNumber() != trackId) {
436 fVerbose.PreTrack();
437 trackId = gMC->GetStack()->GetCurrentTrackNumber();
438 }
439
440 fVerbose.Stepping();
441
442 fSensitiveDetector->ProcessHits();
443 }

◆ PostTrack()

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

User actions after finishing of each track

Definition at line 446 of file MCApplication.cxx.

447 {
448 /// User actions after finishing of each track
449
450 fVerbose.PostTrack();
451 }

◆ FinishPrimary()

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

User actions after finishing of a primary track

Definition at line 454 of file MCApplication.cxx.

455 {
456 /// User actions after finishing of a primary track
457
458 fVerbose.FinishPrimary();
459 }

◆ FinishEvent()

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

User actions after finishing of an event

Definition at line 462 of file MCApplication.cxx.

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

◆ 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 }

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: