CbmRoot
Loading...
Searching...
No Matches
CbmTrdTrianglePRF.cxx
Go to the documentation of this file.
1/* Copyright (C) 2017-2018 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Alexandru Bercuci, Florian Uhlig [committer] */
4
12#include "CbmTrdTrianglePRF.h"
13
14#include <TF1.h>
15#include <TMath.h>
16
17using std::cout;
18using std::endl;
19using std::flush;
20
21//___________________________________________________________________________
22CbmTrdTrianglePRF::CbmTrdTrianglePRF(Float_t W, Float_t H, Int_t n)
23 : TObject()
24 , fN(0)
25 , fBinx(0)
26 , fBinx0(0)
27 , fBiny(0)
28 , fBiny0(0)
29 , fX0(0.)
30 , fY0(0.)
31 , fW(W)
32 , fH(H)
33 , fdW(W / n / 2.)
34 , fdH(H / n / 2.)
35 , fSlope(H / W)
36 , fNorm(0.)
37 , fUp()
38 , fX()
39 , fY()
40 , fPRFx(NULL)
41 , fPRFy(NULL)
42{
46 fN = n * (2 * NR + 1);
47 Double_t epsilon(1.e-3 * W), dw(2 * fdW), dh(2 * fdH);
48
49 Double_t bx0((-NC - 0.5) * W), by0, xv, yv;
50 for (Int_t jcol(-NC); jcol <= NC; jcol++) {
51 for (Int_t jx(0); jx < n; jx++, bx0 += dw) {
52 // compute x bin center
53 xv = bx0 + fdW;
54
55 by0 = (-NR - 0.5) * H;
56 for (Int_t jrow(-NR); jrow <= NR; jrow++) {
57 for (Int_t jy(0); jy < n; jy++, by0 += dh) {
58 // compute y bin center
59 yv = by0 + fdH;
60 fX.push_back(xv);
61 fY.push_back(yv);
62
63 // compute pad type
64 Int_t up1 = GetSide(bx0 - jcol * W + dw - epsilon, by0 - jrow * H + epsilon),
65 up2 = GetSide(bx0 - jcol * W + epsilon, by0 - jrow * H + dh - epsilon);
66 //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);
67 if (up1 != up2) fUp.push_back(0);
68 else
69 fUp.push_back(up1);
70 }
71 }
72 }
73 }
74
75 // build the PRF model
76 fPRFx = new TF1("prfx", "gaus", -(NC + .5) * fW, (NC + .5) * fW);
77 fPRFx->SetParameters(1, 0., 0.46 * fW); // TODO should be loaded from DB
78 fPRFy = new TF1("prfy", "gaus", -(NR + .5) * fH, (NR + .5) * fH);
79 fPRFy->SetParameters(1, 0., 0.46 * fW); // TODO should be loaded from DB
80 fNorm = fPRFx->Integral(-(NC + .5) * fW, (NC + .5) * fW) * fPRFy->Integral(-(NR + .5) * fH, (NR + .5) * fH);
81}
82
83//___________________________________________________________________________
85{
86 if (fPRFy) delete fPRFy;
87 if (fPRFx) delete fPRFx;
88}
89
90//_________________________________________________________
91Bool_t CbmTrdTrianglePRF::GetBin(Double_t x, Double_t y, Int_t& binx, Int_t& biny) const
92{
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//_________________________________________________________
152{
157 Int_t bin(fBinx * fN + fBiny) /*, bin0(fBinx0*fN+fBiny0)*/;
158 return fPRFx->Eval(fX[bin] - fX0) * fPRFy->Eval(fY[bin] - fY0) * 4 * fdW * fdH;
159}
160
161//_________________________________________________________
162void CbmTrdTrianglePRF::GetCurrentPad(Int_t& col, Int_t& row, Int_t& u) const
163{
171 Int_t bin(fBinx * fN + fBiny);
172 col = TMath::Nint(fX[bin] / fW) + NC;
173 row = TMath::Nint(fY[bin] / fH) + NR;
174 u = fUp[bin];
175}
176
177//_________________________________________________________
178Int_t CbmTrdTrianglePRF::GetSide(const Float_t x, const Float_t y) const
179{
185 if (x < -0.5 * fW || x > 0.5 * fW) {
186 printf("x[%f] outside range\n", x);
187 return 0;
188 }
189
190 if (y < -0.5 * fH || y > 0.5 * fH) {
191 printf("y[%f] outside range\n", y);
192 return 0;
193 }
194
195 if (y > fSlope * x) return 1; // up
196 return -1; // down
197}
198
199//_________________________________________________________
201{
205 if ((fBinx + 1) * fN >= static_cast<Int_t>(fX.size())) return kFALSE;
206 fBinx++;
207 return kTRUE;
208}
209
210//_________________________________________________________
212{
216 if (fBiny + 1 >= fN) return kFALSE;
217 fBiny++;
218 return kTRUE;
219}
220
221//_________________________________________________________
222void CbmTrdTrianglePRF::Print(Option_t* opt) const
223{
224 printf("N=%d dw=%f dh=%f Slope=%f\n", fN, fdW, fdH, fSlope);
225 if (strcmp(opt, "all") != 0) return;
226 for (UInt_t i(0); i < fX.size(); i++) {
227 if (i && i % fN == 0) printf("\n\n");
228 printf("%2d(%5.2f %5.2f) ", fUp[i], fX[i], fY[i]);
229 }
230 printf("\n");
231}
232
233//_________________________________________________________
235{
239 if ((fBinx - 1) * fN < 0) return kFALSE;
240 fBinx--;
241 return kTRUE;
242}
243
244//_________________________________________________________
246{
250 if (fBiny - 1 < 0) return kFALSE;
251 fBiny--;
252 return kTRUE;
253}
254
255//_________________________________________________________
256Bool_t CbmTrdTrianglePRF::SetOrigin(Double_t x, Double_t y)
257{
258 Bool_t ret;
259 if ((ret = GetBin(x, y, fBinx0, fBiny0))) {
260 fBinx = fBinx0;
261 fBiny = fBiny0;
262 fX0 = x;
263 fY0 = y;
264 }
265 return ret;
266}
267
ClassImp(CbmConverterManager)
Utility for converting energy to signal over the triangular pad geometry (Bucharest prototype)
Double_t fNorm
normalization factor for the 2D Gauss distribution
Bool_t NextBinX()
Move current bin to the right.
Bool_t PrevBinX()
Move current bin to the left.
std::vector< Double_t > fX
position of bin center along wires
TF1 * fPRFy
PRF model across wires.
Bool_t SetOrigin(Double_t x, Double_t y)
Set map offset @ point (x,y)
Double_t fdH
bin half height
@ NC
no. of neighbor columns (except the hit) to be considered in cluster definition
@ NR
no. of neighbor rows (except the hit) to be considered in cluster definition
CbmTrdTrianglePRF(Float_t W, Float_t H, Int_t n=20)
Build map.
Double_t fH
pad height
Double_t fSlope
slope of triangle H/W
void Print(Option_t *opt="") const
TF1 * fPRFx
PRF model along wires.
Double_t GetChargeFraction() const
Compute charge fraction on the current bin.
Double_t fX0
Index of bin in the map corresponding to cluster center - y direction.
void GetCurrentPad(Int_t &col, Int_t &row, Int_t &u) const
Compute the pad corresponding to current bin.
Bool_t NextBinY()
Move current bin up.
Double_t fY0
y coordinate of cluster
Int_t fBiny
Current bin in the map - y direction.
Int_t fBinx
Current bin in the map - x direction.
std::vector< Double_t > fY
position of bin center across wires
Int_t GetSide(const Float_t x, const Float_t y) const
Define triangular pad type.
Double_t fW
pad width
std::vector< Char_t > fUp
1 for the upper pad, -1 for the bottom pad and 0 on the boundary
Bool_t PrevBinY()
Move current bin down.
Bool_t GetBin(Double_t x, Double_t y, Int_t &binx, Int_t &biny) const
Find bin for point (x,y)
Double_t fdW
bin half width
Int_t fBiny0
Offset bin in the map - y direction.
Int_t fBinx0
Offset bin in the map - x direction.