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

Implementation of the TVirtualMCApplication. More...

#include <Ex01MCApplication.h>

Inheritance diagram for Ex01MCApplication:

Public Member Functions

 Ex01MCApplication (const char *name, const char *title)
 
 Ex01MCApplication ()
 
virtual ~Ex01MCApplication ()
 
void InitMC (const char *setup)
 
void RunMC (Int_t nofEvents)
 
void FinishRun ()
 
virtual TVirtualMCApplicationCloneForWorker () const
 
virtual void InitOnWorker ()
 
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 SetOldGeometry (Bool_t oldGeometry=kTRUE)
 
void TestVMCGeometryGetters ()
 

Static Public Member Functions

static Ex01MCApplicationInstance ()
 

Private Member Functions

void ConstructMaterials ()
 
void ConstructVolumes ()
 

Private Attributes

TVirtualMCStackfStack
 The VMC stack.
 
TVirtualMagFieldfMagField
 The magnetic field.
 
Int_t fImedAr
 The Argon gas medium Id.
 
Int_t fImedAl
 The Aluminium medium Id.
 
Int_t fImedPb
 The Lead medium Id.
 
Bool_t fOldGeometry
 Option for geometry definition.
 

Detailed Description

Implementation of the TVirtualMCApplication.

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

Definition at line 31 of file Ex01MCApplication.h.

Constructor & Destructor Documentation

◆ Ex01MCApplication() [1/2]

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

Standard constructor

Parameters
nameThe MC application name
titleThe MC application description

Definition at line 40 of file Ex01MCApplication.cxx.

41 : TVirtualMCApplication(name, title),
42 fStack(0),
43 fMagField(0),
44 fImedAr(0),
45 fImedAl(0),
46 fImedPb(0),
47 fOldGeometry(kFALSE)
48{
49 /// Standard constructor
50 /// \param name The MC application name
51 /// \param title The MC application description
52
53 // create a user stack
54 fStack = new Ex01MCStack(100);
55
56 // create magnetic field (with zero value)
57 fMagField = new TGeoUniformMagField();
58}
Int_t fImedAl
The Aluminium medium Id.
Int_t fImedAr
The Argon gas medium Id.
Int_t fImedPb
The Lead medium Id.
TVirtualMCStack * fStack
The VMC stack.
TVirtualMagField * fMagField
The magnetic field.
Bool_t fOldGeometry
Option for geometry definition.
Implementation of the TVirtualMCStack interface.
Definition Ex01MCStack.h:33

◆ Ex01MCApplication() [2/2]

Ex01MCApplication::Ex01MCApplication ( )

Default constructor

Definition at line 61 of file Ex01MCApplication.cxx.

63 fStack(0),
64 fMagField(0),
65 fImedAr(0),
66 fImedAl(0),
67 fImedPb(0),
68 fOldGeometry(kFALSE)
69{
70 /// Default constructor
71}

◆ ~Ex01MCApplication()

Ex01MCApplication::~Ex01MCApplication ( )
virtual

Destructor

Definition at line 74 of file Ex01MCApplication.cxx.

75{
76 /// Destructor
77
78 delete fStack;
79 delete fMagField;
80 delete gMC;
81}

Member Function Documentation

◆ Instance()

Ex01MCApplication * Ex01MCApplication::Instance ( )
inlinestatic
Returns
The MC application instance

Definition at line 81 of file Ex01MCApplication.h.

82{
83 /// \return The MC application instance
84 return (Ex01MCApplication*)(TVirtualMCApplication::Instance());
85}
Implementation of the TVirtualMCApplication.

◆ InitMC()

void Ex01MCApplication::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 222 of file Ex01MCApplication.cxx.

223{
224 /// Initialize MC.
225 /// The selection of the concrete MC is done in the macro.
226 /// \param setup The name of the configuration macro
227
228 if (TString(setup) != "") {
229 gROOT->LoadMacro(setup);
230 gInterpreter->ProcessLine("Config()");
231 if (!gMC) {
232 Fatal(
233 "InitMC", "Processing Config() has failed. (No MC is instantiated.)");
234 }
235 }
236
237 gMC->SetStack(fStack);
238 gMC->SetMagField(fMagField);
239 gMC->Init();
240 gMC->BuildPhysics();
241}

