Added Hijing vars.
[u/mrichter/AliRoot.git] / JETAN / AliJetParticlesReaderKine.cxx
CommitLineData
d7c6ab14 1// $Id$
2
3//_______________________________________________________________________
4/////////////////////////////////////////////////////////////////////////
5//
6// class AliJetParticlesReaderKine
7//
8// Reader for Kinematics
9//
10// loizides@ikf.uni-frankfurt.de
11//
12/////////////////////////////////////////////////////////////////////////
13
14#include <Riostream.h>
15#include <TString.h>
16#include <TParticle.h>
17#include <AliRunLoader.h>
18#include <AliStack.h>
19
20#include "AliJetParticle.h"
21#include "AliJetEventParticles.h"
22#include "AliJetParticlesReaderKine.h"
04a02430 23#include "AliHeader.h"
24#include "AliGenPythiaEventHeader.h"
d7c6ab14 25
26ClassImp(AliJetParticlesReaderKine)
27
d7c6ab14 28AliJetParticlesReaderKine::AliJetParticlesReaderKine() :
29 AliJetParticlesReader(),
30 fFileName("galice.root"),
31 fRunLoader(0),
32 fNeutral(kTRUE),fCharged(kTRUE),fEM(kTRUE),
33 fUseTracks(kFALSE)
34{
35 //constructor
36}
37
d7c6ab14 38AliJetParticlesReaderKine::AliJetParticlesReaderKine(TString& fname) :
39 AliJetParticlesReader(),
40 fFileName(fname),
41 fRunLoader(0),
42 fNeutral(kTRUE),fCharged(kTRUE),fEM(kTRUE),
43 fUseTracks(kFALSE)
44{
45 //constructor
46}
47
d7c6ab14 48AliJetParticlesReaderKine::AliJetParticlesReaderKine(TObjArray* dirs, const Char_t *filename):
49 AliJetParticlesReader(dirs),
50 fFileName(filename),
51 fRunLoader(0),
52 fNeutral(kTRUE),fCharged(kTRUE),fEM(kTRUE),
53 fUseTracks(kFALSE)
54{
55 //constructor
56}
57
d7c6ab14 58AliJetParticlesReaderKine::~AliJetParticlesReaderKine()
59{
60 //destructor
61 if(fRunLoader) delete fRunLoader;
62}
63
d7c6ab14 64void AliJetParticlesReaderKine::Rewind()
65{
66 //Rewinds to the beginning
67 if(fRunLoader) delete fRunLoader;
04a02430 68 fRunLoader = 0;
69 fCurrentDir = 0;
70 fNEventsRead = 0;
d7c6ab14 71}
72
d7c6ab14 73Int_t AliJetParticlesReaderKine::ReadNext()
74{
75 //Reads Kinematics Tree
76
77 if((!fOwner) || (fEventParticles == 0))
78 fEventParticles = new AliJetEventParticles();
79
b2760c9e 80 while(fCurrentDir < GetNumberOfDirs())
d7c6ab14 81 {
04a02430 82
83 if (!OpenFile(fCurrentDir))
d7c6ab14 84 {
04a02430 85 delete fRunLoader; //close current session
86 fRunLoader = 0; //assure pointer is null
d7c6ab14 87 fCurrentDir++;
88 continue;
89 }
90
91 if (fCurrentEvent == fRunLoader->GetNumberOfEvents())
92 {
93 //read next directory
94 delete fRunLoader; //close current session
95 fRunLoader = 0; //assure pointer is null
96 fCurrentDir++; //go to next dir
97 continue;
98 }
99
04a02430 100 Info("ReadNext","Reading Event %d",fCurrentEvent);
d7c6ab14 101 fRunLoader->GetEvent(fCurrentEvent);
102 AliStack* stack = fRunLoader->Stack();
103 if (!stack)
104 {
04a02430 105 Error("ReadNext","Can't get stack for event %d",fCurrentEvent);
d7c6ab14 106 continue;
107 }
108
04a02430 109 //clear old event
110 Int_t nprim = stack->GetNprimary();
111 Int_t npart = nprim;
112 if(fUseTracks)
113 npart = stack->GetNtrack();
114 fEventParticles->Reset(npart);
115
116 TString headdesc="";
117 AliHeader *header=fRunLoader->GetHeader();
118 if(!header) {
119 Warning("ReadNext","Header not found in event %d",fCurrentEvent);
120 } else {
121 headdesc+="Run ";
122 headdesc+=header->GetRun();
123 headdesc+=": Ev ";
124 headdesc+=header->GetEventNrInRun();
125 AliGenPythiaEventHeader *pheader=(AliGenPythiaEventHeader*)header->GenEventHeader();
126 if(!pheader) {
127 Warning("ReadNext","Pythia-Header not found in event %d",fCurrentEvent);
128 } else {
042d3031 129 Int_t ntruq=0;
130#ifndef NOUQHEADERINFO
131 ntruq=pheader->NUQTriggerJets();
04a02430 132 if(ntruq){
133 Double_t x0=pheader->GetXJet();
134 Double_t y0=pheader->GetYJet();
135 Double_t zquench[4];
136 pheader->GetZQuench(zquench);
137 fEventParticles->SetXYJet(x0,y0);
138 fEventParticles->SetZQuench(zquench);
139 for(Int_t j=0;j<ntruq;j++){
140 Float_t pjet[4];
141 pheader->UQJet(j,pjet);
142 fEventParticles->AddUQJet(pjet);
143 }
144 }
042d3031 145#endif
04a02430 146 //Int_t ptyp=pheader->ProcessType();
147 Int_t ntrials=pheader->Trials();
148 headdesc+=": Tr ";
149 headdesc+=ntrials;
150 Int_t ntr=pheader->NTriggerJets();
151 if(ntr){
152 for(Int_t j=0;j<ntr;j++){
153 Float_t pjet[4];
154 pheader->TriggerJet(j,pjet);
155 fEventParticles->AddJet(pjet);
156 if(!ntruq) fEventParticles->AddUQJet(pjet);
157 }
158 }
159 }
160 }
161 fEventParticles->SetHeader(headdesc);
162
d7c6ab14 163 //get vertex
164 const TParticle *kv = stack->Particle(0);
165 if(kv) {
166 fEventParticles->SetVertex(kv->Vx(),kv->Vy(),kv->Vz());
167 }
168
04a02430 169 //loop over particles
d7c6ab14 170 for (Int_t i = 0;i<npart; i++)
171 {
172 TParticle *p = stack->Particle(i);
173 if(!p) continue;
b2760c9e 174 Int_t child1 = p->GetFirstDaughter();
175 //Int_t child2 = p->GetLastDaughter();
176 //Int_t mother = p->GetFirstMother();
b2760c9e 177 //cout << child1 << " " << child2 << " " << mother << endl;
04a02430 178 if((child1>=0) && (child1<nprim)) continue;
179 if(p->GetStatusCode()!=1){
180 //p->Print();
181 continue;
182 }
d7c6ab14 183 if(IsAcceptedParticle(p)) //put particle in event
184 fEventParticles->AddParticle(p,i);
185 }
d7c6ab14 186 fCurrentEvent++;
187 fNEventsRead++;
188 return kTRUE;
b2760c9e 189 }
04a02430 190
191 //end of loop over directories specified in fDirs ObjArray
d7c6ab14 192 return kFALSE;
193}
194
d7c6ab14 195Int_t AliJetParticlesReaderKine::OpenFile(Int_t n)
196{
197 //opens file with kine tree
198
04a02430 199 if(fRunLoader){
200 if(fCurrentEvent < fRunLoader->GetNumberOfEvents()) return kTRUE;
201 else return kFALSE;
202 }
203
d7c6ab14 204 const TString& dirname = GetDirName(n);
205 if (dirname == "")
206 {
04a02430 207 Error("OpenNextFile","Can't get directory name with index %d",n);
d7c6ab14 208 return kFALSE;
209 }
210
211 TString filename = dirname +"/"+ fFileName;
212 fRunLoader = AliRunLoader::Open(filename.Data());
213
214 if (fRunLoader == 0)
215 {
216 Error("OpenNextFile","Can't open session from file %s",filename.Data());
217 return kFALSE;
218 }
219
220 if (fRunLoader->GetNumberOfEvents() <= 0)
221 {
222 Error("OpenNextFile","There is no events in this directory.");
223 delete fRunLoader;
224 fRunLoader = 0;
225 return kFALSE;
226 }
04a02430 227
d7c6ab14 228 if (fRunLoader->LoadKinematics())
229 {
230 Error("OpenNextFile","Error occured while loading kinematics.");
231 return kFALSE;
232 }
04a02430 233
d7c6ab14 234 fCurrentEvent = 0;
235 return kTRUE;
236}