CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Conv4HitsReco.cc
Go to the documentation of this file.
1 #define Conv4HitsReco_cxx
2 #include "Conv4HitsReco.h"
4 #include <sstream>
5 // 1 -> 4
6 // 2 -> 3
7 // 3 -> 2
8 // 4 -> 1
9 
11 
12  return (Tq*O0-T0*Oq)/(Tq*Om-Tm*Oq); //dm
13 
14 }
15 
17 
18  return (Tm*O0-T0*Om)/(Tm*Oq-Tq*Om); //dq
19 
20 }
21 
22 void Conv4HitsReco::SetLinSystCoeff(double m, double q){
23 
24  // dq*Tq + dm*Tm = T0 // Tangent condition
25  // dq*Oq + dm*Om = O0 // Orthogonality condition
26 
27  double sqrtEta2mm = sqrt(_eta2+m*m);
28  double sqrtPi2qq = sqrt(_pi2+q*q);
29 
30  double signT = 1.;
31 
32  Tq = -2.*pPN+2.*m*pn+signT*2.*q*sqrtEta2mm/sqrtPi2qq;
33  Tm = 2.*nPN+2.*q*pn+signT*2.*m*sqrtPi2qq/sqrtEta2mm;
34  T0 = PN2-_eta2-_pi2-2.*q*m*pn+2.*q*pPN-2.*m*nPN-signT*2.*sqrtEta2mm*sqrtPi2qq;
35 
36  TVector3 vQminusM = q*unitVp - m*unitVn + vPminusN;
37  double QM = vQminusM.Mag();
38  double pQM = unitVp*vQminusM;
39  double nQM = unitVn*vQminusM;
40  double NVQM = vNminusV*vQminusM;
41 
42  double signO = 1.;
43 
44  Oq = sqrtEta2mm*pQM/QM+m*pn+pNV;
45  Om = m*QM/sqrtEta2mm-signO*sqrtEta2mm*nQM/QM+nQM-nNV-m;
46  O0 = -signO*sqrtEta2mm*QM-m*nQM-NVQM;
47 
48 }
49 
51  std::stringstream ss;
52  TVector3 vPminusM = vPminusN - m*unitVn;
53  double m2 = m*m;
54  double nPM = unitVn*vPminusM;
55  double pPM = unitVp*vPminusM;
56  double NVPM = vNminusV*vPminusM;
57 
58  double alpha = (m*pn+pNV)*(m*pn+pNV)-_eta2-m2;
59  double beta = m2*pn*nPM+m*pn*NVPM+m*nPM*pNV-pPM*(_eta2+m2)+pNV*NVPM;
60  double gamma = m2*nPM*nPM+NVPM*NVPM+2.*m*nPM*NVPM-vPminusM.Mag2()*(_eta2+m2);
61 
62  double disc = sqrt(beta*beta - alpha*gamma);
63 
64  double q01 = (-beta+disc)/alpha;
65  double q02 = (-beta-disc)/alpha;
66 
67 
68  ss << " m: " << m << " q01: " << std::setw(20) << q01 << " q02: "<< std::setw(20) << q02 << "/n";
69  return ss.str();
70 }
71 
72 double Conv4HitsReco::qFromM(double m){
73 
74  LogDebug("Conv4HitsReco")<<qFromM_print(m);
75  return 0.;
76 
77 }
78 
80  radius = plusRadius;
81  return plusCenter;
82 }
83 
85  radius = minusRadius;
86  return minusCenter;
87 }
88 
89 //
90 //Point of intersection between two lines (each identified by a vector and a point)
91 TVector3 Conv4HitsReco::GetIntersection(TVector3& V1, TVector3& p1, TVector3& V2, TVector3& p2){
92 
93  TVector3 v1 = V1.Unit();
94  TVector3 v2 = V2.Unit();
95 
96  double v1v2=v1*v2;
97  return v2*((p1 - p2)*(v1v2*v1-v2)/(v1v2*v1v2-1.))+p2;
98 
99 }
100 
102 
103  return 0.01*0.3*3.8*sqrt(m*m+eta*eta);
104 
105 }
106 
108 
109  return GetPtFromParamAndHitPair(m, _eta);
110 
111 }
112 
114 
115  return GetPtFromParamAndHitPair(q, _pi);
116 
117 }
118 
119 TVector3 Conv4HitsReco::GetConvVertexFromParams(double &m, double &q){
120 
121  TVector3 unitVQminusM = (plusCenter-minusCenter).Unit();
122  TVector3 vtxViaPlus = vP+q*unitVp-plusRadius*unitVQminusM;
123  TVector3 vtxViaMinus = vN+m*unitVn+minusRadius*unitVQminusM;
124 
125  // return 0.5*(vN+m*unitVn+m*unitVQminusM+vP+q*unitVp-q*unitVQminusM);
126  LogDebug("Conv4HitsReco") << ">>>>>>>> Conversion vertex computed via Plus pair\n"
127  << vtxViaPlus
128  << ">>>>>>>> Conversion vertex computed via Minus pair\n"
129  << vtxViaMinus;
130 
131  return 0.5*(vtxViaPlus+vtxViaMinus);
132 
133 }
134 
135 int Conv4HitsReco::ConversionCandidate(TVector3 &vtx, double &ptplus, double &ptminus){
136 
137  double m;
138  double q;
139  int nits = 0;
140 
141  int isNotValidBefore = ComputeMaxLimits()+ComputeMinLimits();
142  int isNotValidAfter = 0;
143  if ( ! isNotValidBefore ){
144 
145  GuessStartingValues(m, q);
146  nits = mqFindByIteration(m, q);
147 
148  if ( q > qMaxLimit || q < qMinLimit ) {
149  isNotValidAfter = 1;
150  LogDebug("Conv4HitsReco")<< ">>>>>>>> quad result not valid for q: qMin= " << qMinLimit << " q= " << q << " qMax= " << qMaxLimit << "\n";
151 
152  }
153  if ( m > mMaxLimit || m < mMinLimit ) {
154  isNotValidAfter = 1;
155  LogDebug("Conv4HitsReco")<<">>>>>>>> quad result not valid for m: mMin= " << mMinLimit << " m= " << m << " mMax= " << mMaxLimit << "\n";
156  }
157 
158  ptminus = GetPtMinusFromParam(m);
159  ptplus = GetPtPlusFromParam(q);
160  minusCenter = vN+m*unitVn;
161  minusRadius = (hit4-minusCenter).Mag();
162  plusCenter = vP+q*unitVp;
163  plusRadius = (hit1-plusCenter).Mag();
165  vtx = convVtx;
166 
167  }
168 
169  if ( isNotValidBefore ) return 0;
170  if ( IsNotValidForPtLimit(m, q, ptLegMinCut, ptLegMaxCut) ) return -1000;
171  if ( IsNotValidForVtxPosition(maxVtxDistance) ) return -2000;
172  if ( isNotValidAfter ) return -1*nits;
173  return nits;
174 
175 }
176 
177 int Conv4HitsReco::mqFindByIteration(double &m, double &q){
178 
179  int maxIte = maxNumberOfIterations;
180  double err = iterationStopRelThreshold;
181  double edm = 1.;
182  double edq = 1.;
183  int i = 0;
184  while ( ((edq > err) || (edm > err)) && (i < maxIte) ){
185  SetLinSystCoeff(m,q);
186  double dm = GetDm();
187  double dq = GetDq();
188  /*
189  while( m+dm > mMaxLimit || m+dm < mMinLimit || q+dq > qMaxLimit || q+dq < qMinLimit ){
190 
191  LogDebug("Conv4HitsReco")<<">>>>>>>> Going outside limits, reducing increments \n";
192  dm=dm/2.;
193  dq=dq/2.;
194  }
195  */
196  m+=dm;
197  q+=dq;
198  edm = fabs(dm/m);
199  edq = fabs(dq/q);
200  LogDebug("Conv4HitsReco")<< ">>>>>>>> Iteration " << i << " m: " << m << " q: " << q << " dm: " << dm << " dq: " << dq << " edm: " << edm << " edq: " << edq << "\n";
201  i++;
202  }
203 
204  return i;
205 
206 }
207 
209 
210  // Q max limit
211  TVector3 vVminusHit2Orthogonal = (vV-hit2).Orthogonal();
212  TVector3 medianPointHit2V = 0.5*(vV+hit2);
213  vQMaxLimit = GetIntersection(vVminusHit2Orthogonal, medianPointHit2V, unitVp, vP);
214  qMaxLimit = (vQMaxLimit-vP).Mag();
215 
216  // M max limit
217  TVector3 vVminusHit3Orthogonal = (vV-hit3).Orthogonal();
218  TVector3 medianPointHit3V = 0.5*(vV+hit3);
219  vMMaxLimit = GetIntersection(vVminusHit3Orthogonal, medianPointHit3V, unitVn, vN);
220  mMaxLimit = (vMMaxLimit-vN).Mag();
221 
222  LogDebug("Conv4HitsReco")<< " >>>>>> Limits: qMax= " << qMaxLimit << " ==>pt " << GetPtFromParamAndHitPair(qMaxLimit, _pi) << " mMax= " << mMaxLimit << " ==>pt " <<GetPtFromParamAndHitPair(mMaxLimit, _eta) << "\n";
223 
224  return IsNotValidForPtLimit(mMaxLimit, qMaxLimit, ptLegMinCut, 100000.); //Max limit not applied here
225 
226 }
227 
228 int Conv4HitsReco::IsNotValidForPtLimit(double m, double q, double ptmin, double ptmax){
229 
230  if ( GetPtFromParamAndHitPair(q, _pi) < ptmin ) return 1;
231  if ( GetPtFromParamAndHitPair(m, _eta) < ptmin ) return 1;
232  if ( GetPtFromParamAndHitPair(q, _pi) > ptmax ) return 1;
233  if ( GetPtFromParamAndHitPair(m, _eta) > ptmax ) return 1;
234  return 0;
235 
236 }
237 
239 
240  TVector3 hitAve = 0.25*(hit1+hit2+hit3+hit4);
241  if ( (convVtx-hitAve).Mag() > maxDist ) return 1;
242  return 0;
243 
244 }
245 
247 
248  //Evaluate if quad is valid and compute min limits
249  if ( ((vV-vQMaxLimit).Cross(vMMaxLimit-vQMaxLimit)).Z() > 0. ){
250  //
251  //Quad is invalid
252  LogDebug("Conv4HitsReco")<< " >>>>>> Quad is invalid\n";
253  return 1;
254  } else {
255  //
256  // Compute q and m Min limits
257  TVector3 vQMinLimit = GetIntersection(v1minus2, vMMaxLimit, unitVp, vP);
258  qMinLimit = (vQMinLimit-vP)*unitVp;
259  TVector3 vMMinLimit = GetIntersection(v3minus4, vQMaxLimit, unitVn, vN);
260  mMinLimit = (vMMinLimit-vN)*unitVn;
261  if ( mMinLimit > mMaxLimit || qMinLimit > qMaxLimit ){
262  LogDebug("Conv4HitsReco")<< " >>>>>> Quad is invalid. qMin= " << qMinLimit << " mMin= " << mMinLimit << "\n";
263  return 2;
264  }
265  if ( IsNotValidForPtLimit(mMinLimit, qMinLimit, -1000., ptLegMaxCut) ){ //Min limit not applied here
266  return 2;
267  }
268 
269  LogDebug("Conv4HitsReco")<< " >>>>>> Quad is valid. qMin= " << qMinLimit << " mMin= " << mMinLimit << "\n";
270  return 0;
271  }
272 
273 }
274 
275 int Conv4HitsReco::GuessStartingValues(double &m, double &q){
276 
277  /*
278  m = 0.5*(mMinLimit+mMaxLimit);
279  q = 0.5*(qMinLimit+qMaxLimit);
280  */
281 
282  m = mMaxLimit;
283  q = qMaxLimit;
284 
285  LogDebug("Conv4HitsReco")<< " >>>>>> Starting values: q= " << q << " m= " << m << "\n";
286 
287  return 0;
288 
289 }
290 
291 
293 
294  LogDebug("Conv4HitsReco")
295  << " ======================================= " << "\n"
296  << " Photon Vertex: "
297  << vV
298  << " Hit1: "
299  << hit1
300  << " Hit2: "
301  << hit2
302  << " Hit3: "
303  << hit3
304  << " Hit4: "
305  << hit4
306  << " N: "
307  << vN
308  << " P: "
309  << vP
310  << " P-N: "
311  << vPminusN
312  << " n: "
313  << unitVn
314  << " p: "
315  << unitVp
316  << " eta: " << _eta << " pi: " << _pi << "\n";
317 
318 }
#define LogDebug(id)
const double Z[kNumberCalorimeter]
const double beta
TVector3 GetMinusCenter(double &)
int i
Definition: DBlmapReader.cc:9
int IsNotValidForPtLimit(double, double, double, double)
double minusRadius
Definition: Conv4HitsReco.h:51
float alpha
Definition: AMPTWrapper.h:95
TVector3 unitVp
Definition: Conv4HitsReco.h:29
TVector3 vNminusV
Definition: Conv4HitsReco.h:27
TVector3 vMMaxLimit
Definition: Conv4HitsReco.h:41
TVector3 hit3
Definition: Conv4HitsReco.h:16
double ptLegMaxCut
Definition: Conv4HitsReco.h:57
double GetPtMinusFromParam(double &)
double GetDm()
double mMaxLimit
Definition: Conv4HitsReco.h:44
double GetPtPlusFromParam(double &)
int GuessStartingValues(double &, double &)
int ComputeMinLimits()
double GetPtFromParamAndHitPair(double &, double &)
double qMaxLimit
Definition: Conv4HitsReco.h:43
TVector3 hit2
Definition: Conv4HitsReco.h:17
int IsNotValidForVtxPosition(double &)
double plusRadius
Definition: Conv4HitsReco.h:50
T sqrt(T t)
Definition: SSEVec.h:48
double GetDq()
TVector3 GetIntersection(TVector3 &, TVector3 &, TVector3 &, TVector3 &)
TVector3 hit4
Definition: Conv4HitsReco.h:15
int maxNumberOfIterations
Definition: Conv4HitsReco.h:54
TVector3 hit1
Definition: Conv4HitsReco.h:18
int mqFindByIteration(double &, double &)
TVector3 vPminusN
Definition: Conv4HitsReco.h:25
double p2[4]
Definition: TauolaWrapper.h:90
TVector3 vQMaxLimit
Definition: Conv4HitsReco.h:42
TVector3 minusCenter
Definition: Conv4HitsReco.h:48
int ComputeMaxLimits()
TVector3 convVtx
Definition: Conv4HitsReco.h:49
double mMinLimit
Definition: Conv4HitsReco.h:46
void SetLinSystCoeff(double, double)
double ptLegMinCut
Definition: Conv4HitsReco.h:56
TVector3 GetConvVertexFromParams(double &, double &)
TVector3 plusCenter
Definition: Conv4HitsReco.h:47
int ConversionCandidate(TVector3 &, double &, double &)
double ptmin
Definition: HydjetWrapper.h:85
double p1[4]
Definition: TauolaWrapper.h:89
double qFromM(double)
TVector3 v1minus2
Definition: Conv4HitsReco.h:22
TVector3 GetPlusCenter(double &)
TVector3 unitVn
Definition: Conv4HitsReco.h:28
double qMinLimit
Definition: Conv4HitsReco.h:45
double maxVtxDistance
Definition: Conv4HitsReco.h:55
Definition: Tm.h:13
TVector3 v3minus4
Definition: Conv4HitsReco.h:21
double iterationStopRelThreshold
Definition: Conv4HitsReco.h:53
std::string qFromM_print(double m)