◆ RunMC()

void Ex01MCApplication::RunMC ( Int_t nofEvents)

Run MC.

Parameters
nofEventsNumber of events to be processed

Definition at line 244 of file Ex01MCApplication.cxx.

245{
246 /// Run MC.
247 /// \param nofEvents Number of events to be processed
248
249 gMC->ProcessRun(nofEvents);
250 FinishRun();
251}

◆ FinishRun()

void Ex01MCApplication::FinishRun ( )

Finish MC run.

Definition at line 254 of file Ex01MCApplication.cxx.

255{
256 /// Finish MC run.
257}

◆ CloneForWorker()

TVirtualMCApplication * Ex01MCApplication::CloneForWorker ( ) const
virtual

Definition at line 260 of file Ex01MCApplication.cxx.

261{
262 return new Ex01MCApplication(GetName(), GetTitle());
263}

◆ InitOnWorker()

void Ex01MCApplication::InitOnWorker ( )
virtual

Definition at line 266 of file Ex01MCApplication.cxx.

267{
268 gMC->SetStack(fStack);
269 gMC->SetMagField(fMagField);
270}

◆ ConstructGeometry()

void Ex01MCApplication::ConstructGeometry ( )
virtual

Construct geometry using TGeo functions or TVirtualMC functions (if oldGeometry is selected)

Definition at line 273 of file Ex01MCApplication.cxx.

274{
275 /// Construct geometry using TGeo functions or
276 /// TVirtualMC functions (if oldGeometry is selected)
277
278 // Cannot use Root geometry if not supported with
279 // selected MC
280 if (!fOldGeometry && !gMC->IsRootGeometrySupported()) {
281 cerr << "Selected MC does not support TGeo geometry" << endl;
282 cerr << "Exiting program" << endl;
283 exit(1);
284 }
285
286 if (!fOldGeometry) {
287 cout << "Geometry will be defined via TGeo" << endl;
290 }
291 else {
292 cout << "Geometry will be defined via VMC" << endl;
293 Ex01DetectorConstructionOld detConstructionOld;
294 detConstructionOld.ConstructMaterials();
295 detConstructionOld.ConstructVolumes();
296 }
297}
The old (deprecated) detector construction class.

◆ InitGeometry()

void Ex01MCApplication::InitGeometry ( )
virtual

Initialize geometry.

Definition at line 300 of file Ex01MCApplication.cxx.

301{
302 /// Initialize geometry.
303
304 fImedAr = gMC->MediumId("ArgonGas");
305 fImedAl = gMC->MediumId("Aluminium");
306 fImedPb = gMC->MediumId("Lead");
307}

◆ GeneratePrimaries()

void Ex01MCApplication::GeneratePrimaries ( )
virtual

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

Definition at line 310 of file Ex01MCApplication.cxx.

311{
312 /// Fill the user stack (derived from TVirtualMCStack) with primary particles.
313
314 // Track ID (filled by stack)
315 Int_t ntr;
316
317 // Option: to be tracked
318 Int_t toBeDone = 1;
319
320 // Geantino
321 Int_t pdg = 0;
322
323 // Polarization
324 Double_t polx = 0.;
325 Double_t poly = 0.;
326 Double_t polz = 0.;
327
328 // Position
329 Double_t vx = -200.;
330 Double_t vy = 0.;
331 Double_t vz = 0.;
332 Double_t tof = 0.;
333
334 // Momentum
335 Double_t px, py, pz, e;
336 px = 1.;
337 py = 0.;
338 pz = 0.;
339 e = 1.;
340
341 // Add particle to stack
342 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
343 poly, polz, kPPrimary, ntr, 1., 0);
344
345 // Change direction and add particle to stack
346 px = 1.;
347 py = 0.1;
348 pz = 0.;
349 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
350 poly, polz, kPPrimary, ntr, 1., 0);
351
352 // Change direction and add particle to stack
353 px = 1.;
354 py = 0.;
355 pz = 0.1;
356 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
357 poly, polz, kPPrimary, ntr, 1., 0);
358}

