]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDtrackGTU.cxx
- add missing forward declaration of AliESDtrack
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackGTU.cxx
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"
28 #include "TClass.h"
29 #include "TMath.h"
30 #include "TH1F.h"
31
32 #include "AliESDTrdTrack.h"
33 #include "AliLog.h"
34 #include "AliTRDgtuParam.h"
35 #include "AliTRDtrackGTU.h"
36 #include "AliTRDtrackletGTU.h"
37 #include "AliTRDtrackletMCM.h"
38 #include "AliESDTrdTrack.h"
39
40 ClassImp(AliTRDtrackGTU)
41
42 AliTRDtrackGTU::AliTRDtrackGTU() :
43   TObject(),
44   fStack(-1),
45   fSector(-1),
46   fPID(0),
47   fTracklets(0x0),
48   fTrackletMask(0),
49   fNTracklets(0),
50   fRefLayerIdx(-1),
51   fZChannel(-1),
52   fZSubChannel(-1),
53   fA(0),
54   fB(0),
55   fC(0),
56   fLabel(-1)
57 {
58 // default ctor
59
60   fTracklets = new TClonesArray("AliTRDtrackletGTU", 6);
61   for (Int_t iTracklet = 0; iTracklet < 6; iTracklet++)
62       new ((*fTracklets)[iTracklet]) AliTRDtrackletGTU();
63 //  fTracklets->BypassStreamer(kFALSE);
64 }
65
66 AliTRDtrackGTU::AliTRDtrackGTU(const AliTRDtrackGTU &rhs) :
67   TObject(),
68   fStack(rhs.fStack),
69   fSector(rhs.fSector),
70   fPID(rhs.fPID),
71   fTracklets(0x0),
72   fTrackletMask(rhs.fTrackletMask),
73   fNTracklets(rhs.fNTracklets),
74   fRefLayerIdx(rhs.fRefLayerIdx),
75   fZChannel(rhs.fZChannel),
76   fZSubChannel(rhs.fZSubChannel),
77   fA(rhs.fA),
78   fB(rhs.fB),
79   fC(rhs.fC),
80   fLabel(rhs.fLabel)
81 {
82   fTracklets = new TClonesArray("AliTRDtrackletGTU", 6);
83   for (Int_t iTracklet = 0; iTracklet < 6; iTracklet++)
84     new ((*fTracklets)[iTracklet]) AliTRDtrackletGTU(*((AliTRDtrackletGTU*)(*(rhs.fTracklets))[iTracklet]));
85 }
86
87 AliTRDtrackGTU& AliTRDtrackGTU::operator=(const AliTRDtrackGTU &rhs)
88 {
89   if (&rhs != this) {
90     TObject::operator=(rhs);
91     fStack         = rhs.fStack;
92     fSector        = rhs.fSector;
93     fPID           = rhs.fPID;
94     fTrackletMask  = rhs.fTrackletMask;
95     fNTracklets    = rhs.fNTracklets;
96     fRefLayerIdx   = rhs.fRefLayerIdx;
97     fZChannel      = rhs.fZChannel;
98     fZSubChannel   = rhs.fZSubChannel;
99     fA             = rhs.fA;
100     fB             = rhs.fB;
101     fC             = rhs.fC;
102     fLabel         = rhs.fLabel;
103     for (Int_t iTracklet = 0; iTracklet < 6; iTracklet++)
104       new ((*fTracklets)[iTracklet]) AliTRDtrackletGTU(*((AliTRDtrackletGTU*)(*(rhs.fTracklets))[iTracklet])); 
105   }
106
107   return *this;
108 }
109
110 AliTRDtrackGTU::~AliTRDtrackGTU()
111 {
112 // dtor
113
114   fTracklets->Delete();
115   delete fTracklets;
116 }
117
118 void AliTRDtrackGTU::AddTracklet(const AliTRDtrackletGTU * const tracklet, Int_t layer)
119 {
120 // add a tracklet to this track
121
122   if ( (fTrackletMask & (1 << layer)) != 0 ) {
123     AliError(Form("Only one tracklet per layer (%i) possible! Mask: 0x%02x", layer, fTrackletMask));
124     return;
125   }
126
127   new ((*fTracklets)[layer]) AliTRDtrackletGTU(*tracklet);
128   fNTracklets++;
129   fTrackletMask |= (1 << layer);
130 }
131
132 AliTRDtrackletGTU* AliTRDtrackGTU::GetTracklet(Int_t layer) const
133 {
134 // get a pointer to the tracklet in the layer specified
135
136   if (IsTrackletInLayer(layer))
137     return ((AliTRDtrackletGTU*) (*fTracklets)[layer]);
138   else
139     return 0x0;
140 }
141
142 Int_t AliTRDtrackGTU::GetNTracklets() const
143 {
144 // returns the number of tracklets in this track
145
146   return fNTracklets;
147 }
148
149 Bool_t AliTRDtrackGTU::IsTrackletInLayer(Int_t layer) const
150 {
151 // checks for a tracklet in the given layer
152
153   if ( (GetTrackletMask() & (1 << layer)) != 0)
154     return kTRUE;
155   else
156     return kFALSE;
157 }
158
159 void AliTRDtrackGTU::SetFitParams(Float_t a, Float_t b, Float_t c)
160 {
161 // set the fit parameters
162
163   fA = a;
164   fB = b;
165   fC = c;
166 }
167
168 Int_t AliTRDtrackGTU::GetZSubChannel()
169 {
170 // returns the z-subchannel
171
172   if (fZSubChannel < 0) {
173     for (Int_t layer = 0; layer < AliTRDgtuParam::GetNLayers(); layer++)
174     {
175       if (IsTrackletInLayer(layer))
176         fZSubChannel = ((AliTRDtrackletGTU*) (*fTracklets)[layer])->GetSubChannel(GetZChannel());
177     }
178   }
179   return fZSubChannel;
180 }
181
182 Int_t AliTRDtrackGTU::GetYapprox()
183 {
184   // returns an approximated y-position for the track
185   // taken from the projected y-position of the tracklet in the reference layer
186   // in which the track was found
187
188   if ((fRefLayerIdx > -1) && (fRefLayerIdx < AliTRDgtuParam::GetNRefLayers()))
189     return ((AliTRDtrackletGTU*) (*fTracklets)[AliTRDgtuParam::GetRefLayer(fRefLayerIdx)])->GetYProj();
190   else
191     return 0;
192 }
193
194 AliESDTrdTrack* AliTRDtrackGTU::CreateTrdTrack() const
195 {
196   // creates an AliESDTrdTrack to be added to the ESD
197
198   AliESDTrdTrack *trk = new AliESDTrdTrack();
199   trk->SetA((Int_t) fA);
200   trk->SetLayerMask(fTrackletMask);
201   trk->SetPID(fPID);
202   trk->SetB((Int_t) fB);
203   trk->SetStack(fStack);
204   trk->SetSector(fSector);
205   trk->SetLabel(fLabel);
206
207   for (Int_t iLayer = 0; iLayer < AliTRDgtuParam::GetNLayers(); iLayer++) {
208     AliTRDtrackletGTU *trklGTU = GetTracklet(iLayer);
209     if (trklGTU) {
210       trk->SetTrackletIndex(trklGTU->GetIndex(), iLayer);
211       AliESDTrdTracklet *trkl = trklGTU->GetTrackletESD();
212       if (trkl)
213         trk->AddTrackletReference(trkl, iLayer);
214     }
215   }
216
217   return trk;
218 }
219
220 Bool_t AliTRDtrackGTU::CookLabel()
221 {
222   // assign label from tracklets according to frequency
223
224   Int_t nLabels = 0;
225   Int_t label[6] = { 0 };
226   Int_t count[6] = { 0 };
227
228   for (Int_t iTracklet = 0; iTracklet < 6; iTracklet++) {
229     if (!IsTrackletInLayer(iTracklet))
230       continue;
231
232     Int_t currLabel = GetTracklet(iTracklet)->GetLabel();
233
234     Bool_t assigned = kFALSE;
235     for (Int_t iLabel = 0; iLabel < nLabels; iLabel++) {
236       if (currLabel == label[iLabel]) {
237         count[iLabel]++;
238         assigned = kTRUE;
239         break;
240       }
241     }
242
243     if (!assigned) {
244       label[nLabels] = currLabel;
245       count[nLabels] = 1;
246       nLabels++;
247     }
248   }
249
250   Int_t index[32];
251   TMath::Sort(6, count, index);
252   fLabel = label[index[0]];
253
254   return kTRUE;
255 }