VMC Examples Version 6.6
Loading...
Searching...
No Matches
Ex02MCApplication Class Reference

Implementation of the TVirtualMCApplication. More...

#include <Ex02MCApplication.h>

Inheritance diagram for Ex02MCApplication:

Public Member Functions

 Ex02MCApplication (const char *name, const char *title)
 
 Ex02MCApplication ()
 
virtual ~Ex02MCApplication ()
 
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 ReadEvent (Int_t i)
 
void SetOldGeometry (Bool_t oldGeometry=kTRUE)
 

Private Member Functions

 Ex02MCApplication (const Ex02MCApplication &origin)
 
void RegisterStack () const
 

Private Attributes

TMCRootManager * fRootManager
 Root manager.
 
Ex02MCStackfStack
 VMC stack.
 
Ex02DetectorConstruction fDetConstruction
 Dector construction.
 
Ex02TrackerSDfTrackerSD
 Tracker SD.
 
TVirtualMagFieldfMagField
 Magnetic field.
 
Bool_t fOldGeometry
 Option for geometry definition.
 

Detailed Description

Implementation of the TVirtualMCApplication.

Date
21/04/2002
Author
I. Hrivnacova; IPN, Orsay

Definition at line 37 of file Ex02MCApplication.h.

Constructor & Destructor Documentation

◆ Ex02MCApplication() [1/3]

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

Standard constructor

Parameters
nameThe MC application name
titleThe MC application description

Definition at line 39 of file Ex02MCApplication.cxx.

40 : TVirtualMCApplication(name, title),
41 fRootManager(0),
42 fStack(0),
44 fTrackerSD(0),
45 fMagField(0),
46 fOldGeometry(kFALSE)
47{
48 /// Standard constructor
49 /// \param name The MC application name
50 /// \param title The MC application description
51
52 // cout << "Ex02MCApplication::Ex02MCApplication " << this << endl;
53
54 // Create application data
55
56 // Create SD
57 fTrackerSD = new Ex02TrackerSD("Tracker Chamber");
58 // Create a user stack
59 fStack = new Ex02MCStack(100);
60 // Constant magnetic field (in kiloGauss)
61 fMagField = new Ex02MagField(20., 0., 0.);
62 // It si also possible to use TGeoUniformMagField class:
63 // fMagField = new TGeoUniformMagField(20., 0., 0.);
64}
TVirtualMagField * fMagField
Magnetic field.
Bool_t fOldGeometry
Option for geometry definition.
TMCRootManager * fRootManager
Root manager.
Ex02MCStack * fStack
VMC stack.
Ex02DetectorConstruction fDetConstruction
Dector construction.
Ex02TrackerSD * fTrackerSD
Tracker SD.
Implementation of the TVirtualMCStack interface.
Definition Ex02MCStack.h:33
Definition of a uniform magnetic field.
The tracker sensitive detector.

◆ Ex02MCApplication() [2/3]

Ex02MCApplication::Ex02MCApplication ( )

Default constructor

Definition at line 94 of file Ex02MCApplication.cxx.

96 fRootManager(0),
97 fStack(0),
99 fTrackerSD(),
100 fMagField(0),
101 fOldGeometry(kFALSE)
102{
103 /// Default constructor
104}

◆ ~Ex02MCApplication()

Ex02MCApplication::~Ex02MCApplication ( )
virtual

Destructor

Definition at line 107 of file Ex02MCApplication.cxx.

108{
109 /// Destructor
110
111 // cout << "Ex02MCApplication::~Ex02MCApplication " << this << endl;
112
113 delete fRootManager;
114 delete fStack;
115 delete fTrackerSD;
116 delete fMagField;
117 delete gMC;
118
119 // cout << "Done Ex02MCApplication::~Ex02MCApplication " << this << endl;
120}

◆ Ex02MCApplication() [3/3]

Ex02MCApplication::Ex02MCApplication ( const Ex02MCApplication & origin)
private

Copy constructor (for clonig on worker thread in MT mode).

