]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDReconstructor.cxx
In AliMUONAlignment
[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 Char_t const * AliTRDReconstructor::fgSteerNames[kNsteer] = {
46   "DigitsConversion       "
47  ,"Write Clusters         "
48  ,"Write Online Tracklets "
49  ,"Stand Alone Tracking   "
50  ,"HLT Mode              "
51  ,"Process Online Trklts  "
52  ,"Debug Streaming       "
53  ,"Cl. Radial Correction  "
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  ,"cc" // Cluster radial correction during reconstruction [false]
64 };
65 Char_t const * AliTRDReconstructor::fgTaskNames[AliTRDrecoParam::kTRDreconstructionTasks] = {
66   "Clusterizer"
67  ,"Tracker"
68  ,"PID"
69 };
70 Char_t const * AliTRDReconstructor::fgTaskFlags[AliTRDrecoParam::kTRDreconstructionTasks] = {
71   "cl"
72  ,"tr"
73  ,"pd"
74 };
75 Int_t AliTRDReconstructor::fgNTimeBins = -1;
76
77 //_____________________________________________________________________________
78 AliTRDReconstructor::AliTRDReconstructor()
79   :AliReconstructor()
80   ,fSteerParam(0)
81   ,fClusterizer(NULL)
82 {
83   // setting default "ON" steering parameters
84   // owner of debug streamers 
85   SETFLG(fSteerParam, kOwner);
86   // write clusters [cw]
87   SETFLG(fSteerParam, kWriteClusters);
88   // track seeding (stand alone tracking) [sa]
89   SETFLG(fSteerParam, kSeeding);
90   // Cluster radial correction during reconstruction [cc]
91   //SETFLG(fSteerParam, kClRadialCorr);
92   memset(fDebugStream, 0, sizeof(TTreeSRedirector *) * AliTRDrecoParam::kTRDreconstructionTasks);
93 }
94
95 //_____________________________________________________________________________
96 AliTRDReconstructor::~AliTRDReconstructor()
97 {
98   //
99   // Destructor
100   //
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   if(fClusterizer){
117     delete fClusterizer;
118     fClusterizer = NULL;
119   }
120 }
121
122
123 //_____________________________________________________________________________
124 void AliTRDReconstructor::Init(){
125   //
126   // Init Options
127   //
128   SetOption(GetOption());
129   Options(fSteerParam);
130
131   if(!fClusterizer){
132     fClusterizer = new AliTRDclusterizer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
133     fClusterizer->SetReconstructor(this);
134   }
135   
136   // Make Debug Streams when Debug Streaming
137   if(IsDebugStreaming()){
138     for(Int_t task = 0; task < AliTRDrecoParam::kTRDreconstructionTasks; task++){
139       TDirectory *savedir = gDirectory;
140       fDebugStream[task] = new TTreeSRedirector(Form("TRD.Debug%s.root", fgTaskNames[task]));
141       savedir->cd();
142       SETFLG(fSteerParam, kOwner);
143     }
144   }
145 }
146
147 //_____________________________________________________________________________
148 void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader
149               , TTree *digitsTree) const
150 {
151   //
152   // Convert raw data digits into digit objects in a root tree
153   //
154
155   //AliInfo("Convert raw data digits into digit objects [RawReader -> Digit TTree]");
156
157   AliTRDrawData rawData;
158   rawReader->Reset();
159   rawReader->Select("TRD");
160   AliTRDrawStreamBase::SetRawStreamVersion(GetRecoParam()->GetRawStreamVersion()->Data());
161   AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
162   manager->MakeBranch(digitsTree);
163   manager->WriteDigits();
164   delete manager;
165
166 }
167
168 //_____________________________________________________________________________
169 void AliTRDReconstructor::Reconstruct(AliRawReader *rawReader
170                                     , TTree *clusterTree) const
171 {
172   //
173   // Reconstruct clusters
174   //
175
176   //AliInfo("Reconstruct TRD clusters from RAW data [RawReader -> Cluster TTree]");
177
178
179   rawReader->Reset();
180   rawReader->Select("TRD");
181   AliTRDrawStreamBase::SetRawStreamVersion(GetRecoParam()->GetRawStreamVersion()->Data());
182
183   if(!fClusterizer){
184     AliFatal("Clusterizer not available!");
185     return;
186   }
187
188   fClusterizer->ResetRecPoints();
189
190   fClusterizer->OpenOutput(clusterTree);
191   fClusterizer->SetUseLabels(kFALSE);
192   fClusterizer->Raw2ClustersChamber(rawReader);
193   
194   fgNTimeBins = fClusterizer->GetNTimeBins();
195   
196   if(IsWritingClusters()) return;
197
198   // take over ownership of clusters
199   fgClusters = fClusterizer->RecPoints();
200   fClusterizer->SetClustersOwner(kFALSE);
201
202   // take over ownership of online tracklets
203   fgTracklets = fClusterizer->TrackletsArray();
204   fClusterizer->SetTrackletsOwner(kFALSE);
205 }
206
207 //_____________________________________________________________________________
208 void AliTRDReconstructor::Reconstruct(TTree *digitsTree
209                                     , TTree *clusterTree) const
210 {
211   //
212   // Reconstruct clusters
213   //
214
215   //AliInfo("Reconstruct TRD clusters from Digits [Digit TTree -> Cluster TTree]");
216   
217   AliTRDclusterizer clusterer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
218   clusterer.SetReconstructor(this);
219   clusterer.OpenOutput(clusterTree);
220   clusterer.ReadDigits(digitsTree);
221   clusterer.MakeClusters();
222
223   fgNTimeBins = clusterer.GetNTimeBins();
224
225   if(IsWritingClusters()) return;
226
227   // take over ownership of clusters
228   fgClusters = clusterer.RecPoints();
229   clusterer.SetClustersOwner(kFALSE);
230
231   // take over ownership of online tracklets
232   fgTracklets = clusterer.TrackletsArray();
233   clusterer.SetTrackletsOwner(kFALSE);
234
235 }
236
237 //_____________________________________________________________________________
238 AliTracker *AliTRDReconstructor::CreateTracker() const
239 {
240   //
241   // Create a TRD tracker
242   //
243
244   //return new AliTRDtracker(NULL);
245   AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
246   tracker->SetReconstructor(this);
247   return tracker;
248
249 }
250
251 //_____________________________________________________________________________
252 void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
253         , TTree* /*clusterTree*/
254         , AliESDEvent* /*esd*/) const
255 {
256   //
257   // Fill ESD
258   //
259
260 }
261
262 //_____________________________________________________________________________
263 void AliTRDReconstructor::SetOption(Option_t *opt)
264 {
265   //
266   // Read option string into the steer param.
267   //
268
269   AliReconstructor::SetOption(opt);
270
271   TString s(opt);
272   TObjArray *opar = s.Tokenize(",");
273   for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
274     Bool_t processed = kFALSE;
275     TString sopt(((TObjString*)(*opar)[ipar])->String());
276     for(Int_t iopt=0; iopt<kNsteer; iopt++){
277       if(!sopt.Contains(fgSteerFlags[iopt])) continue;
278       SETFLG(fSteerParam, BIT(iopt));
279       if(sopt.Contains("!")) CLRFLG(fSteerParam, BIT(iopt));
280       processed = kTRUE;
281       break;    
282     }
283     if(processed) continue;
284
285     AliWarning(Form("Unknown option flag %s.", sopt.Data()));
286   }
287 }
288
289 //_____________________________________________________________________________
290 void AliTRDReconstructor::Options(UInt_t steer)
291 {
292   //
293   // Print the options
294   //
295
296   for(Int_t iopt=0; iopt<kNsteer; iopt++){
297     AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
298   }
299 }
300