CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DcxTrackCandidatesToTracks.cc
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // File and Version Information:
3 // $Id: DcxTrackCandidatesToTracks.cc,v 1.11 2012/01/31 16:41:42 wmtan Exp $
4 //
5 // Description:
6 // Class Implementation for |DcxTrackCandidatesToTracks|
7 //
8 // Environment:
9 // Software developed for the BaBar Detector at the SLAC B-Factory.
10 //
11 // Author List:
12 // S. Wagner
13 //
14 //------------------------------------------------------------------------
15 #include <cmath>
16 #include "RecoTracker/RoadSearchHelixMaker/interface/DcxTrackCandidatesToTracks.hh"
17 #include "RecoTracker/RoadSearchHelixMaker/interface/Dcxmatinv.hh"
18 #include "RecoTracker/RoadSearchHelixMaker/interface/DcxFittedHel.hh"
19 #include "RecoTracker/RoadSearchHelixMaker/interface/DcxHit.hh"
20 #include "RecoTracker/RoadSearchHelixMaker/interface/Dcxprobab.hh"
21 
23 
25 
27 
28 // #include "TrackingTools/TrajectoryParametrization/interface/PerigeeTrajectoryParameters.h"
29 // #include "TrackingTools/TrajectoryParametrization/interface/PerigeeTrajectoryError.h"
30 
32 
34 
35 using std::cout;
36 using std::endl;
37 using std::ostream;
38 
39 double DcxTrackCandidatesToTracks::epsilon = 0.000000001;
40 double DcxTrackCandidatesToTracks::half_pi=1.570796327;
41 
42 //constructors
43 DcxTrackCandidatesToTracks::DcxTrackCandidatesToTracks(){
44  edm::LogInfo("RoadSearch") << "DcxTrackCandidatesToTracks null constructor - does nothing" ;}
45 
46 //points
47 DcxTrackCandidatesToTracks::DcxTrackCandidatesToTracks(std::vector<DcxHit*> &listohits, reco::TrackCollection &output, const MagneticField *field)
48 {
49  double rmin=1000.0;
50  int ntrk=0;
51  for (unsigned int i=0; i<listohits.size(); ++i) {
52  if (!listohits[i]->stereo()){
53  double rhit=sqrt(listohits[i]->x()*listohits[i]->x()+listohits[i]->y()*listohits[i]->y());
54  if ( (rhit<rmin) ){rmin=rhit;}
55  }
56  for (unsigned int j=0; j<listohits.size(); ++j) {
57  for (unsigned int k=0; k<listohits.size(); ++k) {
58  if ( ( ( 1==listohits[i]->Layer())||( 3==listohits[i]->Layer()) )
59  && ( ( 9==listohits[j]->Layer())||(11==listohits[j]->Layer()) )
60  && ( (17==listohits[k]->Layer())||(19==listohits[k]->Layer()) ) ){
61  makecircle(listohits[i]->x(),listohits[i]->y(),listohits[j]->x(),listohits[j]->y(),
62  listohits[k]->x(),listohits[k]->y());
63  double xc=xc_cs; double yc=yc_cs; double rc=rc_cs;
64  double d0=sqrt(xc*xc+yc*yc)-rc;
65 // double dmax=sqrt(xc*xc+yc*yc)+rc; // not used
66  double s3=s3_cs;
67  if ( (fabs(s3)>0.1) ){
68  double d0h=-s3*d0;
69  double phi0h=atan2(yc,xc)+s3*half_pi;
70  double omegah=-s3/rc;
71  DcxHel make_a_circ(d0h,phi0h,omegah,0.0,0.0);// make_a_hel.print();
72  std::vector<DcxHit*> axlist;
73  check_axial( listohits, axlist, make_a_circ);
74  int n_axial=axlist.size();
75  for (unsigned int l=0; l<listohits.size(); ++l) {
76  for (unsigned int m=0; m<listohits.size(); ++m) {
77  if ( ((2==listohits[l]->Layer())||(4==listohits[l]->Layer())) &&
78  ((12==listohits[m]->Layer())||(10==listohits[m]->Layer())) ){
79  double z1=find_z_at_cyl(make_a_circ,listohits[l]);
80  double z2=find_z_at_cyl(make_a_circ,listohits[m]);
81  double l1=find_l_at_z(z1,make_a_circ,listohits[l]);
82  double l2=find_l_at_z(z2,make_a_circ,listohits[m]);
83  double tanl=(z1-z2)/(l1-l2); double z0=z1-tanl*l1;
84  DcxHel make_a_hel(d0h,phi0h,omegah,z0,tanl);// make_a_hel.print();
85  std::vector<DcxHit*> outlist = axlist;
86  check_stereo( listohits, outlist, make_a_hel);
87  int n_stereo=outlist.size()-n_axial;
88  if ((n_stereo>2)&&(n_axial>6)){
89  DcxFittedHel real_fit(outlist,make_a_hel);// real_fit.FitPrint();
90  if (real_fit.Prob()>0.001){
91  ntrk++;
92  edm::LogInfo("RoadSearch") << "ntrk xprob pt nax nst d0 phi0 omega z0 tanl " << ntrk << " " << real_fit.Prob()
93  << " " << real_fit.Pt() << " " << n_axial << " " << n_stereo
94  << " " << real_fit.D0() << " " << real_fit.Phi0() << " " << real_fit.Omega()
95  << " " << real_fit.Z0() << " " << real_fit.Tanl() ;
96 
97 
98  AlgebraicVector5 paraVector;
99  paraVector[0] = real_fit.Omega();
100  paraVector[1] = half_pi - atan(real_fit.Tanl());
101  paraVector[2] = real_fit.Phi0();
102  paraVector[3] = - real_fit.D0();
103  paraVector[4] = real_fit.Z0();
104 
105  PerigeeTrajectoryParameters params(paraVector);
106 
108 
109  GlobalPoint reference(0,0,0);
110 
111  TrajectoryStateClosestToPoint tscp(params,
112  real_fit.Pt(),
113  error,
114  reference,
115  field);
116 
117  GlobalPoint v = tscp.theState().position();
118  math::XYZPoint pos( v.x(), v.y(), v.z() );
119  GlobalVector p = tscp.theState().momentum();
120  math::XYZVector mom( p.x(), p.y(), p.z() );
121 
122  output.push_back(reco::Track(real_fit.Chisq(),
123  outlist.size()-5,
124  pos,
125  mom,
126  tscp.charge(),
127  tscp.theState().curvilinearError()));
128 
129  for (unsigned int n=0; n<outlist.size(); ++n){outlist[n]->SetUsedOnHel(ntrk);}
130  }else{
131  }
132  }
133  }
134  }
135  }
136  }
137  }
138  }
139  }
140  }
141 }//endof DcxTrackCandidatesToTracks
142 
143 //destructor
144 DcxTrackCandidatesToTracks::~DcxTrackCandidatesToTracks( ){ }//endof ~DcxTrackCandidatesToTracks
145 
146 void DcxTrackCandidatesToTracks::makecircle(double x1_cs, double y1_cs, double x2_cs,
147  double y2_cs, double x3_cs, double y3_cs){
148  x1t_cs=x1_cs-x3_cs; y1t_cs=y1_cs-y3_cs; r1s_cs=x1t_cs*x1t_cs+y1t_cs*y1t_cs;
149  x2t_cs=x2_cs-x3_cs; y2t_cs=y2_cs-y3_cs; r2s_cs=x2t_cs*x2t_cs+y2t_cs*y2t_cs;
150  double rho=x1t_cs*y2t_cs-x2t_cs*y1t_cs;
153  fac_cs=sqrt(x1t_cs*x1t_cs+y1t_cs*y1t_cs);
154  xc_cs=x2_cs+y1t_cs*rc_cs/fac_cs;
155  yc_cs=y2_cs-x1t_cs*rc_cs/fac_cs;
156  }else{
157  fac_cs=0.5/rho;
158  xc_cs=fac_cs*(r1s_cs*y2t_cs-r2s_cs*y1t_cs);
159  yc_cs=fac_cs*(r2s_cs*x1t_cs-r1s_cs*x2t_cs);
160  rc_cs=sqrt(xc_cs*xc_cs+yc_cs*yc_cs); xc_cs+=x3_cs; yc_cs+=y3_cs;
161  }
162  s3_cs=0.0;
163  f1_cs=x1_cs*yc_cs-y1_cs*xc_cs; f2_cs=x2_cs*yc_cs-y2_cs*xc_cs;
164  f3_cs=x3_cs*yc_cs-y3_cs*xc_cs;
165  if ((f1_cs<0.0)&&(f2_cs<0.0)&&(f3_cs<0.0))s3_cs=1.0;
166  if ((f1_cs>0.0)&&(f2_cs>0.0)&&(f3_cs>0.0))s3_cs=-1.0;
167 }
168 
169 void DcxTrackCandidatesToTracks::check_axial( std::vector<DcxHit*> &listohits, std::vector<DcxHit*> &outlist, DcxHel make_a_hel){
170  for (unsigned int i=0; i<listohits.size(); ++i) {
171  DcxHit* try_me = listohits[i];
172  if ((!try_me->stereo())&&(!try_me->GetUsedOnHel())){
173  double doca = try_me->residual(make_a_hel);
174 // double len = make_a_hel.Doca_Len();
175 // edm::LogInfo("RoadSearch") << "In check_axial, doca(mmm) len xh yh " << 10000.0*doca << " " << len
176 // << " " << make_a_hel.Xh(len) << " " << make_a_hel.Yh() ;
177  if (fabs(doca)<0.100)outlist.push_back(try_me);
178  }
179  }
180 }
181 
182 void DcxTrackCandidatesToTracks::check_stereo( std::vector<DcxHit*> &listohits, std::vector<DcxHit*> &outlist, DcxHel make_a_hel){
183  for (unsigned int i=0; i<listohits.size(); ++i) {
184  DcxHit* try_me = listohits[i];
185  if ((try_me->stereo())&&(!try_me->GetUsedOnHel())){
186  double doca = try_me->residual(make_a_hel);
187 // double len = make_a_hel.Doca_Len();
188 // edm::LogInfo("RoadSearch") << "In check_stereo, doca(mmm) len xh yh " << 10000.0*doca << " " << len
189 // << " " << make_a_hel.Xh(len) << " " << make_a_hel.Yh(len) ;
190  if (fabs(doca)<0.100)outlist.push_back(try_me);
191  }
192  }
193 }
194 
195 double DcxTrackCandidatesToTracks::find_z_at_cyl(DcxHel he, DcxHit* hi){
196  zint=-1000.0;
197  x0_wr=hi->x(); y0_wr=hi->y(); sx_wr=hi->wx(); sy_wr=hi->wy();
198  xc_cl=he.Xc(); yc_cl=he.Yc(); r_cl=fabs(1.0/he.Omega());
199  double cx=x0_wr-xc_cl; double cy=y0_wr-yc_cl;
200  double a=sx_wr*sx_wr+sy_wr*sy_wr; double b=2.0*(sx_wr*cx+sy_wr*cy);
201  double c=(cx*cx+cy*cy-r_cl*r_cl);
202  double bsq=b*b; double fac=4.0*a*c; double ta=2.0*a;
203  if (fac < bsq){
204  double sfac=sqrt(bsq-fac); double z1=-(b-sfac)/ta; double z2=-(b+sfac)/ta;
205  if (fabs(z1) < fabs(z2)){
206  zint=z1;
207  }else{
208  zint=z2;
209  }
210  }
211  return zint;
212 }
213 double DcxTrackCandidatesToTracks::find_l_at_z(double zi, DcxHel he, DcxHit* hi){
214  double omega=he.Omega(), d0=he.D0();
215  double xl = hi->x()+zi*hi->wx()/hi->wz();
216  double yl = hi->y()+zi*hi->wy()/hi->wz();
217  double rl = sqrt(xl*xl+yl*yl);
218  double orcsq=(1.0+d0*omega)*(1.0+d0*omega);
219  double orlsq=(rl*omega)*(rl*omega);
220  double cphil=(1.0+orcsq-orlsq)/(2.0*(1.0+d0*omega));
221  double phil1=acos(cphil);
222  double l1=fabs(phil1/omega);
223  return l1;
224 }
int i
Definition: DBlmapReader.cc:9
Definition: DDAxes.h:10
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
T sqrt(T t)
Definition: SSEVec.h:46
int j
Definition: DBlmapReader.cc:9
int k[5][pyjets_maxn]
ROOT::Math::SVector< double, 5 > AlgebraicVector5
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
tuple cout
Definition: gather_cfg.py:121
const double epsilon
Definition: DDAxes.h:10
mathSSE::Vec4< T > v