CMS 3D CMS Logo

Conv4HitsReco2.cc
Go to the documentation of this file.
1 //
2 // Simple photon conversion seeding class (src)
3 //
4 // Author: E Song
5 //
6 // Version: 1; 6 Aug 2012
7 //
8 
9 #define Conv4HitsReco2_cxx
10 
11 //#include "Conv4HitsReco2.h"
12 //#include "FWCore/MessegeLogger/interface/MessegeLogger.h"
13 #include "Conv4HitsReco2.h"
14 #include <ctime>
15 
18  Refresh(vPhotVertex, h1, h2, h3, h4);
19 }
20 
22 //Conv4HitsReco2::~Conv4HitsReco() { }
23 
26  // Fix 2D plane, make primary vertex the original point
27  fPV = vPhotVertex;
28  fPV.SetZ(0.);
29  fHitv11 = h3;
30  fHitv11.SetZ(0.);
31  fHitv11 = fHitv11 - fPV;
32  fHitv21 = h4;
33  fHitv21.SetZ(0.);
34  fHitv21 = fHitv21 - fPV;
35  fHitv12 = h2;
36  fHitv12.SetZ(0.);
37  fHitv12 = fHitv12 - fPV;
38  fHitv22 = h1;
39  fHitv22.SetZ(0.);
40  fHitv22 = fHitv22 - fPV;
41 
42  // DEFAULT setup
45  fRadiusECut = 10.0; //cm
46  fPhiECut = 0.03; //rad
47  fRECut = 0.5; //cm
48  fBField = 3.8; //T
49 
50  // TRIVIAL initialization
51  fCutSatisfied = 0;
52  fSignSatisfied = 0;
53  fSolved = 0;
54 
55  fRecPhi = 0.;
56  fRecR = 0.;
57  fRecR1 = 0.;
58  fRecR2 = 0.;
59  fRadiusE = 0.;
60  fRE = 0.;
61  fPhiE = 0.;
62 }
63 
65  const math::XYZVector &v12,
66  const math::XYZVector &v21,
67  const math::XYZVector &v22,
68  math::XYZVector &V11,
69  math::XYZVector &V12,
70  math::XYZVector &V21,
71  math::XYZVector &V22,
72  double NextPhi) {
73  double x11, x12, x21, x22, y11, y12, y21, y22;
74 
75  x11 = v11.X();
76  y11 = v11.Y();
77  x12 = v12.X();
78  y12 = v12.Y();
79  x21 = v21.X();
80  y21 = v21.Y();
81  x22 = v22.X();
82  y22 = v22.Y();
83 
84  double SINP = std::sin(NextPhi);
85  double COSP = std::cos(NextPhi);
86  double SignCOSP = 1.;
87  if (COSP < 0.)
88  SignCOSP = -1.;
89  double AbsCOSP = std::fabs(COSP);
90 
91  double X11 = -std::fabs(x11 * SINP * SignCOSP - y11 * AbsCOSP);
92  double Y11 = std::fabs(y11 * SINP * SignCOSP + x11 * AbsCOSP);
93 
94  double X21 = -std::fabs(x21 * SINP * SignCOSP - y21 * AbsCOSP);
95  double Y21 = std::fabs(y21 * SINP * SignCOSP + x21 * AbsCOSP);
96 
97  double X12 = std::fabs(x12 * SINP * SignCOSP - y12 * AbsCOSP);
98  double Y12 = std::fabs(y12 * SINP * SignCOSP + x12 * AbsCOSP);
99 
100  double X22 = std::fabs(x22 * SINP * SignCOSP - y22 * AbsCOSP);
101  double Y22 = std::fabs(y22 * SINP * SignCOSP + x22 * AbsCOSP);
102 
103  V11.SetXYZ(X11, Y11, 0.);
104  V12.SetXYZ(X12, Y12, 0.);
105  V21.SetXYZ(X21, Y21, 0.);
106  V22.SetXYZ(X22, Y22, 0.);
107 }
108 
109 int Conv4HitsReco2::ConversionCandidate(math::XYZVector &vtx, double &ptplus, double &ptminus) {
110  Reconstruct();
111 
112  ptplus = fRecR2 * fBField * 0.01 * 0.3; // 2 - positron
113  ptminus = fRecR1 * fBField * 0.01 * 0.3; // 1 - electron
114  vtx = fRecV;
115  //std::cout << ".";
116  return fLoop;
117 }
118 
120  double x11, x12, x21, x22, y11, y12, y21, y22;
121  //double X11,X12,X21,X22,Y11,Y12,Y21,Y22;
122  x11 = fHitv11.X();
123  y11 = fHitv11.Y();
124  x12 = fHitv12.X();
125  y12 = fHitv12.Y();
126  x21 = fHitv21.X();
127  y21 = fHitv21.Y();
128  x22 = fHitv22.X();
129  y22 = fHitv22.Y();
130 
131  if (fFixedNumberOfIterations == 0)
133  else
135 
136  // Setting Phi1, Phi2 initial guess range, and first guess
137  double tempr1 = std::sqrt(y11 * y11 + x11 * x11);
138  double tempr2 = std::sqrt(y12 * y12 + x12 * x12);
139 
140  double Phi1 = 2.0 * std::atan(y11 / (x11 + tempr1));
141  double Phi2 = 2.0 * std::atan(y12 / (x12 + tempr2));
142 
143  if (Phi1 < Phi2)
144  Phi1 += 2.0 * 3.141592653; // stupid Atan correction
145 
146  fPhiE = std::fabs((Phi1 - Phi2)) / std::pow(2.0, fLoop + 1);
147 
148  double NextPhi = (Phi1 + Phi2) / 2.0; // first guess
149  double D1, D2 = 0.0;
150  double prevR1 = 0;
151  double prevR2 = 0;
152  double R1 = 0;
153  double R2 = 0;
154 
155  // Iterations
156  for (int i = 0; i < fLoop; i++) {
157  // LOCAL TRANFORMATION & EXTRACTION
158  double SINP = std::sin(NextPhi);
159  double COSP = std::cos(NextPhi);
160  double SignCOSP = 1.;
161  if (COSP < 0.)
162  SignCOSP = -1.;
163  double AbsCOSP = std::fabs(COSP);
164 
165  double X11 = -std::fabs(x11 * SINP * SignCOSP - y11 * AbsCOSP);
166  double Y11 = std::fabs(y11 * SINP * SignCOSP + x11 * AbsCOSP);
167 
168  double X21 = -std::fabs(x21 * SINP * SignCOSP - y21 * AbsCOSP);
169  double Y21 = std::fabs(y21 * SINP * SignCOSP + x21 * AbsCOSP);
170 
171  double X12 = std::fabs(x12 * SINP * SignCOSP - y12 * AbsCOSP);
172  double Y12 = std::fabs(y12 * SINP * SignCOSP + x12 * AbsCOSP);
173 
174  double X22 = std::fabs(x22 * SINP * SignCOSP - y22 * AbsCOSP);
175  double Y22 = std::fabs(y22 * SINP * SignCOSP + x22 * AbsCOSP);
176  // I'm not using LocalTransform() function because this direct way turns out to be faster
177 
178  // SOLVING EQUATIONS
179  double d1 = Y21 - Y11;
180  double d2 = Y22 - Y12;
181 
182  if (((X11 * X11 * d1 * d1 / (X21 - X11) / (X21 - X11) + X11 * X21 + X11 * d1 * d1 / (X21 - X11)) < 0) ||
183  ((X12 * X12 * d2 * d2 / (X22 - X12) / (X22 - X12) + X12 * X22 + X12 * d2 * d2 / (X22 - X12)) < 0)) {
184  fSolved = -1;
185  fLoop = i;
186  return;
187  } // No real root. Break out.
188 
189  else {
190  fSolved = 1;
191  D1 = X11 * d1 / (X21 - X11);
192  D1 = D1 + std::sqrt(X11 * X11 * d1 * d1 / (X21 - X11) / (X21 - X11) + X11 * X21 + X11 * d1 * d1 / (X21 - X11));
193  D2 = X12 * d2 / (X22 - X12);
194  D2 = D2 + std::sqrt(X12 * X12 * d2 * d2 / (X22 - X12) / (X22 - X12) + X12 * X22 + X12 * d2 * d2 / (X22 - X12));
195 
196  R1 = std::fabs((X11 + X21) / 2.0 + (D1 + d1 / 2.0) * d1 / (X21 - X11));
197  R2 = std::fabs((X12 + X22) / 2.0 + (D2 + d2 / 2.0) * d2 / (X22 - X12));
198 
199  if ((Y11 - D1) >= (Y12 - D2)) { // Moving RIGHT
200  Phi1 = NextPhi;
201  // Phi2 remains the same
202  NextPhi = (Phi1 + Phi2) / 2.0;
203  } else if ((Y11 - D1) < (Y12 - D2)) { // Moving LEFT
204  // Phi1 remains the same
205  Phi2 = NextPhi;
206  NextPhi = (Phi1 + Phi2) / 2.0;
207  }
208 
209  // CHECK STOP CONDITION
210  double tmpPhiE = std::fabs(Phi1 - Phi2);
211  double tmpRE = std::fabs((Y11 - D1) - (Y12 - D2));
212  double tmpRadiusE = (std::fabs(R1 - prevR1) + std::fabs(R2 - prevR2)) / 2.;
213 
214  // A. Cut threshold satisfied - STOP - record
215  if ((tmpPhiE <= fPhiECut) && (tmpRE <= fRECut) && (tmpRadiusE <= fRadiusECut) &&
216  (fFixedNumberOfIterations == 0)) {
217  fSolved = 1;
218  fCutSatisfied = 1;
219  fLoop = i + 1;
220  fPhiE = tmpPhiE;
221  fRE = tmpRE;
222  fRadiusE = tmpRadiusE;
223  fRecR1 = R1;
224  fRecR2 = R2;
225  fRecR = ((Y11 - D1) + (Y12 - D2)) / 2.0;
226  fRecPhi = NextPhi;
227  fRecV.SetX(fRecR * cos(fRecPhi));
228  fRecV.SetY(fRecR * sin(fRecPhi));
229  fRecC1.SetXYZ(fRecV.X() - fRecR1 * sin(fRecPhi), fRecV.Y() + fRecR1 * cos(fRecPhi), 0.);
230  fRecC2.SetXYZ(fRecV.X() + fRecR2 * sin(fRecPhi), fRecV.Y() - fRecR2 * cos(fRecPhi), 0.);
231  fRecV = fRecV + fPV;
232  fRecC1 = fRecC1 + fPV;
233  fRecC2 = fRecC2 + fPV;
234  fCutSatisfied = 1;
235  if ((R1 > 0) && (R2 > 0) && (D1 > 0) && (D2 > 0) && ((Y11 - D1) > 0) && ((Y12 - D2) > 0))
236  fSignSatisfied = 1;
237  else
238  fSignSatisfied = 0;
239  } else if (i == fLoop - 1) {
240  fSolved = 1;
241  fCutSatisfied = 1;
242  fLoop = i + 1;
243  fPhiE = tmpPhiE;
244  fRE = tmpRE;
245  fRadiusE = tmpRadiusE;
246  fRecR1 = R1;
247  fRecR2 = R2;
248  fRecR = ((Y11 - D1) + (Y12 - D2)) / 2.0;
249  fRecPhi = NextPhi;
250  fRecV.SetX(fRecR * cos(fRecPhi));
251  fRecV.SetY(fRecR * sin(fRecPhi));
252  fRecC1.SetXYZ(fRecV.X() - fRecR1 * sin(fRecPhi), fRecV.Y() + fRecR1 * cos(fRecPhi), 0.);
253  fRecC2.SetXYZ(fRecV.X() + fRecR2 * sin(fRecPhi), fRecV.Y() - fRecR2 * cos(fRecPhi), 0.);
254  fRecV = fRecV + fPV;
255  fRecC1 = fRecC1 + fPV;
256  fRecC2 = fRecC2 + fPV;
257  fCutSatisfied = 0;
258  if ((R1 > 0) && (R2 > 0) && (D1 > 0) && (D2 > 0) && ((Y11 - D1) > 0) && ((Y12 - D2) > 0))
259  fSignSatisfied = 1;
260  else
261  fSignSatisfied = 0;
262  }
263  // B. Cut threshold NOT satisfied - prepare for next loop
264  prevR1 = R1;
265  prevR2 = R2;
266  }
267  }
268 }
269 
271  std::cout << std::endl << "================================================" << std::endl;
272  std::cout << " Nothing happend here.";
273  if (fSolved == 1)
274  std::cout << "Solved.";
275  if (fCutSatisfied == 1)
276  std::cout << "Cut good.";
277  if (fSignSatisfied == 1)
278  std::cout << "Sign good.";
279 }
280 
282  plusR = fRecR1;
283  return fRecC1;
284 }
286  minusR = fRecR2;
287  return fRecC2;
288 }
Divides< B, C > D2
Definition: Factorize.h:137
int fFixedNumberOfIterations
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
void LocalTransformation(const math::XYZVector &v11, const math::XYZVector &v12, const math::XYZVector &v21, const math::XYZVector &v22, math::XYZVector &V11, math::XYZVector &V12, math::XYZVector &V21, math::XYZVector &V22, double Phi)
math::XYZVector GetMinusCenter(double &)
int ConversionCandidate(math::XYZVector &, double &, double &)
math::XYZVector fPV
T sqrt(T t)
Definition: SSEVec.h:19
Divides< A, C > D1
Definition: Factorize.h:136
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
math::XYZVector fHitv21
math::XYZVector fHitv22
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
math::XYZVector fHitv12
math::XYZVector fRecC1
void Refresh(math::XYZVector &vPhotVertex, math::XYZVector &h1, math::XYZVector &h2, math::XYZVector &h3, math::XYZVector &h4)
math::XYZVector GetPlusCenter(double &)
math::XYZVector fHitv11
math::XYZVector fRecV
math::XYZVector fRecC2
static constexpr float d1
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29