last modification of the task before going into production
[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
48797466 119 Int_t fSteerTask = 0;
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){
48797466 123 for(Int_t itask = 0; 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;
48797466 133 SETBIT(fSteerTask, itask); SETBIT(fSteerTask, 0);
28efdace 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
48797466 189 if(TSTBIT(fSteerTask, kInfoGen)){
190 mgr->AddTask(task = new AliTRDtrackInfoGen());
191 taskPtr[(Int_t)kInfoGen] = task;
192 task->SetDebugLevel(0);
193 task->SetMCdata(fHasMCdata);
194 mgr->ConnectInput( task, 0, mgr->GetCommonInputContainer());
195 AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("trackInfo", TObjArray::Class(), AliAnalysisManager::kExchangeContainer);
196 AliAnalysisDataContainer *coutput1a = mgr->CreateContainer("eventInfo", AliTRDeventInfo::Class(), AliAnalysisManager::kExchangeContainer);
197 mgr->ConnectOutput(task, 0, coutput1);
198 mgr->ConnectOutput(task, 1, coutput1a);
199 }
814ecea4 200
28efdace 201 //____________________________________________
202 // TRD detector checker
10557e39 203 if(TSTBIT(fSteerTask, kCheckDetector)){
28efdace 204 mgr->AddTask(task = new AliTRDcheckDetector());
205 taskPtr[(Int_t)kCheckDetector] = task;
af735a05 206 task->SetDebugLevel(0);
28efdace 207 task->SetMCdata(fHasMCdata);
208
209 // Create containers for input/output
210 mgr->ConnectInput( task, 0, coutput1);
421fb961 211 mgr->ConnectInput( task, 1, coutput1a);
28efdace 212 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
213 }
214
814ecea4 215 //____________________________________________
216 // TRD barrel tracking efficiency
e15179be 217 if(fHasMCdata && TSTBIT(fSteerTask, kTrackingEff)){
773d3f8c 218 mgr->AddTask(task = new AliTRDtrackingEfficiency());
e15179be 219 taskPtr[(Int_t)kTrackingEff] = task;
3d86166d 220 task->SetDebugLevel(0);
221
77203477 222 //Create containers for input/output
773d3f8c 223 mgr->ConnectInput( task, 0, coutput1);
28efdace 224 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
77203477 225 }
814ecea4 226
227 //____________________________________________
228 // TRD combined tracking efficiency
e15179be 229 if(fHasMCdata && TSTBIT(fSteerTask, kTrackingEffMC)){
773d3f8c 230 mgr->AddTask(task = new AliTRDtrackingEfficiencyCombined());
e15179be 231 taskPtr[(Int_t)kTrackingEffMC] = task;
3d86166d 232 task->SetDebugLevel(0);
773d3f8c 233
77203477 234 // Create containers for input/output
773d3f8c 235 mgr->ConnectInput( task, 0, coutput1);
28efdace 236 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
77203477 237 }
814ecea4 238
77203477 239 //____________________________________________
e26505aa 240 // TRD tracking resolution
e15179be 241 if(TSTBIT(fSteerTask, kResolution)){
773d3f8c 242 mgr->AddTask(task = new AliTRDtrackingResolution());
e15179be 243 taskPtr[(Int_t)kResolution] = task;
3d86166d 244 task->SetMCdata(fHasMCdata);
2b468513 245 task->SetPostProcess(kFALSE);
af735a05 246 task->SetDebugLevel(0);
3d86166d 247
77203477 248 // Create containers for input/output
773d3f8c 249 mgr->ConnectInput( task, 0, coutput1);
28efdace 250 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
b2dc316d 251
5198d8c6 252 // Create output containers for calibration tasks
6fc46cba 253 const Int_t nc = 4;
254 const Char_t *cn[nc] = {"Cl", "Trklt", "MC_Cl", "MC_Trklt"};
5198d8c6 255 AliAnalysisDataContainer *co[nc];
256 for(Int_t ic = 0; ic<nc; ic++){
257 co[ic] = mgr->CreateContainer(Form("%s%s", task->GetName(), cn[ic]), TObjArray::Class(), AliAnalysisManager::kExchangeContainer);
258 mgr->ConnectOutput(task, 1+ic, co[ic]);
259 }
b2dc316d 260
261 // test reconstruction calibration plugin
e15179be 262 if(TSTBIT(fSteerTask, kClErrParam)){
5198d8c6 263 mgr->AddTask(task = new AliTRDclusterResolution());
e15179be 264 taskPtr[(Int_t)kClErrParam] = task;
6bc4a8f4 265 ((AliTRDclusterResolution*)task)->SetExB();
5198d8c6 266 mgr->ConnectInput(task, 0, co[0]);
267 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
268
6fc46cba 269 mgr->AddTask(task = new AliTRDclusterResolution("ClErrParamMC"));
e15179be 270 taskPtr[(Int_t)kClErrParam+1] = task;
6bc4a8f4 271 ((AliTRDclusterResolution*)task)->SetExB();
6fc46cba 272 mgr->ConnectInput(task, 0, co[2]);
273 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
5198d8c6 274 }
77203477 275 }
814ecea4 276
ba2773d0 277 //____________________________________________
278 // TRD calibration
10557e39 279 if(TSTBIT(fSteerTask, kCalibration)){
773d3f8c 280 mgr->AddTask(task = new AliTRDcalibration());
3d86166d 281 taskPtr[(Int_t)kCalibration] = task;
773d3f8c 282 ((AliTRDcalibration*)task)->SetLow(0);
283 ((AliTRDcalibration*)task)->SetHigh(30);
773d3f8c 284 ((AliTRDcalibration*)task)->SetFillZero(kFALSE);
3d86166d 285 task->SetDebugLevel(0);
286
ba2773d0 287 // Create containers for input/output
773d3f8c 288 mgr->ConnectInput(task, 0, coutput1);
28efdace 289 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
ba2773d0 290 }
291
56bb0e8e 292 //____________________________________________
293 // TRD alignment
294 if(TSTBIT(fSteerTask, kAlignment)){
295 mgr->AddTask(task = new AliTRDalignmentTask());
296 taskPtr[(Int_t)kAlignment] = task;
297 task->SetDebugLevel(0);
298
299 // Create containers for input/output
300 mgr->ConnectInput(task, 0, coutput1);
301 mgr->ConnectOutput(task, 0, mgr->CreateContainer(Form("h%s", task->GetName()), TObjArray::Class(), AliAnalysisManager::kExchangeContainer));
302
303 mgr->ConnectOutput(task, 1, mgr->CreateContainer(task->GetName(), TTree::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
304 }
305
773d3f8c 306 //____________________________________________
e15179be 307 // TRD PID
10557e39 308 if(TSTBIT(fSteerTask, kPIDChecker)){
773d3f8c 309 mgr->AddTask(task = new AliTRDpidChecker());
3d86166d 310 taskPtr[(Int_t)kPIDChecker] = task;
311 task->SetDebugLevel(0);
c7cf2032 312 task->SetMCdata(fHasMCdata);
3d86166d 313
773d3f8c 314 // Create containers for input/output
773d3f8c 315 mgr->ConnectInput( task, 0, coutput1);
28efdace 316 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
28efdace 317
e15179be 318 //____________________________________________
319 // TRD pid reference
320 if(TSTBIT(fSteerTask, kPIDRefMaker)){
321 mgr->AddTask(task = new AliTRDpidRefMaker());
322 taskPtr[(Int_t)kPIDRefMaker] = task;
323 task->SetDebugLevel(0);
324 task->SetMCdata(fHasMCdata);
325
326 // Create containers for input/output
327 mgr->ConnectInput( task, 0, coutput1);
328 mgr->ConnectOutput(task, 0, mgr->CreateContainer(task->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%s.root", task->GetName())));
329 mgr->ConnectOutput(task, 1, mgr->CreateContainer(Form("%sNN", task->GetName()), TTree::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%sNN.root", task->GetName())));
330 mgr->ConnectOutput(task, 2, mgr->CreateContainer(Form("%sLQ", task->GetName()), TTree::Class(), AliAnalysisManager::kOutputContainer, Form("TRD.Task%sLQ.root", task->GetName())));
331 }
2b468513 332 }
333
28efdace 334
814ecea4 335 if (!mgr->InitAnalysis()) return;
3d86166d 336 printf("\n\tRUNNING TRAIN FOR TASKS:\n");
e15179be 337 for(Int_t itask = 1; itask < NTRDTASKS; itask++){
338 if(TSTBIT(fSteerTask, itask)) printf("\t %s [%s]\n", taskPtr[itask]->GetName(), taskPtr[itask]->GetTitle());
3d86166d 339 }
340 printf("\n\n");
d85cd79c 341 //mgr->PrintStatus();
819f5b0f 342
af735a05 343 mgr->StartAnalysis("local", chain);
814ecea4 344
345 timer.Stop();
819f5b0f 346 timer.Print();
347
2c0cf367 348 cal->Terminate();
af735a05 349 TGeoGlobalMagField::Instance()->SetField(NULL);
8cc0ed91 350 delete cdbManager;
e15179be 351 for(Int_t it=NTRDTASKS; it--; ){
352 if(taskPtr[it]){
353 printf("Cleaning %s [%s] ...\n", fgkTRDtaskClassName[it], taskPtr[it]->GetTitle());
354 delete taskPtr[it];
355 }
94f34623 356 }
d12237d6 357 delete checkESD;
358
8cc0ed91 359 if(mcH) delete mcH;
360 delete esdH;
361 delete mgr;
362 delete chain;
819f5b0f 363 if(MEM) delete mem;
364 if(MEM) TMemStatViewerGUI::ShowGUI();
814ecea4 365}
8cc0ed91 366
e15179be 367//____________________________________________
368TChain* MakeChainLST(const char* filename)
8cc0ed91 369{
370 // Create the chain
371 TChain* chain = new TChain("esdTree");
372
373 if(!filename){
374 chain->Add(Form("%s/AliESDs.root", gSystem->pwd()));
375 return chain;
376 }
377
378
379 // read ESD files from the input list.
380 ifstream in;
381 in.open(filename);
382 TString esdfile;
e15179be 383 while(in.good()) {
8cc0ed91 384 in >> esdfile;
385 if (!esdfile.Contains("root")) continue; // protection
386 chain->Add(esdfile.Data());
387 }
388
389 in.close();
390
391 return chain;
392}
e15179be 393
394//____________________________________________
395TChain* MakeChainXML(const char* xmlfile)
396{
397 if (!TFile::Open(xmlfile)) {
398 Error("MakeChainXML", Form("No file %s was found", xmlfile));
399 return 0x0;
400 }
401
402 if(gSystem->Load("libNetx.so")<0) return 0x0;
403 if(gSystem->Load("libRAliEn.so")<0) return 0x0;
404 TGrid::Connect("alien://") ;
405
406 TGridCollection *collection = (TGridCollection*) TAlienCollection::Open(xmlfile);
407 if (!collection) {
408 Error("MakeChainXML", Form("No collection found in %s", xmlfile)) ;
409 return 0x0;
410 }
411 //collection->CheckIfOnline();
412
413 TGridResult* result = collection->GetGridResult("",0 ,0);
414 if(!result->GetEntries()){
415 Error("MakeChainXML", Form("No entries found in %s", xmlfile)) ;
416 return 0x0;
417 }
418 // Makes the ESD chain
419 TChain* chain = new TChain("esdTree");
420 for (Int_t idx = 0; idx < result->GetEntries(); idx++) {
421 chain->Add(result->GetKey(idx, "turl"));
422 }
423 return chain;
424}