1 #include "AliReaderKineTree.h"
2 //_______________________________________________________________________
3 /////////////////////////////////////////////////////////////////////////
5 // class AliReaderKineTree
7 // Reader for Kinematics
9 // Piotr.Skowronski@cern.ch
11 /////////////////////////////////////////////////////////////////////////
14 #include <TParticle.h>
16 #include <AliRunLoader.h>
20 #include "AliAODParticle.h"
22 ClassImp(AliReaderKineTree)
23 /**********************************************************/
24 const TString AliReaderKineTree::fgkEventFolderName("ReaderKineTree");
26 AliReaderKineTree::AliReaderKineTree():
27 fFileName("galice.root"),
32 /**********************************************************/
34 AliReaderKineTree::AliReaderKineTree(TString& fname):
40 /**********************************************************/
42 AliReaderKineTree::AliReaderKineTree(TObjArray* dirs,const Char_t *filename):
50 /**********************************************************/
51 AliReaderKineTree::AliReaderKineTree(const AliReaderKineTree& in):
53 fFileName(in.fFileName),
59 /**********************************************************/
61 AliReaderKineTree::~AliReaderKineTree()
66 /**********************************************************/
67 AliReaderKineTree& AliReaderKineTree::operator=(const AliReaderKineTree& in)
70 if (this == &in) return *this;
71 AliReader::operator=(in);
76 /**********************************************************/
78 void AliReaderKineTree::Rewind()
80 //Rewinds to the beginning
86 /**********************************************************/
88 Int_t AliReaderKineTree::ReadNext()
90 //Reads Kinematics Tree
95 fEventSim = new AliAOD();
99 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
101 if (fRunLoader == 0x0)
108 if (fCurrentEvent == fRunLoader->GetNumberOfEvents())
110 //read next directory
111 delete fRunLoader;//close current session
112 fRunLoader = 0x0;//assure pointer is null
113 fCurrentDir++;//go to next dir
114 continue;//directory counter is increased inside in case of error
117 Info("ReadNext","Reading Event %d",fCurrentEvent);
119 fRunLoader->GetEvent(fCurrentEvent);
121 AliStack* stack = fRunLoader->Stack();
124 Error("ReadNext","Can not get stack for event %d",fCurrentEvent);
127 Int_t npart = stack->GetNtrack();
128 for (Int_t i = 0;i<npart; i++)
130 TParticle * p = stack->Particle(i);
131 // if (p->GetFirstMother() >= 0) continue; do not apply with pythia etc
133 if(Rejected(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
134 //if not take next partilce
136 AliAODParticle* part = new AliAODParticle(*p,i);
137 if(Rejected(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
138 //if it does not delete it and take next good track
139 fEventSim->AddParticle(part);//put particle in event
141 Info("ReadNext","Read %d particles from event %d (event %d in dir %d).",
142 fEventSim->GetNumberOfParticles(),
143 fNEventsRead,fCurrentEvent,fCurrentDir);
148 }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array
152 /**********************************************************/
154 Int_t AliReaderKineTree::OpenNextFile()
156 //opens file with kine tree
157 Info("OpenNextFile","________________________________________________________");
159 const TString& dirname = GetDirName(fCurrentDir);
162 Error("OpenNextFile","Can not get directory name");
165 TString filename = dirname +"/"+ fFileName;
167 fRunLoader = AliRunLoader::Open(filename.Data(),fgkEventFolderName,"READ");
169 if ( fRunLoader == 0x0)
171 Error("OpenNextFile","Can't open session from file %s",filename.Data());
175 if (fRunLoader->GetNumberOfEvents() <= 0)
177 Error("OpenNextFile","There is no events in this directory.");
183 if (fRunLoader->LoadKinematics())
185 Error("OpenNextFile","Error occured while loading kinematics.");