]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDReconstructor.cxx
data transport between the tracker and the merger is optimized
[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()
92 {
93   //
94   // Destructor
95   //
96
97   if(fgClusters) {
98     fgClusters->Delete(); delete fgClusters;
99   }
100   if(fgTracklets) {
101     fgTracklets->Delete(); delete fgTracklets;
102   }
103   if(fSteerParam&kOwner){
104     for(Int_t itask = 0; itask < AliTRDrecoParam::kTRDreconstructionTasks; itask++)
105       if(fDebugStream[itask]) delete fDebugStream[itask];
106   }
107 }
108
109
110 //_____________________________________________________________________________
111 void AliTRDReconstructor::Init(){
112   //
113   // Init Options
114   //
115   SetOption(GetOption());
116   Options(fSteerParam);
117
118   // Make Debug Streams when Debug Streaming
119   if(IsDebugStreaming()){
120     for(Int_t task = 0; task < AliTRDrecoParam::kTRDreconstructionTasks; task++){
121       TDirectory *savedir = gDirectory;
122       fDebugStream[task] = new TTreeSRedirector(Form("TRD.Debug%s.root", fgTaskNames[task]));
123       savedir->cd();
124       SETFLG(fSteerParam, kOwner);
125     }
126   }
127 }
128
129 //_____________________________________________________________________________
130 void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader
131               , TTree *digitsTree) const
132 {
133   //
134   // Convert raw data digits into digit objects in a root tree
135   //
136
137   //AliInfo("Convert raw data digits into digit objects [RawReader -> Digit TTree]");
138
139   AliTRDrawData rawData;
140   rawReader->Reset();
141   rawReader->Select("TRD");
142   rawData.OpenOutput();
143   AliTRDrawStreamBase::SetRawStreamVersion(GetRecoParam()->GetRawStreamVersion()->Data());
144   AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
145   manager->MakeBranch(digitsTree);
146   manager->WriteDigits();
147   delete manager;
148
149 }
150
151 //_____________________________________________________________________________
152 void AliTRDReconstructor::Reconstruct(AliRawReader *rawReader
153                                     , TTree *clusterTree) const
154 {
155   //
156   // Reconstruct clusters
157   //
158
159   //AliInfo("Reconstruct TRD clusters from RAW data [RawReader -> Cluster TTree]");
160
161
162   rawReader->Reset();
163   rawReader->Select("TRD");
164   AliTRDrawStreamBase::SetRawStreamVersion(GetRecoParam()->GetRawStreamVersion()->Data());
165
166   // New (fast) cluster finder
167   AliTRDclusterizer clusterer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
168   clusterer.SetReconstructor(this);
169   clusterer.OpenOutput(clusterTree);
170   clusterer.OpenTrackletOutput();
171   clusterer.SetUseLabels(kFALSE);
172   clusterer.Raw2ClustersChamber(rawReader);
173   
174   if(IsWritingClusters()) return;
175
176   // take over ownership of clusters
177   fgClusters = clusterer.RecPoints();
178   clusterer.SetClustersOwner(kFALSE);
179
180   // take over ownership of online tracklets
181   fgTracklets = clusterer.TrackletsArray();
182   clusterer.SetTrackletsOwner(kFALSE);
183 }
184
185 //_____________________________________________________________________________
186 void AliTRDReconstructor::Reconstruct(TTree *digitsTree
187                                     , TTree *clusterTree) const
188 {
189   //
190   // Reconstruct clusters
191   //
192
193   //AliInfo("Reconstruct TRD clusters from Digits [Digit TTree -> Cluster TTree]");
194   
195   AliTRDclusterizer clusterer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
196   clusterer.SetReconstructor(this);
197   clusterer.OpenOutput(clusterTree);
198   clusterer.ReadDigits(digitsTree);
199   clusterer.MakeClusters();
200
201   if(IsWritingClusters()) return;
202
203   // take over ownership of clusters
204   fgClusters = clusterer.RecPoints();
205   clusterer.SetClustersOwner(kFALSE);
206
207   // take over ownership of online tracklets
208   fgTracklets = clusterer.TrackletsArray();
209   clusterer.SetTrackletsOwner(kFALSE);
210 }
211
212 //_____________________________________________________________________________
213 AliTracker *AliTRDReconstructor::CreateTracker() const
214 {
215   //
216   // Create a TRD tracker
217   //
218
219   //return new AliTRDtracker(NULL);
220   AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
221   tracker->SetReconstructor(this);
222   return tracker;
223
224 }
225
226 //_____________________________________________________________________________
227 void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
228         , TTree* /*clusterTree*/
229         , AliESDEvent* /*esd*/) const
230 {
231   //
232   // Fill ESD
233   //
234
235 }
236
237
238 //_____________________________________________________________________________
239 void AliTRDReconstructor::SetOption(Option_t *opt)
240 {
241   //
242   // Read option string into the steer param.
243   //
244
245   AliReconstructor::SetOption(opt);
246
247   TString s(opt);
248   TObjArray *opar = s.Tokenize(",");
249   for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
250     Bool_t processed = kFALSE;
251     TString sopt(((TObjString*)(*opar)[ipar])->String());
252     for(Int_t iopt=0; iopt<kNsteer; iopt++){
253       if(!sopt.Contains(fgSteerFlags[iopt])) continue;
254       SETFLG(fSteerParam, BIT(iopt));
255       if(sopt.Contains("!")) CLRFLG(fSteerParam, BIT(iopt));
256       processed = kTRUE;
257       break;    
258     }
259     if(processed) continue;
260
261     AliWarning(Form("Unknown option flag %s.", sopt.Data()));
262   }
263 }
264
265 //_____________________________________________________________________________
266 void AliTRDReconstructor::Options(UInt_t steer)
267 {
268   //
269   // Print the options
270   //
271
272   for(Int_t iopt=0; iopt<kNsteer; iopt++){
273     AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
274   }
275 }
276