new task to check TRD tracking performances at ESD-MC (only) level.
[u/mrichter/AliRoot.git] / TRD / qaRec / run.C
CommitLineData
77203477 1// Steer TRD QA train for Reconstruction (Clusterizer, Tracking and PID).
2//
3// Usage:
e15179be 4// run.C(tasks, files)
77203477 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// "RES" : TRD tracking Resolution
5198d8c6 9// "CLRES": clusters Resolution
ba2773d0 10// "CAL" : TRD calibration
56bb0e8e 11// "ALGN" : TRD alignment
77203477 12// "PID" : TRD PID - pion efficiency
13// "PIDR" : TRD PID - reference data
2b468513 14// "DET" : Basic TRD Detector checks
28efdace 15// "NOFR" : Data set does not have AliESDfriends.root
4b8f8a35 16// "NOMC" : Data set does not have Monte Carlo Informations (real data), so all tasks which rely
17// on MC information are switched off
2c0cf367 18//
19// In compiled mode :
20// Don't forget to load first the libraries
21// gSystem->Load("libMemStat.so")
22// gSystem->Load("libMemStatGui.so")
23// gSystem->Load("libANALYSIS.so")
24// gSystem->Load("libTRDqaRec.so")
e15179be 25// gSystem->Load("libNetx.so") ;
26// gSystem->Load("libRAliEn.so");
2c0cf367 27//
77203477 28// Authors:
29// Alex Bercuci (A.Bercuci@gsi.de)
30// Markus Fasel (m.Fasel@gsi.de)
31
819f5b0f 32#ifndef __CINT__
8cc0ed91 33#include <Riostream.h>
34
819f5b0f 35#include "TStopwatch.h"
36#include "TMemStat.h"
37#include "TMemStatViewerGUI.h"
38
39#include "TROOT.h"
40#include "TSystem.h"
8cc0ed91 41#include "TError.h"
819f5b0f 42#include "TChain.h"
e15179be 43#include "TGrid.h"
44#include "TAlienCollection.h"
45#include "TGridCollection.h"
46#include "TGridResult.h"
af735a05 47#include "TGeoGlobalMagField.h"
819f5b0f 48
f7a1cc68 49#include "AliMagF.h"
8cc0ed91 50#include "AliTracker.h"
819f5b0f 51#include "AliLog.h"
52#include "AliCDBManager.h"
e15179be 53#include "AliGeomManager.h"
819f5b0f 54#include "AliAnalysisManager.h"
55#include "AliAnalysisDataContainer.h"
8cc0ed91 56#include "AliMCEventHandler.h"
57#include "AliESDInputHandler.h"
819f5b0f 58
8cc0ed91 59#include "TRD/AliTRDtrackerV1.h"
60#include "TRD/AliTRDcalibDB.h"
4c0f3c82 61#include "TRD/qaRec/AliTRDtrackInfo/AliTRDeventInfo.h"
9a281e83 62#include "TRD/qaRec/AliTRDcheckESD.h"
819f5b0f 63#include "TRD/qaRec/AliTRDtrackInfoGen.h"
8cc0ed91 64#include "TRD/qaRec/AliTRDtrackingEfficiency.h"
65#include "TRD/qaRec/AliTRDtrackingEfficiencyCombined.h"
66#include "TRD/qaRec/AliTRDtrackingResolution.h"
67#include "TRD/qaRec/AliTRDcalibration.h"
e15179be 68#include "TRD/qaRec/AliTRDalignmentTask.h"
3d86166d 69#include "TRD/qaRec/AliTRDpidChecker.h"
28efdace 70#include "TRD/qaRec/AliTRDpidRefMaker.h"
2b468513 71#include "TRD/qaRec/AliTRDcheckDetector.h"
5198d8c6 72#include "TRD/qaRec/AliTRDclusterResolution.h"
819f5b0f 73#endif
74
3d86166d 75#include "run.h"
76
819f5b0f 77Bool_t MEM = kFALSE;
8cc0ed91 78
e15179be 79TChain* MakeChainLST(const char* filename = 0x0);
80TChain* MakeChainXML(const char* filename = 0x0);
81void run(Char_t *tasks="ALL", const Char_t *files=0x0)
77203477 82{
819f5b0f 83 TMemStat *mem = 0x0;
8cc0ed91 84 if(MEM){
85 gSystem->Load("libMemStat.so");
86 gSystem->Load("libMemStatGui.so");
87 mem = new TMemStat("new, gnubuildin");
88 mem->AddStamp("Start");
89 }
77203477 90
814ecea4 91 TStopwatch timer;
92 timer.Start();
814ecea4 93
107fde80 94 if(gSystem->Load("libANALYSIS.so")<0) return;
95 if(gSystem->Load("libTRDqaRec.so")<0) return;
77203477 96
6bc4a8f4 97 // DB INITIALIZATION
af735a05 98 //TODO We should use the GRP if available similar to AliReconstruction::InitGRP()!
6bc4a8f4 99 // initialize OCDB manager
100 AliCDBManager *cdbManager = AliCDBManager::Instance();
162637e4 101 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
6bc4a8f4 102 cdbManager->SetRun(0);
103 cdbManager->SetCacheFlag(kFALSE);
af735a05 104 // initialize magnetic field.
105 AliMagF *field = 0x0;
106 field = new AliMagF("Maps","Maps", 2, 1., 10., AliMagF::k5kG);
107 //field = new AliMagF("Maps","Maps", 2, 0., 10., AliMagF::k2kG);
108 TGeoGlobalMagField::Instance()->SetField(field);
6fc46cba 109
6bc4a8f4 110 // initialize TRD settings
111 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
112 AliTRDtrackerV1::SetNTimeBins(cal->GetNumberOfTimeBins());
113 AliGeomManager::LoadGeometry();
114
d2381af5 115 Bool_t fHasMCdata = kTRUE;
28efdace 116 Bool_t fHasFriends = kTRUE;
773d3f8c 117 TObjArray *tasksArray = TString(tasks).Tokenize(" ");
28efdace 118
119 Int_t fSteerTask = 0; SETBIT(fSteerTask, kInfoGen);
773d3f8c 120 for(Int_t isel = 0; isel < tasksArray->GetEntriesFast(); isel++){
121 TString s = (dynamic_cast<TObjString *>(tasksArray->UncheckedAt(isel)))->String();
77203477 122 if(s.CompareTo("ALL") == 0){
e15179be 123 for(Int_t itask = 1; itask < NQATASKS; itask++) SETBIT(fSteerTask, itask);
77203477 124 continue;
28efdace 125 } else if(s.CompareTo("NOFR") == 0){
126 fHasFriends = kFALSE;
127 } else if(s.CompareTo("NOMC") == 0){
d2381af5 128 fHasMCdata = kFALSE;
28efdace 129 } else {
130 Bool_t foundOpt = kFALSE;
e15179be 131 for(Int_t itask = 1; itask < NTRDTASKS; itask++){
4c0f3c82 132 if(s.CompareTo(fgkTRDtaskOpt[itask]) != 0) continue;
28efdace 133 SETBIT(fSteerTask, itask);
134 foundOpt = kTRUE;
135 break;
136 }
137 if(!foundOpt) Info("run.C", Form("Task %s not implemented (yet).", s.Data()));
77203477 138 }
139 }
5198d8c6 140 // extra rules for calibration tasks
e15179be 141 if(TSTBIT(fSteerTask, kClErrParam)) SETBIT(fSteerTask, kResolution);
142 if(TSTBIT(fSteerTask, kPIDRefMaker)) SETBIT(fSteerTask, kPIDChecker);
143 if(TSTBIT(fSteerTask, kAlignment)) SETBIT(fSteerTask, kResolution);
5198d8c6 144
8cc0ed91 145 // define task list pointers;
e15179be 146 AliTRDrecoTask *taskPtr[NTRDTASKS], *task = 0x0;
147 memset(taskPtr, 0, NTRDTASKS*sizeof(AliAnalysisTask*));
8cc0ed91 148
814ecea4 149 //____________________________________________//
e15179be 150 // DEFINE DATA CHAIN
151 TChain *chain = 0x0;
152 if(!files) chain = MakeChainLST();
153 else{
154 TString fn(files);
155 if(fn.EndsWith("xml")) chain = MakeChainXML(files);
156 else chain = MakeChainLST(files);
157 }
158 if(!chain) return;
159
814ecea4 160 //chain->SetBranchStatus("*", 0);
161 chain->SetBranchStatus("*FMD*",0);
162 chain->SetBranchStatus("*Calo*",0);
163 chain->SetBranchStatus("Tracks", 1);
164 chain->SetBranchStatus("ESDfriend*",1);
165 chain->Lookup();
166 chain->GetListOfFiles()->Print();
167 printf("\n ----> CHAIN HAS %d ENTRIES <----\n\n", (Int_t)chain->GetEntries());
168
169 AliLog::SetGlobalLogLevel(AliLog::kError);
170
171 //____________________________________________
172 // Make the analysis manager
af735a05 173 AliAnalysisManager *mgr = new AliAnalysisManager("TRD Reconstruction QA");
814ecea4 174 //mgr->SetSpecialOutputLocation(source); // To Be Changed
8cc0ed91 175 AliVEventHandler *esdH = 0x0, *mcH = 0x0;
176 mgr->SetInputEventHandler(esdH = new AliESDInputHandler);
177 if(fHasMCdata) mgr->SetMCtruthEventHandler(mcH = new AliMCEventHandler());
814ecea4 178 //mgr->SetDebugLevel(10);
179
9a281e83 180 //____________________________________________
181 // TRD check ESD
182 AliTRDcheckESD *checkESD = new AliTRDcheckESD();
183 mgr->AddTask(checkESD);
184 checkESD->SetMC(fHasMCdata);
185 mgr->ConnectInput(checkESD, 0, mgr->GetCommonInputContainer()); mgr->ConnectOutput(checkESD, 0, mgr->CreateContainer(checkESD->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", checkESD->GetName())));
186
814ecea4 187 //____________________________________________
188 // TRD track summary generator
773d3f8c 189 mgr->AddTask(task = new AliTRDtrackInfoGen());
3d86166d 190 taskPtr[(Int_t)kInfoGen] = task;
af735a05 191 task->SetDebugLevel(0);
3d86166d 192 task->SetMCdata(fHasMCdata);
af735a05 193 mgr->ConnectInput( task, 0, mgr->GetCommonInputContainer());
421fb961 194 AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("trackInfo", TObjArray::Class(), AliAnalysisManager::kExchangeContainer);
195 AliAnalysisDataContainer *coutput1a = mgr->CreateContainer("eventInfo", AliTRDeventInfo::Class(), AliAnalysisManager::kExchangeContainer);
773d3f8c 196 mgr->ConnectOutput(task, 0, coutput1);
421fb961 197 mgr->ConnectOutput(task, 1, coutput1a);
814ecea4 198
28efdace 199 //____________________________________________
200 // TRD detector checker
10557e39 201 if(TSTBIT(fSteerTask, kCheckDetector)){
28efdace 202 mgr->AddTask(task = new AliTRDcheckDetector());
203 taskPtr[(Int_t)kCheckDetector] = task;
af735a05 204 task->SetDebugLevel(0);
28efdace 205 task->SetMCdata(fHasMCdata);
206
207 // Create containers for input/output
208 mgr->ConnectInput( task, 0, coutput1);
421fb961 209 mgr->ConnectInput( task, 1, coutput1a);
28efdace 210 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
211 }
212
814ecea4 213 //____________________________________________
214 // TRD barrel tracking efficiency
e15179be 215 if(fHasMCdata && TSTBIT(fSteerTask, kTrackingEff)){
773d3f8c 216 mgr->AddTask(task = new AliTRDtrackingEfficiency());
e15179be 217 taskPtr[(Int_t)kTrackingEff] = task;
3d86166d 218 task->SetDebugLevel(0);
219
77203477 220 //Create containers for input/output
773d3f8c 221 mgr->ConnectInput( task, 0, coutput1);
28efdace 222 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
77203477 223 }
814ecea4 224
225 //____________________________________________
226 // TRD combined tracking efficiency
e15179be 227 if(fHasMCdata && TSTBIT(fSteerTask, kTrackingEffMC)){
773d3f8c 228 mgr->AddTask(task = new AliTRDtrackingEfficiencyCombined());
e15179be 229 taskPtr[(Int_t)kTrackingEffMC] = task;
3d86166d 230 task->SetDebugLevel(0);
773d3f8c 231
77203477 232 // Create containers for input/output
773d3f8c 233 mgr->ConnectInput( task, 0, coutput1);
28efdace 234 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
77203477 235 }
814ecea4 236
77203477 237 //____________________________________________
e26505aa 238 // TRD tracking resolution
e15179be 239 if(TSTBIT(fSteerTask, kResolution)){
773d3f8c 240 mgr->AddTask(task = new AliTRDtrackingResolution());
e15179be 241 taskPtr[(Int_t)kResolution] = task;
3d86166d 242 task->SetMCdata(fHasMCdata);
2b468513 243 task->SetPostProcess(kFALSE);
af735a05 244 task->SetDebugLevel(0);
3d86166d 245
77203477 246 // Create containers for input/output
773d3f8c 247 mgr->ConnectInput( task, 0, coutput1);
28efdace 248 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
b2dc316d 249
5198d8c6 250 // Create output containers for calibration tasks
6fc46cba 251 const Int_t nc = 4;
252 const Char_t *cn[nc] = {"Cl", "Trklt", "MC_Cl", "MC_Trklt"};
5198d8c6 253 AliAnalysisDataContainer *co[nc];
254 for(Int_t ic = 0; ic<nc; ic++){
255 co[ic] = mgr->CreateContainer(Form("%s%s", task->GetName(), cn[ic]), TObjArray::Class(), AliAnalysisManager::kExchangeContainer);
256 mgr->ConnectOutput(task, 1+ic, co[ic]);
257 }
b2dc316d 258
259 // test reconstruction calibration plugin
e15179be 260 if(TSTBIT(fSteerTask, kClErrParam)){
5198d8c6 261 mgr->AddTask(task = new AliTRDclusterResolution());
e15179be 262 taskPtr[(Int_t)kClErrParam] = task;
6bc4a8f4 263 ((AliTRDclusterResolution*)task)->SetExB();
5198d8c6 264 mgr->ConnectInput(task, 0, co[0]);
265 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
266
6fc46cba 267 mgr->AddTask(task = new AliTRDclusterResolution("ClErrParamMC"));
e15179be 268 taskPtr[(Int_t)kClErrParam+1] = task;
6bc4a8f4 269 ((AliTRDclusterResolution*)task)->SetExB();
6fc46cba 270 mgr->ConnectInput(task, 0, co[2]);
271 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
5198d8c6 272 }
77203477 273 }
814ecea4 274
ba2773d0 275 //____________________________________________
276 // TRD calibration
10557e39 277 if(TSTBIT(fSteerTask, kCalibration)){
773d3f8c 278 mgr->AddTask(task = new AliTRDcalibration());
3d86166d 279 taskPtr[(Int_t)kCalibration] = task;
773d3f8c 280 ((AliTRDcalibration*)task)->SetLow(0);
281 ((AliTRDcalibration*)task)->SetHigh(30);
773d3f8c 282 ((AliTRDcalibration*)task)->SetFillZero(kFALSE);
3d86166d 283 task->SetDebugLevel(0);
284
ba2773d0 285 // Create containers for input/output
773d3f8c 286 mgr->ConnectInput(task, 0, coutput1);
28efdace 287 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
ba2773d0 288 }
289
56bb0e8e 290 //____________________________________________
291 // TRD alignment
292 if(TSTBIT(fSteerTask, kAlignment)){
293 mgr->AddTask(task = new AliTRDalignmentTask());
294 taskPtr[(Int_t)kAlignment] = task;
295 task->SetDebugLevel(0);
296
297 // Create containers for input/output
298 mgr->ConnectInput(task, 0, coutput1);
299 mgr->ConnectOutput(task, 0, mgr->CreateContainer(Form("h%s", task->GetName()), TObjArray::Class(), AliAnalysisManager::kExchangeContainer));
300
301 mgr->ConnectOutput(task, 1, mgr->CreateContainer(task->GetName(), TTree::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
302 }
303
773d3f8c 304 //____________________________________________
e15179be 305 // TRD PID
10557e39 306 if(TSTBIT(fSteerTask, kPIDChecker)){
773d3f8c 307 mgr->AddTask(task = new AliTRDpidChecker());
3d86166d 308 taskPtr[(Int_t)kPIDChecker] = task;
309 task->SetDebugLevel(0);
c7cf2032 310 task->SetMCdata(fHasMCdata);
3d86166d 311
773d3f8c 312 // Create containers for input/output
773d3f8c 313 mgr->ConnectInput( task, 0, coutput1);
28efdace 314 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
28efdace 315
e15179be 316 //____________________________________________
317 // TRD pid reference
318 if(TSTBIT(fSteerTask, kPIDRefMaker)){
319 mgr->AddTask(task = new AliTRDpidRefMaker());
320 taskPtr[(Int_t)kPIDRefMaker] = task;
321 task->SetDebugLevel(0);
322 task->SetMCdata(fHasMCdata);
323
324 // Create containers for input/output
325 mgr->ConnectInput( task, 0, coutput1);
326 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
327 mgr->ConnectOutput(task, 1, mgr->CreateContainer(Form("%sNN", task->GetName()), TTree::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%sNN.root", task->GetName())));
328 mgr->ConnectOutput(task, 2, mgr->CreateContainer(Form("%sLQ", task->GetName()), TTree::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%sLQ.root", task->GetName())));
329 }
2b468513 330 }
331
28efdace 332
814ecea4 333 if (!mgr->InitAnalysis()) return;
3d86166d 334 printf("\n\tRUNNING TRAIN FOR TASKS:\n");
e15179be 335 for(Int_t itask = 1; itask < NTRDTASKS; itask++){
336 if(TSTBIT(fSteerTask, itask)) printf("\t %s [%s]\n", taskPtr[itask]->GetName(), taskPtr[itask]->GetTitle());
3d86166d 337 }
338 printf("\n\n");
d85cd79c 339 //mgr->PrintStatus();
819f5b0f 340
af735a05 341 mgr->StartAnalysis("local", chain);
814ecea4 342
343 timer.Stop();
819f5b0f 344 timer.Print();
345
2c0cf367 346 cal->Terminate();
af735a05 347 TGeoGlobalMagField::Instance()->SetField(NULL);
8cc0ed91 348 delete cdbManager;
e15179be 349 for(Int_t it=NTRDTASKS; it--; ){
350 if(taskPtr[it]){
351 printf("Cleaning %s [%s] ...\n", fgkTRDtaskClassName[it], taskPtr[it]->GetTitle());
352 delete taskPtr[it];
353 }
94f34623 354 }
8cc0ed91 355 if(mcH) delete mcH;
356 delete esdH;
357 delete mgr;
358 delete chain;
819f5b0f 359 if(MEM) delete mem;
360 if(MEM) TMemStatViewerGUI::ShowGUI();
814ecea4 361}
8cc0ed91 362
e15179be 363//____________________________________________
364TChain* MakeChainLST(const char* filename)
8cc0ed91 365{
366 // Create the chain
367 TChain* chain = new TChain("esdTree");
368
369 if(!filename){
370 chain->Add(Form("%s/AliESDs.root", gSystem->pwd()));
371 return chain;
372 }
373
374
375 // read ESD files from the input list.
376 ifstream in;
377 in.open(filename);
378 TString esdfile;
e15179be 379 while(in.good()) {
8cc0ed91 380 in >> esdfile;
381 if (!esdfile.Contains("root")) continue; // protection
382 chain->Add(esdfile.Data());
383 }
384
385 in.close();
386
387 return chain;
388}
e15179be 389
390//____________________________________________
391TChain* MakeChainXML(const char* xmlfile)
392{
393 if (!TFile::Open(xmlfile)) {
394 Error("MakeChainXML", Form("No file %s was found", xmlfile));
395 return 0x0;
396 }
397
398 if(gSystem->Load("libNetx.so")<0) return 0x0;
399 if(gSystem->Load("libRAliEn.so")<0) return 0x0;
400 TGrid::Connect("alien://") ;
401
402 TGridCollection *collection = (TGridCollection*) TAlienCollection::Open(xmlfile);
403 if (!collection) {
404 Error("MakeChainXML", Form("No collection found in %s", xmlfile)) ;
405 return 0x0;
406 }
407 //collection->CheckIfOnline();
408
409 TGridResult* result = collection->GetGridResult("",0 ,0);
410 if(!result->GetEntries()){
411 Error("MakeChainXML", Form("No entries found in %s", xmlfile)) ;
412 return 0x0;
413 }
414 // Makes the ESD chain
415 TChain* chain = new TChain("esdTree");
416 for (Int_t idx = 0; idx < result->GetEntries(); idx++) {
417 chain->Add(result->GetKey(idx, "turl"));
418 }
419 return chain;
420}