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

Implementation of the TVirtualMCApplication. More...

#include <MCApplication.h>

Inheritance diagram for VMC::ExGarfield::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
 

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.
 

Detailed Description

Implementation of the TVirtualMCApplication.

Garfield garfieldpp 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::ExGarfield::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
Int_t fEventNo
Event counter.
Bool_t fIsMaster
If is on master thread.
DetectorConstruction * fDetConstruction
Dector construction.
TMCRootManager * fRootManager
Root manager.
SensitiveDetector * fSensitiveDetector
Calorimeter SD.
TMCVerbose fVerbose
VMC verbose helper.
Ex03MCStack * fStack
VMC stack.
PrimaryGenerator * fPrimaryGenerator
Primary generator.

◆ MCApplication() [2/3]

VMC::ExGarfield::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::ExGarfield::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::ExGarfield::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::ExGarfield::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 153 of file MCApplication.cxx.

154 {
155 /// Initialize MC.
156 /// The selection of the concrete MC is done in the macro.
157 /// \param setup The name of the configuration macro
158
159 fVerbose.InitMC();
160
161 if (TString(setup) != "") {
162 gROOT->LoadMacro(setup);
163 gInterpreter->ProcessLine("Config()");
164 if (!gMC) {
165 Fatal(
166 "InitMC", "Processing Config() has failed. (No MC is instantiated.)");
167 }
168 }
169
170// MT support available from root v 5.34/18
171#if ROOT_VERSION_CODE >= 336402
172 // Create Root manager
173 if (!gMC->IsMT()) {
174 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
175 // fRootManager->SetDebug(true);
176 }
177#else
178 // Create Root manager
179 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
180 // fRootManager->SetDebug(true);
181#endif
182
183 gMC->SetStack(fStack);
184 gMC->Init();
185 gMC->BuildPhysics();
186
188 }

◆ RunMC()

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

Run MC.

Parameters
nofEventsNumber of events to be processed

Definition at line 191 of file MCApplication.cxx.

192 {
193 /// Run MC.
194 /// \param nofEvents Number of events to be processed
195
196 fVerbose.RunMC(nofEvents);
197
198 gMC->ProcessRun(nofEvents);
199 FinishRun();
200 }

◆ FinishRun()

void VMC::ExGarfield::MCApplication::FinishRun ( )

Finish MC run.

Definition at line 203 of file MCApplication.cxx.

204 {
205 /// Finish MC run.
206
207 fVerbose.FinishRun();
208 // cout << "MCApplication::FinishRun: " << endl;
209 if (fRootManager) {
210 fRootManager->WriteAll();
211 fRootManager->Close();
212 }
213 }

◆ ReadEvent()

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

Read i -th event and prints hits.

Parameters
iThe number of event to be read

Definition at line 247 of file MCApplication.cxx.

248 {
249 /// Read \em i -th event and prints hits.
250 /// \param i The number of event to be read
251
254 fRootManager->ReadEvent(i);
255 }

◆ CloneForWorker()

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

Definition at line 216 of file MCApplication.cxx.

217 {
218 return new MCApplication(*this);
219 }

◆ InitOnWorker()

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

Definition at line 222 of file MCApplication.cxx.

223 {
224 // cout << "MCApplication::InitForWorker " << this << endl;
225
226 // Create Root manager
227 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
228 // fRootManager->SetDebug(true);
229
230 // Set data to MC
231 gMC->SetStack(fStack);
232
234 }

◆ FinishRunOnWorker()

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

Definition at line 237 of file MCApplication.cxx.

238 {
239 // cout << "MCApplication::FinishWorkerRun: " << endl;
240 if (fRootManager) {
241 fRootManager->WriteAll();
242 fRootManager->Close();
243 }
244 }

◆ ConstructGeometry()

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

259 {
260 /// Construct geometry using detector contruction class.
261 /// The detector contruction class is using TGeo functions or
262 /// TVirtualMC functions (if oldGeometry is selected)
263
264 fVerbose.ConstructGeometry();
265
267 }

◆ InitGeometry()

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

Initialize geometry

Definition at line 270 of file MCApplication.cxx.

271 {
272 /// Initialize geometry
273
274 fVerbose.InitGeometry();
275
277 }

◆ GeneratePrimaries()

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

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

Definition at line 280 of file MCApplication.cxx.

281 {
282 /// Fill the user stack (derived from TVirtualMCStack) with primary
283 /// particles.
284
285 fVerbose.GeneratePrimaries();
286
287 TVector3 origin;
289 }
virtual void GeneratePrimaries(const TVector3 &worldSize)

◆ BeginEvent()

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

User actions at beginning of event

Definition at line 292 of file MCApplication.cxx.

