StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FtfDedx.cxx
1 /*:>-------------------------------------------------------------------
2 **: FILE: FtfDedx.cxx
3 **: HISTORY:
4 **:<------------------------------------------------------------------*/
5 #include "Stl3Util/ftf/FtfDedx.h"
6 
7 
8 //***********************************************************************
9 // constructor
10 //***********************************************************************
11 FtfDedx::FtfDedx(St_l3_Coordinate_Transformer *trafo, float cutLow, float cutHigh, float driftLoss)
12 {
13  fCoordTransformer = trafo;
14  fCutLow = cutLow;
15  fCutHigh = cutHigh;
16  fNTruncate = 0;
17  fDriftLoss = driftLoss;
18  // initialize unit vector perpendicular to rows
19  // for each sector
20  for (int sector=0; sector<24; sector++) {
21  // caution: sector>12 needs x->-x and y->y (east side!)
22  fUnitVec[sector].x = fCoordTransformer->GetSectorSin(sector);
23  if (sector+1>12) fUnitVec[sector].x = -1 * fUnitVec[sector].x;
24  fUnitVec[sector].y = fCoordTransformer->GetSectorCos(sector);
25  }
26 }
27 
28 
29 //***********************************************************************
30 // dEdx calculation using Truncated Mean algorithm
31 // averaging method: dE/dx = (sum of q/s)/(# of points)
32 //
33 // author: christof
34 //***********************************************************************
35 int FtfDedx::TruncatedMean(FtfTrack *track) {
36 
37  double padLength;
38  int nPointsInArray;
39 
40  // dx calculation:
41  // straight-line approx. in x-y-plane
42  // assume perfect hit position on track
43  // :=> don't calculate intersection of circle and row
44  // 1/cosl corr. factor for dip angle
45 
46 // printf("Track: id %i, pt %f, nHits %i, q %i, tanl %f\n",
47 // fTrack->id, fTrack->pt, fTrack->nHits, fTrack->q, fTrack->tanl);
48 
49  // calculate dip angle correction factor
50  double cosl = 1 / (::sqrt( 1 + (double) track->tanl*track->tanl));
51 
52 // printf(" cosl %f\n", cosl);
53  if ( cosl==0 ) return 0;
54 
55  // calculate center of circle
56  double tPhi0 = track->psi + track->q * pi/2;
57  if ( tPhi0 > 2*pi ) tPhi0 = tPhi0 - 2*pi;
58  else if ( tPhi0 < 0. ) tPhi0 = tPhi0 + 2*pi;
59 
60  double x0 = track->r0 * cos(track->phi0);
61  double y0 = track->r0 * sin(track->phi0);
62  double rr = track->pt / ( bFactor *track->getPara()->bField );
63  double xc = x0 - rr * cos(tPhi0);
64  double yc = y0 - rr * sin(tPhi0);
65 
66 // printf(" xc %f yc %f\n", xc, yc);
67 
68  nPointsInArray = 0;
69 
70  //now loop over hits
71  for ( FtfHit *ihit = (FtfHit *)track->firstHit ;
72  ihit != 0 ;
73  ihit = (FtfHit *)ihit->nextTrackHit) {
74 
75  // discard hits with wrong charge information
76  // i.e. hits of one-pad cluster or merged cluster
77  if (ihit->flags) continue;
78 
79  // calculate direction of the tangent of circle at position
80  // of given hit:
81  // - rotate radius vector to hit by -90 degrees
82  // matrix ( 0 1 )
83  // ( -1 0 )
84  // - divide by length to get unity vector
85  struct christofs_2d_vector tangent;
86  tangent.x = (ihit->y - yc)/rr;
87  tangent.y = -(ihit->x - xc)/rr;
88  //printf(" tangent x %f y %f\n", tangent.x, tangent.y);
89 
90  // get crossing angle by calculating dot product of
91  // tanget and unity vector perpendicular to row (look-up table)
92  double cosCrossing = fabs(tangent.x * fUnitVec[ihit->sector-1].x + tangent.y * fUnitVec[ihit->sector-1].y);
93 
94  // padlength
95  if (ihit->row<14) padLength = padLengthInnerSector;
96  else padLength = padLengthOuterSector;
97 
98  // ==> finally dx:
99  if ( cosCrossing==0 ) continue;
100  double dx = padLength / (cosCrossing * cosl);
101 
102  // drift length correctrion: d_loss [m^-1], l_drift [cm]
103  // q_corr = q_meas / ( 1 - l_drift * d_loss/100 )
104  double scaleDrift = 1 - fabs(ihit->z) * fDriftLoss/100;
105 
106 
107  // first shot: de_scale as implemented in tph.F,
108  // i.e. gas gain, wire-to-pad coupling, etc.
109  // !! hard coded, has to come from the db somewhere sometime !!
110  double deScale;
111  if (ihit->row<14) deScale = 5.0345021e-9;
112  else deScale = 1.4234702e-8;
113 
114  fDedxArray[nPointsInArray] = ihit->q * deScale / ( dx * scaleDrift );
115  nPointsInArray++;
116 
117 // printf(" ihit row %i x %f y %f z %f q %d q_scaled %e scale %e flags %d\n",
118 // ihit->row, ihit->x, ihit->y, ihit->z, ihit->q, ihit->q*deScale, deScale, ihit->flags);
119 // printf(" cosCros: %f, cosl: %f ===>> dx %f\n", cosCrossing, cosl, dx);
120 
121  }
122 
123  // sort dEdxArray
124  sort( fDedxArray, fDedxArray+nPointsInArray );
125 
126  // calculate absolute cuts
127  int cLow = (int) floor(nPointsInArray * fCutLow);
128  int cHigh = (int) floor(nPointsInArray * fCutHigh);
129 
130  track->nDedx = 0;
131  track->dedx = 0;
132 
133  for (int i=cLow; i<cHigh; i++) {
134  track->nDedx++;
135  track->dedx += fDedxArray[i];
136  }
137 
138  if (track->nDedx>0) track->dedx = track->dedx/track->nDedx;
139 
140 // printf(" %e %i\n", track->dedx, track->nDedx);
141 
142  return 0;
143 }
Definition: FtfHit.h:16