CMS 3D CMS Logo

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  return (Tq * O0 - T0 * Oq) / (Tq * Om - Tm * Oq); //dm
12 }
13 
15  return (Tm * O0 - T0 * Om) / (Tm * Oq - Tq * Om); //dq
16 }
17 
18 void Conv4HitsReco::SetLinSystCoeff(double m, double q) {
19  // dq*Tq + dm*Tm = T0 // Tangent condition
20  // dq*Oq + dm*Om = O0 // Orthogonality condition
21 
22  double sqrtEta2mm = sqrt(_eta2 + m * m);
23  double sqrtPi2qq = sqrt(_pi2 + q * q);
24 
25  double signT = 1.;
26 
27  Tq = -2. * pPN + 2. * m * pn + signT * 2. * q * sqrtEta2mm / sqrtPi2qq;
28  Tm = 2. * nPN + 2. * q * pn + signT * 2. * m * sqrtPi2qq / sqrtEta2mm;
29  T0 = PN2 - _eta2 - _pi2 - 2. * q * m * pn + 2. * q * pPN - 2. * m * nPN - signT * 2. * sqrtEta2mm * sqrtPi2qq;
30 
31  TVector3 vQminusM = q * unitVp - m * unitVn + vPminusN;
32  double QM = vQminusM.Mag();
33  double pQM = unitVp * vQminusM;
34  double nQM = unitVn * vQminusM;
35  double NVQM = vNminusV * vQminusM;
36 
37  double signO = 1.;
38 
39  Oq = sqrtEta2mm * pQM / QM + m * pn + pNV;
40  Om = m * QM / sqrtEta2mm - signO * sqrtEta2mm * nQM / QM + nQM - nNV - m;
41  O0 = -signO * sqrtEta2mm * QM - m * nQM - NVQM;
42 }
43 
45  std::stringstream ss;
46  TVector3 vPminusM = vPminusN - m * unitVn;
47  double m2 = m * m;
48  double nPM = unitVn * vPminusM;
49  double pPM = unitVp * vPminusM;
50  double NVPM = vNminusV * vPminusM;
51 
52  double alpha = (m * pn + pNV) * (m * pn + pNV) - _eta2 - m2;
53  double beta = m2 * pn * nPM + m * pn * NVPM + m * nPM * pNV - pPM * (_eta2 + m2) + pNV * NVPM;
54  double gamma = m2 * nPM * nPM + NVPM * NVPM + 2. * m * nPM * NVPM - vPminusM.Mag2() * (_eta2 + m2);
55 
56  double disc = sqrt(beta * beta - alpha * gamma);
57 
58  double q01 = (-beta + disc) / alpha;
59  double q02 = (-beta - disc) / alpha;
60 
61  ss << " m: " << m << " q01: " << std::setw(20) << q01 << " q02: " << std::setw(20) << q02 << "/n";
62  return ss.str();
63 }
64 
65 double Conv4HitsReco::qFromM(double m) {
66  LogDebug("Conv4HitsReco") << qFromM_print(m);
67  return 0.;
68 }
69 
72  return plusCenter;
73 }
74 
77  return minusCenter;
78 }
79 
80 //
81 //Point of intersection between two lines (each identified by a vector and a point)
82 TVector3 Conv4HitsReco::GetIntersection(TVector3 &V1, TVector3 &p1, TVector3 &V2, TVector3 &p2) {
83  TVector3 v1 = V1.Unit();
84  TVector3 v2 = V2.Unit();
85 
86  double v1v2 = v1 * v2;
87  return v2 * ((p1 - p2) * (v1v2 * v1 - v2) / (v1v2 * v1v2 - 1.)) + p2;
88 }
89 
90 double Conv4HitsReco::GetPtFromParamAndHitPair(double &m, double &eta) {
91  return 0.01 * 0.3 * 3.8 * sqrt(m * m + eta * eta);
92 }
93 
95 
97 
98 TVector3 Conv4HitsReco::GetConvVertexFromParams(double &m, double &q) {
99  TVector3 unitVQminusM = (plusCenter - minusCenter).Unit();
100  TVector3 vtxViaPlus = vP + q * unitVp - plusRadius * unitVQminusM;
101  TVector3 vtxViaMinus = vN + m * unitVn + minusRadius * unitVQminusM;
102 
103  // return 0.5*(vN+m*unitVn+m*unitVQminusM+vP+q*unitVp-q*unitVQminusM);
104  LogDebug("Conv4HitsReco") << ">>>>>>>> Conversion vertex computed via Plus pair\n"
105  << vtxViaPlus.x() << "," << vtxViaPlus.y() << "," << vtxViaPlus.z()
106  << ">>>>>>>> Conversion vertex computed via Minus pair\n"
107  << vtxViaMinus.x() << "," << vtxViaMinus.y() << "," << vtxViaMinus.z();
108 
109  return 0.5 * (vtxViaPlus + vtxViaMinus);
110 }
111 
112 int Conv4HitsReco::ConversionCandidate(TVector3 &vtx, double &ptplus, double &ptminus) {
113  double m;
114  double q;
115  int nits = 0;
116 
117  int isNotValidBefore = ComputeMaxLimits() + ComputeMinLimits();
118  int isNotValidAfter = 0;
119  if (!isNotValidBefore) {
121  nits = mqFindByIteration(m, q);
122 
123  if (q > qMaxLimit || q < qMinLimit) {
124  isNotValidAfter = 1;
125  LogDebug("Conv4HitsReco") << ">>>>>>>> quad result not valid for q: qMin= " << qMinLimit << " q= " << q
126  << " qMax= " << qMaxLimit << "\n";
127  }
128  if (m > mMaxLimit || m < mMinLimit) {
129  isNotValidAfter = 1;
130  LogDebug("Conv4HitsReco") << ">>>>>>>> quad result not valid for m: mMin= " << mMinLimit << " m= " << m
131  << " mMax= " << mMaxLimit << "\n";
132  }
133 
134  ptminus = GetPtMinusFromParam(m);
135  ptplus = GetPtPlusFromParam(q);
136  minusCenter = vN + m * unitVn;
137  minusRadius = (hit4 - minusCenter).Mag();
138  plusCenter = vP + q * unitVp;
139  plusRadius = (hit1 - plusCenter).Mag();
141  vtx = convVtx;
142  }
143 
144  if (isNotValidBefore)
145  return 0;
147  return -1000;
149  return -2000;
150  if (isNotValidAfter)
151  return -1 * nits;
152  return nits;
153 }
154 
155 int Conv4HitsReco::mqFindByIteration(double &m, double &q) {
156  int maxIte = maxNumberOfIterations;
158  double edm = 1.;
159  double edq = 1.;
160  int i = 0;
161  while (((edq > err) || (edm > err)) && (i < maxIte)) {
162  SetLinSystCoeff(m, q);
163  double dm = GetDm();
164  double dq = GetDq();
165  /*
166  while( m+dm > mMaxLimit || m+dm < mMinLimit || q+dq > qMaxLimit || q+dq < qMinLimit ){
167 
168  LogDebug("Conv4HitsReco")<<">>>>>>>> Going outside limits, reducing increments \n";
169  dm=dm/2.;
170  dq=dq/2.;
171  }
172  */
173  m += dm;
174  q += dq;
175  edm = fabs(dm / m);
176  edq = fabs(dq / q);
177  LogDebug("Conv4HitsReco") << ">>>>>>>> Iteration " << i << " m: " << m << " q: " << q << " dm: " << dm
178  << " dq: " << dq << " edm: " << edm << " edq: " << edq << "\n";
179  i++;
180  }
181 
182  return i;
183 }
184 
186  // Q max limit
187  TVector3 vVminusHit2Orthogonal = (vV - hit2).Orthogonal();
188  TVector3 medianPointHit2V = 0.5 * (vV + hit2);
189  vQMaxLimit = GetIntersection(vVminusHit2Orthogonal, medianPointHit2V, unitVp, vP);
190  qMaxLimit = (vQMaxLimit - vP).Mag();
191 
192  // M max limit
193  TVector3 vVminusHit3Orthogonal = (vV - hit3).Orthogonal();
194  TVector3 medianPointHit3V = 0.5 * (vV + hit3);
195  vMMaxLimit = GetIntersection(vVminusHit3Orthogonal, medianPointHit3V, unitVn, vN);
196  mMaxLimit = (vMMaxLimit - vN).Mag();
197 
198  LogDebug("Conv4HitsReco") << " >>>>>> Limits: qMax= " << qMaxLimit << " ==>pt "
199  << GetPtFromParamAndHitPair(qMaxLimit, _pi) << " mMax= " << mMaxLimit << " ==>pt "
201 
202  return IsNotValidForPtLimit(mMaxLimit, qMaxLimit, ptLegMinCut, 100000.); //Max limit not applied here
203 }
204 
205 int Conv4HitsReco::IsNotValidForPtLimit(double m, double q, double ptmin, double ptmax) {
207  return 1;
209  return 1;
211  return 1;
213  return 1;
214  return 0;
215 }
216 
218  TVector3 hitAve = 0.25 * (hit1 + hit2 + hit3 + hit4);
219  if ((convVtx - hitAve).Mag() > maxDist)
220  return 1;
221  return 0;
222 }
223 
225  //Evaluate if quad is valid and compute min limits
226  if (((vV - vQMaxLimit).Cross(vMMaxLimit - vQMaxLimit)).Z() > 0.) {
227  //
228  //Quad is invalid
229  LogDebug("Conv4HitsReco") << " >>>>>> Quad is invalid\n";
230  return 1;
231  } else {
232  //
233  // Compute q and m Min limits
234  TVector3 vQMinLimit = GetIntersection(v1minus2, vMMaxLimit, unitVp, vP);
235  qMinLimit = (vQMinLimit - vP) * unitVp;
236  TVector3 vMMinLimit = GetIntersection(v3minus4, vQMaxLimit, unitVn, vN);
237  mMinLimit = (vMMinLimit - vN) * unitVn;
238  if (mMinLimit > mMaxLimit || qMinLimit > qMaxLimit) {
239  LogDebug("Conv4HitsReco") << " >>>>>> Quad is invalid. qMin= " << qMinLimit << " mMin= " << mMinLimit << "\n";
240  return 2;
241  }
242  if (IsNotValidForPtLimit(mMinLimit, qMinLimit, -1000., ptLegMaxCut)) { //Min limit not applied here
243  return 2;
244  }
245 
246  LogDebug("Conv4HitsReco") << " >>>>>> Quad is valid. qMin= " << qMinLimit << " mMin= " << mMinLimit << "\n";
247  return 0;
248  }
249 }
250 
251 int Conv4HitsReco::GuessStartingValues(double &m, double &q) {
252  /*
253  m = 0.5*(mMinLimit+mMaxLimit);
254  q = 0.5*(qMinLimit+qMaxLimit);
255  */
256 
257  m = mMaxLimit;
258  q = qMaxLimit;
259 
260  LogDebug("Conv4HitsReco") << " >>>>>> Starting values: q= " << q << " m= " << m << "\n";
261 
262  return 0;
263 }
264 
266  LogDebug("Conv4HitsReco") << " ======================================= "
267  << "\n"
268  << " Photon Vertex: " << vV.x() << "," << vV.y() << "," << vV.z() << " Hit1: " << hit1.x()
269  << "," << hit1.y() << "," << hit1.z() << " Hit2: " << hit2.x() << "," << hit2.y() << ","
270  << hit2.z() << " Hit3: " << hit3.x() << "," << hit3.y() << "," << hit3.z()
271  << " Hit4: " << hit4.x() << "," << hit4.y() << "," << hit4.z() << " N: " << vN.x() << ","
272  << vN.y() << "," << vN.z() << " P: " << vP.x() << "," << vP.y() << "," << vP.z()
273  << " P-N: " << vPminusN.x() << "," << vP.y() << "," << vP.z() << " n: " << unitVn.x() << ","
274  << unitVn.y() << "," << unitVn.z() << " p: " << unitVp.x() << "," << unitVp.y() << ","
275  << unitVp.z() << " eta: " << _eta << " pi: " << _pi << "\n";
276 }
Conv4HitsReco::nNV
double nNV
Definition: Conv4HitsReco.h:35
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
Conv4HitsReco::GetPtMinusFromParam
double GetPtMinusFromParam(double &)
Definition: Conv4HitsReco.cc:94
Conv4HitsReco::v1minus2
TVector3 v1minus2
Definition: Conv4HitsReco.h:21
zMuMuMuonUserData.alpha
alpha
zGenParticlesMatch = cms.InputTag(""),
Definition: zMuMuMuonUserData.py:9
edm
HLT enums.
Definition: AlignableModifier.h:19
zMuMuMuonUserData.beta
beta
Definition: zMuMuMuonUserData.py:10
Conv4HitsReco::GuessStartingValues
int GuessStartingValues(double &, double &)
Definition: Conv4HitsReco.cc:251
Conv4HitsReco::nPN
double nPN
Definition: Conv4HitsReco.h:31
Conv4HitsReco::GetDq
double GetDq()
Definition: Conv4HitsReco.cc:14
CustomPhysics_cfi.gamma
gamma
Definition: CustomPhysics_cfi.py:17
Conv4HitsReco::convVtx
TVector3 convVtx
Definition: Conv4HitsReco.h:48
Conv4HitsReco::hit3
TVector3 hit3
Definition: Conv4HitsReco.h:15
Conv4HitsReco::qMaxLimit
double qMaxLimit
Definition: Conv4HitsReco.h:42
Conv4HitsReco::IsNotValidForVtxPosition
int IsNotValidForVtxPosition(double &)
Definition: Conv4HitsReco.cc:217
Conv4HitsReco::maxNumberOfIterations
int maxNumberOfIterations
Definition: Conv4HitsReco.h:53
TtSemiLepEvtBuilder_cfi.disc
disc
Definition: TtSemiLepEvtBuilder_cfi.py:60
Conv4HitsReco::T0
double T0
Definition: Conv4HitsReco.h:63
Conv4HitsReco::GetDm
double GetDm()
Definition: Conv4HitsReco.cc:10
Conv4HitsReco::hit2
TVector3 hit2
Definition: Conv4HitsReco.h:16
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
Conv4HitsReco::pPN
double pPN
Definition: Conv4HitsReco.h:30
Conv4HitsReco::ComputeMaxLimits
int ComputeMaxLimits()
Definition: Conv4HitsReco.cc:185
PVValHelper::eta
Definition: PVValidationHelpers.h:69
Conv4HitsReco::GetPtFromParamAndHitPair
double GetPtFromParamAndHitPair(double &, double &)
Definition: Conv4HitsReco.cc:90
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
Conv4HitsReco::_eta
double _eta
Definition: Conv4HitsReco.h:36
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
Conv4HitsReco::SetLinSystCoeff
void SetLinSystCoeff(double, double)
Definition: Conv4HitsReco.cc:18
p2
double p2[4]
Definition: TauolaWrapper.h:90
Conv4HitsReco::GetIntersection
TVector3 GetIntersection(TVector3 &, TVector3 &, TVector3 &, TVector3 &)
Definition: Conv4HitsReco.cc:82
Conv4HitsReco::plusCenter
TVector3 plusCenter
Definition: Conv4HitsReco.h:46
Conv4HitsReco::ConversionCandidate
int ConversionCandidate(TVector3 &, double &, double &)
Definition: Conv4HitsReco.cc:112
Conv4HitsReco::v3minus4
TVector3 v3minus4
Definition: Conv4HitsReco.h:20
Conv4HitsReco::mqFindByIteration
int mqFindByIteration(double &, double &)
Definition: Conv4HitsReco.cc:155
Tm
Definition: Tm.h:13
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Conv4HitsReco::pNV
double pNV
Definition: Conv4HitsReco.h:34
Conv4HitsReco::vP
TVector3 vP
Definition: Conv4HitsReco.h:23
Conv4HitsReco::GetPtPlusFromParam
double GetPtPlusFromParam(double &)
Definition: Conv4HitsReco.cc:96
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
Conv4HitsReco::ComputeMinLimits
int ComputeMinLimits()
Definition: Conv4HitsReco.cc:224
Conv4HitsReco::vQMaxLimit
TVector3 vQMaxLimit
Definition: Conv4HitsReco.h:41
Conv4HitsReco::qFromM
double qFromM(double)
Definition: Conv4HitsReco.cc:65
Conv4HitsReco::minusCenter
TVector3 minusCenter
Definition: Conv4HitsReco.h:47
Conv4HitsReco::hit4
TVector3 hit4
Definition: Conv4HitsReco.h:14
symbols.dm
dm
Definition: symbols.py:66
p1
double p1[4]
Definition: TauolaWrapper.h:89
submitPVResolutionJobs.q
q
Definition: submitPVResolutionJobs.py:84
Conv4HitsReco::hit1
TVector3 hit1
Definition: Conv4HitsReco.h:17
Conv4HitsReco::O0
double O0
Definition: Conv4HitsReco.h:64
Conv4HitsReco::iterationStopRelThreshold
double iterationStopRelThreshold
Definition: Conv4HitsReco.h:52
Conv4HitsReco::qFromM_print
std::string qFromM_print(double m)
Definition: Conv4HitsReco.cc:44
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
Conv4HitsReco::Tq
double Tq
Definition: Conv4HitsReco.h:63
Conv4HitsReco.h
Conv4HitsReco::plusRadius
double plusRadius
Definition: Conv4HitsReco.h:49
TtFullHadJetPartonMatch_cfi.maxDist
maxDist
Definition: TtFullHadJetPartonMatch_cfi.py:35
Conv4HitsReco::Oq
double Oq
Definition: Conv4HitsReco.h:64
Conv4HitsReco::Om
double Om
Definition: Conv4HitsReco.h:64
Conv4HitsReco::_pi2
double _pi2
Definition: Conv4HitsReco.h:39
muonTiming_cfi.ptmax
ptmax
Definition: muonTiming_cfi.py:22
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:18
Conv4HitsReco::ptLegMinCut
double ptLegMinCut
Definition: Conv4HitsReco.h:55
Conv4HitsReco::Dump
void Dump()
Definition: Conv4HitsReco.cc:265
Conv4HitsReco::mMinLimit
double mMinLimit
Definition: Conv4HitsReco.h:45
Conv4HitsReco::vNminusV
TVector3 vNminusV
Definition: Conv4HitsReco.h:26
CosmicsPD_Skims.radius
radius
Definition: CosmicsPD_Skims.py:135
ptmin
double ptmin
Definition: HydjetWrapper.h:84
Conv4HitsReco::unitVn
TVector3 unitVn
Definition: Conv4HitsReco.h:27
Conv4HitsReco::pn
double pn
Definition: Conv4HitsReco.h:29
Conv4HitsReco::vMMaxLimit
TVector3 vMMaxLimit
Definition: Conv4HitsReco.h:40
Conv4HitsReco::vPminusN
TVector3 vPminusN
Definition: Conv4HitsReco.h:24
Conv4HitsReco::ptLegMaxCut
double ptLegMaxCut
Definition: Conv4HitsReco.h:56
BeamSpotPI::Z
Definition: BeamSpotPayloadInspectorHelper.h:32
Conv4HitsReco::GetMinusCenter
TVector3 GetMinusCenter(double &)
Definition: Conv4HitsReco.cc:75
Conv4HitsReco::vV
TVector3 vV
Definition: Conv4HitsReco.h:13
Conv4HitsReco::PN2
double PN2
Definition: Conv4HitsReco.h:33
Conv4HitsReco::IsNotValidForPtLimit
int IsNotValidForPtLimit(double, double, double, double)
Definition: Conv4HitsReco.cc:205
Conv4HitsReco::mMaxLimit
double mMaxLimit
Definition: Conv4HitsReco.h:43
Conv4HitsReco::vN
TVector3 vN
Definition: Conv4HitsReco.h:22
Conv4HitsReco::GetPlusCenter
TVector3 GetPlusCenter(double &)
Definition: Conv4HitsReco.cc:70
Conv4HitsReco::minusRadius
double minusRadius
Definition: Conv4HitsReco.h:50
Conv4HitsReco::unitVp
TVector3 unitVp
Definition: Conv4HitsReco.h:28
Conv4HitsReco::_eta2
double _eta2
Definition: Conv4HitsReco.h:38
Conv4HitsReco::GetConvVertexFromParams
TVector3 GetConvVertexFromParams(double &, double &)
Definition: Conv4HitsReco.cc:98
Conv4HitsReco::_pi
double _pi
Definition: Conv4HitsReco.h:37
Conv4HitsReco::maxVtxDistance
double maxVtxDistance
Definition: Conv4HitsReco.h:54
Conv4HitsReco::qMinLimit
double qMinLimit
Definition: Conv4HitsReco.h:44