CMS 3D CMS Logo

TwoTrackMinimumDistance.cc
Go to the documentation of this file.
7 
8 using namespace std;
9 
10 namespace {
11  inline GlobalPoint mean(pair<GlobalPoint, GlobalPoint> pr) {
12  return GlobalPoint(0.5 * (pr.first.basicVector() + pr.second.basicVector()));
13  }
14 
15  inline double dist(pair<GlobalPoint, GlobalPoint> pr) { return (pr.first - pr.second).mag(); }
16 } // namespace
17 
19  if (!status_)
20  throw cms::Exception(
21  "TrackingTools/PatternTools",
22  "TwoTrackMinimumDistance::could not compute track crossing. Check status before calling this method!");
23  switch (theCharge) {
24  case (hh):
25  return theTTMDhh.firstAngle();
26  break;
27  case (hl):
28  return theTTMDhl.firstAngle();
29  break;
30  case (ll):
31  return theTTMDll.firstAngle();
32  break;
33  }
34  return 0;
35 }
36 
38  if (!status_)
39  throw cms::Exception(
40  "TrackingTools/PatternTools",
41  "TwoTrackMinimumDistance::could not compute track crossing. Check status before calling this method!");
42  switch (theCharge) {
43  case (hh):
44  return theTTMDhh.secondAngle();
45  break;
46  case (hl):
47  return theTTMDhl.secondAngle();
48  break;
49  case (ll):
50  return theTTMDll.secondAngle();
51  break;
52  }
53  return 0;
54 }
55 
56 pair<double, double> TwoTrackMinimumDistance::pathLength() const {
57  if (!status_)
58  throw cms::Exception(
59  "TrackingTools/PatternTools",
60  "TwoTrackMinimumDistance::could not compute track crossing. Check status before calling this method!");
61  switch (theCharge) {
62  case (hh):
63  return theTTMDhh.pathLength();
64  break;
65  case (hl):
66  return theTTMDhl.pathLength();
67  break;
68  case (ll):
69  return theTTMDll.pathLength();
70  break;
71  }
72  return std::pair<double, double>(0, 0);
73 }
74 
75 pair<GlobalPoint, GlobalPoint> TwoTrackMinimumDistance::points() const {
76  if (!status_)
77  throw cms::Exception(
78  "TrackingTools/PatternTools",
79  "TwoTrackMinimumDistance::could not compute track crossing. Check status before calling this method!");
80  return points_;
81 }
82 
84  return calculate(sta.globalParameters(), stb.globalParameters());
85 }
86 
88  // pair<GlobalPoint, GlobalPoint> ret = theIniAlgo.points ( sta, stb );
89  return calculate(sta.parameters(), stb.parameters());
90 }
91 
93  bool isHelixA = (sta.magneticField().inTesla(sta.position()).z() != 0.) && sta.charge() != 0.;
94  bool isHelixB = (stb.magneticField().inTesla(stb.position()).z() != 0.) && stb.charge() != 0.;
95  if (!isHelixA && !isHelixB) {
96  status_ = pointsLineLine(sta, stb);
97  } else if (isHelixA && isHelixB) {
98  status_ = pointsHelixHelix(sta, stb);
99  } else {
100  status_ = pointsHelixLine(sta, stb);
101  }
102  return status_;
103 }
104 
106  const GlobalTrajectoryParameters& stb) {
107  theCharge = ll;
108  if (theTTMDll.calculate(sta, stb))
109  return false;
110  points_ = theTTMDll.points();
111  return true;
112 }
113 
115  const GlobalTrajectoryParameters& stb) {
116  theCharge = hl;
117  if (theTTMDhl.calculate(sta, stb, 0.000001))
118  return false;
119  points_ = theTTMDhl.points();
120  return true;
121 }
122 
124  const GlobalTrajectoryParameters& stb) {
125  if ((sta.position() - stb.position()).mag2() < 1e-7f && (sta.momentum() - stb.momentum()).mag2() < 1e-7f &&
126  sta.charge() == stb.charge()) {
127  edm::LogWarning("TwoTrackMinimumDistance") << "comparing track with itself!";
128  };
129 
130  theCharge = hh;
131  if (theModus == FastMode) {
132  // first we try directly - in FastMode only ...
133  if (!(theTTMDhh.calculate(sta, stb, .0001))) {
134  points_ = theTTMDhh.points();
135  return true;
136  };
137  };
138 
139  // okay. did not work. so we use CAIR, and then TTMD again.
140  bool cairStat = theIniAlgo.calculate(sta, stb);
141 
142  if (!cairStat) { // yes. CAIR may fail.
143  edm::LogWarning("TwoTrackMinimumDistance") << "Computation HelixHelix::CAIR failed.";
144  if (theModus == SlowMode) { // we can still try ttmd here.
145  if (!(theTTMDhh.calculate(sta, stb, .0001))) {
146  points_ = theTTMDhh.points();
147  return true;
148  }
149  };
150  // we can try with more sloppy settings
151  if (!(theTTMDhh.calculate(sta, stb, .1))) {
152  points_ = theTTMDhh.points();
153  return true;
154  }
155  return false;
156  edm::LogWarning("TwoTrackMinimumDistance") << "TwoTrackMinimumDistanceHelixHelix failed";
157  };
158 
159  pair<GlobalTrajectoryParameters, GlobalTrajectoryParameters> ini = theIniAlgo.trajectoryParameters();
160 
161  pair<GlobalPoint, GlobalPoint> inip(ini.first.position(), ini.second.position());
162  bool isFirstALine = ini.first.charge() == 0. || ini.first.magneticField().inTesla(ini.first.position()).z() == 0.;
163  bool isSecondALine = ini.second.charge() == 0. || ini.second.magneticField().inTesla(ini.second.position()).z() == 0.;
164  bool gotDist = false;
165  if (!isFirstALine && !isSecondALine)
166  gotDist = theTTMDhh.calculate(ini.first, ini.second, .0001);
167  else if (isFirstALine && isSecondALine)
168  gotDist = theTTMDll.calculate(ini.first, ini.second);
169  else
170  gotDist = theTTMDhl.calculate(ini.first, ini.second, .0001);
171  if (gotDist) {
172  points_ = inip;
173  } else {
174  if (!isFirstALine && !isSecondALine)
175  points_ = theTTMDhh.points();
176  else if (isFirstALine && isSecondALine)
177  points_ = theTTMDll.points();
178  else
179  points_ = theTTMDhl.points();
180  // if we are still worse than CAIR, we use CAIR results.
181  if (dist(points_) > dist(inip))
182  points_ = inip;
183  };
184  return true;
185 }
186 
188 
189 float TwoTrackMinimumDistance::distance() const { return dist(points_); }
TrajectoryStateOnSurface.h
TwoTrackMinimumDistance::secondAngle
double secondAngle() const
Definition: TwoTrackMinimumDistance.cc:37
MagneticField::inTesla
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
FreeTrajectoryState.h
MessageLogger.h
SiStripPI::mean
Definition: SiStripPayloadInspectorHelper.h:169
TwoTrackMinimumDistance::crossingPoint
GlobalPoint crossingPoint() const override
Definition: TwoTrackMinimumDistance.cc:187
TwoTrackMinimumDistance::pointsHelixHelix
bool pointsHelixHelix(const GlobalTrajectoryParameters &sta, const GlobalTrajectoryParameters &stb)
Definition: TwoTrackMinimumDistance.cc:123
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
GlobalTrajectoryParameters::position
GlobalPoint position() const
Definition: GlobalTrajectoryParameters.h:60
GlobalTrajectoryParameters::charge
TrackCharge charge() const
Definition: GlobalTrajectoryParameters.h:72
TwoTrackMinimumDistance::firstAngle
double firstAngle() const
Definition: TwoTrackMinimumDistance.cc:18
TwoTrackMinimumDistance::pointsHelixLine
bool pointsHelixLine(const GlobalTrajectoryParameters &sta, const GlobalTrajectoryParameters &stb)
Definition: TwoTrackMinimumDistance.cc:114
TwoTrackMinimumDistance.h
TwoTrackMinimumDistance::calculate
bool calculate(const TrajectoryStateOnSurface &sta, const TrajectoryStateOnSurface &stb) override
Definition: TwoTrackMinimumDistance.cc:83
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
GlobalTrajectoryParameters
Definition: GlobalTrajectoryParameters.h:15
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Point3DBase< float, GlobalTag >
GlobalTrajectoryParameters::momentum
GlobalVector momentum() const
Definition: GlobalTrajectoryParameters.h:65
TwoTrackMinimumDistance::points
std::pair< GlobalPoint, GlobalPoint > points() const override
Definition: TwoTrackMinimumDistance.cc:75
edm::LogWarning
Definition: MessageLogger.h:141
sipixeldigitoraw
Definition: SiPixelDigiToRaw.cc:38
FreeTrajectoryState::parameters
const GlobalTrajectoryParameters & parameters() const
Definition: FreeTrajectoryState.h:79
TwoTrackMinimumDistance::pathLength
std::pair< double, double > pathLength() const
Definition: TwoTrackMinimumDistance.cc:56
TwoTrackMinimumDistance::pointsLineLine
bool pointsLineLine(const GlobalTrajectoryParameters &sta, const GlobalTrajectoryParameters &stb)
Definition: TwoTrackMinimumDistance.cc:105
mag2
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Definition: Basic3DVectorLD.h:124
MagneticField.h
TwoTrackMinimumDistance::distance
float distance() const override
Definition: TwoTrackMinimumDistance.cc:189
AlignmentTrackSelector_cfi.theCharge
theCharge
Definition: AlignmentTrackSelector_cfi.py:20
std
Definition: JetResolutionObject.h:76
FreeTrajectoryState
Definition: FreeTrajectoryState.h:27
Exception
Definition: hltDiff.cc:246
Exception.h
GlobalTrajectoryParameters::magneticField
const MagneticField & magneticField() const
Definition: GlobalTrajectoryParameters.h:106
TrajectoryStateOnSurface::globalParameters
const GlobalTrajectoryParameters & globalParameters() const
Definition: TrajectoryStateOnSurface.h:64
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37