◆ BeginEvent()

void Ex01MCApplication::BeginEvent ( )
virtual

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

Definition at line 361 of file Ex01MCApplication.cxx.

362{
363 /// User actions at beginning of event.
364 /// Nothing to be done this example
365}

◆ BeginPrimary()

void Ex01MCApplication::BeginPrimary ( )
virtual

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

Definition at line 368 of file Ex01MCApplication.cxx.

369{
370 /// User actions at beginning of a primary track.
371 /// Nothing to be done this example
372}

◆ PreTrack()

void Ex01MCApplication::PreTrack ( )
virtual

User actions at beginning of each track. Print info message.

Definition at line 375 of file Ex01MCApplication.cxx.

376{
377 /// User actions at beginning of each track.
378 /// Print info message.
379
380 cout << endl;
381 cout << "Starting new track" << endl;
382}

◆ Stepping()

void Ex01MCApplication::Stepping ( )
virtual

User actions at each step. Print track position, the current volume and current medium names.

Definition at line 385 of file Ex01MCApplication.cxx.

386{
387 /// User actions at each step.
388 /// Print track position, the current volume and current medium names.
389
390 TLorentzVector position;
391 gMC->TrackPosition(position);
392
393 cout << "Track " << position.X() << " " << position.Y() << " " << position.Z()
394 << " in " << gMC->CurrentVolName() << " ";
395
396 if (gMC->CurrentMedium() == fImedAr) cout << "ArgonGas";
397 if (gMC->CurrentMedium() == fImedAl) cout << "Aluminium";
398 if (gMC->CurrentMedium() == fImedPb) cout << "Lead";
399
400 cout << endl;
401
402 // // Test other TVirtualMC::TrackPosition() functions
403
404 // Double_t dx, dy, dz;
405 // gMC->TrackPosition(dx, dy, dz);
406
407 // Float_t x, y, z;
408 // gMC->TrackPosition(x, y, z);
409
410 // cout << "Track position (double): " << dx << " " << dy << " " << dz
411 // << " (float): " << x << " " << y << " " << z << endl;
412}

◆ PostTrack()

void Ex01MCApplication::PostTrack ( )
virtual

User actions after finishing of each track Nothing to be done this example

Definition at line 415 of file Ex01MCApplication.cxx.

416{
417 /// User actions after finishing of each track
418 /// Nothing to be done this example
419}

◆ FinishPrimary()

void Ex01MCApplication::FinishPrimary ( )
virtual

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

Definition at line 422 of file Ex01MCApplication.cxx.

423{
424 /// User actions after finishing of a primary track.
425 /// Nothing to be done this example
426}

◆ FinishEvent()

void Ex01MCApplication::FinishEvent ( )
virtual

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

Definition at line 429 of file Ex01MCApplication.cxx.

430{
431 /// User actions after finishing of an event
432 /// Nothing to be done this example
433}

◆ SetOldGeometry()

void Ex01MCApplication::SetOldGeometry ( Bool_t oldGeometry = kTRUE)
inline

Select old geometry definition (via TVirtualMC)

Definition at line 87 of file Ex01MCApplication.h.

88{
89 /// Select old geometry definition (via TVirtualMC)
90 fOldGeometry = oldGeometry;
91}

◆ TestVMCGeometryGetters()

void Ex01MCApplication::TestVMCGeometryGetters ( )

Test (new) TVirtualMC functions: GetTransform(), GetShape(), GetMaterial(), GetMedium()

Definition at line 436 of file Ex01MCApplication.cxx.

