copy TRD performance train to PWG1
[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")
26// gSystem->Load("libTRDqaRec.so")
27// gSystem->Load("libPWG1.so");
28// gSystem->Load("libNetx.so") ;
29// gSystem->Load("libRAliEn.so");
30//
31// Authors:
32// Alex Bercuci (A.Bercuci@gsi.de)
33// Markus Fasel (m.Fasel@gsi.de)
34
35#if ! defined (__CINT__) || defined (__MAKECINT__)
36//#ifndef __CINT__
37#include <Riostream.h>
38
39#include "TStopwatch.h"
40#include "TMemStat.h"
41#include "TMemStatViewerGUI.h"
42
43#include "TROOT.h"
44#include "TClass.h"
45#include "TSystem.h"
46#include "TError.h"
47#include "TChain.h"
48#include "TGrid.h"
49#include "TAlienCollection.h"
50#include "TGridCollection.h"
51#include "TGridResult.h"
52#include "TGeoGlobalMagField.h"
53
54#include "AliMagF.h"
55#include "AliTracker.h"
56#include "AliLog.h"
57#include "AliCDBManager.h"
58#include "AliGRPManager.h"
59#include "AliGeomManager.h"
60#include "AliAnalysisManager.h"
61#include "AliAnalysisDataContainer.h"
62#include "AliMCEventHandler.h"
63#include "AliESDInputHandler.h"
64
65#include "TRD/AliTRDtrackerV1.h"
66#include "TRD/AliTRDcalibDB.h"
67
68#include "TRD/qaRec/macros/AliTRDperformanceTrain.h"
69#include "TRD/qaRec/macros/AddTRDcheckESD.C"
70#include "TRD/qaRec/macros/AddTRDinfoGen.C"
71#include "TRD/qaRec/macros/AddTRDcheckDET.C"
72#include "TRD/qaRec/macros/AddTRDefficiency.C"
73#include "TRD/qaRec/macros/AddTRDresolution.C"
74#include "TRD/qaRec/macros/AddTRDcheckPID.C"
75
76#include "PWG1/macros/AddPerformanceTask.C"
77#endif
78
79#include "../../TRD/qaRec/macros/AliTRDperformanceTrain.h"
80#include "../../PWG1/macros/AddPerformanceTask.h"
81
82
83Bool_t MEM = kFALSE;
84
85TChain* MakeChainLST(const char* filename = 0x0);
86TChain* MakeChainXML(const char* filename = 0x0);
87void run(Char_t *trd="ALL", Char_t *tpc="ALL", const Char_t *files=0x0, Long64_t nev=1234567890, Long64_t first = 0)
88{
89 TMemStat *mem = 0x0;
90 if(MEM){
91 gSystem->Load("libMemStat.so");
92 gSystem->Load("libMemStatGui.so");
93 mem = new TMemStat("new, gnubuildin");
94 mem->AddStamp("Start");
95 }
96 TStopwatch timer;
97 timer.Start();
98
99
100
101 // VERY GENERAL SETTINGS
102 AliLog::SetGlobalLogLevel(AliLog::kError);
103 if(gSystem->Load("libANALYSIS.so")<0) return;
104 if(gSystem->Load("libANALYSISalice.so")<0) return;
105
106 Bool_t fHasMCdata = 1;//HasReadMCData(trd);
107 //Bool_t fHasFriends = HasReadFriendData(trd);
108
109 // INITIALIZATION OF RUNNING ENVIRONMENT
110 //TODO We should use the GRP if available similar to AliReconstruction::InitGRP()!
111 // initialize OCDB manager
112 AliCDBManager *cdbManager = AliCDBManager::Instance();
113 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
114 cdbManager->SetSpecificStorage("GRP/GRP/Data", Form("local://%s",gSystem->pwd()));
115 cdbManager->SetRun(0);
116 cdbManager->SetCacheFlag(kFALSE);
117 // initialize magnetic field from the GRP manager.
118 AliGRPManager grpMan;
119 grpMan.ReadGRPEntry();
120 grpMan.SetMagField();
121 //AliRunInfo *runInfo = grpMan.GetRunInfo();
122 AliGeomManager::LoadGeometry();
123
124
125 // DEFINE DATA CHAIN
126 TChain *chain = 0x0;
127 if(!files) chain = MakeChainLST();
128 else{
129 TString fn(files);
130 if(fn.EndsWith("xml")) chain = MakeChainXML(files);
131 else chain = MakeChainLST(files);
132 }
133 if(!chain) return;
134 chain->SetBranchStatus("*FMD*",0);
135 chain->SetBranchStatus("*Calo*",0);
136 chain->SetBranchStatus("Tracks", 1);
137 chain->SetBranchStatus("ESDfriend*",1);
138 chain->Lookup();
139 chain->GetListOfFiles()->Print();
140 printf("\n ----> CHAIN HAS %d ENTRIES <----\n\n", (Int_t)chain->GetEntries());
141
142
143 // BUILD ANALYSIS MANAGER
144 AliAnalysisManager *mgr = new AliAnalysisManager("Post Reconstruction Calibration/QA");
145 AliVEventHandler *esdH = 0x0, *mcH = 0x0;
146 mgr->SetInputEventHandler(esdH = new AliESDInputHandler);
147 if(fHasMCdata) mgr->SetMCtruthEventHandler(mcH = new AliMCEventHandler());
148 //mgr->SetDebugLevel(10);
149
150
151
152///////////////////////////////////////////////////////////
153/////////////// TRD ///////////
154///////////////////////////////////////////////////////////
155 // TRD specific library
156 if(gSystem->Load("libTRDqaRec.so")<0) return;
157 // TRD data containers
158 AliAnalysisDataContainer *ci[] = {0x0, 0x0, 0x0};
159
160
161 // initialize TRD settings
162 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
163 AliTRDtrackerV1::SetNTimeBins(cal->GetNumberOfTimeBins());
164
165 // plug (set of) TRD wagons in the train
166 if(trd){
167 for(Int_t it=0; it<NTRDQATASKS; it++){
168 if(gROOT->LoadMacro(Form("$ALICE_ROOT/TRD/qaRec/macros/Add%s.C+", TString(fgkTRDtaskClassName[it])(3,20).Data()))) {
169 Error("run.C", Form("Error loading %s task.", fgkTRDtaskClassName[it]));
170 return;
171 }
172
173 switch(it){
174 case kCheckESD:
175 AddTRDcheckESD(mgr); break;
176 case kInfoGen:
177 AddTRDinfoGen(mgr, trd, 0x0, ci); break;
178 case kCheckDET:
179 AddTRDcheckDET(mgr, trd, ci); break;
180 case kEfficiency:
181 AddTRDefficiency(mgr, trd, ci); break;
182 case kResolution:
183 AddTRDresolution(mgr, trd, ci); break;
184 case kCheckPID:
185 AddTRDcheckPID(mgr, trd, ci); break;
186 default:
187 Warning("run.C", Form("No performance task registered at slot %d.", it));
188 }
189 }
190 }
191
192///////////////////////////////////////////////////////////
193/////////////// TPC ///////////
194///////////////////////////////////////////////////////////
195 if(gSystem->Load("libPWG1.so")<0) return;
196
197 // BUILD STEERING TASK FOR TPC
198 if(tpc){
199 if(gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddPerformanceTask.C+")) {
200 Error("run.C", "Error loading AliPerformanceTask task.");
201 return;
202 }
203 AddPerformanceTask(mgr, tpc);
204 }
205
206 if (!mgr->InitAnalysis()) return;
207 // verbosity
208 printf("\n\tRUNNING TRAIN FOR TASKS:\n");
209 mgr->GetTasks()->ls();
210 //mgr->PrintStatus();
211
212 mgr->StartAnalysis("local", chain, nev, first);
213
214 timer.Stop();
215 timer.Print();
216
217 cal->Terminate();
218 TGeoGlobalMagField::Instance()->SetField(NULL);
219 delete cdbManager;
220
221 // verbosity
222 printf("\n\tCLEANING UP TRAIN:\n");
223 mgr->GetTasks()->Delete();
224
225 if(mcH) delete mcH;
226 delete esdH;
227 delete mgr;
228 delete chain;
229 if(MEM) delete mem;
230 if(MEM) TMemStatViewerGUI::ShowGUI();
231}
232
233//____________________________________________
234TChain* MakeChainLST(const char* filename)
235{
236 // Create the chain
237 TChain* chain = new TChain("esdTree");
238
239 if(!filename){
240 chain->Add(Form("%s/AliESDs.root", gSystem->pwd()));
241 return chain;
242 }
243
244
245 // read ESD files from the input list.
246 ifstream in;
247 in.open(filename);
248 TString esdfile;
249 while(in.good()) {
250 in >> esdfile;
251 if (!esdfile.Contains("root")) continue; // protection
252 chain->Add(esdfile.Data());
253 }
254
255 in.close();
256
257 return chain;
258}
259
260//____________________________________________
261TChain* MakeChainXML(const char* xmlfile)
262{
263 if (!TFile::Open(xmlfile)) {
264 Error("MakeChainXML", Form("No file %s was found", xmlfile));
265 return 0x0;
266 }
267
268 if(gSystem->Load("libNetx.so")<0) return 0x0;
269 if(gSystem->Load("libRAliEn.so")<0) return 0x0;
270 TGrid::Connect("alien://") ;
271
272 TGridCollection *collection = (TGridCollection*) TAlienCollection::Open(xmlfile);
273 if (!collection) {
274 Error("MakeChainXML", Form("No collection found in %s", xmlfile)) ;
275 return 0x0;
276 }
277 //collection->CheckIfOnline();
278
279 TGridResult* result = collection->GetGridResult("",0 ,0);
280 if(!result->GetEntries()){
281 Error("MakeChainXML", Form("No entries found in %s", xmlfile)) ;
282 return 0x0;
283 }
284 // Makes the ESD chain
285 TChain* chain = new TChain("esdTree");
286 for (Int_t idx = 0; idx < result->GetEntries(); idx++) {
287 chain->Add(result->GetKey(idx, "turl"));
288 }
289 return chain;
290}