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

◆ Ex02MCApplication() [2/3]

Ex02MCApplication::Ex02MCApplication ( )

Default constructor

Definition at line 94 of file Ex02MCApplication.cxx.

95 : TVirtualMCApplication(),
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 Int_t threadRank = 1;
216 // The real thread rank will be set in MCRootManager
217 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite, threadRank);
218 // fRootManager->SetDebug(true);
219
220 // Set data to MC
221 gMC->SetStack(fStack);
222 gMC->SetMagField(fMagField);
223
225}

◆ FinishRunOnWorker()

void Ex02MCApplication::FinishRunOnWorker ( )
virtual

Definition at line 228 of file Ex02MCApplication.cxx.

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

◆ 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 238 of file Ex02MCApplication.cxx.

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

◆ InitGeometry()

void Ex02MCApplication::InitGeometry ( )
virtual

Initialize geometry

Definition at line 266 of file Ex02MCApplication.cxx.

267{
268 /// Initialize geometry
269
270 fTrackerSD->Initialize();
271}

◆ GeneratePrimaries()

void Ex02MCApplication::GeneratePrimaries ( )
virtual

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

Definition at line 274 of file Ex02MCApplication.cxx.

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

◆ BeginEvent()

void Ex02MCApplication::BeginEvent ( )
virtual

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

Definition at line 316 of file Ex02MCApplication.cxx.

317{
318 /// User actions at beginning of event.
319 /// Nothing to be done this example
320
321 fStack->SetObjectNumber();
322}

◆ BeginPrimary()

void Ex02MCApplication::BeginPrimary ( )
virtual

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

Definition at line 325 of file Ex02MCApplication.cxx.

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

◆ PreTrack()

void Ex02MCApplication::PreTrack ( )
virtual

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

Definition at line 332 of file Ex02MCApplication.cxx.

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

◆ Stepping()

void Ex02MCApplication::Stepping ( )
virtual

User actions at each step

Definition at line 339 of file Ex02MCApplication.cxx.

340{
341 /// User actions at each step
342
343 fTrackerSD->ProcessHits();
344}

◆ PostTrack()

void Ex02MCApplication::PostTrack ( )
virtual

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

Definition at line 347 of file Ex02MCApplication.cxx.

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

◆ FinishPrimary()

void Ex02MCApplication::FinishPrimary ( )
virtual

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

Definition at line 354 of file Ex02MCApplication.cxx.

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

◆ FinishEvent()

void Ex02MCApplication::FinishEvent ( )
virtual

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

Definition at line 361 of file Ex02MCApplication.cxx.

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

◆ 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 387 of file Ex02MCApplication.cxx.

388{
389 /// Read \em i -th event and prints hits.
390 /// \param i The number of event to be read
391
392 if (!fRootManager) {
393 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kRead);
394 }
395
396 fTrackerSD->Register();
398 fRootManager->ReadEvent(i);
399
400 fStack->Print();
401 fTrackerSD->Print();
402}

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