FairRoot/PandaRoot
PndFlukaGenerator.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndFlukaGenerator source file -----
3 // -------------------------------------------------------------------------
4 
5 
6 #include <iostream>
7 #include "TClonesArray.h"
8 #include "TFile.h"
9 #include "TLorentzVector.h"
10 #include "TTree.h"
11 #include "TVector3.h"
12 #include "TParticle.h"
13 #include "PndFlukaGenerator.h"
14 #include "FairPrimaryGenerator.h"
15 
16 #include "TF1.h"
17 #include "TRandom.h"
18 
19 
20 #define MAX 200
21 
22 
23 using std::cout;
24 using std::endl;
25 //using std::max;
26 
27 
28 // ----- Default constructor ------------------------------------------
30  iEvent = 0;
31  iEntry = 0;
32  fInputRootFile = NULL;
33  fInputTree = NULL;
34 }
35 // ------------------------------------------------------------------------
36 
37 // ----- Standard constructor -----------------------------------------
38 PndFlukaGenerator::PndFlukaGenerator(const Char_t* fileName) {
39 
40  fFileName = TString(fileName);
41  Init();
42 
43 }
44 
45 // ----- Destructor ---------------------------------------------------
47  CloseInput();
48 
49 }
50 // ------------------------------------------------------------------------
51 
53 {
54  iEvent = 0;
55  iEntry = 0;
56 
57  cout << "-I PndFlukaGenerator: Opening input file " << fFileName.Data() << endl;
58 
59  // open ROOT input file
60 
61  fInputRootFile = new TFile(fFileName,"READ");
62  if (fInputRootFile->IsZombie())
63  Fatal("PndFlukaGenerator","Cannot open ROOT input file.");
64 
65  fInputTree = (TTree*) fInputRootFile->Get("ResultsTree");
66  if (!SetBranchAddresses())
67  Fatal("PndFlukaGenerator","Incompatible ROOT input file!");
68  return kTRUE;
69 }
70 
71 // ------------------------------------------------------------------------
72 
74 {
75  if (0==fInputTree) return false;
76 
77  fInputTree->SetMakeClass(1);
78 
79  fInputTree->SetBranchStatus("*",0);
80 
81  fInputTree->SetBranchStatus("Npart",1);
82  // fInputTree->SetBranchStatus("Weight",1);
83  fInputTree->SetBranchStatus("pid",1);
84  // fInputTree->SetBranchStatus("NofInt",1);
85  // fInputTree->SetBranchStatus("etot",1);
86  // fInputTree->SetBranchStatus("ptot",1);
87  fInputTree->SetBranchStatus("px",1);
88  fInputTree->SetBranchStatus("py",1);
89  fInputTree->SetBranchStatus("pz",1);
90  // fInputTree->SetBranchStatus("time",1);
91  fInputTree->SetBranchStatus("xx",1);
92  fInputTree->SetBranchStatus("yy",1);
93  fInputTree->SetBranchStatus("zz",1);
94 
95 
96  fInputTree->SetBranchAddress("Npart",&fnpart);
97  fInputTree->SetBranchAddress("pid",&fpid);
98  fInputTree->SetBranchAddress("px",&fpx);
99  fInputTree->SetBranchAddress("py",&fpy);
100  fInputTree->SetBranchAddress("pz",&fpz);
101  fInputTree->SetBranchAddress("xx",&fvx);
102  fInputTree->SetBranchAddress("yy",&fvy);
103  fInputTree->SetBranchAddress("zz",&fvz);
104 
105 
106  return true;
107 }
108 
109 // ----- Public method ReadEvent --------------------------------------
111 {
112  if ( ! fInputRootFile ) {
113  cout << "-E PndFlukaGenerator: Input ROOT file not open!" << endl;
114  return kFALSE;
115  }
116 
117  return ReadRootEvent(primGen);
118 
119 
120 }
121 
122 
123 // ------------------------------------------------------------------------
124 
126 {
127  // Check for number of events in input file
128 
129  //Int_t nentries = fInputTree->GetEntries(); //[R.K. 01/2017] unused variable?
130 
131  if ( iEntry > fInputTree->GetEntries() ) {
132  cout << "-E PndFlukaGenerator: No more events in input file!" << endl;
133  CloseInput();
134  return kFALSE;
135  }
136 
137  // preserve orginal TDirectory
138  TFile *g=gFile;
139  fInputRootFile->cd();
140  g->cd();
141 
142  Int_t evmul=0;
143 
144  do
145  {
146  fInputTree->GetEntry(iEntry);
147 
148  evmul++;
149 
150  if ( fnpart < evmul ){
151  break;
152  }
153 
154 // cout << "Pid= " << fpid << endl;
155 // cout << "momentum " << fpx << " " << fpy << " " << fpz <<endl;
156 // cout << "vertex " << fvx << " " << fvy << " " << fvz <<endl;
157 
158  primGen->AddTrack(fpid,fpx,fpy,fpz,fvx,fvy,fvz);
159 
160  iEntry++;
161 
162  } while (evmul <= fnpart);
163 
164  return kTRUE;
165 
166 }
167 
168 
169 // ----- Private method CloseInput ------------------------------------
171  if (fInputRootFile)
172  {
173  cout << "-I PndFlukaGenerator: Closing ROOT input file " << fFileName.Data() << endl;
174  fInputRootFile->Close();
175  delete fInputRootFile;
176  fInputRootFile = NULL;
177  }
178 }
179 
180 // ------------------------------------------------------------------------
181 
void CloseInput()
number of particles in event
TFile * fInputRootFile
Input file name.
Double_t fpx
Pointer to input tree.
Int_t fnpart
PDG code of particle.
TFile * g
TTree * fInputTree
Pointer to input file.
FairPrimaryGenerator * primGen
Definition: sim_emc_apd.C:81
Double_t fvx
Momentum of particle.
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Bool_t ReadRootEvent(FairPrimaryGenerator *primGen)
TString fFileName
Root tree entry number.
Int_t fpid
Start Vertex of particle.
ClassImp(PndAnaContFact)
Int_t iEntry
Event number.