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