ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitCommon/MathTools/src/HelixIntersector.cc
Revision: 1.1
Committed: Wed Sep 17 04:01:50 2008 UTC (16 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_005, Mit_004
Log Message:
Moved MitVertex contents to MitCommon. MitVertex therefore is obsolute and should not be touched anymore.

File Contents

# User Rev Content
1 loizides 1.1 // $Id: HelixIntersector.cc,v 1.2 2008/09/04 13:55:30 loizides Exp $
2    
3     #include "MitCommon/MathTools/interface/HelixIntersector.h"
4     #include <iostream>
5    
6     using namespace std;
7     using namespace mithep;
8    
9     // Local constants, macros & typedefs ...
10     //static const int testMode = 0;
11    
12     //--------------------------------------------------------------------------------------------------
13     // Constructor
14     //--------------------------------------------------------------------------------------------------
15     HelixIntersector::HelixIntersector(const TVectorD *tr1, const TVector3 *momentum1,
16     const TVectorD *tr2, const TVector3 *momentum2) :
17     fISec0(tr1,momentum1,tr2,momentum2),
18     fISec1(tr1,momentum1,tr2,momentum2)
19     {
20     // short cuts
21     TrackParams &trk0 = fISec0.fTrk0;
22     TrackParams &trk1 = fISec0.fTrk1;
23     fISecs[0] = &fISec0;
24     fISecs[1] = &fISec1;
25    
26     // Calculate intersections and test for existence
27    
28     // line connecting the two centers
29     TVector3 connector = trk1.Center() - trk0.Center();
30    
31     // intersection positions relative to connector
32     double para = (connector.Mag2()+trk0.Radius()*trk0.Radius()
33     -trk1.Radius()*trk1.Radius())/(2.0*connector.Mag());
34     double perpsqr = trk0.Radius()*trk0.Radius() - para*para;
35    
36     // intersection exist if perp is real -> perp^2 is positive
37     fHasIntersections = (perpsqr >= 0.0);
38    
39     // fill Intersection objects appropriately
40     if (fHasIntersections) {
41    
42     // vector perpendicular to connector (sign doesn't matter)
43     TVector3 perpvec(connector.y(),-connector.x(),0.0);
44     perpvec.SetMag(sqrt(perpsqr));
45    
46     // make both combinations
47     for (int i = 0; i < 2; i++) {
48     // the intersection
49     fISecs[i]->fLocation =
50     trk0.Center() + para * connector.Unit() + double(2*i-1) * perpvec;
51    
52     // calculate tracks/intersection specific quantities for real intersections both tracks have
53     // the same point
54     fISecs[i]->SetLocation(fISecs[i]->fLocation,fISecs[i]->fLocation);
55     }
56    
57     if (fabs(fISecs[0]->DeltaZ()) > fabs(fISecs[1]->DeltaZ())) {
58     Intersection* tmp = fISecs[1];
59     fISecs[1] = fISecs[0];
60     fISecs[0] = tmp;
61     }
62    
63     }
64     else {
65     // no intersection so we pick points of closest approach
66     TVector3 locTrk0 = trk0.Center() + trk0.Radius() * connector.Unit();
67     TVector3 locTrk1 = trk1.Center() - trk1.Radius() * connector.Unit();
68    
69     // mean is the "nominal" location
70     fISecs[0]->fLocation = (locTrk0 + locTrk1) * 0.5;
71    
72     // for closest approach points actually on the tracks are used calculate tracks/intersection
73     // specific quantities
74     fISecs[0]->SetLocation(locTrk0,locTrk1);
75     }
76    
77     }
78    
79     //--------------------------------------------------------------------------------------------------
80     // Destructor
81     //--------------------------------------------------------------------------------------------------
82     HelixIntersector::~HelixIntersector()
83     {
84     }
85    
86     HelixIntersector::TrackParams::TrackParams(const TVectorD *trk, const TVector3 *momentum) :
87     Helix ((*trk)(0),(*trk)(1),(*trk)(2),(*trk)(3),Angle((*trk)(4))),
88     fTrkMom(*momentum)
89     {
90     // Calculate center of r-phi plane circles
91     double rho = Radius() + Helicity() * D0();
92     double phi = Helicity() * M_PI/2.0 + Phi0();
93     double z = 0.0;
94     if ( rho < 0 )
95     printf("Cylindrical coordinates supplied with negative Rho\n");
96     fCenter.SetXYZ(rho*cos(phi),rho*sin(phi),z);
97    
98     // Original code ....
99     //fCenter.SetRhoPhiZ(Radius() + Helicity() * D0(),
100     // Helicity() * M_PI/2.0 + Phi0(),0.0);
101    
102     //if (testMode) {
103     // cout << "Center Test: "
104     // << Center() + Radius()*Center().Unit() << " "
105     // << Position(M_PI*Radius()/fabs(SinTheta())) << " DIFF="
106     // << ( ( Center() + Radius()*Center().Unit())
107     // - Position(M_PI*Radius()/fabs(SinTheta()))).perp()
108     // << endl;
109     //}
110     }
111    
112     void HelixIntersector::TrackParams::SetLocation(TVector3& location)
113     {
114     // rotation about circle center
115     double deltaphi = M_PI - fCenter.Angle(location-fCenter);
116    
117     // check for backward locations
118     if (fTrkMom.Dot(location)<0.0)
119     deltaphi = - deltaphi;
120    
121    
122     // calculate arc length to and z of intersection
123     fArcLen = Radius()*deltaphi/SinTheta();
124     fZAtISec = Z0() + Radius()*deltaphi*CotTheta();
125    
126     //if (testMode) {
127     // cout << "Arclen test: " << Position(fArcLen) << " "
128     // << location << " DIFF=" << (location-Position(fArcLen)).perp()
129     // << endl;
130     //}
131    
132     // calculate momentum of track at intersection
133     fMomentum = Direction(fArcLen) * fTrkMom.Mag();
134     }
135    
136     HelixIntersector::Intersection::Intersection(const TVectorD *tr1, const TVector3 *momentum1,
137     const TVectorD *tr2, const TVector3 *momentum2) :
138     fDeltaZ(0.0),
139     fTrk0 (tr1,momentum1),
140     fTrk1 (tr2,momentum2)
141     {
142     fTrks[0] = &fTrk0;
143     fTrks[1] = &fTrk1;
144     }
145    
146     void HelixIntersector::Intersection::SetLocation(TVector3& loc1, TVector3& loc2)
147     {
148     // calculate tracks specific quantities
149     fTrk0.SetLocation(loc1);
150     fTrk1.SetLocation(loc2);
151    
152     // combined variables
153     fDeltaZ = fTrk0.fZAtISec - fTrk1.fZAtISec;
154     fLocation.SetZ((fTrk0.fZAtISec + fTrk1.fZAtISec)/2.0);
155     fMomentum = fTrk0.fMomentum + fTrk1.fMomentum;
156    
157     //if (testMode) {
158     // cout << "Final Test: " << fTrk0.Position(fTrk0.fArcLen) << " "
159     // << fTrk1.Position(fTrk1.fArcLen) << " "
160     // << "DIFF= " << (fTrk0.Position(fTrk0.fArcLen)-
161     // fTrk1.Position(fTrk1.fArcLen)).perp() << " "
162     // << "LOCDIFF= " << (loc1-loc2).perp() << endl;
163     //}
164     }