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