Parameters
originThe source object (on master).

Definition at line 67 of file Ex02MCApplication.cxx.

68 : TVirtualMCApplication(origin.GetName(), origin.GetTitle()),
69 fRootManager(0),
70 fStack(0),
72 fTrackerSD(0),
73 fMagField(0),
74 fOldGeometry(kFALSE)
75{
76 /// Copy constructor (for clonig on worker thread in MT mode).
77 /// \param origin The source object (on master).
78
79 // cout << "Ex02MCApplication::Ex02MCApplication " << this << endl;
80
81 // Create application data
82
83 // Create SD
84 fTrackerSD = new Ex02TrackerSD(*(origin.fTrackerSD));
85 // Create a user stack
86 fStack = new Ex02MCStack(100);
87 // Constant magnetic field (in kiloGauss)
88 fMagField = new Ex02MagField(20., 0., 0.);
89 // It si also possible to use TGeoUniformMagField class:
90 // fMagField = new TGeoUniformMagField(20., 0., 0.);
91}

Member Function Documentation

◆ InitMC()

void Ex02MCApplication::InitMC ( const char * setup)

Initialize MC from Config.C macro The selection of the concrete MC is done in the macro.

Parameters
setupThe name of the configuration macro

Definition at line 141 of file Ex02MCApplication.cxx.

142{
143 /// Initialize MC from Config.C macro
144 /// The selection of the concrete MC is done in the macro.
145 /// \param setup The name of the configuration macro
146
147 if (TString(setup) != "") {
148 gROOT->LoadMacro(setup);
149 gInterpreter->ProcessLine("Config()");
150 if (!gMC) {
151 Fatal(
152 "InitMC", "Processing Config() has failed. (No MC is instantiated.)");
153 }
154 }
155
156// MT support available from root v 5.34/18
157#if ROOT_VERSION_CODE >= 336402
158 // Create Root manager
159 if (!gMC->IsMT()) {
160 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
161 // fRootManager->SetDebug(true);
162 }
163#else
164 // Create Root manager
165 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
166 // fRootManager->SetDebug(true);
167#endif
168
169 // Set data to MC
170 gMC->SetStack(fStack);
171 gMC->SetMagField(fMagField);
172
173 // Init MC
174 gMC->Init();
175 gMC->BuildPhysics();
176
178}

◆ RunMC()

void Ex02MCApplication::RunMC ( Int_t nofEvents)

Run MC.

Parameters
nofEventsNumber of events to be processed

Definition at line 181 of file Ex02MCApplication.cxx.

182{
183 /// Run MC.
184 /// \param nofEvents Number of events to be processed
185
186 gMC->ProcessRun(nofEvents);
187 FinishRun();
188}

◆ FinishRun()

void Ex02MCApplication::FinishRun ( )

Finish MC run.

Definition at line 191 of file Ex02MCApplication.cxx.

192{
193 /// Finish MC run.
194
195 // cout << "Ex02MCApplication::FinishRun: " << endl;
196 if (fRootManager) {
197 // fRootManager->WriteAndClose();
198 fRootManager->WriteAll();
199 fRootManager->Close();
200 }
201}

◆ CloneForWorker()

TVirtualMCApplication * Ex02MCApplication::CloneForWorker ( ) const
virtual

Definition at line 204 of file Ex02MCApplication.cxx.

205{
206 return new Ex02MCApplication(*this);
207}

◆ InitOnWorker()

void Ex02MCApplication::InitOnWorker ( )
virtual

Definition at line 210 of file Ex02MCApplication.cxx.

211{
212 // cout << "Ex02MCApplication::InitForWorker " << this << endl;
213
214 // Create Root manager
215 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
216 // fRootManager->SetDebug(true);
217
218 // Set data to MC
219 gMC->SetStack(fStack);
220 gMC->SetMagField(fMagField);
221
223}

◆ FinishRunOnWorker()

void Ex02MCApplication::FinishRunOnWorker ( )
virtual

Definition at line 226 of file Ex02MCApplication.cxx.

