FairRoot/PandaRoot
PndTrkCombiLegendreTransform.cxx
Go to the documentation of this file.
1 //
3 // PndTrkCombiLegendreTransform
4 //
5 // Class to perform the Combinatorial Legendre Transformation:
6 // for each couple ij of hits, the 4 intersections of the r = r(theta)
7 // sinusoidal curves are computed and the accumulation histo is
8 // filled with these points only.
9 // 1. the nof entries in the histo and its binning are not dependent anymore
10 // 2. the nof entries in the histo is 2 * N * (N - 1), with N = nof hits
11 // 3. if the couple ij was considered, then the couple ji is skipped
12 // 4. this method is equivalent to fill the accumulation plot with the 4 tangents
13 // of each couple of hits (4 lines are tangent to both two circles)
14 //
15 // authors: Lia Lavezzi - INFN Pavia (2012)
16 //
18 
20 
21 #include <iostream>
22 
23 using namespace std;
24 
25 
26 // ----- Default constructor -------------------------------------------
28  fThetaNofBin = 180;
29  fThetaMin = 0;
30  fThetaMax = 180;
31  fRNofBin = 1000;
32  fRMin = -0.07;
33  fRMax = 0.07;
34  fhLegendre = NULL;
35 }
36 
37 // -------------------------------------------------------------------------
38 
39 // ----- Destructor ----------------------------------------------------
41 
42 }
43 // -------------------------------------------------------------------------
44 
45 // ------ HISTOGRAM --------------------------------------------------------
47  if(fhLegendre == NULL) fhLegendre = new TH2F("fhCombiLegendre", "", fThetaNofBin, fThetaMin, fThetaMax, fRNofBin, fRMin, fRMax);
48  else fhLegendre->SetBins(fThetaNofBin, fThetaMin, fThetaMax, fRNofBin, fRMin, fRMax);
49 }
50 
51 void PndTrkCombiLegendreTransform::SetUpLegendreHisto(double thetaNofBin, double thetaMin, double thetaMax, double rNofBin, double rMin, double rMax) {
52  fThetaNofBin = thetaNofBin;
53  fThetaMin = thetaMin;
54  fThetaMax = thetaMax;
55  fRNofBin = rNofBin;
56  fRMin = rMin;
57  fRMax = rMax;
58  SetUpLegendreHisto();
59 }
60 
62  fhLegendre->Reset();
63  fhLegendre->SetStats(kFALSE);
64 }
65 
66 
67 void PndTrkCombiLegendreTransform::FillHisto(TH2F *histo, double x1, double y1, double r1, double x2, double y2, double r2)
68 {
69  double theta, r;
70  ComputeThetaR(x1, y1, r1, x2, y2, r2, theta, r);
71  histo->Fill(theta * TMath::RadToDeg(), r);
72 }
73 
74 void PndTrkCombiLegendreTransform::ComputeThetaR(double x1, double y1, double r1, double x2, double y2, double r2, double &theta, double &r)
75 {
76 
77  double dx = x1 - x2;
78  double dy = y1 - y2;
79 
80  if(r1 == 0 && r2 == 0) { // two points
81  theta = TMath::ATan2(-dx, dy);
82  r = x1 * TMath::Cos(theta) + y1 * TMath::Sin(theta);
83  // cout << "2points " << theta * TMath::RadToDeg() << "/ r " << r << endl;
84  }
85  else if(r1 > 0 && r2 > 0) { // two circles
86  double dr[4] = {r1 - r2, r1 + r2, -r1 - r2, -r1 + r2};
87  for(int ir = 0; ir < 4; ir++) {
88 
89  double alpha = TMath::ATan2(dy, dx);
90  if(dy < 0) alpha += (2 * TMath::Pi());
91 
92  double distance = TMath::Sqrt(dx * dx + dy * dy);
93  theta = alpha + TMath::ACos(-dr[ir]/distance);
94 
95  while(theta < 0) theta += TMath::Pi();
96  while(theta > TMath::Pi()) theta -= TMath::Pi();
97 
98  // try all the combinations (++ +- -+ --) and...
99  double rA[2], rB[2];
100  rA[0] = x1 * TMath::Cos(theta) + y1 * TMath::Sin(theta) - r1;
101  rA[1] = x1 * TMath::Cos(theta) + y1 * TMath::Sin(theta) + r1;
102  rB[0] = x2 * TMath::Cos(theta) + y2 * TMath::Sin(theta) - r2;
103  rB[1] = x2 * TMath::Cos(theta) + y2 * TMath::Sin(theta) + r2;
104 
105  // ...get the one where curve A and curve B have the same r --> they cross
106  if(fabs(rA[0] - rB[0]) < 1e-10 || fabs(rA[0] - rB[1]) < 1e-10) r = rA[0];
107  else if(fabs(rA[1] - rB[0]) < 1e-10 || fabs(rA[1] - rB[1]) < 1e-10) r = rA[1];
108 
109  // cout << "2circles " << theta * TMath::RadToDeg() << "/ r " << r << endl;
110  // cout << "ir " << ir << " theta " << theta * TMath::RadToDeg() << "/ r " << r << endl;
111  }
112  }
113  else { // one point/one circle
114  double rj;
115  if(r1 > 0) rj = r1;
116  else rj = r2;
117 
118  double dr[2] = {-rj, rj};
119  for(int ir = 0; ir < 2; ir++) {
120 
121  double alpha = TMath::ATan2(dy, dx);
122  if(dy < 0) alpha += (2 * TMath::Pi());
123 
124  double distance = TMath::Sqrt(dx * dx + dy * dy);
125  theta = alpha + TMath::ACos(dr[ir]/distance);
126 
127  while(theta < 0) theta += TMath::Pi();
128  while(theta > TMath::Pi()) theta -= TMath::Pi();
129 
130  if(r1 > 0) r = x2 * TMath::Cos(theta) + y2 * TMath::Sin(theta);
131  else r = x1 * TMath::Cos(theta) + y1 * TMath::Sin(theta);
132  // cout << "1pt/1cir " << theta * TMath::RadToDeg() << "/ r " << r << endl;
133 
134  // cout << "ir " << ir << " theta " << theta * TMath::RadToDeg() << "/ r " << r << endl;
135  }
136  }
137 }
138 
139 
140 void PndTrkCombiLegendreTransform::FillLegendreHisto(double x1, double y1, double radius1, double x2, double y2, double radius2) {
141  FillHisto(fhLegendre, x1, y1, radius1, x2, y2, radius2);
142 }
143 
145  fhLegendre->Draw("colz");
146 }
147 
148 int PndTrkCombiLegendreTransform::ExtractLegendreMaximum(double &theta_max, double &r_max) {
149  ExtractMaximumFromHisto(fhLegendre, theta_max, r_max);
150 }
151 
152 int PndTrkCombiLegendreTransform::ExtractMaximumFromHisto(TH2F *histo, double &theta_max, double &r_max) {
153  int bin = histo->GetMaximumBin();
154  int binx, biny, binz;
155  histo->GetBinXYZ(bin, binx, biny, binz);
156  theta_max = histo->GetXaxis()->GetBinCenter(binx);
157  r_max = histo->GetYaxis()->GetBinCenter(biny);
158  return histo->GetMaximum();
159 
160 }
161 
163  double theta, r;
164  ExtractLegendreMaximum(theta, r);
165  ExtractLineParameters(theta, r, slope, intercept);
166 }
167 
168 void PndTrkCombiLegendreTransform::ExtractLineParameters(double theta, double r, double &slope, double &intercept) {
169  // r = x cost + y sint --> y = r/sint - x/tant
170 
171  if(theta == 0.) theta = 1.e-6; // CHECK
172 
173  slope = - 1./TMath::Tan(TMath::DegToRad() * theta);
174  intercept = r/TMath::Sin(TMath::DegToRad() * theta);
175 
176 }
178 
double dy
double r
Definition: RiemannTest.C:14
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
static T Sin(const T &x)
Definition: PndCAMath.h:42
float Tan(float x)
Definition: PndCAMath.h:165
void FillLegendreHisto(double x1, double y1, double radius1, double x2, double y2, double radius2)
double r1
void FillHisto(TH2F *histo, double x1, double y1, double r1, double x2, double y2, double r2)
static T Cos(const T &x)
Definition: PndCAMath.h:43
void ComputeThetaR(double x1, double y1, double r1, double x2, double y2, double r2, double &theta, double &r)
Double_t fThetaMin
Definition: run_full.C:19
void ExtractLineParameters(double theta, double r, double &slope, double &intercept)
void ExtractLegendreSingleLineParameters(double &slope, double &intercept)
static T ATan2(const T &y, const T &x)
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
double dx
int ExtractLegendreMaximum(double &theta_max, double &r_max)
int ExtractMaximumFromHisto(TH2F *histo, double &theta_max, double &r_max)
ClassImp(PndAnaContFact)
double alpha
Definition: f_Init.h:9
Double_t fThetaMax
Definition: run_full.C:21
Double_t Pi
double r2
static int ir
Definition: ranlxd.cxx:374