]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDReconstructor.cxx
Coding rules
[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 <TFile.h>
25 #include <TObjString.h>
26 #include <TObjArray.h>
27 #include <TClonesArray.h>
28
29 #include "AliRunLoader.h"
30 #include "AliRawReader.h"
31 #include "AliLog.h"
32 #include "AliESDTrdTrack.h"
33 #include "AliESDEvent.h"
34
35 #include "AliTRDReconstructor.h"
36 #include "AliTRDclusterizer.h"
37 #include "AliTRDtracker.h"
38 #include "AliTRDpidESD.h"
39 #include "AliTRDrawData.h"
40 #include "AliTRDdigitsManager.h"
41 #include "AliTRDtrackerV1.h"
42 #include "AliTRDrecoParam.h"
43
44 #include "TTreeStream.h"
45
46 #define SETFLG(n,f) ((n) |= f)
47 #define CLRFLG(n,f) ((n) &= ~f)
48
49 ClassImp(AliTRDReconstructor)
50
51 TClonesArray *AliTRDReconstructor::fgClusters = 0x0;
52 TClonesArray *AliTRDReconstructor::fgTracklets = 0x0;
53 Char_t* AliTRDReconstructor::fgSteerNames[kNsteer] = {
54   "DigitsConversion       "
55  ,"Tail Cancellation      "
56  ,"Clusters LUT           "
57  ,"Clusters GAUSS         "
58  ,"Clusters Sharing       "
59  ,"NN PID                 "
60  ,"8 dEdx slices in ESD   "
61  ,"Write Clusters         "
62  ,"Write Online Tracklets "
63  ,"Drift Gas Argon        "
64  ,"Stand Alone Tracking   "
65  ,"Vertex Constrain       "
66  ,"Tracklet Improve       "
67  ,"HLT Mode              "
68  ,"Cosmic Reconstruction "
69  ,"Process Online Tracklets"
70 };
71 Char_t* AliTRDReconstructor::fgSteerFlags[kNsteer] = {
72   "dc"// digits conversion [false]
73  ,"tc"// apply tail cancellation [true]
74  ,"lut"// look-up-table for cluster shape in the r-phi direction
75  ,"gs"// gauss cluster shape in the r-phi direction
76  ,"sh"// cluster sharing between tracks
77  ,"nn"// PID method in reconstruction (NN) [true]
78  ,"8s"// 8 dEdx slices in ESD [true] 
79  ,"cw"// write clusters [true]
80  ,"tw"// write online tracklets [false]
81  ,"ar"// drift gas [false] - do not update the number of exponentials in the TC !
82  ,"sa"// track seeding (stand alone tracking) [true]
83  ,"vc"// vertex constrain on stand alone track finder [false]
84  ,"ti"// improve tracklets in stand alone track finder [true]
85  ,"hlt"// HLT reconstruction [false]
86  ,"cos"// Cosmic Reconstruction [false]
87  ,"tp"// also use online tracklets for reconstruction [false]
88 };
89 Char_t* AliTRDReconstructor::fgTaskNames[kNtasks] = {
90   "RawReader"
91  ,"Clusterizer"
92  ,"Tracker"
93  ,"PID"
94 };
95 Char_t* AliTRDReconstructor::fgTaskFlags[kNtasks] = {
96   "rr"
97  ,"cl"
98  ,"tr"
99  ,"pd"
100 };
101
102 //_____________________________________________________________________________
103 AliTRDReconstructor::AliTRDReconstructor()
104   :AliReconstructor()
105   ,fSteerParam(0)
106 {
107   // setting default "ON" steering parameters
108   // owner of debug streamers 
109   SETFLG(fSteerParam, kOwner);
110   // write clusters [cw]
111   SETFLG(fSteerParam, kWriteClusters);
112   // track seeding (stand alone tracking) [sa]
113   SETFLG(fSteerParam, kSeeding);
114   // PID method in reconstruction (NN) [nn]
115   SETFLG(fSteerParam, kSteerPID);
116   // number of dEdx slices in the ESD track [8s]
117   SETFLG(fSteerParam, kEightSlices);
118   // vertex constrain for stand alone track finder
119   SETFLG(fSteerParam, kVertexConstrained);
120   // improve tracklets for stand alone track finder
121   SETFLG(fSteerParam, kImproveTracklet);
122   // use look up table for cluster r-phi position
123   SETFLG(fSteerParam, kLUT);
124   // use tail cancellation
125   SETFLG(fSteerParam, kTC);
126
127   memset(fStreamLevel, 0, kNtasks*sizeof(UChar_t));
128   memset(fDebugStream, 0, sizeof(TTreeSRedirector *) * kNtasks);
129   // Xe tail cancellation parameters
130   fTCParams[0] = 1.156; // r1
131   fTCParams[1] = 0.130; // r2
132   fTCParams[2] = 0.114; // c1
133   fTCParams[3] = 0.624; // c2
134   // Ar tail cancellation parameters
135   fTCParams[4] = 6.;    // r1
136   fTCParams[5] = 0.62;  // r2
137   fTCParams[6] = 0.0087;// c1
138   fTCParams[7] = 0.07;  // c2
139 }
140
141 //_____________________________________________________________________________
142 AliTRDReconstructor::AliTRDReconstructor(const AliTRDReconstructor &r)
143   :AliReconstructor(r)
144   ,fSteerParam(r.fSteerParam)
145 {
146   memcpy(fStreamLevel, r.fStreamLevel, kNtasks*sizeof(UChar_t));
147   memcpy(fTCParams, r.fTCParams, 8*sizeof(Double_t));
148   memcpy(fDebugStream, r.fDebugStream, sizeof(TTreeSRedirector *) *kNtasks);
149   // ownership of debug streamers is not taken
150   CLRFLG(fSteerParam, kOwner);
151 }
152
153 //_____________________________________________________________________________
154 AliTRDReconstructor::~AliTRDReconstructor()
155 {
156   if(fgClusters) {
157     fgClusters->Delete(); delete fgClusters;
158   }
159   if(fgTracklets) {
160     fgTracklets->Delete(); delete fgTracklets;
161   }
162   if(fSteerParam&kOwner){
163     for(Int_t itask = 0; itask < kNtasks; itask++)
164       if(fDebugStream[itask]) delete fDebugStream[itask];
165   }
166 }
167
168
169 //_____________________________________________________________________________
170 void AliTRDReconstructor::Init(){
171   //
172   // Init Options
173   //
174   SetOption(GetOption());
175   Options(fSteerParam, fStreamLevel);
176 }
177
178 //_____________________________________________________________________________
179 void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader
180               , TTree *digitsTree) const
181 {
182   //
183   // Convert raw data digits into digit objects in a root tree
184   //
185
186   //AliInfo("Convert raw data digits into digit objects [RawReader -> Digit TTree]");
187
188   AliTRDrawData rawData;
189   rawReader->Reset();
190   rawReader->Select("TRD");
191   rawData.OpenOutput();
192   AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
193   manager->MakeBranch(digitsTree);
194   manager->WriteDigits();
195   delete manager;
196
197 }
198
199 //_____________________________________________________________________________
200 void AliTRDReconstructor::Reconstruct(AliRawReader *rawReader
201                                     , TTree *clusterTree) const
202 {
203   //
204   // Reconstruct clusters
205   //
206
207   //AliInfo("Reconstruct TRD clusters from RAW data [RawReader -> Cluster TTree]");
208
209
210   rawReader->Reset();
211   rawReader->Select("TRD");
212
213   // New (fast) cluster finder
214   AliTRDclusterizer clusterer(fgTaskNames[kClusterizer], fgTaskNames[kClusterizer]);
215   clusterer.SetReconstructor(this);
216   clusterer.OpenOutput(clusterTree);
217   clusterer.OpenTrackletOutput();
218   clusterer.SetUseLabels(kFALSE);
219   clusterer.Raw2ClustersChamber(rawReader);
220   
221   if(IsWritingClusters()) return;
222
223   // take over ownership of clusters
224   fgClusters = clusterer.RecPoints();
225   clusterer.SetClustersOwner(kFALSE);
226
227   // take over ownership of online tracklets
228   fgTracklets = clusterer.TrackletsArray();
229   clusterer.SetTrackletsOwner(kFALSE);
230 }
231
232 //_____________________________________________________________________________
233 void AliTRDReconstructor::Reconstruct(TTree *digitsTree
234                                     , TTree *clusterTree) const
235 {
236   //
237   // Reconstruct clusters
238   //
239
240   //AliInfo("Reconstruct TRD clusters from Digits [Digit TTree -> Cluster TTree]");
241
242   AliTRDclusterizer clusterer(fgTaskNames[kClusterizer], fgTaskNames[kClusterizer]);
243   clusterer.SetReconstructor(this);
244   clusterer.OpenOutput(clusterTree);
245   clusterer.ReadDigits(digitsTree);
246   clusterer.MakeClusters();
247
248   if(IsWritingClusters()) return;
249
250   // take over ownership of clusters
251   fgClusters = clusterer.RecPoints();
252   clusterer.SetClustersOwner(kFALSE);
253
254   // take over ownership of online tracklets
255   fgTracklets = clusterer.TrackletsArray();
256   clusterer.SetTrackletsOwner(kFALSE);
257 }
258
259 //_____________________________________________________________________________
260 AliTracker *AliTRDReconstructor::CreateTracker() const
261 {
262   //
263   // Create a TRD tracker
264   //
265
266   //return new AliTRDtracker(NULL);
267   AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
268   tracker->SetReconstructor(this);
269   return tracker;
270
271 }
272
273 //_____________________________________________________________________________
274 void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
275         , TTree* /*clusterTree*/
276         , AliESDEvent* /*esd*/) const
277 {
278   //
279   // Fill ESD
280   //
281
282 }
283
284
285 //_____________________________________________________________________________
286 void AliTRDReconstructor::SetOption(Option_t *opt)
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   for(Int_t iopt=0; iopt<kNsteer; iopt++){
354     AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
355   }
356   AliDebugGeneral("AliTRDReconstructor", 1, " Debug Streaming"); 
357   for(Int_t it=0; it<kNtasks; it++) 
358     AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s [sl_%s] %d", fgTaskNames[it], fgTaskFlags[it], stream ? stream[it] : 0));
359 }
360