ALIROOT-5488 Remove build/include from the include directories
[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"
03e2f460 47#include "AliTRDtrackletMCM.h"
ff4c44cb 48#include "AliTRDonlineTrackMatching.h"
29f95561 49
97b6dfac 50#define SETFLG(n,f) ((n) |= f)
51#define CLRFLG(n,f) ((n) &= ~f)
52
121a60bd 53ClassImp(AliTRDReconstructor)
54
2c7f43b6 55Int_t AliTRDReconstructor::fgStreamLevel = 1; // stream (debug) level
56
57
c4daee41 58AliESDTrdTrigger AliTRDReconstructor::fgTriggerFlags;
ff4c44cb 59AliTRDonlineTrackMatching AliTRDReconstructor::fgOnlineTrackMatcher;
828c6f80 60TClonesArray *AliTRDReconstructor::fgClusters = NULL;
61TClonesArray *AliTRDReconstructor::fgTracklets = NULL;
cb8b99ee 62TClonesArray *AliTRDReconstructor::fgTracks = NULL;
828c6f80 63Char_t const * AliTRDReconstructor::fgSteerNames[kNsteer] = {
b72f4eaf 64 "DigitsConversion "
b72f4eaf 65 ,"Write Clusters "
66 ,"Write Online Tracklets "
b72f4eaf 67 ,"Stand Alone Tracking "
8fc736d7 68 ,"HLT Mode "
69 ,"Process Online Trklts "
70 ,"Debug Streaming "
71 ,"Cl. Radial Correction "
b72f4eaf 72};
828c6f80 73Char_t const * AliTRDReconstructor::fgSteerFlags[kNsteer] = {
b72f4eaf 74 "dc"// digits conversion [false]
b72f4eaf 75 ,"cw"// write clusters [true]
76 ,"tw"// write online tracklets [false]
b72f4eaf 77 ,"sa"// track seeding (stand alone tracking) [true]
b72f4eaf 78 ,"hlt"// HLT reconstruction [false]
a5b99acd 79 ,"tp"// also use online tracklets for reconstruction [false]
a2fbb6ec 80 ,"deb"// Write debug stream [false]
b30d8c09 81 ,"cc" // Cluster radial correction during reconstruction [false]
b72f4eaf 82};
828c6f80 83Char_t const * AliTRDReconstructor::fgTaskNames[AliTRDrecoParam::kTRDreconstructionTasks] = {
a2fbb6ec 84 "Clusterizer"
b72f4eaf 85 ,"Tracker"
86 ,"PID"
87};
828c6f80 88Char_t const * AliTRDReconstructor::fgTaskFlags[AliTRDrecoParam::kTRDreconstructionTasks] = {
a2fbb6ec 89 "cl"
b72f4eaf 90 ,"tr"
91 ,"pd"
92};
c6f7c6cb 93Int_t AliTRDReconstructor::fgNTimeBins = -1;
952051c5 94const Float_t AliTRDReconstructor::fgkMinClustersInTrack = 0.5; //
95const Float_t AliTRDReconstructor::fgkLabelFraction = 0.8; //
96const Double_t AliTRDReconstructor::fgkMaxChi2 = 12.0; //
97const Double_t AliTRDReconstructor::fgkMaxSnp = 0.95; // Maximum local sine of the azimuthal angle
98const Double_t AliTRDReconstructor::fgkMaxStep = 2.0; // Maximal step size in propagation
99const Double_t AliTRDReconstructor::fgkEpsilon = 1.e-5; // Precision of radial coordinate
b72f4eaf 100
eb38ed55 101//_____________________________________________________________________________
3a039a31 102AliTRDReconstructor::AliTRDReconstructor()
103 :AliReconstructor()
97b6dfac 104 ,fSteerParam(0)
5127281e 105 ,fClusterizer(NULL)
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]
9dcc64cc 113 //SETFLG(fSteerParam, kSeeding);
8fc736d7 114 // Cluster radial correction during reconstruction [cc]
b30d8c09 115 //SETFLG(fSteerParam, kClRadialCorr);
a2fbb6ec 116 memset(fDebugStream, 0, sizeof(TTreeSRedirector *) * AliTRDrecoParam::kTRDreconstructionTasks);
eb38ed55 117}
118
3a039a31 119//_____________________________________________________________________________
48f8adf3 120AliTRDReconstructor::~AliTRDReconstructor()
121{
d39401ad 122 //
123 // Destructor
124 //
125
d2eba04b 126 if(fClusterizer){
127 delete fClusterizer;
128 fClusterizer = NULL;
129 }
48f8adf3 130 if(fgClusters) {
6d54fcbf 131 fgClusters->Delete();
132 delete fgClusters;
133 fgClusters = NULL;
48f8adf3 134 }
a5b99acd 135 if(fgTracklets) {
6d54fcbf 136 fgTracklets->Delete();
137 delete fgTracklets;
138 fgTracklets = NULL;
a5b99acd 139 }
cb8b99ee 140 if(fgTracks) {
141 fgTracks->Delete();
142 delete fgTracks;
143 fgTracks = NULL;
144 }
2c7f43b6 145 if((fSteerParam&kOwner)|| AliTRDReconstructor::GetStreamLevel()>0){
a2fbb6ec 146 for(Int_t itask = 0; itask < AliTRDrecoParam::kTRDreconstructionTasks; itask++)
29f95561 147 if(fDebugStream[itask]) delete fDebugStream[itask];
148 }
18c05eb3 149}
48f8adf3 150
91834b8d 151
48f8adf3 152//_____________________________________________________________________________
91834b8d 153void AliTRDReconstructor::Init(){
18c05eb3 154 //
155 // Init Options
156 //
18c05eb3 157 SetOption(GetOption());
a2fbb6ec 158 Options(fSteerParam);
159
5127281e 160 if(!fClusterizer){
161 fClusterizer = new AliTRDclusterizer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
162 fClusterizer->SetReconstructor(this);
d2eba04b 163 AliInfo(Form("Build TRD clusterizer[%p]", (void*)fClusterizer));
5127281e 164 }
165
a2fbb6ec 166 // Make Debug Streams when Debug Streaming
167 if(IsDebugStreaming()){
168 for(Int_t task = 0; task < AliTRDrecoParam::kTRDreconstructionTasks; task++){
169 TDirectory *savedir = gDirectory;
2d2d464a 170 fDebugStream[task] = new TTreeSRedirector(Form("TRD.Debug%s.root", fgTaskNames[task]),"recreate");
a2fbb6ec 171 savedir->cd();
172 SETFLG(fSteerParam, kOwner);
173 }
174 }
acd241e9 175}
0397ce53 176
121a60bd 177//_____________________________________________________________________________
a8fbb161 178void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader
91834b8d 179 , TTree *digitsTree) const
121a60bd 180{
3bc9d03e 181 //
25ca55ce 182 // Convert raw data digits into digit objects in a root tree
3bc9d03e 183 //
121a60bd 184
d2eba04b 185 AliDebug(1, "Convert raw data digits into digit objects [RawReader -> Digit TTree]");
186 AliDebug(2, Form("clusters[%p] tracklets[%p] tracks[%p]", (void*)fgClusters, (void*)fgTracklets, (void*)fgTracks));
91834b8d 187
3a0f6479 188 rawReader->Reset();
189 rawReader->Select("TRD");
d2eba04b 190 ResetContainers();
191
192 AliTRDrawData rawData;
d2eba04b 193
a8fbb161 194 AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
195 manager->MakeBranch(digitsTree);
196 manager->WriteDigits();
c0ab62ff 197 delete manager;
0ee00e25 198
d2eba04b 199 for (Int_t iSector = 0; iSector < 18; iSector++) fgTriggerFlags.SetFlags(iSector, rawData.GetTriggerFlags(iSector));
121a60bd 200}
201
202//_____________________________________________________________________________
25ca55ce 203void AliTRDReconstructor::Reconstruct(AliRawReader *rawReader
204 , TTree *clusterTree) const
205{
206 //
207 // Reconstruct clusters
208 //
209
d2eba04b 210 AliDebug(1, "Reconstruct TRD clusters from RAW data [RawReader -> Cluster TTree]");
211 AliDebug(2, Form("clusters[%p] tracklets[%p] tracks[%p]", (void*)fgClusters, (void*)fgTracklets, (void*)fgTracks));
5127281e 212 if(!fClusterizer){
213 AliFatal("Clusterizer not available!");
214 return;
215 }
d2eba04b 216 rawReader->Reset();
217 rawReader->Select("TRD");
218 ResetContainers();
5127281e 219 fClusterizer->OpenOutput(clusterTree);
5127281e 220 fClusterizer->SetUseLabels(kFALSE);
07897df4 221 fClusterizer->SetStoreRawSignals(kTRUE);
d2eba04b 222 fClusterizer->ResetRecPoints();
5127281e 223 fClusterizer->Raw2ClustersChamber(rawReader);
3e1f6592 224 fgNTimeBins = fClusterizer->GetNTimeBins();
d2eba04b 225 for (Int_t iSector = 0; iSector < 18; iSector++) fgTriggerFlags.SetFlags(iSector, fClusterizer->GetTriggerFlags(iSector));
25ca55ce 226}
227
228//_____________________________________________________________________________
a8fbb161 229void AliTRDReconstructor::Reconstruct(TTree *digitsTree
230 , TTree *clusterTree) const
25ca55ce 231{
232 //
233 // Reconstruct clusters
234 //
e4f2f73d 235
d2eba04b 236 AliDebug(1, "Reconstruct TRD clusters from Digits [Digit TTree -> Cluster TTree]");
237 AliDebug(2, Form("Start :: clusters[%p] tracklets[%p] tracks[%p]", (void*)fgClusters, (void*)fgTracklets, (void*)fgTracks));
238 if(!fClusterizer){
239 AliFatal("Clusterizer not available!");
240 return;
cb8b99ee 241 }
242
eea7663c 243 ResetContainers();
d2eba04b 244 AliTRDclusterizer clusterizer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
245 clusterizer.SetReconstructor(this);
246 clusterizer.SetUseLabels(kTRUE);
247 clusterizer.SetStoreRawSignals(kTRUE);
248 clusterizer.OpenOutput(clusterTree);
249 clusterizer.ReadDigits(digitsTree);
eea7663c 250 clusterizer.ReadTracklets();
251 clusterizer.ReadTracks();
d2eba04b 252 clusterizer.MakeClusters();
253 fgNTimeBins = clusterizer.GetNTimeBins();
25ca55ce 254}
255
256//_____________________________________________________________________________
44dbae42 257AliTracker *AliTRDReconstructor::CreateTracker() const
121a60bd 258{
3bc9d03e 259 //
260 // Create a TRD tracker
261 //
121a60bd 262
e4f2f73d 263 //return new AliTRDtracker(NULL);
3a039a31 264 AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
265 tracker->SetReconstructor(this);
d2eba04b 266 AliInfo(Form("Build TRD tracker[%p]", (void*)tracker));
3a039a31 267 return tracker;
25ca55ce 268
25ca55ce 269}
270
271//_____________________________________________________________________________
272void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
91834b8d 273 , TTree* /*clusterTree*/
cb8b99ee 274 , AliESDEvent* esd) const
25ca55ce 275{
276 //
af26ce80 277 // Fill ESD
25ca55ce 278 //
279
cb8b99ee 280 // ----- filling tracklets -----
d2eba04b 281 AliDebug(1, Form("Loading onl.tracklets(%i) to ESD", fgTracklets ? fgTracklets->GetEntriesFast() : 0));
5fedeee9 282 Int_t trackletIndex[1080] = { 0 };
283 TList trklList;
284 AliTRDrawStream::SortTracklets(fgTracklets, trklList, trackletIndex);
285 TIter trackletIter(&trklList);
03e2f460 286 while (AliTRDtrackletBase* tracklet = (AliTRDtrackletBase*) trackletIter()) {
287 Int_t label = -2; // mark raw tracklets with label -2
d2eba04b 288 if (AliTRDtrackletMCM *trklMCM = dynamic_cast<AliTRDtrackletMCM*> (tracklet)) label = trklMCM->GetLabel();
60557224 289 esd->AddTrdTracklet(tracklet->GetTrackletWord(), tracklet->GetHCId(), label);
cb8b99ee 290 }
291
292 // ----- filling GTU tracks -----
d2eba04b 293 AliDebug(1, Form("Loading gtu.tracks(%i) to ESD", fgTracks ? fgTracks->GetEntriesFast() : 0));
cb8b99ee 294 if (fgTracks) {
295 for (Int_t iTrack = 0; iTrack < fgTracks->GetEntriesFast(); iTrack++) {
296 AliESDTrdTrack *trdTrack = (AliESDTrdTrack*) ((*fgTracks)[iTrack]);
297
cb8b99ee 298 UInt_t stack = trdTrack->GetStack();
299
03e2f460 300 Int_t refIndex[6];
301 AliTRDrawStream::AssignTracklets(trdTrack, trackletIndex, refIndex);
302
303 for (Int_t iLayer = 0; iLayer < 6; ++iLayer) {
d2eba04b 304 Int_t det = trdTrack->GetSector()*30 + stack*6 + iLayer;
305 AliESDTrdTracklet *trkl = refIndex[iLayer] > -1 ? esd->GetTrdTracklet(refIndex[iLayer]) : 0x0;
306 if (trkl) {
307 AliDebug(5, Form("adding tracklet with index %i: 0x%08x",
308 refIndex[iLayer], trkl->GetTrackletWord()));
309 if (trkl->GetDetector() != det)
310 AliError(Form("inconsistent assignment of tracklet 0x%08x in det %i to track in %i",
311 trkl->GetTrackletWord(), trkl->GetDetector(), det));
312 trdTrack->AddTrackletReference(trkl, iLayer);
313 }
cb8b99ee 314 }
315 // only add the track when it's complete (including tracklet references)
316 esd->AddTrdTrack(trdTrack);
317 }
318 }
c4daee41 319 esd->SetTrdTrigger(&fgTriggerFlags);
ff4c44cb 320
321 // ----- matching GTU tracks to global tracks -----
322 AliDebug(1, Form("TRD track matching with %i ESD, %i TRD tracks",
323 esd->GetNumberOfTracks(), esd->GetNumberOfTrdTracks()));
324 fgOnlineTrackMatcher.ProcessEvent(esd);
25ca55ce 325}
3a039a31 326
828c6f80 327//_____________________________________________________________________________
3a039a31 328void AliTRDReconstructor::SetOption(Option_t *opt)
329{
d39401ad 330 //
331 // Read option string into the steer param.
332 //
954135b1 333 // The following string options are available during reconstruction.
334 // In square brackets the default values are given.
335 // "dc" : digits conversion [false]
336 // "cw" : write clusters [true]
337 // "tw" : write online tracklets [false]
338 // "sa" : track seeding (stand alone tracking) [true]
339 // "hlt" : HLT reconstruction [false]
340 // "tp" : also use online tracklets for reconstruction [false]
341 // "deb" : Write debug stream [false]
342 // "cc" : Cluster radial correction during reconstruction [false]
343 //
344 // To check the actual options used during reconstruction include the following line in your rec.C script
345 // AliLog::SetClassDebugLevel("AliTRDReconstructor", 1);
97b6dfac 346
347 AliReconstructor::SetOption(opt);
3a039a31 348
349 TString s(opt);
350 TObjArray *opar = s.Tokenize(",");
351 for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
d39401ad 352 Bool_t processed = kFALSE;
3a039a31 353 TString sopt(((TObjString*)(*opar)[ipar])->String());
b72f4eaf 354 for(Int_t iopt=0; iopt<kNsteer; iopt++){
355 if(!sopt.Contains(fgSteerFlags[iopt])) continue;
356 SETFLG(fSteerParam, BIT(iopt));
357 if(sopt.Contains("!")) CLRFLG(fSteerParam, BIT(iopt));
d39401ad 358 processed = kTRUE;
b72f4eaf 359 break;
360 }
d39401ad 361 if(processed) continue;
b72f4eaf 362
363 AliWarning(Form("Unknown option flag %s.", sopt.Data()));
3a039a31 364 }
d2eba04b 365 opar->Delete();
09d5920f 366 delete opar;
3a039a31 367}
368
acd241e9 369//_____________________________________________________________________________
a2fbb6ec 370void AliTRDReconstructor::Options(UInt_t steer)
b72f4eaf 371{
d39401ad 372 //
373 // Print the options
374 //
375
b72f4eaf 376 for(Int_t iopt=0; iopt<kNsteer; iopt++){
9e8fdff4 377 AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
b72f4eaf 378 }
b72f4eaf 379}
380
d2eba04b 381
382//_____________________________________________________________________________
383TClonesArray* AliTRDReconstructor::GetClusters()
384{
385// Build/ Retrieve cluster array
386 if(!fgClusters){
387 fgClusters = new TClonesArray("AliTRDcluster", Int_t(GetRecoParam()->GetNClusters()));
388 fgClusters->SetOwner();
389 AliInfoGeneral("AliTRDReconstructor", Form("Allocate cluster array @ %p", (void*)fgClusters));
390 }
391 return fgClusters;
392}
393
394//_____________________________________________________________________________
395TClonesArray* AliTRDReconstructor::GetTracklets(const char *trkltype)
396{
397// Build/ Retrieve online tracklets array
398
eea7663c 399 if (trkltype && strlen(trkltype) > 0) {
d2eba04b 400 if(fgTracklets && (TClass::GetClass(trkltype) != fgTracklets->GetClass())){
401 fgTracklets->Delete();
402 delete fgTracklets;
403 }
404 if (!fgTracklets) {
405 fgTracklets = new TClonesArray(trkltype, 200);
406 fgTracklets->SetOwner(kTRUE);
407 AliInfoGeneral("AliTRDReconstructor", Form("Allocate online tracklets[%s] array @ %p", trkltype, (void*)fgTracklets));
408 }
409 }
410 return fgTracklets;
411}
412
413//_____________________________________________________________________________
414TClonesArray* AliTRDReconstructor::GetTracks()
415{
416// Build/ Retrieve cluster array
417 if(!fgTracks){
418 fgTracks = new TClonesArray("AliESDTrdTrack", 100);
419 fgTracks->SetOwner();
420 AliInfoGeneral("AliTRDReconstructor", Form("Allocate online tracks array @ %p", (void*)fgTracks));
421 }
422 return fgTracks;
423}
424
425//_____________________________________________________________________________
426void AliTRDReconstructor::ResetContainers() const
427{
428// prepare data containers for a new event
429
430 if(fgClusters){
431 AliDebug(1, Form("Removing %5d clusters @ %p", fgClusters->GetEntriesFast(), (void*)fgClusters));
432 fgClusters->Clear();
433 }
434 if(fgTracklets){
435 AliDebug(1, Form("Removing %3d online tracklets @ %p", fgTracklets->GetEntriesFast(), (void*)fgTracklets));
436 fgTracklets->Clear();
437 }
438 if(fgTracks){
439 AliDebug(1, Form("Removing %3d online tracks @ %p", fgTracks->GetEntriesFast(), (void*)fgTracks));
440 fgTracks->Clear();
441 }
ab67cd8d
JK
442 for (Int_t iSector = 0; iSector < 18; iSector++)
443 fgTriggerFlags.SetFlags(iSector, 0);
d2eba04b 444}