c33a29b9a4ef0cd60fcdc2d1fec81aef8d92e823
[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 <TObjString.h>
25 #include <TObjArray.h>
26 #include <TTreeStream.h>
27 #include <TDirectory.h>
28
29 #include "AliRawReader.h"
30
31 #include "AliTRDReconstructor.h"
32 #include "AliTRDclusterizer.h"
33 #include "AliTRDrawData.h"
34 #include "AliTRDrawStreamBase.h"
35 #include "AliTRDdigitsManager.h"
36 #include "AliTRDtrackerV1.h"
37
38 #define SETFLG(n,f) ((n) |= f)
39 #define CLRFLG(n,f) ((n) &= ~f)
40
41 ClassImp(AliTRDReconstructor)
42
43 TClonesArray *AliTRDReconstructor::fgClusters = NULL;
44 TClonesArray *AliTRDReconstructor::fgTracklets = NULL;
45 AliTRDdigitsParam *AliTRDReconstructor::fgDigitsParam = NULL;
46 Char_t const * AliTRDReconstructor::fgSteerNames[kNsteer] = {
47   "DigitsConversion       "
48  ,"Write Clusters         "
49  ,"Write Online Tracklets "
50  ,"Stand Alone Tracking   "
51  ,"HLT Mode               "
52  ,"Process Online Tracklets"
53  ,"Debug Streaming        "
54 };
55 Char_t const * AliTRDReconstructor::fgSteerFlags[kNsteer] = {
56   "dc"// digits conversion [false]
57  ,"cw"// write clusters [true]
58  ,"tw"// write online tracklets [false]
59  ,"sa"// track seeding (stand alone tracking) [true]
60  ,"hlt"// HLT reconstruction [false]
61  ,"tp"// also use online tracklets for reconstruction [false]
62  ,"deb"// Write debug stream [false]
63 };
64 Char_t const * AliTRDReconstructor::fgTaskNames[AliTRDrecoParam::kTRDreconstructionTasks] = {
65   "Clusterizer"
66  ,"Tracker"
67  ,"PID"
68 };
69 Char_t const * AliTRDReconstructor::fgTaskFlags[AliTRDrecoParam::kTRDreconstructionTasks] = {
70   "cl"
71  ,"tr"
72  ,"pd"
73 };
74
75 //_____________________________________________________________________________
76 AliTRDReconstructor::AliTRDReconstructor()
77   :AliReconstructor()
78   ,fSteerParam(0)
79 {
80   // setting default "ON" steering parameters
81   // owner of debug streamers 
82   SETFLG(fSteerParam, kOwner);
83   // write clusters [cw]
84   SETFLG(fSteerParam, kWriteClusters);
85   // track seeding (stand alone tracking) [sa]
86   SETFLG(fSteerParam, kSeeding);
87
88   memset(fDebugStream, 0, sizeof(TTreeSRedirector *) * AliTRDrecoParam::kTRDreconstructionTasks);
89 }
90
91 //_____________________________________________________________________________
92 AliTRDReconstructor::~AliTRDReconstructor()
93 {
94   //
95   // Destructor
96   //
97
98   if(fgDigitsParam){
99     delete fgDigitsParam;
100     fgDigitsParam = NULL;
101   }
102   if(fgClusters) {
103     fgClusters->Delete();
104     delete fgClusters;
105     fgClusters = NULL;
106   }
107   if(fgTracklets) {
108     fgTracklets->Delete();
109     delete fgTracklets;
110     fgTracklets = NULL;
111   }
112   if(fSteerParam&kOwner){
113     for(Int_t itask = 0; itask < AliTRDrecoParam::kTRDreconstructionTasks; itask++)
114       if(fDebugStream[itask]) delete fDebugStream[itask];
115   }
116 }
117
118
119 //_____________________________________________________________________________
120 void AliTRDReconstructor::Init(){
121   //
122   // Init Options
123   //
124   SetOption(GetOption());
125   Options(fSteerParam);
126
127   // Make Debug Streams when Debug Streaming
128   if(IsDebugStreaming()){
129     for(Int_t task = 0; task < AliTRDrecoParam::kTRDreconstructionTasks; task++){
130       TDirectory *savedir = gDirectory;
131       fDebugStream[task] = new TTreeSRedirector(Form("TRD.Debug%s.root", fgTaskNames[task]));
132       savedir->cd();
133       SETFLG(fSteerParam, kOwner);
134     }
135   }
136 }
137
138 //_____________________________________________________________________________
139 void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader
140               , TTree *digitsTree) const
141 {
142   //
143   // Convert raw data digits into digit objects in a root tree
144   //
145
146   //AliInfo("Convert raw data digits into digit objects [RawReader -> Digit TTree]");
147
148   AliTRDrawData rawData;
149   rawReader->Reset();
150   rawReader->Select("TRD");
151   rawData.OpenOutput();
152   AliTRDrawStreamBase::SetRawStreamVersion(GetRecoParam()->GetRawStreamVersion()->Data());
153   AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
154   manager->MakeBranch(digitsTree);
155   manager->WriteDigits();
156   delete manager;
157
158 }
159
160 //_____________________________________________________________________________
161 void AliTRDReconstructor::Reconstruct(AliRawReader *rawReader
162                                     , TTree *clusterTree) const
163 {
164   //
165   // Reconstruct clusters
166   //
167
168   //AliInfo("Reconstruct TRD clusters from RAW data [RawReader -> Cluster TTree]");
169
170
171   rawReader->Reset();
172   rawReader->Select("TRD");
173   AliTRDrawStreamBase::SetRawStreamVersion(GetRecoParam()->GetRawStreamVersion()->Data());
174
175   // New (fast) cluster finder
176   AliTRDclusterizer clusterer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
177   clusterer.SetReconstructor(this);
178   clusterer.OpenOutput(clusterTree);
179   clusterer.OpenTrackletOutput();
180   clusterer.SetUseLabels(kFALSE);
181   clusterer.Raw2ClustersChamber(rawReader);
182   
183   if(IsWritingClusters()) return;
184
185   // take over ownership of clusters
186   fgClusters = clusterer.RecPoints();
187   clusterer.SetClustersOwner(kFALSE);
188
189   // take over ownership of online tracklets
190   fgTracklets = clusterer.TrackletsArray();
191   clusterer.SetTrackletsOwner(kFALSE);
192 }
193
194 //_____________________________________________________________________________
195 void AliTRDReconstructor::Reconstruct(TTree *digitsTree
196                                     , TTree *clusterTree) const
197 {
198   //
199   // Reconstruct clusters
200   //
201
202   //AliInfo("Reconstruct TRD clusters from Digits [Digit TTree -> Cluster TTree]");
203   
204   AliTRDclusterizer clusterer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
205   clusterer.SetReconstructor(this);
206   clusterer.OpenOutput(clusterTree);
207   clusterer.ReadDigits(digitsTree);
208   clusterer.MakeClusters();
209
210   if(IsWritingClusters()) return;
211
212   // take over ownership of clusters
213   fgClusters = clusterer.RecPoints();
214   clusterer.SetClustersOwner(kFALSE);
215
216   // take over ownership of online tracklets
217   fgTracklets = clusterer.TrackletsArray();
218   clusterer.SetTrackletsOwner(kFALSE);
219 }
220
221 //_____________________________________________________________________________
222 AliTracker *AliTRDReconstructor::CreateTracker() const
223 {
224   //
225   // Create a TRD tracker
226   //
227
228   //return new AliTRDtracker(NULL);
229   AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
230   tracker->SetReconstructor(this);
231   return tracker;
232
233 }
234
235 //_____________________________________________________________________________
236 void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
237         , TTree* /*clusterTree*/
238         , AliESDEvent* /*esd*/) const
239 {
240   //
241   // Fill ESD
242   //
243
244 }
245
246 //_____________________________________________________________________________
247 void AliTRDReconstructor::SetDigitsParam(AliTRDdigitsParam const *par)
248
249   if(fgDigitsParam) (*fgDigitsParam) = (*par);
250   else fgDigitsParam = new AliTRDdigitsParam(*par);
251 }
252
253
254 //_____________________________________________________________________________
255 void AliTRDReconstructor::SetOption(Option_t *opt)
256 {
257   //
258   // Read option string into the steer param.
259   //
260
261   AliReconstructor::SetOption(opt);
262
263   TString s(opt);
264   TObjArray *opar = s.Tokenize(",");
265   for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
266     Bool_t processed = kFALSE;
267     TString sopt(((TObjString*)(*opar)[ipar])->String());
268     for(Int_t iopt=0; iopt<kNsteer; iopt++){
269       if(!sopt.Contains(fgSteerFlags[iopt])) continue;
270       SETFLG(fSteerParam, BIT(iopt));
271       if(sopt.Contains("!")) CLRFLG(fSteerParam, BIT(iopt));
272       processed = kTRUE;
273       break;    
274     }
275     if(processed) continue;
276
277     AliWarning(Form("Unknown option flag %s.", sopt.Data()));
278   }
279 }
280
281 //_____________________________________________________________________________
282 void AliTRDReconstructor::Options(UInt_t steer)
283 {
284   //
285   // Print the options
286   //
287
288   for(Int_t iopt=0; iopt<kNsteer; iopt++){
289     AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
290   }
291 }
292