]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TRD/macros/rec-hlt-trd.cxx
updating macros (Theo)
[u/mrichter/AliRoot.git] / HLT / TRD / macros / rec-hlt-trd.cxx
CommitLineData
b04a8120 1// This macro is used to simulate the HLT::TRD reconstruction
9d0c6289 2// usage: aliroot rec-hlt-trd.cxx("/data/run/raw.root") reconstruct local raw root file (you might add "alien://" to reconstruct remotely)
3// or: aliroot rec-hlt-trd.cxx("/data/run/") reconstruct local raw ddls *1
4// or copy into folder and aliroot rec-hlt-trd.cxx reconstruct raw.root in pwd
bb90bd84 5//
9d0c6289 6// (*1) here /data/run/ must contain subfolders rawX (be sure to have the last "/" !!)
bb90bd84 7
8#if !defined (__CINT__) || defined (__MAKECINT__)
9
10#include <iostream>
11#include <stdlib.h>
12#include <fstream>
dded75b4 13#include <algorithm>
bb90bd84 14
15#include "TString.h"
16#include "TMath.h"
17
18#include "AliHLTSystem.h"
19#include "AliHLTPluginBase.h"
20#include "AliLog.h"
21#include "AliReconstruction.h"
22#include "AliHLTDataTypes.h"
23#include "AliHLTConfiguration.h"
24
25#include <valgrind/callgrind.h>
26#include <sys/time.h>
27#include "TSystem.h"
9d0c6289 28#include "TFile.h"
29#include "TGrid.h"
30#include "TGridResult.h"
bb90bd84 31
9d0c6289 32#include "AliCDBManager.h"
33#include "AliCDBEntry.h"
34#include "AliTriggerConfiguration.h"
35#include "AliTriggerClass.h"
36#include "AliExternalTrackParam.h"
bb90bd84 37#endif
38
b04a8120 39#include "readCDBentry.h"
dded75b4 40
9d0c6289 41int rec_hlt_trd(const TString input ="raw.root", TString outPath=gSystem->pwd());
42Int_t ExtractRunNumber(const TString str);
bb90bd84 43int main(int argc, char** argv)
44{
9d0c6289 45 if(argc==2) return rec_hlt_trd(argv[1]);
46 else if(argc==3) return rec_hlt_trd(argv[1],argv[2]);
47 else return rec_hlt_trd();
bb90bd84 48}
49
9d0c6289 50int rec_hlt_trd(const TString filename, TString outPath)
bb90bd84 51{
52
53 ///////////////////////////////////////////////////////////////////////////////////////////////////
54 //
55 // define the analysis chain to be run
56 //
57
9d0c6289 58 // What chains should be run? (usually would be: TRD-OffEsdFile)
b04a8120 59 TString chains="TRD-OffEsdFile";
9d0c6289 60
61 // cosmics or not
62 Bool_t bCosmics=kFALSE;
63
64 // look only in data containing TRD triggers?
65 Bool_t useOnlyTRDtrigger=kFALSE;
66
67 // Is the TRD full? (this is only important if ddl files should be read)
dded75b4 68 Bool_t fullTRD=kFALSE;
bb90bd84 69
70 // If not use these SMs:
71 Int_t TRDmodules[18] = {0,1,7,8,9,10,17,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
72
7fdbc17b 73 // Use custom arguments for components?
b04a8120 74 Bool_t customArgs=kFALSE;
9d0c6289 75
76 // Disable HLT flag?
77 Bool_t disableHLTflag=kFALSE;
bb90bd84 78
79 ///////////////////////////////////////////////////////////////////////////////////////////////////
80 //
579d2e0a 81 // set paths
bb90bd84 82 //
9d0c6289 83 TString dataPath = outPath;
84 dataPath.Resize(dataPath.Last('/')+1);
85 if(!dataPath.Length()){
86 dataPath=gSystem->pwd();
87 dataPath+="/";
88 outPath.Prepend(dataPath);
89 }
90
91 TString extInput = filename;
92 dataPath = filename;
93 dataPath.Resize(dataPath.Last('/')+1);
94 if(!dataPath.Length()){
95 dataPath=gSystem->pwd();
96 dataPath+="/";
97 extInput.Prepend(dataPath);
98 }
99
100 printf("File path %s\n",dataPath.Data());
101 printf("Processing file %s\n",extInput.Data());
102 printf("Output to %s\n",outPath.Data());
103
bb90bd84 104 if(!gSystem->AccessPathName("galice.root")){
105 cerr << "please delete the galice.root or run at different place." << endl;
9d0c6289 106 return -1;
bb90bd84 107 }
108
9d0c6289 109 Bool_t bRealData=kFALSE;
110 if(filename.Contains(".root") && !filename.Contains("raw.root")){
111 bRealData = kTRUE;
112 printf("processing real data\n");
113 }else{
114 bRealData = kFALSE;
115 printf("processing simulated data\n");
116 }
117
118 if(filename.Contains("alien://") || bRealData){
119 TGrid::Connect("alien://");
120 }
121
122 if(filename.Contains(".root") && !TFile::Open(filename))return -1;
bb90bd84 123
9d0c6289 124 gSystem->mkdir(outPath.Data());
125 gSystem->ChangeDirectory(outPath.Data());
126
579d2e0a 127 ///////////////////////////////////////////////////////////////////////////////////////////////////
128 //
129 // init the HLT system
130 //
9d0c6289 131 AliHLTSystem* gHLT=AliHLTPluginBase::GetInstance();
132
bb90bd84 133 Int_t usedModules=0;
134 if(fullTRD){
135 usedModules = 18;
136 for(int i=0; i<18; i++)
137 TRDmodules[i]=i;
138 }else{
dded75b4 139#if !defined (__CINT__) || defined (__MAKECINT__)
9d0c6289 140 std::sort((UInt_t*)TRDmodules, ((UInt_t*)TRDmodules) + 18);
dded75b4 141#endif
bb90bd84 142 for(int i=0; i<18; i++)
9d0c6289 143 if(TRDmodules[i]>-1)usedModules++;
bb90bd84 144 }
145
9d0c6289 146 TString option="libAliHLTUtil.so libAliHLTTRD.so libAliHLTMUON.so libAliHLTGlobal.so libAliHLTTrigger.so loglevel=0x7f chains=";
bb90bd84 147 option+=chains;
9d0c6289 148 TString afterTr, afterTrOff, afterCf;
bb90bd84 149
150 for (int module = 0; module < usedModules; module++)
151 {
152 TString arg, publisher, cf, tr, trOff;
153 // raw data publisher components
9d0c6289 154 publisher.Form("TRD-RP_%02d", TRDmodules[module]);
155 arg.Form("-minid %d -datatype 'DDL_RAW ' 'TRD ' -dataspec %i -verbose", TRDmodules[module]+1024, (int)TMath::Power(2,TRDmodules[module]));
bb90bd84 156 AliHLTConfiguration pubConf(publisher.Data(), "AliRawReaderPublisher", NULL , arg.Data());
157
158 // Clusterizer
9d0c6289 159 arg = "";
160 if(customArgs || disableHLTflag){
b04a8120 161 arg = readCDBentry("HLT/ConfigTRD/ClusterizerComponent"); //output_percentage 100 -lowflux -experiment -tailcancellation -faststreamer -yPosMethod LUT
7fdbc17b 162 if(customArgs)
163 arg += "";
9d0c6289 164 if(disableHLTflag)
b04a8120 165 arg += " -HLTflag no";
9d0c6289 166 }
167
168 cf.Form("TRD-CF_%02d", TRDmodules[module]);
169 AliHLTConfiguration cfConf(cf.Data(), "TRDClusterizer", publisher.Data(), arg.Data());
170
171 if (afterCf.Length()>0) afterCf+=" ";
172 afterCf+=cf;
bb90bd84 173
174 // Tracker
9d0c6289 175 arg="";
176 if(customArgs || disableHLTflag){
b04a8120 177 arg = readCDBentry("HLT/ConfigTRD/TrackerV1Component"); //"output_percentage 100 -lowflux -NTimeBins 24";
7fdbc17b 178 if(customArgs)
179 arg += "";
9d0c6289 180 if(disableHLTflag)
b04a8120 181 arg += " -HLTflag no";
9d0c6289 182 }
183
184 tr.Form("TRD-TR_%02d", TRDmodules[module]);
bb90bd84 185 AliHLTConfiguration trConf(tr.Data(), "TRDTrackerV1", cf.Data(), arg.Data());
186
9d0c6289 187 if (afterTr.Length()>0) afterTr+=" ";
188 afterTr+=tr;
189
190 // Offline Tracker (for debug purposes only)
b04a8120 191 arg = readCDBentry("HLT/ConfigTRD/TrackerV1Component"); //"output_percentage 100 -lowflux -NTimeBins 24";
7fdbc17b 192 if(customArgs)
193 arg += " -highLevelOutput yes -emulateHLToutput no";
b04a8120 194 if(disableHLTflag)
195 arg+=" -HLTflag no";
bb90bd84 196
9d0c6289 197 trOff.Form("TRD-TROFF_%02d", TRDmodules[module]);
bb90bd84 198 AliHLTConfiguration trOffConf(trOff.Data(), "TRDOfflineTrackerV1", cf.Data(), arg.Data());
199
9d0c6289 200 if (afterTrOff.Length()>0) afterTrOff+=" ";
201 afterTrOff+=trOff;
bb90bd84 202
203 }
204
9d0c6289 205 // cluster histogramm
206 AliHLTConfiguration histoConf("TRD-ClHisto", "TRDClusterHisto", afterCf.Data(), "");
207 AliHLTConfiguration writerHistoConf( "TRD-ClHistoFile", "ROOTFileWriter", "TRD-ClHisto", "-directory hlt-trd-histo/ -datafile histo.root -concatenate-events -concatenate-blocks");
208
209 // calibration (you may use tr or trOff here)
210 AliHLTConfiguration calibConf("TRD-Calib", "TRDCalibration", afterTr.Data(), "-TrgStr hi -rejectTrgStr");
211 AliHLTConfiguration writerCalibConf( "TRD-CalibFile", "ROOTFileWriter", "TRD-Calib", "-directory hlt-trd-calib/ -datafile calib.root -concatenate-events -concatenate-blocks -write-all-events");
bb90bd84 212
213 // esd converter
9d0c6289 214 AliHLTConfiguration esdConf("TRD-Esd", "GlobalEsdConverter", afterTr.Data(), "-notree");
bb90bd84 215
216 // root file writer
217 AliHLTConfiguration writerConf("TRD-EsdFile", "EsdCollector", "TRD-Esd", "-directory hlt-trd-esd/");
218
9d0c6289 219 // root file writer (with esd friends) (you may use tr or trOff here)
220 AliHLTConfiguration writerOffConf("TRD-OffEsdFile", "TRDEsdWriter", afterTr.Data(), "-concatenate-events -concatenate-blocks");
221
9d0c6289 222 ///////////////////////////////////////////////////////////////////////////////////////////////////
223 //
224 // Init CDBManager and trigger
225 //
226 AliCDBManager * man = AliCDBManager::Instance();
579d2e0a 227 Int_t run = 0;
9d0c6289 228 if(bRealData){
229 man->SetDefaultStorage("alien://folder=/alice/data/2009/OCDB");
7fdbc17b 230 //man->SetDefaultStorage("alien://folder=/alice/data/2009/OCDB?cacheFold=/lustre/alice/local/alice/data/2009/OCDB");
231 //man->SetSpecificStorage("GRP/GRP/Data","alien://folder=/alice/data/2009/OCDB?cacheFold=/lustre/alice/local/alice/data/2009/OCDB");
579d2e0a 232 run = ExtractRunNumber(filename);
9d0c6289 233 }else{
234 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
235 man->SetSpecificStorage("GRP/GRP/Data", Form("local://%s",dataPath.Data()));
236 //rec.SetSpecificStorage("GRP/GRP/Data", Form("local://%s",gSystem->pwd()));
237 }
238 man->SetRun(run);
7fdbc17b 239
9d0c6289 240 if(bCosmics){
241 // no magnetic field
242 AliExternalTrackParam::SetMostProbablePt(8.);
243 }
244
245 // Find TRD triggers
246 TString filestring = filename;
247 if(useOnlyTRDtrigger){
248 AliCDBEntry *grp_ctp = man->Get("GRP/CTP/Config");
249 AliTriggerConfiguration *trg_conf = (AliTriggerConfiguration *)grp_ctp->GetObject();
250 trg_conf->Print();
251 TObjArray trg_masks = trg_conf->GetClasses(); // Reference!!!
252 std::vector<unsigned char> triggerconfs;
253 for(Int_t iobj = 0; iobj < trg_masks.GetEntriesFast(); iobj++){
254
255 AliTriggerClass * trg_class = (AliTriggerClass*)trg_masks.UncheckedAt(iobj);
256 AliTriggerCluster * trg_clust = (AliTriggerCluster *)trg_class->GetCluster();
257
258 printf("ioj[%d]\n", iobj); trg_class->Print(0x0);
7fdbc17b 259
579d2e0a 260 // cosmic run 2009
261 // if(TString(trg_class->GetName()).Contains("TRD")){
262 // triggerconfs.push_back(trg_class->GetMask());
263 // }
264
265 // pp run 2009
266 if(TString(trg_class->GetName()).Contains("CINT1B-ABCE-NOPF-ALL")){
7fdbc17b 267 triggerconfs.push_back(trg_class->GetMask());
9d0c6289 268 }
579d2e0a 269
9d0c6289 270 }
271
272 Int_t itrg = 0;
273 printf("Number of Trigger Clusters including TRD: %d\n", (Int_t)triggerconfs.size());
274 for(std::vector<unsigned char>::iterator it = triggerconfs.begin(); it < triggerconfs.end(); it++)
275 printf("Trigger Mask %d for TRD: %d\n", itrg++, *it);
276 filestring += "?EventType=7";
277 char triggerbuf[256];
278 Int_t triggerval = 0;
279 for(std::vector<unsigned char>::iterator it = triggerconfs.begin(); it < triggerconfs.end(); it++)
280 triggerval += *it;
281 sprintf(triggerbuf, "?Trigger=%d", triggerval);
282 filestring += triggerbuf; // This line does the trigger selection. It has to be uncommented if one wants to apply trigger selection
283 }
284 printf("Filename: %s\n", filestring.Data());
bb90bd84 285
286 ///////////////////////////////////////////////////////////////////////////////////////////////////
287 //
579d2e0a 288 // init and run the reconstruction
bb90bd84 289 //
290 AliReconstruction rec;
9d0c6289 291 rec.SetInput(filestring.Data());
bb90bd84 292 rec.SetRunVertexFinder(kFALSE);
293 rec.SetRunLocalReconstruction("HLT");
294 rec.SetRunTracking(":");
295 rec.SetLoadAlignFromCDB(0);
296 rec.SetFillESD("");
7fdbc17b 297 rec.SetRunQA(":");
bb90bd84 298 rec.SetRunGlobalQA(kFALSE);
299 rec.SetFillTriggerESD(kFALSE);
bb90bd84 300
301 rec.SetOption("HLT", option);
302 rec.Run();
9d0c6289 303
304 return 0;
305}
306
307Int_t ExtractRunNumber(const TString str){
308 TObjArray *ptoks = (TObjArray *)str.Tokenize("?");
309 TString path = ((TObjString *)ptoks->UncheckedAt(0))->String();
310 TObjArray *toks = (TObjArray *)path.Tokenize("/");
311 TString fname = ((TObjString *)(toks->UncheckedAt(toks->GetEntriesFast() - 1)))->String();
312 TString rstr = fname(2,9);
313 return rstr.Atoi();
bb90bd84 314}