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  if ((sta.magneticField().inTesla(sta.position()).z() == 0.)||
85  (stb.magneticField().inTesla(stb.position()).z() == 0.)) {
86  status_ = pointsLineLine(sta, stb);
87  } else if ( sta.charge() != 0. && stb.charge() != 0. ) {
88  status_ = pointsHelixHelix(sta, stb);
89  } else if ( sta.charge() == 0. && stb.charge() == 0. ) {
90  status_ = pointsLineLine(sta, stb);
91  } else {
92  status_ = pointsHelixLine(sta, stb);
93  }
94  return status_;
95 }
96 
97 bool
99  const GlobalTrajectoryParameters & stb)
100 {
101  theCharge = ll;
102  if (theTTMDll.calculate(sta, stb)) return false;
103  points_ = theTTMDll.points();
104  return true;
105 }
106 
107 bool
109  const GlobalTrajectoryParameters & stb)
110 {
111  theCharge = hl;
112  if (theTTMDhl.calculate(sta, stb, 0.000001)) return false;
113  points_ = theTTMDhl.points();
114  return true;
115 }
116 
117 bool
119  const GlobalTrajectoryParameters & stb)
120 {
121  if ( ( sta.position() - stb.position() ).mag2() < 1e-7f &&
122  ( sta.momentum() - stb.momentum() ).mag2() < 1e-7f &&
123  sta.charge()==stb.charge()
124  )
125  {
126  edm::LogWarning ( "TwoTrackMinimumDistance") << "comparing track with itself!";
127  };
128 
129  theCharge = hh;
130  if ( theModus == FastMode )
131  {
132  // first we try directly - in FastMode only ...
133  if ( !(theTTMDhh.calculate ( sta, stb, .0001 )) )
134  {
135  points_ = theTTMDhh.points();
136  return true;
137  };
138  };
139 
140  // okay. did not work. so we use CAIR, and then TTMD again.
141  bool cairStat = theIniAlgo.calculate ( sta, stb );
142 
143  if (!cairStat) { // yes. CAIR may fail.
144  edm::LogWarning ( "TwoTrackMinimumDistance" ) << "Computation HelixHelix::CAIR failed.";
145  if ( theModus == SlowMode ) { // we can still try ttmd here.
146  if ( !(theTTMDhh.calculate ( sta, stb, .0001 )) ) {
147  points_ = theTTMDhh.points();
148  return true;
149  }
150  };
151  // we can try with more sloppy settings
152  if ( !(theTTMDhh.calculate ( sta, stb, .1 )) ) {
153  points_ = theTTMDhh.points();
154  return true;
155  }
156  return false;
157  edm::LogWarning ( "TwoTrackMinimumDistance" ) << "TwoTrackMinimumDistanceHelixHelix failed";
158  };
159 
160  pair<GlobalTrajectoryParameters, GlobalTrajectoryParameters >
161  ini = theIniAlgo.trajectoryParameters();
162 
163  pair<GlobalPoint, GlobalPoint> inip ( ini.first.position(),
164  ini.second.position() );
165  if ( theTTMDhh.calculate ( ini.first, ini.second, .0001 ) ) {
166  points_ = inip;
167  } else {
168  points_ = theTTMDhh.points();
169  // if we are still worse than CAIR, we use CAIR results.
170  if ( dist ( points_ ) > dist ( inip ) ) points_ = inip;
171  };
172  return true;
173 }
174 
175 
177 {
178  return mean ( points_ );
179 }
180 
181 
183 {
184  return dist ( points_ );
185 }
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
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Definition: DDAxes.h:10
bool pointsHelixLine(const GlobalTrajectoryParameters &sta, const GlobalTrajectoryParameters &stb)
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)