]>
Commit | Line | Data |
---|---|---|
d08133e6 | 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> | |
25 | #include <TFile.h> | |
26 | #include <TEventList.h> | |
27 | #include <TEntryList.h> | |
28 | #include <TTreeFormula.h> | |
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" | |
39 | #include "AliRunTagCuts.h" | |
40 | #include "AliXMLCollection.h" | |
41 | ||
42 | class TTree; | |
43 | ||
44 | ClassImp(AliTagAnalysis) | |
45 | ||
46 | //___________________________________________________________________________ | |
47 | AliTagAnalysis::AliTagAnalysis(): | |
48 | TObject(), | |
49 | ftagresult(0x0), | |
50 | fTagDirName(), | |
51 | fChain(0x0) | |
52 | { | |
53 | //Default constructor for a AliTagAnalysis | |
54 | } | |
55 | ||
56 | //___________________________________________________________________________ | |
57 | AliTagAnalysis::~AliTagAnalysis() { | |
58 | //Default destructor for a AliTagAnalysis | |
59 | } | |
60 | ||
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 | ||
68 | if (! fChain) fChain = new TChain("T"); | |
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 | ||
81 | //___________________________________________________________________________ | |
82 | void AliTagAnalysis::ChainLocalTags(const char *dirname) { | |
83 | //Searches the entries of the provided direcory | |
84 | //Chains the tags that are stored locally | |
85 | fTagDirName = dirname; | |
86 | TString fTagFilename; | |
87 | ||
88 | if (! fChain) fChain = new TChain("T"); | |
89 | ||
90 | const char * tagPattern = "tag.root"; | |
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 | |
95 | while((name = gSystem->GetDirEntry(dirp))) { | |
96 | if (strstr(name,tagPattern)) { | |
97 | fTagFilename = fTagDirName; | |
98 | fTagFilename += "/"; | |
99 | fTagFilename += name; | |
100 | ||
101 | fChain->Add(fTagFilename); | |
102 | }//pattern check | |
103 | }//directory loop | |
104 | AliInfo(Form("Chained tag files: %d ",fChain->GetEntries())); | |
105 | } | |
106 | ||
107 | ||
108 | //___________________________________________________________________________ | |
109 | void AliTagAnalysis::ChainGridTags(TGridResult *res) { | |
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 | ||
115 | if (! fChain) fChain = new TChain("T"); | |
116 | ||
117 | TString gridname = "alien://"; | |
118 | TString alienUrl; | |
119 | ||
120 | for(Int_t i = 0; i < nEntries; i++) { | |
121 | alienUrl = ftagresult->GetKey(i,"turl"); | |
122 | fChain->Add(alienUrl); | |
123 | }//grid result loop | |
124 | } | |
125 | ||
126 | ||
127 | //___________________________________________________________________________ | |
128 | TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) { | |
129 | //Queries the tag chain using the defined | |
130 | //event tag cuts from the AliEventTagCuts object | |
131 | //and returns a TChain along with the associated TEventList | |
132 | AliInfo(Form("Querying the tags........")); | |
b97856f9 | 133 | |
134 | TString fAliceFile = "esdTree"; | |
135 | ||
d08133e6 | 136 | //ESD file chain |
b97856f9 | 137 | TChain *fESDchain = new TChain(fAliceFile.Data()); |
138 | //global entry list | |
139 | TEntryList *fGlobalList = new TEntryList(); | |
d08133e6 | 140 | |
141 | //Defining tag objects | |
142 | AliRunTag *tag = new AliRunTag; | |
143 | AliEventTag *evTag = new AliEventTag; | |
144 | fChain->SetBranchAddress("AliTAG",&tag); | |
145 | ||
146 | TString guid = 0; | |
147 | TString turl = 0; | |
148 | TString path = 0; | |
149 | ||
150 | Int_t iAccepted = 0; | |
151 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
152 | fChain->GetEntry(iTagFiles); | |
153 | if(RunTagCuts->IsAccepted(tag)) { | |
b97856f9 | 154 | TEntryList *fLocalList = new TEntryList(); |
d08133e6 | 155 | Int_t iEvents = tag->GetNEvents(); |
156 | const TClonesArray *tagList = tag->GetEventTags(); | |
157 | for(Int_t i = 0; i < iEvents; i++) { | |
158 | evTag = (AliEventTag *) tagList->At(i); | |
159 | guid = evTag->GetGUID(); | |
160 | turl = evTag->GetTURL(); | |
161 | path = evTag->GetPath(); | |
b97856f9 | 162 | fLocalList->SetTreeName(fAliceFile.Data()); |
163 | fLocalList->SetFileName(turl.Data()); | |
164 | if(EvTagCuts->IsAccepted(evTag)) fLocalList->Enter(i); | |
d08133e6 | 165 | }//event loop |
d08133e6 | 166 | |
167 | if(path != "") fESDchain->AddFile(path); | |
168 | else if(turl != "") fESDchain->AddFile(turl); | |
b97856f9 | 169 | fGlobalList->Add(fLocalList); |
170 | iAccepted += fLocalList->GetN(); | |
d08133e6 | 171 | }//run tags cut |
172 | }//tag file loop | |
b97856f9 | 173 | AliInfo(Form("Accepted events: %d",iAccepted)); |
174 | fESDchain->SetEntryList(fGlobalList,"ne"); | |
d08133e6 | 175 | |
176 | return fESDchain; | |
177 | } | |
178 | ||
179 | //___________________________________________________________________________ | |
180 | TChain *AliTagAnalysis::QueryTags(const char *fRunCut, const char *fEventCut) { | |
181 | //Queries the tag chain using the defined | |
182 | //event tag cuts from the AliEventTagCuts object | |
183 | //and returns a TChain along with the associated TEventList | |
184 | AliInfo(Form("Querying the tags........")); | |
185 | ||
b97856f9 | 186 | TString fAliceFile = "esdTree"; |
187 | ||
188 | //ESD file chain | |
189 | TChain *fESDchain = new TChain(fAliceFile.Data()); | |
190 | //global entry list | |
191 | TEntryList *fGlobalList = new TEntryList(); | |
d08133e6 | 192 | |
193 | //Defining tag objects | |
194 | AliRunTag *tag = new AliRunTag; | |
195 | AliEventTag *evTag = new AliEventTag; | |
196 | fChain->SetBranchAddress("AliTAG",&tag); | |
197 | ||
198 | TString guid = 0; | |
199 | TString turl = 0; | |
200 | TString path = 0; | |
201 | ||
202 | TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain); | |
203 | TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain); | |
204 | ||
205 | Int_t current = -1; | |
206 | Int_t iAccepted = 0; | |
207 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
208 | fChain->GetEntry(iTagFiles); | |
209 | if (current != fChain->GetTreeNumber()) { | |
210 | fRunFormula->UpdateFormulaLeaves(); | |
211 | fEventFormula->UpdateFormulaLeaves(); | |
212 | current = fChain->GetTreeNumber(); | |
213 | } | |
214 | if(fRunFormula->EvalInstance(iTagFiles) == 1) { | |
b97856f9 | 215 | TEntryList *fLocalList = new TEntryList(); |
d08133e6 | 216 | Int_t iEvents = fEventFormula->GetNdata(); |
217 | const TClonesArray *tagList = tag->GetEventTags(); | |
218 | for(Int_t i = 0; i < iEvents; i++) { | |
219 | evTag = (AliEventTag *) tagList->At(i); | |
220 | guid = evTag->GetGUID(); | |
221 | turl = evTag->GetTURL(); | |
222 | path = evTag->GetPath(); | |
b97856f9 | 223 | fLocalList->SetTreeName(fAliceFile.Data()); |
224 | fLocalList->SetFileName(turl.Data()); | |
225 | if(fEventFormula->EvalInstance(i) == 1) fLocalList->Enter(i); | |
d08133e6 | 226 | }//event loop |
b97856f9 | 227 | iAccepted += fLocalList->GetN(); |
d08133e6 | 228 | |
229 | if(path != "") fESDchain->AddFile(path); | |
230 | else if(turl != "") fESDchain->AddFile(turl); | |
b97856f9 | 231 | fGlobalList->Add(fLocalList); |
232 | iAccepted += fLocalList->GetN(); | |
d08133e6 | 233 | }//run tag cut |
234 | }//tag file loop | |
b97856f9 | 235 | AliInfo(Form("Accepted events: %d",iAccepted)); |
236 | fESDchain->SetEntryList(fGlobalList,"ne"); | |
d08133e6 | 237 | |
238 | return fESDchain; | |
239 | } | |
240 | ||
241 | //___________________________________________________________________________ | |
242 | Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) { | |
243 | //Queries the tag chain using the defined | |
244 | //event tag cuts from the AliEventTagCuts object | |
245 | //and returns a XML collection | |
246 | AliInfo(Form("Creating the collection........")); | |
247 | ||
248 | AliXMLCollection *collection = new AliXMLCollection(); | |
249 | collection->SetCollectionName(name); | |
250 | collection->WriteHeader(); | |
251 | ||
d08133e6 | 252 | TString guid = 0x0; |
253 | TString turl = 0x0; | |
254 | TString lfn = 0x0; | |
255 | ||
256 | //Defining tag objects | |
257 | AliRunTag *tag = new AliRunTag; | |
258 | AliEventTag *evTag = new AliEventTag; | |
259 | fChain->SetBranchAddress("AliTAG",&tag); | |
260 | ||
261 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
262 | //Event list | |
263 | TEntryList *fList = new TEntryList(); | |
264 | fChain->GetEntry(iTagFiles); | |
265 | if(RunTagCuts->IsAccepted(tag)) { | |
266 | Int_t iEvents = tag->GetNEvents(); | |
267 | const TClonesArray *tagList = tag->GetEventTags(); | |
268 | for(Int_t i = 0; i < iEvents; i++) { | |
269 | evTag = (AliEventTag *) tagList->At(i); | |
270 | guid = evTag->GetGUID(); | |
271 | turl = evTag->GetTURL(); | |
272 | lfn = turl(8,turl.Length()); | |
273 | if(EvTagCuts->IsAccepted(evTag)) fList->Enter(i); | |
274 | }//event loop | |
275 | collection->WriteBody(iTagFiles+1,guid,lfn,turl,fList); | |
276 | }//run tag cuts | |
277 | }//tag file loop | |
278 | collection->Export(); | |
279 | ||
280 | return kTRUE; | |
281 | } | |
282 | ||
283 | //___________________________________________________________________________ | |
284 | Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, const char *fRunCut, const char *fEventCut) { | |
285 | //Queries the tag chain using the defined | |
286 | //event tag cuts from the AliEventTagCuts object | |
287 | //and returns a XML collection | |
288 | AliInfo(Form("Creating the collection........")); | |
289 | ||
290 | AliXMLCollection *collection = new AliXMLCollection(); | |
291 | collection->SetCollectionName(name); | |
292 | collection->WriteHeader(); | |
293 | ||
294 | TString guid = 0x0; | |
295 | TString turl = 0x0; | |
296 | TString lfn = 0x0; | |
297 | ||
298 | //Defining tag objects | |
299 | AliRunTag *tag = new AliRunTag; | |
300 | AliEventTag *evTag = new AliEventTag; | |
301 | fChain->SetBranchAddress("AliTAG",&tag); | |
302 | ||
303 | TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain); | |
304 | TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain); | |
305 | ||
306 | Int_t current = -1; | |
307 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
308 | //Event list | |
309 | TEntryList *fList = new TEntryList(); | |
310 | fChain->GetEntry(iTagFiles); | |
311 | if (current != fChain->GetTreeNumber()) { | |
312 | fRunFormula->UpdateFormulaLeaves(); | |
313 | fEventFormula->UpdateFormulaLeaves(); | |
314 | current = fChain->GetTreeNumber(); | |
315 | } | |
316 | if(fRunFormula->EvalInstance(iTagFiles) == 1) { | |
317 | Int_t iEvents = fEventFormula->GetNdata(); | |
318 | const TClonesArray *tagList = tag->GetEventTags(); | |
319 | for(Int_t i = 0; i < iEvents; i++) { | |
320 | evTag = (AliEventTag *) tagList->At(i); | |
321 | guid = evTag->GetGUID(); | |
322 | turl = evTag->GetTURL(); | |
323 | lfn = turl(8,turl.Length()); | |
324 | if(fEventFormula->EvalInstance(i) == 1) fList->Enter(i); | |
325 | }//event loop | |
326 | collection->WriteBody(iTagFiles+1,guid,lfn,turl,fList); | |
327 | }//run tag cuts | |
328 | }//tag file loop | |
329 | collection->Export(); | |
330 | ||
331 | return kTRUE; | |
332 | } | |
333 | ||
334 | //___________________________________________________________________________ | |
335 | TChain *AliTagAnalysis::GetInputChain(const char* system, const char *wn) { | |
336 | //returns the chain+event list - used in batch sessions | |
337 | // this function will be removed once the new root | |
338 | // improvements are committed | |
339 | TString fsystem = system; | |
340 | Int_t iAccepted = 0; | |
341 | //ESD file chain | |
342 | TChain *fESDchain = new TChain("esdTree"); | |
343 | //Event list | |
344 | TEventList *fEventList = new TEventList(); | |
345 | AliXMLCollection *collection = AliXMLCollection::Open(wn); | |
346 | ||
347 | collection->Reset(); | |
348 | while (collection->Next()) { | |
349 | AliInfo(Form("Adding: %s",collection->GetTURL(""))); | |
350 | fESDchain->Add(collection->GetTURL("")); | |
351 | TEntryList *list = (TEntryList *)collection->GetEventList(""); | |
352 | for(Int_t i = 0; i < list->GetN(); i++) fEventList->Enter(iAccepted+list->GetEntry(i)); | |
353 | ||
354 | if(fsystem == "pp") iAccepted += 100; | |
355 | else if(fsystem == "PbPb") iAccepted += 1; | |
356 | } | |
357 | ||
358 | fESDchain->SetEventList(fEventList); | |
359 | ||
360 | AliInfo(Form("Number of selected events: %d",fEventList->GetN())); | |
361 | ||
362 | return fESDchain; | |
363 | } | |
364 | ||
365 | //___________________________________________________________________________ | |
366 | TChain *AliTagAnalysis::GetChainFromCollection(const char* collectionname, const char* treename) { | |
367 | //returns the TChain+TEntryList object- used in batch sessions | |
368 | TString fAliceFile = treename; | |
369 | Int_t iAccepted = 0; | |
370 | TChain *fAnalysisChain = new TChain(); | |
371 | if(fAliceFile == "esdTree") { | |
372 | //ESD file chain | |
373 | fAnalysisChain->SetName("esdTree"); | |
374 | } else if(fAliceFile == "aodTree") { | |
375 | //AOD file chain | |
376 | fAnalysisChain->SetName("aodTree"); | |
377 | AliFatal("AOD case not yet implemented!!!"); | |
378 | } | |
379 | else AliFatal("Inconsistent tree name - use esdTree or aodTree!"); | |
380 | //Event list | |
381 | TEntryList *fGlobalList = new TEntryList(); | |
382 | AliXMLCollection *collection = AliXMLCollection::Open(collectionname); | |
383 | ||
384 | collection->Reset(); | |
385 | while (collection->Next()) { | |
386 | AliInfo(Form("Adding: %s",collection->GetTURL(""))); | |
387 | fAnalysisChain->Add(collection->GetTURL("")); | |
388 | TEntryList *list = (TEntryList *)collection->GetEventList(""); | |
389 | list->SetTreeName(fAliceFile.Data()); | |
390 | list->SetFileName(collection->GetTURL("")); | |
391 | fGlobalList->Add(list); | |
392 | iAccepted += list->GetN(); | |
393 | } | |
394 | ||
395 | fAnalysisChain->SetEntryList(fGlobalList,"ne"); | |
396 | ||
397 | AliInfo(Form("Number of selected events: %d",iAccepted)); | |
398 | ||
399 | return fAnalysisChain; | |
400 | } |