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

Implementation of the TVirtualMCApplication. More...

#include <MCApplication.h>

Inheritance diagram for VMC::Monopole::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 ()
 
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 SetBinSize (Double_t binSize)
 
DetectorConstructionGetDetectorConstruction () const
 

Static Public Member Functions

static MCApplicationInstance ()
 

Private Member Functions

 MCApplication (const MCApplication &origin)
 
void RegisterStack () const
 

Private Attributes

TMCRootManager * fRootManager
 Root manager.
 
Ex03MCStackfStack
 The VMC stack.
 
DetectorConstructionfDetConstruction
 Dector construction.
 
TGeoUniformMagField * fMagField
 Magnetic field.
 
Double_t fBinSize
 Edep histogram bin size.
 
Double_t fOffsetX
 The Edep histogram offset.
 
Double_t fProjRange
 Projected range.
 
Double_t fProjRange2
 Projected range square.
 
Int_t fImedAl
 The Aluminium medium Id.
 
Int_t fNofEvents
 Number of events.
 
Bool_t fIsMaster
 If is on master thread.
 

Detailed Description

Implementation of the TVirtualMCApplication.

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

Definition at line 40 of file MCApplication.h.

Constructor & Destructor Documentation

◆ MCApplication() [1/3]

VMC::Monopole::MCApplication::MCApplication ( const char * name,
const char * title )

Standard constructor

Parameters
nameThe MC application name
titleThe MC application description

Definition at line 57 of file MCApplication.cxx.

58 : TVirtualMCApplication(name, title),
59 fRootManager(0),
60 fStack(0),
62 fMagField(0),
63 fBinSize(0.),
64 fOffsetX(0.),
65 fProjRange(0.),
66 fProjRange2(0.),
67 fImedAl(0),
68 fNofEvents(0),
69 fIsMaster(kTRUE)
70{
71 /// Standard constructor
72 /// \param name The MC application name
73 /// \param title The MC application description
74
75 // Create a user stack
76 fStack = new Ex03MCStack(1000);
77
78 // Create detector construction
79 fDetConstruction = new DetectorConstruction();
80
81 // Constant magnetic field (in kiloGauss)
82 fMagField = new TGeoUniformMagField(0, 0, 2);
83}
Implementation of the TVirtualMCStack interface.
Definition Ex03MCStack.h:36
Ex03MCStack * fStack
The VMC stack.
Int_t fImedAl
The Aluminium medium Id.
Double_t fBinSize
Edep histogram bin size.
Double_t fProjRange
Projected range.
Bool_t fIsMaster
If is on master thread.
Int_t fNofEvents
Number of events.
Double_t fOffsetX
The Edep histogram offset.
DetectorConstruction * fDetConstruction
Dector construction.
TMCRootManager * fRootManager
Root manager.
TGeoUniformMagField * fMagField
Magnetic field.
Double_t fProjRange2
Projected range square.

◆ MCApplication() [2/3]

VMC::Monopole::MCApplication::MCApplication ( )

Default constructor

Definition at line 108 of file MCApplication.cxx.

110 fRootManager(0),
111 fStack(0),
113 fMagField(0),
114 fBinSize(0.5),
115 fImedAl(0),
116 fNofEvents(0),
117 fIsMaster(kTRUE)
118{
119 /// Default constructor
120}

◆ ~MCApplication()

VMC::Monopole::MCApplication::~MCApplication ( )
virtual

Destructor

Definition at line 123 of file MCApplication.cxx.

124{
125 /// Destructor
126
127 delete fStack;
128 if (fIsMaster) delete fDetConstruction;
129 delete fMagField;
130 delete gMC;
131}

◆ MCApplication() [3/3]

VMC::Monopole::MCApplication::MCApplication ( const MCApplication & origin)
private

Copy constructor for cloning application on workers (in multithreading mode)

Parameters
originThe source MC application

Definition at line 86 of file MCApplication.cxx.

87 : TVirtualMCApplication(origin.GetName(), origin.GetTitle()),
88 fRootManager(0),
89 fStack(0),
90 fDetConstruction(origin.fDetConstruction),
91 fMagField(0),
92 fImedAl(origin.fImedAl),
93 fNofEvents(0),
94 fIsMaster(kFALSE)
95{
96 /// Copy constructor for cloning application on workers (in multithreading
97 /// mode) \param origin The source MC application
98
99 // Create new user stack
100 fStack = new Ex03MCStack(1000);
101
102 // Constant magnetic field (in kiloGauss)
103 fMagField = new TGeoUniformMagField(origin.fMagField->GetFieldValue()[0],
104 origin.fMagField->GetFieldValue()[1], origin.fMagField->GetFieldValue()[2]);
105}

Member Function Documentation

