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

109 : TVirtualMCApplication(),
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}
MCApplication(const char *name, const char *title)

◆ 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
187 fDetConstruction->SetGeometryInitialized(true);
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}
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 "
248 << fDetConstruction->GetAbsorberMaterial()
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 350 of file MCApplication.cxx.

351{
352 /// Construct geometry using detector contruction class.
353 /// The detector contruction class is using TGeo functions.
354
355 fDetConstruction->ConstructGeometry();
356}

◆ InitGeometry()

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

Initialize geometry.

Definition at line 359 of file MCApplication.cxx.

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

◆ GeneratePrimaries()

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

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

Definition at line 367 of file MCApplication.cxx.

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

◆ BeginEvent()

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

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

Definition at line 408 of file MCApplication.cxx.

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

◆ BeginPrimary()

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

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

Definition at line 415 of file MCApplication.cxx.

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

◆ PreTrack()

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

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

Definition at line 422 of file MCApplication.cxx.

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

◆ 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 434 of file MCApplication.cxx.

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

◆ PostTrack()

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

User actions after finishing of each track

Definition at line 475 of file MCApplication.cxx.

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

◆ FinishPrimary()

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

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

Definition at line 491 of file MCApplication.cxx.

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

◆ FinishEvent()

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

User actions after finishing of an event

Definition at line 498 of file MCApplication.cxx.

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

◆ SetBinSize()

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

Set Edep histogram bin size (in cm)

Definition at line 507 of file MCApplication.cxx.

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

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