added noise to the digit can be negative, may affect to the observed discrepancy...
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackGTU.cxx
CommitLineData
52c19022 1/**************************************************************************
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 **************************************************************************/
15
16////////////////////////////////////////////////////////////////////////////
17// //
18// A GTU track //
19// //
20// Author: J. Klein (Jochen.Klein@cern.ch) //
21// //
22////////////////////////////////////////////////////////////////////////////
23
24/* $Id: AliTRDtrackGTU.cxx 27566 2008-07-24 15:31:08Z cblume $ */
25
26#include "TObject.h"
27#include "TObjArray.h"
4cc89512 28#include "TClass.h"
29#include "TH1F.h"
52c19022 30
4d6aee34 31#include "AliESDTrdTrack.h"
52c19022 32#include "AliLog.h"
33#include "AliTRDgtuParam.h"
34#include "AliTRDtrackGTU.h"
35#include "AliTRDtrackletGTU.h"
4cc89512 36#include "AliTRDtrackletMCM.h"
52c19022 37#include "AliESDTrdTrack.h"
38
39ClassImp(AliTRDtrackGTU)
5f006bd7 40
52c19022 41AliTRDtrackGTU::AliTRDtrackGTU() :
42 TObject(),
43 fStack(-1),
44 fSector(-1),
52c19022 45 fPID(0),
46 fTracklets(0x0),
47 fTrackletMask(0),
48 fNTracklets(0),
49 fRefLayerIdx(-1),
50 fZChannel(-1),
51 fZSubChannel(-1),
52 fA(0),
53 fB(0),
4cc89512 54 fC(0),
55 fLabel(-1)
52c19022 56{
4cc89512 57// default ctor
58
52c19022 59 fTracklets = new TClonesArray("AliTRDtrackletGTU", 6);
60 for (Int_t iTracklet = 0; iTracklet < 6; iTracklet++)
61 new ((*fTracklets)[iTracklet]) AliTRDtrackletGTU();
62// fTracklets->BypassStreamer(kFALSE);
63}
64
dd09a2e2 65AliTRDtrackGTU::AliTRDtrackGTU(const AliTRDtrackGTU &rhs) :
66 TObject(),
67 fStack(rhs.fStack),
68 fSector(rhs.fSector),
69 fPID(rhs.fPID),
70 fTracklets(0x0),
71 fTrackletMask(rhs.fTrackletMask),
72 fNTracklets(rhs.fNTracklets),
73 fRefLayerIdx(rhs.fRefLayerIdx),
74 fZChannel(rhs.fZChannel),
75 fZSubChannel(rhs.fZSubChannel),
76 fA(rhs.fA),
77 fB(rhs.fB),
78 fC(rhs.fC),
79 fLabel(rhs.fLabel)
80{
81 fTracklets = new TClonesArray("AliTRDtrackletGTU", 6);
82 for (Int_t iTracklet = 0; iTracklet < 6; iTracklet++)
83 new ((*fTracklets)[iTracklet]) AliTRDtrackletGTU(*((AliTRDtrackletGTU*)(*(rhs.fTracklets))[iTracklet]));
84}
85
86AliTRDtrackGTU& AliTRDtrackGTU::operator=(const AliTRDtrackGTU &rhs)
87{
88 if (&rhs != this) {
89 TObject::operator=(rhs);
90 fStack = rhs.fStack;
91 fSector = rhs.fSector;
92 fPID = rhs.fPID;
93 fTrackletMask = rhs.fTrackletMask;
94 fNTracklets = rhs.fNTracklets;
95 fRefLayerIdx = rhs.fRefLayerIdx;
96 fZChannel = rhs.fZChannel;
97 fZSubChannel = rhs.fZSubChannel;
98 fA = rhs.fA;
99 fB = rhs.fB;
100 fC = rhs.fC;
101 fLabel = rhs.fLabel;
102 for (Int_t iTracklet = 0; iTracklet < 6; iTracklet++)
103 new ((*fTracklets)[iTracklet]) AliTRDtrackletGTU(*((AliTRDtrackletGTU*)(*(rhs.fTracklets))[iTracklet]));
104 }
105
106 return *this;
107}
108
52c19022 109AliTRDtrackGTU::~AliTRDtrackGTU()
110{
4cc89512 111// dtor
112
52c19022 113 fTracklets->Delete();
114 delete fTracklets;
115}
116
5f006bd7 117void AliTRDtrackGTU::AddTracklet(const AliTRDtrackletGTU * const tracklet, Int_t layer)
52c19022 118{
4cc89512 119// add a tracklet to this track
120
52c19022 121 if ( (fTrackletMask & (1 << layer)) != 0 ) {
122 AliError(Form("Only one tracklet per layer (%i) possible! Mask: 0x%02x", layer, fTrackletMask));
123 return;
124 }
125
126 new ((*fTracklets)[layer]) AliTRDtrackletGTU(*tracklet);
127 fNTracklets++;
128 fTrackletMask |= (1 << layer);
129}
130
44eafcf2 131AliTRDtrackletGTU* AliTRDtrackGTU::GetTracklet(Int_t layer) const
52c19022 132{
4cc89512 133// get a pointer to the tracklet in the layer specified
134
80f93426 135 if (IsTrackletInLayer(layer))
136 return ((AliTRDtrackletGTU*) (*fTracklets)[layer]);
5f006bd7 137 else
80f93426 138 return 0x0;
52c19022 139}
140
141Int_t AliTRDtrackGTU::GetNTracklets() const
142{
4cc89512 143// returns the number of tracklets in this track
144
52c19022 145 return fNTracklets;
146}
147
5f006bd7 148Bool_t AliTRDtrackGTU::IsTrackletInLayer(Int_t layer) const
52c19022 149{
4cc89512 150// checks for a tracklet in the given layer
151
52c19022 152 if ( (GetTrackletMask() & (1 << layer)) != 0)
153 return kTRUE;
5f006bd7 154 else
52c19022 155 return kFALSE;
156}
157
5f006bd7 158void AliTRDtrackGTU::SetFitParams(Float_t a, Float_t b, Float_t c)
52c19022 159{
4cc89512 160// set the fit parameters
161
5f006bd7 162 fA = a;
52c19022 163 fB = b;
164 fC = c;
165}
166
5f006bd7 167Int_t AliTRDtrackGTU::GetZSubChannel()
52c19022 168{
4cc89512 169// returns the z-subchannel
170
52c19022 171 if (fZSubChannel < 0) {
172 for (Int_t layer = 0; layer < AliTRDgtuParam::GetNLayers(); layer++)
173 {
174 if (IsTrackletInLayer(layer))
175 fZSubChannel = ((AliTRDtrackletGTU*) (*fTracklets)[layer])->GetSubChannel(GetZChannel());
176 }
177 }
178 return fZSubChannel;
179}
180
5f006bd7 181Int_t AliTRDtrackGTU::GetYapprox()
52c19022 182{
d2c8b010 183 // returns an approximated y-position for the track
184 // taken from the projected y-position of the tracklet in the reference layer
185 // in which the track was found
4cc89512 186
d2c8b010 187 if ((fRefLayerIdx > -1) && (fRefLayerIdx < AliTRDgtuParam::GetNRefLayers()))
188 return ((AliTRDtrackletGTU*) (*fTracklets)[AliTRDgtuParam::GetRefLayer(fRefLayerIdx)])->GetYProj();
189 else
190 return 0;
52c19022 191}
192
193AliESDTrdTrack* AliTRDtrackGTU::CreateTrdTrack() const
194{
44eafcf2 195 // creates an AliESDTrdTrack to be added to the ESD
196
197 AliESDTrdTrack *trk = new AliESDTrdTrack();
198 trk->SetA((Int_t) fA);
199 trk->SetLayerMask(fTrackletMask);
200 trk->SetPID(fPID);
201 trk->SetB((Int_t) fB);
202 trk->SetStack(fStack);
203 trk->SetSector(fSector);
204 if (fLabel >= 0)
205 trk->SetLabel(fLabel);
206
207 for (Int_t iLayer = 0; iLayer < AliTRDgtuParam::GetNLayers(); iLayer++) {
208 AliTRDtrackletGTU *trklGTU = GetTracklet(iLayer);
209 if (trklGTU) {
a10c6981 210 trk->SetTrackletIndex(trklGTU->GetIndex(), iLayer);
44eafcf2 211 AliESDTrdTracklet *trkl = trklGTU->GetTrackletESD();
212 if (trkl)
213 trk->AddTrackletReference(trkl, iLayer);
214 }
215 }
52cd0cc0 216
44eafcf2 217 return trk;
52c19022 218}
4cc89512 219
5f006bd7 220Bool_t AliTRDtrackGTU::CookLabel()
4cc89512 221{
222 TH1F *h = new TH1F("trkref", "trkref", 100000, 0, 100000);
223 for (Int_t iTracklet = 0; iTracklet < 6; iTracklet++) {
80f93426 224 if (!IsTrackletInLayer(iTracklet))
225 continue;
4cc89512 226 h->Fill( ((AliTRDtrackletGTU*) (*fTracklets)[iTracklet])->GetLabel());
227 }
228 if (h->GetEntries() > 0)
80f93426 229 fLabel = h->GetMaximumBin() - 1;
5f006bd7 230 else
4cc89512 231 fLabel = -1;
232 delete h;
233 return (fLabel >= 0);
234}