18#include "MCApplication.h"
19#include "DetectorConstruction.h"
20#include "Ex03MCStack.h"
22#include <TMCRootManager.h>
25#include <TDatabasePDG.h>
26#include <TGeoManager.h>
27#include <TGeoMaterial.h>
29#include <TInterpreter.h>
30#include <TLorentzVector.h>
33#include <TVirtualMC.h>
43 int G4lrint(
double ad)
45 return (ad > 0) ?
static_cast<int>(ad + .5) : static_cast<int>(ad - .5);
82 fMagField =
new TGeoUniformMagField(0, 0, 2);
90 fDetConstruction(origin.fDetConstruction),
92 fImedAl(origin.fImedAl),
159 if (TString(setup) !=
"") {
160 gROOT->LoadMacro(setup);
161 gInterpreter->ProcessLine(
"Config()");
164 "InitMC",
"Processing Config() has failed. (No MC is instantiated.)");
169#if ROOT_VERSION_CODE >= 336402
172 fRootManager =
new TMCRootManager(GetName(), TMCRootManager::kWrite);
177 fRootManager =
new TMCRootManager(GetName(), TMCRootManager::kWrite);
196 Int_t numBins = G4lrint(length / binSize);
208 new TH1D(
"h1",
"Edep (MeV/mm) along absorber (mm)", numBins, 0, length));
226 gMC->ProcessRun(nofEvents);
237 TDatabasePDG* pdgDB = TDatabasePDG::Instance();
238 TParticlePDG* monopole = pdgDB->GetParticle(60000000);
241 mass = monopole->Mass();
245 cout <<
"\n The run consists of " <<
fNofEvents <<
" monopole "
246 <<
" of " << mass <<
" GeV "
258 rms = std::sqrt(rms);
265 cout <<
"\n projected Range= " <<
fProjRange <<
" cm "
266 <<
" rms= " << rms <<
" cm " << endl;
362 fImedAl = gMC->MediumId(
"Aluminium");
377 Int_t pdg = 60000000;
391 Double_t kinEnergy = 100.;
392 Double_t mass = 100.;
393 Double_t e = mass + kinEnergy;
397 px = sqrt(e * e - mass * mass);
402 fStack->
PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
403 poly, polz, kPPrimary, ntr, 1., 0);
438 static TLorentzVector prevPosition;
440 TLorentzVector position;
441 gMC->TrackPosition(position);
443 Double_t edep = gMC->Edep();
445 prevPosition = position;
452 Double_t x = position.X() * 10.;
453 Double_t dx = (position.X() - prevPosition.X()) * 10.;
462 Double_t random = gRandom->Uniform(0, 1);
470 prevPosition = position;
481 TLorentzVector position;
482 gMC->TrackPosition(position);
484 Double_t x = position.X() -
fOffsetX / 10.;
511 cerr <<
"Geometry alredy initialized: cannot set Edep histogram bin size"
Implementation of the TVirtualMCStack interface.
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)
virtual Int_t GetCurrentParentTrackNumber() const
The detector construction (via TGeo )
Bool_t GetGeometryInitialized() const
TString GetAbsorberMaterial() const
Double_t GetWorldSizeX() const
void SetGeometryInitialized(Bool_t geometryInitialized)
Double_t GetAbsorberSizeX() const
Implementation of the TVirtualMCApplication.
Ex03MCStack * fStack
The VMC stack.
void InitMC(const char *setup)
virtual void BeginEvent()
Int_t fImedAl
The Aluminium medium Id.
void SetBinSize(Double_t binSize)
Double_t fBinSize
Edep histogram bin size.
virtual void BeginPrimary()
Double_t fProjRange
Projected range.
virtual void FinishPrimary()
void RunMC(Int_t nofEvents)
void RegisterStack() const
virtual void FinishEvent()
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.
virtual void ConstructGeometry()
TMCRootManager * fRootManager
Root manager.
TGeoUniformMagField * fMagField
Magnetic field.
Double_t fProjRange2
Projected range square.
virtual void InitGeometry()
virtual void GeneratePrimaries()
std::vector< TH1D * > fHistograms