]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDReconstructor.cxx
Fix tracklet writing
[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
e3b2b5e5 24#include <TFile.h>
3a039a31 25#include <TObjString.h>
26#include <TObjArray.h>
66f6bfd9 27#include <TClonesArray.h>
121a60bd 28
121a60bd 29#include "AliRunLoader.h"
3bc9d03e 30#include "AliRawReader.h"
31#include "AliLog.h"
3bc9d03e 32#include "AliESDTrdTrack.h"
af885e0f 33#include "AliESDEvent.h"
3bc9d03e 34
35#include "AliTRDReconstructor.h"
3fe61b77 36#include "AliTRDclusterizer.h"
121a60bd 37#include "AliTRDtracker.h"
b0f03c34 38#include "AliTRDpidESD.h"
a8fbb161 39#include "AliTRDrawData.h"
40#include "AliTRDdigitsManager.h"
e4f2f73d 41#include "AliTRDtrackerV1.h"
42#include "AliTRDrecoParam.h"
121a60bd 43
29f95561 44#include "TTreeStream.h"
45
97b6dfac 46#define SETFLG(n,f) ((n) |= f)
47#define CLRFLG(n,f) ((n) &= ~f)
48
121a60bd 49ClassImp(AliTRDReconstructor)
50
66f6bfd9 51TClonesArray *AliTRDReconstructor::fgClusters = 0x0;
a5b99acd 52TClonesArray *AliTRDReconstructor::fgTracklets = 0x0;
b72f4eaf 53Char_t* AliTRDReconstructor::fgSteerNames[kNsteer] = {
54 "DigitsConversion "
55 ,"Tail Cancellation "
56 ,"Clusters LUT "
57 ,"Clusters GAUSS "
58 ,"Clusters Sharing "
59 ,"NN PID "
60 ,"8 dEdx slices in ESD "
61 ,"Write Clusters "
62 ,"Write Online Tracklets "
63 ,"Drift Gas Argon "
64 ,"Stand Alone Tracking "
65 ,"Vertex Constrain "
66 ,"Tracklet Improve "
67 ,"HLT Mode "
68 ,"Cosmic Reconstruction "
a5b99acd 69 ,"Process Online Tracklets"
b72f4eaf 70};
71Char_t* AliTRDReconstructor::fgSteerFlags[kNsteer] = {
72 "dc"// digits conversion [false]
73 ,"tc"// apply tail cancellation [true]
c96d03ba 74 ,"lut"// look-up-table for cluster shape in the r-phi direction
b72f4eaf 75 ,"gs"// gauss cluster shape in the r-phi direction
76 ,"sh"// cluster sharing between tracks
77 ,"nn"// PID method in reconstruction (NN) [true]
78 ,"8s"// 8 dEdx slices in ESD [true]
79 ,"cw"// write clusters [true]
80 ,"tw"// write online tracklets [false]
81 ,"ar"// drift gas [false] - do not update the number of exponentials in the TC !
82 ,"sa"// track seeding (stand alone tracking) [true]
83 ,"vc"// vertex constrain on stand alone track finder [false]
84 ,"ti"// improve tracklets in stand alone track finder [true]
85 ,"hlt"// HLT reconstruction [false]
86 ,"cos"// Cosmic Reconstruction [false]
a5b99acd 87 ,"tp"// also use online tracklets for reconstruction [false]
b72f4eaf 88};
89Char_t* AliTRDReconstructor::fgTaskNames[kNtasks] = {
90 "RawReader"
91 ,"Clusterizer"
92 ,"Tracker"
93 ,"PID"
94};
95Char_t* AliTRDReconstructor::fgTaskFlags[kNtasks] = {
96 "rr"
97 ,"cl"
98 ,"tr"
99 ,"pd"
100};
101
eb38ed55 102//_____________________________________________________________________________
3a039a31 103AliTRDReconstructor::AliTRDReconstructor()
104 :AliReconstructor()
97b6dfac 105 ,fSteerParam(0)
3a039a31 106{
97b6dfac 107 // setting default "ON" steering parameters
89971837 108 // owner of debug streamers
109 SETFLG(fSteerParam, kOwner);
97b6dfac 110 // write clusters [cw]
111 SETFLG(fSteerParam, kWriteClusters);
112 // track seeding (stand alone tracking) [sa]
113 SETFLG(fSteerParam, kSeeding);
114 // PID method in reconstruction (NN) [nn]
115 SETFLG(fSteerParam, kSteerPID);
89971837 116 // number of dEdx slices in the ESD track [8s]
b72f4eaf 117 SETFLG(fSteerParam, kEightSlices);
118 // vertex constrain for stand alone track finder
119 SETFLG(fSteerParam, kVertexConstrained);
120 // improve tracklets for stand alone track finder
121 SETFLG(fSteerParam, kImproveTracklet);
122 // use look up table for cluster r-phi position
123 SETFLG(fSteerParam, kLUT);
124 // use tail cancellation
125 SETFLG(fSteerParam, kTC);
97b6dfac 126
89971837 127 memset(fStreamLevel, 0, kNtasks*sizeof(UChar_t));
128 memset(fDebugStream, 0, sizeof(TTreeSRedirector *) * kNtasks);
3a039a31 129 // Xe tail cancellation parameters
130 fTCParams[0] = 1.156; // r1
131 fTCParams[1] = 0.130; // r2
132 fTCParams[2] = 0.114; // c1
133 fTCParams[3] = 0.624; // c2
134 // Ar tail cancellation parameters
181c7f7e 135 fTCParams[4] = 6.; // r1
136 fTCParams[5] = 0.62; // r2
137 fTCParams[6] = 0.0087;// c1
138 fTCParams[7] = 0.07; // c2
eb38ed55 139}
140
3a039a31 141//_____________________________________________________________________________
142AliTRDReconstructor::AliTRDReconstructor(const AliTRDReconstructor &r)
143 :AliReconstructor(r)
181c7f7e 144 ,fSteerParam(r.fSteerParam)
3a039a31 145{
89971837 146 memcpy(fStreamLevel, r.fStreamLevel, kNtasks*sizeof(UChar_t));
91834b8d 147 memcpy(fTCParams, r.fTCParams, 8*sizeof(Double_t));
89971837 148 memcpy(fDebugStream, r.fDebugStream, sizeof(TTreeSRedirector *) *kNtasks);
149 // ownership of debug streamers is not taken
150 CLRFLG(fSteerParam, kOwner);
3a039a31 151}
eb38ed55 152
48f8adf3 153//_____________________________________________________________________________
154AliTRDReconstructor::~AliTRDReconstructor()
155{
156 if(fgClusters) {
157 fgClusters->Delete(); delete fgClusters;
158 }
a5b99acd 159 if(fgTracklets) {
160 fgTracklets->Delete(); delete fgTracklets;
161 }
f29f13a6 162 if(fSteerParam&kOwner){
89971837 163 for(Int_t itask = 0; itask < kNtasks; itask++)
29f95561 164 if(fDebugStream[itask]) delete fDebugStream[itask];
165 }
18c05eb3 166}
48f8adf3 167
91834b8d 168
acd241e9 169//_____________________________________________________________________________
91834b8d 170void AliTRDReconstructor::Init(){
18c05eb3 171 //
172 // Init Options
173 //
18c05eb3 174 SetOption(GetOption());
b72f4eaf 175 Options(fSteerParam, fStreamLevel);
acd241e9 176}
0397ce53 177
121a60bd 178//_____________________________________________________________________________
a8fbb161 179void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader
91834b8d 180 , TTree *digitsTree) const
121a60bd 181{
3bc9d03e 182 //
25ca55ce 183 // Convert raw data digits into digit objects in a root tree
3bc9d03e 184 //
121a60bd 185
ad5dd6ec 186 //AliInfo("Convert raw data digits into digit objects [RawReader -> Digit TTree]");
91834b8d 187
a8fbb161 188 AliTRDrawData rawData;
3a0f6479 189 rawReader->Reset();
190 rawReader->Select("TRD");
92c7f341 191 rawData.OpenOutput();
a8fbb161 192 AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
193 manager->MakeBranch(digitsTree);
194 manager->WriteDigits();
c0ab62ff 195 delete manager;
0ee00e25 196
121a60bd 197}
198
25ca55ce 199//_____________________________________________________________________________
200void AliTRDReconstructor::Reconstruct(AliRawReader *rawReader
201 , TTree *clusterTree) const
202{
203 //
204 // Reconstruct clusters
205 //
206
91834b8d 207 //AliInfo("Reconstruct TRD clusters from RAW data [RawReader -> Cluster TTree]");
208
209
3a0f6479 210 rawReader->Reset();
211 rawReader->Select("TRD");
212
ca21baaa 213 // New (fast) cluster finder
b72f4eaf 214 AliTRDclusterizer clusterer(fgTaskNames[kClusterizer], fgTaskNames[kClusterizer]);
3d0c7d6d 215 clusterer.SetReconstructor(this);
216 clusterer.OpenOutput(clusterTree);
b72f4eaf 217 clusterer.SetUseLabels(kFALSE);
ca21baaa 218 clusterer.Raw2ClustersChamber(rawReader);
66f6bfd9 219
220 if(IsWritingClusters()) return;
d6e36038 221
66f6bfd9 222 // take over ownership of clusters
223 fgClusters = clusterer.RecPoints();
224 clusterer.SetClustersOwner(kFALSE);
a5b99acd 225
226 // take over ownership of online tracklets
227 fgTracklets = clusterer.TrackletsArray();
228 clusterer.SetTrackletsOwner(kFALSE);
25ca55ce 229}
230
231//_____________________________________________________________________________
a8fbb161 232void AliTRDReconstructor::Reconstruct(TTree *digitsTree
233 , TTree *clusterTree) const
25ca55ce 234{
235 //
236 // Reconstruct clusters
237 //
e4f2f73d 238
91834b8d 239 //AliInfo("Reconstruct TRD clusters from Digits [Digit TTree -> Cluster TTree]");
240
b72f4eaf 241 AliTRDclusterizer clusterer(fgTaskNames[kClusterizer], fgTaskNames[kClusterizer]);
3d0c7d6d 242 clusterer.SetReconstructor(this);
243 clusterer.OpenOutput(clusterTree);
25ca55ce 244 clusterer.ReadDigits(digitsTree);
245 clusterer.MakeClusters();
d6e36038 246
66f6bfd9 247 if(IsWritingClusters()) return;
248
249 // take over ownership of clusters
250 fgClusters = clusterer.RecPoints();
251 clusterer.SetClustersOwner(kFALSE);
a5b99acd 252
253 // take over ownership of online tracklets
254 fgTracklets = clusterer.TrackletsArray();
255 clusterer.SetTrackletsOwner(kFALSE);
25ca55ce 256}
257
258//_____________________________________________________________________________
44dbae42 259AliTracker *AliTRDReconstructor::CreateTracker() const
121a60bd 260{
3bc9d03e 261 //
262 // Create a TRD tracker
263 //
121a60bd 264
e4f2f73d 265 //return new AliTRDtracker(NULL);
3a039a31 266 AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
267 tracker->SetReconstructor(this);
268 return tracker;
25ca55ce 269
25ca55ce 270}
271
272//_____________________________________________________________________________
273void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
91834b8d 274 , TTree* /*clusterTree*/
275 , AliESDEvent* /*esd*/) const
25ca55ce 276{
277 //
af26ce80 278 // Fill ESD
25ca55ce 279 //
280
25ca55ce 281}
3a039a31 282
91834b8d 283
3a039a31 284//_____________________________________________________________________________
285void AliTRDReconstructor::SetOption(Option_t *opt)
286{
91834b8d 287// Read option string into the steer param.
91834b8d 288//
97b6dfac 289
290 AliReconstructor::SetOption(opt);
3a039a31 291
292 TString s(opt);
293 TObjArray *opar = s.Tokenize(",");
294 for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
b72f4eaf 295 Bool_t PROCESSED = kFALSE;
3a039a31 296 TString sopt(((TObjString*)(*opar)[ipar])->String());
b72f4eaf 297 for(Int_t iopt=0; iopt<kNsteer; iopt++){
298 if(!sopt.Contains(fgSteerFlags[iopt])) continue;
299 SETFLG(fSteerParam, BIT(iopt));
300 if(sopt.Contains("!")) CLRFLG(fSteerParam, BIT(iopt));
301 PROCESSED = kTRUE;
302 break;
303 }
17de99aa 304 // extra rules
305 if(sopt.Contains("gs") && !sopt.Contains("!")){
306 CLRFLG(fSteerParam, kLUT); PROCESSED = kTRUE;
307 }
308
b72f4eaf 309 if(PROCESSED) continue;
310
311 if(sopt.Contains("sl")){
91834b8d 312 TObjArray *stl = sopt.Tokenize("_");
313 if(stl->GetEntriesFast() < 3) continue;
314 TString taskstr(((TObjString*)(*stl)[1])->String());
315 TString levelstring(((TObjString*)(*stl)[2])->String());
91834b8d 316 Int_t level = levelstring.Atoi();
b72f4eaf 317
318 // Set the stream Level
319 PROCESSED = kFALSE;
320 for(Int_t it=0; it<kNtasks; it++){
321 if(taskstr.CompareTo(fgTaskFlags[it]) != 0) continue;
322 SetStreamLevel(level, ETRDReconstructorTask(it));
323 PROCESSED = kTRUE;
324 }
325 }
326 if(PROCESSED) continue;
327
328 AliWarning(Form("Unknown option flag %s.", sopt.Data()));
3a039a31 329 }
330}
331
acd241e9 332//_____________________________________________________________________________
89971837 333void AliTRDReconstructor::SetStreamLevel(Int_t level, ETRDReconstructorTask task){
18c05eb3 334 //
335 // Set the Stream Level for one of the tasks Clusterizer, Tracker or PID
336 //
29f95561 337 const Int_t minLevel[4] = {1, 1, 2, 1}; // the minimum debug level upon which a debug stream is created for different tasks
91834b8d 338 //AliInfo(Form("Setting Stream Level for Task %s to %d", taskname.Data(),level));
18c05eb3 339 fStreamLevel[(Int_t)task] = level;
29f95561 340 // Initialize DebugStreamer if not yet done
341 if(level >= minLevel[task] && !fDebugStream[task]){
342 TDirectory *savedir = gDirectory;
b72f4eaf 343 fDebugStream[task] = new TTreeSRedirector(Form("TRD.Debug%s.root", fgTaskNames[task]));
29f95561 344 savedir->cd();
89971837 345 SETFLG(fSteerParam, kOwner);
29f95561 346 }
acd241e9 347}
b72f4eaf 348
349//_____________________________________________________________________________
350void AliTRDReconstructor::Options(UInt_t steer, UChar_t *stream)
351{
352 for(Int_t iopt=0; iopt<kNsteer; iopt++){
9e8fdff4 353 AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
b72f4eaf 354 }
9e8fdff4 355 AliDebugGeneral("AliTRDReconstructor", 1, " Debug Streaming");
b72f4eaf 356 for(Int_t it=0; it<kNtasks; it++)
9e8fdff4 357 AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s [sl_%s] %d", fgTaskNames[it], fgTaskFlags[it], stream ? stream[it] : 0));
b72f4eaf 358}
359