CMS 3D CMS Logo

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