]>
Commit | Line | Data |
---|---|---|
1 | #include "AliReaderKineTree.h" | |
2 | //_______________________________________________________________________ | |
3 | ///////////////////////////////////////////////////////////////////////// | |
4 | // | |
5 | // class AliReaderKineTree | |
6 | // | |
7 | // Reader for Kinematics | |
8 | // | |
9 | // Piotr.Skowronski@cern.ch | |
10 | // | |
11 | ///////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | #include <TString.h> | |
14 | #include <TParticle.h> | |
15 | ||
16 | #include <AliRunLoader.h> | |
17 | #include <AliStack.h> | |
18 | ||
19 | #include "AliAOD.h" | |
20 | #include "AliAODParticle.h" | |
21 | ||
22 | ClassImp(AliReaderKineTree) | |
23 | /**********************************************************/ | |
24 | const TString AliReaderKineTree::fgkEventFolderName("ReaderKineTree"); | |
25 | ||
26 | AliReaderKineTree::AliReaderKineTree(): | |
27 | fFileName("galice.root"), | |
28 | fRunLoader(0x0) | |
29 | { | |
30 | //ctor | |
31 | } | |
32 | /**********************************************************/ | |
33 | ||
34 | AliReaderKineTree::AliReaderKineTree(TString& fname): | |
35 | fFileName(fname), | |
36 | fRunLoader(0x0) | |
37 | { | |
38 | //ctor | |
39 | } | |
40 | /**********************************************************/ | |
41 | ||
42 | AliReaderKineTree::AliReaderKineTree(TObjArray* dirs,const Char_t *filename): | |
43 | AliReader(dirs), | |
44 | fFileName(filename), | |
45 | fRunLoader(0x0) | |
46 | { | |
47 | //ctor | |
48 | } | |
49 | ||
50 | /**********************************************************/ | |
51 | AliReaderKineTree::AliReaderKineTree(const AliReaderKineTree& in): | |
52 | AliReader(in), | |
53 | fFileName(in.fFileName), | |
54 | fRunLoader(0x0) | |
55 | { | |
56 | //cpy ctor | |
57 | } | |
58 | ||
59 | /**********************************************************/ | |
60 | ||
61 | AliReaderKineTree::~AliReaderKineTree() | |
62 | { | |
63 | //dtor | |
64 | delete fRunLoader; | |
65 | } | |
66 | /**********************************************************/ | |
67 | AliReaderKineTree& AliReaderKineTree::operator=(const AliReaderKineTree& in) | |
68 | { | |
69 | //Assiment operator | |
70 | if (this == &in) return *this; | |
71 | AliReader::operator=(in); | |
72 | delete fRunLoader; | |
73 | fRunLoader = 0x0; | |
74 | return * this; | |
75 | } | |
76 | /**********************************************************/ | |
77 | ||
78 | void AliReaderKineTree::Rewind() | |
79 | { | |
80 | //Rewinds to the beginning | |
81 | delete fRunLoader; | |
82 | fRunLoader = 0x0; | |
83 | fCurrentDir = 0; | |
84 | fNEventsRead= 0; | |
85 | } | |
86 | /**********************************************************/ | |
87 | ||
88 | Int_t AliReaderKineTree::ReadNext() | |
89 | { | |
90 | //Reads Kinematics Tree | |
91 | ||
92 | Info("Read",""); | |
93 | if (fEventSim == 0x0) | |
94 | { | |
95 | fEventSim = new AliAOD(); | |
96 | } | |
97 | fEventSim->Reset(); | |
98 | ||
99 | do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./" | |
100 | { | |
101 | if (fRunLoader == 0x0) | |
102 | if (OpenNextFile()) | |
103 | { | |
104 | fCurrentDir++; | |
105 | continue; | |
106 | } | |
107 | ||
108 | if (fCurrentEvent == fRunLoader->GetNumberOfEvents()) | |
109 | { | |
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 | |
115 | } | |
116 | ||
117 | Info("ReadNext","Reading Event %d",fCurrentEvent); | |
118 | ||
119 | fRunLoader->GetEvent(fCurrentEvent); | |
120 | ||
121 | AliStack* stack = fRunLoader->Stack(); | |
122 | if (!stack) | |
123 | { | |
124 | Error("ReadNext","Can not get stack for event %d",fCurrentEvent); | |
125 | continue; | |
126 | } | |
127 | Int_t npart = stack->GetNtrack(); | |
128 | for (Int_t i = 0;i<npart; i++) | |
129 | { | |
130 | TParticle * p = stack->Particle(i); | |
131 | // if (p->GetFirstMother() >= 0) continue; do not apply with pythia etc | |
132 | ||
133 | if(Rejected(p->GetPdgCode())) continue; //check if we are intersted with particles of this type | |
134 | //if not take next partilce | |
135 | ||
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 | |
140 | } | |
141 | Info("ReadNext","Read %d particles from event %d (event %d in dir %d).", | |
142 | fEventSim->GetNumberOfParticles(), | |
143 | fNEventsRead,fCurrentEvent,fCurrentDir); | |
144 | ||
145 | fCurrentEvent++; | |
146 | fNEventsRead++; | |
147 | return 0; | |
148 | }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array | |
149 | ||
150 | return 1; | |
151 | } | |
152 | /**********************************************************/ | |
153 | ||
154 | Int_t AliReaderKineTree::OpenNextFile() | |
155 | { | |
156 | //opens file with kine tree | |
157 | Info("OpenNextFile","________________________________________________________"); | |
158 | ||
159 | const TString& dirname = GetDirName(fCurrentDir); | |
160 | if (dirname == "") | |
161 | { | |
162 | Error("OpenNextFile","Can not get directory name"); | |
163 | return 1; | |
164 | } | |
165 | TString filename = dirname +"/"+ fFileName; | |
166 | ||
167 | fRunLoader = AliRunLoader::Open(filename.Data(),fgkEventFolderName,"READ"); | |
168 | ||
169 | if ( fRunLoader == 0x0) | |
170 | { | |
171 | Error("OpenNextFile","Can't open session from file %s",filename.Data()); | |
172 | return 1; | |
173 | } | |
174 | ||
175 | if (fRunLoader->GetNumberOfEvents() <= 0) | |
176 | { | |
177 | Error("OpenNextFile","There is no events in this directory."); | |
178 | delete fRunLoader; | |
179 | fRunLoader = 0x0; | |
180 | return 2; | |
181 | } | |
182 | ||
183 | if (fRunLoader->LoadKinematics()) | |
184 | { | |
185 | Error("OpenNextFile","Error occured while loading kinematics."); | |
186 | return 3; | |
187 | } | |
188 | ||
189 | fCurrentEvent = 0; | |
190 | return 0; | |
191 | } |