293 {
294 /// User actions at beginning of event
295
296 fVerbose.BeginEvent();
297
298 // Clear TGeo tracks (if filled)
299 if (TString(gMC->GetName()) == "TGeant3TGeo" &&
300 gGeoManager->GetListOfTracks() && gGeoManager->GetTrack(0) &&
301 ((TVirtualGeoTrack*)gGeoManager->GetTrack(0))->HasPoints()) {
302
303 gGeoManager->ClearTracks();
304 // if (gPad) gPad->Clear();
305 }
306
307 fEventNo++;
308 cout << " Start generating event Nr " << fEventNo << endl;
309 }

◆ BeginPrimary()

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

313 {
314 /// User actions at beginning of a primary track.
315 /// If test for user defined decay is activated,
316 /// the primary track ID is printed on the screen.
317
318 fVerbose.BeginPrimary();
319 }

◆ PreTrack()

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

323 {
324 /// User actions at beginning of each track
325 /// If test for user defined decay is activated,
326 /// the decay products of the primary track (K0Short)
327 /// are printed on the screen.
328
329 fVerbose.PreTrack();
330 }

◆ Stepping()

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

User actions at each step

Definition at line 333 of file MCApplication.cxx.

334 {
335 /// User actions at each step
336
337 // Work around for Fluka VMC, which does not call
338 // MCApplication::PreTrack()
339 //
340 // cout << "MCApplication::Stepping" << this << endl;
341 static Int_t trackId = 0;
342 if (TString(gMC->GetName()) == "TFluka" &&
343 gMC->GetStack()->GetCurrentTrackNumber() != trackId) {
344 fVerbose.PreTrack();
345 trackId = gMC->GetStack()->GetCurrentTrackNumber();
346 }
347
348 fVerbose.Stepping();
349
351 }

◆ PostTrack()

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

User actions after finishing of each track

Definition at line 354 of file MCApplication.cxx.

355 {
356 /// User actions after finishing of each track
357
358 fVerbose.PostTrack();
359 }

◆ FinishPrimary()

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

User actions after finishing of a primary track

Definition at line 362 of file MCApplication.cxx.

363 {
364 /// User actions after finishing of a primary track
365
366 fVerbose.FinishPrimary();
367 }

◆ FinishEvent()

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

User actions after finishing of an event

Definition at line 370 of file MCApplication.cxx.

371 {
372 /// User actions after finishing of an event
373
374 fVerbose.FinishEvent();
375
376 // update hit info from Garfield
378 fRootManager->Fill();
379
380 // reset data
382 fStack->Reset();
383 }

◆ SetVerboseLevel()

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

Set verbosity

Parameters
verboseLevelThe new verbose level value

Definition at line 105 of file MCApplication.h.

106{
107 fVerbose.SetLevel(verboseLevel);
108}

◆ GetDetectorConstruction()

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

Definition at line 111 of file MCApplication.h.

112{
113 return fDetConstruction;
114}

◆ GetCalorimeterSD()

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

Definition at line 117 of file MCApplication.h.

118{
119 return fSensitiveDetector;
120}

◆ GetPrimaryGenerator()

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

Definition at line 123 of file MCApplication.h.

124{
125 return fPrimaryGenerator;
126}

◆ RegisterStack()

void VMC::ExGarfield::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 }

Member Data Documentation

◆ fRootManager

TMCRootManager* VMC::ExGarfield::MCApplication::fRootManager
mutableprivate

Root manager.

Definition at line 89 of file MCApplication.h.

◆ fEventNo

Int_t VMC::ExGarfield::MCApplication::fEventNo
private

Event counter.

Definition at line 90 of file MCApplication.h.

◆ fVerbose

TMCVerbose VMC::ExGarfield::MCApplication::fVerbose
private

VMC verbose helper.

Definition at line 91 of file MCApplication.h.

◆ fStack

Ex03MCStack* VMC::ExGarfield::MCApplication::fStack
private

VMC stack.

Definition at line 92 of file MCApplication.h.

◆ fDetConstruction

DetectorConstruction* VMC::ExGarfield::MCApplication::fDetConstruction
private

Dector construction.

Definition at line 93 of file MCApplication.h.

◆ fSensitiveDetector

SensitiveDetector* VMC::ExGarfield::MCApplication::fSensitiveDetector
private

Calorimeter SD.

Definition at line 94 of file MCApplication.h.

◆ fPrimaryGenerator

PrimaryGenerator* VMC::ExGarfield::MCApplication::fPrimaryGenerator
private

Primary generator.

Definition at line 95 of file MCApplication.h.

◆ fIsMaster

Bool_t VMC::ExGarfield::MCApplication::fIsMaster
private

If is on master thread.

Definition at line 96 of file MCApplication.h.


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