]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDReconstructor.cxx
Moving reconstruction settings to the reco params, new cosmics reco param OCDB entry...
[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   AliTRDrawStreamBase::SetSubtractBaseline(10);
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   // New (fast) cluster finder
182   AliTRDclusterizer clusterer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
183   clusterer.SetReconstructor(this);
184   clusterer.OpenOutput(clusterTree);
185   clusterer.OpenTrackletOutput();
186   clusterer.SetUseLabels(kFALSE);
187   clusterer.Raw2ClustersChamber(rawReader);
188   
189   if(IsWritingClusters()) return;
190
191   // take over ownership of clusters
192   fgClusters = clusterer.RecPoints();
193   clusterer.SetClustersOwner(kFALSE);
194
195   // take over ownership of online tracklets
196   fgTracklets = clusterer.TrackletsArray();
197   clusterer.SetTrackletsOwner(kFALSE);
198 }
199
200 //_____________________________________________________________________________
201 void AliTRDReconstructor::Reconstruct(TTree *digitsTree
202                                     , TTree *clusterTree) const
203 {
204   //
205   // Reconstruct clusters
206   //
207
208   //AliInfo("Reconstruct TRD clusters from Digits [Digit TTree -> Cluster TTree]");
209   
210   AliTRDclusterizer clusterer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
211   clusterer.SetReconstructor(this);
212   clusterer.OpenOutput(clusterTree);
213   clusterer.ReadDigits(digitsTree);
214   clusterer.MakeClusters();
215
216   if(IsWritingClusters()) return;
217
218   // take over ownership of clusters
219   fgClusters = clusterer.RecPoints();
220   clusterer.SetClustersOwner(kFALSE);
221
222   // take over ownership of online tracklets
223   fgTracklets = clusterer.TrackletsArray();
224   clusterer.SetTrackletsOwner(kFALSE);
225 }
226
227 //_____________________________________________________________________________
228 AliTracker *AliTRDReconstructor::CreateTracker() const
229 {
230   //
231   // Create a TRD tracker
232   //
233
234   //return new AliTRDtracker(NULL);
235   AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
236   tracker->SetReconstructor(this);
237   return tracker;
238
239 }
240
241 //_____________________________________________________________________________
242 void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
243         , TTree* /*clusterTree*/
244         , AliESDEvent* /*esd*/) const
245 {
246   //
247   // Fill ESD
248   //
249
250 }
251
252
253 //_____________________________________________________________________________
254 void AliTRDReconstructor::SetOption(Option_t *opt)
255 {
256   //
257   // Read option string into the steer param.
258   //
259
260   AliReconstructor::SetOption(opt);
261
262   TString s(opt);
263   TObjArray *opar = s.Tokenize(",");
264   for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
265     Bool_t processed = kFALSE;
266     TString sopt(((TObjString*)(*opar)[ipar])->String());
267     for(Int_t iopt=0; iopt<kNsteer; iopt++){
268       if(!sopt.Contains(fgSteerFlags[iopt])) continue;
269       SETFLG(fSteerParam, BIT(iopt));
270       if(sopt.Contains("!")) CLRFLG(fSteerParam, BIT(iopt));
271       processed = kTRUE;
272       break;    
273     }
274     if(processed) continue;
275
276     AliWarning(Form("Unknown option flag %s.", sopt.Data()));
277   }
278 }
279
280 //_____________________________________________________________________________
281 void AliTRDReconstructor::Options(UInt_t steer)
282 {
283   //
284   // Print the options
285   //
286
287   for(Int_t iopt=0; iopt<kNsteer; iopt++){
288     AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
289   }
290 }
291