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