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