1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // Class for TRD reconstruction //
22 // For the special options which can be used during reconstruction and their //
23 // default values pls. see function SetOption(). //
25 ///////////////////////////////////////////////////////////////////////////////
27 #include <TObjString.h>
28 #include <TObjArray.h>
29 #include <TTreeStream.h>
30 #include <TDirectory.h>
33 #include "AliRawReader.h"
36 #include "AliTRDReconstructor.h"
37 #include "AliTRDclusterizer.h"
38 #include "AliTRDrawData.h"
39 #include "AliTRDrawStream.h"
40 #include "AliTRDdigitsManager.h"
41 #include "AliTRDtrackerV1.h"
42 #include "AliESDEvent.h"
43 #include "AliESDTrdTrack.h"
44 #include "AliESDTrdTracklet.h"
45 #include "AliESDTrdTrigger.h"
46 #include "AliTRDtrackletWord.h"
47 #include "AliTRDtrackletMCM.h"
48 #include "AliTRDonlineTrackMatching.h"
50 #define SETFLG(n,f) ((n) |= f)
51 #define CLRFLG(n,f) ((n) &= ~f)
53 ClassImp(AliTRDReconstructor)
55 Int_t AliTRDReconstructor::fgStreamLevel = 1; // stream (debug) level
58 AliESDTrdTrigger AliTRDReconstructor::fgTriggerFlags;
59 AliTRDonlineTrackMatching AliTRDReconstructor::fgOnlineTrackMatcher;
60 TClonesArray *AliTRDReconstructor::fgClusters = NULL;
61 TClonesArray *AliTRDReconstructor::fgTracklets = NULL;
62 TClonesArray *AliTRDReconstructor::fgTracks = NULL;
63 Char_t const * AliTRDReconstructor::fgSteerNames[kNsteer] = {
66 ,"Write Online Tracklets "
67 ,"Stand Alone Tracking "
69 ,"Process Online Trklts "
71 ,"Cl. Radial Correction "
73 Char_t const * AliTRDReconstructor::fgSteerFlags[kNsteer] = {
74 "dc"// digits conversion [false]
75 ,"cw"// write clusters [true]
76 ,"tw"// write online tracklets [false]
77 ,"sa"// track seeding (stand alone tracking) [true]
78 ,"hlt"// HLT reconstruction [false]
79 ,"tp"// also use online tracklets for reconstruction [false]
80 ,"deb"// Write debug stream [false]
81 ,"cc" // Cluster radial correction during reconstruction [false]
83 Char_t const * AliTRDReconstructor::fgTaskNames[AliTRDrecoParam::kTRDreconstructionTasks] = {
88 Char_t const * AliTRDReconstructor::fgTaskFlags[AliTRDrecoParam::kTRDreconstructionTasks] = {
93 Int_t AliTRDReconstructor::fgNTimeBins = -1;
94 const Float_t AliTRDReconstructor::fgkMinClustersInTrack = 0.5; //
95 const Float_t AliTRDReconstructor::fgkLabelFraction = 0.8; //
96 const Double_t AliTRDReconstructor::fgkMaxChi2 = 12.0; //
97 const Double_t AliTRDReconstructor::fgkMaxSnp = 0.95; // Maximum local sine of the azimuthal angle
98 const Double_t AliTRDReconstructor::fgkMaxStep = 2.0; // Maximal step size in propagation
99 const Double_t AliTRDReconstructor::fgkEpsilon = 1.e-5; // Precision of radial coordinate
101 //_____________________________________________________________________________
102 AliTRDReconstructor::AliTRDReconstructor()
107 // setting default "ON" steering parameters
108 // owner of debug streamers
109 SETFLG(fSteerParam, kOwner);
110 // write clusters [cw]
111 SETFLG(fSteerParam, kWriteClusters);
112 // track seeding (stand alone tracking) [sa]
113 //SETFLG(fSteerParam, kSeeding);
114 // Cluster radial correction during reconstruction [cc]
115 //SETFLG(fSteerParam, kClRadialCorr);
116 memset(fDebugStream, 0, sizeof(TTreeSRedirector *) * AliTRDrecoParam::kTRDreconstructionTasks);
119 //_____________________________________________________________________________
120 AliTRDReconstructor::~AliTRDReconstructor()
131 fgClusters->Delete();
136 fgTracklets->Delete();
145 if((fSteerParam&kOwner)|| AliTRDReconstructor::GetStreamLevel()>0){
146 for(Int_t itask = 0; itask < AliTRDrecoParam::kTRDreconstructionTasks; itask++)
147 if(fDebugStream[itask]) delete fDebugStream[itask];
152 //_____________________________________________________________________________
153 void AliTRDReconstructor::Init(){
157 SetOption(GetOption());
158 Options(fSteerParam);
161 fClusterizer = new AliTRDclusterizer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
162 fClusterizer->SetReconstructor(this);
163 AliInfo(Form("Build TRD clusterizer[%p]", (void*)fClusterizer));
166 // Make Debug Streams when Debug Streaming
167 if(IsDebugStreaming()){
168 for(Int_t task = 0; task < AliTRDrecoParam::kTRDreconstructionTasks; task++){
169 TDirectory *savedir = gDirectory;
170 fDebugStream[task] = new TTreeSRedirector(Form("TRD.Debug%s.root", fgTaskNames[task]),"recreate");
172 SETFLG(fSteerParam, kOwner);
177 //_____________________________________________________________________________
178 void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader
179 , TTree *digitsTree) const
182 // Convert raw data digits into digit objects in a root tree
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));
189 rawReader->Select("TRD");
192 AliTRDrawData rawData;
194 AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
195 manager->MakeBranch(digitsTree);
196 manager->WriteDigits();
199 for (Int_t iSector = 0; iSector < 18; iSector++) fgTriggerFlags.SetFlags(iSector, rawData.GetTriggerFlags(iSector));
202 //_____________________________________________________________________________
203 void AliTRDReconstructor::Reconstruct(AliRawReader *rawReader
204 , TTree *clusterTree) const
207 // Reconstruct clusters
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));
213 AliFatal("Clusterizer not available!");
217 rawReader->Select("TRD");
219 fClusterizer->OpenOutput(clusterTree);
220 fClusterizer->SetUseLabels(kFALSE);
221 fClusterizer->SetStoreRawSignals(kTRUE);
222 fClusterizer->ResetRecPoints();
223 fClusterizer->Raw2ClustersChamber(rawReader);
224 fgNTimeBins = fClusterizer->GetNTimeBins();
225 for (Int_t iSector = 0; iSector < 18; iSector++) fgTriggerFlags.SetFlags(iSector, fClusterizer->GetTriggerFlags(iSector));
228 //_____________________________________________________________________________
229 void AliTRDReconstructor::Reconstruct(TTree *digitsTree
230 , TTree *clusterTree) const
233 // Reconstruct clusters
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));
239 AliFatal("Clusterizer not available!");
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);
250 clusterizer.ReadTracklets();
251 clusterizer.ReadTracks();
252 clusterizer.MakeClusters();
253 fgNTimeBins = clusterizer.GetNTimeBins();
256 //_____________________________________________________________________________
257 AliTracker *AliTRDReconstructor::CreateTracker() const
260 // Create a TRD tracker
263 //return new AliTRDtracker(NULL);
264 AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
265 tracker->SetReconstructor(this);
266 AliInfo(Form("Build TRD tracker[%p]", (void*)tracker));
271 //_____________________________________________________________________________
272 void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
273 , TTree* /*clusterTree*/
274 , AliESDEvent* esd) const
280 // ----- filling tracklets -----
281 AliDebug(1, Form("Loading onl.tracklets(%i) to ESD", fgTracklets ? fgTracklets->GetEntriesFast() : 0));
282 Int_t trackletIndex[1080] = { 0 };
284 AliTRDrawStream::SortTracklets(fgTracklets, trklList, trackletIndex);
285 TIter trackletIter(&trklList);
286 while (AliTRDtrackletBase* tracklet = (AliTRDtrackletBase*) trackletIter()) {
287 Int_t label = -2; // mark raw tracklets with label -2
288 if (AliTRDtrackletMCM *trklMCM = dynamic_cast<AliTRDtrackletMCM*> (tracklet)) label = trklMCM->GetLabel();
289 esd->AddTrdTracklet(tracklet->GetTrackletWord(), tracklet->GetHCId(), label);
292 // ----- filling GTU tracks -----
293 AliDebug(1, Form("Loading gtu.tracks(%i) to ESD", fgTracks ? fgTracks->GetEntriesFast() : 0));
295 for (Int_t iTrack = 0; iTrack < fgTracks->GetEntriesFast(); iTrack++) {
296 AliESDTrdTrack *trdTrack = (AliESDTrdTrack*) ((*fgTracks)[iTrack]);
298 UInt_t stack = trdTrack->GetStack();
301 AliTRDrawStream::AssignTracklets(trdTrack, trackletIndex, refIndex);
303 for (Int_t iLayer = 0; iLayer < 6; ++iLayer) {
304 Int_t det = trdTrack->GetSector()*30 + stack*6 + iLayer;
305 AliESDTrdTracklet *trkl = refIndex[iLayer] > -1 ? esd->GetTrdTracklet(refIndex[iLayer]) : 0x0;
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);
315 // only add the track when it's complete (including tracklet references)
316 esd->AddTrdTrack(trdTrack);
319 esd->SetTrdTrigger(&fgTriggerFlags);
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);
327 //_____________________________________________________________________________
328 void AliTRDReconstructor::SetOption(Option_t *opt)
331 // Read option string into the steer param.
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]
344 // To check the actual options used during reconstruction include the following line in your rec.C script
345 // AliLog::SetClassDebugLevel("AliTRDReconstructor", 1);
347 AliReconstructor::SetOption(opt);
350 TObjArray *opar = s.Tokenize(",");
351 for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
352 Bool_t processed = kFALSE;
353 TString sopt(((TObjString*)(*opar)[ipar])->String());
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));
361 if(processed) continue;
363 AliWarning(Form("Unknown option flag %s.", sopt.Data()));
369 //_____________________________________________________________________________
370 void AliTRDReconstructor::Options(UInt_t steer)
376 for(Int_t iopt=0; iopt<kNsteer; iopt++){
377 AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
382 //_____________________________________________________________________________
383 TClonesArray* AliTRDReconstructor::GetClusters()
385 // Build/ Retrieve cluster array
387 fgClusters = new TClonesArray("AliTRDcluster", Int_t(GetRecoParam()->GetNClusters()));
388 fgClusters->SetOwner();
389 AliInfoGeneral("AliTRDReconstructor", Form("Allocate cluster array @ %p", (void*)fgClusters));
394 //_____________________________________________________________________________
395 TClonesArray* AliTRDReconstructor::GetTracklets(const char *trkltype)
397 // Build/ Retrieve online tracklets array
399 if (trkltype && strlen(trkltype) > 0) {
400 if(fgTracklets && (TClass::GetClass(trkltype) != fgTracklets->GetClass())){
401 fgTracklets->Delete();
405 fgTracklets = new TClonesArray(trkltype, 200);
406 fgTracklets->SetOwner(kTRUE);
407 AliInfoGeneral("AliTRDReconstructor", Form("Allocate online tracklets[%s] array @ %p", trkltype, (void*)fgTracklets));
413 //_____________________________________________________________________________
414 TClonesArray* AliTRDReconstructor::GetTracks()
416 // Build/ Retrieve cluster array
418 fgTracks = new TClonesArray("AliESDTrdTrack", 100);
419 fgTracks->SetOwner();
420 AliInfoGeneral("AliTRDReconstructor", Form("Allocate online tracks array @ %p", (void*)fgTracks));
425 //_____________________________________________________________________________
426 void AliTRDReconstructor::ResetContainers() const
428 // prepare data containers for a new event
431 AliDebug(1, Form("Removing %5d clusters @ %p", fgClusters->GetEntriesFast(), (void*)fgClusters));
435 AliDebug(1, Form("Removing %3d online tracklets @ %p", fgTracklets->GetEntriesFast(), (void*)fgTracklets));
436 fgTracklets->Clear();
439 AliDebug(1, Form("Removing %3d online tracks @ %p", fgTracks->GetEntriesFast(), (void*)fgTracks));
442 for (Int_t iSector = 0; iSector < 18; iSector++)
443 fgTriggerFlags.SetFlags(iSector, 0);