EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicEventGenerator.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicEventGenerator.h
1 //
2 // AYK (ayk@bnl.gov), 2013/06/12
3 //
4 // Interface to eic-smear import classes;
5 //
6 
7 #include <assert.h>
8 
9 #include <set>
10 
11 #ifndef _EIC_EVENT_GENERATOR_
12 #define _EIC_EVENT_GENERATOR_
13 
14 #include <TChain.h>
15 #include <TH1D.h>
16 
17 #include "FairGenerator.h"
18 #include "FairTask.h"
19 
22 
23 // Of course want to use eic-smear code conventions on the tree/branch names;
24 #define _EIC_GENERATOR_TREE_ "EICTree"
25 #define _EIC_GENERATOR_EVENT_BRANCH_ "event"
26 
27 // Basically describes which entries in the original ParticleMC array made
28 // it into the GEANT input table for tracking;
29 #define _EIC_MAPPING_BRANCH_ "ParticleMap"
30 
32 class TBranch;
33 
34 class ProMCBook;
35 
36 namespace EicMC {
37  class Reader;
38 }
39 
40 // erhic::EventMC has a pure virtual member -> have to create
41 // inherited class in order to instantiate it;
43 {
44  public:
45  EventProMC() {};
47 
48  // FIXME: for now can not get these from the ProMC Pythia 8 pp-files;
49  const erhic::ParticleMC* BeamLepton() const { return 0; };
50  const erhic::ParticleMC* BeamHadron() const { return 0; };
51  const erhic::ParticleMC* ExchangeBoson() const { return 0; };
52  const erhic::ParticleMC* ScatteredLepton() const { return 0; };
53 
54  // There is no parser either (but have to create implementation of this
55  // pure virtual member);
56  bool Parse(const std::string&) { assert(0); return false; };
57 
58  ClassDef(EventProMC, 1);
59 };
60 
61 // Same story; THINK: do I really need these complications for EicMC input?;
63 {
64  public:
65  EventEicMC() {};
67 
68  // FIXME: add proper calls here, please;
69  const erhic::ParticleMC* BeamLepton() const { return 0; };
70  const erhic::ParticleMC* BeamHadron() const { return 0; };
71  const erhic::ParticleMC* ExchangeBoson() const { return 0; };
72  const erhic::ParticleMC* ScatteredLepton() const { return 0; };
73 
74  // There is no parser either (but have to create implementation of this
75  // pure virtual member);
76  bool Parse(const std::string&) { assert(0); return false; };
77 
78  ClassDef(EventEicMC, 1);
79 };
80 
81 //
82 // Want to access protected variables in Forester class, but
83 // can not just use it as a base class in EicEventGenerator because
84 // of ambiguos inheritance of TObject; so create an intermediate
85 // class and be happy; actually the functionality matches the name;
86 //
87 class Poacher: public erhic::Forester
88 {
89  public:
91  Poacher(const TString &fileName);
92 
93  ~Poacher() {};
94 
96 
97  std::string EventName() const;
98 
99  private:
100  // Part related to ProMC input;
101  ProMCBook *mProMCBook;
105 
106  // Part related to EicMC input;
108  EicMC::Reader *mReaderEicMC;
109 
110  void ResetProMC() {
111  mProMCBook = 0;
112  mEventProMC = 0;
114  };
115  void ResetEicMC() {
116  mReaderEicMC = 0;
117  mEventEicMC = 0;
118  };
119 
120  ClassDef(Poacher,3);
121 };
122 
124  // Avoid the access complications;
125  friend class EicEventGenerator;
126 
127  public:
130 
131  const std::vector<unsigned> &GetData() const { return mData; };
132 
133  private:
134  std::vector <unsigned> mData;
135 
137 };
138 
139 // FIXME: create a separate EicProtoGenerator.h file;
140 #include <EicBoxGenerator.h>
141 
143 {
144  friend class EicEventGeneratorTask;
145 
146  public:
148  //EicEventGenerator(): FairGenerator() { ResetVars(); };
149 
153  EicEventGenerator(TString fileName = "");
154 
156  virtual ~EicEventGenerator() {};
157 
158  // Singelton instance get method;
159  static EicEventGenerator* Instance() { return mInstance; };
160 
161  // Well, may want to use the same input file to be processed in chunks
162  // in a batch mode; FairRunSim class does not seem to provide functionality
163  // to skip events, so implement this feature here;
164  int SkipFewEvents(unsigned eventsToSkip);
166 
167  // May want to select only few particle types; can call more than once
168  // (say enable only electrons and pi-minus tracks);
169  void SelectPdgCode(int pdg) { mSelectedPdgCodes.insert(pdg); };
170  void SelectLeadingParticle(double pmin = 0.0) {
171  mSelectLeadingParticle = true;
173  };
174 
175  void BuildEnergyFlowPlot(int etaBinNum, double etaMin, double etaMax) {
176  mEnergyFlowHist = new TH1D("EnergyFlowPlot", "Energy Flow Plot", etaBinNum, etaMin, etaMax);
177  mEnergyFlowHist->GetXaxis()->SetTitle("Pseudorapidity");
178  mEnergyFlowHist->GetYaxis()->SetTitle("Energy flow per rapidity unit per event, [GeV]");
179 
180  mParticleCountHist = new TH1D("ParticleCountPlot", "Particle Count Plot", etaBinNum, etaMin, etaMax);
181  mParticleCountHist->GetXaxis()->SetTitle("Pseudorapidity");
182  mParticleCountHist->GetYaxis()->SetTitle("Particle count per rapidity unit per event");
183 
184  // FIXME: some sanity check needed here;
185  mEtaBinWidth = (etaMax - etaMin)/etaBinNum;
186  };
187  void AddEnergyFlowPdgCode(int pdg) { mEnergyFlowPdgCodes.insert(pdg); };
188 
193  virtual Bool_t ReadEvent(FairPrimaryGenerator* primGen);
194 
195  const TChain *GetInputTree() const { return mInputTree; };
196 
197  private:
198  static EicEventGenerator *mInstance;
199 
201  TChain *mInputTree;
204 
205  // Do not want to rely on "vp->GetStatus() == 1" check when passing data
206  // over to the GEANT engine; just record the exact list of particles which
207  // will enter PndMCTrack array and import it back during the reconstruction;
209 
210  Bool_t mSelectLeadingParticle; // may want to select leading particles only ...
211  Double_t mSelectedLeadingParticlePmin; // ... and with a momentum cut-off
212  std::set<Int_t> mSelectedPdgCodes; // if empty, all particles; otherwise selected only
213 
214  // May want to carve a huge input file into several chunks to be processed by different
215  // batch jobs; SkipFewEvents() helps to arrange a jump, fine; however, since ReadEvent() may
216  // want to skip several events (because there are no particles left after SelectPdgCode()
217  // call(s)), one needs to restrict max event chunk to consider in order not to grab events
218  // from the "next chunk";
219  UInt_t mEventChunkSize; // consider at most that number of event candidates
220  UInt_t mEventCounter; // internal counter which helps to obey mEventChunkSize limit
221 
222  double mEtaBinWidth;
225  std::set<Int_t> mEnergyFlowPdgCodes;
226 
227  void ResetVars() {
228  mPoacher = 0;
229  mGeneratorEvent = 0;
231 
234 
235  mEtaBinWidth = 0.0;
237  };
238 
240 };
241 
243  public:
244  EicEventGeneratorTask(TTree* tree = 0): mOutputTree(tree) {};
246 
247  // The only method I need here;
248  void FinishTask();
249 
250  private:
251  TTree* mOutputTree;
252 
254 };
255 
256 #endif