437{
438 /// Test (new) TVirtualMC functions:
439 /// GetTransform(), GetShape(), GetMaterial(), GetMedium()
440
441 // Get transformation of 10th layer
442 //
443 TString volPath = "/EXPH_1/CALB_1/LAYB_9";
444 TGeoHMatrix matrix;
445 Bool_t result = gMC->GetTransformation(volPath, matrix);
446 if (result) {
447 cout << "Transformation for " << volPath.Data() << ": " << endl;
448 matrix.Print();
449 }
450 else {
451 cerr << "Volume path " << volPath.Data() << " not found" << endl;
452 }
453 cout << endl;
454
455 volPath = "/EXPH_1/CALB_1/LAYB_100";
456 result = gMC->GetTransformation(volPath, matrix);
457 if (result) {
458 cout << "Transformation for " << volPath.Data() << ": " << endl;
459 matrix.Print();
460 }
461 else {
462 cerr << "Volume path " << volPath.Data() << " not found" << endl;
463 }
464 cout << endl;
465
466 volPath = "/EXPH_1/CALB_1/LAYB_9";
467 result = gMC->GetTransformation(volPath, matrix);
468 if (result) {
469 cout << "Transformation for " << volPath.Data() << ": " << endl;
470 matrix.Print();
471 }
472 else {
473 cerr << "Volume path " << volPath.Data() << " not found" << endl;
474 }
475 cout << endl;
476
477 // Get shape
478 //
479 volPath = "/EXPH_1/CALB_1/LAYB_9";
480 TString shapeType;
481 TArrayD par;
482 result = gMC->GetShape(volPath, shapeType, par);
483 if (result) {
484 cout << "Shape for " << volPath.Data() << ": " << endl;
485 cout << shapeType.Data() << " parameters: ";
486 for (Int_t ipar = 0; ipar < par.GetSize(); ipar++)
487 cout << par.At(ipar) << ", ";
488 cout << endl;
489 }
490 else {
491 cerr << "Volume path " << volPath.Data() << " not found" << endl;
492 }
493 cout << endl;
494
495 // Get material by material ID
496 //
497 TString matName;
498 Int_t imat = 2;
499 Double_t a, z, density, radl, inter;
500 TArrayD mpar;
501#if ROOT_VERSION_CODE >= ROOT_VERSION(5, 30, 0)
502 result = gMC->GetMaterial(imat, matName, a, z, density, radl, inter, mpar);
503 if (result) {
504 cout << "Material with ID " << imat << ": " << endl;
505 cout << matName.Data() << " Aeff = " << a << " Zeff = " << z
506 << " density = " << density << " radl = " << radl
507 << " inter = " << inter << endl;
508 if (mpar.GetSize() > 0) {
509 cout << " User defined parameters: ";
510 for (Int_t ipar = 0; ipar < par.GetSize(); ipar++)
511 cout << mpar.At(ipar) << ", ";
512 cout << endl;
513 }
514 }
515 else {
516 cerr << "Material with ID " << imat << " not found" << endl;
517 }
518 cout << endl;
519#endif
520
521 // Get material by volume name
522 //
523 TString volName = "LAYB";
524 mpar.Set(0);
525 result =
526 gMC->GetMaterial(volName, matName, imat, a, z, density, radl, inter, mpar);
527 if (result) {
528 cout << "Material for " << volName.Data() << " volume: " << endl;
529 cout << matName.Data() << " " << imat << " Aeff = " << a
530 << " Zeff = " << z << " density = " << density << " radl = " << radl
531 << " inter = " << inter << endl;
532 if (mpar.GetSize() > 0) {
533 cout << " User defined parameters: ";
534 for (Int_t ipar = 0; ipar < par.GetSize(); ipar++)
535 cout << mpar.At(ipar) << ", ";
536 cout << endl;
537 }
538 }
539 else {
540 cerr << "Volume " << volName.Data() << " not found" << endl;
541 }
542 cout << endl;
543
544 // Get medium
545 //
546 TString medName;
547 Int_t imed, nmat, isvol, ifield;
548 Double_t fieldm, tmaxfd, stemax, deemax, epsil, stmin;
549 result = gMC->GetMedium(volName, medName, imed, nmat, isvol, ifield, fieldm,
550 tmaxfd, stemax, deemax, epsil, stmin, mpar);
551 if (result) {
552 cout << "Medium for " << volName.Data() << " volume: " << endl;
553 cout << medName.Data() << " " << imed << " nmat = " << nmat
554 << " isvol = " << isvol << " ifield = " << ifield
555 << " fieldm = " << fieldm << " tmaxfd = " << tmaxfd
556 << " stemax = " << stemax << " deemax = " << deemax
557 << " epsil = " << epsil << " stmin = " << stmin << endl;
558 if (mpar.GetSize() > 0) {
559 cout << " User defined parameters: ";
560 for (Int_t ipar = 0; ipar < par.GetSize(); ipar++)
561 cout << mpar.At(ipar) << ", ";
562 cout << endl;
563 }
564 }
565 else {
566 cerr << "Volume " << volName.Data() << " not found" << endl;
567 }
568 cout << endl;
569
570 // Test getters non-existing position/volume
571 //
572
573 // Transformation
574 volPath = "/EXPH_1/CALB_1/LAYB_100";
575 result = gMC->GetTransformation(volPath, matrix);
576 cout << "GetTransformation: Volume path " << volPath.Data();
577 if (!result)
578 cout << " not found" << endl;
579 else
580 cout << " found" << endl;
581
582 // Shape
583 result = gMC->GetShape(volPath, shapeType, par);
584 cout << "GetShape: Volume path " << volPath.Data();
585 if (!result)
586 cout << " not found" << endl;
587 else
588 cout << " found" << endl;
589
590 // Material
591 volName = "XYZ";
592 result =
593 gMC->GetMaterial(volName, matName, imat, a, z, density, radl, inter, mpar);
594 cout << "GetMaterial: Volume name " << volName.Data();
595 if (!result)
596 cout << " not found" << endl;
597 else
598 cout << " found" << endl;
599
600 // Medium
601 result = gMC->GetMedium(volName, medName, imed, nmat, isvol, ifield, fieldm,
602 tmaxfd, stemax, deemax, epsil, stmin, mpar);
603 cout << "GetMedium: Volume name " << volName.Data();
604 if (!result)
605 cout << " not found" << endl;
606 else
607 cout << " found" << endl;
608}

