BmnRoot
Loading...
Searching...
No Matches
MpdUnigenGenerator.cxx
Go to the documentation of this file.
2
3#include "constants.h"
4
6: FairGenerator(),
7 fEventNumber(0),
8 fInFile(nullptr),
9 fInTree(nullptr),
10 fEvent(nullptr),
11 fRun(nullptr),
12 fParticle(nullptr),
13 fSpectatorsON(kFALSE),
14 fPhiMin(0.),
15 fPhiMax(0.),
16 fEventPlaneSet(kFALSE)
17{}
18
19MpdUnigenGenerator::MpdUnigenGenerator(TString fileName, Bool_t isSpectator)
20: FairGenerator(),
21 fEventNumber(0),
22 fInFile(nullptr),
23 fInTree(nullptr),
24 fEvent(nullptr),
25 fRun(nullptr),
26 fParticle(nullptr),
27 fPhiMin(0.),
28 fPhiMax(0.),
29 fEventPlaneSet(kFALSE)
30{
31 std::cout << "-I MpdUnigenGenerator: Opening input file " << fileName.Data() << std::endl;
32
33 fInFile = new TFile(fileName,"read");
34 if (!fInFile){
35 Fatal("MpdUnigenGenerator", "Cannot open input file.");
36 exit(1);
37 }
38
39 fInTree = (TTree*) fInFile->Get("events");
40 fNEntries = fInTree->GetEntries();
41 fRun = dynamic_cast<URun*>(fInFile->Get("run"));
42 Double_t mProt = 0.938272;
43 Double_t pTarg = fRun->GetPTarg(); // target momentum per nucleon
44 Double_t pProj = fRun->GetPProj(); // projectile momentum per nucleon
45 //Double_t eTarg = TMath::Sqrt(pProj * pProj + mProt * mProt);
46 Double_t eProj = TMath::Sqrt(pTarg * pTarg + mProt * mProt);
47 fBetaCM = pProj / eProj;
48 fGammaCM = 1. / TMath::Sqrt(1. - fBetaCM * fBetaCM);
49 Double_t pBeam = fGammaCM * (pProj - fBetaCM * eProj);
50 LOG(info) << GetName() << ": sqrt(s_NN) = " << fRun->GetNNSqrtS() << " GeV, p_beam = " << pBeam << " GeV/u";
51 LOG(info) << GetName() << ": Lorentz transformation to lab system: " << " beta " << fBetaCM << ", gamma " << fGammaCM;
52
53
54 if (!fInTree){
55 Fatal("MpdUnigenGenerator", "Cannot open TTree from the file.");
56 exit(1);
57 }
58
59 fSpectatorsON = isSpectator;
60 if (fSpectatorsON)
61 std::cout << "-I MpdUnigenGenerator: Spectators ON" << std::endl;
62
63 Long64_t nEntries = fInTree->GetEntries();
64 std::cout << "-I MpdUnigenGenerator: Number of entries in tree: " << nEntries << std::endl;
65 fInTree->SetBranchAddress("event", &fEvent);
66
67 if (fSpectatorsON){
69 }
70}
71
72Bool_t MpdUnigenGenerator::ReadEvent(FairPrimaryGenerator* primGen){
73 // Check for input file
74 using namespace std;
75 if (!fInFile) {
76 cout << "-E- MpdUnigenGenerator: Input file not open! " << endl;
77 return kFALSE;
78 }
79
80 // Check for primary generator
81 if (!primGen) {
82 cout << "-E- MpdUnigenGenerator::ReadEvent: "
83 << "No PrimaryGenerator!" << endl;
84 return kFALSE;
85 }
86
87 // Check if current event exists in tree
88 if ( fEventNumber >= fNEntries ) {
89 cout << "-E- MpdUnigenGenerator::ReadEvent: "
90 << "Reached the of the tree" << endl;
91 return kFALSE;
92 }
93
94 fInTree->GetEntry(fEventNumber);
95 std::cout << "-I- MpdUnigenGenerator: Event " << fEventNumber << std::endl;
96
97 Double_t phi = fEvent->GetPhi();
98 Double_t dphi = 0.;
99 // ---> Generate rotation angle
100 std::cout << "Rotation of EP will be performed " << fEventPlaneSet << std::endl;
101 if (fEventPlaneSet) {
102// gRandom->SetSeed(0);
103
104 dphi = uniform_real_distribution_(random_engine_);
105// dphi = gRandom->Uniform(fPhiMin, fPhiMax);
106 std::cout << "EP is rotated to " << dphi << std::endl;
107 phi += dphi;
108 }
109
110 FairMCEventHeader* header = primGen->GetEvent();
111 if (header && (!header->IsSet())) {
112 header->SetEventID(fEvent->GetEventNr());
113 header->SetB(fEvent->GetB());
114 header->MarkSet(kTRUE);
115 header->SetRotZ(phi);
116 }
117
118 UInt_t nTracks = fEvent->GetNpa();
119 Int_t ionPdg;
120 for (UInt_t iTrack = 0; iTrack < nTracks; iTrack++){
121 fParticle = fEvent->GetParticle(iTrack);
122 if (!fParticle)
123 continue;
124
125 Double_t px = fParticle->Px();
126 Double_t py = fParticle->Py();
127 Double_t pz = fParticle->Pz();
128 Double_t mass = fParticle->GetMomentum().M();
129
130 Double_t e = sqrt(mass * mass + px * px + py * py + pz * pz);
132 pz = fGammaCM * (pz + fBetaCM * e);
133
134 if (fEventPlaneSet) {
135 Double_t pt = TMath::Sqrt(px * px + py * py);
136 Double_t azim = TMath::ATan2(py, px);
137 azim += dphi;
138 px = pt * TMath::Cos(azim);
139 py = pt * TMath::Sin(azim);
140 }
141
142 if (fParticle->GetPdg() < 1e9) {
143 primGen->AddTrack(fParticle->GetPdg(), px, py, pz, 0., 0., 0.);
144 } else {
145 // Since hyper-nuclei are not (yet) supported by FairRoot, their PDG
146 // is replaced by that of the non-strange analogue.
147 ionPdg = fParticle->GetPdg();
148 if (GetIonLambdas(fParticle->GetPdg())) {
149 ionPdg = fParticle->GetPdg() - GetIonLambdas(fParticle->GetPdg()) * kPdgLambda;
150 std::cout << "-W- MpdUnigenGenerator: Replacing hypernucleus (PDG " << fParticle->GetPdg() << ") by PDG " << ionPdg << std::endl;
151 }
152 // Charged ions can be registered
153 if (GetIonCharge(ionPdg) > 0) {
154 primGen->AddTrack(ionPdg, px, py, pz, 0., 0., 0.);
155 } else {
156 // Neutral ions are not supported by GEANT4.
157 // They are thus decomposed into neutrons (as an approximation)
158 Int_t neutralFragmentMass = GetIonMass(ionPdg);
159 for (Int_t iNeutron = 0; iNeutron < neutralFragmentMass; iNeutron++) {
160 Double_t pxNeutron = px/(Double_t)neutralFragmentMass;
161 Double_t pyNeutron = py/(Double_t)neutralFragmentMass;
162 Double_t pzNeutron = pz/(Double_t)neutralFragmentMass;
163 //Double_t eNeutron = fParticle->E()/(Double_t)neutralFragmentMass;
164
165 primGen->AddTrack(2112, pxNeutron, pyNeutron, pzNeutron, 0., 0., 0.);
166 }
167 std::cout << "-W- MpdUnigenGenerator: Neutral fragment (PDG " << ionPdg << ") is split into " << neutralFragmentMass << " neutrons." << std::endl;
168 } // Neutral ion ?
169 } // ion ?
170 }
171 fEventNumber++;
172 return kTRUE;
173}
174
176 std::cout << "-I- MpdUnigenGenerator: Registering ions..." << std::endl;
177 UParticle* particle {nullptr};
178 Int_t nIons {0};
179 fIonMap.clear();
180
181 for (Int_t iEvent=0; iEvent<fInTree->GetEntries(); iEvent++) {
182 fInTree->GetEntry(iEvent);
183
184 for (Int_t iParticle=0; iParticle<fEvent->GetNpa(); iParticle++) {
185 particle = fEvent->GetParticle(iParticle);
186
187 Int_t pdgCode = particle->GetPdg();
188 if (pdgCode > 1e9) { // ion
189 // For ions the PDG code is +-10LZZZAAAI,
190 // where A = n_Lambda + n_proton + n_neutron, Z = n_proton, L = n_Lambda
191 // and I = 0 - ground state, I>0 - excitations
192 const Int_t nLambda = GetIonLambdas(pdgCode);
193 const Int_t chrg = GetIonCharge(pdgCode);
194 const Int_t mass = GetIonMass(pdgCode);
195
196 // Neutral ions are skipped (not present in G4IonTable)
197 if (chrg == 0) continue;
198
199 // Add ion to ion map
200 TString ionName = Form("Ion_%d_%d_%d", mass, chrg, nLambda);
201 if (fIonMap.find(ionName) == fIonMap.end()) { // new ion
202 fIonMap[ionName] = new FairIon(ionName, chrg, mass, chrg);
203
204 std::cout << "-I- MpdUnigenGenerator: Added new ion with PDG " << pdgCode
205 << " (Charge " << chrg << ", Mass " << mass << ", nLambda " << nLambda
206 << ") from event " << iEvent << " at index " << iParticle << std::endl;
207
208 nIons++;
209 } //new ion ?
210 } // ion ?
211 } // particle loop
212 } // event loop
213
214 // Adding new ions to FairRunSim instance
215 for (const auto& entry : fIonMap) {
216 FairRunSim::Instance()->AddNewIon(entry.second);
217 }
218
219 return fIonMap.size();
220}
Double_t fPhiMin
Double_t fPhiMax
friend F32vec4 sqrt(const F32vec4 &a)
Definition P4_F32vec4.h:34
Bool_t ReadEvent(FairPrimaryGenerator *primGen) override
Int_t GetEventNr() const
Definition UEvent.h:84
Int_t GetNpa() const
Definition UEvent.h:114
Double_t GetPhi() const
Definition UEvent.h:94
UParticle * GetParticle(Int_t index) const
Definition UEvent.cxx:100
Double_t GetB() const
Definition UEvent.h:89
Int_t GetPdg() const
Definition UParticle.h:127
Double_t Py() const
Definition UParticle.h:172
TLorentzVector GetMomentum() const
Definition UParticle.h:187
Double_t Pz() const
Definition UParticle.h:177
Double_t Px() const
Definition UParticle.h:167
Definition URun.h:8
Double_t GetNNSqrtS()
Definition URun.cxx:156
Double_t GetPTarg() const
Definition URun.h:46
Double_t GetPProj() const
Definition URun.h:43
const CoordinateSystem gCoordinateSystem
Definition constants.h:2
@ sysLaboratory
Definition constants.h:1
STL namespace.