Bug corrected
[u/mrichter/AliRoot.git] / HBTAN / AliHBTReaderKineTree.cxx
CommitLineData
81f7fe9f 1#include "AliHBTReaderKineTree.h"
2
81f7fe9f 3#include <TString.h>
4#include <TObjString.h>
5#include <TTree.h>
6#include <TFile.h>
7#include <TParticle.h>
8
9#include <AliRun.h>
88cb7938 10#include <AliRunLoader.h>
81f7fe9f 11#include <AliStack.h>
12#include <AliHeader.h>
13
14#include "AliHBTRun.h"
15#include "AliHBTEvent.h"
16#include "AliHBTParticle.h"
17#include "AliHBTParticleCut.h"
18
19ClassImp(AliHBTReaderKineTree)
20/**********************************************************/
88cb7938 21const TString AliHBTReaderKineTree::fgkEventFolderName("HBTReaderKineTree");
81f7fe9f 22
bed069a4 23AliHBTReaderKineTree::AliHBTReaderKineTree():
24 fFileName("galice.root"),
25 fRunLoader(0x0)
81f7fe9f 26{
bed069a4 27 //ctor
81f7fe9f 28}
bed069a4 29/**********************************************************/
81f7fe9f 30
bed069a4 31AliHBTReaderKineTree::AliHBTReaderKineTree(TString& fname):
32 fFileName(fname),
33 fRunLoader(0x0)
81f7fe9f 34{
bed069a4 35 //ctor
81f7fe9f 36}
81f7fe9f 37/**********************************************************/
bed069a4 38
39AliHBTReaderKineTree::AliHBTReaderKineTree(TObjArray* dirs,const Char_t *filename):
40 AliHBTReader(dirs),
41 fFileName(filename),
42 fRunLoader(0x0)
81f7fe9f 43{
bed069a4 44 //ctor
81f7fe9f 45}
46/**********************************************************/
47
bed069a4 48AliHBTReaderKineTree::~AliHBTReaderKineTree()
49{
50 //dtor
51 delete fRunLoader;
52}
53/**********************************************************/
81f7fe9f 54
bed069a4 55void AliHBTReaderKineTree::Rewind()
56{
57 delete fRunLoader;
58 fRunLoader = 0x0;
59 fCurrentDir = 0;
60 fNEventsRead= 0;
61}
81f7fe9f 62/**********************************************************/
bed069a4 63
64Int_t AliHBTReaderKineTree::ReadNext()
bdec021f 65{
66 //Reads Kinematics Tree
67
68 Info("Read","");
bed069a4 69 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
70 fParticlesEvent->Reset();
81f7fe9f 71
72 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
73 {
bed069a4 74 if (fRunLoader == 0x0)
75 if (OpenNextFile())
76 {
77 fCurrentDir++;
78 continue;
79 }
80
81 if (fCurrentEvent == fRunLoader->GetNumberOfEvents())
81f7fe9f 82 {
bed069a4 83 //read next directory
84 delete fRunLoader;//close current session
85 fRunLoader = 0x0;//assure pointer is null
86 fCurrentDir++;//go to next dir
87 continue;//directory counter is increased inside in case of error
81f7fe9f 88 }
bed069a4 89
90 Info("ReadNext","Reading Event %d",fCurrentEvent);
91
92 fRunLoader->GetEvent(fCurrentEvent);
81f7fe9f 93
bed069a4 94 AliStack* stack = fRunLoader->Stack();
95 if (!stack)
81f7fe9f 96 {
bed069a4 97 Error("ReadNext","Can not get stack for event %d",fCurrentEvent);
98 continue;
99 }
100 Int_t npart = stack->GetNtrack();
101 for (Int_t i = 0;i<npart; i++)
102 {
81f7fe9f 103 TParticle * p = stack->Particle(i);
88cb7938 104// if (p->GetFirstMother() >= 0) continue; do not apply with pythia etc
81f7fe9f 105
106 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
88cb7938 107 //if not take next partilce
81f7fe9f 108
8089a083 109 AliHBTParticle* part = new AliHBTParticle(*p,i);
81f7fe9f 110 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
111 //if it does not delete it and take next good track
bed069a4 112 fParticlesEvent->AddParticle(part);//put particle in event
113 }
114 Info("ReadNext","Read %d particles from event %d (event %d in dir %d).",
115 fParticlesEvent->GetNumberOfParticles(),
116 fNEventsRead,fCurrentEvent,fCurrentDir);
117
118 fCurrentEvent++;
119 fNEventsRead++;
120 return 0;
121 }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array
122
123 return 1;
81f7fe9f 124}
bed069a4 125/**********************************************************/
81f7fe9f 126
bed069a4 127Int_t AliHBTReaderKineTree::OpenNextFile()
81f7fe9f 128{
129//opens file with kine tree
bed069a4 130 Info("OpenNextFile","________________________________________________________");
131
132 const TString& dirname = GetDirName(fCurrentEvent);
81f7fe9f 133 if (dirname == "")
134 {
bed069a4 135 Error("OpenNextFile","Can not get directory name");
136 return 1;
81f7fe9f 137 }
138 TString filename = dirname +"/"+ fFileName;
88cb7938 139
bed069a4 140 fRunLoader = AliRunLoader::Open(filename.Data(),fgkEventFolderName,"READ");
81f7fe9f 141
bed069a4 142 if ( fRunLoader == 0x0)
81f7fe9f 143 {
bed069a4 144 Error("OpenNextFile","Can't open session from file %s",filename.Data());
81f7fe9f 145 return 0x0;
146 }
bed069a4 147
148 if (fRunLoader->GetNumberOfEvents() <= 0)
149 {
150 Error("OpenNextFile","There is no events in this directory.");
151 delete fRunLoader;
152 fRunLoader = 0x0;
153 return 1;
154 }
155
156 if (fRunLoader->LoadKinematics())
157 {
158 Error("OpenNextFile","Error occured while loading kinematics.");
159 return 1;
160 }
161
162 fCurrentEvent = 0;
163 return 0;
81f7fe9f 164}