]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliTagAnalysis.cxx
QA library for detector checks from ESD
[u/mrichter/AliRoot.git] / STEER / AliTagAnalysis.cxx
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
29 //ROOT-AliEn
30 #include <TGridResult.h>
31
32 #include "AliLog.h"
33
34 #include "AliRunTag.h"
35 #include "AliEventTag.h"
36 #include "AliTagAnalysis.h"
37 #include "AliEventTagCuts.h"
38 #include "AliRunTagCuts.h"
39 #include "AliXMLCollection.h"
40
41 class TTree;
42
43 ClassImp(AliTagAnalysis)
44
45 TChain *AliTagAnalysis::fgChain = 0;
46
47 //___________________________________________________________________________
48 AliTagAnalysis::AliTagAnalysis(): 
49   TObject(),
50   ftagresult(0x0),
51   fTagDirName(),
52   fChain(0x0)
53 {
54   //Default constructor for a AliTagAnalysis
55 }
56
57 //___________________________________________________________________________
58 AliTagAnalysis::~AliTagAnalysis() {
59 //Default destructor for a AliTagAnalysis
60 }
61
62 //___________________________________________________________________________
63 void AliTagAnalysis::ChainLocalTags(const char *dirname) {
64   //Searches the entries of the provided direcory
65   //Chains the tags that are stored locally
66   fTagDirName = dirname;
67   TString fTagFilename;
68   
69   TChain *fgChain = new TChain("T");
70   fChain = fgChain;
71   
72   const char * tagPattern = "tag.root";
73   // Open the working directory
74   void * dirp = gSystem->OpenDirectory(fTagDirName);
75   const char * name = 0x0;
76   // Add all files matching *pattern* to the chain
77   while((name = gSystem->GetDirEntry(dirp))) {
78     if (strstr(name,tagPattern)) { 
79       fTagFilename = fTagDirName;
80       fTagFilename += "/";
81       fTagFilename += name;
82                 
83       fChain->Add(fTagFilename);  
84     }//pattern check
85   }//directory loop
86   AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
87 }
88
89
90 //___________________________________________________________________________
91 void AliTagAnalysis::ChainGridTags(TGridResult *res) {
92   //Loops overs the entries of the TGridResult
93   //Chains the tags that are stored in the GRID
94   ftagresult = res;
95   Int_t nEntries = ftagresult->GetEntries();
96  
97   TChain *fgChain = new TChain("T");
98   fChain = fgChain;
99
100   TString gridname = "alien://";
101   TString alienUrl;
102  
103   for(Int_t i = 0; i < nEntries; i++) {
104     alienUrl = ftagresult->GetKey(i,"turl");
105     fChain->Add(alienUrl);
106   }//grid result loop  
107 }
108
109
110 //___________________________________________________________________________
111 TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) {
112   //Queries the tag chain using the defined 
113   //event tag cuts from the AliEventTagCuts object
114   //and returns a TChain along with the associated TEventList
115   AliInfo(Form("Querying the tags........"));
116   
117   //ESD file chain
118   TChain *fESDchain = new TChain("esdTree");
119   //Event list
120   TEventList *fEventList = new TEventList();
121   
122   //Defining tag objects
123   AliRunTag *tag = new AliRunTag;
124   AliEventTag *evTag = new AliEventTag;
125   fChain->SetBranchAddress("AliTAG",&tag);
126
127   TString guid = 0;
128   TString turl = 0;
129   TString path = 0;
130
131   Int_t iAccepted = 0;
132   for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
133     fChain->GetEntry(iTagFiles);
134     if(RunTagCuts->IsAccepted(tag)) {
135       Int_t iEvents = tag->GetNEvents();
136       const TClonesArray *tagList = tag->GetEventTags();
137       for(Int_t i = 0; i < iEvents; i++) {
138         evTag = (AliEventTag *) tagList->At(i);
139         guid = evTag->GetGUID(); 
140         turl = evTag->GetTURL(); 
141         path = evTag->GetPath();
142         if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(iAccepted+i);
143       }//event loop
144       iAccepted += iEvents;
145     
146       if(path != "") fESDchain->AddFile(path);
147       else if(turl != "") fESDchain->AddFile(turl);
148     }//run tags cut
149   }//tag file loop
150   AliInfo(Form("Accepted events: %d",fEventList->GetN()));
151   fESDchain->SetEventList(fEventList);
152    
153   return fESDchain;
154 }
155
156 //___________________________________________________________________________
157 Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) {
158   //Queries the tag chain using the defined 
159   //event tag cuts from the AliEventTagCuts object
160   //and returns a XML collection
161   AliInfo(Form("Creating the collection........"));
162
163   AliXMLCollection *collection = new AliXMLCollection();
164   collection->SetCollectionName(name);
165   collection->WriteHeader();
166
167   //Event list
168   TEventList *fEventList = new TEventList();
169   TString guid = 0x0;
170   TString turl = 0x0;
171   TString lfn = 0x0;
172   
173   //Defining tag objects
174   AliRunTag *tag = new AliRunTag;
175   AliEventTag *evTag = new AliEventTag;
176   fChain->SetBranchAddress("AliTAG",&tag);
177
178   for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
179     fChain->GetEntry(iTagFiles);
180     if(RunTagCuts->IsAccepted(tag)) {
181       Int_t iEvents = tag->GetNEvents();
182       const TClonesArray *tagList = tag->GetEventTags();
183       for(Int_t i = 0; i < iEvents; i++) {
184         evTag = (AliEventTag *) tagList->At(i);
185         guid = evTag->GetGUID(); 
186         turl = evTag->GetTURL(); 
187         lfn = turl(8,turl.Length());
188
189         if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(i);
190       }//event loop
191       collection->WriteBody(iTagFiles+1,guid,lfn,turl,fEventList);
192       fEventList->Clear();
193     }//run tag cuts
194   }//tag file loop
195   collection->Export();
196
197   return kTRUE;
198 }
199
200 //___________________________________________________________________________
201 TChain *AliTagAnalysis::GetInputChain(const char* system, const char*global, const char *wn) {
202   //returns the chain+event list - used in batch sessions
203   TString fsystem = system;
204   Int_t iAccepted = 0;
205   //ESD file chain
206   TChain *fESDchain = new TChain("esdTree");
207   //Event list
208   TEventList *fEventList = new TEventList();
209   AliXMLCollection *collection1 = AliXMLCollection::Open(global);
210   AliXMLCollection *collection2 = AliXMLCollection::Open(wn);
211   collection1->OverlapCollection(collection2);
212   collection1->Reset();
213   while (collection1->Next()) {
214     AliInfo(Form("Adding: %s",collection1->GetTURL("")));
215     fESDchain->Add(collection1->GetTURL(""));
216     TEntryList *list = (TEntryList *)collection1->GetEventList("");
217     for(Int_t i = 0; i < list->GetN(); i++) fEventList->Enter(iAccepted+list->GetEntry(i));
218
219     if(fsystem == "pp") iAccepted += 100;
220     else if(fsystem == "PbPb") iAccepted += 1;
221   }
222
223   fESDchain->SetEventList(fEventList);
224   
225   AliInfo(Form("Number of selected events: %d",fEventList->GetN()));
226
227   return fESDchain;
228 }