]>
Commit | Line | Data |
---|---|---|
c7e89ea3 | 1 | /************************************************************************** |
2 | * Author: Panos Christakoglou. * | |
3 | * Contributors are mentioned in the code where appropriate. * | |
4 | * * | |
5 | * Permission to use, copy, modify and distribute this software and its * | |
6 | * documentation strictly for non-commercial purposes is hereby granted * | |
7 | * without fee, provided that the above copyright notice appears in all * | |
8 | * copies and that both the copyright notice and this permission notice * | |
9 | * appear in the supporting documentation. The authors make no claims * | |
10 | * about the suitability of this software for any purpose. It is * | |
11 | * provided "as is" without express or implied warranty. * | |
12 | **************************************************************************/ | |
13 | ||
14 | /* $Id$ */ | |
15 | ||
16 | //----------------------------------------------------------------- | |
17 | // AliTagAnalysis class | |
18 | // This is the class to deal with the tag analysis | |
19 | // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch | |
20 | //----------------------------------------------------------------- | |
21 | ||
22 | //ROOT | |
23 | #include <TSystem.h> | |
24 | #include <TChain.h> | |
2f514327 | 25 | #include <TFile.h> |
c7e89ea3 | 26 | #include <TEventList.h> |
2f514327 | 27 | #include <TEntryList.h> |
5b7be856 | 28 | #include <TTreeFormula.h> |
c7e89ea3 | 29 | |
30 | //ROOT-AliEn | |
31 | #include <TGridResult.h> | |
32 | ||
33 | #include "AliLog.h" | |
34 | ||
35 | #include "AliRunTag.h" | |
36 | #include "AliEventTag.h" | |
37 | #include "AliTagAnalysis.h" | |
38 | #include "AliEventTagCuts.h" | |
a3acd4e8 | 39 | #include "AliRunTagCuts.h" |
b6003316 | 40 | #include "AliXMLCollection.h" |
c7e89ea3 | 41 | |
2f514327 | 42 | class TTree; |
43 | ||
c7e89ea3 | 44 | ClassImp(AliTagAnalysis) |
45 | ||
54ac820d | 46 | //___________________________________________________________________________ |
47 | AliTagAnalysis::AliTagAnalysis(): | |
48 | TObject(), | |
fe12e09c | 49 | ftagresult(0x0), |
50 | fTagDirName(), | |
51 | fChain(0x0) | |
c7e89ea3 | 52 | { |
54ac820d | 53 | //Default constructor for a AliTagAnalysis |
c7e89ea3 | 54 | } |
55 | ||
54ac820d | 56 | //___________________________________________________________________________ |
57 | AliTagAnalysis::~AliTagAnalysis() { | |
58 | //Default destructor for a AliTagAnalysis | |
c7e89ea3 | 59 | } |
60 | ||
6e2eae7e | 61 | //___________________________________________________________________________ |
62 | Bool_t AliTagAnalysis::AddTagsFile(const char *alienUrl) { | |
63 | ||
64 | // Add a single tags file to the chain | |
65 | ||
66 | Bool_t rv = kTRUE ; | |
67 | ||
fc9e60bc | 68 | if (! fChain) fChain = new TChain("T"); |
6e2eae7e | 69 | |
70 | TFile *f = TFile::Open(alienUrl,"READ"); | |
71 | fChain->Add(alienUrl); | |
72 | AliInfo(Form("Chained tag files: %d ",fChain->GetEntries())); | |
73 | delete f; | |
74 | ||
75 | if (fChain->GetEntries() == 0 ) | |
76 | rv = kFALSE ; | |
77 | ||
78 | return rv ; | |
79 | } | |
80 | ||
54ac820d | 81 | //___________________________________________________________________________ |
82 | void AliTagAnalysis::ChainLocalTags(const char *dirname) { | |
c7e89ea3 | 83 | //Searches the entries of the provided direcory |
84 | //Chains the tags that are stored locally | |
85 | fTagDirName = dirname; | |
86 | TString fTagFilename; | |
87 | ||
fc9e60bc | 88 | if (! fChain) fChain = new TChain("T"); |
c7e89ea3 | 89 | |
f2313c5b | 90 | const char * tagPattern = "tag.root"; |
c7e89ea3 | 91 | // Open the working directory |
92 | void * dirp = gSystem->OpenDirectory(fTagDirName); | |
93 | const char * name = 0x0; | |
94 | // Add all files matching *pattern* to the chain | |
54ac820d | 95 | while((name = gSystem->GetDirEntry(dirp))) { |
96 | if (strstr(name,tagPattern)) { | |
97 | fTagFilename = fTagDirName; | |
98 | fTagFilename += "/"; | |
99 | fTagFilename += name; | |
c7e89ea3 | 100 | |
54ac820d | 101 | fChain->Add(fTagFilename); |
54ac820d | 102 | }//pattern check |
103 | }//directory loop | |
c7e89ea3 | 104 | AliInfo(Form("Chained tag files: %d ",fChain->GetEntries())); |
105 | } | |
106 | ||
107 | ||
54ac820d | 108 | //___________________________________________________________________________ |
109 | void AliTagAnalysis::ChainGridTags(TGridResult *res) { | |
c7e89ea3 | 110 | //Loops overs the entries of the TGridResult |
111 | //Chains the tags that are stored in the GRID | |
112 | ftagresult = res; | |
113 | Int_t nEntries = ftagresult->GetEntries(); | |
114 | ||
fc9e60bc | 115 | if (! fChain) fChain = new TChain("T"); |
c7e89ea3 | 116 | |
117 | TString gridname = "alien://"; | |
118 | TString alienUrl; | |
119 | ||
54ac820d | 120 | for(Int_t i = 0; i < nEntries; i++) { |
121 | alienUrl = ftagresult->GetKey(i,"turl"); | |
54ac820d | 122 | fChain->Add(alienUrl); |
54ac820d | 123 | }//grid result loop |
c7e89ea3 | 124 | } |
125 | ||
126 | ||
54ac820d | 127 | //___________________________________________________________________________ |
a3acd4e8 | 128 | TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) { |
c7e89ea3 | 129 | //Queries the tag chain using the defined |
130 | //event tag cuts from the AliEventTagCuts object | |
b6003316 | 131 | //and returns a TChain along with the associated TEventList |
c7e89ea3 | 132 | AliInfo(Form("Querying the tags........")); |
133 | ||
df16faa3 | 134 | //ESD file chain |
135 | TChain *fESDchain = new TChain("esdTree"); | |
136 | //Event list | |
137 | TEventList *fEventList = new TEventList(); | |
c7e89ea3 | 138 | |
139 | //Defining tag objects | |
140 | AliRunTag *tag = new AliRunTag; | |
141 | AliEventTag *evTag = new AliEventTag; | |
142 | fChain->SetBranchAddress("AliTAG",&tag); | |
143 | ||
d021d0d7 | 144 | TString guid = 0; |
145 | TString turl = 0; | |
146 | TString path = 0; | |
c7e89ea3 | 147 | |
df16faa3 | 148 | Int_t iAccepted = 0; |
149 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
54ac820d | 150 | fChain->GetEntry(iTagFiles); |
a3acd4e8 | 151 | if(RunTagCuts->IsAccepted(tag)) { |
152 | Int_t iEvents = tag->GetNEvents(); | |
153 | const TClonesArray *tagList = tag->GetEventTags(); | |
154 | for(Int_t i = 0; i < iEvents; i++) { | |
155 | evTag = (AliEventTag *) tagList->At(i); | |
156 | guid = evTag->GetGUID(); | |
157 | turl = evTag->GetTURL(); | |
158 | path = evTag->GetPath(); | |
159 | if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(iAccepted+i); | |
160 | }//event loop | |
161 | iAccepted += iEvents; | |
d021d0d7 | 162 | |
a3acd4e8 | 163 | if(path != "") fESDchain->AddFile(path); |
164 | else if(turl != "") fESDchain->AddFile(turl); | |
165 | }//run tags cut | |
54ac820d | 166 | }//tag file loop |
df16faa3 | 167 | AliInfo(Form("Accepted events: %d",fEventList->GetN())); |
168 | fESDchain->SetEventList(fEventList); | |
c7e89ea3 | 169 | |
df16faa3 | 170 | return fESDchain; |
c7e89ea3 | 171 | } |
172 | ||
5b7be856 | 173 | //___________________________________________________________________________ |
174 | TChain *AliTagAnalysis::QueryTags(const char *fRunCut, const char *fEventCut) { | |
175 | //Queries the tag chain using the defined | |
176 | //event tag cuts from the AliEventTagCuts object | |
177 | //and returns a TChain along with the associated TEventList | |
178 | AliInfo(Form("Querying the tags........")); | |
179 | ||
180 | //ESD file chain | |
181 | TChain *fESDchain = new TChain("esdTree"); | |
182 | //Event list | |
183 | TEventList *fEventList = new TEventList(); | |
184 | ||
185 | //Defining tag objects | |
186 | AliRunTag *tag = new AliRunTag; | |
187 | AliEventTag *evTag = new AliEventTag; | |
188 | fChain->SetBranchAddress("AliTAG",&tag); | |
189 | ||
190 | TString guid = 0; | |
191 | TString turl = 0; | |
192 | TString path = 0; | |
193 | ||
194 | TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain); | |
195 | TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain); | |
196 | ||
197 | Int_t current = -1; | |
198 | Int_t iAccepted = 0; | |
199 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
200 | fChain->GetEntry(iTagFiles); | |
201 | if (current != fChain->GetTreeNumber()) { | |
202 | fRunFormula->UpdateFormulaLeaves(); | |
203 | fEventFormula->UpdateFormulaLeaves(); | |
204 | current = fChain->GetTreeNumber(); | |
205 | } | |
206 | if(fRunFormula->EvalInstance(iTagFiles) == 1) { | |
207 | Int_t iEvents = fEventFormula->GetNdata(); | |
208 | const TClonesArray *tagList = tag->GetEventTags(); | |
209 | for(Int_t i = 0; i < iEvents; i++) { | |
210 | evTag = (AliEventTag *) tagList->At(i); | |
211 | guid = evTag->GetGUID(); | |
212 | turl = evTag->GetTURL(); | |
213 | path = evTag->GetPath(); | |
214 | if(fEventFormula->EvalInstance(i) == 1) fEventList->Enter(iAccepted+i); | |
215 | }//event loop | |
216 | iAccepted += iEvents; | |
217 | ||
218 | if(path != "") fESDchain->AddFile(path); | |
219 | else if(turl != "") fESDchain->AddFile(turl); | |
220 | }//run tag cut | |
221 | }//tag file loop | |
222 | AliInfo(Form("Accepted events: %d",fEventList->GetN())); | |
223 | fESDchain->SetEventList(fEventList); | |
224 | ||
225 | return fESDchain; | |
226 | } | |
227 | ||
b6003316 | 228 | //___________________________________________________________________________ |
a3acd4e8 | 229 | Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) { |
b6003316 | 230 | //Queries the tag chain using the defined |
231 | //event tag cuts from the AliEventTagCuts object | |
232 | //and returns a XML collection | |
233 | AliInfo(Form("Creating the collection........")); | |
234 | ||
235 | AliXMLCollection *collection = new AliXMLCollection(); | |
236 | collection->SetCollectionName(name); | |
237 | collection->WriteHeader(); | |
238 | ||
6e2eae7e | 239 | //Event list |
240 | //TEntryList *fEventList = new TEntryList(); | |
b6003316 | 241 | TString guid = 0x0; |
c6e443c8 | 242 | TString turl = 0x0; |
eb771b73 | 243 | TString lfn = 0x0; |
b6003316 | 244 | |
245 | //Defining tag objects | |
246 | AliRunTag *tag = new AliRunTag; | |
247 | AliEventTag *evTag = new AliEventTag; | |
248 | fChain->SetBranchAddress("AliTAG",&tag); | |
249 | ||
250 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
5b7be856 | 251 | //Event list |
252 | TEntryList *fList = new TEntryList(); | |
b6003316 | 253 | fChain->GetEntry(iTagFiles); |
a3acd4e8 | 254 | if(RunTagCuts->IsAccepted(tag)) { |
255 | Int_t iEvents = tag->GetNEvents(); | |
256 | const TClonesArray *tagList = tag->GetEventTags(); | |
257 | for(Int_t i = 0; i < iEvents; i++) { | |
258 | evTag = (AliEventTag *) tagList->At(i); | |
259 | guid = evTag->GetGUID(); | |
260 | turl = evTag->GetTURL(); | |
eb771b73 | 261 | lfn = turl(8,turl.Length()); |
5b7be856 | 262 | if(EvTagCuts->IsAccepted(evTag)) fList->Enter(i); |
263 | }//event loop | |
264 | collection->WriteBody(iTagFiles+1,guid,lfn,turl,fList); | |
265 | }//run tag cuts | |
266 | }//tag file loop | |
267 | collection->Export(); | |
268 | ||
269 | return kTRUE; | |
270 | } | |
271 | ||
272 | //___________________________________________________________________________ | |
273 | Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, const char *fRunCut, const char *fEventCut) { | |
274 | //Queries the tag chain using the defined | |
275 | //event tag cuts from the AliEventTagCuts object | |
276 | //and returns a XML collection | |
277 | AliInfo(Form("Creating the collection........")); | |
278 | ||
279 | AliXMLCollection *collection = new AliXMLCollection(); | |
280 | collection->SetCollectionName(name); | |
281 | collection->WriteHeader(); | |
2f514327 | 282 | |
5b7be856 | 283 | TString guid = 0x0; |
284 | TString turl = 0x0; | |
285 | TString lfn = 0x0; | |
286 | ||
287 | //Defining tag objects | |
288 | AliRunTag *tag = new AliRunTag; | |
289 | AliEventTag *evTag = new AliEventTag; | |
290 | fChain->SetBranchAddress("AliTAG",&tag); | |
291 | ||
292 | TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain); | |
293 | TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain); | |
294 | ||
295 | Int_t current = -1; | |
296 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
297 | //Event list | |
298 | TEntryList *fList = new TEntryList(); | |
299 | fChain->GetEntry(iTagFiles); | |
300 | if (current != fChain->GetTreeNumber()) { | |
301 | fRunFormula->UpdateFormulaLeaves(); | |
302 | fEventFormula->UpdateFormulaLeaves(); | |
303 | current = fChain->GetTreeNumber(); | |
304 | } | |
305 | if(fRunFormula->EvalInstance(iTagFiles) == 1) { | |
306 | Int_t iEvents = fEventFormula->GetNdata(); | |
307 | const TClonesArray *tagList = tag->GetEventTags(); | |
308 | for(Int_t i = 0; i < iEvents; i++) { | |
309 | evTag = (AliEventTag *) tagList->At(i); | |
310 | guid = evTag->GetGUID(); | |
311 | turl = evTag->GetTURL(); | |
312 | lfn = turl(8,turl.Length()); | |
313 | if(fEventFormula->EvalInstance(i) == 1) fList->Enter(i); | |
a3acd4e8 | 314 | }//event loop |
5b7be856 | 315 | collection->WriteBody(iTagFiles+1,guid,lfn,turl,fList); |
a3acd4e8 | 316 | }//run tag cuts |
b6003316 | 317 | }//tag file loop |
318 | collection->Export(); | |
319 | ||
320 | return kTRUE; | |
321 | } | |
c7e89ea3 | 322 | |
df122a89 | 323 | //___________________________________________________________________________ |
16b3f79e | 324 | TChain *AliTagAnalysis::GetInputChain(const char* system, const char *wn) { |
2f514327 | 325 | //returns the chain+event list - used in batch sessions |
16b3f79e | 326 | // this function will be removed once the new root |
327 | // improvements are committed | |
2f514327 | 328 | TString fsystem = system; |
329 | Int_t iAccepted = 0; | |
330 | //ESD file chain | |
331 | TChain *fESDchain = new TChain("esdTree"); | |
df122a89 | 332 | //Event list |
333 | TEventList *fEventList = new TEventList(); | |
16b3f79e | 334 | AliXMLCollection *collection = AliXMLCollection::Open(wn); |
335 | ||
336 | collection->Reset(); | |
337 | while (collection->Next()) { | |
338 | AliInfo(Form("Adding: %s",collection->GetTURL(""))); | |
339 | fESDchain->Add(collection->GetTURL("")); | |
340 | TEntryList *list = (TEntryList *)collection->GetEventList(""); | |
2f514327 | 341 | for(Int_t i = 0; i < list->GetN(); i++) fEventList->Enter(iAccepted+list->GetEntry(i)); |
342 | ||
343 | if(fsystem == "pp") iAccepted += 100; | |
344 | else if(fsystem == "PbPb") iAccepted += 1; | |
345 | } | |
df122a89 | 346 | |
2f514327 | 347 | fESDchain->SetEventList(fEventList); |
348 | ||
349 | AliInfo(Form("Number of selected events: %d",fEventList->GetN())); | |
df122a89 | 350 | |
2f514327 | 351 | return fESDchain; |
df122a89 | 352 | } |
16b3f79e | 353 | |
354 | //___________________________________________________________________________ | |
355 | TChain *AliTagAnalysis::GetChainFromCollection(const char* collectionname, const char* treename) { | |
356 | //returns the TChain+TEntryList object- used in batch sessions | |
357 | TString fAliceFile = treename; | |
358 | Int_t iAccepted = 0; | |
359 | TChain *fAnalysisChain = new TChain(); | |
360 | if(fAliceFile == "esdTree") { | |
361 | //ESD file chain | |
362 | fAnalysisChain->SetName("esdTree"); | |
363 | } else if(fAliceFile == "aodTree") { | |
364 | //AOD file chain | |
365 | fAnalysisChain->SetName("aodTree"); | |
366 | AliFatal("AOD case not yet implemented!!!"); | |
367 | } | |
368 | else AliFatal("Inconsistent tree name - use esdTree or aodTree!"); | |
369 | //Event list | |
370 | TEntryList *fGlobalList = new TEntryList(); | |
371 | AliXMLCollection *collection = AliXMLCollection::Open(collectionname); | |
372 | ||
373 | collection->Reset(); | |
374 | while (collection->Next()) { | |
375 | AliInfo(Form("Adding: %s",collection->GetTURL(""))); | |
376 | fAnalysisChain->Add(collection->GetTURL("")); | |
377 | TEntryList *list = (TEntryList *)collection->GetEventList(""); | |
378 | list->SetTreeName(fAliceFile.Data()); | |
379 | list->SetFileName(collection->GetTURL("")); | |
380 | fGlobalList->Add(list); | |
381 | iAccepted += list->GetN(); | |
382 | } | |
383 | ||
d73db370 | 384 | fAnalysisChain->SetEntryList(fGlobalList,"ne"); |
16b3f79e | 385 | |
386 | AliInfo(Form("Number of selected events: %d",iAccepted)); | |
387 | ||
388 | return fAnalysisChain; | |
389 | } |