◆ Instance()

MCApplication * VMC::Monopole::MCApplication::Instance ( )
inlinestatic
Returns
The MC application instance

Definition at line 98 of file MCApplication.h.

99{
100 return (MCApplication*)(TVirtualMCApplication::Instance());
101}

◆ InitMC()

void VMC::Monopole::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 if (TString(setup) != "") {
160 gROOT->LoadMacro(setup);
161 gInterpreter->ProcessLine("Config()");
162 if (!gMC) {
163 Fatal(
164 "InitMC", "Processing Config() has failed. (No MC is instantiated.)");
165 }
166 }
167
168 // MT support available from root v 5.34/18
169#if ROOT_VERSION_CODE >= 336402
170 // Create Root manager
171 if (!gMC->IsMT()) {
172 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
173 // fRootManager->SetDebug(true);
174 }
175#else
176 // Create Root manager
177 fRootManager = new TMCRootManager(GetName(), TMCRootManager::kWrite);
178 // fRootManager->SetDebug(true);
179#endif
180
181 gMC->SetStack(fStack);
182 gMC->SetMagField(fMagField);
183 gMC->Init();
184 gMC->BuildPhysics();
185
186 // Notify detector construction about initialization
188
189 // initialize projected range, tallies, Ebeam, and book histograms
190 // Double_t maxStepSize = 0.5;
191 fProjRange = 0.;
192 fProjRange2 = 0.;
193
194 Double_t length = fDetConstruction->GetAbsorberSizeX() * 10.; // in mm
195 Double_t binSize = fBinSize * 10.; // in mm
196 Int_t numBins = G4lrint(length / binSize);
197
198 // Define offset for filling histogram
199 fOffsetX = -0.5 * length; // in mm
200
201 // cout << "numBins, length, offsetX "
202 // << numBins << ", " << length << ", " << fOffsetX << endl;
203
204 // Create histograms
205 // fHistograms.push_back(new TH1D("Edep_x", "Edep (MeV/mm) along absorber
206 // (mm)", numBins, 0, length));
207 fHistograms.push_back(
208 new TH1D("h1", "Edep (MeV/mm) along absorber (mm)", numBins, 0, length));
209 // fHistograms.push_back(new TH1D("h2", "DEDX (MeV/mm) of proton", 100,
210 // -3., 7.)); fHistograms.push_back(new TH1D("h3", "DEDX (MeV/mm) of
211 // monopole", 100, -3., 7.)); fHistograms.push_back(new TH1D("h4", "Range(mm)
212 // of proton", 100, -3., 7.)); fHistograms.push_back(new TH1D("h5", "Range(mm)
213 // of monopole", 100, -3., 7.)); Control histograms fHistograms.push_back(new
214 // TH1D("x", "x", 100, -10, 10)); fHistograms.push_back(new TH1D("Edep (MeV)",
215 // "Edep (Mev)", 100, 0, 100));
216
218}
void SetGeometryInitialized(Bool_t geometryInitialized)
std::vector< TH1D * > fHistograms

◆ RunMC()

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

Run MC.

Parameters
nofEventsNumber of events to be processed

Definition at line 221 of file MCApplication.cxx.

222{
223 /// Run MC.
224 /// \param nofEvents Number of events to be processed
225
226 gMC->ProcessRun(nofEvents);
227 fNofEvents = nofEvents;
228 FinishRun();
229}

◆ FinishRun()

void VMC::Monopole::MCApplication::FinishRun ( )

Finish MC run.

Definition at line 232 of file MCApplication.cxx.

