ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitCommon/MathTools/src/HelixIntersector.cc
Revision: 1.2
Committed: Wed Nov 12 18:22:13 2008 UTC (16 years, 5 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_008pre2, Mit_008pre1, Mit_006b, Mit_006a, Mit_006
Changes since 1.1: +5 -3 lines
Log Message:
Silenced HelixIntersector output (negative rho coordinates warning)

File Contents

# User Rev Content
1 bendavid 1.2 // $Id: HelixIntersector.cc,v 1.1 2008/09/17 04:01:50 loizides Exp $
2 loizides 1.1
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 bendavid 1.2 // if ( rho < 0 ) {
95     // printf("Cylindrical coordinates supplied with negative Rho\n");
96     // printf("Radius = %5f, Helicity = %5f, D0 = %5f, Rho=%5f\n", Radius(), Helicity(), D0(), rho);
97     // }
98 loizides 1.1 fCenter.SetXYZ(rho*cos(phi),rho*sin(phi),z);
99    
100     // Original code ....
101     //fCenter.SetRhoPhiZ(Radius() + Helicity() * D0(),
102     // Helicity() * M_PI/2.0 + Phi0(),0.0);
103    
104     //if (testMode) {
105     // cout << "Center Test: "
106     // << Center() + Radius()*Center().Unit() << " "
107     // << Position(M_PI*Radius()/fabs(SinTheta())) << " DIFF="
108     // << ( ( Center() + Radius()*Center().Unit())
109     // - Position(M_PI*Radius()/fabs(SinTheta()))).perp()
110     // << endl;
111     //}
112     }
113    
114     void HelixIntersector::TrackParams::SetLocation(TVector3& location)
115     {
116     // rotation about circle center
117     double deltaphi = M_PI - fCenter.Angle(location-fCenter);
118    
119     // check for backward locations
120     if (fTrkMom.Dot(location)<0.0)
121     deltaphi = - deltaphi;
122    
123    
124     // calculate arc length to and z of intersection
125     fArcLen = Radius()*deltaphi/SinTheta();
126     fZAtISec = Z0() + Radius()*deltaphi*CotTheta();
127    
128     //if (testMode) {
129     // cout << "Arclen test: " << Position(fArcLen) << " "
130     // << location << " DIFF=" << (location-Position(fArcLen)).perp()
131     // << endl;
132     //}
133    
134     // calculate momentum of track at intersection
135     fMomentum = Direction(fArcLen) * fTrkMom.Mag();
136     }
137    
138     HelixIntersector::Intersection::Intersection(const TVectorD *tr1, const TVector3 *momentum1,
139     const TVectorD *tr2, const TVector3 *momentum2) :
140     fDeltaZ(0.0),
141     fTrk0 (tr1,momentum1),
142     fTrk1 (tr2,momentum2)
143     {
144     fTrks[0] = &fTrk0;
145     fTrks[1] = &fTrk1;
146     }
147    
148     void HelixIntersector::Intersection::SetLocation(TVector3& loc1, TVector3& loc2)
149     {
150     // calculate tracks specific quantities
151     fTrk0.SetLocation(loc1);
152     fTrk1.SetLocation(loc2);
153    
154     // combined variables
155     fDeltaZ = fTrk0.fZAtISec - fTrk1.fZAtISec;
156     fLocation.SetZ((fTrk0.fZAtISec + fTrk1.fZAtISec)/2.0);
157     fMomentum = fTrk0.fMomentum + fTrk1.fMomentum;
158    
159     //if (testMode) {
160     // cout << "Final Test: " << fTrk0.Position(fTrk0.fArcLen) << " "
161     // << fTrk1.Position(fTrk1.fArcLen) << " "
162     // << "DIFF= " << (fTrk0.Position(fTrk0.fArcLen)-
163     // fTrk1.Position(fTrk1.fArcLen)).perp() << " "
164     // << "LOCDIFF= " << (loc1-loc2).perp() << endl;
165     //}
166     }