CMS 3D CMS Logo

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