15#include "FairMCEventHeader.h"
16#include "FairPrimaryGenerator.h"
17#include "FairRunSim.h"
35 : FairGenerator(
"UnigenGenerator",
"CBM generator")
39 LOG(debug) << GetName() <<
": Constructor";
41 LOG(fatal) << GetName() <<
": When choosing "
42 <<
"mode kRotateFixed, a rotation angle must be specified!";
43 if (fileName[0] ==
'\0')
return;
44 if (!
Init()) LOG(fatal) << GetName() <<
": Error in intialisation! Aborting...";
51 : FairGenerator(
"UnigenGenerator",
"CBM generator")
56 LOG(debug) << GetName() <<
": Constructor";
57 if (fileName[0] ==
'\0')
return;
58 if (!
Init()) LOG(fatal) << GetName() <<
": Error in intialisation! Aborting...";
66 LOG(debug) << GetName() <<
": Destructor";
76 primGen->AddTrack(pdgCode, momentum.Px(), momentum.Py(), momentum.Pz(), 0., 0., 0.);
86 LOG(info) << GetName() <<
": Closing input file " <<
fFileName;
99 LOG(info) << GetName() <<
": End of input tree - restarting with first entry";
103 LOG(info) << GetName() <<
": End of input tree reached";
111 LOG(error) << GetName() <<
": Error reading entry " <<
fCurrentEntry <<
" (returns " << result <<
")!";
126 LOG(warning) << GetName() <<
": Already initialised!";
130 LOG(info) << GetName() <<
": Initialising...";
131 std::stringstream ss;
133 case kStandard: ss <<
" standard; rotate event plane to zero";
break;
134 case kRotateFixed: ss <<
" rotate event plane by fixed angle " <<
fPhi;
break;
135 case kNoRotation: ss <<
" no event plane rotation";
break;
136 case kReuseEvents: ss <<
" re-use events if necessary; random event plane angle";
break;
137 default: ss <<
"unkown";
break;
139 LOG(info) << GetName() <<
": Mode " << ss.str();
142 TFile* oldFile = gFile;
143 TDirectory* oldDir = gDirectory;
152 if (!
fFile->IsOpen()) {
153 LOG(error) << GetName() <<
": Could not open input file " <<
fFileName;
156 LOG(info) << GetName() <<
": Open input file " <<
fFileName;
160 if (run ==
nullptr) {
161 LOG(error) << GetName() <<
": No run description in input file!";
165 LOG(info) << GetName() <<
": Run description";
169 Double_t mProt = 0.938272;
172 Double_t eTarg = TMath::Sqrt(pProj * pProj + mProt * mProt);
173 Double_t eProj = TMath::Sqrt(pTarg * pTarg + mProt * mProt);
177 LOG(info) << GetName() <<
": sqrt(s_NN) = " << run->
GetNNSqrtS() <<
" GeV, p_beam = " << pBeam <<
" GeV/u";
178 LOG(info) << GetName() <<
": Lorentz transformation to lab system: "
183 if (
fTree ==
nullptr) {
184 LOG(error) << GetName() <<
": No event tree in input file!";
190 LOG(info) << GetName() <<
": " <<
fAvailableEvents <<
" events in input tree";
194 LOG(info) << GetName() <<
": " << nIons <<
" ions registered.";
206 assert(pdgCode >= 1e9);
210 Int_t ionPdg = pdgCode;
213 LOG(warn) << GetName() <<
": Replacing hypernucleus (PDG " << pdgCode <<
") by PDG " << ionPdg;
223 TVector3 neutronMom = momentum * (1. / Double_t(mass));
224 for (Int_t iNeutron = 0; iNeutron < mass; iNeutron++)
226 LOG(warn) << GetName() <<
": Neutral fragment with PDG " << ionPdg <<
" is split into " << mass <<
" neutrons";
253 case kStandard: phi2 = -1. * phi1;
break;
256 case kReuseEvents: phi2 = gRandom->Uniform(0., 2 * TMath::Pi());
break;
257 default: phi2 = 0.;
break;
261 for (Int_t iPart = 0; iPart <
fEvent->
GetNpa(); iPart++) {
267 TVector3 momentum(particle->
Px(), particle->
Py(), pz);
269 if (phi2 != 0.) momentum.RotateZ(phi2);
272 if (particle->
GetPdg() < 1e9)
280 FairMCEventHeader* eventHeader = primGen->GetEvent();
282 if (eventHeader->IsSet()) {
283 LOG(warning) << GetName() <<
": Event header is already set; "
284 <<
" event info will not be stored";
287 eventHeader->SetEventID(eventId);
289 eventHeader->SetRotZ(phi1 + phi2);
290 eventHeader->MarkSet(kTRUE);
294 LOG(info) << GetName() <<
": Event ID " << eventId <<
", particles " << nPart <<
", primaries " <<
fNofPrimaries
295 <<
", b = " << impact <<
" fm, phi (source) = " << phi1 <<
" rad , phi (generated) = " << phi2 <<
" rad";
306 LOG(debug) << GetName() <<
": Registering ions";
312 for (Int_t iEvent = 0; iEvent <
fTree->GetEntries(); ++iEvent) {
313 fTree->GetEntry(iEvent);
316 for (Int_t iParticle = 0; iParticle <
fEvent->
GetNpa(); ++iParticle) {
319 Int_t pdgCode = particle->
GetPdg();
330 if (charge == 0)
continue;
333 TString ionName = Form(
"Ion_%d_%d_%d", mass, charge, nLambda);
335 fIonMap[ionName] =
new FairIon(ionName, charge, mass, charge);
337 LOG(debug) << GetName() <<
": Adding new ion " << ionName <<
", PDG " << pdgCode <<
" (mass " << mass
338 <<
", charge " << charge <<
", nLambda " << nLambda <<
") from event " << iEvent <<
" at index "
346 FairRunSim* run = FairRunSim::Instance();
347 for (
const auto& entry :
fIonMap)
348 run->AddNewIon(entry.second);
ClassImp(CbmUnigenGenerator)
Generates input to transport simulation from files in Unigen format.
Double_t fPhi
Event plane rotation angle.
Int_t fNofEvents
Number of processed events.
void ProcessIon(FairPrimaryGenerator *primGen, Int_t pdgCode, const TVector3 &momentum)
Treat a composite particle (ion)
TString fFileName
Input file name.
CbmUnigenGenerator(const char *fileName="", EMode mode=kStandard)
Default constructor.
UEvent * fEvent
Current input event.
void AddPrimary(FairPrimaryGenerator *primGen, Int_t pdgCode, const TVector3 &momentum)
Add a primary particle to the event generator.
TFile * fFile
Input ROOT file.
EMode fMode
Rotation mode.
std::map< TString, FairIon * > fIonMap
Map from ion name to FairIon.
Int_t GetIonCharge(Int_t pdgCode) const
Charge number of an ion.
Double_t fGammaCM
Gamma factor of CM in lab frame.
Bool_t GetNextEntry()
Get next entry from input tree.
Int_t GetIonLambdas(Int_t pdgCode) const
Number of Lambdas in an ion.
TTree * fTree
Input ROOT tree.
Double_t fBetaCM
CM velocity in the lab frame.
virtual ~CbmUnigenGenerator()
Destructor.
Int_t fCurrentEntry
Current entry number.
void CloseInput()
Close the input file.
Int_t RegisterIons()
Register ions to the simulation.
@ kNoRotation
No event rotation.
@ kStandard
Rotate events to zero event plane (default)
@ kRotateFixed
Rotate events around z by a fixed angle.
@ kReuseEvents
Reuse events if more are requested than present.
Bool_t Init()
Initialisation.
Bool_t fIsInit
Flag whether generator is initialised.
static const Int_t kPdgLambda
Decomposition of ion PDG code.
Int_t fAvailableEvents
Maximum number of events in the input file.
Int_t GetIonMass(Int_t pdgCode) const
Mass number of an ion.
Int_t fNofPrimaries
Number of primaries registered in current event.
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Read one event from the input file.
UParticle * GetParticle(Int_t index) const
Double_t GetPTarg() const
void Print(Option_t *="") const
Double_t GetPProj() const