CbmRoot
CbmTrdTrianglePRF.cxx
Go to the documentation of this file.
1 
8 #include <TF1.h>
9 #include <TMath.h>
10 
11 #include "CbmTrdTrianglePRF.h"
12 
13 using std::cout;
14 using std::endl;
15 using std::flush;
16 
17 //___________________________________________________________________________
18 CbmTrdTrianglePRF::CbmTrdTrianglePRF(Float_t W, Float_t H, Int_t n)
19  : TObject()
20  , fN(0)
21  , fBinx(0)
22  , fBinx0(0)
23  , fBiny(0)
24  , fBiny0(0)
25  , fX0(0.)
26  , fY0(0.)
27  , fW(W)
28  , fH(H)
29  , fdW(W / n / 2.)
30  , fdH(H / n / 2.)
31  , fSlope(H / W)
32  , fNorm(0.)
33  , fUp()
34  , fX()
35  , fY()
36  , fPRFx(NULL)
37  , fPRFy(NULL) {
41  fN = n * (2 * NR + 1);
42  Double_t epsilon(1.e-3 * W), dw(2 * fdW), dh(2 * fdH);
43 
44  Double_t bx0((-NC - 0.5) * W), by0, xv, yv;
45  for (Int_t jcol(-NC); jcol <= NC; jcol++) {
46  for (Int_t jx(0); jx < n; jx++, bx0 += dw) {
47  // compute x bin center
48  xv = bx0 + fdW;
49 
50  by0 = (-NR - 0.5) * H;
51  for (Int_t jrow(-NR); jrow <= NR; jrow++) {
52  for (Int_t jy(0); jy < n; jy++, by0 += dh) {
53  // compute y bin center
54  yv = by0 + fdH;
55  fX.push_back(xv);
56  fY.push_back(yv);
57 
58  // compute pad type
59  Int_t up1 = GetSide(bx0 - jcol * W + dw - epsilon,
60  by0 - jrow * H + epsilon),
61  up2 = GetSide(bx0 - jcol * W + epsilon,
62  by0 - jrow * H + dh - epsilon);
63  //printf("v(%5.2f %5.2f) lu(%5.2f %5.2f)[%d] rl(%5.2f %5.2f)[%d]\n", xv, yv, bx0-jcol*W, by0-jrow*H+fdH, up2, bx0-jcol*W+fdW, by0-jrow*H, up1);
64  if (up1 != up2)
65  fUp.push_back(0);
66  else
67  fUp.push_back(up1);
68  }
69  }
70  }
71  }
72 
73  // build the PRF model
74  fPRFx = new TF1("prfx", "gaus", -(NC + .5) * fW, (NC + .5) * fW);
75  fPRFx->SetParameters(1, 0., 0.46 * fW); // TODO should be loaded from DB
76  fPRFy = new TF1("prfy", "gaus", -(NR + .5) * fH, (NR + .5) * fH);
77  fPRFy->SetParameters(1, 0., 0.46 * fW); // TODO should be loaded from DB
78  fNorm = fPRFx->Integral(-(NC + .5) * fW, (NC + .5) * fW)
79  * fPRFy->Integral(-(NR + .5) * fH, (NR + .5) * fH);
80 }
81 
82 //___________________________________________________________________________
84  if (fPRFy) delete fPRFy;
85  if (fPRFx) delete fPRFx;
86 }
87 
88 //_________________________________________________________
89 Bool_t CbmTrdTrianglePRF::GetBin(Double_t x,
90  Double_t y,
91  Int_t& binx,
92  Int_t& biny) const {
97  // look to the right
98  Int_t nbinx(fX.size() / fN / 2);
99  binx = -1;
100  for (Int_t ix(nbinx); ix < 2 * nbinx; ix++) {
101  if (x < fX[ix * fN] - fdW) break;
102  if (x > fX[ix * fN] + fdW) continue;
103 
104  if (TMath::Abs(fX[ix * fN] - x) <= fdW) {
105  binx = ix;
106  break;
107  }
108  }
109  if (binx < 0) { // if not found look to the left
110  for (Int_t ix(nbinx); ix--;) {
111  if (x > fX[ix * fN] + fdW) break;
112  if (x < fX[ix * fN] - fdW) continue;
113 
114  if (TMath::Abs(fX[ix * fN] - x) <= fdW) {
115  binx = ix;
116  break;
117  }
118  }
119  }
120  if (binx < 0) return kFALSE;
121 
122  // look upward
123  Int_t nbiny(fN / 2);
124  biny = -1;
125  for (Int_t iy(nbiny); iy < fN; iy++) {
126  if (y < fY[iy] - fdH) break;
127  if (y > fY[iy] + fdH) continue;
128 
129  if (TMath::Abs(fY[iy] - y) <= fdH) {
130  biny = iy;
131  break;
132  }
133  }
134  if (biny < 0) { // if not found look to downwards
135  for (Int_t iy(nbiny); iy--;) {
136  if (y > fY[iy] + fdH) break;
137  if (y < fY[iy] - fdH) continue;
138 
139  if (TMath::Abs(fY[iy] - y) <= fdH) {
140  biny = iy;
141  break;
142  }
143  }
144  }
145  if (biny < 0) return kFALSE;
146 
147  return kTRUE;
148 }
149 
150 //_________________________________________________________
156  Int_t bin(fBinx * fN + fBiny) /*, bin0(fBinx0*fN+fBiny0)*/;
157  return fPRFx->Eval(fX[bin] - fX0) * fPRFy->Eval(fY[bin] - fY0) * 4 * fdW
158  * fdH;
159 }
160 
161 //_________________________________________________________
162 void CbmTrdTrianglePRF::GetCurrentPad(Int_t& col, Int_t& row, Int_t& u) const {
170  Int_t bin(fBinx * fN + fBiny);
171  col = TMath::Nint(fX[bin] / fW) + NC;
172  row = TMath::Nint(fY[bin] / fH) + NR;
173  u = fUp[bin];
174 }
175 
176 //_________________________________________________________
177 Int_t CbmTrdTrianglePRF::GetSide(const Float_t x, const Float_t y) const {
183  if (x < -0.5 * fW || x > 0.5 * fW) {
184  printf("x[%f] outside range\n", x);
185  return 0;
186  }
187 
188  if (y < -0.5 * fH || y > 0.5 * fH) {
189  printf("y[%f] outside range\n", y);
190  return 0;
191  }
192 
193  if (y > fSlope * x) return 1; // up
194  return -1; // down
195 }
196 
197 //_________________________________________________________
202  if ((fBinx + 1) * fN >= static_cast<Int_t>(fX.size())) return kFALSE;
203  fBinx++;
204  return kTRUE;
205 }
206 
207 //_________________________________________________________
212  if (fBiny + 1 >= fN) return kFALSE;
213  fBiny++;
214  return kTRUE;
215 }
216 
217 //_________________________________________________________
218 void CbmTrdTrianglePRF::Print(Option_t* opt) const {
219  printf("N=%d dw=%f dh=%f Slope=%f\n", fN, fdW, fdH, fSlope);
220  if (strcmp(opt, "all") != 0) return;
221  for (UInt_t i(0); i < fX.size(); i++) {
222  if (i && i % fN == 0) printf("\n\n");
223  printf("%2d(%5.2f %5.2f) ", fUp[i], fX[i], fY[i]);
224  }
225  printf("\n");
226 }
227 
228 //_________________________________________________________
233  if ((fBinx - 1) * fN < 0) return kFALSE;
234  fBinx--;
235  return kTRUE;
236 }
237 
238 //_________________________________________________________
243  if (fBiny - 1 < 0) return kFALSE;
244  fBiny--;
245  return kTRUE;
246 }
247 
248 //_________________________________________________________
249 Bool_t CbmTrdTrianglePRF::SetOrigin(Double_t x, Double_t y) {
250  Bool_t ret;
251  if ((ret = GetBin(x, y, fBinx0, fBiny0))) {
252  fBinx = fBinx0;
253  fBiny = fBiny0;
254  fX0 = x;
255  fY0 = y;
256  }
257  return ret;
258 }
259 
CbmTrdTrianglePRF::fUp
std::vector< Char_t > fUp
1 for the upper pad, -1 for the bottom pad and 0 on the boundary
Definition: CbmTrdTrianglePRF.h:142
CbmTrdTrianglePRF::fY
std::vector< Double_t > fY
position of bin center across wires
Definition: CbmTrdTrianglePRF.h:144
CbmTrdTrianglePRF::fH
Double_t fH
pad height
Definition: CbmTrdTrianglePRF.h:136
CbmTrdTrianglePRF::fdW
Double_t fdW
bin half width
Definition: CbmTrdTrianglePRF.h:137
CbmTrdTrianglePRF::PrevBinY
Bool_t PrevBinY()
Move current bin down.
Definition: CbmTrdTrianglePRF.cxx:239
CbmTrdTrianglePRF::fSlope
Double_t fSlope
slope of triangle H/W
Definition: CbmTrdTrianglePRF.h:139
CbmTrdTrianglePRF.h
CbmTrdTrianglePRF::fBinx0
Int_t fBinx0
Offset bin in the map - x direction.
Definition: CbmTrdTrianglePRF.h:127
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmTrdTrianglePRF::fBiny0
Int_t fBiny0
Offset bin in the map - y direction.
Definition: CbmTrdTrianglePRF.h:132
CbmTrdTrianglePRF::fY0
Double_t fY0
y coordinate of cluster
Definition: CbmTrdTrianglePRF.h:134
CbmTrdTrianglePRF::fBinx
Int_t fBinx
Current bin in the map - x direction.
Definition: CbmTrdTrianglePRF.h:124
CbmTrdTrianglePRF::fBiny
Int_t fBiny
Current bin in the map - y direction.
Definition: CbmTrdTrianglePRF.h:129
CbmTrdTrianglePRF::fPRFx
TF1 * fPRFx
PRF model along wires.
Definition: CbmTrdTrianglePRF.h:145
CbmTrdTrianglePRF::NextBinX
Bool_t NextBinX()
Move current bin to the right.
Definition: CbmTrdTrianglePRF.cxx:198
CbmTrdTrianglePRF::PrevBinX
Bool_t PrevBinX()
Move current bin to the left.
Definition: CbmTrdTrianglePRF.cxx:229
CbmTrdTrianglePRF::~CbmTrdTrianglePRF
virtual ~CbmTrdTrianglePRF()
Definition: CbmTrdTrianglePRF.cxx:83
CbmTrdTrianglePRF::SetOrigin
Bool_t SetOrigin(Double_t x, Double_t y)
Set map offset @ point (x,y)
Definition: CbmTrdTrianglePRF.cxx:249
CbmTrdTrianglePRF::fN
Int_t fN
Definition: CbmTrdTrianglePRF.h:122
CbmTrdTrianglePRF::Print
void Print(Option_t *opt="") const
Definition: CbmTrdTrianglePRF.cxx:218
CbmTrdTrianglePRF::GetCurrentPad
void GetCurrentPad(Int_t &col, Int_t &row, Int_t &u) const
Compute the pad corresponding to current bin.
Definition: CbmTrdTrianglePRF.cxx:162
CbmTrdTrianglePRF::NR
@ NR
no. of neighbor rows (except the hit) to be considered in cluster definition
Definition: CbmTrdTrianglePRF.h:31
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmTrdTrianglePRF::CbmTrdTrianglePRF
CbmTrdTrianglePRF(Float_t W, Float_t H, Int_t n=20)
Build map.
Definition: CbmTrdTrianglePRF.cxx:18
CbmTrdTrianglePRF::fW
Double_t fW
pad width
Definition: CbmTrdTrianglePRF.h:135
CbmTrdTrianglePRF::fX
std::vector< Double_t > fX
position of bin center along wires
Definition: CbmTrdTrianglePRF.h:143
CbmTrdTrianglePRF::GetBin
Bool_t GetBin(Double_t x, Double_t y, Int_t &binx, Int_t &biny) const
Find bin for point (x,y)
Definition: CbmTrdTrianglePRF.cxx:89
CbmTrdTrianglePRF::GetChargeFraction
Double_t GetChargeFraction() const
Compute charge fraction on the current bin.
Definition: CbmTrdTrianglePRF.cxx:151
CbmTrdTrianglePRF::NC
@ NC
no. of neighbor columns (except the hit) to be considered in cluster definition
Definition: CbmTrdTrianglePRF.h:29
CbmTrdTrianglePRF::fdH
Double_t fdH
bin half height
Definition: CbmTrdTrianglePRF.h:138
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmTrdTrianglePRF::fPRFy
TF1 * fPRFy
PRF model across wires.
Definition: CbmTrdTrianglePRF.h:146
CbmTrdTrianglePRF::NextBinY
Bool_t NextBinY()
Move current bin up.
Definition: CbmTrdTrianglePRF.cxx:208
CbmTrdTrianglePRF::fX0
Double_t fX0
Index of bin in the map corresponding to cluster center - y direction.
Definition: CbmTrdTrianglePRF.h:133
CbmTrdTrianglePRF::fNorm
Double_t fNorm
normalization factor for the 2D Gauss distribution
Definition: CbmTrdTrianglePRF.h:140
CbmTrdTrianglePRF
Utility for converting energy to signal over the triangular pad geometry (Bucharest prototype)
Definition: CbmTrdTrianglePRF.h:26
CbmTrdTrianglePRF::GetSide
Int_t GetSide(const Float_t x, const Float_t y) const
Define triangular pad type.
Definition: CbmTrdTrianglePRF.cxx:177