Revert some of the recent changes (Theo)
[u/mrichter/AliRoot.git] / TRD / AliTRDReconstructor.cxx
CommitLineData
121a60bd 1/**************************************************************************
91834b8d 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**************************************************************************/
121a60bd 15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
4fad09c9 20// Class for TRD reconstruction //
121a60bd 21// //
22///////////////////////////////////////////////////////////////////////////////
23
3a039a31 24#include <TObjString.h>
25#include <TObjArray.h>
d39401ad 26#include <TTreeStream.h>
27#include <TDirectory.h>
121a60bd 28
3bc9d03e 29#include "AliRawReader.h"
3bc9d03e 30
31#include "AliTRDReconstructor.h"
3fe61b77 32#include "AliTRDclusterizer.h"
a8fbb161 33#include "AliTRDrawData.h"
a2fbb6ec 34#include "AliTRDrawStreamBase.h"
a8fbb161 35#include "AliTRDdigitsManager.h"
e4f2f73d 36#include "AliTRDtrackerV1.h"
29f95561 37
97b6dfac 38#define SETFLG(n,f) ((n) |= f)
39#define CLRFLG(n,f) ((n) &= ~f)
40
121a60bd 41ClassImp(AliTRDReconstructor)
42
828c6f80 43TClonesArray *AliTRDReconstructor::fgClusters = NULL;
44TClonesArray *AliTRDReconstructor::fgTracklets = NULL;
828c6f80 45Char_t const * AliTRDReconstructor::fgSteerNames[kNsteer] = {
b72f4eaf 46 "DigitsConversion "
b72f4eaf 47 ,"Write Clusters "
48 ,"Write Online Tracklets "
b72f4eaf 49 ,"Stand Alone Tracking "
a2fbb6ec 50 ,"HLT Mode "
a5b99acd 51 ,"Process Online Tracklets"
a2fbb6ec 52 ,"Debug Streaming "
b72f4eaf 53};
828c6f80 54Char_t const * AliTRDReconstructor::fgSteerFlags[kNsteer] = {
b72f4eaf 55 "dc"// digits conversion [false]
b72f4eaf 56 ,"cw"// write clusters [true]
57 ,"tw"// write online tracklets [false]
b72f4eaf 58 ,"sa"// track seeding (stand alone tracking) [true]
b72f4eaf 59 ,"hlt"// HLT reconstruction [false]
a5b99acd 60 ,"tp"// also use online tracklets for reconstruction [false]
a2fbb6ec 61 ,"deb"// Write debug stream [false]
b72f4eaf 62};
828c6f80 63Char_t const * AliTRDReconstructor::fgTaskNames[AliTRDrecoParam::kTRDreconstructionTasks] = {
a2fbb6ec 64 "Clusterizer"
b72f4eaf 65 ,"Tracker"
66 ,"PID"
67};
828c6f80 68Char_t const * AliTRDReconstructor::fgTaskFlags[AliTRDrecoParam::kTRDreconstructionTasks] = {
a2fbb6ec 69 "cl"
b72f4eaf 70 ,"tr"
71 ,"pd"
72};
c6f7c6cb 73Int_t AliTRDReconstructor::fgNTimeBins = -1;
b72f4eaf 74
eb38ed55 75//_____________________________________________________________________________
3a039a31 76AliTRDReconstructor::AliTRDReconstructor()
77 :AliReconstructor()
97b6dfac 78 ,fSteerParam(0)
5127281e 79 ,fClusterizer(NULL)
3a039a31 80{
97b6dfac 81 // setting default "ON" steering parameters
89971837 82 // owner of debug streamers
83 SETFLG(fSteerParam, kOwner);
97b6dfac 84 // write clusters [cw]
85 SETFLG(fSteerParam, kWriteClusters);
86 // track seeding (stand alone tracking) [sa]
87 SETFLG(fSteerParam, kSeeding);
a2fbb6ec 88
89 memset(fDebugStream, 0, sizeof(TTreeSRedirector *) * AliTRDrecoParam::kTRDreconstructionTasks);
eb38ed55 90}
91
3a039a31 92//_____________________________________________________________________________
48f8adf3 93AliTRDReconstructor::~AliTRDReconstructor()
94{
d39401ad 95 //
96 // Destructor
97 //
98
48f8adf3 99 if(fgClusters) {
6d54fcbf 100 fgClusters->Delete();
101 delete fgClusters;
102 fgClusters = NULL;
48f8adf3 103 }
a5b99acd 104 if(fgTracklets) {
6d54fcbf 105 fgTracklets->Delete();
106 delete fgTracklets;
107 fgTracklets = NULL;
a5b99acd 108 }
f29f13a6 109 if(fSteerParam&kOwner){
a2fbb6ec 110 for(Int_t itask = 0; itask < AliTRDrecoParam::kTRDreconstructionTasks; itask++)
29f95561 111 if(fDebugStream[itask]) delete fDebugStream[itask];
112 }
5127281e 113 if(fClusterizer){
114 delete fClusterizer;
115 fClusterizer = NULL;
116 }
18c05eb3 117}
48f8adf3 118
91834b8d 119
48f8adf3 120//_____________________________________________________________________________
91834b8d 121void AliTRDReconstructor::Init(){
18c05eb3 122 //
123 // Init Options
124 //
18c05eb3 125 SetOption(GetOption());
a2fbb6ec 126 Options(fSteerParam);
127
5127281e 128 if(!fClusterizer){
129 fClusterizer = new AliTRDclusterizer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
130 fClusterizer->SetReconstructor(this);
131 }
132
a2fbb6ec 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 }
acd241e9 142}
0397ce53 143
121a60bd 144//_____________________________________________________________________________
a8fbb161 145void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader
91834b8d 146 , TTree *digitsTree) const
121a60bd 147{
3bc9d03e 148 //
25ca55ce 149 // Convert raw data digits into digit objects in a root tree
3bc9d03e 150 //
121a60bd 151
ad5dd6ec 152 //AliInfo("Convert raw data digits into digit objects [RawReader -> Digit TTree]");
91834b8d 153
a8fbb161 154 AliTRDrawData rawData;
3a0f6479 155 rawReader->Reset();
156 rawReader->Select("TRD");
92c7f341 157 rawData.OpenOutput();
a2fbb6ec 158 AliTRDrawStreamBase::SetRawStreamVersion(GetRecoParam()->GetRawStreamVersion()->Data());
a8fbb161 159 AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
160 manager->MakeBranch(digitsTree);
161 manager->WriteDigits();
c0ab62ff 162 delete manager;
0ee00e25 163
121a60bd 164}
165
166//_____________________________________________________________________________
25ca55ce 167void AliTRDReconstructor::Reconstruct(AliRawReader *rawReader
168 , TTree *clusterTree) const
169{
170 //
171 // Reconstruct clusters
172 //
173
91834b8d 174 //AliInfo("Reconstruct TRD clusters from RAW data [RawReader -> Cluster TTree]");
175
176
3a0f6479 177 rawReader->Reset();
178 rawReader->Select("TRD");
a2fbb6ec 179 AliTRDrawStreamBase::SetRawStreamVersion(GetRecoParam()->GetRawStreamVersion()->Data());
3a0f6479 180
5127281e 181 if(!fClusterizer){
182 AliFatal("Clusterizer not available!");
183 return;
184 }
185
da0a4b87 186 fClusterizer->ResetRecPoints();
187
5127281e 188 fClusterizer->OpenOutput(clusterTree);
189 fClusterizer->OpenTrackletOutput();
190 fClusterizer->SetUseLabels(kFALSE);
191 fClusterizer->Raw2ClustersChamber(rawReader);
66f6bfd9 192
193 if(IsWritingClusters()) return;
d6e36038 194
66f6bfd9 195 // take over ownership of clusters
5127281e 196 fgClusters = fClusterizer->RecPoints();
197 fClusterizer->SetClustersOwner(kFALSE);
a5b99acd 198
199 // take over ownership of online tracklets
5127281e 200 fgTracklets = fClusterizer->TrackletsArray();
201 fClusterizer->SetTrackletsOwner(kFALSE);
c6f7c6cb 202
5127281e 203 fgNTimeBins = fClusterizer->GetNTimeBins();
25ca55ce 204}
205
206//_____________________________________________________________________________
a8fbb161 207void AliTRDReconstructor::Reconstruct(TTree *digitsTree
208 , TTree *clusterTree) const
25ca55ce 209{
210 //
211 // Reconstruct clusters
212 //
e4f2f73d 213
91834b8d 214 //AliInfo("Reconstruct TRD clusters from Digits [Digit TTree -> Cluster TTree]");
a2fbb6ec 215
c665eaa7 216 AliTRDclusterizer clusterer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
217 clusterer.SetReconstructor(this);
218 clusterer.OpenOutput(clusterTree);
219 clusterer.ReadDigits(digitsTree);
220 clusterer.MakeClusters();
d6e36038 221
66f6bfd9 222 if(IsWritingClusters()) return;
223
224 // take over ownership of clusters
c665eaa7 225 fgClusters = clusterer.RecPoints();
226 clusterer.SetClustersOwner(kFALSE);
a5b99acd 227
228 // take over ownership of online tracklets
c665eaa7 229 fgTracklets = clusterer.TrackletsArray();
230 clusterer.SetTrackletsOwner(kFALSE);
231
232 fgNTimeBins = clusterer.GetNTimeBins();
c6f7c6cb 233
25ca55ce 234}
235
236//_____________________________________________________________________________
44dbae42 237AliTracker *AliTRDReconstructor::CreateTracker() const
121a60bd 238{
3bc9d03e 239 //
240 // Create a TRD tracker
241 //
121a60bd 242
e4f2f73d 243 //return new AliTRDtracker(NULL);
3a039a31 244 AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
245 tracker->SetReconstructor(this);
246 return tracker;
25ca55ce 247
25ca55ce 248}
249
250//_____________________________________________________________________________
251void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
91834b8d 252 , TTree* /*clusterTree*/
253 , AliESDEvent* /*esd*/) const
25ca55ce 254{
255 //
af26ce80 256 // Fill ESD
25ca55ce 257 //
258
25ca55ce 259}
3a039a31 260
828c6f80 261//_____________________________________________________________________________
3a039a31 262void AliTRDReconstructor::SetOption(Option_t *opt)
263{
d39401ad 264 //
265 // Read option string into the steer param.
266 //
97b6dfac 267
268 AliReconstructor::SetOption(opt);
3a039a31 269
270 TString s(opt);
271 TObjArray *opar = s.Tokenize(",");
272 for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
d39401ad 273 Bool_t processed = kFALSE;
3a039a31 274 TString sopt(((TObjString*)(*opar)[ipar])->String());
b72f4eaf 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));
d39401ad 279 processed = kTRUE;
b72f4eaf 280 break;
281 }
d39401ad 282 if(processed) continue;
b72f4eaf 283
284 AliWarning(Form("Unknown option flag %s.", sopt.Data()));
3a039a31 285 }
286}
287
acd241e9 288//_____________________________________________________________________________
a2fbb6ec 289void AliTRDReconstructor::Options(UInt_t steer)
b72f4eaf 290{
d39401ad 291 //
292 // Print the options
293 //
294
b72f4eaf 295 for(Int_t iopt=0; iopt<kNsteer; iopt++){
9e8fdff4 296 AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
b72f4eaf 297 }
b72f4eaf 298}
299