67692e59f92edab95770a5e0536b00167898deda
[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 ClassImp(AliTRDReconstructor)
46
47 TClonesArray *AliTRDReconstructor::fgClusters = 0x0;
48 //_____________________________________________________________________________
49 AliTRDReconstructor::AliTRDReconstructor()
50   :AliReconstructor()
51   ,fSteerParam(0x00000007)
52 {
53   //
54   // Default constructor
55   //
56
57   memset(fStreamLevel, 0, 5*sizeof(UChar_t));
58   // Xe tail cancellation parameters
59   fTCParams[0] = 1.156; // r1
60   fTCParams[1] = 0.130; // r2
61   fTCParams[2] = 0.114; // c1
62   fTCParams[3] = 0.624; // c2
63   // Ar tail cancellation parameters
64   fTCParams[4] = 6.;    // r1
65   fTCParams[5] = 0.62;  // r2
66   fTCParams[6] = 0.0087;// c1
67   fTCParams[7] = 0.07;  // c2
68
69 }
70
71 //_____________________________________________________________________________
72 AliTRDReconstructor::AliTRDReconstructor(const AliTRDReconstructor &r)
73   :AliReconstructor(r)
74   ,fSteerParam(r.fSteerParam)
75 {
76   //
77   // Copy constructor
78   //
79
80   memcpy(fStreamLevel,r.fStreamLevel, 5*sizeof(UChar_t));
81   memcpy(fTCParams   ,r.fTCParams   , 8*sizeof(Double_t));
82
83 }
84
85 //_____________________________________________________________________________
86 AliTRDReconstructor::~AliTRDReconstructor()
87 {
88   //
89   // Destructor
90   //
91
92   if(fgClusters) {
93     fgClusters->Delete(); delete fgClusters;
94   }
95
96 }
97
98 //_____________________________________________________________________________
99 void AliTRDReconstructor::Init()
100 {
101   //
102   // Init Options
103   //
104
105   SetOption(GetOption());
106
107   AliInfo("TRD reconstruction will use the following settings:");
108   printf("\tWrite Clusters         [cw] : %s\n", fSteerParam&kWriteClusters?"yes":"no");
109   printf("\tWrite Online Tracklets [tw] : %s\n", fSteerParam&kWriteTracklets?"yes":"no");
110   printf("\tDrift Gas Argon        [ar] : %s\n", fSteerParam&kDriftGas?"yes":"no");
111   printf("\tStand Alone Tracking   [sa] : %s\n", fSteerParam&kSeeding?"yes":"no");
112   printf("\tHLT         Tracking  [hlt] : %s\n", fSteerParam&kHLT?"yes":"no");
113   printf("\tNN PID                 [nn] : %s\n", fSteerParam&kSteerPID?"yes":"no");
114   printf("\tStreaming Levels            : Clusterizer[%d] Tracker[%d] PID[%d]\n"
115         ,fStreamLevel[kClusterizer]
116         ,fStreamLevel[kTracker]
117         ,fStreamLevel[kPID]);
118
119 }
120
121 //_____________________________________________________________________________
122 void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader
123                                       , TTree *digitsTree) const
124 {
125   //
126   // Convert raw data digits into digit objects in a root tree
127   //
128
129   AliTRDrawData rawData;
130   rawReader->Reset();
131   rawReader->Select("TRD");
132   AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
133   manager->MakeBranch(digitsTree);
134   manager->WriteDigits();
135   delete manager;
136
137 }
138
139 //_____________________________________________________________________________
140 void AliTRDReconstructor::Reconstruct(AliRawReader *rawReader
141                                     , TTree *clusterTree) const
142 {
143   //
144   // Reconstruct clusters
145   //
146
147   rawReader->Reset();
148   rawReader->Select("TRD");
149
150   // New (fast) cluster finder
151   AliTRDclusterizer clusterer("clusterer","TRD clusterizer");
152   clusterer.SetReconstructor(this);
153   clusterer.OpenOutput(clusterTree);
154   clusterer.SetAddLabels(kFALSE);
155   clusterer.Raw2ClustersChamber(rawReader);
156   
157   if(IsWritingClusters()) return;
158
159   // take over ownership of clusters
160   fgClusters = clusterer.RecPoints();
161   clusterer.SetClustersOwner(kFALSE);
162
163 }
164
165 //_____________________________________________________________________________
166 void AliTRDReconstructor::Reconstruct(TTree *digitsTree
167                                     , TTree *clusterTree) const
168 {
169   //
170   // Reconstruct clusters
171   //
172
173   AliTRDclusterizer clusterer("clusterer","TRD clusterizer");
174   clusterer.SetReconstructor(this);
175   clusterer.OpenOutput(clusterTree);
176   clusterer.ReadDigits(digitsTree);
177   clusterer.MakeClusters();
178
179   if(IsWritingClusters()) return;
180
181   // take over ownership of clusters
182   fgClusters = clusterer.RecPoints();
183   clusterer.SetClustersOwner(kFALSE);
184
185 }
186
187 //_____________________________________________________________________________
188 AliTracker *AliTRDReconstructor::CreateTracker() const
189 {
190   //
191   // Create a TRD tracker
192   //
193
194   //return new AliTRDtracker(NULL);
195   AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
196   tracker->SetReconstructor(this);
197   return tracker;
198
199 }
200
201 //_____________________________________________________________________________
202 void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
203                                 , TTree* /*clusterTree*/
204                                 , AliESDEvent* /*esd*/) const
205 {
206   //
207   // Fill ESD
208   //
209
210 }
211
212 //_____________________________________________________________________________
213 void AliTRDReconstructor::SetOption(Option_t *opt)
214 {
215   //
216   // Read option string into the steer param.
217   //
218   // Default steer param values
219   //
220   // write clusters [cw] = true
221   // track seeding (stand alone tracking) [sa] = true
222   // PID method in reconstruction (NN) [nn] = true
223   // write online tracklets [tw] = false
224   // drift gas [ar] = false
225   // HLT tracking [hlt] = false
226   //
227
228   fSteerParam = 0x00000007;
229
230   TString s(opt);
231   TObjArray *opar = s.Tokenize(",");
232   for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
233     TString sopt(((TObjString*)(*opar)[ipar])->String());
234     if(sopt.Contains("!cw")){ 
235       fSteerParam &= ~kWriteClusters;
236       continue;
237     } else if(sopt.Contains("!sa")){
238       fSteerParam &= ~kSeeding;
239       continue;
240     } else if(sopt.Contains("!nn")){
241       fSteerParam &= ~kSteerPID;
242       continue;
243     } else if(sopt.Contains("tw")){
244       if(!sopt.Contains("!")) fSteerParam |= kWriteTracklets;
245       continue; 
246     } else if(sopt.Contains("ar")){
247       if(!sopt.Contains("!")) fSteerParam |= kDriftGas;
248       continue; 
249     } else if(sopt.Contains("hlt")){
250       if(!sopt.Contains("!")) fSteerParam |= kHLT;
251       continue; 
252     } else if(sopt.Contains("sl")){
253         TObjArray *stl = sopt.Tokenize("_");
254         if(stl->GetEntriesFast() < 3) continue;
255                         TString taskstr(((TObjString*)(*stl)[1])->String());
256                         TString levelstring(((TObjString*)(*stl)[2])->String());
257         // Set the stream Level
258         Int_t level = levelstring.Atoi();
259         AliTRDReconstructorTask task = kTracker;
260         if(taskstr.CompareTo("cl") == 0) task = kClusterizer;   
261         else if(taskstr.CompareTo("tr") == 0) task = kTracker;
262         else if(taskstr.CompareTo("pi") == 0) task = kPID;
263         SetStreamLevel(level, task);
264         continue;
265                 }
266   }
267
268 }
269
270 //_____________________________________________________________________________
271 void AliTRDReconstructor::SetStreamLevel(Int_t level, AliTRDReconstructorTask task)
272 {
273   //
274   // Set the Stream Level for one of the tasks Clusterizer, Tracker or PID
275   //
276
277   TString taskname;
278   switch(task) {
279     case kClusterizer: 
280       taskname = "Clusterizer";
281       break;
282     case kTracker: 
283       taskname = "Tracker";
284       break;
285     case kPID: 
286       taskname = "PID";
287       break;
288   }
289
290   fStreamLevel[(Int_t)task] = level;
291
292 }