◆ ConstructMaterials()

void Ex01MCApplication::ConstructMaterials ( )
private

Construct materials using TGeo modeller

Definition at line 88 of file Ex01MCApplication.cxx.

89{
90 /// Construct materials using TGeo modeller
91
92 // Create Root geometry manager
93 new TGeoManager("E01_geometry", "E01 VMC example geometry");
94
95 Double_t a; // Mass of a mole in g/mole
96 Double_t z; // Atomic number
97 Double_t density; // Material density in g/cm3
98
99 a = 39.95;
100 z = 18.;
101 density = 1.782e-03;
102 TGeoMaterial* matAr = new TGeoMaterial("ArgonGas", a, z, density);
103
104 a = 26.98;
105 z = 13.;
106 density = 2.7;
107 TGeoMaterial* matAl = new TGeoMaterial("Aluminium", a, z, density);
108
109 a = 207.19;
110 z = 82.;
111 density = 11.35;
112 TGeoMaterial* matLead = new TGeoMaterial("Lead", a, z, density);
113
114 /*
115 // Set material IDs
116 // This step is needed, only if user wants to use the material Ids
117 // in his application. Be aware that the material Ids vary
118 // with each concrete MC.
119 // It is recommended to use Media Ids instead, which values
120 // set by user are preserved in all MCs
121 Int_t imat = 0;
122 matAr->SetUniqueID(imat++);
123 matAl->SetUniqueID(imat++);
124 matLead->SetUniqueID(imat++);
125 */
126
127 //
128 // Tracking medias
129 //
130
131 Double_t param[20];
132 param[0] = 0; // isvol - Not used
133 param[1] = 2; // ifield - User defined magnetic field
134 param[2] = 10.; // fieldm - Maximum field value (in kiloGauss)
135 param[3] = -20.; // tmaxfd - Maximum angle due to field deflection
136 param[4] = -0.01; // stemax - Maximum displacement for multiple scat
137 param[5] = -.3; // deemax - Maximum fractional energy loss, DLS
138 param[6] = .001; // epsil - Tracking precision
139 param[7] = -.8; // stmin
140 for (Int_t i = 8; i < 20; ++i) param[i] = 0.;
141
142 fImedAr = 1;
143 new TGeoMedium("ArgonGas", fImedAr, matAr, param);
144
145 fImedAl = 2;
146 new TGeoMedium("Aluminium", fImedAl, matAl, param);
147
148 fImedPb = 3;
149 new TGeoMedium("Lead", fImedPb, matLead, param);
150}

