]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/TRD/run.C
Fix coverity issues
[u/mrichter/AliRoot.git] / PWGPP / TRD / run.C
1 // Steer TRD QA train for Reconstruction (Clusterizer, Tracking and PID).
2 // 
3 // Usage:Char_t *optList="ALL", Int_t run, const Char_t *files=NULL, Long64_t nev=1234567890, Long64_t first = 0
4 //   run.C(optList, run, files, nev, first)
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 //     run   : run number [default 0]; if negative value is specified the OCDB connection is left to AddTRDinfoGen.C
23 //     files : the list of ESD files to be processed [default AliESds.root from cwd]
24 //     nev   : number of events to be processed [default all]
25 //     first : first event to process [default 0]
26 //
27 // In compiled mode :
28 // Don't forget to load first the libraries
29 // gSystem->Load("libMemStat.so")
30 // gSystem->Load("libMemStatGui.so")
31 // gSystem->Load("libANALYSIS.so")
32 // gSystem->Load("libANALYSISalice.so")
33 // gSystem->Load("libTENDER.so");
34 // gSystem->Load("libCORRFW.so");
35 // gSystem->Load("libPWGPP.so");
36 // gSystem->Load("libPWGmuon.so");
37 // gSystem->Load("libNetx.so") ;
38 // gSystem->Load("libRAliEn.so");
39 //
40 // Authors:
41 //   Alex Bercuci (A.Bercuci@gsi.de) 
42 //   Markus Fasel (m.Fasel@gsi.de) 
43
44 #if ! defined (__CINT__) || defined (__MAKECINT__)
45 //#ifndef __CINT__
46 #include <Riostream.h>
47
48 #include "TStopwatch.h"
49 #include "TMemStat.h"
50 #include "TMemStatViewerGUI.h"
51
52 #include "TGrid.h"
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=0, 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("libCORRFW.so")<0) return;
110   if(gSystem->Load("libPWGPP.so")<0) return;
111   if(gSystem->Load("libPWGmuon.so")<0) return;
112
113   Bool_t fHasMCdata = UseMC(optList);
114   Bool_t fHasFriends = UseFriends(optList);
115   
116   // DEFINE DATA CHAIN
117   TChain *chain = NULL;
118   if(!files) chain = MakeChainLST();
119   else{
120     TString fn(files);
121     if(fn.EndsWith("xml")) chain = MakeChainXML(files);
122     else chain = MakeChainLST(files);
123   }
124   if(!chain) return;
125   chain->Lookup();
126   chain->GetListOfFiles()->Print();
127   Int_t nfound=(Int_t)chain->GetEntries();
128   printf("\tENTRIES FOUND [%d] REQUESTED [%d]\n", nfound, nev>nfound?nfound:nev);
129
130
131   // BUILD ANALYSIS MANAGER
132   AliAnalysisManager *mgr = new AliAnalysisManager("TRD Reconstruction Performance & Calibration");
133   AliESDInputHandlerRP *esdH(NULL);
134   mgr->SetInputEventHandler(esdH = new AliESDInputHandlerRP);
135   if(fHasFriends){
136     esdH->SetReadFriends(kTRUE);
137     esdH->SetActiveBranches("ESDfriend");
138   }
139   AliMCEventHandler *mcH(NULL);
140   if(fHasMCdata) mgr->SetMCtruthEventHandler(mcH = new AliMCEventHandler());
141   //mgr->SetDebugLevel(10);
142   mgr->SetSkipTerminate(kTRUE);
143
144   // add CDB task
145   if(run>=0){
146     gROOT->LoadMacro("$ALICE_ROOT/PWGPP/PilotTrain/AddTaskCDBconnect.C");
147     AliTaskCDBconnect *taskCDB = AddTaskCDBconnect();
148     if (!taskCDB) return;
149     taskCDB->SetRunNumber(run);
150   } else Warning("run.C", "OCDB connection via AliTRDinfoGen.");
151
152   gROOT->LoadMacro("$ALICE_ROOT/PWGPP/macros/AddTrainPerformanceTRD.C");
153   if(!AddTrainPerformanceTRD(optList)) {
154     Error("run.C", "Error loading TRD train.");
155     return;
156   }
157
158   if (!mgr->InitAnalysis()) return;
159   // verbosity
160   printf("\tRUNNING TRAIN FOR TASKS:\n");
161   TObjArray *taskList=mgr->GetTasks();
162   for(Int_t itask=0; itask<taskList->GetEntries(); itask++){ 
163     AliAnalysisTask *task=(AliAnalysisTask*)taskList->At(itask);
164     printf(" %s [%s]\n", task->GetName(), task->GetTitle());
165   }
166   //mgr->PrintStatus();
167   mgr->StartAnalysis("local", chain, nev, first);
168   timer.Stop();
169   timer.Print();  
170
171   // verbosity
172   printf("\tCLEANING TASK LIST:\n");
173   mgr->GetTasks()->Delete();
174
175   if(mcH) delete mcH;
176   delete esdH;
177   delete chain;
178   if(MEM) delete mem;
179   if(MEM) TMemStatViewerGUI::ShowGUI();
180 }
181
182 //____________________________________________
183 TChain* MakeChainLST(const char* filename)
184 {
185   // Create the chain
186   TChain* chain = new TChain("esdTree");
187   if(!filename){
188     chain->Add(Form("%s/AliESDs.root", gSystem->pwd()));
189     return chain;
190   }
191
192
193   // read ESD files from the input list.
194   FILE *fp(NULL);
195   if(!(fp = fopen(filename, "rt"))){
196     Error("run::MakeChainLST()", Form("Input list \"%s\" not readable", filename));
197     return NULL;
198   }
199   TString esdFile;
200   while(esdFile.Gets(fp)){
201     if (!esdFile.Contains("root")) continue; // protection
202     if(esdFile.BeginsWith("alien://") && !gGrid){
203       if(gSystem->Load("libNetx.so")<0) return NULL;
204       if(gSystem->Load("libRAliEn.so")<0) return NULL;
205       TGrid::Connect("alien://");
206     }
207     chain->Add(esdFile.Data());
208   }
209   fclose(fp);
210
211   return chain;
212 }
213
214 //____________________________________________
215 TChain* MakeChainXML(const char* xmlfile)
216 {
217   if (!TFile::Open(xmlfile)) {
218     Error("MakeChainXML", Form("No file %s was found", xmlfile));
219     return NULL;
220   }
221
222   if(gSystem->Load("libNetx.so")<0) return NULL;
223   if(gSystem->Load("libRAliEn.so")<0) return NULL;
224   TGrid::Connect("alien://") ;
225
226   TGridCollection *collection = (TGridCollection*) TAlienCollection::Open(xmlfile);
227   if (!collection) {
228     Error("MakeChainXML", Form("No collection found in %s", xmlfile)) ; 
229     return NULL;
230   }
231   //collection->CheckIfOnline();
232
233   TGridResult* result = collection->GetGridResult("",0 ,0);
234   if(!result->GetEntries()){
235     Error("MakeChainXML", Form("No entries found in %s", xmlfile)) ; 
236     return NULL;
237   }
238   // Makes the ESD chain 
239   TChain* chain = new TChain("esdTree");
240   for (Int_t idx = 0; idx < result->GetEntries(); idx++) {
241     chain->Add(result->GetKey(idx, "turl")); 
242   }
243   return chain;
244 }
245
246 //______________________________________________________
247 Bool_t UseMC(Char_t *opt){
248   return !(Bool_t)strstr(opt, "NOMC");
249 }
250
251 //____________________________________________
252 Bool_t UseFriends(Char_t *opt){
253   return !(Bool_t)strstr(opt, "NOFR");
254 }