added trigger correlation hardware to offline
[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){
88 gSystem->Load("libMemStat.so");
89 gSystem->Load("libMemStatGui.so");
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();
139 printf("\n ----> CHAIN HAS %d ENTRIES <----\n\n", (Int_t)chain->GetEntries());
140
141
142 // BUILD ANALYSIS MANAGER
143 AliAnalysisManager *mgr = new AliAnalysisManager("Post Reconstruction Calibration/QA");
144 AliVEventHandler *esdH = 0x0, *mcH = 0x0;
145 mgr->SetInputEventHandler(esdH = new AliESDInputHandler);
146 if(fHasMCdata) mgr->SetMCtruthEventHandler(mcH = new AliMCEventHandler());
147 //mgr->SetDebugLevel(10);
148
d4f4bb29 149 gROOT->LoadMacro("$ALICE_ROOT/PWG1/macros/AddTrainPerformanceTRD.C");
523a3d00 150 if(! AddTrainPerformanceTRD(fHasMCdata, fHasFriends, optList)) {
d4f4bb29 151 Error("run.C", "Error loading TRD train.");
152 return;
1ee39b3a 153 }
154
155 if (!mgr->InitAnalysis()) return;
156 // verbosity
157 printf("\n\tRUNNING TRAIN FOR TASKS:\n");
158 mgr->GetTasks()->ls();
159 //mgr->PrintStatus();
160
161 mgr->StartAnalysis("local", chain, nev, first);
162
163 timer.Stop();
164 timer.Print();
165
1ee39b3a 166 TGeoGlobalMagField::Instance()->SetField(NULL);
167 delete cdbManager;
168
169 // verbosity
170 printf("\n\tCLEANING UP TRAIN:\n");
171 mgr->GetTasks()->Delete();
172
173 if(mcH) delete mcH;
174 delete esdH;
175 delete mgr;
176 delete chain;
177 if(MEM) delete mem;
178 if(MEM) TMemStatViewerGUI::ShowGUI();
179}
180
181//____________________________________________
182TChain* MakeChainLST(const char* filename)
183{
184 // Create the chain
185 TChain* chain = new TChain("esdTree");
186
187 if(!filename){
188 chain->Add(Form("%s/AliESDs.root", gSystem->pwd()));
189 return chain;
190 }
191
192
193 // read ESD files from the input list.
194 ifstream in;
195 in.open(filename);
196 TString esdfile;
197 while(in.good()) {
198 in >> esdfile;
199 if (!esdfile.Contains("root")) continue; // protection
200 chain->Add(esdfile.Data());
201 }
202
203 in.close();
204
205 return chain;
206}
207
208//____________________________________________
209TChain* MakeChainXML(const char* xmlfile)
210{
211 if (!TFile::Open(xmlfile)) {
212 Error("MakeChainXML", Form("No file %s was found", xmlfile));
213 return 0x0;
214 }
215
216 if(gSystem->Load("libNetx.so")<0) return 0x0;
217 if(gSystem->Load("libRAliEn.so")<0) return 0x0;
218 TGrid::Connect("alien://") ;
219
220 TGridCollection *collection = (TGridCollection*) TAlienCollection::Open(xmlfile);
221 if (!collection) {
222 Error("MakeChainXML", Form("No collection found in %s", xmlfile)) ;
223 return 0x0;
224 }
225 //collection->CheckIfOnline();
226
227 TGridResult* result = collection->GetGridResult("",0 ,0);
228 if(!result->GetEntries()){
229 Error("MakeChainXML", Form("No entries found in %s", xmlfile)) ;
230 return 0x0;
231 }
232 // Makes the ESD chain
233 TChain* chain = new TChain("esdTree");
234 for (Int_t idx = 0; idx < result->GetEntries(); idx++) {
235 chain->Add(result->GetKey(idx, "turl"));
236 }
237 return chain;
238}