ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/TrackingTools/PatternTools/src/TwoTrackMinimumDistance.cc
Revision: 1.1
Committed: Fri Nov 25 16:38:25 2011 UTC (13 years, 5 months ago) by econte
Content type: text/plain
Branch: MAIN
CVS Tags: TBD2011, TBD_2011, HEAD
Log Message:
new IPHC alignment

File Contents

# User Rev Content
1 econte 1.1 #include "TrackingTools/PatternTools/interface/TwoTrackMinimumDistance.h"
2     #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
3     #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
4     #include "FWCore/MessageLogger/interface/MessageLogger.h"
5     #include "FWCore/Utilities/interface/Exception.h"
6     #include "MagneticField/Engine/interface/MagneticField.h"
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    
20     double TwoTrackMinimumDistance::firstAngle() const
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    
32     double TwoTrackMinimumDistance::secondAngle() const
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
65     TwoTrackMinimumDistance::calculate(const TrajectoryStateOnSurface & sta,
66     const TrajectoryStateOnSurface & stb)
67     {
68     return calculate ( sta.globalParameters(), stb.globalParameters() );
69     }
70    
71    
72     bool
73     TwoTrackMinimumDistance::calculate(const FreeTrajectoryState & sta,
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
81     TwoTrackMinimumDistance::calculate(const GlobalTrajectoryParameters & sta,
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
98     TwoTrackMinimumDistance::pointsLineLine(const GlobalTrajectoryParameters & sta,
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
108     TwoTrackMinimumDistance::pointsHelixLine(const GlobalTrajectoryParameters & sta,
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
118     TwoTrackMinimumDistance::pointsHelixHelix(const GlobalTrajectoryParameters & sta,
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    
176     GlobalPoint TwoTrackMinimumDistance::crossingPoint() const
177     {
178     return mean ( points_ );
179     }
180    
181    
182     float TwoTrackMinimumDistance::distance() const
183     {
184     return dist ( points_ );
185     }