233{
234 /// Finish MC run.
235
236 // Get monopole mass from TDatabasePDG
237 TDatabasePDG* pdgDB = TDatabasePDG::Instance();
238 TParticlePDG* monopole = pdgDB->GetParticle(60000000);
239 Double_t mass = 0;
240 if (monopole) {
241 mass = monopole->Mass();
242 }
243
244 // run conditions
245 cout << "\n The run consists of " << fNofEvents << " monopole "
246 << " of " << mass << " GeV "
247 << " through " << fDetConstruction->GetAbsorberSizeX() << " cm of "
249 // << " (density: " << G4BestUnit(density,"Volumic Mass") << ")"
250 << endl;
251
252 // compute projected range and straggling
253
256 Double_t rms = fProjRange2 - fProjRange * fProjRange;
257 if (rms > 0.) {
258 rms = std::sqrt(rms);
259 }
260 else {
261 rms = 0.;
262 }
263
264 cout.precision(5);
265 cout << "\n projected Range= " << fProjRange << " cm "
266 << " rms= " << rms << " cm " << endl;
267
268 /*
269 G4double ekin[100], dedxproton[100], dedxmp[100];
270 G4EmCalculator calc;
271 calc.SetVerbose(0);
272 G4int i;
273 for(i = 0; i < 100; ++i) {
274 ekin[i] = std::pow(10., 0.1*G4double(i)) * keV;
275 dedxproton[i] =
276 calc.ComputeElectronicDEDX(ekin[i], "proton", matName);
277 dedxmp[i] =
278 calc.ComputeElectronicDEDX(ekin[i], "monopole", matName);
279 }
280
281 if(GetVerbose() > 0){
282 G4cout << "### Stopping Powers" << G4endl;
283 for(i=0; i<100; i++) {
284 G4cout << " E(MeV)= " << ekin[i] << " dedxp= " << dedxproton[i]
285 << " dedxmp= " << dedxmp[i]
286 << G4endl;
287 }
288 }
289 G4cout << "### End of stopping power table" << G4endl;
290
291 if(GetVerbose() > 0){
292 G4cout << "Range table for " << matName << G4endl;
293 }
294
295 for(i=0; i<100; ++i) {
296 G4double e = std::log10(ekin[i] / MeV) + 0.05;
297 fHisto->Fill(1, e, dedxproton[i]);
298 fHisto->Fill(2, e, dedxmp[i]);
299 fHisto->Fill(3, e,
300 std::log10(calc.GetRange(ekin[i],"proton",matName)/mm)); fHisto->Fill(4, e,
301 std::log10(calc.GetRange(ekin[i],"monopole",matName)/mm));
302 }
303 */
304 // normalize histogram
305 // G4double fac = (mm/MeV) / (nEvents * fBinLength);
306 Double_t fac = 1. / (fNofEvents * fBinSize * 10.);
307 fHistograms[0]->Scale(fac);
308
309 if (fRootManager) {
310 fRootManager->WriteAll();
311 fRootManager->Close();
312 }
313}

◆ ConstructGeometry()

void VMC::Monopole::MCApplication::ConstructGeometry ( )
virtual

Construct geometry using detector contruction class. The detector contruction class is using TGeo functions.

Definition at line 349 of file MCApplication.cxx.

350{
351 /// Construct geometry using detector contruction class.
352 /// The detector contruction class is using TGeo functions.
353
355}

◆ InitGeometry()

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

Initialize geometry.

Definition at line 358 of file MCApplication.cxx.

359{
360 /// Initialize geometry.
361
362 fImedAl = gMC->MediumId("Aluminium");
363}

◆ GeneratePrimaries()

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

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

Definition at line 366 of file MCApplication.cxx.

367{
368 /// Fill the user stack (derived from TVirtualMCStack) with primary particles.
369
370 // Track ID (filled by stack)
371 Int_t ntr;
372
373 // Option: to be tracked
374 Int_t toBeDone = 1;
375
376 // Monopole
377 Int_t pdg = 60000000;
378
379 // Polarization
380 Double_t polx = 0.;
381 Double_t poly = 0.;
382 Double_t polz = 0.;
383
384 // Position
385 Double_t vx = -0.5 * (fDetConstruction->GetWorldSizeX()) + 1e-10; // + 1*um
386 Double_t vy = 0.;
387 Double_t vz = 0.;
388 Double_t tof = 0.08;
389
390 // Energy (in GeV)
391 Double_t kinEnergy = 100.;
392 Double_t mass = 100.;
393 Double_t e = mass + kinEnergy;
394
395 // Particle momentum
396 Double_t px, py, pz;
397 px = sqrt(e * e - mass * mass);
398 py = 0.;
399 pz = 0.;
400
401 // Add particle to stack
402 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
403 poly, polz, kPPrimary, ntr, 1., 0);
404}
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 VMC::Monopole::MCApplication::BeginEvent ( )
virtual

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

Definition at line 407 of file MCApplication.cxx.

408{
409 /// User actions at beginning of event.
410 /// Nothing to be done this example
411}

◆ BeginPrimary()

void VMC::Monopole::MCApplication::BeginPrimary ( )
virtual

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

Definition at line 414 of file MCApplication.cxx.

415{
416 /// User actions at beginning of a primary track.
417 /// Nothing to be done this example
418}

◆ PreTrack()

void VMC::Monopole::MCApplication::PreTrack ( )
virtual

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

Definition at line 421 of file MCApplication.cxx.

422{
423 /// User actions at beginning of each track.
424 /// Print info message.
425
426 // Check the monopole properties set via configuration macro
427 // cout << endl;
428 // std::cout << "&&&&& Track mass: " << gMC->TrackMass() << std::endl;
429 // std::cout << "&&&&& Track charge: " << gMC->TrackCharge() << std::endl;
430}

◆ Stepping()

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

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

Definition at line 433 of file MCApplication.cxx.

