FairRoot/PandaRoot
PndTrkLegendreTransform.cxx
Go to the documentation of this file.
1 //
3 // PndTrkLegendreTransform
4 //
5 // Class to perform the Legendre Transformation
6 //
7 // authors: Lia Lavezzi - INFN Pavia (2012)
8 //
10 
12 
13 #include <iostream>
14 
15 using namespace std;
16 
17 
18 // ----- Default constructor -------------------------------------------
20  fThetaNofBin = 180;
21  fThetaMin = 0;
22  fThetaMax = 180;
23  fRNofBin = 1000;
24  fRMin = -0.07;
25  fRMax = 0.07;
26 
27 
28  fThetaMinZoom = 0;
29  fThetaMaxZoom = 180;
30  fRMinZoom = -0.07;
31  fRMaxZoom = 0.07;
32 
33  fhLegendre = NULL;
34  fhLegendreZoom = NULL;
35 }
36 
37 // -------------------------------------------------------------------------
38 
39 // ----- Destructor ----------------------------------------------------
41 
42 }
43 // -------------------------------------------------------------------------
44 
45 // ------ HISTOGRAM --------------------------------------------------------
47  fhLegendre = new TH2F("fhLegendre", "", fThetaNofBin, fThetaMin, fThetaMax, fRNofBin, fRMin, fRMax);
48 }
49 
50 void PndTrkLegendreTransform::SetUpLegendreHisto(double thetaNofBin, double thetaMin, double thetaMax, double rNofBin, double rMin, double rMax) {
51  fThetaNofBin = thetaNofBin;
52  fThetaMin = thetaMin;
53  fThetaMax = thetaMax;
54  fRNofBin = rNofBin;
55  fRMin = rMin;
56  fRMax = rMax;
57  if(fhLegendre) {
58  fhLegendre->SetBins(fThetaNofBin, fThetaMin, fThetaMax, fRNofBin, fRMin, fRMax);
59  ResetLegendreHisto();
60  }
61  else SetUpLegendreHisto();
62 }
63 
65  fhLegendre->Reset();
66  fhLegendre->SetStats(kFALSE);
67 }
68 
69 
70 void PndTrkLegendreTransform::FillHisto(TH2F *histo, double thetamin, double thetamax, double x, double y, double radius) {
71  Double_t thetaRad = thetamin * TMath::DegToRad();
72  double deltaThetaRad = TMath::DegToRad() * (thetamax - thetamin)/fThetaNofBin;
73 
74 
75  // computation
76  //double deltar = deltaThetaRad * (y * TMath::Cos(thetaRad) - x * TMath::Sin(thetaRad)); //[R.K. 01/2017] unused variable
77  // cout << "cfr delta r " << x << " " << y << " " << radius << " " << deltar << " " << (fRMax - fRMin)/fRNofBin << " " << 2 * radius << endl;
78 
79 
80  while(thetaRad < thetamax * TMath::DegToRad()) {
81  double thetaDeg = thetaRad * TMath::RadToDeg();
82 
83  // STT
84  if(radius > 0.) {
85  double r1 = x * TMath::Cos(thetaRad) + y * TMath::Sin(thetaRad) + radius;
86  double r2 = x * TMath::Cos(thetaRad) + y * TMath::Sin(thetaRad) - radius;
87  // histo->Fill(thetaDeg, r1, radius);
88  // histo->Fill(thetaDeg, r2, radius);
89  histo->Fill(thetaDeg, r1);
90  histo->Fill(thetaDeg, r2);
91  }
92  else { // MVD, SCITIL, GEM
93  double r = x * TMath::Cos(thetaRad) + y * TMath::Sin(thetaRad);
94  histo->Fill(thetaDeg, r);
95  }
96 
97  thetaRad += deltaThetaRad;
98 
99  }
100 }
101 
102 void PndTrkLegendreTransform::FillLegendreHisto(double x, double y, double radius) {
103  FillHisto(fhLegendre, fThetaMin, fThetaMax, x, y, radius);
104 }
105 
106 // void PndTrkLegendreTransform::ApplyThresholdLegendreHisto(double threshold) {
107 // int max = fhLegendre->GetMaximum();
108 // fhLegendre->GetZaxis()->SetRangeUser(max * threshold, max);
109 // }
110 
111 int PndTrkLegendreTransform::ExtractLegendreMaximum(double &theta_max, double &r_max) {
112  return ExtractMaximumFromHisto(fhLegendre, theta_max, r_max);
113 }
114 
115 void PndTrkLegendreTransform::ExtractLegendreMaxima(int nmaxima, std::vector< double > &theta_max, std::vector< double > &r_max, std::vector < int > &content_max) {
116  ExtractMaximaFromHisto(nmaxima, fhLegendre, theta_max, r_max, content_max);
117 }
118 
119 
120 void PndTrkLegendreTransform::ExtractLegendreSingleLineParameters(double &slope, double &intercept) {
121  double theta, r;
122  ExtractLegendreMaximum(theta, r);
123  ExtractLineParameters(theta, r, slope, intercept);
124 }
125 
126 // ------ ZOOM -----------------------------------------------------------------
128  fhLegendreZoom = new TH2F("fhLegendreZoom", "", fThetaNofBin, fThetaMinZoom, fThetaMaxZoom, fRNofBin, fRMin, fRMax);
129 }
130 
131 void PndTrkLegendreTransform::SetUpZoomHisto(double theta, double r, double deltatheta, double deltar) {
132  if(fhLegendreZoom) {
133  ResetZoomHisto();
134  }
135 
136  fThetaMinZoom = theta - deltatheta;
137  fThetaMaxZoom = theta + deltatheta;
138  fRMinZoom = r - deltar;
139  fRMaxZoom = r + deltar;
140 
141  fhLegendreZoom->GetXaxis()->SetLimits(fThetaMinZoom, fThetaMaxZoom);
142  fhLegendreZoom->GetYaxis()->SetLimits(fRMinZoom, fRMaxZoom);
143 
144 }
145 
147  fhLegendreZoom->Reset();
148  fhLegendreZoom->SetStats(kFALSE);
149 }
150 
151 void PndTrkLegendreTransform::FillZoomHisto(double x, double y, double radius) {
152  FillHisto(fhLegendreZoom, fThetaMinZoom, fThetaMaxZoom, x, y, radius);
153 }
154 
155 int PndTrkLegendreTransform::ExtractZoomMaximum(double &theta_max, double &r_max) {
156  return ExtractMaximumFromHisto(fhLegendreZoom, theta_max, r_max);
157 }
158 
159 void PndTrkLegendreTransform::ExtractZoomSingleLineParameters(double &slope, double &intercept) {
160  double theta, r;
161  ExtractZoomMaximum(theta, r);
162  ExtractLineParameters(theta, r, slope, intercept);
163 }
164 
165 // GET A SINGLE LINE --> THE MAXIMUM -------------------------------------------
166 int PndTrkLegendreTransform::ExtractMaximumFromHisto(TH2F *histo, double &theta_max, double &r_max) {
167  int bin = histo->GetMaximumBin();
168  int binx, biny, binz;
169  histo->GetBinXYZ(bin, binx, biny, binz);
170  theta_max = histo->GetXaxis()->GetBinCenter(binx);
171  r_max = histo->GetYaxis()->GetBinCenter(biny);
172  return histo->GetMaximum();
173  // cout << "== THETA, R max ======== " << theta_max << " " << r_max << endl;
174 }
175 
176 void PndTrkLegendreTransform::ExtractMaximaFromHisto(int nmaxima, TH2F *histo, std::vector< double > &theta_max, std::vector< double > &r_max, std::vector < int > &content_max) {
177 
178  // PEAK Finder 2D
179  int maxbins[nmaxima];
180  for(int ibin = 0; ibin < nmaxima; ibin++) maxbins[ibin] = 0;
181 
182  for(int ibinx = 1; ibinx <= histo->GetNbinsX() ; ibinx++) {
183  for(int ibiny = 1; ibiny <= histo->GetNbinsY() ; ibiny++) {
184 
185  int bincontent = histo->GetBinContent(ibinx, ibiny);
186  if(bincontent == 0) continue;
187 
188  int ibintotal = histo->GetBin(ibinx, ibiny);
189 
190  // cout << "current bin: " << ibintotal << " contains " << bincontent << " entries" << endl;
191 
192  for(int ibinm = nmaxima - 1; ibinm >= 0; ibinm--) {
193  // cout << "ibinm " << ibinm << " " << bincontent << " " << maxbins[ibinm] << " " << histo->GetBinContent(maxbins[ibinm]) << endl;
194  if(bincontent >= histo->GetBinContent(maxbins[ibinm])) {
195  for(int jbinm = 0; jbinm < ibinm; jbinm++) maxbins[jbinm] = maxbins[jbinm + 1];
196  maxbins[ibinm] = ibintotal;
197  break;
198  }
199  }
200  }
201  }
202 
203  for(int ibin = 0; ibin < nmaxima; ibin++) {
204  int bin = maxbins[ibin];
205  int binx, biny, binz;
206  histo->GetBinXYZ(bin, binx, biny, binz);
207  theta_max.push_back(histo->GetXaxis()->GetBinCenter(binx));
208  r_max.push_back(histo->GetYaxis()->GetBinCenter(biny));
209  content_max.push_back(histo->GetBinContent(bin));
210 
211  }
212 
213 }
214 
215 
216 void PndTrkLegendreTransform::ExtractLineParameters(double theta, double r, double &slope, double &intercept) {
217  // r = x cost + y sint --> y = r/sint - x/tant
218 
219  if(theta == 0.) theta = 1.e-6; // CHECK
220 
221  slope = - 1./TMath::Tan(TMath::DegToRad() * theta);
222  intercept = r/TMath::Sin(TMath::DegToRad() * theta);
223 
224 }
225 
226 // -----------------------------------------------------------------------------
227 // DELETE A PEAK
229  DeleteZoneAroundXY(fhLegendre, x, y);
230 }
231 
233  DeleteZoneAroundXY(fhLegendreZoom, x, y);
234 }
235 
236 
237 void PndTrkLegendreTransform::DeleteZoneAroundXY(TH2F *histo, double x, double y) {
238 
239  // int bin = histo->GetMaximumBin();
240  // int bin1, bin2, bin3;
241  // histo->GetBinXYZ(bin, bin1, bin2, bin3);
242  // cout << "MAX BIN BEFORE " << bin << " " << bin1 << " " << bin2 << " " << bin3 << endl;
243 
244  int binx = (int) ((x - histo->GetXaxis()->GetXmin())/histo->GetXaxis()->GetBinWidth(1)) + 1;
245  int biny = (int) ((y - histo->GetYaxis()->GetXmin())/histo->GetYaxis()->GetBinWidth(1)) + 1;
246 
247  // delete the bin and a line and a row around it
248  histo->SetBinContent(binx, biny, 0);
249  histo->SetBinContent(binx + 1, biny, 0);
250  histo->SetBinContent(binx - 1, biny, 0);
251  histo->SetBinContent(binx + 1, biny + 1, 0);
252  histo->SetBinContent(binx, biny + 1, 0);
253  histo->SetBinContent(binx - 1, biny + 1, 0);
254  histo->SetBinContent(binx + 1, biny - 1, 0);
255  histo->SetBinContent(binx, biny - 1, 0);
256  histo->SetBinContent(binx - 1, biny - 1, 0);
257 
258  // cout << "deleting binx " << binx << " " << biny << endl;
259  // bin = histo->GetMaximumBin();
260  // histo->GetBinXYZ(bin, bin1, bin2, bin3);
261  // cout << "MAX BIN AFTER " << bin << " " << bin1 << " " << bin2 << " " << bin3 << endl;
262 }
263 
264 
265 // -----------------------------------------------------------------------------
266 
267 
268 
270  fhLegendre->Draw("colz");
271 }
272 
274  fhLegendreZoom->Draw("colz");
275 }
276 
278 
double r
Definition: RiemannTest.C:14
static T Sin(const T &x)
Definition: PndCAMath.h:42
float Tan(float x)
Definition: PndCAMath.h:165
void FillLegendreHisto(double x, double y, double radius)
double r1
void FillHisto(TH2F *histo, double thetamin, double thetamax, double x, double y, double radius)
static T Cos(const T &x)
Definition: PndCAMath.h:43
void DeleteZoneAroundXYLegendre(double x, double y)
Double_t fThetaMin
Definition: run_full.C:19
void ExtractMaximaFromHisto(int nmaxima, TH2F *histo, std::vector< double > &theta_max, std::vector< double > &r_max, std::vector< int > &content_max)
int ExtractLegendreMaximum(double &theta_max, double &r_max)
Double_t
int ExtractZoomMaximum(double &theta_max, double &r_max)
void FillZoomHisto(double x, double y, double radius)
void ExtractLineParameters(double theta, double r, double &slope, double &intercept)
void ExtractLegendreSingleLineParameters(double &slope, double &intercept)
void DeleteZoneAroundXYZoom(double x, double y)
int ExtractMaximumFromHisto(TH2F *histo, double &theta_max, double &r_max)
Double_t x
ClassImp(PndAnaContFact)
void ExtractZoomSingleLineParameters(double &slope, double &intercept)
Double_t y
Double_t fThetaMax
Definition: run_full.C:21
void DeleteZoneAroundXY(TH2F *histo, double x, double y)
double r2
void ExtractLegendreMaxima(int nmaxima, std::vector< double > &theta_max, std::vector< double > &r_max, std::vector< int > &content_max)