]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/macros/sim-hlt-tpc.C
bugfix: correcting the condition for the check for the local GRP entry added before...
[u/mrichter/AliRoot.git] / HLT / TPCLib / macros / sim-hlt-tpc.C
1 // $Id$
2 /*
3  * @file sim-hlt-tpc.C
4  * @brief HLT Conformal mapping tracker embedded into AliRoot simulation.
5  *
6  * Example macro to run the HLT Conformal mapping tracker embedded into
7  * AliRoot simulation. The reconstruction is done from the TPC digits.
8  *
9  * Usage: aliroot -b -q sim-hlt-tpc.C | tee sim-hlt-tpc.log
10  *
11  * The chain to be run is defined within the macro. The input data is
12  * read from the TPC.Digits.
13  *
14  * The following options can be specified comma separated in a string:
15  * <pre>
16  *   aliroot -b -q sim-hlt-tpc.C'("options")'
17  *       CA      use the cellular automaton  tracker and track merger
18  *       CM      use the conformal mapping tracker and track merger
19  *       SORTED  use CF pre-sorting and corresponding sequential CF
20  *               algorithm, by default the algorithm capable of reading
21  *               unsorted data is used
22  *       RAW     write raw data for all detectors
23  *       RAWHLT  write raw data only for HLT
24  *       MC      propagate the MC information
25  * </pre>
26  *
27  * The macro asumes the data to be already simulated. If it should run
28  * within the initial simulation, comment the corresponding functions
29  * below (SetRunGeneration etc.)
30  *
31  * @author Matthias.Richter@ift.uib.no
32  * @ingroup alihlt_tpc
33  */
34 sim_hlt_tpc(const char* options="CA")
35 {
36   // this is just a tool to switch the logging systems
37   AliHLTLogging log;
38   //log.SwitchAliLog(0);
39
40   ///////////////////////////////////////////////////////////////////////////////////////////////////
41   ///////////////////////////////////////////////////////////////////////////////////////////////////
42   ///////////////////////////////////////////////////////////////////////////////////////////////////
43   //
44   // scanning the options
45   //
46   bool bUseCA=true;   // use the CA tracker and merger
47   bool bCFSort=false; // CF pre-sorting and sequential CF algorithm
48   bool bRawData=false;// raw data for all detectors
49   bool bRawHLTData=false; // raw data only for HLT
50   bool bPropagateMC=false;
51   TString tsOptions=options;
52   TObjArray* pTokens=tsOptions.Tokenize(",");
53   if (pTokens) {
54     for (int n=0; n<pTokens->GetEntries(); n++) {
55       TString arg=((TObjString*)pTokens->At(n))->GetString();
56       if (arg.CompareTo("ca", TString::kIgnoreCase)==0) {
57         bUseCA=true;
58       } else if (arg.CompareTo("cm", TString::kIgnoreCase)==0) {
59         bUseCA=false;
60       } else if (arg.CompareTo("sorted", TString::kIgnoreCase)==0) {
61         bCFSort=true;
62       } else if (arg.CompareTo("unsorted", TString::kIgnoreCase)==0) {
63         bCFSort=false;
64       } else if (arg.CompareTo("raw", TString::kIgnoreCase)==0) {
65         bRawData=true;
66       } else if (arg.CompareTo("rawhlt", TString::kIgnoreCase)==0) {
67         bRawHLTData=true;
68       } else if (arg.CompareTo("mc", TString::kIgnoreCase)==0) {
69         bPropagateMC=true;
70       } else {
71         cout << "unknown argument: " << arg << endl;
72         return 0;
73       }
74     }
75     delete pTokens;
76   }
77   // summary
78   cout << "using " << bUseCA?"CA":"CM" << " tracker" << endl;
79   
80   ///////////////////////////////////////////////////////////////////////////////////////////////////
81   ///////////////////////////////////////////////////////////////////////////////////////////////////
82   ///////////////////////////////////////////////////////////////////////////////////////////////////
83   //
84   // init the HLT system in order to define the analysis chain below
85   //
86   AliHLTSystem* gHLT=AliHLTPluginBase::GetInstance();
87
88   ///////////////////////////////////////////////////////////////////////////////////////////////////
89   ///////////////////////////////////////////////////////////////////////////////////////////////////
90   ///////////////////////////////////////////////////////////////////////////////////////////////////
91   //
92   // define the analysis chain
93   //
94
95   // load TPCParam from OCDB
96   const char* cdbEntry="TPC/Calib/Parameters";
97   AliCDBManager* pMan=AliCDBManager::Instance();
98   AliTPCParam* pTPCParam=NULL;
99   if (pMan) {
100     if (!pMan->IsDefaultStorageSet()) {
101       pMan->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
102       pMan->SetRun(0);
103     }
104     AliCDBEntry *pEntry = pMan->Get(cdbEntry);
105     if (pEntry && 
106         pEntry->GetObject() &&
107         (pTPCParam=dynamic_cast<AliTPCParam*>(pEntry->GetObject()))) {
108     } else {
109       HLTWarning("can not load AliTPCParam from CDB entry %s", cdbEntry);
110     }
111   }
112
113   int iMinSlice=0; 
114   int iMaxSlice=35;
115   int iMinPart=0;
116   int iMaxPart=5;
117   TString mergerInput;
118   TString writerInput;
119   TString sinkClusterInput;
120   for (int slice=iMinSlice; slice<=iMaxSlice; slice++) {
121     TString trackerInput;
122     for (int part=iMinPart; part<=iMaxPart; part++) {
123       TString arg, publisher, cf;
124
125       // digit publisher components
126       arg.Form("-slice %d -partition %d", slice, part);
127       publisher.Form("DP_%02d_%d", slice, part);
128       AliHLTConfiguration pubconf(publisher.Data(), "TPCDigitPublisher", NULL , arg.Data());
129
130       // cluster finder components
131       arg="-timebins ";
132       if (pTPCParam) arg+=pTPCParam->GetMaxTBin()+1;
133       else arg+=446; // old simulated data
134       if (bCFSort) arg+=" -sorted ";
135       if (bPropagateMC) arg+=" -do-mc ";
136       cf.Form("CF_%02d_%d", slice, part);
137       AliHLTConfiguration cfconf(cf.Data(), "TPCClusterFinderUnpacked", publisher.Data(), arg.Data());
138       if (trackerInput.Length()>0) trackerInput+=" ";
139       trackerInput+=cf;
140       if (sinkClusterInput.Length()>0) sinkClusterInput+=" ";
141       sinkClusterInput+=cf;
142     }
143
144     TString tracker;
145     // tracker finder components
146     tracker.Form("TR_%02d", slice);
147     if (bUseCA) {
148       AliHLTConfiguration trackerconf(tracker.Data(), "TPCCATracker", trackerInput.Data(), "");
149     } else {
150       AliHLTConfiguration trackerconf(tracker.Data(), "TPCSliceTracker", trackerInput.Data(), "-pp-run");
151     }
152
153     //add all trackers to writer input. Include if you would like all slice tracks written.
154     //if (writerInput.Length()>0) writerInput+=" ";
155     //writerInput+=tracker;
156
157     // add all clusterfinders to the writer input
158     if (writerInput.Length()>0) writerInput+=" ";
159     writerInput+=trackerInput;
160
161     if (mergerInput.Length()>0) mergerInput+=" ";
162     mergerInput+=tracker;
163
164   }
165
166   // GlobalMerger component
167   if (bUseCA) {
168     AliHLTConfiguration mergerconf("globalmerger","TPCCAGlobalMerger",mergerInput.Data(),"");
169   } else {
170     AliHLTConfiguration mergerconf("globalmerger","TPCGlobalMerger",mergerInput.Data(),"");
171   }
172
173   // collector for the MC information to be propagated from CFs to ESDConverter
174   AliHLTConfiguration mcinfo("mcinfo", "BlockFilter"   , sinkClusterInput.Data(), "-datatype 'CLMCINFO' 'TPC '");
175
176   if (writerInput.Length()>0) writerInput+=" ";
177   writerInput+="globalmerger";
178
179   TString converterInput="globalmerger";
180   if (bPropagateMC) converterInput+=" mcinfo";
181
182   //////////////////////////////////////////////////////////////////////////////////////////
183   //
184   // output section
185   //
186
187   //////////////////////////////////////////////////////////////////////////////////////////
188   // sink1: id=sink-writeall write all blocks
189   AliHLTConfiguration sink1("sink-writeall", "FileWriter"   , writerInput.Data(), "-specfmt -subdir=event_%d -blcknofmt=_0x%x -idfmt=_0x%08x");
190
191
192   //////////////////////////////////////////////////////////////////////////////////////////
193   // sink2: id=sink-esd-file write ESD using the TPCEsdWriter
194   AliHLTConfiguration sink2("sink-esd-file", "TPCEsdWriter"   , converterInput.Data(), "-datafile AliHLTESDs.root");
195
196
197   //////////////////////////////////////////////////////////////////////////////////////////
198   // sink3: id=sink-esd add ESD to HLTOUT using the TPCEsdConverter
199
200   // the esd converter configuration
201   AliHLTConfiguration sink3("sink-esd", "TPCEsdConverter"   , converterInput.Data(), "");
202
203   //////////////////////////////////////////////////////////////////////////////////////////
204   // sink4: id=sink-clusters add cluster data blocks to HLTOUT
205   AliHLTConfiguration sink4("sink-clusters", "BlockFilter"   , sinkClusterInput.Data(), "-datatype 'CLUSTERS' 'TPC '");
206
207   ///////////////////////////////////////////////////////////////////////////////////////////////////
208   ///////////////////////////////////////////////////////////////////////////////////////////////////
209   ///////////////////////////////////////////////////////////////////////////////////////////////////
210   //
211   // Init and run the HLT simulation
212   // All but HLT simulation is switched off
213   //
214   AliSimulation sim;
215  
216   // switch of simulation and data generation
217   // comment all that stuff to also simulate the events and data
218   sim.SetRunGeneration(kFALSE);
219   sim.SetMakeDigits("");
220   sim.SetMakeSDigits("");
221   sim.SetMakeDigitsFromHits("");
222   sim.SetMakeTrigger("");
223   sim.SetRunQA(":");
224
225   // the normal simulation sets the specific storage for the GRP entry
226   if (gSystem->AccessPathName("GRP/GRP/Data")) {
227     cerr << "*********************************************************" << endl;
228     cerr << "error: no GRP entry found in the currect directory, simulation might be incomplete. Skip setting specific storage for GRP entry" << endl;
229     cerr << "*********************************************************" << endl << endl;
230   } else {
231     sim.SetSpecificStorage("GRP/GRP/Data",
232                            Form("local://%s",gSystem->pwd()));
233   }
234
235   TString rawDataSelection="HLT";
236   if (bRawData) rawDataSelection="ALL";
237   if (bRawHLTData || bRawData) sim.SetWriteRawData(rawDataSelection, "raw.root", kTRUE);
238
239   // set the options for the HLT simulation
240   sim.SetRunHLT("libAliHLTUtil.so libAliHLTTPC.so loglevel=0x7c "
241                 "chains=sink-esd,sink-clusters");
242   sim.Run();
243 }