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 **************************************************************************/
16 /* $Id: AliTRDgtuParam.cxx 28397 2008-09-02 09:33:00Z cblume $ */
18 ////////////////////////////////////////////////////////////////////////////
20 // Parameters for GTU simulation //
22 // Author: J. Klein (Jochen.Klein@cern.ch) //
24 ////////////////////////////////////////////////////////////////////////////
29 #include "TDecompLU.h"
30 #include "TGraphAsymmErrors.h"
34 #include "AliTRDgtuParam.h"
35 #include "AliTRDgeometry.h"
36 #include "AliTRDpadPlane.h"
38 ClassImp(AliTRDgtuParam)
40 AliTRDgtuParam *AliTRDgtuParam::fgInstance = 0;
42 // ----- matching windows -----
43 Int_t AliTRDgtuParam::fgDeltaY = 19;
44 Int_t AliTRDgtuParam::fgDeltaAlpha = 21;
46 // ----- Bin widths (granularity) -----
47 const Float_t AliTRDgtuParam::fgkBinWidthY = 160e-4;
48 const Float_t AliTRDgtuParam::fgkBinWidthdY = 140e-4;
50 // ----- Bit widths (used for internal representation) -----
51 const Int_t AliTRDgtuParam::fgkBitWidthY = 13;
52 const Int_t AliTRDgtuParam::fgkBitWidthdY = 7;
53 const Int_t AliTRDgtuParam::fgkBitWidthYProj = 10;
54 const Int_t AliTRDgtuParam::fgkBitExcessY = 4;
55 const Int_t AliTRDgtuParam::fgkBitExcessAlpha = 10;
56 const Int_t AliTRDgtuParam::fgkBitExcessYProj = 2;
58 // ----- Tracking parameters -----
60 const Int_t AliTRDgtuParam::fgkNZChannels = 3; // No. of z-channels
61 const Int_t AliTRDgtuParam::fgkNLinks = 12; // No. of links
62 const Int_t AliTRDgtuParam::fgkFixLayer = 2; // which layer is fixed for the generation of the z-channel map
63 const Int_t AliTRDgtuParam::fgkDeltaY = 39; // accepted deviation in y_proj, default: 9
64 const Int_t AliTRDgtuParam::fgkDeltaAlpha = 31; // accepted deviation in alpha, default: 11
65 const Int_t AliTRDgtuParam::fgkNRefLayers = 3; // no. of reference layers
68 AliTRDgtuParam::AliTRDgtuParam() :
76 fGeo = new AliTRDgeometry();
77 fRefLayers = new Int_t[fgkNRefLayers];
81 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
87 GenerateZChannelMap();
90 AliTRDgtuParam::~AliTRDgtuParam()
98 AliTRDgtuParam* AliTRDgtuParam::Instance()
100 // get (or create) the single instance
103 fgInstance = new AliTRDgtuParam();
108 void AliTRDgtuParam::Terminate()
110 // destruct the instance
112 if (fgInstance != 0) {
118 Bool_t AliTRDgtuParam::IsInZChannel(Int_t stack, Int_t layer, Int_t zchannel, Int_t zpos) const
120 return (fZSubChannel[stack][zchannel][layer][zpos] != 0);
123 Int_t AliTRDgtuParam::GetZSubchannel(Int_t stack, Int_t layer, Int_t zchannel, Int_t zpos) const
125 return fZSubChannel[stack][zchannel][layer][zpos];
128 Int_t AliTRDgtuParam::GetRefLayer(Int_t refLayerIdx) const
130 // returns the reference layer indexed by refLayerIdx
132 if (refLayerIdx >= 0 && refLayerIdx < fgkNRefLayers)
133 return fRefLayers[refLayerIdx];
138 Int_t AliTRDgtuParam::GenerateZChannelMap()
140 // generate the z-channel map
141 // assuming that the tracks come from the vertex
142 // +/- fVertexSize in z-direction
144 Int_t iSec = 0; // sector is irrelevant
145 Bool_t collision = kFALSE;
147 for (Int_t iStack = 0; iStack < fGeo->Nstack(); iStack++) {
149 Float_t x[6] = { 0 };
150 Float_t z[6][16] = {{ 0 }};
151 Float_t dZ[6][16] = {{ 0 }};
153 for (Int_t iLayer = 0; iLayer < fGeo->Nlayer(); iLayer++) {
154 AliTRDpadPlane *pp = fGeo->GetPadPlane(iLayer, iStack);
155 x[iLayer] = fGeo->GetTime0(iLayer) - fGeo->CdrHght(); // ???
156 for (Int_t iRow = 0; iRow < fGeo->GetRowMax(iLayer, iStack, iSec); iRow++) {
157 z[iLayer][iRow] = pp->GetRowPos(iRow); // this is the right (pos. z-direction) border of the pad
158 dZ[iLayer][iRow] = pp->GetRowSize(iRow); // length of the pad in z-direction
159 for (Int_t i = 0; i < fgkNZChannels; i++)
160 fZSubChannel[iStack][i][iLayer][iRow] = 0;
164 for (Int_t fixRow = 0; fixRow < fGeo->GetRowMax(fgkFixLayer, iStack, iSec); fixRow++) {
166 Double_t fixZmin = z[fgkFixLayer][fixRow] - dZ[fgkFixLayer][fixRow];
167 Double_t fixZmax = z[fgkFixLayer][fixRow];
168 Double_t fixX = x[fgkFixLayer] + 1.5; // ??? 1.5 from where?
170 for (Int_t iLayer = 0; iLayer < fGeo->Nlayer(); iLayer++) {
171 Double_t leftZ, rightZ;
173 if (iLayer <= fgkFixLayer) {
174 leftZ = (fixZmin + fVertexSize) * (x[iLayer] + 1.5) / fixX - fVertexSize;
175 rightZ = (fixZmax - fVertexSize) * (x[iLayer] + 1.5) / fixX + fVertexSize;
178 leftZ = (fixZmin - fVertexSize) * (x[iLayer] + 1.5) / fixX + fVertexSize;
179 rightZ = (fixZmax + fVertexSize) * (x[iLayer] + 1.5) / fixX - fVertexSize;
182 Double_t epsilon = 0.001;
183 for (Int_t iRow = 0; iRow < fGeo->GetRowMax(iLayer, iStack, iSec); iRow++) {
184 if ( (z[iLayer][iRow] ) > (leftZ + epsilon) &&
185 (z[iLayer][iRow] - dZ[iLayer][iRow] ) < (rightZ - epsilon) ) {
186 fZChannelMap[iStack][fixRow][iLayer][iRow] = 1;
187 if (fZSubChannel[iStack][fixRow % fgkNZChannels][iLayer][iRow] != 0) {
188 AliError("Collision in Z-Channel assignment occured! No reliable tracking!!!");
192 fZSubChannel[iStack][fixRow % fgkNZChannels][iLayer][iRow] = fixRow / fgkNZChannels + 1;
203 Bool_t AliTRDgtuParam::DisplayZChannelMap(Int_t zchannel, Int_t subchannel) const
205 // display the z-channel map
207 if (zchannel >= fgkNZChannels) {
208 AliError("Invalid Z channel!");
212 Int_t zchmin = zchannel >= 0 ? zchannel : 0;
213 Int_t zchmax = zchannel >= 0 ? zchannel + 1 : fgkNZChannels;
216 TCanvas *c = new TCanvas("zchmap", "Z-Chhannel Mapping");
218 TGraph **graphz = new TGraph*[fgkNZChannels];
219 for (Int_t zch = zchmin; zch < zchmax; zch++)
220 graphz[zch] = new TGraph;
221 TGraphAsymmErrors *graph = new TGraphAsymmErrors();
222 graph->SetTitle("Z-Channel Map");
223 graph->SetPoint(i, 0, 0); // vertex
224 graph->SetPointError(i++, 20, 20, 0, 0);
225 // graph->SetRange //????
226 for (Int_t iLayer = 0; iLayer < fGeo->Nlayer(); iLayer++) {
227 for (Int_t iStack = 0; iStack < fGeo->Nstack(); iStack++) {
228 AliTRDpadPlane *pp = fGeo->GetPadPlane(iLayer, iStack);
229 for (Int_t iRow = 0; iRow < fGeo->GetRowMax(iLayer, iStack, 0); iRow++) {
230 graph->SetPoint(i, pp->GetRowPos(iRow), fGeo->GetTime0(iLayer) - fGeo->CdrHght());
231 graph->SetPointError(i++, pp->GetRowSize(iRow), 0, 0, 0);
232 for (Int_t zch = zchmin; zch < zchmax; zch++)
233 if (fZSubChannel[iStack][zch][iLayer][iRow] != 0)
234 if (subchannel == 0 || fZSubChannel[iStack][zch][iLayer][iRow] == subchannel)
235 graphz[zch]->SetPoint(j++, pp->GetRowPos(iRow) - pp->GetRowSize(iRow)/2, fGeo->GetTime0(iLayer) - fGeo->CdrHght());
239 graph->SetMarkerStyle(kDot);
242 for (Int_t zch = zchmin; zch < zchmax; zch++) {
243 graphz[zch]->SetMarkerStyle(kCircle);
244 graphz[zch]->SetMarkerColor(zch+2);
245 graphz[zch]->SetMarkerSize(0.3 + zch*0.2);
246 graphz[zch]->Draw("P");
247 gROOT->Add(graphz[zch]);
253 Int_t AliTRDgtuParam::GetCiAlpha(Int_t layer) const
255 // get the constant for the calculation of alpha
257 Int_t ci = (Int_t) (GetChamberThickness() / fGeo->GetTime0(layer) * GetBinWidthY() / GetBinWidthdY() * (1 << (GetBitExcessAlpha() + GetBitExcessY() + 1)) );
261 Int_t AliTRDgtuParam::GetCiYProj(Int_t layer) const
263 // get the constant for the calculation of y_proj
265 Float_t xmid = (fGeo->GetTime0(0) + fGeo->GetTime0(fGeo->Nlayer()-1)) / 2.;
266 Int_t ci = (Int_t) (- (fGeo->GetTime0(layer) - xmid) / GetChamberThickness() * GetBinWidthdY() / GetBinWidthY() * (1 << GetBitExcessYProj()) );
270 Int_t AliTRDgtuParam::GetYt(Int_t stack, Int_t layer, Int_t zrow) const
272 return (Int_t) (- ( (layer % 2 ? 1 : -1) *
273 (GetGeo()->GetPadPlane(layer, stack)->GetRowPos(zrow) - GetGeo()->GetPadPlane(layer, stack)->GetRowSize(zrow) / 2) *
274 TMath::Tan(- 2.0 / 180.0 * TMath::Pi()) ) / 0.016 );
277 Bool_t AliTRDgtuParam::GenerateRecoCoefficients(Int_t trackletMask)
279 // calculate the coefficients for the straight line fit
280 // depending on the mask of contributing tracklets
282 fCurrTrackletMask = trackletMask;
284 TMatrix a(GetNLayers(), 3);
285 TMatrix b(3, GetNLayers());
288 for (Int_t layer = 0; layer < GetNLayers(); layer++) {
289 if ( (trackletMask & (1 << layer)) == 0) {
296 a(layer, 1) = fGeo->GetTime0(layer);
297 a(layer, 2) = (layer % 2 ? 1 : -1) * fGeo->GetTime0(layer);
306 for (Int_t layer = 0; layer < GetNLayers(); layer++) {
307 fAki[layer] = b.GetMatrixArray()[layer];
308 fBki[layer] = b.GetMatrixArray()[GetNLayers() + layer];
309 fCki[layer] = b.GetMatrixArray()[2 * GetNLayers() + layer];
314 Float_t AliTRDgtuParam::GetAki(Int_t k, Int_t i)
316 // get A_ki for the calculation of the tracking parameters
317 if (fCurrTrackletMask != k)
318 GenerateRecoCoefficients(k);
323 Float_t AliTRDgtuParam::GetBki(Int_t k, Int_t i)
325 // get B_ki for the calculation of the tracking parameters
327 if (fCurrTrackletMask != k)
328 GenerateRecoCoefficients(k);
333 Float_t AliTRDgtuParam::GetCki(Int_t k, Int_t i)
335 // get B_ki for the calculation of the tracking parameters
337 if (fCurrTrackletMask != k)
338 GenerateRecoCoefficients(k);
344 Float_t AliTRDgtuParam::GetD(Int_t k) const
346 // get the determinant for the calculation of the tracking parameters
349 for (Int_t i = 0; i < GetNLayers(); i++) {
350 if ( !((k >> i) & 0x1) )
352 Float_t xi = fGeo->GetTime0(i);
355 t(2,0) += TMath::Power(-1, i) * xi;
357 t(1,1) += TMath::Power(xi, 2);
358 t(2,1) += TMath::Power(-1, i) * TMath::Power(xi, 2);
359 t(0,2) += TMath::Power(-1, i) * xi;
360 t(1,2) += TMath::Power(-1, i) * TMath::Power(xi, 2);
361 t(2,2) += TMath::Power(xi, 2);
363 return t.Determinant();
366 Bool_t AliTRDgtuParam::GetFitParams(TVectorD& rhs, Int_t k)
368 // calculate the fitting parameters
372 for (Int_t i = 0; i < GetNLayers(); i++) {
373 if ( !((k >> i) & 0x1) )
375 Float_t xi = fGeo->GetTime0(i);
378 t(2,0) += TMath::Power(-1, i) * xi;
380 t(1,1) += TMath::Power(xi, 2);
381 t(2,1) += TMath::Power(-1, i) * TMath::Power(xi, 2);
382 t(0,2) -= TMath::Power(-1, i) * xi;
383 t(1,2) -= TMath::Power(-1, i) * TMath::Power(xi, 2);
384 t(2,2) -= TMath::Power(xi, 2);
388 return lr.Decompose();
392 Bool_t AliTRDgtuParam::GetIntersectionPoints(Int_t k, Float_t &x1, Float_t &x2)
394 // get the x-coord. of the assumed circle/straight line intersection points
399 for (Int_t layer = 0; layer < GetNLayers(); layer++) {
400 if ( (k >> layer) & 0x1 ) {
408 if ( (l1 >= 0) && (l2 >= 0) ) {
409 x1 = fGeo->GetTime0(l1) + 10./6 * (nHits -1);
410 x2 = fGeo->GetTime0(l2) - 10./6 * (nHits -1);
417 Float_t AliTRDgtuParam::GetPt(Int_t a, Float_t /* b */, Float_t x1, Float_t x2) const
419 // returns 0.3 * B * 1/a (1/128 GeV/c)
420 // a : offset, b : slope (not used)
422 Float_t c1 = x1 * x2 / 2. / 10000.; // conversion cm to m
425 r = (0.3 * fMagField / 2. / (fgkBinWidthY/100.)) * (((Int_t) c1) << 8) / (a >> 1); //??? why shift of a?