1 /**************************************************************************
2 * Author: Panos Christakoglou. *
3 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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 //-----------------------------------------------------------------
26 #include <TEventList.h>
27 #include <TEntryList.h>
28 #include <TTreeFormula.h>
31 #include <TGridResult.h>
35 #include "AliRunTag.h"
36 #include "AliEventTag.h"
37 #include "AliTagAnalysis.h"
38 #include "AliEventTagCuts.h"
39 #include "AliRunTagCuts.h"
40 #include "AliXMLCollection.h"
44 ClassImp(AliTagAnalysis)
46 //___________________________________________________________________________
47 AliTagAnalysis::AliTagAnalysis():
53 //Default constructor for a AliTagAnalysis
56 //___________________________________________________________________________
57 AliTagAnalysis::~AliTagAnalysis() {
58 //Default destructor for a AliTagAnalysis
61 //___________________________________________________________________________
62 Bool_t AliTagAnalysis::AddTagsFile(const char *alienUrl) {
64 // Add a single tags file to the chain
68 if (! fChain) fChain = new TChain("T");
70 TFile *f = TFile::Open(alienUrl,"READ");
71 fChain->Add(alienUrl);
72 AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
75 if (fChain->GetEntries() == 0 )
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;
88 if (! fChain) fChain = new TChain("T");
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;
101 fChain->Add(fTagFilename);
104 AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
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
113 Int_t nEntries = ftagresult->GetEntries();
115 if (! fChain) fChain = new TChain("T");
117 TString gridname = "alien://";
120 for(Int_t i = 0; i < nEntries; i++) {
121 alienUrl = ftagresult->GetKey(i,"turl");
122 fChain->Add(alienUrl);
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........"));
135 TChain *fESDchain = new TChain("esdTree");
137 TEventList *fEventList = new TEventList();
139 //Defining tag objects
140 AliRunTag *tag = new AliRunTag;
141 AliEventTag *evTag = new AliEventTag;
142 fChain->SetBranchAddress("AliTAG",&tag);
149 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
150 fChain->GetEntry(iTagFiles);
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);
161 iAccepted += iEvents;
163 if(path != "") fESDchain->AddFile(path);
164 else if(turl != "") fESDchain->AddFile(turl);
167 AliInfo(Form("Accepted events: %d",fEventList->GetN()));
168 fESDchain->SetEventList(fEventList);
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........"));
181 TChain *fESDchain = new TChain("esdTree");
183 TEventList *fEventList = new TEventList();
185 //Defining tag objects
186 AliRunTag *tag = new AliRunTag;
187 AliEventTag *evTag = new AliEventTag;
188 fChain->SetBranchAddress("AliTAG",&tag);
194 TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain);
195 TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain);
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();
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);
216 iAccepted += iEvents;
218 if(path != "") fESDchain->AddFile(path);
219 else if(turl != "") fESDchain->AddFile(turl);
222 AliInfo(Form("Accepted events: %d",fEventList->GetN()));
223 fESDchain->SetEventList(fEventList);
228 //___________________________________________________________________________
229 Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) {
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........"));
235 AliXMLCollection *collection = new AliXMLCollection();
236 collection->SetCollectionName(name);
237 collection->WriteHeader();
240 //TEntryList *fEventList = new TEntryList();
245 //Defining tag objects
246 AliRunTag *tag = new AliRunTag;
247 AliEventTag *evTag = new AliEventTag;
248 fChain->SetBranchAddress("AliTAG",&tag);
250 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
252 TEntryList *fList = new TEntryList();
253 fChain->GetEntry(iTagFiles);
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();
261 lfn = turl(8,turl.Length());
262 if(EvTagCuts->IsAccepted(evTag)) fList->Enter(i);
264 collection->WriteBody(iTagFiles+1,guid,lfn,turl,fList);
267 collection->Export();
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........"));
279 AliXMLCollection *collection = new AliXMLCollection();
280 collection->SetCollectionName(name);
281 collection->WriteHeader();
287 //Defining tag objects
288 AliRunTag *tag = new AliRunTag;
289 AliEventTag *evTag = new AliEventTag;
290 fChain->SetBranchAddress("AliTAG",&tag);
292 TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain);
293 TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain);
296 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
298 TEntryList *fList = new TEntryList();
299 fChain->GetEntry(iTagFiles);
300 if (current != fChain->GetTreeNumber()) {
301 fRunFormula->UpdateFormulaLeaves();
302 fEventFormula->UpdateFormulaLeaves();
303 current = fChain->GetTreeNumber();
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);
315 collection->WriteBody(iTagFiles+1,guid,lfn,turl,fList);
318 collection->Export();
323 //___________________________________________________________________________
324 TChain *AliTagAnalysis::GetInputChain(const char* system, const char*global, const char *wn) {
325 //returns the chain+event list - used in batch sessions
326 TString fsystem = system;
329 TChain *fESDchain = new TChain("esdTree");
331 TEventList *fEventList = new TEventList();
332 AliXMLCollection *collection1 = AliXMLCollection::Open(global);
333 AliXMLCollection *collection2 = AliXMLCollection::Open(wn);
334 collection1->OverlapCollection(collection2);
335 collection1->Reset();
336 while (collection1->Next()) {
337 AliInfo(Form("Adding: %s",collection1->GetTURL("")));
338 fESDchain->Add(collection1->GetTURL(""));
339 TEntryList *list = (TEntryList *)collection1->GetEventList("");
340 for(Int_t i = 0; i < list->GetN(); i++) fEventList->Enter(iAccepted+list->GetEntry(i));
342 if(fsystem == "pp") iAccepted += 100;
343 else if(fsystem == "PbPb") iAccepted += 1;
346 fESDchain->SetEventList(fEventList);
348 AliInfo(Form("Number of selected events: %d",fEventList->GetN()));