227{
228 // cout << "Ex02MCApplication::FinishWorkerRun: " << endl;
229 if (fRootManager) {
230 fRootManager->WriteAll();
231 fRootManager->Close();
232 }
233}

◆ ConstructGeometry()

void Ex02MCApplication::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 236 of file Ex02MCApplication.cxx.

237{
238 /// Construct geometry using detector contruction class.
239 /// The detector contruction class is using TGeo functions or
240 /// TVirtualMC functions (if oldGeometry is selected)
241
242 // Cannot use Root geometry if not supported with
243 // selected MC
244 if (!fOldGeometry && !gMC->IsRootGeometrySupported()) {
245 cerr << "Selected MC does not support TGeo geometry" << endl;
246 cerr << "Exiting program" << endl;
247 exit(1);
248 }
249
250 if (!fOldGeometry) {
251 cout << "Geometry will be defined via TGeo" << endl;
254 }
255 else {
256 cout << "Geometry will be defined via VMC" << endl;
257 Ex02DetectorConstructionOld detConstructionOld;
258 detConstructionOld.ConstructMaterials();
259 detConstructionOld.ConstructGeometry();
260 }
261}
The old detector construction (via VMC functions)

◆ InitGeometry()

void Ex02MCApplication::InitGeometry ( )
virtual

Initialize geometry

Definition at line 264 of file Ex02MCApplication.cxx.

265{
266 /// Initialize geometry
267
269}

◆ GeneratePrimaries()

void Ex02MCApplication::GeneratePrimaries ( )
virtual

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

Definition at line 272 of file Ex02MCApplication.cxx.

273{
274 /// Fill the user stack (derived from TVirtualMCStack) with primary particles.
275
276 // Track ID (filled by stack)
277 Int_t ntr;
278
279 // Option: to be tracked
280 Int_t toBeDone = 1;
281
282 // Particle type
283 // Int_t pdg = 0; // geantino
284 Int_t pdg = kProton;
285
286 // Polarization
287 Double_t polx = 0.;
288 Double_t poly = 0.;
289 Double_t polz = 0.;
290
291 // Position
292 Double_t vx = 0.;
293 Double_t vy = 0.;
294 Double_t vz = -0.5 * (fDetConstruction.GetWorldFullLength());
295 Double_t tof = 0.;
296
297 // Energy
298 Double_t kinEnergy = 3.0;
299 Double_t mass = 0.9382723;
300 Double_t e = mass + kinEnergy;
301
302 // Momentum
303 Double_t px, py, pz;
304 px = 0.;
305 py = 0.;
306 pz = sqrt(e * e - mass * mass);
307
308 // Add particle to stack
309 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
310 poly, polz, kPPrimary, ntr, 1., 0);
311}
virtual void PushTrack(Int_t toBeDone, Int_t parent, Int_t pdg, Double_t px, Double_t py, Double_t pz, Double_t e, Double_t vx, Double_t vy, Double_t vz, Double_t tof, Double_t polx, Double_t poly, Double_t polz, TMCProcess mech, Int_t &ntr, Double_t weight, Int_t is)

◆ BeginEvent()

void Ex02MCApplication::BeginEvent ( )
virtual

User actions at beginning of event. Nothing to be done this example

Definition at line 314 of file Ex02MCApplication.cxx.

315{
316 /// User actions at beginning of event.
317 /// Nothing to be done this example
318
320}
void SetObjectNumber()

◆ BeginPrimary()

void Ex02MCApplication::BeginPrimary ( )
virtual

User actions at beginning of a primary track. Nothing to be done this example

Definition at line 323 of file Ex02MCApplication.cxx.

324{
325 /// User actions at beginning of a primary track.
326 /// Nothing to be done this example
327}

◆ PreTrack()

void Ex02MCApplication::PreTrack ( )
virtual

User actions at beginning of each track. Nothing to be done this example

Definition at line 330 of file Ex02MCApplication.cxx.

331{
332 /// User actions at beginning of each track.
333 /// Nothing to be done this example
334}

