Commented unnecessary include AliLog
[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 //
954135b1 21// //
22// For the special options which can be used during reconstruction and their //
23// default values pls. see function SetOption(). //
121a60bd 24// //
25///////////////////////////////////////////////////////////////////////////////
26
3a039a31 27#include <TObjString.h>
28#include <TObjArray.h>
d39401ad 29#include <TTreeStream.h>
30#include <TDirectory.h>
cb8b99ee 31#include <TRef.h>
121a60bd 32
3bc9d03e 33#include "AliRawReader.h"
cb8b99ee 34#include "AliLog.h"
3bc9d03e 35
36#include "AliTRDReconstructor.h"
3fe61b77 37#include "AliTRDclusterizer.h"
a8fbb161 38#include "AliTRDrawData.h"
8df1f8f5 39#include "AliTRDrawStream.h"
a8fbb161 40#include "AliTRDdigitsManager.h"
e4f2f73d 41#include "AliTRDtrackerV1.h"
cb8b99ee 42#include "AliESDEvent.h"
43#include "AliESDTrdTrack.h"
44#include "AliESDTrdTracklet.h"
c4daee41 45#include "AliESDTrdTrigger.h"
cb8b99ee 46#include "AliTRDtrackletWord.h"
29f95561 47
97b6dfac 48#define SETFLG(n,f) ((n) |= f)
49#define CLRFLG(n,f) ((n) &= ~f)
50
121a60bd 51ClassImp(AliTRDReconstructor)
52
c4daee41 53AliESDTrdTrigger AliTRDReconstructor::fgTriggerFlags;
828c6f80 54TClonesArray *AliTRDReconstructor::fgClusters = NULL;
55TClonesArray *AliTRDReconstructor::fgTracklets = NULL;
cb8b99ee 56TClonesArray *AliTRDReconstructor::fgTracks = NULL;
828c6f80 57Char_t const * AliTRDReconstructor::fgSteerNames[kNsteer] = {
b72f4eaf 58 "DigitsConversion "
b72f4eaf 59 ,"Write Clusters "
60 ,"Write Online Tracklets "
b72f4eaf 61 ,"Stand Alone Tracking "
8fc736d7 62 ,"HLT Mode "
63 ,"Process Online Trklts "
64 ,"Debug Streaming "
65 ,"Cl. Radial Correction "
b72f4eaf 66};
828c6f80 67Char_t const * AliTRDReconstructor::fgSteerFlags[kNsteer] = {
b72f4eaf 68 "dc"// digits conversion [false]
b72f4eaf 69 ,"cw"// write clusters [true]
70 ,"tw"// write online tracklets [false]
b72f4eaf 71 ,"sa"// track seeding (stand alone tracking) [true]
b72f4eaf 72 ,"hlt"// HLT reconstruction [false]
a5b99acd 73 ,"tp"// also use online tracklets for reconstruction [false]
a2fbb6ec 74 ,"deb"// Write debug stream [false]
b30d8c09 75 ,"cc" // Cluster radial correction during reconstruction [false]
b72f4eaf 76};
828c6f80 77Char_t const * AliTRDReconstructor::fgTaskNames[AliTRDrecoParam::kTRDreconstructionTasks] = {
a2fbb6ec 78 "Clusterizer"
b72f4eaf 79 ,"Tracker"
80 ,"PID"
81};
828c6f80 82Char_t const * AliTRDReconstructor::fgTaskFlags[AliTRDrecoParam::kTRDreconstructionTasks] = {
a2fbb6ec 83 "cl"
b72f4eaf 84 ,"tr"
85 ,"pd"
86};
c6f7c6cb 87Int_t AliTRDReconstructor::fgNTimeBins = -1;
952051c5 88const Float_t AliTRDReconstructor::fgkMinClustersInTrack = 0.5; //
89const Float_t AliTRDReconstructor::fgkLabelFraction = 0.8; //
90const Double_t AliTRDReconstructor::fgkMaxChi2 = 12.0; //
91const Double_t AliTRDReconstructor::fgkMaxSnp = 0.95; // Maximum local sine of the azimuthal angle
92const Double_t AliTRDReconstructor::fgkMaxStep = 2.0; // Maximal step size in propagation
93const Double_t AliTRDReconstructor::fgkEpsilon = 1.e-5; // Precision of radial coordinate
b72f4eaf 94
eb38ed55 95//_____________________________________________________________________________
3a039a31 96AliTRDReconstructor::AliTRDReconstructor()
97 :AliReconstructor()
97b6dfac 98 ,fSteerParam(0)
5127281e 99 ,fClusterizer(NULL)
3a039a31 100{
97b6dfac 101 // setting default "ON" steering parameters
89971837 102 // owner of debug streamers
103 SETFLG(fSteerParam, kOwner);
97b6dfac 104 // write clusters [cw]
105 SETFLG(fSteerParam, kWriteClusters);
106 // track seeding (stand alone tracking) [sa]
9dcc64cc 107 //SETFLG(fSteerParam, kSeeding);
8fc736d7 108 // Cluster radial correction during reconstruction [cc]
b30d8c09 109 //SETFLG(fSteerParam, kClRadialCorr);
a2fbb6ec 110 memset(fDebugStream, 0, sizeof(TTreeSRedirector *) * AliTRDrecoParam::kTRDreconstructionTasks);
eb38ed55 111}
112
3a039a31 113//_____________________________________________________________________________
48f8adf3 114AliTRDReconstructor::~AliTRDReconstructor()
115{
d39401ad 116 //
117 // Destructor
118 //
119
48f8adf3 120 if(fgClusters) {
6d54fcbf 121 fgClusters->Delete();
122 delete fgClusters;
123 fgClusters = NULL;
48f8adf3 124 }
a5b99acd 125 if(fgTracklets) {
6d54fcbf 126 fgTracklets->Delete();
127 delete fgTracklets;
128 fgTracklets = NULL;
a5b99acd 129 }
cb8b99ee 130 if(fgTracks) {
131 fgTracks->Delete();
132 delete fgTracks;
133 fgTracks = NULL;
134 }
f29f13a6 135 if(fSteerParam&kOwner){
a2fbb6ec 136 for(Int_t itask = 0; itask < AliTRDrecoParam::kTRDreconstructionTasks; itask++)
29f95561 137 if(fDebugStream[itask]) delete fDebugStream[itask];
138 }
5127281e 139 if(fClusterizer){
140 delete fClusterizer;
141 fClusterizer = NULL;
142 }
18c05eb3 143}
48f8adf3 144
91834b8d 145
48f8adf3 146//_____________________________________________________________________________
91834b8d 147void AliTRDReconstructor::Init(){
18c05eb3 148 //
149 // Init Options
150 //
18c05eb3 151 SetOption(GetOption());
a2fbb6ec 152 Options(fSteerParam);
153
5127281e 154 if(!fClusterizer){
155 fClusterizer = new AliTRDclusterizer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
156 fClusterizer->SetReconstructor(this);
157 }
158
a2fbb6ec 159 // Make Debug Streams when Debug Streaming
160 if(IsDebugStreaming()){
161 for(Int_t task = 0; task < AliTRDrecoParam::kTRDreconstructionTasks; task++){
162 TDirectory *savedir = gDirectory;
163 fDebugStream[task] = new TTreeSRedirector(Form("TRD.Debug%s.root", fgTaskNames[task]));
164 savedir->cd();
165 SETFLG(fSteerParam, kOwner);
166 }
167 }
acd241e9 168}
0397ce53 169
121a60bd 170//_____________________________________________________________________________
a8fbb161 171void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader
91834b8d 172 , TTree *digitsTree) const
121a60bd 173{
3bc9d03e 174 //
25ca55ce 175 // Convert raw data digits into digit objects in a root tree
3bc9d03e 176 //
121a60bd 177
ad5dd6ec 178 //AliInfo("Convert raw data digits into digit objects [RawReader -> Digit TTree]");
91834b8d 179
a8fbb161 180 AliTRDrawData rawData;
3a0f6479 181 rawReader->Reset();
182 rawReader->Select("TRD");
a8fbb161 183 AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
184 manager->MakeBranch(digitsTree);
185 manager->WriteDigits();
c0ab62ff 186 delete manager;
0ee00e25 187
cb8b99ee 188 // take over ownership of online tracklets
189 fgTracklets = rawData.TrackletsArray();
190 rawData.SetTrackletsOwner(0x0);
191
192 // take over GTU tracks
193 fgTracks = rawData.TracksArray();
194 rawData.SetTracksOwner(0x0);
c4daee41 195
196 for (Int_t iSector = 0; iSector < 18; iSector++) {
197 fgTriggerFlags.SetFlags(iSector, rawData.GetTriggerFlags(iSector));
198 }
121a60bd 199}
200
201//_____________________________________________________________________________
25ca55ce 202void AliTRDReconstructor::Reconstruct(AliRawReader *rawReader
203 , TTree *clusterTree) const
204{
205 //
206 // Reconstruct clusters
207 //
208
91834b8d 209 //AliInfo("Reconstruct TRD clusters from RAW data [RawReader -> Cluster TTree]");
210
211
3a0f6479 212 rawReader->Reset();
213 rawReader->Select("TRD");
214
5127281e 215 if(!fClusterizer){
216 AliFatal("Clusterizer not available!");
217 return;
218 }
219
da0a4b87 220 fClusterizer->ResetRecPoints();
221
5127281e 222 fClusterizer->OpenOutput(clusterTree);
5127281e 223 fClusterizer->SetUseLabels(kFALSE);
07897df4 224 fClusterizer->SetStoreRawSignals(kTRUE);
5127281e 225 fClusterizer->Raw2ClustersChamber(rawReader);
66f6bfd9 226
3e1f6592 227 fgNTimeBins = fClusterizer->GetNTimeBins();
228
cb8b99ee 229 // take over ownership of online tracklets
230 fgTracklets = fClusterizer->TrackletsArray();
231 fClusterizer->SetTrackletsOwner(kFALSE);
232
233 // take over GTU tracks
234 fgTracks = fClusterizer->TracksArray();
235 fClusterizer->SetTracksOwner(kFALSE);
236
c4daee41 237 for (Int_t iSector = 0; iSector < 18; iSector++) {
238 fgTriggerFlags.SetFlags(iSector, fClusterizer->GetTriggerFlags(iSector));
239 }
240
66f6bfd9 241 if(IsWritingClusters()) return;
d6e36038 242
66f6bfd9 243 // take over ownership of clusters
5127281e 244 fgClusters = fClusterizer->RecPoints();
245 fClusterizer->SetClustersOwner(kFALSE);
25ca55ce 246}
247
248//_____________________________________________________________________________
a8fbb161 249void AliTRDReconstructor::Reconstruct(TTree *digitsTree
250 , TTree *clusterTree) const
25ca55ce 251{
252 //
253 // Reconstruct clusters
254 //
e4f2f73d 255
91834b8d 256 //AliInfo("Reconstruct TRD clusters from Digits [Digit TTree -> Cluster TTree]");
a2fbb6ec 257
c665eaa7 258 AliTRDclusterizer clusterer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
259 clusterer.SetReconstructor(this);
302bfc4e 260 clusterer.SetUseLabels(kTRUE);
07897df4 261 clusterer.SetStoreRawSignals(kTRUE);
c665eaa7 262 clusterer.OpenOutput(clusterTree);
263 clusterer.ReadDigits(digitsTree);
264 clusterer.MakeClusters();
d6e36038 265
cb8b99ee 266 // read tracklets and tracks if not done during reading of raw data
267 if (!fgTracklets) {
268 clusterer.ReadTracklets();
269 fgTracklets = clusterer.TrackletsArray();
270 clusterer.SetTrackletsOwner(kFALSE);
271 }
272 if (!fgTracks) {
273 clusterer.ReadTracks();
274 fgTracks = clusterer.TracksArray();
275 clusterer.SetTracksOwner(kFALSE);
276 }
277
3e1f6592 278 fgNTimeBins = clusterer.GetNTimeBins();
279
66f6bfd9 280 if(IsWritingClusters()) return;
281
282 // take over ownership of clusters
c665eaa7 283 fgClusters = clusterer.RecPoints();
284 clusterer.SetClustersOwner(kFALSE);
25ca55ce 285}
286
287//_____________________________________________________________________________
44dbae42 288AliTracker *AliTRDReconstructor::CreateTracker() const
121a60bd 289{
3bc9d03e 290 //
291 // Create a TRD tracker
292 //
121a60bd 293
e4f2f73d 294 //return new AliTRDtracker(NULL);
3a039a31 295 AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
296 tracker->SetReconstructor(this);
297 return tracker;
25ca55ce 298
25ca55ce 299}
300
301//_____________________________________________________________________________
302void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
91834b8d 303 , TTree* /*clusterTree*/
cb8b99ee 304 , AliESDEvent* esd) const
25ca55ce 305{
306 //
af26ce80 307 // Fill ESD
25ca55ce 308 //
309
cb8b99ee 310 // ----- filling tracklets -----
311 Int_t trackletIndex[1080] = { 0 };
312 AliDebug(1, Form("Filling tracklets from %p (%i)",
313 fgTracklets, fgTracklets ? fgTracklets->GetEntriesFast() : 0));
314 if (fgTracklets) {
315 Int_t nTracklets = fgTracklets->GetEntriesFast();
316
317 Int_t lastHC = -1;
318 for (Int_t iTracklet = 0; iTracklet < nTracklets; iTracklet++) {
319 AliTRDtrackletBase *trkl = (AliTRDtrackletBase*) ((*fgTracklets)[iTracklet]);
320 Int_t hc = trkl->GetHCId();
321 // hc += trkl->GetY() > 0 ? 1 : 0;
322 if ((hc < 0) || (hc >= 1080)) {
323 AliError(Form("HC for tracklet: 0x%08x out of range: %i", trkl->GetTrackletWord(), trkl->GetHCId()));
324 continue;
c4daee41 325 }
cb8b99ee 326 AliDebug(5, Form("hc: %4i : 0x%08x z: %2i", hc, trkl->GetTrackletWord(), trkl->GetZbin()));
327 if (hc != lastHC) {
328 AliDebug(2, Form("set tracklet index for HC %i to %i", hc, iTracklet));
329 trackletIndex[hc] = iTracklet + 1;
330 lastHC = hc;
331 }
332 }
333
334 for (Int_t iDet = 0; iDet < 540; iDet++) {
335 Int_t trklIndexA = trackletIndex[2*iDet + 0] - 1;
336 Int_t trklIndexB = trackletIndex[2*iDet + 1] - 1;
337 Int_t trklIndex = esd->GetNumberOfTrdTracklets();
338 AliTRDtrackletBase *trklA = trklIndexA > -1 ? (AliTRDtrackletBase*) ((*fgTracklets)[trklIndexA]) : 0x0;
339 AliTRDtrackletBase *trklB = trklIndexB > -1 ? (AliTRDtrackletBase*) ((*fgTracklets)[trklIndexB]) : 0x0;
340 while (trklA != 0x0 || trklB != 0x0) {
341 AliDebug(5, Form("det %i - A: %i/%i -> %p, B: %i/%i -> %p",
342 iDet, trklIndexA, nTracklets, trklA, trklIndexB, nTracklets, trklB));
343 if (trklA == 0x0) {
344 AliESDTrdTracklet esdTracklet(trklB->GetTrackletWord(), trklB->GetHCId());
345 esd->AddTrdTracklet(&esdTracklet);
346 trklIndexB++;
347 trklB = trklIndexB < nTracklets ? (AliTRDtrackletBase*) ((*fgTracklets)[trklIndexB]) : 0x0;
348 if (trklB && trklB->GetHCId() != 2*iDet + 1)
349 trklB = 0x0;
350 }
351 else if (trklB == 0x0) {
352 AliESDTrdTracklet esdTracklet(trklA->GetTrackletWord(), trklA->GetHCId());
353 esd->AddTrdTracklet(&esdTracklet);
354 trklIndexA++;
355 trklA = trklIndexA < nTracklets ? (AliTRDtrackletBase*) ((*fgTracklets)[trklIndexA]) : 0x0;
356 if (trklA && trklA->GetHCId() != 2*iDet)
357 trklA = 0x0;
358 }
359 else {
360 if ((trklA->GetZbin() < trklB->GetZbin()) ||
361 ((trklA->GetZbin() == trklB->GetZbin()) && (trklA->GetYbin() < trklB->GetYbin()))) {
362 AliESDTrdTracklet esdTracklet(trklA->GetTrackletWord(), trklA->GetHCId());
363 esd->AddTrdTracklet(&esdTracklet);
364 trklIndexA++;
365 trklA = trklIndexA < nTracklets ? (AliTRDtrackletBase*) ((*fgTracklets)[trklIndexA]) : 0x0;
366 if (trklA && trklA->GetHCId() != 2*iDet)
367 trklA = 0x0;
368 }
369 else {
370 AliESDTrdTracklet esdTracklet(trklB->GetTrackletWord(), trklB->GetHCId());
371 esd->AddTrdTracklet(&esdTracklet);
372 trklIndexB++;
373 trklB = trklIndexB < nTracklets ? (AliTRDtrackletBase*) ((*fgTracklets)[trklIndexB]) : 0x0;
374 if (trklB && trklB->GetHCId() != 2*iDet + 1)
375 trklB = 0x0;
376 }
377 }
378 }
379 // updating tracklet indices as in ESD
380 if (esd->GetNumberOfTrdTracklets() != trklIndex) {
381 trackletIndex[2*iDet + 0] = trackletIndex[2*iDet + 1] = trklIndex;
382 }
383 else
384 trackletIndex[2*iDet + 0] = trackletIndex[2*iDet + 1] = -1;
385 }
386 }
387
388 // ----- filling GTU tracks -----
389 AliDebug(1, Form("Now filling ESD with GTU tracks from %p (%i)",
390 fgTracks, fgTracks ? fgTracks->GetEntriesFast() : 0));
391 if (fgTracks) {
392 for (Int_t iTrack = 0; iTrack < fgTracks->GetEntriesFast(); iTrack++) {
393 AliESDTrdTrack *trdTrack = (AliESDTrdTrack*) ((*fgTracks)[iTrack]);
394
395 UInt_t mask = trdTrack->GetLayerMask();
396 UInt_t stack = trdTrack->GetStack();
397
398 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
399 if (mask & (1 << iLayer)) {
400
401 Int_t det = trdTrack->GetSector()*30 + stack*6 + iLayer;
402 Int_t idx = trdTrack->GetTrackletIndex(iLayer);
403
404 if ((det < 0) || (det > 539)) {
405 AliError(Form("Invalid detector no. from track: %i", 2*det));
406 continue;
407 }
408 if (trackletIndex[2*det] >= 0) {
409 if ((trackletIndex[2*det] + idx > -1) &&
410 (trackletIndex[2*det] + idx < esd->GetNumberOfTrdTracklets())) {
411 AliESDTrdTracklet *trkl = esd->GetTrdTracklet(trackletIndex[2*det] + idx);
412 if (trkl) {
413 AliDebug(5, Form("adding tracklet: 0x%08x", trkl->GetTrackletWord()));
414 trdTrack->AddTrackletReference(trkl, iLayer);
415 }
416 }
417 }
418 }
419 }
420 // only add the track when it's complete (including tracklet references)
421 esd->AddTrdTrack(trdTrack);
422 }
423 }
424
c4daee41 425 esd->SetTrdTrigger(&fgTriggerFlags);
426
cb8b99ee 427 // clearing variables for next event
428 fgTracklets = 0x0;
429 fgTracks = 0x0;
25ca55ce 430}
3a039a31 431
828c6f80 432//_____________________________________________________________________________
3a039a31 433void AliTRDReconstructor::SetOption(Option_t *opt)
434{
d39401ad 435 //
436 // Read option string into the steer param.
437 //
954135b1 438 // The following string options are available during reconstruction.
439 // In square brackets the default values are given.
440 // "dc" : digits conversion [false]
441 // "cw" : write clusters [true]
442 // "tw" : write online tracklets [false]
443 // "sa" : track seeding (stand alone tracking) [true]
444 // "hlt" : HLT reconstruction [false]
445 // "tp" : also use online tracklets for reconstruction [false]
446 // "deb" : Write debug stream [false]
447 // "cc" : Cluster radial correction during reconstruction [false]
448 //
449 // To check the actual options used during reconstruction include the following line in your rec.C script
450 // AliLog::SetClassDebugLevel("AliTRDReconstructor", 1);
97b6dfac 451
452 AliReconstructor::SetOption(opt);
3a039a31 453
454 TString s(opt);
455 TObjArray *opar = s.Tokenize(",");
456 for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
d39401ad 457 Bool_t processed = kFALSE;
3a039a31 458 TString sopt(((TObjString*)(*opar)[ipar])->String());
b72f4eaf 459 for(Int_t iopt=0; iopt<kNsteer; iopt++){
460 if(!sopt.Contains(fgSteerFlags[iopt])) continue;
461 SETFLG(fSteerParam, BIT(iopt));
462 if(sopt.Contains("!")) CLRFLG(fSteerParam, BIT(iopt));
d39401ad 463 processed = kTRUE;
b72f4eaf 464 break;
465 }
d39401ad 466 if(processed) continue;
b72f4eaf 467
468 AliWarning(Form("Unknown option flag %s.", sopt.Data()));
3a039a31 469 }
470}
471
acd241e9 472//_____________________________________________________________________________
a2fbb6ec 473void AliTRDReconstructor::Options(UInt_t steer)
b72f4eaf 474{
d39401ad 475 //
476 // Print the options
477 //
478
b72f4eaf 479 for(Int_t iopt=0; iopt<kNsteer; iopt++){
9e8fdff4 480 AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
b72f4eaf 481 }
b72f4eaf 482}
483