◆ ConstructVolumes()

void Ex01MCApplication::ConstructVolumes ( )
private

Contruct volumes using TGeo modeller

Definition at line 153 of file Ex01MCApplication.cxx.

154{
155 /// Contruct volumes using TGeo modeller
156
157 //------------------------------ experimental hall (world volume)
158 //------------------------------ beam line along x axis
159
160 Double_t* ubuf = 0;
161
162 Double_t expHall[3];
163 expHall[0] = 300.;
164 expHall[1] = 100.;
165 expHall[2] = 100.;
166 TGeoVolume* top = gGeoManager->Volume("EXPH", "BOX", fImedAr, expHall, 3);
167 gGeoManager->SetTopVolume(top);
168
169 //------------------------------ a tracker tube
170
171 Double_t trackerTube[3];
172 trackerTube[0] = 0.;
173 trackerTube[1] = 60.;
174 trackerTube[2] = 50.;
175 gGeoManager->Volume("TRTU", "TUBE", fImedAl, trackerTube, 3);
176
177 Double_t posX = -100.;
178 Double_t posY = 0.;
179 Double_t posZ = 0.;
180 gGeoManager->Node("TRTU", 1, "EXPH", posX, posY, posZ, 0, kTRUE, ubuf);
181
182 //------------------------------ a calorimeter block
183
184 Double_t calBox[3];
185 calBox[0] = 100.;
186 calBox[1] = 50.;
187 calBox[2] = 50.;
188 gGeoManager->Volume("CALB", "BOX", fImedPb, calBox, 3);
189
190 posX = 100.;
191 posY = 0.;
192 posZ = 0.;
193 gGeoManager->Node("CALB", 1, "EXPH", posX, posY, posZ, 0, kTRUE, ubuf);
194
195 //------------------------------ calorimeter layers
196
197 Double_t layerBox[3];
198 layerBox[0] = 1.;
199 layerBox[1] = 40.;
200 layerBox[2] = 40.;
201 gGeoManager->Volume("LAYB", "BOX", fImedAl, layerBox, 3);
202
203 for (Int_t i = 0; i < 19; i++) {
204 posX = (i - 9) * 10.;
205 posY = 0.;
206 posZ = 0.;
207 gGeoManager->Node("LAYB", i, "CALB", posX, posY, posZ, 0, kTRUE, ubuf);
208 }
209
210 // close geometry
211 gGeoManager->CloseGeometry();
212
213 // notify VMC about Root geometry
214 gMC->SetRootGeometry();
215}

Member Data Documentation

◆ fStack

TVirtualMCStack* Ex01MCApplication::fStack
private

The VMC stack.

Definition at line 69 of file Ex01MCApplication.h.

◆ fMagField

TVirtualMagField* Ex01MCApplication::fMagField
private

The magnetic field.

Definition at line 70 of file Ex01MCApplication.h.

◆ fImedAr

Int_t Ex01MCApplication::fImedAr
private

The Argon gas medium Id.

Definition at line 71 of file Ex01MCApplication.h.

◆ fImedAl

Int_t Ex01MCApplication::fImedAl
private

The Aluminium medium Id.

Definition at line 72 of file Ex01MCApplication.h.

◆ fImedPb

Int_t Ex01MCApplication::fImedPb
private

The Lead medium Id.

Definition at line 73 of file Ex01MCApplication.h.

◆ fOldGeometry

Bool_t Ex01MCApplication::fOldGeometry
private

Option for geometry definition.

Definition at line 74 of file Ex01MCApplication.h.


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