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