008ac94c |
1 | /************************************************************************** |
2 | * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. * |
3 | * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for * |
4 | * full copyright notice. * |
5 | **************************************************************************/ |
6 | |
7 | /////////////////////////////////////////////////////////////////////////// |
8 | // |
9 | // Finds events according to specified criteria |
10 | // |
11 | // origin: Mikolaj Krzewicki, mikolaj.krzewicki@cern.ch |
12 | // |
13 | ////////////////////////////////////////////////////////////////////////// |
14 | |
15 | #include "AliEveEventSelector.h" |
16 | #include "AliEveEventManager.h" |
17 | #include "AliESD.h" |
18 | #include "AliESDEvent.h" |
19 | #include "AliESDRun.h" |
20 | #include <TEntryList.h> |
21 | #include <TDirectory.h> |
22 | #include <TTree.h> |
23 | #include <TObjArray.h> |
24 | #include <TRegexp.h> |
25 | #include <TROOT.h> |
26 | |
27 | ClassImp(AliEveEventSelector) |
28 | |
29 | //_____________________________________________________________________________ |
30 | AliEveEventSelector::AliEveEventSelector(AliEveEventManager* evman): |
31 | fPEventManager(evman), |
32 | fWrapAround(kTRUE), |
33 | fMaxEventId(fPEventManager->GetMaxEventId()), |
34 | fSelectOnString(kFALSE), |
35 | fString(""), |
36 | fPEntryList(NULL), |
37 | fEntryListId(0), |
38 | fSelectOnTriggerType(kFALSE), |
39 | fTriggerType(""), |
40 | fSelectOnTriggerString(kFALSE), |
41 | fTriggerSelectionString(""), |
42 | fTriggerMaskPatternString("trgmask"), |
43 | fSelectOnMultiplicity(kFALSE), |
44 | fMultiplicityLow(0), |
45 | fMultiplicityHigh(0) |
46 | { |
47 | //ctor |
48 | } |
49 | |
50 | //_____________________________________________________________________________ |
51 | void AliEveEventSelector::SetSelectionString( const TString& str ) |
52 | { |
53 | //selection string setter |
54 | |
55 | TTree* pESDTree = fPEventManager->GetESDTree(); |
56 | if (!pESDTree || fString==str) return;//don't waist time |
57 | fString = str; |
58 | if (str == "" ) return;//on reset don't recalculate |
59 | fMaxEventId = fPEventManager->GetMaxEventId(); |
60 | pESDTree->Draw( ">>listofentries", fString, "entrylist"); |
61 | fPEntryList = dynamic_cast<TEntryList*>(gDirectory->Get("listofentries")); |
62 | } |
63 | |
64 | //_____________________________________________________________________________ |
65 | void AliEveEventSelector::SetSelectionString( const char* str ) |
66 | { |
67 | TString ts = str; |
68 | SetSelectionString(ts); |
69 | } |
70 | |
71 | //_____________________________________________________________________________ |
72 | void AliEveEventSelector::SetTriggerType( const TString& type ) |
73 | { |
74 | fTriggerType = type; |
75 | } |
76 | |
77 | //_____________________________________________________________________________ |
78 | void AliEveEventSelector::SetTriggerType( const char* type) |
79 | { |
80 | TString ts = type; |
81 | SetTriggerType(ts); |
82 | } |
83 | |
84 | //_____________________________________________________________________________ |
85 | void AliEveEventSelector::UpdateEntryList() |
86 | { |
87 | //update the entrylist from file if file changed |
88 | TTree* pESDTree = fPEventManager->GetESDTree(); |
89 | if (!pESDTree) return; |
90 | |
91 | Long64_t treesize = fPEventManager->GetMaxEventId(); |
92 | if (treesize<=fMaxEventId) return; //nothing changed, do nothing |
93 | pESDTree->Draw(">>+fPEntryList", fString, "entrylist", |
94 | fMaxEventId, treesize-fMaxEventId ); |
95 | fMaxEventId = treesize; |
96 | } |
97 | |
98 | //_____________________________________________________________________________ |
99 | void AliEveEventSelector::Update() |
100 | { |
101 | //refresh stuff |
102 | |
103 | UpdateEntryList(); |
104 | } |
105 | |
106 | //_____________________________________________________________________________ |
107 | Bool_t AliEveEventSelector::FindNext( Int_t& output ) |
108 | { |
109 | //does the magick of selecting the next event |
110 | |
111 | static const TEveException kEH("AliEveEventSelector::GetNext "); |
112 | |
113 | TTree* pESDTree = fPEventManager->GetESDTree(); |
114 | if (!pESDTree) return kFALSE; |
115 | AliESDEvent* pESDEvent = fPEventManager->GetESD(); |
116 | Int_t eventId = fPEventManager->GetEventId(); |
117 | fMaxEventId = fPEventManager->GetMaxEventId(); |
118 | |
119 | if (!fSelectOnString) |
120 | { |
121 | // pure non-string |
122 | for (Int_t i = eventId+1; i<fMaxEventId+1; i++) |
123 | { |
124 | if (pESDTree->GetEntry(i) <= 0) |
125 | throw (kEH + "failed getting required event from ESD."); |
126 | if (CheckOtherSelection(pESDEvent)) |
127 | { |
128 | output = i; |
129 | return kTRUE; |
130 | } |
131 | } |
132 | if (!fWrapAround) return kFALSE; |
133 | for (Int_t i = 0; i<eventId+1; i++) |
134 | { |
135 | if (pESDTree->GetEntry(i) <= 0) |
136 | throw (kEH + "failed getting required event from ESD."); |
137 | if (CheckOtherSelection(pESDEvent)) |
138 | { |
139 | output = i; |
140 | return kTRUE; |
141 | } |
142 | } |
143 | return kFALSE; |
144 | } |
145 | else |
146 | { |
147 | //select using the entrylist |
148 | for (Long64_t i=fEntryListId+1; i<fPEntryList->GetN(); i++ ) |
149 | { |
150 | Long64_t entry = fPEntryList->GetEntry(i); |
151 | if (pESDTree->GetEntry(entry) <= 0) |
152 | throw (kEH + "failed getting required event from ESD."); |
153 | if (CheckOtherSelection(pESDEvent)) |
154 | { |
155 | output = entry; |
156 | fEntryListId = i; |
157 | return kTRUE; |
158 | } |
159 | } |
160 | if (!fWrapAround) return kFALSE; |
161 | for (Long64_t i=0; i<fEntryListId+1; i++ ) |
162 | { |
163 | Long64_t entry = fPEntryList->GetEntry(i); |
164 | if (pESDTree->GetEntry(entry) <= 0) |
165 | throw (kEH + "failed getting required event from ESD."); |
166 | if (CheckOtherSelection(pESDEvent)) |
167 | { |
168 | output = entry; |
169 | fEntryListId=i; |
170 | return kTRUE; |
171 | } |
172 | } |
173 | return kFALSE; |
174 | } |
175 | return kFALSE; |
176 | |
177 | } |
178 | |
179 | //_____________________________________________________________________________ |
180 | Bool_t AliEveEventSelector::FindPrev( Int_t& output ) |
181 | { |
182 | //does the magick of selecting the previous event |
183 | |
184 | static const TEveException kEH("AliEveEventSelector::GetNext "); |
185 | |
186 | TTree* pESDTree = fPEventManager->GetESDTree(); |
187 | if (!pESDTree) return kFALSE; |
188 | AliESDEvent* pESDEvent = fPEventManager->GetESD(); |
189 | Int_t eventId = fPEventManager->GetEventId(); |
190 | fMaxEventId = fPEventManager->GetMaxEventId(); |
191 | |
192 | if (!fSelectOnString) |
193 | { |
194 | // pure non-string |
195 | for (Int_t i = eventId-1; i>-1; i--) |
196 | { |
197 | if (pESDTree->GetEntry(i) <= 0) |
198 | throw (kEH + "failed getting required event from ESD."); |
199 | if (CheckOtherSelection(pESDEvent)) |
200 | { |
201 | output = i; |
202 | return kTRUE; |
203 | } |
204 | } |
205 | if (!fWrapAround) return kFALSE; |
206 | for (Int_t i = fMaxEventId; i>eventId-1; i--) |
207 | { |
208 | if (pESDTree->GetEntry(i) <= 0) |
209 | throw (kEH + "failed getting required event from ESD."); |
210 | if (CheckOtherSelection(pESDEvent)) |
211 | { |
212 | output = i; |
213 | return kTRUE; |
214 | } |
215 | } |
216 | return kFALSE; |
217 | } |
218 | else |
219 | { |
220 | //select using the entrylist |
221 | for (Long64_t i=fEntryListId-1; i>-1; i--) |
222 | { |
223 | Long64_t entry = fPEntryList->GetEntry(i); |
224 | if (pESDTree->GetEntry(entry) <= 0) |
225 | throw (kEH + "failed getting required event from ESD."); |
226 | if (CheckOtherSelection(pESDEvent)) |
227 | { |
228 | output = entry; |
229 | fEntryListId = i; |
230 | return kTRUE; |
231 | } |
232 | } |
233 | if (!fWrapAround) return kFALSE; |
234 | for (Long64_t i=fPEntryList->GetN()-1; i>fEntryListId-1; i--) |
235 | { |
236 | Long64_t entry = fPEntryList->GetEntry(i); |
237 | if (pESDTree->GetEntry(entry) <= 0) |
238 | throw (kEH + "failed getting required event from ESD."); |
239 | if (CheckOtherSelection(pESDEvent)) |
240 | { |
241 | output = entry; |
242 | fEntryListId=i; |
243 | return kTRUE; |
244 | } |
245 | } |
246 | return kFALSE; |
247 | } |
248 | return kFALSE; |
249 | } |
250 | |
251 | //_____________________________________________________________________________ |
252 | Bool_t AliEveEventSelector::CheckOtherSelection( AliESDEvent* pESDEvent ) |
253 | { |
254 | //checks the event for any other hardcoded selection criteria |
255 | Bool_t ret=kTRUE; |
256 | |
257 | //trigger stuff |
258 | if (fSelectOnTriggerType) |
259 | { |
260 | TString firedtrclasses = pESDEvent->GetFiredTriggerClasses(); |
261 | printf(firedtrclasses.Data()); |
262 | printf("\n"); |
263 | printf(fTriggerType.Data()); |
264 | printf("\n"); |
265 | if (!(firedtrclasses.Contains(fTriggerType))) return kFALSE; |
266 | //if (!pESDEvent->IsTriggerClassFired(fTriggerType.Data())) return kFALSE; |
267 | } |
268 | |
269 | if (fSelectOnMultiplicity) |
270 | { |
271 | Int_t mult = pESDEvent->GetNumberOfTracks(); |
272 | Int_t mhigh = (fMultiplicityHigh==0)?100000000:fMultiplicityHigh; |
273 | if (mult<fMultiplicityLow || mult>mhigh) return kFALSE; |
274 | } |
275 | |
276 | if (fSelectOnTriggerString) |
277 | { |
278 | ULong64_t triggermask = pESDEvent->GetTriggerMask(); |
279 | TString triggermaskstr; |
280 | triggermaskstr += triggermask; |
281 | TString selstr(fTriggerSelectionString); //make copy |
282 | selstr.ReplaceAll(fTriggerMaskPatternString,triggermaskstr); |
283 | Int_t returncode; |
284 | Bool_t result = static_cast<Bool_t>(gROOT->ProcessLine(selstr,&returncode)); |
285 | //if (!returncode) return kFALSE; |
286 | if (!result) return kFALSE; |
287 | } |
288 | |
289 | return ret; |
290 | } |
291 | |
292 | //_____________________________________________________________________________ |
293 | void AliEveEventSelector::SetTriggerSelectionString( TString str ) |
294 | { |
295 | const AliESDRun* run = fPEventManager->GetESD()->GetESDRun(); |
296 | for (Int_t i=0; i<run->kNTriggerClasses; i++) |
297 | { |
34a9a725 |
298 | TString name(run->GetTriggerClass(i)); |
299 | if (name.IsNull()) continue; |
008ac94c |
300 | TString valuestr("("); |
301 | valuestr += fTriggerMaskPatternString; |
302 | valuestr += "&"; |
303 | valuestr += static_cast<ULong64_t>(1<<i); |
304 | valuestr += ")"; |
305 | str.ReplaceAll(name,valuestr); |
306 | }//for i |
307 | fTriggerSelectionString = str; |
308 | } |
309 | |