]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/TRD/run.C
- fix coding rule violations
[u/mrichter/AliRoot.git] / PWGPP / TRD / run.C
1 // Steer TRD QA train for Reconstruction (Clusterizer, Tracking and PID).
2 // 
3 // Usage:
4 //   run.C(optList, files, nev, first, runNo, ocdb_uri, grp_uri)
5 //
6 //   optList : "ALL" [default] or one/more of the following:
7 //     "EFF"  : TRD Tracking Efficiency 
8 //     "EFFC" : TRD Tracking Efficiency Combined (barrel + stand alone) - only in case of simulations
9 //     "MULT"  : TRD single track selection
10 //     "RES"  : TRD tracking Resolution
11 //     "CLRES": clusters Resolution
12 //     "CAL"  : TRD calibration
13 //     "ALGN" : TRD alignment
14 //     "PID"  : TRD PID - pion efficiency 
15 //     "PIDR" : TRD PID - reference data
16 //     "V0"   : monitor V0 performance for use in TRD PID calibration
17 //     "DET"  : Basic TRD Detector checks
18 //      ****** SPECIAL OPTIONS **********
19 //     "NOFR" : Data set does not have AliESDfriends.root 
20 //     "NOMC" : Data set does not have Monte Carlo Informations (default have MC), 
21 //
22 //     files : the list of ESD files to be processed [default AliESds.root from cwd]
23 //     nev   : number of events to be processed [default all]
24 //     first : first event to process [default 0]
25 //     runNo : run number [default 0]
26 //     ocdb_uri : OCDB location [default local, $ALICE_ROOT]. In case of AliEn the syntax should be of the form
27 //                 alien://folder=/alice/data/2010/OCDB?user=username?cacheF=yourDirectory?cacheS=yourSize
28 //     grp_uri  : GRP/GRP/Data location [default cwd]. In case of AliEn the syntax should be of the form
29 //                 alien://folder=/alice/data/2010/OCDB?user=username?cacheF=yourDirectory?cacheS=yourSize
30 // In compiled mode : 
31 // Don't forget to load first the libraries
32 // gSystem->Load("libMemStat.so")
33 // gSystem->Load("libMemStatGui.so")
34 // gSystem->Load("libANALYSIS.so")
35 // gSystem->Load("libANALYSISalice.so")
36 // gSystem->Load("libTENDER.so");
37 // gSystem->Load("libPWGPP.so");
38 // gSystem->Load("libNetx.so") ;
39 // gSystem->Load("libRAliEn.so");
40 //
41 // Authors:
42 //   Alex Bercuci (A.Bercuci@gsi.de) 
43 //   Markus Fasel (m.Fasel@gsi.de) 
44
45 #if ! defined (__CINT__) || defined (__MAKECINT__)
46 //#ifndef __CINT__
47 #include <Riostream.h>
48
49 #include "TStopwatch.h"
50 #include "TMemStat.h"
51 #include "TMemStatViewerGUI.h"
52
53 #include "TROOT.h"
54 #include "TClass.h"
55 #include "TSystem.h"
56 #include "TError.h"
57 #include "TChain.h"
58 #include "TGrid.h"
59 #include "TAlienCollection.h"
60 #include "TGridCollection.h"
61 #include "TGridResult.h"
62 #include "TGeoGlobalMagField.h"
63
64 #include "AliMagF.h"
65 #include "AliTracker.h"
66 #include "AliLog.h"
67 #include "AliCDBManager.h"
68 #include "AliGRPManager.h"
69 #include "AliGeomManager.h"
70 #include "AliAnalysisManager.h"
71 #include "AliAnalysisDataContainer.h"
72 #include "AliMCEventHandler.h"
73 #include "AliESDInputHandler.h"
74
75 #include "TRD/AliTRDtrackerV1.h"
76 #include "TRD/AliTRDcalibDB.h"
77
78 #include "PWGPP/TRD/macros/AddTRDcheckESD.C"
79 #include "PWGPP/TRD/macros/AddTRDinfoGen.C"
80 #include "PWGPP/TRD/macros/AddTRDcheckDET.C"
81 #include "PWGPP/TRD/macros/AddTRDefficiency.C"
82 #include "PWGPP/TRD/macros/AddTRDresolution.C"
83 #include "PWGPP/TRD/macros/AddTRDcheckPID.C"
84 #endif
85
86 Bool_t MEM = kFALSE;
87
88 TChain* MakeChainLST(const char* filename = NULL);
89 TChain* MakeChainXML(const char* filename = NULL);
90 Bool_t UseMC(Char_t *opt);
91 Bool_t UseFriends(Char_t *opt);
92 void run(Char_t *optList="ALL", Int_t run, const Char_t *files=NULL, Long64_t nev=1234567890, Long64_t first = 0)
93 {
94   TMemStat *mem = NULL;
95   if(MEM){ 
96     if(gSystem->Load("libMemStat.so")<0) return;
97     if(gSystem->Load("libMemStatGui.so")<0) return;
98     mem = new TMemStat("new, gnubuildin");
99     mem->AddStamp("Start");
100   }
101   TStopwatch timer;
102   timer.Start();
103
104   // VERY GENERAL SETTINGS
105   //AliLog::SetGlobalLogLevel(AliLog::kError);
106   if(gSystem->Load("libANALYSIS.so")<0) return;
107   if(gSystem->Load("libANALYSISalice.so")<0) return;
108   if(gSystem->Load("libTENDER.so")<0) return;
109   if(gSystem->Load("libPWGPP.so")<0) return;
110   if(gSystem->Load("libCORRFW.so")<0) return;
111
112   Bool_t fHasMCdata = UseMC(optList);
113   Bool_t fHasFriends = UseFriends(optList);
114   
115   // DEFINE DATA CHAIN
116   TChain *chain = NULL;
117   if(!files) chain = MakeChainLST();
118   else{
119     TString fn(files);
120     if(fn.EndsWith("xml")) chain = MakeChainXML(files);
121     else chain = MakeChainLST(files);
122   }
123   if(!chain) return;
124   chain->Lookup();
125   chain->GetListOfFiles()->Print();
126   Int_t nfound=(Int_t)chain->GetEntries();
127   printf("\tENTRIES FOUND [%d] REQUESTED [%d]\n", nfound, nev>nfound?nfound:nev);
128
129
130   // BUILD ANALYSIS MANAGER
131   AliAnalysisManager *mgr = new AliAnalysisManager("TRD Reconstruction Performance & Calibration");
132   AliESDInputHandlerRP *esdH(NULL);
133   mgr->SetInputEventHandler(esdH = new AliESDInputHandlerRP);
134   if(fHasFriends){
135     esdH->SetReadFriends(kTRUE);
136     esdH->SetActiveBranches("ESDfriend");
137   }
138   AliMCEventHandler *mcH(NULL);
139   if(fHasMCdata) mgr->SetMCtruthEventHandler(mcH = new AliMCEventHandler());
140   //mgr->SetDebugLevel(10);
141   mgr->SetSkipTerminate(kTRUE);
142
143   // add CDB task
144   gROOT->LoadMacro("$ALICE_ROOT/PWGPP/PilotTrain/AddTaskCDBconnect.C");
145   AliTaskCDBconnect *taskCDB = AddTaskCDBconnect();
146   if (!taskCDB) return;
147   taskCDB->SetRunNumber(run);
148
149   gROOT->LoadMacro("$ALICE_ROOT/PWGPP/macros/AddTrainPerformanceTRD.C");
150   if(!AddTrainPerformanceTRD(optList)) {
151     Error("run.C", "Error loading TRD train.");
152     return;
153   }
154
155   if (!mgr->InitAnalysis()) return;
156   // verbosity
157   printf("\tRUNNING TRAIN FOR TASKS:\n");
158   TObjArray *taskList=mgr->GetTasks();
159   for(Int_t itask=0; itask<taskList->GetEntries(); itask++){ 
160     AliAnalysisTask *task=(AliAnalysisTask*)taskList->At(itask);
161     printf(" %s [%s]\n", task->GetName(), task->GetTitle());
162   }
163   //mgr->PrintStatus();
164   mgr->StartAnalysis("local", chain, nev, first);
165   timer.Stop();
166   timer.Print();  
167
168   // verbosity
169   printf("\tCLEANING TASK LIST:\n");
170   mgr->GetTasks()->Delete();
171
172   if(mcH) delete mcH;
173   delete esdH;
174   delete chain;
175   if(MEM) delete mem;
176   if(MEM) TMemStatViewerGUI::ShowGUI();
177 }
178
179 //____________________________________________
180 TChain* MakeChainLST(const char* filename)
181 {
182   // Create the chain
183   TChain* chain = new TChain("esdTree");
184
185   if(!filename){
186     chain->Add(Form("%s/AliESDs.root", gSystem->pwd()));
187     return chain;
188   }
189
190
191   // read ESD files from the input list.
192   ifstream in;
193   in.open(filename);
194   TString esdfile;
195   while(in.good()) {
196     in >> esdfile;
197     if (!esdfile.Contains("root")) continue; // protection
198     chain->Add(esdfile.Data());
199   }
200
201   in.close();
202
203   return chain;
204 }
205
206 //____________________________________________
207 TChain* MakeChainXML(const char* xmlfile)
208 {
209   if (!TFile::Open(xmlfile)) {
210     Error("MakeChainXML", Form("No file %s was found", xmlfile));
211     return NULL;
212   }
213
214   if(gSystem->Load("libNetx.so")<0) return NULL;
215   if(gSystem->Load("libRAliEn.so")<0) return NULL;
216   TGrid::Connect("alien://") ;
217
218   TGridCollection *collection = (TGridCollection*) TAlienCollection::Open(xmlfile);
219   if (!collection) {
220     Error("MakeChainXML", Form("No collection found in %s", xmlfile)) ; 
221     return NULL;
222   }
223   //collection->CheckIfOnline();
224
225   TGridResult* result = collection->GetGridResult("",0 ,0);
226   if(!result->GetEntries()){
227     Error("MakeChainXML", Form("No entries found in %s", xmlfile)) ; 
228     return NULL;
229   }
230   // Makes the ESD chain 
231   TChain* chain = new TChain("esdTree");
232   for (Int_t idx = 0; idx < result->GetEntries(); idx++) {
233     chain->Add(result->GetKey(idx, "turl")); 
234   }
235   return chain;
236 }
237
238 //______________________________________________________
239 Bool_t UseMC(Char_t *opt){
240   return !(Bool_t)strstr(opt, "NOMC");
241 }
242
243 //____________________________________________
244 Bool_t UseFriends(Char_t *opt){
245   return !(Bool_t)strstr(opt, "NOFR");
246 }