434{
435 /// User actions at each step.
436 /// Print track position, the current volume and current medium names.
437
438 static TLorentzVector prevPosition;
439
440 TLorentzVector position;
441 gMC->TrackPosition(position);
442
443 Double_t edep = gMC->Edep();
444 if (edep <= 0.) {
445 prevPosition = position;
446 return;
447 }
448
449 edep *= 1.e03; // convert in MeV
450
451 // Bragg curve
452 Double_t x = position.X() * 10.;
453 Double_t dx = (position.X() - prevPosition.X()) * 10.;
454 // cout << "prevPosition "
455 // << prevPosition.X() << ", " << prevPosition.Y() << ", " <<
456 // prevPosition.Z() << endl;
457 // cout << "position "
458 // << position.X() << ", " << position.Y() << ", " << position.Z() <<
459 // endl;
460 // cout << "dx= " << dx << endl;
461
462 Double_t random = gRandom->Uniform(0, 1);
463 x += dx * random - fOffsetX;
464
465 fHistograms[0]->Fill(x, edep);
466 // fHistograms[1]->Fill(x);
467 // fHistograms[2]->Fill(edep);
468
469 // keep position from previous step
470 prevPosition = position;
471}

◆ PostTrack()

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

User actions after finishing of each track

Definition at line 474 of file MCApplication.cxx.

475{
476 /// User actions after finishing of each track
477
478 // Skip secondary tracks
479 if (fStack->GetCurrentParentTrackNumber() != -1) return;
480
481 TLorentzVector position;
482 gMC->TrackPosition(position);
483
484 Double_t x = position.X() - fOffsetX / 10.; // in cm
485 fProjRange += x;
486 fProjRange2 += x * x;
487}
virtual Int_t GetCurrentParentTrackNumber() const

◆ FinishPrimary()

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

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

Definition at line 490 of file MCApplication.cxx.

491{
492 /// User actions after finishing of a primary track.
493 /// Nothing to be done this example
494}

◆ FinishEvent()

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

User actions after finishing of an event

Definition at line 497 of file MCApplication.cxx.

498{
499 /// User actions after finishing of an event
500
501 // fRootManager->Fill();
502 fStack->Reset();
503}

◆ SetBinSize()

void VMC::Monopole::MCApplication::SetBinSize ( Double_t binSize)

Set Edep histogram bin size (in cm)

Definition at line 506 of file MCApplication.cxx.

507{
508 /// Set Edep histogram bin size (in cm)
509
511 cerr << "Geometry alredy initialized: cannot set Edep histogram bin size"
512 << endl;
513 return;
514 }
515
516 fBinSize = binSize;
517}

◆ GetDetectorConstruction()

DetectorConstruction * VMC::Monopole::MCApplication::GetDetectorConstruction ( ) const
inline
Returns
the detector construction

Definition at line 104 of file MCApplication.h.

105{
106 return fDetConstruction;
107}

◆ RegisterStack()

void VMC::Monopole::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::Monopole::MCApplication::fRootManager
mutableprivate

Root manager.

Definition at line 80 of file MCApplication.h.

◆ fStack

Ex03MCStack* VMC::Monopole::MCApplication::fStack
private

The VMC stack.

Definition at line 81 of file MCApplication.h.

◆ fDetConstruction

DetectorConstruction* VMC::Monopole::MCApplication::fDetConstruction
private

Dector construction.

Definition at line 82 of file MCApplication.h.

◆ fMagField

TGeoUniformMagField* VMC::Monopole::MCApplication::fMagField
private

Magnetic field.

Definition at line 83 of file MCApplication.h.

◆ fBinSize

Double_t VMC::Monopole::MCApplication::fBinSize
private

Edep histogram bin size.

Definition at line 84 of file MCApplication.h.

◆ fOffsetX

Double_t VMC::Monopole::MCApplication::fOffsetX
private

The Edep histogram offset.

Definition at line 85 of file MCApplication.h.

◆ fProjRange

Double_t VMC::Monopole::MCApplication::fProjRange
private

Projected range.

Definition at line 86 of file MCApplication.h.

◆ fProjRange2

Double_t VMC::Monopole::MCApplication::fProjRange2
private

Projected range square.

Definition at line 87 of file MCApplication.h.

◆ fImedAl

Int_t VMC::Monopole::MCApplication::fImedAl
private

The Aluminium medium Id.

Definition at line 88 of file MCApplication.h.

◆ fNofEvents

Int_t VMC::Monopole::MCApplication::fNofEvents
private

Number of events.

Definition at line 89 of file MCApplication.h.

◆ fIsMaster

Bool_t VMC::Monopole::MCApplication::fIsMaster
private

If is on master thread.

Definition at line 90 of file MCApplication.h.


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