-Added base Calo QA class.
[u/mrichter/AliRoot.git] / PWG1 / TRD / run.C
CommitLineData
1ee39b3a 1// Steer TRD QA train for Reconstruction (Clusterizer, Tracking and PID).
2//
3// Usage:
4// run.C(tasks, files)
5// tasks : "ALL" or one/more of the following:
6// "EFF" : TRD Tracking Efficiency
7// "EFFC" : TRD Tracking Efficiency Combined (barrel + stand alone) - only in case of simulations
8// "MULT" : TRD single track selection
9// "RES" : TRD tracking Resolution
10// "CLRES": clusters Resolution
11// "CAL" : TRD calibration
12// "ALGN" : TRD alignment
13// "PID" : TRD PID - pion efficiency
14// "PIDR" : TRD PID - reference data
15// "DET" : Basic TRD Detector checks
16// "NOFR" : Data set does not have AliESDfriends.root
17// "NOMC" : Data set does not have Monte Carlo Informations (real data), so all tasks which rely
18// on MC information are switched off
19//
20// In compiled mode :
21// Don't forget to load first the libraries
22// gSystem->Load("libMemStat.so")
23// gSystem->Load("libMemStatGui.so")
24// gSystem->Load("libANALYSIS.so")
25// gSystem->Load("libANALYSISalice.so")
1ee39b3a 26// gSystem->Load("libPWG1.so");
27// gSystem->Load("libNetx.so") ;
28// gSystem->Load("libRAliEn.so");
29//
30// Authors:
31// Alex Bercuci (A.Bercuci@gsi.de)
32// Markus Fasel (m.Fasel@gsi.de)
33
34#if ! defined (__CINT__) || defined (__MAKECINT__)
35//#ifndef __CINT__
36#include <Riostream.h>
37
38#include "TStopwatch.h"
39#include "TMemStat.h"
40#include "TMemStatViewerGUI.h"
41
42#include "TROOT.h"
43#include "TClass.h"
44#include "TSystem.h"
45#include "TError.h"
46#include "TChain.h"
47#include "TGrid.h"
48#include "TAlienCollection.h"
49#include "TGridCollection.h"
50#include "TGridResult.h"
51#include "TGeoGlobalMagField.h"
52
53#include "AliMagF.h"
54#include "AliTracker.h"
55#include "AliLog.h"
56#include "AliCDBManager.h"
57#include "AliGRPManager.h"
58#include "AliGeomManager.h"
59#include "AliAnalysisManager.h"
60#include "AliAnalysisDataContainer.h"
61#include "AliMCEventHandler.h"
62#include "AliESDInputHandler.h"
63
64#include "TRD/AliTRDtrackerV1.h"
65#include "TRD/AliTRDcalibDB.h"
66
d4f4bb29 67#include "PWG1/TRD/macros/AliTRDperformanceTrain.h"
68#include "PWG1/TRD/macros/AddTRDcheckESD.C"
69#include "PWG1/TRD/macros/AddTRDinfoGen.C"
70#include "PWG1/TRD/macros/AddTRDcheckDET.C"
71#include "PWG1/TRD/macros/AddTRDefficiency.C"
72#include "PWG1/TRD/macros/AddTRDresolution.C"
73#include "PWG1/TRD/macros/AddTRDcheckPID.C"
1ee39b3a 74
1ee39b3a 75#endif
76
d4f4bb29 77#include "macros/AliTRDperformanceTrain.h"
1ee39b3a 78
79
80Bool_t MEM = kFALSE;
81
82TChain* MakeChainLST(const char* filename = 0x0);
83TChain* MakeChainXML(const char* filename = 0x0);
523a3d00 84void run(Char_t *optList="ALL", const Char_t *files=0x0, Long64_t nev=1234567890, Long64_t first = 0, Int_t runNo=0, const Char_t *ocdb_uri="local://$ALICE_ROOT/OCDB", const Char_t *grp_uri=Form("local://%s", gSystem->pwd()))
1ee39b3a 85{
86 TMemStat *mem = 0x0;
87 if(MEM){
5bb83ff3 88 if(gSystem->Load("libMemStat.so")<0) return;
89 if(gSystem->Load("libMemStatGui.so")<0) return;
1ee39b3a 90 mem = new TMemStat("new, gnubuildin");
91 mem->AddStamp("Start");
92 }
93 TStopwatch timer;
94 timer.Start();
95
1ee39b3a 96 // VERY GENERAL SETTINGS
97 AliLog::SetGlobalLogLevel(AliLog::kError);
98 if(gSystem->Load("libANALYSIS.so")<0) return;
99 if(gSystem->Load("libANALYSISalice.so")<0) return;
c732f879 100 if(gSystem->Load("libTENDER.so")<0) return;
d4f4bb29 101 if(gSystem->Load("libPWG1.so")<0) return;
1ee39b3a 102
523a3d00 103 Bool_t fHasMCdata = HasReadMCData(optList);
104 Bool_t fHasFriends = HasReadFriendData(optList);
1ee39b3a 105
106 // INITIALIZATION OF RUNNING ENVIRONMENT
1ee39b3a 107 // initialize OCDB manager
108 AliCDBManager *cdbManager = AliCDBManager::Instance();
523a3d00 109 cdbManager->SetDefaultStorage(ocdb_uri);
110 if(!cdbManager->IsDefaultStorageSet()){
111 Error("run.C", "Error setting OCDB.");
112 return;
113 }
114 cdbManager->SetRun(runNo);
115 cdbManager->SetSpecificStorage("GRP/GRP/Data", grp_uri);
1ee39b3a 116 cdbManager->SetCacheFlag(kFALSE);
117 // initialize magnetic field from the GRP manager.
118 AliGRPManager grpMan;
523a3d00 119 if(!grpMan.ReadGRPEntry()) return;
120 if(!grpMan.SetMagField()) return;
1ee39b3a 121 //AliRunInfo *runInfo = grpMan.GetRunInfo();
122 AliGeomManager::LoadGeometry();
123
1ee39b3a 124 // DEFINE DATA CHAIN
125 TChain *chain = 0x0;
126 if(!files) chain = MakeChainLST();
127 else{
128 TString fn(files);
129 if(fn.EndsWith("xml")) chain = MakeChainXML(files);
130 else chain = MakeChainLST(files);
131 }
132 if(!chain) return;
1ee39b3a 133 chain->Lookup();
134 chain->GetListOfFiles()->Print();
f2e89a4c 135 Int_t nfound=(Int_t)chain->GetEntries();
136 printf("\tENTRIES FOUND [%d] REQUESTED [%d]\n", nfound, nev>nfound?nfound:nev);
1ee39b3a 137
138
139 // BUILD ANALYSIS MANAGER
5bb83ff3 140 AliAnalysisManager *mgr = new AliAnalysisManager("TRD Reconstruction Performance & Calibration");
265a93da 141 AliESDInputHandlerRP *esdH(NULL);
142 mgr->SetInputEventHandler(esdH = new AliESDInputHandlerRP);
143 esdH->SetReadFriends(kTRUE);
144 esdH->SetActiveBranches("ESDfriend");
145 AliMCEventHandler *mcH(NULL);
1ee39b3a 146 if(fHasMCdata) mgr->SetMCtruthEventHandler(mcH = new AliMCEventHandler());
147 //mgr->SetDebugLevel(10);
148
d4f4bb29 149 gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTrainPerformanceTRD.C");
c3ebe2ae 150 if(!AddTrainPerformanceTRD(optList)) {
d4f4bb29 151 Error("run.C", "Error loading TRD train.");
152 return;
1ee39b3a 153 }
154
155 if (!mgr->InitAnalysis()) return;
156 // verbosity
5bb83ff3 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 }
b91fdd71 163 //mgr->PrintStatus();
1ee39b3a 164 mgr->StartAnalysis("local", chain, nev, first);
165
166 timer.Stop();
167 timer.Print();
168
1ee39b3a 169 delete cdbManager;
170
171 // verbosity
5bb83ff3 172 printf("\tCLEANING TASK LIST:\n");
1ee39b3a 173 mgr->GetTasks()->Delete();
174
175 if(mcH) delete mcH;
176 delete esdH;
1ee39b3a 177 delete chain;
178 if(MEM) delete mem;
179 if(MEM) TMemStatViewerGUI::ShowGUI();
180}
181
182//____________________________________________
183TChain* MakeChainLST(const char* filename)
184{
185 // Create the chain
186 TChain* chain = new TChain("esdTree");
187
188 if(!filename){
189 chain->Add(Form("%s/AliESDs.root", gSystem->pwd()));
190 return chain;
191 }
192
193
194 // read ESD files from the input list.
195 ifstream in;
196 in.open(filename);
197 TString esdfile;
198 while(in.good()) {
199 in >> esdfile;
200 if (!esdfile.Contains("root")) continue; // protection
201 chain->Add(esdfile.Data());
202 }
203
204 in.close();
205
206 return chain;
207}
208
209//____________________________________________
210TChain* MakeChainXML(const char* xmlfile)
211{
212 if (!TFile::Open(xmlfile)) {
213 Error("MakeChainXML", Form("No file %s was found", xmlfile));
214 return 0x0;
215 }
216
217 if(gSystem->Load("libNetx.so")<0) return 0x0;
218 if(gSystem->Load("libRAliEn.so")<0) return 0x0;
219 TGrid::Connect("alien://") ;
220
221 TGridCollection *collection = (TGridCollection*) TAlienCollection::Open(xmlfile);
222 if (!collection) {
223 Error("MakeChainXML", Form("No collection found in %s", xmlfile)) ;
224 return 0x0;
225 }
226 //collection->CheckIfOnline();
227
228 TGridResult* result = collection->GetGridResult("",0 ,0);
229 if(!result->GetEntries()){
230 Error("MakeChainXML", Form("No entries found in %s", xmlfile)) ;
231 return 0x0;
232 }
233 // Makes the ESD chain
234 TChain* chain = new TChain("esdTree");
235 for (Int_t idx = 0; idx < result->GetEntries(); idx++) {
236 chain->Add(result->GetKey(idx, "turl"));
237 }
238 return chain;
239}