19 #include <TDatabasePDG.h>
20 #include <TParticlePDG.h>
38 , fPDG(TDatabasePDG::Instance())
41 LOG(info) <<
"FairShieldGenerator: Opening input file " << fileName;
42 fInputFile =
new std::ifstream(fFileName);
43 if (!fInputFile->is_open()) {
44 LOG(fatal) <<
"Cannot open input file.";
46 LOG(info) <<
"FairShieldGenerator: Looking for ions...";
47 Int_t nIons = RegisterIons();
48 LOG(info) <<
"FairShieldGenerator: " << nIons <<
" ions registered.";
50 LOG(info) <<
"FairShieldGenerator: Reopening input file " << fileName;
51 fInputFile =
new std::ifstream(fFileName);
59 if (!fInputFile->is_open()) {
60 LOG(error) <<
"FairShieldGenerator: Input file not open!";
80 *fInputFile >> eventId;
81 *fInputFile >> nTracks;
82 if (nTracks < 0 || nTracks > (INT_MAX - 1))
83 LOG(fatal) <<
"Error reading the number of events from event header.";
84 *fInputFile >> pBeam >> b;
87 if (fInputFile->eof()) {
88 LOG(info) <<
"FairShieldGenerator: End of input file reached ";
93 LOG(info) <<
"FairShieldGenerator: Event " << eventId <<
", pBeam = " << pBeam <<
"GeV, b = " << b
94 <<
" fm, multiplicity " << nTracks;
97 for (Int_t itrack = 0; itrack < nTracks; itrack++) {
100 *fInputFile >> iPid >> iMass >> iCharge >> px >> py >> pz;
105 sprintf(ionName,
"Ion_%d_%d", iMass, iCharge);
106 TParticlePDG* part = fPDG->GetParticle(ionName);
108 LOG(warn) <<
"FairShieldGenerator::ReadEvent: Cannot find " << ionName <<
" in database!";
111 pdgType = part->PdgCode();
113 pdgType = fPDG->ConvertGeant3ToPdg(iPid);
117 primGen->
AddTrack(pdgType, px, py, pz, 0., 0., 0.);
123 void FairShieldGenerator::CloseInput()
126 if (fInputFile->is_open()) {
127 LOG(info) <<
"FairShieldGenerator: Closing input file " << fFileName;
131 fInputFile =
nullptr;
135 Int_t FairShieldGenerator::RegisterIons()
138 Int_t eventId, nTracks, iPid, iMass, iCharge;
139 Double_t pBeam, b, px, py, pz;
142 while (!fInputFile->eof()) {
144 *fInputFile >> eventId;
145 *fInputFile >> nTracks;
146 if (nTracks < 0 || nTracks > (INT_MAX - 1))
147 LOG(fatal) <<
"Error reading the number of events from event header.";
148 *fInputFile >> pBeam >> b;
149 if (fInputFile->eof()) {
152 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
153 *fInputFile >> iPid >> iMass >> iCharge >> px >> py >> pz;
156 sprintf(buffer,
"Ion_%d_%d", iMass, iCharge);
157 TString ionName(buffer);
158 if (fIonMap.find(ionName) == fIonMap.end()) {
160 fIonMap[ionName] = ion;
168 for (
const auto& mi : fIonMap) {
virtual ~FairShieldGenerator()
static FairRunSim * Instance()
ClassImp(FairEventBuilder)
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
virtual void AddTrack(Int_t pdgid, Double_t px, Double_t py, Double_t pz, Double_t vx, Double_t vy, Double_t vz, Int_t parent=-1, Bool_t wanttracking=true, Double_t e=-9e9, Double_t tof=0., Double_t weight=0., TMCProcess proc=kPPrimary)
void AddNewIon(FairIon *ion)