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