Renaming AliHLTReconstructorBase to AliHLTPluginBase to reflect the
[u/mrichter/AliRoot.git] / HLT / TPCLib / macros / rec-hlt-tpc.C
1 // $Id$
2 /*
3  * Example macro to run the HLT Conformal mapping tracker embedded into
4  * AliRoot reconstruction. The reconstruction is done from the TPC raw
5  * data.
6  *
7  * Usage:
8  * <pre>
9  *   aliroot -b -q rec-hlt-tpc.C | tee rec-hlt-tpc.log
10  *   aliroot -b -q rec-hlt-tpc.C'("./","decoder All")' | tee rec-hlt-tpc.log
11  * </pre>
12  *
13  * The macro asumes raw data to be available in the rawx folders, either
14  * simulated or real data. A different input can be specified as parameter
15  * <pre>
16  *   aliroot -b -q rec-hlt-tpc.C'("input.root")'
17  * </pre>
18  *
19  * The second parameter changes which clusterfinder you use:
20  *    - decoder, uses TPCClusterFinderDecoder. This is default.
21  *    - packed, uses TPCClusterFinderPacked
22  *
23  * Also in the second parameter you can set which output you would like to have:
24  *    - ESD, gives you an ESD file. This is default.
25  *    - TrackHistogram, will run the TrackHistogram component, and give 
26  *      root files with histograms.
27  *    - TrackDump, dumps the track struct to a text file.
28  *    - ClusterHisto, gives you histograms of the cluster.
29  *    - ClusterDump, dumps the cluster struct to text flie.
30  *    - All, gives you all 3 output.
31  *
32  * In the first section, an analysis chain is defined. The scale of the
33  * chain can be defined by choosing the range of sectors and partitions.
34  *
35  * The reconstruction is steered by the AliReconstruction object in the
36  * usual way.
37  *
38  * @ingroup alihlt_tpc
39  * @author Matthias.Richter@ift.uib.no
40  */
41 void rec_hlt_tpc(const char* input="./", char* opt="decoder ESD")
42 {
43   
44   if(!gSystem->AccessPathName("galice.root")){
45     cerr << "please delete the galice.root or run at different place." << endl;
46     return;
47   }
48
49   if (!input) {
50     cerr << "please specify input or run without arguments" << endl;
51     return;
52   }
53
54   ///////////////////////////////////////////////////////////////////////////////////////////////////
55   //
56   // init the HLT system in order to define the analysis chain below
57   //
58   AliHLTSystem* gHLT=AliHLTPluginBase::GetInstance();
59  
60   ///////////////////////////////////////////////////////////////////////////////////////////////////
61   //
62   // Setting up which output to give
63   //
64   Bool_t bUseClusterFinderDecoder=kTRUE;
65   TString option="libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so loglevel=0x7c chains=";
66   Bool_t esdout=kFALSE, dumpout=kFALSE, histout=kFALSE, chout=kFALSE, cdout=kFALSE;
67   TString allArgs=opt;
68   TString argument;
69   TObjArray* pTokens=allArgs.Tokenize(" ");
70   if (pTokens) {
71     for (int i=0; i<pTokens->GetEntries(); i++) {
72       argument=((TObjString*)pTokens->At(i))->GetString();
73       if (argument.IsNull()) continue;
74  
75       if (argument.Contains("-statistics=")) {
76         argument.ReplaceAll("-statistics=", "");
77         if (argument.Contains("root")) {
78           if (option.Length()>0) option+=",";
79           option+="statroot";
80         }
81         if (argument.Contains("raw")) {
82           if (option.Length()>0) option+=",";
83           option+="statraw";
84         }
85         continue;
86       }
87       if (argument.CompareTo("decoder",TString::kIgnoreCase)==0) {
88         bUseClusterFinderDecoder = kTRUE;
89         continue;
90       }
91       if (argument.CompareTo("packed",TString::kIgnoreCase)==0) {
92         bUseClusterFinderDecoder = kFALSE;
93         continue;
94       }
95       if (argument.CompareTo("trackhistogram",TString::kIgnoreCase)==0) {
96         histout = kTRUE;
97         if (option.Length()>0) option+=",";
98         option+="histFile";
99         continue;
100       }
101       if (argument.CompareTo("trackdump",TString::kIgnoreCase)==0) {
102         dumpout = kTRUE;
103         if (option.Length()>0) option+=",";
104         option+="dump";
105         continue;
106       }
107       if (argument.CompareTo("esd",TString::kIgnoreCase)==0) {
108         esdout = kTRUE;
109         if (option.Length()>0) option+=",";
110         option+="sink1";
111         continue;
112       }      
113       if (argument.CompareTo("clusterdump",TString::kIgnoreCase)==0) {
114         cdout = kTRUE;
115         if (option.Length()>0) option+=",";
116         option+="cdump";
117         continue;
118       }      
119       if (argument.CompareTo("clusterhisto",TString::kIgnoreCase)==0) {
120         chout = kTRUE;
121         if (option.Length()>0) option+=",";
122         option+="chhisto";
123         continue;
124       }      
125       if (argument.CompareTo("all",TString::kIgnoreCase)==0) {
126         histout = kTRUE;
127         dumpout = kTRUE;
128         esdout = kTRUE;
129         chout = kTRUE;
130         cdout = kTRUE;
131         if (option.Length()>0) option+=",";
132         option+="sink1,histFile,dump,cdump,chhisto";
133         continue;
134       }
135       else {
136         break;
137       }
138     }
139   }
140   if (!histout && !dumpout && !esdout && !chout && !cdout) {
141     cout << "you need to specify an output option, on or more out of: ESD, TrackHistogram, TrackDump, ClusterHisto, ClusterDump" << endl;
142     return;
143   }
144   if ((option.Contains("statroot") || option.Contains("statraw")) && !esdout) {
145     cout << "!!!!!!!! Warning: HLT statistics are only collected for output type ESD !!!!!!!!" << endl;
146   }
147
148   ///////////////////////////////////////////////////////////////////////////////////////////////////
149   //
150   // define the analysis chain to be run
151   //
152   int iMinSlice=0;
153   int iMaxSlice=35;
154   int iMinPart=0;
155   int iMaxPart=5;
156   TString writerInput;
157   TString mergerInput;
158   TString histoInput;
159   TString histogramHandlerInputClusterFinder;
160   TString cdumpInput;
161   for (int slice=iMinSlice; slice<=iMaxSlice; slice++) {
162     TString trackerInput;
163     for (int part=iMinPart; part<=iMaxPart; part++) {
164       TString arg, publisher, cf;
165       TString clusterHistoOutput;
166       // raw data publisher components
167       int ddlno=768;
168       if (part>1) ddlno+=72+4*slice+(part-2);
169       else ddlno+=2*slice+part;
170       arg.Form("-minid %d -datatype 'DDL_RAW ' 'TPC '  -dataspec 0x%02x%02x%02x%02x -verbose", ddlno, slice, slice, part, part);
171       publisher.Form("DP_%02d_%d", slice, part);
172       AliHLTConfiguration pubconf(publisher.Data(), "AliRawReaderPublisher", NULL , arg.Data());
173
174       // cluster finder components
175       cf.Form("CF_%02d_%d", slice, part);
176       if (bUseClusterFinderDecoder) {
177         AliHLTConfiguration cfconf(cf.Data(), "TPCClusterFinderDecoder", publisher.Data(), "-timebins 1001");
178       } else {
179         AliHLTConfiguration cfconf(cf.Data(), "TPCClusterFinderPacked", publisher.Data(), "-timebins 1001 -sorted");
180       }
181       if (trackerInput.Length()>0) trackerInput+=" ";
182       trackerInput+=cf;
183       if (writerInput.Length()>0) writerInput+=" ";
184       writerInput+=cf;
185       if (histoInput.Length()>0) histoInput+=" ";
186       histoInput+=cf;
187       if (cdumpInput.Length()>0) cdumpInput+=" ";
188       cdumpInput+=cf;
189
190       if(chout){
191         clusterHistoOutput.Form("CH_%02d_%d", slice, part);
192         AliHLTConfiguration cfconf(clusterHistoOutput.Data(), "TPCClusterHisto", cf.Data(), "");
193         if (histogramHandlerInputClusterFinder.Length()>0) histogramHandlerInputClusterFinder+=" ";
194         histogramHandlerInputClusterFinder+=clusterHistoOutput;
195       }
196     }
197     TString tracker;
198     // tracker finder components
199     tracker.Form("TR_%02d", slice);
200     AliHLTConfiguration trackerconf(tracker.Data(), "TPCSliceTracker", trackerInput.Data(), "-pp-run -solenoidBz 0.5");
201     if (writerInput.Length()>0) writerInput+=" ";
202     writerInput+=tracker;
203     if (mergerInput.Length()>0) mergerInput+=" ";
204     mergerInput+=tracker;
205     //add all slice tracks to histo input
206     //if (histoInput.Length()>0) histoInput+=" ";
207     //histoInput+=tracker;
208   }
209
210   // GlobalMerger component
211   AliHLTConfiguration mergerconf("globalmerger","TPCGlobalMerger",mergerInput.Data(),"");
212   
213   //add all global tracks to histo input
214   if (histoInput.Length()>0) histoInput+=" ";
215   histoInput+="globalmerger";
216   
217   // specify whether to write all blocks separately or merge the tracks
218   // and convert to ESD
219   bool writeBlocks=false;
220
221   if(esdout){
222     if (writeBlocks) {
223       // the writer configuration
224       AliHLTConfiguration fwconf("sink1", "FileWriter"   , writerInput.Data(), "-specfmt=_%d -subdir=out_%d -blcknofmt=_0x%x -idfmt=_0x%08x");
225     } else {
226            
227       //AliHLTConfiguration sink("sink1", "TPCEsdWriter"   , "globalmerger", "-datafile AliHLTESDs.root");
228       
229       // the esd converter configuration
230       AliHLTConfiguration esdcconf("esd-converter", "TPCEsdConverter"   , "globalmerger", "");
231       
232       // the root file writer configuration
233       AliHLTConfiguration sink("sink1", "EsdCollector"   , "esd-converter", "-directory hlt-tpc-esd");
234
235       // optional component statistics
236       AliHLTConfiguration statroot("statroot", "StatisticsCollector"   , "esd-converter", "-file HLT.statistics.root -publish 0");
237       AliHLTConfiguration statraw("statraw", "FileWriter"   , "esd-converter", "-datatype COMPSTAT PRIV -datafile HLT.statistics.raw -concatenate-blocks -concatenate-events");
238     }
239   }
240   //Chain with Track Histogram
241   if(histout){
242     AliHLTConfiguration histoconf("histo","TPCTrackHisto",histoInput.Data(),"");  
243     AliHLTConfiguration fwconf("histFile", "ROOTFileWriter"   , "histo", "-datafile TrackHisto -concatenate-events -overwrite");
244   }
245   //Chain with Track Dump
246   if(dumpout){
247     AliHLTConfiguration dumpconf("dump","TPCTrackDump","globalmerger","-directory TrackDump");
248   }
249   if(chout){
250     AliHLTConfiguration cfconf("HHCF", "TPCHistogramHandler", histogramHandlerInputClusterFinder.Data(), "-use-general");
251     AliHLTConfiguration rootFileWriterClusters("chhisto", "ROOTFileWriter", "HHCF" , "-datafile histogramHandlerClusterFinder -concatenate-events -overwrite");
252   }
253   if(cdout){
254     AliHLTConfiguration cdumpconf("cdump","TPCClusterDump",cdumpInput.Data(),"-directory ClusterDump");
255   }
256
257
258   ///////////////////////////////////////////////////////////////////////////////////////////////////
259   //
260   // Init and run the reconstruction
261   // All but HLT reconstructio is switched off
262   //
263   AliReconstruction rec;
264   rec.SetInput(input);
265   rec.SetRunVertexFinder(kFALSE);
266   rec.SetRunLocalReconstruction("HLT");
267   rec.SetRunTracking("");
268   rec.SetLoadAlignFromCDB(0);
269   rec.SetRunQA(":");
270
271   // NOTE: FillESD is a step in the AliReconstruction sequence and has
272   // nothing to do with the fact that this macro writes ESD output
273   // HLT processes the HLTOUT during FillESD and extracts data which
274   // has already been prepared. This step is currently not necessary for
275   // this macro
276   rec.SetFillESD("");
277   rec.SetOption("HLT", option);
278   rec.Run();
279 }