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