81f7fe9f |
1 | #include "AliHBTReaderKineTree.h" |
2 | |
d0c23b58 |
3 | #include <Riostream.h> |
81f7fe9f |
4 | #include <TString.h> |
5 | #include <TObjString.h> |
6 | #include <TTree.h> |
7 | #include <TFile.h> |
8 | #include <TParticle.h> |
9 | |
10 | #include <AliRun.h> |
88cb7938 |
11 | #include <AliRunLoader.h> |
81f7fe9f |
12 | #include <AliStack.h> |
13 | #include <AliHeader.h> |
14 | |
15 | #include "AliHBTRun.h" |
16 | #include "AliHBTEvent.h" |
17 | #include "AliHBTParticle.h" |
18 | #include "AliHBTParticleCut.h" |
19 | |
20 | ClassImp(AliHBTReaderKineTree) |
21 | /**********************************************************/ |
88cb7938 |
22 | const TString AliHBTReaderKineTree::fgkEventFolderName("HBTReaderKineTree"); |
81f7fe9f |
23 | |
88cb7938 |
24 | AliHBTReaderKineTree::AliHBTReaderKineTree():fFileName("galice.root") |
81f7fe9f |
25 | { |
26 | fParticles = new AliHBTRun(); |
27 | fIsRead = kFALSE; |
28 | } |
29 | |
30 | AliHBTReaderKineTree:: |
31 | AliHBTReaderKineTree(TString& fname):fFileName(fname) |
32 | { |
33 | fParticles = new AliHBTRun(); |
34 | fIsRead = kFALSE; |
35 | } |
36 | |
37 | |
38 | /**********************************************************/ |
39 | AliHBTReaderKineTree:: |
40 | AliHBTReaderKineTree(TObjArray* dirs,const Char_t *filename):AliHBTReader(dirs),fFileName(filename) |
41 | { |
42 | fParticles = new AliHBTRun(); |
43 | fIsRead = kFALSE; |
44 | } |
45 | /**********************************************************/ |
46 | |
47 | AliHBTEvent* AliHBTReaderKineTree::GetParticleEvent(Int_t n) |
48 | { |
49 | //returns Nth event with simulated particles |
50 | if (!fIsRead) |
51 | if(Read(fParticles,0x0)) |
52 | { |
53 | Error("GetParticleEvent","Error in reading"); |
54 | return 0x0; |
55 | } |
56 | |
57 | return fParticles->GetEvent(n); |
58 | } |
59 | |
60 | /********************************************************************/ |
61 | |
62 | Int_t AliHBTReaderKineTree::GetNumberOfPartEvents() |
63 | { |
64 | //returns number of events of particles |
65 | if (!fIsRead) |
66 | if(Read(fParticles,0x0)) |
67 | { |
68 | Error("GetNumberOfPartEvents","Error in reading"); |
69 | return 0; |
70 | } |
71 | return fParticles->GetNumberOfEvents(); |
72 | } |
73 | |
74 | |
75 | /**********************************************************/ |
bdec021f |
76 | Int_t AliHBTReaderKineTree::Read(AliHBTRun* particles, AliHBTRun* /*tracks*/) |
77 | { |
78 | //Reads Kinematics Tree |
79 | |
80 | Info("Read",""); |
81 | |
81f7fe9f |
82 | if (!particles) //check if an object is instatiated |
83 | { |
84 | Error("Read"," particles object must instatiated before passing it to the reader"); |
85 | return 1; |
86 | } |
87 | particles->Reset();//clear runs == delete all old events |
88 | |
89 | Int_t Ndirs;//total number of directories specified in fDirs array |
90 | Int_t Nevents; //number of events read in current directory |
91 | Int_t totalNevents = 0; //total number of read events |
92 | Int_t currentdir = 0; //number of current directory name is fDirs array |
93 | |
94 | if (fDirs) //if array with directories is supplied by user |
95 | { |
96 | Ndirs = fDirs->GetEntries(); //get the number if directories |
97 | } |
98 | else |
99 | { |
100 | Ndirs = 0; //if the array is not supplied read only from current directory |
101 | } |
102 | |
103 | do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./" |
104 | { |
bdec021f |
105 | Info("Read","________________________________________________________"); |
88cb7938 |
106 | AliRunLoader * rl = OpenFile(currentdir); |
107 | |
108 | if (rl == 0x0) |
81f7fe9f |
109 | { |
88cb7938 |
110 | Error("Read","Cannot open session"); |
111 | return 2; |
81f7fe9f |
112 | } |
88cb7938 |
113 | rl->LoadHeader(); |
114 | rl->LoadKinematics("READ"); |
115 | Nevents = rl->GetNumberOfEvents(); |
81f7fe9f |
116 | |
117 | for(Int_t currentEvent =0; currentEvent<Nevents;currentEvent++)//loop over all events |
118 | { |
119 | // cout<<"processing event "<<currentEvent<<" in current dir."<<endl; |
88cb7938 |
120 | rl->GetEvent(currentEvent); |
121 | AliStack* stack = rl->Stack(); |
81f7fe9f |
122 | if (!stack) |
123 | { |
124 | Error("Read","Can not get stack for event %d",currentEvent); |
125 | continue; |
126 | } |
127 | Int_t npart = stack->GetNtrack(); |
128 | Int_t nnn = 0; |
129 | for (Int_t i = 0;i<npart; i++) |
130 | { |
131 | |
132 | TParticle * p = stack->Particle(i); |
88cb7938 |
133 | // if (p->GetFirstMother() >= 0) continue; do not apply with pythia etc |
81f7fe9f |
134 | |
135 | if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type |
88cb7938 |
136 | //if not take next partilce |
81f7fe9f |
137 | |
8089a083 |
138 | AliHBTParticle* part = new AliHBTParticle(*p,i); |
81f7fe9f |
139 | if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts |
140 | //if it does not delete it and take next good track |
141 | particles->AddParticle(totalNevents,part);//put track and particle on the run |
142 | |
143 | if ( (nnn%100) == 0) |
144 | { |
145 | cout<<nnn<<"\r"; |
146 | fflush(0); |
147 | } |
148 | nnn++; |
149 | } |
bdec021f |
150 | Info("Read","Total read %d",nnn); |
81f7fe9f |
151 | totalNevents++; |
152 | } |
88cb7938 |
153 | delete rl; |
154 | currentdir++; |
81f7fe9f |
155 | }while(currentdir < Ndirs);//end of loop over directories specified in fDirs Obj Array |
156 | fIsRead = kTRUE; |
157 | return 0; |
158 | } |
159 | |
88cb7938 |
160 | AliRunLoader* AliHBTReaderKineTree::OpenFile(Int_t n) |
81f7fe9f |
161 | { |
162 | //opens file with kine tree |
163 | |
164 | const TString& dirname = GetDirName(n); |
165 | if (dirname == "") |
166 | { |
167 | Error("OpenFiles","Can not get directory name"); |
168 | return 0x0; |
169 | } |
170 | TString filename = dirname +"/"+ fFileName; |
88cb7938 |
171 | |
172 | AliRunLoader *ret = AliRunLoader::Open(filename.Data(),fgkEventFolderName,"READ"); |
81f7fe9f |
173 | |
174 | if ( ret == 0x0) |
175 | { |
88cb7938 |
176 | Error("OpenFiles","Can't open session from file %s",filename.Data()); |
81f7fe9f |
177 | return 0x0; |
178 | } |
179 | |
180 | return ret; |
181 | } |