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 ////////////////////////////////////////////////////////////////////////////
28 #include "TDecompLU.h"
29 #include "TGraphAsymmErrors.h"
33 #include "AliTRDgtuParam.h"
34 #include "AliTRDgeometry.h"
35 #include "AliTRDpadPlane.h"
37 ClassImp(AliTRDgtuParam)
39 AliTRDgtuParam *AliTRDgtuParam::fgInstance = 0;
41 // ----- Bin widths (granularity) -----
42 const Float_t AliTRDgtuParam::fgkBinWidthY = 160e-4;
43 const Float_t AliTRDgtuParam::fgkBinWidthdY = 140e-4;
45 // ----- Bit widths (used for internal representation) -----
46 const Int_t AliTRDgtuParam::fgkBitWidthY = 13;
47 const Int_t AliTRDgtuParam::fgkBitWidthdY = 7;
48 const Int_t AliTRDgtuParam::fgkBitWidthYProj = 10;
49 const Int_t AliTRDgtuParam::fgkBitExcessY = 4;
50 const Int_t AliTRDgtuParam::fgkBitExcessAlpha = 10;
51 const Int_t AliTRDgtuParam::fgkBitExcessYProj = 2;
53 // ----- Tracking parameters -----
55 const Int_t AliTRDgtuParam::fgkNZChannels = 3; // No. of z-channels
56 const Int_t AliTRDgtuParam::fgkNLinks = 12; // No. of links
57 const Int_t AliTRDgtuParam::fgkFixLayer = 2; // which layer is fixed for the generation of the z-channel map
58 const Int_t AliTRDgtuParam::fgkDeltaY = 39; // accepted deviation in y_proj, default: 9
59 const Int_t AliTRDgtuParam::fgkDeltaAlpha = 31; // accepted deviation in alpha, default: 11
60 const Int_t AliTRDgtuParam::fgkNRefLayers = 3; // no. of reference layers
63 AliTRDgtuParam::AliTRDgtuParam() :
70 fGeo = new AliTRDgeometry();
71 fRefLayers = new Int_t[fgkNRefLayers];
78 AliTRDgtuParam::~AliTRDgtuParam()
86 AliTRDgtuParam* AliTRDgtuParam::Instance()
88 // get (or create) the single instance
91 fgInstance = new AliTRDgtuParam();
96 void AliTRDgtuParam::Terminate()
98 // destruct the instance
100 if (fgInstance != 0) {
106 Bool_t AliTRDgtuParam::IsInZChannel(Int_t stack, Int_t layer, Int_t zchannel, Int_t zpos) const
108 return (fZSubChannel[stack][zchannel][layer][zpos] != 0);
111 Int_t AliTRDgtuParam::GetZSubchannel(Int_t stack, Int_t layer, Int_t zchannel, Int_t zpos) const
113 return fZSubChannel[stack][zchannel][layer][zpos];
116 Int_t AliTRDgtuParam::GetRefLayer(Int_t refLayerIdx) const
118 if (refLayerIdx >= 0 && refLayerIdx < fgkNRefLayers)
119 return fRefLayers[refLayerIdx];
124 Int_t AliTRDgtuParam::zChannelGen()
126 // generate the z-channel map
127 // assuming that the tracks come from the vertex
128 // +/- fVertexSize in z-direction
130 Int_t iSec = 0; // sector is irrelevant
131 Bool_t collision = kFALSE;
133 for (Int_t iStack = 0; iStack < fGeo->Nstack(); iStack++) {
135 Float_t X[6] = { 0 };
136 Float_t Z[6][16] = {{ 0 }};
137 Float_t dZ[6][16] = {{ 0 }};
139 for (Int_t iLayer = 0; iLayer < fGeo->Nlayer(); iLayer++) {
140 AliTRDpadPlane *pp = fGeo->GetPadPlane(iLayer, iStack);
141 X[iLayer] = fGeo->GetTime0(iLayer) - fGeo->CdrHght(); // ???
142 for (Int_t iRow = 0; iRow < fGeo->GetRowMax(iLayer, iStack, iSec); iRow++) {
143 Z[iLayer][iRow] = pp->GetRowPos(iRow); // this is the right (pos. z-direction) border of the pad
144 dZ[iLayer][iRow] = pp->GetRowSize(iRow); // length of the pad in z-direction
145 for (Int_t i = 0; i < fgkNZChannels; i++)
146 fZSubChannel[iStack][i][iLayer][iRow] = 0;
150 for (Int_t fixRow = 0; fixRow < fGeo->GetRowMax(fgkFixLayer, iStack, iSec); fixRow++) {
152 Double_t fixZmin = Z[fgkFixLayer][fixRow] - dZ[fgkFixLayer][fixRow];
153 Double_t fixZmax = Z[fgkFixLayer][fixRow];
154 Double_t fixX = X[fgkFixLayer] + 1.5; // ??? 1.5 from where?
156 for (Int_t iLayer = 0; iLayer < fGeo->Nlayer(); iLayer++) {
157 Double_t leftZ, rightZ;
159 if (iLayer <= fgkFixLayer) {
160 leftZ = (fixZmin + fVertexSize) * (X[iLayer] + 1.5) / fixX - fVertexSize;
161 rightZ = (fixZmax - fVertexSize) * (X[iLayer] + 1.5) / fixX + fVertexSize;
164 leftZ = (fixZmin - fVertexSize) * (X[iLayer] + 1.5) / fixX + fVertexSize;
165 rightZ = (fixZmax + fVertexSize) * (X[iLayer] + 1.5) / fixX - fVertexSize;
168 Double_t epsilon = 0.001;
169 for (Int_t iRow = 0; iRow < fGeo->GetRowMax(iLayer, iStack, iSec); iRow++) {
170 if ( (Z[iLayer][iRow] ) > (leftZ + epsilon) &&
171 (Z[iLayer][iRow] - dZ[iLayer][iRow] ) < (rightZ - epsilon) ) {
172 fZChannelMap[iStack][fixRow][iLayer][iRow] = 1;
173 if (fZSubChannel[iStack][fixRow % fgkNZChannels][iLayer][iRow] != 0) {
174 AliError("Collision in Z-Channel assignment occured! No reliable tracking!!!");
178 fZSubChannel[iStack][fixRow % fgkNZChannels][iLayer][iRow] = fixRow / fgkNZChannels + 1;
189 Bool_t AliTRDgtuParam::DisplayZChannelMap(Int_t zchannel, Int_t subchannel) const
191 // display the z-channel map
193 if (zchannel > fgkNZChannels) {
194 AliError("Invalid Z channel!");
198 Int_t zchmin = zchannel >= 0 ? zchannel : 0;
199 Int_t zchmax = zchannel >= 0 ? zchannel + 1 : fgkNZChannels;
202 TCanvas *c = new TCanvas("zchmap", "Z-Chhannel Mapping");
204 TGraph **graphz = new TGraph*[fgkNZChannels];
205 for (Int_t zch = zchmin; zch < zchmax; zch++)
206 graphz[zch] = new TGraph;
207 TGraphAsymmErrors *graph = new TGraphAsymmErrors();
208 graph->SetTitle("Z-Channel Map");
209 graph->SetPoint(i, 0, 0); // vertex
210 graph->SetPointError(i++, 20, 20, 0, 0);
211 // graph->SetRange //????
212 for (Int_t iLayer = 0; iLayer < fGeo->Nlayer(); iLayer++) {
213 for (Int_t iStack = 0; iStack < fGeo->Nstack(); iStack++) {
214 AliTRDpadPlane *pp = fGeo->GetPadPlane(iLayer, iStack);
215 for (Int_t iRow = 0; iRow < fGeo->GetRowMax(iLayer, iStack, 0); iRow++) {
216 graph->SetPoint(i, pp->GetRowPos(iRow), fGeo->GetTime0(iLayer) - fGeo->CdrHght());
217 graph->SetPointError(i++, pp->GetRowSize(iRow), 0, 0, 0);
218 for (Int_t zch = zchmin; zch < zchmax; zch++)
219 if (fZSubChannel[iStack][zch][iLayer][iRow] != 0)
220 if (subchannel == 0 || fZSubChannel[iStack][zch][iLayer][iRow] == subchannel)
221 graphz[zch]->SetPoint(j++, pp->GetRowPos(iRow) - pp->GetRowSize(iRow)/2, fGeo->GetTime0(iLayer) - fGeo->CdrHght());
225 graph->SetMarkerStyle(kDot);
227 for (Int_t zch = zchmin; zch < zchmax; zch++) {
228 graphz[zch]->SetMarkerStyle(kCircle);
229 graphz[zch]->SetMarkerColor(zch+2);
230 graphz[zch]->SetMarkerSize(0.3 + zch*0.2);
231 graphz[zch]->Draw("P");
236 Int_t AliTRDgtuParam::GetCiAlpha(Int_t layer) const
238 // get the constant for the calculation of alpha
240 Int_t Ci = (Int_t) (GetChamberThickness() / fGeo->GetTime0(layer) * GetBinWidthY() / GetBinWidthdY() * (1 << (GetBitExcessAlpha() + GetBitExcessY() + 1)) );
244 Int_t AliTRDgtuParam::GetCiYProj(Int_t layer) const
246 // get the constant for the calculation of y_proj
248 Float_t Xmid = (fGeo->GetTime0(0) + fGeo->GetTime0(fGeo->Nlayer()-1)) / 2.;
249 Int_t Ci = (Int_t) (- (fGeo->GetTime0(layer) - Xmid) / GetChamberThickness() * GetBinWidthdY() / GetBinWidthY() * (1 << GetBitExcessYProj()) );
253 Int_t AliTRDgtuParam::GetYt(Int_t stack, Int_t layer, Int_t zrow) const
255 return (Int_t) (- ( (layer % 2 ? 1 : -1) *
256 (GetGeo()->GetPadPlane(layer, stack)->GetRowPos(zrow) - GetGeo()->GetPadPlane(layer, stack)->GetRowSize(zrow) / 2) *
257 TMath::Tan(- 2.0 / 180.0 * TMath::Pi()) ) / 0.016 );
260 Bool_t AliTRDgtuParam::GenerateRecoCoefficients(Int_t trackletMask)
262 fCurrTrackletMask = trackletMask;
264 TMatrix a(GetNLayers(), 3);
265 TMatrix b(3, GetNLayers());
268 for (Int_t layer = 0; layer < GetNLayers(); layer++) {
269 if ( (trackletMask & (1 << layer)) == 0) {
276 a(layer, 1) = fGeo->GetTime0(layer);
277 a(layer, 2) = (layer % 2 ? 1 : -1) * fGeo->GetTime0(layer);
286 for (Int_t layer = 0; layer < GetNLayers(); layer++) {
287 fAki[layer] = b.GetMatrixArray()[layer];
288 fBki[layer] = b.GetMatrixArray()[GetNLayers() + layer];
289 fCki[layer] = b.GetMatrixArray()[2 * GetNLayers() + layer];
294 Float_t AliTRDgtuParam::GetAki(Int_t k, Int_t i)
296 // get A_ki for the calculation of the tracking parameters
297 if (fCurrTrackletMask != k)
298 GenerateRecoCoefficients(k);
303 Float_t AliTRDgtuParam::GetBki(Int_t k, Int_t i)
305 // get B_ki for the calculation of the tracking parameters
307 if (fCurrTrackletMask != k)
308 GenerateRecoCoefficients(k);
313 Float_t AliTRDgtuParam::GetCki(Int_t k, Int_t i)
315 // get B_ki for the calculation of the tracking parameters
317 if (fCurrTrackletMask != k)
318 GenerateRecoCoefficients(k);
324 Float_t AliTRDgtuParam::GetD(Int_t k) const
326 // get the determinant for the calculation of the tracking parameters
329 for (Int_t i = 0; i < GetNLayers(); i++) {
330 if ( !((k >> i) & 0x1) )
332 Float_t xi = fGeo->GetTime0(i);
335 t(2,0) += TMath::Power(-1, i) * xi;
337 t(1,1) += TMath::Power(xi, 2);
338 t(2,1) += TMath::Power(-1, i) * TMath::Power(xi, 2);
339 t(0,2) += TMath::Power(-1, i) * xi;
340 t(1,2) += TMath::Power(-1, i) * TMath::Power(xi, 2);
341 t(2,2) += TMath::Power(xi, 2);
343 return t.Determinant();
346 Bool_t AliTRDgtuParam::GetFitParams(TVectorD& rhs, Int_t k)
348 // calculate the fitting parameters
352 for (Int_t i = 0; i < GetNLayers(); i++) {
353 if ( !((k >> i) & 0x1) )
355 Float_t xi = fGeo->GetTime0(i);
358 t(2,0) += TMath::Power(-1, i) * xi;
360 t(1,1) += TMath::Power(xi, 2);
361 t(2,1) += TMath::Power(-1, i) * TMath::Power(xi, 2);
362 t(0,2) -= TMath::Power(-1, i) * xi;
363 t(1,2) -= TMath::Power(-1, i) * TMath::Power(xi, 2);
364 t(2,2) -= TMath::Power(xi, 2);
368 return lr.Decompose();
372 Bool_t AliTRDgtuParam::GetIntersectionPoints(Int_t k, Float_t &x1, Float_t &x2)
374 // get the x-coord. of the assumed circle/straight line intersection points
379 for (Int_t layer = 0; layer < GetNLayers(); layer++) {
380 if ( (k >> layer) & 0x1 ) {
388 x1 = fGeo->GetTime0(l1) + 10./6 * (nHits -1);
389 x2 = fGeo->GetTime0(l2) - 10./6 * (nHits -1);
391 return ( (l1 >= 0) && (l2 >= 0) );
394 Float_t AliTRDgtuParam::GetRadius(Int_t a, Float_t b, Float_t x1, Float_t x2)
396 // get the radius for the track
397 Float_t d = (1 + b * b /2 ) * (x2 - x1);
398 Float_t c1 = x1 * x2 / 2;
399 // Float_t c2 = (x1 + x2) / (x1 * x2);
400 printf("c1: %f\n", c1);
403 r = (375. / 10000.) * c1 * 256 / (a >> 1);
406 Float_t y1 = a + b*x1;
407 Float_t y2 = a + b*x2;
408 Float_t alpha = TMath::Abs( TMath::ATan(y2/x2) - TMath::ATan(y1/x1) );
409 d = TMath::Sqrt( TMath::Power(x2-x1, 2) + TMath::Power(y2-y1, 2) );
410 r = d / 2. / TMath::Sin(alpha);