]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDReconstructor.cxx
updates requested by HLT
[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   AliTRDrawStreamBase::SetRawStreamVersion(GetRecoParam()->GetRawStreamVersion()->Data());
158   AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
159   manager->MakeBranch(digitsTree);
160   manager->WriteDigits();
161   delete manager;
162
163 }
164
165 //_____________________________________________________________________________
166 void AliTRDReconstructor::Reconstruct(AliRawReader *rawReader
167                                     , TTree *clusterTree) const
168 {
169   //
170   // Reconstruct clusters
171   //
172
173   //AliInfo("Reconstruct TRD clusters from RAW data [RawReader -> Cluster TTree]");
174
175
176   rawReader->Reset();
177   rawReader->Select("TRD");
178   AliTRDrawStreamBase::SetRawStreamVersion(GetRecoParam()->GetRawStreamVersion()->Data());
179
180   if(!fClusterizer){
181     AliFatal("Clusterizer not available!");
182     return;
183   }
184
185   fClusterizer->ResetRecPoints();
186
187   fClusterizer->OpenOutput(clusterTree);
188   fClusterizer->SetUseLabels(kFALSE);
189   fClusterizer->Raw2ClustersChamber(rawReader);
190   
191   fgNTimeBins = fClusterizer->GetNTimeBins();
192   
193   if(IsWritingClusters()) return;
194
195   // take over ownership of clusters
196   fgClusters = fClusterizer->RecPoints();
197   fClusterizer->SetClustersOwner(kFALSE);
198
199   // take over ownership of online tracklets
200   fgTracklets = fClusterizer->TrackletsArray();
201   fClusterizer->SetTrackletsOwner(kFALSE);
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   AliTRDclusterizer clusterer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
215   clusterer.SetReconstructor(this);
216   clusterer.OpenOutput(clusterTree);
217   clusterer.ReadDigits(digitsTree);
218   clusterer.MakeClusters();
219
220   fgNTimeBins = clusterer.GetNTimeBins();
221
222   if(IsWritingClusters()) return;
223
224   // take over ownership of clusters
225   fgClusters = clusterer.RecPoints();
226   clusterer.SetClustersOwner(kFALSE);
227
228   // take over ownership of online tracklets
229   fgTracklets = clusterer.TrackletsArray();
230   clusterer.SetTrackletsOwner(kFALSE);
231
232 }
233
234 //_____________________________________________________________________________
235 AliTracker *AliTRDReconstructor::CreateTracker() const
236 {
237   //
238   // Create a TRD tracker
239   //
240
241   //return new AliTRDtracker(NULL);
242   AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
243   tracker->SetReconstructor(this);
244   return tracker;
245
246 }
247
248 //_____________________________________________________________________________
249 void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
250         , TTree* /*clusterTree*/
251         , AliESDEvent* /*esd*/) const
252 {
253   //
254   // Fill ESD
255   //
256
257 }
258
259 //_____________________________________________________________________________
260 void AliTRDReconstructor::SetOption(Option_t *opt)
261 {
262   //
263   // Read option string into the steer param.
264   //
265
266   AliReconstructor::SetOption(opt);
267
268   TString s(opt);
269   TObjArray *opar = s.Tokenize(",");
270   for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
271     Bool_t processed = kFALSE;
272     TString sopt(((TObjString*)(*opar)[ipar])->String());
273     for(Int_t iopt=0; iopt<kNsteer; iopt++){
274       if(!sopt.Contains(fgSteerFlags[iopt])) continue;
275       SETFLG(fSteerParam, BIT(iopt));
276       if(sopt.Contains("!")) CLRFLG(fSteerParam, BIT(iopt));
277       processed = kTRUE;
278       break;    
279     }
280     if(processed) continue;
281
282     AliWarning(Form("Unknown option flag %s.", sopt.Data()));
283   }
284 }
285
286 //_____________________________________________________________________________
287 void AliTRDReconstructor::Options(UInt_t steer)
288 {
289   //
290   // Print the options
291   //
292
293   for(Int_t iopt=0; iopt<kNsteer; iopt++){
294     AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
295   }
296 }
297