]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDReconstructor.cxx
Enable ConvertDigits
[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   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.SetUseLabels(kFALSE);
217   clusterer.Raw2ClustersChamber(rawReader);
218   
219   if(IsWritingClusters()) return;
220
221   // take over ownership of clusters
222   fgClusters = clusterer.RecPoints();
223   clusterer.SetClustersOwner(kFALSE);
224
225   // take over ownership of online tracklets
226   fgTracklets = clusterer.TrackletsArray();
227   clusterer.SetTrackletsOwner(kFALSE);
228 }
229
230 //_____________________________________________________________________________
231 void AliTRDReconstructor::Reconstruct(TTree *digitsTree
232                                     , TTree *clusterTree) const
233 {
234   //
235   // Reconstruct clusters
236   //
237
238   //AliInfo("Reconstruct TRD clusters from Digits [Digit TTree -> Cluster TTree]");
239
240   AliTRDclusterizer clusterer(fgTaskNames[kClusterizer], fgTaskNames[kClusterizer]);
241   clusterer.SetReconstructor(this);
242   clusterer.OpenOutput(clusterTree);
243   clusterer.ReadDigits(digitsTree);
244   clusterer.MakeClusters();
245
246   if(IsWritingClusters()) return;
247
248   // take over ownership of clusters
249   fgClusters = clusterer.RecPoints();
250   clusterer.SetClustersOwner(kFALSE);
251
252   // take over ownership of online tracklets
253   fgTracklets = clusterer.TrackletsArray();
254   clusterer.SetTrackletsOwner(kFALSE);
255 }
256
257 //_____________________________________________________________________________
258 AliTracker *AliTRDReconstructor::CreateTracker() const
259 {
260   //
261   // Create a TRD tracker
262   //
263
264   //return new AliTRDtracker(NULL);
265   AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
266   tracker->SetReconstructor(this);
267   return tracker;
268
269 }
270
271 //_____________________________________________________________________________
272 void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
273         , TTree* /*clusterTree*/
274         , AliESDEvent* /*esd*/) const
275 {
276   //
277   // Fill ESD
278   //
279
280 }
281
282
283 //_____________________________________________________________________________
284 void AliTRDReconstructor::SetOption(Option_t *opt)
285 {
286 // Read option string into the steer param.
287 //
288
289   AliReconstructor::SetOption(opt);
290
291   TString s(opt);
292   TObjArray *opar = s.Tokenize(",");
293   for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
294     Bool_t PROCESSED = kFALSE;
295     TString sopt(((TObjString*)(*opar)[ipar])->String());
296     for(Int_t iopt=0; iopt<kNsteer; iopt++){
297       if(!sopt.Contains(fgSteerFlags[iopt])) continue;
298       SETFLG(fSteerParam, BIT(iopt));
299       if(sopt.Contains("!")) CLRFLG(fSteerParam, BIT(iopt));
300       PROCESSED = kTRUE;
301       break;    
302     }
303     // extra rules
304     if(sopt.Contains("gs") && !sopt.Contains("!")){
305       CLRFLG(fSteerParam, kLUT); PROCESSED = kTRUE;
306     }
307
308     if(PROCESSED) continue;
309
310     if(sopt.Contains("sl")){
311       TObjArray *stl = sopt.Tokenize("_");
312       if(stl->GetEntriesFast() < 3) continue;
313       TString taskstr(((TObjString*)(*stl)[1])->String());
314       TString levelstring(((TObjString*)(*stl)[2])->String());
315       Int_t level = levelstring.Atoi();
316
317       // Set the stream Level
318       PROCESSED = kFALSE;
319       for(Int_t it=0; it<kNtasks; it++){
320         if(taskstr.CompareTo(fgTaskFlags[it]) != 0) continue;
321         SetStreamLevel(level, ETRDReconstructorTask(it));
322         PROCESSED = kTRUE;
323       }
324     } 
325     if(PROCESSED) continue;
326
327     AliWarning(Form("Unknown option flag %s.", sopt.Data()));
328   }
329 }
330
331 //_____________________________________________________________________________
332 void AliTRDReconstructor::SetStreamLevel(Int_t level, ETRDReconstructorTask task){
333   //
334   // Set the Stream Level for one of the tasks Clusterizer, Tracker or PID
335   //
336   const Int_t minLevel[4] = {1, 1, 2, 1}; // the minimum debug level upon which a debug stream is created for different tasks
337   //AliInfo(Form("Setting Stream Level for Task %s to %d", taskname.Data(),level));
338   fStreamLevel[(Int_t)task] = level;
339   // Initialize DebugStreamer if not yet done
340   if(level >= minLevel[task] && !fDebugStream[task]){
341     TDirectory *savedir = gDirectory;
342     fDebugStream[task] = new TTreeSRedirector(Form("TRD.Debug%s.root", fgTaskNames[task]));
343     savedir->cd();
344     SETFLG(fSteerParam, kOwner);
345   }
346 }
347
348 //_____________________________________________________________________________
349 void AliTRDReconstructor::Options(UInt_t steer, UChar_t *stream)
350 {
351   for(Int_t iopt=0; iopt<kNsteer; iopt++){
352     AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
353   }
354   AliDebugGeneral("AliTRDReconstructor", 1, " Debug Streaming"); 
355   for(Int_t it=0; it<kNtasks; it++) 
356     AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s [sl_%s] %d", fgTaskNames[it], fgTaskFlags[it], stream ? stream[it] : 0));
357 }
358