]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDReconstructor.cxx
modify "Add" macro names accordingly
[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 "AliTRDgtuTrack.h"
40 #include "AliTRDrawData.h"
41 #include "AliTRDdigitsManager.h"
42 #include "AliTRDtrackerV1.h"
43 #include "AliTRDrecoParam.h"
44
45 #include "TTreeStream.h"
46
47 #define SETFLG(n,f) ((n) |= f)
48 #define CLRFLG(n,f) ((n) &= ~f)
49
50 ClassImp(AliTRDReconstructor)
51
52 TClonesArray *AliTRDReconstructor::fgClusters = 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 };
70 Char_t* AliTRDReconstructor::fgSteerFlags[kNsteer] = {
71   "dc"// digits conversion [false]
72  ,"tc"// apply tail cancellation [true]
73  ,"lut"// look-up-table for cluster shape in the r-phi direction
74  ,"gs"// gauss cluster shape in the r-phi direction
75  ,"sh"// cluster sharing between tracks
76  ,"nn"// PID method in reconstruction (NN) [true]
77  ,"8s"// 8 dEdx slices in ESD [true] 
78  ,"cw"// write clusters [true]
79  ,"tw"// write online tracklets [false]
80  ,"ar"// drift gas [false] - do not update the number of exponentials in the TC !
81  ,"sa"// track seeding (stand alone tracking) [true]
82  ,"vc"// vertex constrain on stand alone track finder [false]
83  ,"ti"// improve tracklets in stand alone track finder [true]
84  ,"hlt"// HLT reconstruction [false]
85  ,"cos"// Cosmic Reconstruction [false]
86 };
87 Char_t* AliTRDReconstructor::fgTaskNames[kNtasks] = {
88   "RawReader"
89  ,"Clusterizer"
90  ,"Tracker"
91  ,"PID"
92 };
93 Char_t* AliTRDReconstructor::fgTaskFlags[kNtasks] = {
94   "rr"
95  ,"cl"
96  ,"tr"
97  ,"pd"
98 };
99
100 //_____________________________________________________________________________
101 AliTRDReconstructor::AliTRDReconstructor()
102   :AliReconstructor()
103   ,fSteerParam(0)
104 {
105   // setting default "ON" steering parameters
106   // owner of debug streamers 
107   SETFLG(fSteerParam, kOwner);
108   // write clusters [cw]
109   SETFLG(fSteerParam, kWriteClusters);
110   // track seeding (stand alone tracking) [sa]
111   SETFLG(fSteerParam, kSeeding);
112   // PID method in reconstruction (NN) [nn]
113   SETFLG(fSteerParam, kSteerPID);
114   // number of dEdx slices in the ESD track [8s]
115   SETFLG(fSteerParam, kEightSlices);
116   // vertex constrain for stand alone track finder
117   SETFLG(fSteerParam, kVertexConstrained);
118   // improve tracklets for stand alone track finder
119   SETFLG(fSteerParam, kImproveTracklet);
120   // use look up table for cluster r-phi position
121   SETFLG(fSteerParam, kLUT);
122   // use tail cancellation
123   SETFLG(fSteerParam, kTC);
124
125   memset(fStreamLevel, 0, kNtasks*sizeof(UChar_t));
126   memset(fDebugStream, 0, sizeof(TTreeSRedirector *) * kNtasks);
127   // Xe tail cancellation parameters
128   fTCParams[0] = 1.156; // r1
129   fTCParams[1] = 0.130; // r2
130   fTCParams[2] = 0.114; // c1
131   fTCParams[3] = 0.624; // c2
132   // Ar tail cancellation parameters
133   fTCParams[4] = 6.;    // r1
134   fTCParams[5] = 0.62;  // r2
135   fTCParams[6] = 0.0087;// c1
136   fTCParams[7] = 0.07;  // c2
137 }
138
139 //_____________________________________________________________________________
140 AliTRDReconstructor::AliTRDReconstructor(const AliTRDReconstructor &r)
141   :AliReconstructor(r)
142   ,fSteerParam(r.fSteerParam)
143 {
144   memcpy(fStreamLevel, r.fStreamLevel, kNtasks*sizeof(UChar_t));
145   memcpy(fTCParams, r.fTCParams, 8*sizeof(Double_t));
146   memcpy(fDebugStream, r.fDebugStream, sizeof(TTreeSRedirector *) *kNtasks);
147   // ownership of debug streamers is not taken
148   CLRFLG(fSteerParam, kOwner);
149 }
150
151 //_____________________________________________________________________________
152 AliTRDReconstructor::~AliTRDReconstructor()
153 {
154   if(fgClusters) {
155     fgClusters->Delete(); delete fgClusters;
156   }
157   if(fSteerParam&kOwner){
158     for(Int_t itask = 0; itask < kNtasks; itask++)
159       if(fDebugStream[itask]) delete fDebugStream[itask];
160   }
161 }
162
163
164 //_____________________________________________________________________________
165 void AliTRDReconstructor::Init(){
166   //
167   // Init Options
168   //
169   SetOption(GetOption());
170   Options(fSteerParam, fStreamLevel);
171 }
172
173 //_____________________________________________________________________________
174 void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader
175               , TTree *digitsTree) const
176 {
177   //
178   // Convert raw data digits into digit objects in a root tree
179   //
180   AliInfo("Feature not available for the moment."); return;
181
182   AliInfo("Convert raw data digits into digit objects [RawReader -> Digit TTree]");
183
184   AliTRDrawData rawData;
185   rawReader->Reset();
186   rawReader->Select("TRD");
187   AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
188   manager->MakeBranch(digitsTree);
189   manager->WriteDigits();
190   delete manager;
191
192 }
193
194 //_____________________________________________________________________________
195 void AliTRDReconstructor::Reconstruct(AliRawReader *rawReader
196                                     , TTree *clusterTree) const
197 {
198   //
199   // Reconstruct clusters
200   //
201
202   //AliInfo("Reconstruct TRD clusters from RAW data [RawReader -> Cluster TTree]");
203
204
205   rawReader->Reset();
206   rawReader->Select("TRD");
207
208   // New (fast) cluster finder
209   AliTRDclusterizer clusterer(fgTaskNames[kClusterizer], fgTaskNames[kClusterizer]);
210   clusterer.SetReconstructor(this);
211   clusterer.OpenOutput(clusterTree);
212   clusterer.SetUseLabels(kFALSE);
213   clusterer.Raw2ClustersChamber(rawReader);
214   
215   if(IsWritingClusters()) return;
216
217   // take over ownership of clusters
218   fgClusters = clusterer.RecPoints();
219   clusterer.SetClustersOwner(kFALSE);
220 }
221
222 //_____________________________________________________________________________
223 void AliTRDReconstructor::Reconstruct(TTree *digitsTree
224                                     , TTree *clusterTree) const
225 {
226   //
227   // Reconstruct clusters
228   //
229
230   //AliInfo("Reconstruct TRD clusters from Digits [Digit TTree -> Cluster TTree]");
231
232   AliTRDclusterizer clusterer(fgTaskNames[kClusterizer], fgTaskNames[kClusterizer]);
233   clusterer.SetReconstructor(this);
234   clusterer.OpenOutput(clusterTree);
235   clusterer.ReadDigits(digitsTree);
236   clusterer.MakeClusters();
237
238   if(IsWritingClusters()) return;
239
240   // take over ownership of clusters
241   fgClusters = clusterer.RecPoints();
242   clusterer.SetClustersOwner(kFALSE);
243 }
244
245 //_____________________________________________________________________________
246 AliTracker *AliTRDReconstructor::CreateTracker() const
247 {
248   //
249   // Create a TRD tracker
250   //
251
252   //return new AliTRDtracker(NULL);
253   AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
254   tracker->SetReconstructor(this);
255   return tracker;
256
257 }
258
259 //_____________________________________________________________________________
260 void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
261         , TTree* /*clusterTree*/
262         , AliESDEvent* /*esd*/) const
263 {
264   //
265   // Fill ESD
266   //
267
268 }
269
270
271 //_____________________________________________________________________________
272 void AliTRDReconstructor::SetOption(Option_t *opt)
273 {
274 // Read option string into the steer param.
275 //
276
277   AliReconstructor::SetOption(opt);
278
279   TString s(opt);
280   TObjArray *opar = s.Tokenize(",");
281   for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
282     Bool_t PROCESSED = kFALSE;
283     TString sopt(((TObjString*)(*opar)[ipar])->String());
284     for(Int_t iopt=0; iopt<kNsteer; iopt++){
285       if(!sopt.Contains(fgSteerFlags[iopt])) continue;
286       SETFLG(fSteerParam, BIT(iopt));
287       if(sopt.Contains("!")) CLRFLG(fSteerParam, BIT(iopt));
288       PROCESSED = kTRUE;
289       break;    
290     }
291     // extra rules
292     if(sopt.Contains("gs") && !sopt.Contains("!")){
293       CLRFLG(fSteerParam, kLUT); PROCESSED = kTRUE;
294     }
295
296     if(PROCESSED) continue;
297
298     if(sopt.Contains("sl")){
299       TObjArray *stl = sopt.Tokenize("_");
300       if(stl->GetEntriesFast() < 3) continue;
301       TString taskstr(((TObjString*)(*stl)[1])->String());
302       TString levelstring(((TObjString*)(*stl)[2])->String());
303       Int_t level = levelstring.Atoi();
304
305       // Set the stream Level
306       PROCESSED = kFALSE;
307       for(Int_t it=0; it<kNtasks; it++){
308         if(taskstr.CompareTo(fgTaskFlags[it]) != 0) continue;
309         SetStreamLevel(level, ETRDReconstructorTask(it));
310         PROCESSED = kTRUE;
311       }
312     } 
313     if(PROCESSED) continue;
314
315     AliWarning(Form("Unknown option flag %s.", sopt.Data()));
316   }
317 }
318
319 //_____________________________________________________________________________
320 void AliTRDReconstructor::SetStreamLevel(Int_t level, ETRDReconstructorTask task){
321   //
322   // Set the Stream Level for one of the tasks Clusterizer, Tracker or PID
323   //
324   const Int_t minLevel[4] = {1, 1, 2, 1}; // the minimum debug level upon which a debug stream is created for different tasks
325   //AliInfo(Form("Setting Stream Level for Task %s to %d", taskname.Data(),level));
326   fStreamLevel[(Int_t)task] = level;
327   // Initialize DebugStreamer if not yet done
328   if(level >= minLevel[task] && !fDebugStream[task]){
329     TDirectory *savedir = gDirectory;
330     fDebugStream[task] = new TTreeSRedirector(Form("TRD.Debug%s.root", fgTaskNames[task]));
331     savedir->cd();
332     SETFLG(fSteerParam, kOwner);
333   }
334 }
335
336 //_____________________________________________________________________________
337 void AliTRDReconstructor::Options(UInt_t steer, UChar_t *stream)
338 {
339   for(Int_t iopt=0; iopt<kNsteer; iopt++){
340     AliInfoGeneral("AliTRDReconstructor", Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
341   }
342   AliInfoGeneral("AliTRDReconstructor", " Debug Streaming"); 
343   for(Int_t it=0; it<kNtasks; it++) 
344     AliInfoGeneral("AliTRDReconstructor", Form(" %s [sl_%s] %d", fgTaskNames[it], fgTaskFlags[it], stream ? stream[it] : 0));
345 }
346