FairRoot/PandaRoot
PndGiBuuGenerator.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndGiBuuGenerator source file -----
3 // -------------------------------------------------------------------------
4 
5 
6 #include <iostream>
7 #include "PndGiBuuGenerator.h"
8 #include "FairPrimaryGenerator.h"
9 
10 // ----- Standard constructor -----------------------------------------
11 PndGiBuuGenerator::PndGiBuuGenerator(const Char_t* fileName, const Char_t* pidDataFileName) :
12  fEvent(0), fRunId(0), fFileName(fileName), fPidDataFileName(pidDataFileName), fInputAsciiFile(0), fPx(0), fPy(0), fPz(0), fPdg(0)
13 {
14  std::cout << "Constructor Called!" << std::endl;
15 }
16 // ------------------------------------------------------------------------
17 
18 
19 // ----- Destructor ---------------------------------------------------
21  CloseInput();
22  for (std::map<Int_t, PndGiBuuDecayerAbs*>::const_iterator iter = fDecayerMap.begin(); iter != fDecayerMap.end(); iter++){
23  delete(iter->second);
24  }
25 }
26 // ------------------------------------------------------------------------
27 
29 {
30 
31  fInputAsciiFile = new std::ifstream(fFileName.Data(), std::ifstream::in);
32  if (0 == fInputAsciiFile) {
33  Fatal("PndGiBuuGenerator", "Cannot open ASCII input file.");
34  }
35 
36  FillPidMap();
37 
38  return kTRUE;
39 }
40 
41 // ------------------------------------------------------------------------
42 
43 
44 
45 // ----- Public method ReadEvent --------------------------------------
47 {
48 
49  Int_t GiBuuPid = 0, GiBuuCharge = 0;
50  //Int_t runId = 0; //[R.K. 01/2017] unused variable?
51  Int_t motherId1 = 0;
52  Int_t motherId2 = 0;
53  Int_t dummyInt = 0;
54  Double_t mass = 0.;
55  Double_t energy = 0.;
56  Int_t oldEventNr = fEvent;
57  Int_t oldRunId = fRunId;
58 
59  Double_t dummyDouble = 0.;
60 
61  std::cout << "ReadEvent: " << fEvent << std::endl;
62 
63  if (fEvent > 0){
64  WriteoutDecayParticle(oldEventNr, oldRunId, primGen);
65  } else {
66  oldEventNr = 0;
67  oldRunId = 0;
68  fEvent = 0;
69  fRunId = 0;
70  }
71 
72  while (fEvent == oldEventNr && !(fInputAsciiFile->eof())){
73  *fInputAsciiFile >> GiBuuPid >> GiBuuCharge >> motherId1 >> motherId2 >> dummyInt >> mass >> dummyInt >> energy >> fPx >> fPy >> fPz >> dummyDouble >> fEvent >> fRunId >> dummyDouble;
74  if (0 == oldEventNr){
75  oldEventNr = fEvent;
76  oldRunId = fRunId;
77  }
78  fPdg = GetPdgParticleId(GiBuuPid, GiBuuCharge);
79  WriteoutDecayParticle(oldEventNr, oldRunId, primGen);
80  }
81 
82  return kTRUE;
83 }
84 
85 void PndGiBuuGenerator::WriteoutDecayParticle(Int_t oldEventNr, Int_t oldRunId, FairPrimaryGenerator* primGen)
86 {
87  if (fEvent == oldEventNr && fRunId == oldRunId) {
88  if (fDecayerMap.count(fPdg) > 0) {
89  std::vector<PndGiBuuTrack> tracks = fDecayerMap[fPdg]->DecayTrack(PndGiBuuTrack(fPdg, fPx, fPy, fPz, 0., 0., 0.));
90  for (size_t i = 0; i < tracks.size(); i++) {
91  std::cout << "Writing decayed particles: " << tracks[i].GetPdgId() << std::endl;
92  primGen->AddTrack(tracks[i].GetPdgId(),
93  tracks[i].GetMomentum().X(), tracks[i].GetMomentum().Y(), tracks[i].GetMomentum().Z(),
94  tracks[i].GetVertex().X(), tracks[i].GetVertex().Y(), tracks[i].GetVertex().Z());
95  }
96  } else {
97  std::cout << "Writing particle direct: " << fPdg << std::endl;
98  primGen->AddTrack(fPdg, fPx, fPy, fPz, 0., 0., 0.);
99  }
100  }
101 }
102 
104 {
105  std::ifstream* PidFile = new std::ifstream(fPidDataFileName.Data(), std::ifstream::in);
106  if (0 == PidFile){
107  Fatal("PndGiBuuGenerator::FillPidMap", "No pid file!");
108  }
109  Int_t giPid = 0;
110  Int_t giCharge = 0;
111  Int_t pdgPid = 0;
112 
113 // std::cout << "Reading In PidFile: " << fPidDataFileName.Data() << " " << PidFile << " " << PidFile->eof() << std::endl;
114 
115  while (!(PidFile->eof())){
116  *PidFile >> giPid >> giCharge >> pdgPid;
117  std::pair<Int_t, Int_t> GiBuuPid(giPid, giCharge);
118  fMapGiBuuToPdg[GiBuuPid] = pdgPid;
119 // std::cout << giPid << " " << giCharge << " = " << pdgPid << std::endl;
120  }
121  PidFile->close();
122  PidFile = 0;
123 
124 }
125 
126 Int_t PndGiBuuGenerator::GetPdgParticleId(Int_t GiBuuId, Int_t charge)
127 {
128  std::pair<Int_t, Int_t> GiBuuPid(GiBuuId, charge);
129  if (fMapGiBuuToPdg.count(GiBuuPid) > 0){
130  return fMapGiBuuToPdg[GiBuuPid];
131  } else {
132  return 0;
133  }
134 }
135 
136 // ----- Private method CloseInput ------------------------------------
138 
139  fInputAsciiFile->close();
140  //delete fInputAsciiFile;
141  fInputAsciiFile = NULL;
142 
143 }
144 // ------------------------------------------------------------------------
145 
146 
147 
TString fFileName
Run number in GiBuu.
std::map< std::pair< Int_t, Int_t >, Int_t > fMapGiBuuToPdg
Int_t i
Definition: run_full.C:25
double Y
Definition: anaLmdDigi.C:68
void CloseInput()
PDG code of particle.
FairPrimaryGenerator * primGen
Definition: sim_emc_apd.C:81
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Int_t fPdg
Momentum of particle.
Double_t
Int_t fRunId
Event number.
void WriteoutDecayParticle(Int_t oldEventNr, Int_t oldRunId, FairPrimaryGenerator *primGen)
Int_t GetPdgParticleId(Int_t GiBuuId, Int_t charge)
TString PidFile
double X
Definition: anaLmdDigi.C:68
TString fPidDataFileName
Input file name.
ClassImp(PndAnaContFact)
double Z
Definition: anaLmdDigi.C:68
std::map< Int_t, PndGiBuuDecayerAbs * > fDecayerMap
std::ifstream * fInputAsciiFile
Input Pid data file name.
Double_t energy
Definition: plot_dirc.C:15