CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/TrackingTools/PatternTools/src/TwoTrackMinimumDistance.cc

Go to the documentation of this file.
00001 #include "TrackingTools/PatternTools/interface/TwoTrackMinimumDistance.h"
00002 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00003 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h" 
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 #include "FWCore/Utilities/interface/Exception.h"
00006 #include "MagneticField/Engine/interface/MagneticField.h"
00007 
00008 using namespace std;
00009 
00010 namespace {
00011   inline GlobalPoint mean ( pair<GlobalPoint, GlobalPoint> pr ) {
00012     return GlobalPoint ( 0.5*(pr.first.basicVector() + pr.second.basicVector()) );
00013   }
00014 
00015   inline double dist ( pair<GlobalPoint, GlobalPoint> pr ) {
00016     return ( pr.first - pr.second ).mag();
00017   }
00018 }
00019 
00020 double TwoTrackMinimumDistance::firstAngle() const
00021 {
00022   if (!status_)
00023     throw cms::Exception("TrackingTools/PatternTools","TwoTrackMinimumDistance::could not compute track crossing. Check status before calling this method!");
00024   switch ( theCharge ) {
00025    case (hh): return theTTMDhh.firstAngle(); break;
00026    case (hl): return theTTMDhl.firstAngle(); break;
00027    case (ll): return theTTMDll.firstAngle(); break;
00028   }
00029   return 0;
00030 }
00031 
00032 double TwoTrackMinimumDistance::secondAngle() const
00033 {
00034   if (!status_)
00035     throw cms::Exception("TrackingTools/PatternTools","TwoTrackMinimumDistance::could not compute track crossing. Check status before calling this method!");
00036   switch ( theCharge ) {
00037    case (hh): return theTTMDhh.secondAngle(); break;
00038    case (hl): return theTTMDhl.secondAngle(); break;
00039    case (ll): return theTTMDll.secondAngle(); break;
00040   }
00041   return 0;
00042 }
00043 
00044 
00045 pair <double, double> TwoTrackMinimumDistance::pathLength() const
00046 {
00047   if (!status_)
00048     throw cms::Exception("TrackingTools/PatternTools","TwoTrackMinimumDistance::could not compute track crossing. Check status before calling this method!");
00049   switch ( theCharge ) {
00050    case (hh): return theTTMDhh.pathLength(); break;
00051    case (hl): return theTTMDhl.pathLength(); break;
00052    case (ll): return theTTMDll.pathLength(); break;
00053   }
00054   return std::pair<double,double>(0,0);
00055 }
00056 
00057 pair<GlobalPoint, GlobalPoint> TwoTrackMinimumDistance::points() const
00058 {
00059   if (!status_)
00060     throw cms::Exception("TrackingTools/PatternTools","TwoTrackMinimumDistance::could not compute track crossing. Check status before calling this method!");
00061   return points_;
00062 }
00063 
00064 bool
00065 TwoTrackMinimumDistance::calculate(const TrajectoryStateOnSurface & sta, 
00066                                 const TrajectoryStateOnSurface & stb) 
00067 {
00068   return calculate ( sta.globalParameters(), stb.globalParameters() );
00069 }
00070 
00071 
00072 bool
00073 TwoTrackMinimumDistance::calculate(const FreeTrajectoryState & sta, 
00074                                 const FreeTrajectoryState & stb) 
00075 {
00076 //  pair<GlobalPoint, GlobalPoint> ret  = theIniAlgo.points ( sta, stb );
00077   return calculate ( sta.parameters(), stb.parameters() );
00078 }
00079 
00080 bool
00081 TwoTrackMinimumDistance::calculate(const GlobalTrajectoryParameters & sta,
00082                                 const GlobalTrajectoryParameters & stb)
00083 {
00084   bool isHelixA = (sta.magneticField().inTesla(sta.position()).z() != 0.)
00085     && sta.charge() != 0.;
00086   bool isHelixB = (stb.magneticField().inTesla(stb.position()).z() != 0.)
00087     && stb.charge() != 0.;
00088   if (! isHelixA && ! isHelixB) {
00089     status_ = pointsLineLine(sta, stb);
00090   } else if ( isHelixA && isHelixB ) {
00091     status_ = pointsHelixHelix(sta, stb);
00092   } else {
00093     status_ = pointsHelixLine(sta, stb);
00094   }
00095   return status_;
00096 }
00097 
00098 bool
00099 TwoTrackMinimumDistance::pointsLineLine(const GlobalTrajectoryParameters & sta,
00100                                 const GlobalTrajectoryParameters & stb)
00101 {
00102   theCharge = ll;
00103   if (theTTMDll.calculate(sta, stb)) return false;
00104   points_ = theTTMDll.points();
00105   return true;
00106 }
00107 
00108 bool
00109 TwoTrackMinimumDistance::pointsHelixLine(const GlobalTrajectoryParameters & sta,
00110                                 const GlobalTrajectoryParameters & stb)
00111 {
00112   theCharge = hl;
00113   if (theTTMDhl.calculate(sta, stb, 0.000001)) return false;
00114   points_ = theTTMDhl.points();
00115   return true;
00116 }
00117 
00118 bool
00119 TwoTrackMinimumDistance::pointsHelixHelix(const GlobalTrajectoryParameters & sta,
00120                                 const GlobalTrajectoryParameters & stb)
00121 {
00122   if ( ( sta.position() - stb.position() ).mag2() < 1e-7f &&
00123        ( sta.momentum() - stb.momentum() ).mag2() < 1e-7f &&
00124        sta.charge()==stb.charge()
00125        )
00126   {
00127     edm::LogWarning ( "TwoTrackMinimumDistance") << "comparing track with itself!";
00128   };
00129 
00130   theCharge = hh;
00131   if ( theModus == FastMode )
00132   {
00133     // first we try directly - in FastMode only ...
00134     if ( !(theTTMDhh.calculate ( sta, stb, .0001 )) )
00135     {
00136       points_ = theTTMDhh.points();
00137       return true;
00138     };
00139   };
00140 
00141   // okay. did not work. so we use CAIR, and then TTMD again.
00142   bool cairStat = theIniAlgo.calculate ( sta, stb );
00143   
00144   if (!cairStat) { // yes. CAIR may fail.
00145     edm::LogWarning ( "TwoTrackMinimumDistance" ) << "Computation HelixHelix::CAIR failed.";
00146     if ( theModus == SlowMode ) { // we can still try ttmd here.
00147       if ( !(theTTMDhh.calculate ( sta, stb, .0001 )) ) {
00148         points_ = theTTMDhh.points();
00149         return true;
00150       }
00151     };
00152     // we can try with more sloppy settings
00153     if ( !(theTTMDhh.calculate ( sta, stb, .1 )) ) {
00154         points_ = theTTMDhh.points();
00155         return true;
00156       }
00157     return false;
00158     edm::LogWarning ( "TwoTrackMinimumDistance" ) << "TwoTrackMinimumDistanceHelixHelix failed";
00159   };
00160 
00161   pair<GlobalTrajectoryParameters, GlobalTrajectoryParameters >
00162         ini = theIniAlgo.trajectoryParameters();
00163 
00164   pair<GlobalPoint, GlobalPoint> inip ( ini.first.position(), 
00165       ini.second.position() );
00166   bool isFirstALine = ini.first.charge() == 0. || ini.first.magneticField().inTesla(ini.first.position()).z() == 0.;
00167   bool isSecondALine = ini.second.charge() == 0. || ini.second.magneticField().inTesla(ini.second.position()).z() == 0.;
00168   bool gotDist = false;
00169   if (!isFirstALine && !isSecondALine) gotDist = theTTMDhh.calculate ( ini.first, ini.second, .0001 );
00170   else if ( isFirstALine && isSecondALine) gotDist = theTTMDll.calculate ( ini.first, ini.second );
00171   else gotDist = theTTMDhl.calculate ( ini.first, ini.second, .0001 );
00172   if ( gotDist ) {
00173     points_ = inip;
00174   } else {
00175     points_ = theTTMDhh.points();
00176     // if we are still worse than CAIR, we use CAIR results.
00177     if ( dist ( points_ ) > dist ( inip ) ) points_ = inip;
00178   };
00179   return true;
00180 }
00181 
00182 
00183 GlobalPoint TwoTrackMinimumDistance::crossingPoint() const
00184 {
00185   return mean ( points_ );
00186 }
00187 
00188 
00189 float TwoTrackMinimumDistance::distance() const
00190 {
00191   return dist ( points_ );
00192 }