]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDReconstructor.cxx
All FMD corrections are now divided into the analysis + adding new corrections
[u/mrichter/AliRoot.git] / TRD / AliTRDReconstructor.cxx
1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
7 * Permission to use, copy, modify and distribute this software and its   *
8 * documentation strictly for non-commercial purposes is hereby granted   *
9 * without fee, provided that the above copyright notice appears in all   *
10 * copies and that both the copyright notice and this permission notice   *
11 * appear in the supporting documentation. The authors make no claims     *
12 * about the suitability of this software for any purpose. It is          *
13 * provided "as is" without express or implied warranty.                  *
14 **************************************************************************/
15
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // Class for TRD reconstruction                                              //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include <TObjString.h>
25 #include <TObjArray.h>
26 #include <TTreeStream.h>
27 #include <TDirectory.h>
28
29 #include "AliRawReader.h"
30
31 #include "AliTRDReconstructor.h"
32 #include "AliTRDclusterizer.h"
33 #include "AliTRDrawData.h"
34 #include "AliTRDdigitsManager.h"
35 #include "AliTRDtrackerV1.h"
36
37 #define SETFLG(n,f) ((n) |= f)
38 #define CLRFLG(n,f) ((n) &= ~f)
39
40 ClassImp(AliTRDReconstructor)
41
42 TClonesArray *AliTRDReconstructor::fgClusters = 0x0;
43 TClonesArray *AliTRDReconstructor::fgTracklets = 0x0;
44 Char_t* AliTRDReconstructor::fgSteerNames[kNsteer] = {
45   "DigitsConversion       "
46  ,"Tail Cancellation      "
47  ,"Clusters LUT           "
48  ,"Clusters GAUSS         "
49  ,"Clusters Sharing       "
50  ,"NN PID                 "
51  ,"8 dEdx slices in ESD   "
52  ,"Write Clusters         "
53  ,"Write Online Tracklets "
54  ,"Drift Gas Argon        "
55  ,"Stand Alone Tracking   "
56  ,"Vertex Constrain       "
57  ,"Tracklet Improve       "
58  ,"HLT Mode              "
59  ,"Cosmic Reconstruction "
60  ,"Process Online Tracklets"
61 };
62 Char_t* AliTRDReconstructor::fgSteerFlags[kNsteer] = {
63   "dc"// digits conversion [false]
64  ,"tc"// apply tail cancellation [true]
65  ,"lut"// look-up-table for cluster shape in the r-phi direction
66  ,"gs"// gauss cluster shape in the r-phi direction
67  ,"sh"// cluster sharing between tracks
68  ,"nn"// PID method in reconstruction (NN) [true]
69  ,"8s"// 8 dEdx slices in ESD [true] 
70  ,"cw"// write clusters [true]
71  ,"tw"// write online tracklets [false]
72  ,"ar"// drift gas [false] - do not update the number of exponentials in the TC !
73  ,"sa"// track seeding (stand alone tracking) [true]
74  ,"vc"// vertex constrain on stand alone track finder [false]
75  ,"ti"// improve tracklets in stand alone track finder [true]
76  ,"hlt"// HLT reconstruction [false]
77  ,"cos"// Cosmic Reconstruction [false]
78  ,"tp"// also use online tracklets for reconstruction [false]
79 };
80 Char_t* AliTRDReconstructor::fgTaskNames[kNtasks] = {
81   "RawReader"
82  ,"Clusterizer"
83  ,"Tracker"
84  ,"PID"
85 };
86 Char_t* AliTRDReconstructor::fgTaskFlags[kNtasks] = {
87   "rr"
88  ,"cl"
89  ,"tr"
90  ,"pd"
91 };
92
93 //_____________________________________________________________________________
94 AliTRDReconstructor::AliTRDReconstructor()
95   :AliReconstructor()
96   ,fSteerParam(0)
97 {
98   // setting default "ON" steering parameters
99   // owner of debug streamers 
100   SETFLG(fSteerParam, kOwner);
101   // write clusters [cw]
102   SETFLG(fSteerParam, kWriteClusters);
103   // track seeding (stand alone tracking) [sa]
104   SETFLG(fSteerParam, kSeeding);
105   // PID method in reconstruction (NN) [nn]
106   SETFLG(fSteerParam, kSteerPID);
107   // number of dEdx slices in the ESD track [8s]
108   SETFLG(fSteerParam, kEightSlices);
109   // vertex constrain for stand alone track finder
110   SETFLG(fSteerParam, kVertexConstrained);
111   // improve tracklets for stand alone track finder
112   SETFLG(fSteerParam, kImproveTracklet);
113   // use look up table for cluster r-phi position
114   SETFLG(fSteerParam, kLUT);
115   // use tail cancellation
116   SETFLG(fSteerParam, kTC);
117
118   memset(fStreamLevel, 0, kNtasks*sizeof(UChar_t));
119   memset(fDebugStream, 0, sizeof(TTreeSRedirector *) * kNtasks);
120   // Xe tail cancellation parameters
121   fTCParams[0] = 1.156; // r1
122   fTCParams[1] = 0.130; // r2
123   fTCParams[2] = 0.114; // c1
124   fTCParams[3] = 0.624; // c2
125   // Ar tail cancellation parameters
126   fTCParams[4] = 6.;    // r1
127   fTCParams[5] = 0.62;  // r2
128   fTCParams[6] = 0.0087;// c1
129   fTCParams[7] = 0.07;  // c2
130 }
131
132 //_____________________________________________________________________________
133 AliTRDReconstructor::AliTRDReconstructor(const AliTRDReconstructor &r)
134   :AliReconstructor(r)
135   ,fSteerParam(r.fSteerParam)
136 {
137   //
138   // Copy constructor
139   //
140
141   memcpy(fStreamLevel, r.fStreamLevel, kNtasks*sizeof(UChar_t));
142   memcpy(fTCParams, r.fTCParams, 8*sizeof(Double_t));
143   memcpy(fDebugStream, r.fDebugStream, sizeof(TTreeSRedirector *) *kNtasks);
144   // ownership of debug streamers is not taken
145   CLRFLG(fSteerParam, kOwner);
146 }
147
148 //_____________________________________________________________________________
149 AliTRDReconstructor::~AliTRDReconstructor()
150 {
151   //
152   // Destructor
153   //
154
155   if(fgClusters) {
156     fgClusters->Delete(); delete fgClusters;
157   }
158   if(fgTracklets) {
159     fgTracklets->Delete(); delete fgTracklets;
160   }
161   if(fSteerParam&kOwner){
162     for(Int_t itask = 0; itask < kNtasks; itask++)
163       if(fDebugStream[itask]) delete fDebugStream[itask];
164   }
165 }
166
167
168 //_____________________________________________________________________________
169 void AliTRDReconstructor::Init(){
170   //
171   // Init Options
172   //
173   SetOption(GetOption());
174   Options(fSteerParam, fStreamLevel);
175 }
176
177 //_____________________________________________________________________________
178 void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader
179               , TTree *digitsTree) const
180 {
181   //
182   // Convert raw data digits into digit objects in a root tree
183   //
184
185   //AliInfo("Convert raw data digits into digit objects [RawReader -> Digit TTree]");
186
187   AliTRDrawData rawData;
188   rawReader->Reset();
189   rawReader->Select("TRD");
190   rawData.OpenOutput();
191   AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
192   manager->MakeBranch(digitsTree);
193   manager->WriteDigits();
194   delete manager;
195
196 }
197
198 //_____________________________________________________________________________
199 void AliTRDReconstructor::Reconstruct(AliRawReader *rawReader
200                                     , TTree *clusterTree) const
201 {
202   //
203   // Reconstruct clusters
204   //
205
206   //AliInfo("Reconstruct TRD clusters from RAW data [RawReader -> Cluster TTree]");
207
208
209   rawReader->Reset();
210   rawReader->Select("TRD");
211
212   // New (fast) cluster finder
213   AliTRDclusterizer clusterer(fgTaskNames[kClusterizer], fgTaskNames[kClusterizer]);
214   clusterer.SetReconstructor(this);
215   clusterer.OpenOutput(clusterTree);
216   clusterer.OpenTrackletOutput();
217   clusterer.SetUseLabels(kFALSE);
218   clusterer.Raw2ClustersChamber(rawReader);
219   
220   if(IsWritingClusters()) return;
221
222   // take over ownership of clusters
223   fgClusters = clusterer.RecPoints();
224   clusterer.SetClustersOwner(kFALSE);
225
226   // take over ownership of online tracklets
227   fgTracklets = clusterer.TrackletsArray();
228   clusterer.SetTrackletsOwner(kFALSE);
229 }
230
231 //_____________________________________________________________________________
232 void AliTRDReconstructor::Reconstruct(TTree *digitsTree
233                                     , TTree *clusterTree) const
234 {
235   //
236   // Reconstruct clusters
237   //
238
239   //AliInfo("Reconstruct TRD clusters from Digits [Digit TTree -> Cluster TTree]");
240
241   AliTRDclusterizer clusterer(fgTaskNames[kClusterizer], fgTaskNames[kClusterizer]);
242   clusterer.SetReconstructor(this);
243   clusterer.OpenOutput(clusterTree);
244   clusterer.ReadDigits(digitsTree);
245   clusterer.MakeClusters();
246
247   if(IsWritingClusters()) return;
248
249   // take over ownership of clusters
250   fgClusters = clusterer.RecPoints();
251   clusterer.SetClustersOwner(kFALSE);
252
253   // take over ownership of online tracklets
254   fgTracklets = clusterer.TrackletsArray();
255   clusterer.SetTrackletsOwner(kFALSE);
256 }
257
258 //_____________________________________________________________________________
259 AliTracker *AliTRDReconstructor::CreateTracker() const
260 {
261   //
262   // Create a TRD tracker
263   //
264
265   //return new AliTRDtracker(NULL);
266   AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
267   tracker->SetReconstructor(this);
268   return tracker;
269
270 }
271
272 //_____________________________________________________________________________
273 void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
274         , TTree* /*clusterTree*/
275         , AliESDEvent* /*esd*/) const
276 {
277   //
278   // Fill ESD
279   //
280
281 }
282
283
284 //_____________________________________________________________________________
285 void AliTRDReconstructor::SetOption(Option_t *opt)
286 {
287   //
288   // Read option string into the steer param.
289   //
290
291   AliReconstructor::SetOption(opt);
292
293   TString s(opt);
294   TObjArray *opar = s.Tokenize(",");
295   for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
296     Bool_t processed = kFALSE;
297     TString sopt(((TObjString*)(*opar)[ipar])->String());
298     for(Int_t iopt=0; iopt<kNsteer; iopt++){
299       if(!sopt.Contains(fgSteerFlags[iopt])) continue;
300       SETFLG(fSteerParam, BIT(iopt));
301       if(sopt.Contains("!")) CLRFLG(fSteerParam, BIT(iopt));
302       processed = kTRUE;
303       break;    
304     }
305     // extra rules
306     if(sopt.Contains("gs") && !sopt.Contains("!")){
307       CLRFLG(fSteerParam, kLUT); processed = kTRUE;
308     }
309
310     if(processed) continue;
311
312     if(sopt.Contains("sl")){
313       TObjArray *stl = sopt.Tokenize("_");
314       if(stl->GetEntriesFast() < 3) continue;
315       TString taskstr(((TObjString*)(*stl)[1])->String());
316       TString levelstring(((TObjString*)(*stl)[2])->String());
317       Int_t level = levelstring.Atoi();
318
319       // Set the stream Level
320       processed = kFALSE;
321       for(Int_t it=0; it<kNtasks; it++){
322         if(taskstr.CompareTo(fgTaskFlags[it]) != 0) continue;
323         SetStreamLevel(level, ETRDReconstructorTask(it));
324         processed = kTRUE;
325       }
326     } 
327     if(processed) continue;
328
329     AliWarning(Form("Unknown option flag %s.", sopt.Data()));
330   }
331 }
332
333 //_____________________________________________________________________________
334 void AliTRDReconstructor::SetStreamLevel(Int_t level, ETRDReconstructorTask task){
335   //
336   // Set the Stream Level for one of the tasks Clusterizer, Tracker or PID
337   //
338   const Int_t minLevel[4] = {1, 1, 2, 1}; // the minimum debug level upon which a debug stream is created for different tasks
339   //AliInfo(Form("Setting Stream Level for Task %s to %d", taskname.Data(),level));
340   fStreamLevel[(Int_t)task] = level;
341   // Initialize DebugStreamer if not yet done
342   if(level >= minLevel[task] && !fDebugStream[task]){
343     TDirectory *savedir = gDirectory;
344     fDebugStream[task] = new TTreeSRedirector(Form("TRD.Debug%s.root", fgTaskNames[task]));
345     savedir->cd();
346     SETFLG(fSteerParam, kOwner);
347   }
348 }
349
350 //_____________________________________________________________________________
351 void AliTRDReconstructor::Options(UInt_t steer, UChar_t *stream)
352 {
353   //
354   // Print the options
355   //
356
357   for(Int_t iopt=0; iopt<kNsteer; iopt++){
358     AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
359   }
360   AliDebugGeneral("AliTRDReconstructor", 1, " Debug Streaming"); 
361   for(Int_t it=0; it<kNtasks; it++) 
362     AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s [sl_%s] %d", fgTaskNames[it], fgTaskFlags[it], stream ? stream[it] : 0));
363 }
364