1 #include "ERTextDecay.h" 7 #include "TVirtualMC.h" 8 #include "TMCProcess.h" 11 #include "FairRunSim.h" 12 #include "FairLogger.h" 14 #include "ERDecayMCEventHeader.h" 18 #include "ERMCEventHeader.h" 20 ERTextDecay::ERTextDecay(TString name):
27 ERTextDecay::~ERTextDecay(){
31 void ERTextDecay::AddOutputIon(Int_t A, Int_t Z, Int_t Q){
32 FairRunSim* run = FairRunSim::Instance();
33 TString outputIonName = fName + TString(
"_OutputIon");
34 FairIon* ion =
new FairIon(outputIonName,A,Z,Q);
35 fOutputIons.push_back(ion);
37 fOutputs.push_back(ion);
41 void ERTextDecay::AddOutputParticle(Int_t pdg){
43 fOutputParticlesPDG.push_back(TDatabasePDG::Instance()->GetParticle(pdg));
44 fOutputs.push_back(TDatabasePDG::Instance()->GetParticle(pdg));
47 Bool_t ERTextDecay::Init(){
51 for (Int_t iOut = 0; iOut < fOutputs.size(); iOut++){
52 if (TString(fOutputs[iOut]->ClassName()).Contains(
"FairIon")){
53 FairIon* ion = (FairIon*)fOutputs[iOut];
54 TParticlePDG* ionPDG = TDatabasePDG::Instance()->GetParticle(ion->GetName());
56 std::cerr <<
"ERTextDecay: Ion "<< ion->GetName() <<
" not found in database!" << endl;
59 fOutputs[iOut] = ionPDG;
64 cerr <<
"File for " << fName <<
" decay not defined!" << endl;
69 cerr <<
"Problem in "<< fName <<
" decay file reading!" << endl;
73 if (fVolumeName ==
""){
74 cerr <<
"Volume name for decay is not defined!" << endl;
81 Bool_t ERTextDecay::ReadFile(){
82 TString path = TString(gSystem->Getenv(
"VMCWORKDIR")) +
"/input/" + fFileName;
86 cerr <<
"Can`t open file " << path << endl;
91 std::getline(f,header);
93 Float_t E, Px, Py, Pz, Angle;
95 vector<TLorentzVector> decay;
97 for (Int_t iOutput = 0; iOutput < fNOutputs; iOutput++){
99 decay.push_back(TLorentzVector(Px,Py,Pz,0.));
100 if (iOutput == fNOutputs-1)
103 fDecays.push_back(decay);
105 cout << fDecays.size() <<
" events have read from file " << path << endl;
109 Bool_t ERTextDecay::Stepping() {
110 if (gMC->CurrentEvent() > fDecays.size()-1) {
113 Fatal(
"ERTextDecay::BeginEvent",
"Events count in file %s less currenet event number", fFileName.Data());
116 if(!fDecayFinish && gMC->TrackPid() == fInputIonPDG->PdgCode() && gMC->CurrentVolName() == fVolumeName){
118 gMC->SetMaxStep(fStep);
119 gMC->TrackPosition(fDecayPos);
121 vector<TLorentzVector> decay = fDecays[gMC->CurrentEvent()];
123 if (fDecayPos.Z() > fDecayPosZ){
125 gMC->TrackMomentum(fInputIonV);
127 TLorentzVector target(0,0,0,fTargetMass);
128 fInputIonV += target;
130 LOG(INFO) <<
"ERTextDecay: Decay with beta = " << fInputIonV.Beta() <<
"; Gamma = " << fInputIonV.Gamma() <<endl;
131 LOG(INFO) <<
"ERTextDecay: Primary ion with mom = (" << fInputIonV.Px() <<
"," << fInputIonV.Py()
132 <<
"," << fInputIonV.Pz() <<
")" << endl;
133 for (Int_t iOut = 0; iOut < fOutputs.size(); iOut++){
135 TParticlePDG* particle = (TParticlePDG*)fOutputs[iOut];
136 TLorentzVector particleV = decay[iOut];
138 particleV.SetE(TMath::Sqrt(particleV.Px()*particleV.Px() + particleV.Py()*particleV.Py() +
139 particleV.Pz()* particleV.Pz() + particle->Mass()*particle->Mass()));
140 particleV.Boost(fInputIonV.BoostVector());
143 gMC->GetStack()->PushTrack(1,gMC->GetStack()->GetCurrentTrackNumber(), particle->PdgCode(),
144 particleV.Px(),particleV.Py(),particleV.Pz(),
145 particleV.E(), fDecayPos.X(), fDecayPos.Y(), fDecayPos.Z(),
146 gMC->TrackTime(), 0., 0., 0.,
147 kPDecay, newTrackNb, particle->Mass(), 0);
149 cout <<
"ERTextDecay: Added output particle with PDG = " << particle->PdgCode() <<
"; pos=(" 150 << fDecayPos.X() <<
"," << fDecayPos.Y() <<
"," << fDecayPos.Z() <<
"); mom=(" 151 << particleV.Px() <<
"," << particleV.Py() <<
"," << particleV.Pz() <<
")" << endl;
153 decay[iOut] = particleV;
156 fDecayFinish = kTRUE;
158 gMC->SetMaxStep(10000.);
165 void ERTextDecay::SaveToEventHeader(){