there have been some changes in the on-line tracklet and GTU track
[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;
133 chain->SetBranchStatus("*FMD*",0);
134 chain->SetBranchStatus("*Calo*",0);
135 chain->SetBranchStatus("Tracks", 1);
136 chain->SetBranchStatus("ESDfriend*",1);
137 chain->Lookup();
138 chain->GetListOfFiles()->Print();
f2e89a4c 139 Int_t nfound=(Int_t)chain->GetEntries();
140 printf("\tENTRIES FOUND [%d] REQUESTED [%d]\n", nfound, nev>nfound?nfound:nev);
1ee39b3a 141
142
143 // BUILD ANALYSIS MANAGER
5bb83ff3 144 AliAnalysisManager *mgr = new AliAnalysisManager("TRD Reconstruction Performance & Calibration");
1ee39b3a 145 AliVEventHandler *esdH = 0x0, *mcH = 0x0;
146 mgr->SetInputEventHandler(esdH = new AliESDInputHandler);
a310e49b 147 //esdH->SetActiveBranches("ESDfriend");
1ee39b3a 148 if(fHasMCdata) mgr->SetMCtruthEventHandler(mcH = new AliMCEventHandler());
149 //mgr->SetDebugLevel(10);
150
d4f4bb29 151 gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTrainPerformanceTRD.C");
c3ebe2ae 152 if(!AddTrainPerformanceTRD(optList)) {
d4f4bb29 153 Error("run.C", "Error loading TRD train.");
154 return;
1ee39b3a 155 }
156
157 if (!mgr->InitAnalysis()) return;
158 // verbosity
5bb83ff3 159 printf("\tRUNNING TRAIN FOR TASKS:\n");
160 TObjArray *taskList=mgr->GetTasks();
161 for(Int_t itask=0; itask<taskList->GetEntries(); itask++){
162 AliAnalysisTask *task=(AliAnalysisTask*)taskList->At(itask);
163 printf(" %s [%s]\n", task->GetName(), task->GetTitle());
164 }
b91fdd71 165 //mgr->PrintStatus();
1ee39b3a 166 mgr->StartAnalysis("local", chain, nev, first);
167
168 timer.Stop();
169 timer.Print();
170
1ee39b3a 171 delete cdbManager;
172
173 // verbosity
5bb83ff3 174 printf("\tCLEANING TASK LIST:\n");
1ee39b3a 175 mgr->GetTasks()->Delete();
176
177 if(mcH) delete mcH;
178 delete esdH;
179 delete mgr;
180 delete chain;
181 if(MEM) delete mem;
182 if(MEM) TMemStatViewerGUI::ShowGUI();
183}
184
185//____________________________________________
186TChain* MakeChainLST(const char* filename)
187{
188 // Create the chain
189 TChain* chain = new TChain("esdTree");
190
191 if(!filename){
192 chain->Add(Form("%s/AliESDs.root", gSystem->pwd()));
193 return chain;
194 }
195
196
197 // read ESD files from the input list.
198 ifstream in;
199 in.open(filename);
200 TString esdfile;
201 while(in.good()) {
202 in >> esdfile;
203 if (!esdfile.Contains("root")) continue; // protection
204 chain->Add(esdfile.Data());
205 }
206
207 in.close();
208
209 return chain;
210}
211
212//____________________________________________
213TChain* MakeChainXML(const char* xmlfile)
214{
215 if (!TFile::Open(xmlfile)) {
216 Error("MakeChainXML", Form("No file %s was found", xmlfile));
217 return 0x0;
218 }
219
220 if(gSystem->Load("libNetx.so")<0) return 0x0;
221 if(gSystem->Load("libRAliEn.so")<0) return 0x0;
222 TGrid::Connect("alien://") ;
223
224 TGridCollection *collection = (TGridCollection*) TAlienCollection::Open(xmlfile);
225 if (!collection) {
226 Error("MakeChainXML", Form("No collection found in %s", xmlfile)) ;
227 return 0x0;
228 }
229 //collection->CheckIfOnline();
230
231 TGridResult* result = collection->GetGridResult("",0 ,0);
232 if(!result->GetEntries()){
233 Error("MakeChainXML", Form("No entries found in %s", xmlfile)) ;
234 return 0x0;
235 }
236 // Makes the ESD chain
237 TChain* chain = new TChain("esdTree");
238 for (Int_t idx = 0; idx < result->GetEntries(); idx++) {
239 chain->Add(result->GetKey(idx, "turl"));
240 }
241 return chain;
242}