◆ Stepping()

void Ex02MCApplication::Stepping ( )
virtual

User actions at each step

Definition at line 337 of file Ex02MCApplication.cxx.

338{
339 /// User actions at each step
340
342}

◆ PostTrack()

void Ex02MCApplication::PostTrack ( )
virtual

User actions at each step. Nothing to be done this example

Definition at line 345 of file Ex02MCApplication.cxx.

346{
347 /// User actions at each step.
348 /// Nothing to be done this example
349}

◆ FinishPrimary()

void Ex02MCApplication::FinishPrimary ( )
virtual

User actions after finishing of a primary track. Nothing to be done this example

Definition at line 352 of file Ex02MCApplication.cxx.

353{
354 /// User actions after finishing of a primary track.
355 /// Nothing to be done this example
356}

◆ FinishEvent()

void Ex02MCApplication::FinishEvent ( )
virtual

User actions after finishing of an event Nothing to be done this example

Definition at line 359 of file Ex02MCApplication.cxx.

360{
361 /// User actions after finishing of an event
362 /// Nothing to be done this example
363
364 // Geant4 own visualization is activated via G4 macro (g4config.in)
365
366 // TGeo visualization
367 if (gGeoManager && gGeoManager->GetListOfTracks() &&
368 gGeoManager->GetTrack(0) &&
369 ((TVirtualGeoTrack*)gGeoManager->GetTrack(0))->HasPoints()) {
370
371 gGeoManager->SetVisOption(0);
372 gGeoManager->SetTopVisible();
373 gGeoManager->DrawTracks("/*"); // this means all tracks
374 }
375
376 fRootManager->Fill();
377
379
380 fStack->Print();
381 fStack->Reset();
382}
virtual void Print(Option_t *option="") const

◆ ReadEvent()

void Ex02MCApplication::ReadEvent ( Int_t i)

Read i -th event and prints hits.

Parameters
iThe number of event to be read

Definition at line 385 of file Ex02MCApplication.cxx.

386{
387 /// Read \em i -th event and prints hits.
388 /// \param i The number of event to be read
389
390 if (!fRootManager) {
391 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kRead);
392 }
393
396 fRootManager->ReadEvent(i);
397
398 fStack->Print();
399 fTrackerSD->Print();
400}
virtual void Print(const Option_t *option=0) const

◆ SetOldGeometry()

void Ex02MCApplication::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 89 of file Ex02MCApplication.h.

90{
91 fOldGeometry = oldGeometry;
92}

◆ RegisterStack()

void Ex02MCApplication::RegisterStack ( ) const
private

Register stack in the Root manager.

Definition at line 126 of file Ex02MCApplication.cxx.

127{
128 /// Register stack in the Root manager.
129
130 if (fRootManager) {
131 // cout << "Ex02MCApplication::RegisterStack: " << endl;
132 fRootManager->Register("stack", "Ex02MCStack", &fStack);
133 }
134}

Member Data Documentation

◆ fRootManager

TMCRootManager* Ex02MCApplication::fRootManager
mutableprivate

Root manager.

Definition at line 75 of file Ex02MCApplication.h.

◆ fStack

Ex02MCStack* Ex02MCApplication::fStack
private

VMC stack.

Definition at line 76 of file Ex02MCApplication.h.

◆ fDetConstruction

Ex02DetectorConstruction Ex02MCApplication::fDetConstruction
private

Dector construction.

Definition at line 77 of file Ex02MCApplication.h.

◆ fTrackerSD

Ex02TrackerSD* Ex02MCApplication::fTrackerSD
private

Tracker SD.

Definition at line 78 of file Ex02MCApplication.h.

◆ fMagField

TVirtualMagField* Ex02MCApplication::fMagField
private

Magnetic field.

Definition at line 79 of file Ex02MCApplication.h.

◆ fOldGeometry

Bool_t Ex02MCApplication::fOldGeometry
private

Option for geometry definition.

Definition at line 80 of file Ex02MCApplication.h.


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