CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
CgemHitOnTrack.cxx
Go to the documentation of this file.
1// $Id: CgemHitOnTrack.cxx,v 1.4 2018/01/04 00:11:49 huangzhen Exp $
2//
4#include "CLHEP/Units/PhysicalConstants.h"
5#include "CLHEP/Matrix/Vector.h"
6#include "CLHEP/Matrix/SymMatrix.h"
7#include "CLHEP/Matrix/Matrix.h"
8#include "TROOT.h"
9#include "CLHEP/Geometry/Point3D.h"
10
11#include "MdcGeom/Constants.h"
12#include "MdcGeom/BesAngle.h"
13// MdcGeom needed to verify if hit is inside of chamber...
14// and to find the trajectory describing the hit, i.e. wire
15#include "MdcGeom/MdcLayer.h"
16#include "MdcGeom/MdcSWire.h"
17#include "TrkBase/TrkPoca.h"
18#include "TrkBase/TrkDifTraj.h"
19#include "TrkBase/TrkRep.h"
20#include "TrkBase/TrkSimpTraj.h"
21#include "TrkBase/TrkRecoTrk.h"
23#include "GaudiKernel/ISvcLocator.h"
24#include "GaudiKernel/Bootstrap.h"
25#include "GaudiKernel/IInterface.h"
26#include "GaudiKernel/Kernel.h"
27#include "GaudiKernel/Service.h"
28#include "GaudiKernel/SvcFactory.h"
29#include "GaudiKernel/IDataProviderSvc.h"
31#include "TrackUtil/Helix.h"
32using std::cout;
33using std::endl;
34
35const CgemGeomSvc* CgemHitOnTrack::_cgemGeomSvc = NULL;
36const CgemCalibFunSvc* CgemHitOnTrack::_cgemCalibFunSvc = NULL;
37//-------------
38// Constructors
39//-------------
40CgemHitOnTrack::CgemHitOnTrack(//const TrkFundHit& fundHit,
41 const RecCgemCluster& baseHit,
42 double t0)
43: TrkHitOnTrk(NULL,10.e-4),
44 //: TrkHitOnTrk(&fundHit,10.e-4),
45 //_hitTraj(baseHit.hitTraj()), //yzhang FIXME add hitTraj of this Cluster ?
46 //_fitTime(baseHit.rawTime()-t0*1e-9),
47 _fitTime(t0*1e-9),//yzhang FIXME
48 _dHit(&baseHit)
49{
50 ICgemGeomSvc* icgemGeomSvc = NULL;
51 StatusCode sc = Gaudi::svcLocator()->service("CgemGeomSvc", icgemGeomSvc);
52 CgemGeomSvc* cgemGeomSvc = dynamic_cast<CgemGeomSvc*> (icgemGeomSvc);
53 if(sc==StatusCode::SUCCESS && cgemGeomSvc!=NULL){
54 _clusterr = cgemGeomSvc->getCgemLayer(baseHit.getlayerid())->getMiddleROfGapD()/10.;//r[baseHit.getlayerid()];
55 //std::cout<<__FILE__<<" "<<__LINE__<<" _clusterr "<<_clusterr<<std::endl;
56 }else{
57 _clusterr = -999;
58 //std::cout<<__FILE__<<" "<<__LINE__<<" _clusterr Could not find CgemGeomSvc "<<_clusterr<<std::endl;
59 }
60 //hitTraj not implemented
61 // need to flag somehow that that we haven't computed things yet...
62 // now, we know that _drift[0] is for ambig <0, and _drift[1] is ambig >0
63 // and _drift is signed according to ambig. Thus _drift[0] should be -tive
64 // and _drift[1] should be +tive. To indicate this are not yet initialized,
65 // put 'impossible' values here...
66 //_drift[0] = +9999;
67 //_drift[1] = -9999;
68 setHitResid(-21212121.0);
69 setHitRms( 0.02 );
70 //setHitLen(0.5 * baseHit.layer()->zLength());//yzhang FIXME
71 setFltLen(0.);
72 //layer
73 double length = cgemGeomSvc->getCgemLayer(baseHit.getlayerid())->getLengthOfCgemLayer();
74 //_startLen = hitTraj()->lowRange() - 5.;//lowRange?
75 //_endLen = hitTraj()->hiRange() + 5.;
76 _startLen = -1.*length/2. - 5.;
77 _endLen = length/2. + 5.;
78
79 //double r[3] = {7.9838 ,12.5104 ,16.7604};//cm
80}
81
83CgemHitOnTrack::clone(TrkRep *rep, const TrkDifTraj *trkTraj) const
84{
85 return new CgemHitOnTrack(*this,rep,trkTraj);
86}
87//CgemHitOnTrack::CgemHitOnTrack(const TrkFundHit *fundHit, int ambig, double fittime,
88// int layer, int wire)
89// : TrkHitOnTrk(fundHit,10.e-4),
90// _ambig(ambig), _fitTime(fittime)
91//{
92// cout << "using old CgemHitOnTrack constructor..." << endl;
93
94// IService* ser;
95// StatusCode sc = Gaudi::svcLocator()->getService("MdcGeomSvc",ser);
96// if (!sc.isSuccess())
97// cout <<"CgemHitOnTrack::Could not open Geometry Service"<<endl;
98// MdcGeomSvc *m_gmSvc = dynamic_cast<MdcGeomSvc*> (ser);
99// if(!m_gmSvc) cout <<"CgemHitOnTrack::Could not open Geometry Service"<<endl;
100
101
102
103// _drift[0] = +9999;
104// _drift[1] = -9999;
105// _hitTraj = gblEnv->getMdc()->getMdcLayer(layer)->makeHitTrajInGlobalCoords(wire);
106// _hitTraj = m_gmSvc->Layer(layer)->makeHitTrajInGlobalCoords(wire);
107// setHitResid(-21212121.0);
108// setHitRms( 0.01 );
109// setHitLen(2.);
110// setFltLen(0.);
111// _startLen = hitTraj()->lowRange() - 5.;
112// _endLen = hitTraj()->hiRange() + 5.;
113//}
114
116 const TrkDifTraj* trkTraj, const RecCgemCluster *hb)
117: TrkHitOnTrk(hot,newRep,trkTraj)
118{
119 _hitTraj = hot._hitTraj;
120 _fitTime = hot._fitTime;
121 _drift[0] = hot._drift[0];
122 _drift[1] = hot._drift[1];
123 _startLen = hot._startLen;
124 _endLen = hot._endLen;
125 _dHit = (hb==0?hot._dHit:hb);
126 _clusterr = hot._clusterr;
127}
128
130{ ; }
131
132void
134{
135 //_fitTime= _dHit->rawTime()-t0*1e-9;
136 _fitTime = t0*1e-9;//FIXME
137}
138
139double
141{
142 double dca = -9999.;
143 if ( getParentRep() == 0 ) {
144 // cout << "no parent rep" << endl;
145 return dca;
146 }
147 // WARNING: cannot use the internal _poca, as it lags one iteration
148 // behind the fit... therfore use _EXTERNAL_ residual
149 //if (isActive()) { // FIXME: currently can only use 'resid()' if isActive..
150 // dca = resid()+drift();
151 //} else {
152 // TrkPoca poca(getParentRep()->traj(), fltLen(), *hitTraj(), hitLen(),
153 // _tolerance);
154 // if (poca.status().success()) dca = poca.doca();
155 //}
156 //yzhang FIXME
157 return dca;
158}
159
160double
162{
163 static Hep3Vector dir;
164 static HepPoint3D pos;
165 if (getParentRep() == 0) return 0.;
166 getParentRep()->traj().getInfo(fltLen(), pos, dir);
167
168 return BesAngle(dir.phi() - pos.phi());
169}
170
171double
173{
174 static Hep3Vector dir;
175 static HepPoint3D pos;
176 if (getParentRep() == 0) return 0.;
177 getParentRep()->traj().getInfo(fltLen(), pos, dir);
178
179 return entranceAngle(pos, dir);
180}
181
182double
183CgemHitOnTrack::entranceAngle(const HepPoint3D pos, const Hep3Vector dir) const
184{
185 double angle = EntranceAngle(dir.phi() - _dHit->getrecphi());
186 return angle;
187}
188
189//unsigned
190//CgemHitOnTrack::layerNumber() const
191//{
192// return layernumber();
193//}
194
195double
197{
198 return getParentRep()==0?0:Constants::pi/2-getParentRep()->traj().direction(fltLen()).theta();
199}
200
202CgemHitOnTrack::updateMeasurement(const TrkDifTraj* traj, bool maintainAmb)
203{
204 //std::cout<<__FILE__<<" "<<__LINE__<<" WARNING CgemHitOnTrack::updateMeasurement not implemented "<<std::endl;
205 traj = (traj!=0?traj:&(getParentRep()->traj()));//track traj
206 //TrkErrCode status=updatePoca(traj,maintainAmb);
207 //if (status.failure()) {
208 // std::cout<<" ErrMsg(warning) " << "CgemHitOnTrack::updateMeasurement failed " << status << std::endl;
209 // return status;
210 //}
211 //assert (_poca!=0);
212 double dca=-999;//FIXME _poca->doca();
213 ////yzhang FIXME
214 bool forceIteration = true;//(maintainAmb&&ambig()!=0)?false:updateAmbiguity(dca);
215 //if( whatView()==0) {
216 BesAngle phiCluster = BesAngle(_dHit->getrecphi());//-pi 2 pi
217 double flt=0;
218 const HepVector par = getParentRep()->traj().localTrajectory(0.,flt)->parameters()->parameter();
219 //cout<<par<<endl;
220 double d0 = par[0];
221 double phi0 = par[1];
222 double omega = par[2];
223 double radius = fabs(omega)<0.00001 ? -9999: 1./fabs(omega);
224 double l = d0 + radius;
225 double r = _clusterr;
226 double xc = l * cos(phi0 - Constants::halfPi);
227 double yc = l * sin(phi0 - Constants::halfPi);
228 double phi_center = atan2(yc,xc);
229
230 double cosPhi = (radius * radius + l * l - r * r) / (2 * radius * l);
231 if(cosPhi < -1 || cosPhi > 1) return TrkErrCode(TrkErrCode::fail);
232 double dPhi = phi_center - acos(cosPhi) - (phi0-Constants::halfPi);
233 //std::cout<<__FILE__<<" "<<__LINE__<<" radius "<<radius<<" l "<<l<<" r "<<r<<" xc "<<xc<<" yc "<<yc <<" cosPhi "<<cosPhi<<" phi center "<<phi_center<<" phi0 - pi/2 "<<phi0-Constants::halfPi<<" "<<std::endl;
234 BesAngle phi(dPhi);
235 //if(dPhi < -M_PI) dPhi += 2 * M_PI;
236
237 double x = radius*sin(dPhi) - (radius + d0)*sin(phi0);
238 double y = -1.*radius*cos(dPhi) + (radius + d0)*sin(phi0);
239
240 //double phiTrack = atan2(y,x);
241 BesAngle phiTrack = BesAngle(atan2(y,x));
242
243 //std::cout<<__FILE__<<" "<<__LINE__<<" phiCluster "<<phiCluster<<" phiTrack "<<phiTrack<<" x "<<x<<" y "<<y<<std::endl;
244 dca = (phiCluster - phiTrack).rad();
245 //}
246 //return TrkErrCode(TrkErrCode::fail);//not used for fit
247 return TrkErrCode(TrkErrCode::succeed);//not used for fit
248 //TrkErrCode(TrkErrCode::succeed, 11, "Ambiguity flipped");
249}
250
251void
252CgemHitOnTrack::updateCorrections()
253{
254 std::cout<<__FILE__<<" "<<__LINE__<<" WARNING CgemHitOnTrack::updateCorrections not implemented "<<std::endl;
255 const TrkRep* tkRep = getParentRep();
256 assert(tkRep != 0);
257 static HepPoint3D pos; static Hep3Vector dir;
258 _trkTraj->getInfo(fltLen(), pos, dir);
259
260 // for bes3 cosmic test
261 //int wireAmb = wireAmbig();
262 double tof = tkRep->arrivalTime(fltLen());
263 // at this point, since dcaToWire is computed, _ambig must be either -1 or +1
264 //assert( ambig() == -1 || ambig() == 1 );
265 //double eAngle = entranceAngle(pos, dir);//2011-11-22
266 //double dAngle = Constants::pi/2 - dir.theta();
267 //double z = pos.z();
268 // note the special case for INCOMING tracks:
269 // wire left of track implies hit on the right side of wire
270 //int wireAmb= fabs(eAngle)<Constants::pi/2?_ambig:-_ambig; //yzhang delete 2012-07-17
271
272 // provide the underlying hit with the *external* information
273 // needed to compute the drift distance, i.e. those numbers that
274 // the hit cannot figure out by itself...
275 double dist = -999;//FIXME
276 //_dHit->driftDist(tof, wireAmb, eAngle, dAngle, z);
277 //<<" dir "<<dir<<" pos "<<pos
278 //assert(dist>0);//yzhang 2011-12-05 delete
279
280 //FIXME//_fitTime = _dHit->driftTime(tof,z);
281 //
282 //std::cout<<" CgemHitOnTrack ("<<layernumber()<<","<<wire()<<") "<<mdcHit()->isCosmicFit()<<" fltLen "<<fltLen() <<" eAngle "<<eAngle<<" ambig "<<ambig()<<" wireAmb "<<wireAmb<<" tof "<<tof<<" dd "<<dist<<" dt "<<_fitTime<<std::endl;
283 //_drift[ambig()<0?0:1] = ambig() * dist;
284 //assert( driftCurrent() );
285
286 double newSig = -999;//_dHit->sigma(dist, wireAmb, eAngle, dAngle, z);
287
288 //assert(newSig>0);//yzhang 2011-12-05 delete
289 setHitRms(newSig);
290}
291
292bool
293CgemHitOnTrack::timeResid(double &t, double &tErr) const
294{
295 //double v = driftVelocity();
296 //if (v <= 0) return false;
297 //t = (fabs(drift())-fabs(dcaToWire()))/v;
298 t = -999;//FIXME
299 //tErr= hitRms()/v;
300 return true;
301}
302
303bool
304CgemHitOnTrack::timeAbsolute(double &t, double &tErr) const
305{
306 double tresid(-1.0);
307 if(timeResid(tresid,tErr)){
308 // add back the track time
309 t = tresid + getParentRep()->parentTrack()->trackT0();
310 return true;
311 } else
312 return false;
313}
314
317{
318 //enum TrkViewInfo {noView=-1,xyView=0, zView, bothView };
320 if(_dHit->getflag()==0) view = TrkEnums::TrkViewInfo(0);
321 else if(_dHit->getflag()==1) view = TrkEnums::TrkViewInfo(1);
322 else if(_dHit->getflag()==2) view = TrkEnums::TrkViewInfo(2);
323
324 return view;
325}
326
327/*
328 int
329 CgemHitOnTrack::layernumber() const
330 {
331 return _dHit->layernumber();
332 }
333
334 const MdcLayer*
335 CgemHitOnTrack::layer() const
336 {
337 return _dHit->getlayerid();
338 }
339
340 int
341 CgemHitOnTrack::wire() const
342 {
343 return _dHit->wirenumber();
344 }
345
346 int
347 CgemHitOnTrack::whichView() const
348 {
349 return _dHit->whichView();
350 }
351
352 double
353 CgemHitOnTrack::rawTime() const
354 {
355 return _dHit->rawTime();
356 }
357*/
358
359 double
361 {
362 return _dHit->getenergydeposit();
363 }
364
365const Trajectory*
367{
368 //return _hitTraj;
369 std::cout<<__FILE__<<" "<<__LINE__<<" CgemHitOnTrack::hitTraj() not implemented, return NULL "<<std::endl;
370 return NULL;
371}
372
373// Replace underlying hit pointer (base class doesn't own it)
374
375void
377{
378 _dHit = newBase;
379}
380
381/*
382 CgemHitOnTrack::isBeyondEndflange() const {
383 std::cout<<__FILE__<<" "<<__LINE__
384 <<" hitLen "<<hitLen()
385 <<" startLen "<<_startLen
386 <<" endLen "<<_endLen
387 << std::endl;
388 return (hitLen() < _startLen || hitLen() > _endLen);
389 }
390 */
391
392void CgemHitOnTrack::print(std::ostream&) const{
393 std::cout<<" CgemHOT id "<<_dHit->getclusterid()<<" layer "<<_dHit->getlayerid()<<" recphi "<< _dHit->getrecphi()<<" recv "<< _dHit->getrecv()<<" recz "<<_dHit->getRecZ() << std::endl;
394}
395
397//CgemHitOnTrack::getFitStuff(HepVector &derivs, double &deltaChi ) const
398CgemHitOnTrack::getFitStuff(HepVector &derivs, HepVector &derivs2, double & sigma1, double & sigma2, double &deltaChi1, double &deltaChi2 ) const
399{
400 //std::cout<<__FILE__<<" "<<__LINE__<<" CgemHitOnTrack::getFitStuff implemented"<<std::endl;
401 if (_poca==0 || _poca->status().failure()) {
403 }
404 double vec_phi = _dHit->getrecphi() ;
405 double vec_z = _dHit->getRecZ() ;
406 double flt=0;
407 HepVector trkpar = getParentRep()->traj().localTrajectory(0.,flt)->parameters()->parameter(); //get para??????
408 IMdcUtilitySvc* m_mdcUtilitySvc;
409 Gaudi::svcLocator()->service("MdcUtilitySvc",m_mdcUtilitySvc);
410 if (m_mdcUtilitySvc == NULL) cout<< " Can not load MdcUtilitySvc"<<endl;
411 HepVector trkparbes = m_mdcUtilitySvc->patPar2BesPar(trkpar);
412 trkparbes[2]=-trkparbes[2]; // modification for the reversed sign in TrackUtil/Helix
413
414 HepPoint3D pivot(0., 0., 0.);
415 Helix cgem_helix_0(pivot, trkparbes);
416 HepMatrix J_dmdx(2,3,0), J_dxda(3,5,0), J(2,5,0) ;
417 HepSymMatrix V(2,0), W(2,0) ;
418 HepVector a_new(5), dm(2);
419 J_dmdx(1,1)= 1. ;
420 J_dmdx(2,3)= 1. ;
421 int layer = _dHit->getlayerid() ;
422 double rl, R, x_reso, v_reso, a_stero;
423
424 if(layer==0) { rl=79.838/10. ; R=87.5026/10.; x_reso=0.1372/10.; v_reso=0.1273/10.;a_stero=45.94*3.1415926/180;}
425 else if (layer==1) { rl=125.104/10. ; R=132.7686/10.; x_reso=0.1476/10.;v_reso=0.1326/10.;a_stero=31.10*3.1415926/180;}
426 else { rl=167.604/10.; R=175.2686/10.; x_reso=0.1412/10.;v_reso=0.1378/10.;a_stero=32.99*3.1415926/180;} //cm
427 double d_phi = cgem_helix_0.IntersectCylinder(rl); //const can only call const
428 HepPoint3D pos = cgem_helix_0.x(d_phi);
429 double x = pos.x();
430 double y = pos.y();
431 double z = pos.z();
432 double r2 = x*x+y*y;
433 double tmp_phi = atan2(y, x); //[-pi,pi), return azimuthal angle
434 double dphi = vec_phi - tmp_phi;
435 if(dphi < -M_PI) dphi += 2*M_PI;
436 if(dphi >= M_PI) dphi -= 2*M_PI;
437 dm[0]=-dphi*rl*sin(vec_phi);
438 dm[1]=vec_z-z;
439 J_dxda=cgem_helix_0.delXDelA(d_phi); //3X5; derivative of x,y,z to 5 paras
440 J=J_dmdx*J_dxda;
441 for (int i=0;i<5;i++){
442 derivs2[i]=J(1,i) ;
443 derivs2[i+5]=J(2,i) ;
444 }
445 V(1,1)=rl*rl/R/R*sin(vec_phi)*sin(vec_phi)*x_reso*x_reso;
446 V(2,1)=rl/R*sin(vec_phi)/tan(a_stero)*x_reso*x_reso;
448 W=V;
449
450 int ifail=99;
451 V.invert(ifail);
452 if (ifail) {
454 }
455 J=V*J;
456
457 for (int i=0;i<5;i++){
458 derivs[i]=J(1,i) ;
459 derivs[i+5]=J(2,i) ;
460 }
461 assert (_trkTraj == &(getParentRep()->traj()));
462 sigma1=sqrt(W(1,1));
463 sigma2=sqrt(W(2,2));
464 deltaChi1=dm[0]; //V(1,2)=V(2,1)
465 deltaChi2=dm[1];
466
468 // FIXME: I wish I could tell poca to NOT iterate
469 // and ONLY compute the distance & derivatives...
470 // TrkDifPoca poca(*_trkTraj,fltLen(),*hitTraj(), hitLen(),_tolerance);
471 /*
472 if (poca.status().failure()) {
473 return TrkErrCode(TrkErrCode::fail);
474 }
475 if (derivs.num_row() != 0) {
476 poca.fetchDerivs(derivs);
477 } else {
478 derivs = poca.derivs();
479 }
480 double sigInv = 1. / hitRms();
481 deltaChi = _resid * sigInv; // NOTE: use _INTERNAL_ residual
482 derivs *= sigInv;
483 */
484 //return TrkErrCode(TrkErrCode::fail);//yzhang FIXME
485}
486
488//CgemHitOnTrack::getFitStuff(double &deltaChi) const
489CgemHitOnTrack::getFitStuff(double & sigma1, double & sigma2, double &deltaChi1, double &deltaChi2) const
490{
491 assert (_trkTraj == &(getParentRep()->traj()));
492 double vec_phi = _dHit->getrecphi() ;
493 double vec_z = _dHit->getRecZ() ;
494 double flt=0;
495 HepVector trkpar = getParentRep()->traj().localTrajectory(0.,flt)->parameters()->parameter(); //get para??????
496 IMdcUtilitySvc* m_mdcUtilitySvc;
497 Gaudi::svcLocator()->service("MdcUtilitySvc",m_mdcUtilitySvc);
498 if (m_mdcUtilitySvc == NULL) cout<< " Can not load MdcUtilitySvc"<<endl;
499 HepVector trkparbes = m_mdcUtilitySvc->patPar2BesPar(trkpar);
500 trkparbes[2]=-trkparbes[2]; // modification for the reversed sign in TrackUtil/Helix
501
502 HepPoint3D pivot(0., 0., 0.);
503 Helix cgem_helix_0(pivot, trkparbes);
504 HepSymMatrix V(2,0), W(2,0) ;
505 HepVector dm(2);
506 int layer = _dHit->getlayerid() ;
507 double rl, R, x_reso, v_reso, a_stero;
508 if(layer==0) { rl=79.838/10. ; R=87.5026/10.; x_reso=0.1372/10.; v_reso=0.1273/10.;a_stero=45.94*3.1415926/180;}
509 else if (layer==1) { rl=125.104/10. ; R=132.7686/10.; x_reso=0.1476/10.;v_reso=0.1326/10.;a_stero=31.10*3.1415926/180;}
510 else { rl=167.604/10.; R=175.2686/10.; x_reso=0.1412/10.;v_reso=0.1378/10.;a_stero=32.99*3.1415926/180;} //cm
511 double d_phi = cgem_helix_0.IntersectCylinder(rl); //const can only call const
512 HepPoint3D pos = cgem_helix_0.x(d_phi);
513
514 double x = pos.x();
515 double y = pos.y();
516 double z = pos.z();
517 double r2 = x*x+y*y;
518 double tmp_phi = atan2(y, x); //[-pi,pi), return azimuthal angle
519 double dphi = vec_phi - tmp_phi;
520 if(dphi < -M_PI) dphi += 2*M_PI;
521 if(dphi >= M_PI) dphi -= 2*M_PI;
522
523 dm[0]=dphi*rl*sin(vec_phi);
524 dm[1]=-(vec_z-z);
525 V(1,1)=rl*rl/R/R*sin(vec_phi)*sin(vec_phi)*x_reso*x_reso;
526 V(2,1)=rl/R*sin(vec_phi)/tan(a_stero)*x_reso*x_reso;
528 W=V;
529 int ifail=99;
530 V.invert(ifail);
531 if (ifail) {
533 }
534
535 sigma1=sqrt(W(1,1));
536 sigma2=sqrt(W(2,2));
537 deltaChi1=dm[0]; //V(1,2)=V(2,1)
538 deltaChi2=dm[1];
539
541}
542
543TrkErrCode CgemHitOnTrack::getFitStuff(HepVector &Xderivs, double &XdeltaChi, HepVector &Vderivs, double &VdeltaChi) const
544{
545 //---get infomation from cluster
546 int layer = _dHit->getlayerid();
547 int sheet = _dHit->getsheetid();
548 double phi_cluster = _dHit->getrecphi();
549 double z_cluster = _dHit->getRecZ()/10;
550 double Q = _dHit->getenergydeposit();
551 //cout<<"layer:"<<layer<<endl;
552
553 //---get geometry parameters from CgemGeomSvc
554 CgemGeoReadoutPlane* readoutPlane = _cgemGeomSvc->getReadoutPlane(layer,sheet);
555 double r_X = readoutPlane->getRX()/10;
556 double r_V = readoutPlane->getRV()/10;
557 double r_M = readoutPlane->getMidRAtGap()/10;
558 double a_stero = readoutPlane->getStereoAngle();
559
560 //---calculate the intersection of cgem layer and helix track
561 double flt=0;
562 HepVector trkpar = getParentRep()->traj().localTrajectory(0.,flt)->parameters()->parameter(); //get para??????
563 //cout<<"barbar:"<<trkpar[0]<<" "<<trkpar[1]<<" "<<trkpar[2]<<" "<<trkpar[3]<<" "<<trkpar[4]<<endl;
564 HepPoint3D pivot(0,0,0);
565 trkpar[0] = -trkpar[0];// BarBar d0 -> BESIII dr
566 trkpar[1] = trkpar[1]-M_PI/2;// BarBar phi0 -> BESIII phi0
567 trkpar[2] = 333.567*trkpar[2];// BarBar omega -> BESIII kappa
568 trkpar[2] = -trkpar[2]; // modification for the reversed sign in TrackUtil/Helix
569 trkpar[3] = trkpar[3];
570 trkpar[4] = trkpar[4];
571 while(trkpar[1] < 0) trkpar[1] += 2*M_PI;
572 while(trkpar[1] >= 2*M_PI) trkpar[1] -= 2*M_PI;
573 //cout<<"besIII:"<<trkpar[0]<<" "<<trkpar[1]<<" "<<trkpar[2]<<" "<<trkpar[3]<<" "<<trkpar[4]<<endl;
574
575 Helix cgem_helix_0(pivot, trkpar);
576 double dPhi = cgem_helix_0.IntersectCylinder(r_M);
577 HepPoint3D pos = cgem_helix_0.x(dPhi);
578 double x_cross = pos.x();
579 double y_cross = pos.y();
580 double z_cross = pos.z();
581 double phi_cross = pos.phi(); //[-pi,pi)
582 while( phi_cross < 0) phi_cross += 2*M_PI;
583 while( phi_cross >= 2*M_PI) phi_cross -= 2*M_PI;
584 double r2 = pos.perp2();
585 //double dphi = phi_cluster - phi_cross;
586 double dphi = phi_cross - phi_cluster;
587 while(dphi < -M_PI) dphi += 2*M_PI;
588 while(dphi >= M_PI) dphi -= 2*M_PI;
589 //cout<<"radius:"<<cgem_helix_0.radius()<<endl;
590 //cout<<"distance:"<<cgem_helix_0.center().perp()<<endl;
591
592 //---get sigma of X and V strip from CgemCalibFunSvc
593 int iView(0), mode(1);//FIXME
594 double T(100);//FIXME
595 double Phi_tangent = cgem_helix_0.direction(dPhi).phi();
596 double Phi_position = phi_cross;//FIXME
597 double delta_phi=Phi_tangent - Phi_position;
598 while(delta_phi>M_PI) delta_phi-=CLHEP::twopi;
599 while(delta_phi<-M_PI) delta_phi+=CLHEP::twopi;
600 double sigma_X = _cgemCalibFunSvc->getSigma(layer,0,mode,delta_phi,Q,T)/10;// mm->cm
601 double sigma_V = _cgemCalibFunSvc->getSigma(layer,1,mode,delta_phi,Q,T)/10;// mm->cm
602
603 //---calculate partial derivative of X and V w.r.t x,y,z
604 HepMatrix J_dmdx(2,3,0), J_dxda(3,5,0), J(2,5,0);
605 J_dmdx(1,1)=-r_X*y_cross/r2;
606 J_dmdx(1,2)= r_X*x_cross/r2;
607 J_dmdx(1,3)= 0.0;
608 J_dmdx(2,1)=-r_V*cos(a_stero)*y_cross/r2;
609 J_dmdx(2,2)= r_V*cos(a_stero)*x_cross/r2;
610 J_dmdx(2,3)= sin(a_stero);
611
612 //---calculate partial derivative of x,y,z w.r.t helix parameters:dr, phi0, kappa, dz, tanl
613 double alpha = cgem_helix_0.alpha();
614 //cout<<"alpha:"<<alpha<<endl;
615 alpha = -alpha; // modification for the reversed sign in TrackUtil/Helix
616 double dr = cgem_helix_0.dr();
617 double phi0 = cgem_helix_0.phi0();
618 double kappa = cgem_helix_0.kappa();
619 kappa = -kappa; // modification for the reversed sign in TrackUtil/Helix
620 double dz = cgem_helix_0.dz();
621 double tanl = cgem_helix_0.tanl();
622
623 double cosPhi=cos(dPhi);
624 double sinPhi=sin(dPhi);
625
626 double dPhiDdr = -(kappa/alpha-cosPhi/(dr+alpha/kappa))/sinPhi;
627 //double dPhiDdr2= -kappa*kappa*(2.0*alpha*dr+kappa*(dr*dr+r2))/(2*alpha*(alpha+dr*kappa)*(alpha+dr*kappa)*sinPhi);
628 //cout<<"dPhiDdr = "<<dPhiDdr<<endl;
629 //cout<<"dPhiDdr2= "<<dPhiDdr2<<endl;
630 double dPhiDkappa = -kappa*(dr*dr-r2)*(2*alpha+dr*kappa)/(2*alpha*(alpha+dr*kappa)*(alpha+dr*kappa)*sinPhi);
631
632 double dxDdr = cos(phi0)+alpha/kappa*sin(phi0+dPhi)*dPhiDdr;
633 double dyDdr = sin(phi0)-alpha/kappa*cos(phi0+dPhi)*dPhiDdr;
634 double dxDphi0 = -dr*sin(phi0)+alpha/kappa*(-sin(phi0)+sin(phi0+dPhi));
635 double dyDphi0 = -dr*cos(phi0)+alpha/kappa*( cos(phi0)-cos(phi0+dPhi));
636 double dxDkappa = -alpha/(kappa*kappa)*(cos(phi0)-cos(phi0+dPhi))+alpha/kappa*sin(phi0+dPhi)*dPhiDkappa;
637 double dyDkappa = -alpha/(kappa*kappa)*(sin(phi0)-sin(phi0+dPhi))-alpha/kappa*cos(phi0+dPhi)*dPhiDkappa;
638 double dzDdr = -alpha/kappa*tanl*dPhiDdr;
639 double dzDkappa = alpha/(kappa*kappa)*tanl*dPhi-alpha/kappa*tanl*dPhiDkappa;
640 double dzDtanl = -alpha/kappa*dPhi;
641
642 //---return the partial residuals and derivatives of X and V w.r.t helix parameters:d0, phi0, omega, z0, tanl
643 J_dxda(1,1) = -1*dxDdr;//BESIII dr -> BarBar d0
644 J_dxda(1,2) = dxDphi0;
645 J_dxda(1,3) = -alpha*dxDkappa;// BESIII kappa -> BarBar omega
646 J_dxda(2,1) = -1*dyDdr;//BESIII dr -> BarBar d0
647 J_dxda(2,2) = dyDphi0;
648 J_dxda(2,3) = -alpha*dyDkappa;// BESIII kappa -> BarBar omega
649 J_dxda(3,1) = -1*dzDdr;//BESIII dr -> BarBar d0
650 J_dxda(3,3) = -alpha*dzDkappa;// BESIII kappa -> BarBar omega
651 J_dxda(3,4) = 1.0;
652 J_dxda(3,5) = dzDtanl;
653 J=J_dmdx*J_dxda;
654 int nPar = getParentRep()->traj().localTrajectory(0.,flt)->nPar();
655 for(int i=1;i<=nPar;i++){
656 Xderivs(i) = J(1,i)/sigma_X;
657 Vderivs(i) = J(2,i)/sigma_V;
658 }
659 XdeltaChi = dphi*r_X/sigma_X;//delta X
660 //VdeltaChi = ((z_cluster-z_cross)*sin(a_stero)+r_V*cos(a_stero)*dphi)/sigma_V;
661 VdeltaChi = ((z_cross-z_cluster)*sin(a_stero)+r_V*cos(a_stero)*dphi)/sigma_V;
662 //cout<<"X:"<<phi_cluster<<" "<<phi_cross<<" "<<sigma_V<<endl;
663 //cout<<"V:"<<z_cluster<<" "<<z_cross<<" "<<sigma_V<<endl;
664 if(nPar == 3){
665 Vderivs = HepVector(nPar,0);
666 VdeltaChi = 0;
667 }
669}
670
671TrkErrCode CgemHitOnTrack::getFitStuff(double &XdeltaChi, double &VdeltaChi) const
672{
673 //---get infomation from cluster
674 int layer = _dHit->getlayerid();
675 int sheet = _dHit->getsheetid();
676 double phi_cluster = _dHit->getrecphi();
677 double z_cluster = _dHit->getRecZ()/10;
678 double Q = _dHit->getenergydeposit();
679
680 //---get geometry parameters from CgemGeomSvc
681 CgemGeoReadoutPlane* readoutPlane = _cgemGeomSvc->getReadoutPlane(layer,sheet);
682 double r_X = readoutPlane->getRX()/10;
683 double r_V = readoutPlane->getRV()/10;
684 double r_M = readoutPlane->getMidRAtGap()/10;
685 double a_stero = readoutPlane->getStereoAngle();
686
687 //---calculate the intersection of cgem layer and helix track
688 double flt=0;
689 HepVector trkpar = getParentRep()->traj().localTrajectory(0.,flt)->parameters()->parameter(); //get para??????
690 HepPoint3D pivot(0,0,0);
691 //cout<<"barbar parameters:"<<trkpar[0]<<" "<<trkpar[1]<<" "<<trkpar[2]<<" "<<trkpar[3]<<" "<<trkpar[4]<<endl;
692 trkpar[0] = -trkpar[0];// BarBar d0 -> BESIII dr
693 trkpar[1] = trkpar[1]-M_PI/2;// BarBar phi0 -> BESIII phi0
694 trkpar[2] = 333.567*trkpar[2];// BarBar omega -> BESIII kappa
695 trkpar[2] = -trkpar[2]; // modification for the reversed sign in TrackUtil/Helix
696 trkpar[3] = trkpar[3];
697 trkpar[4] = trkpar[4];
698 while(trkpar[1] < 0) trkpar[1] += 2*M_PI;
699 while(trkpar[1] >= 2*M_PI) trkpar[1] -= 2*M_PI;
700 //cout<<"besIII parameters:"<<trkpar[0]<<" "<<trkpar[1]<<" "<<trkpar[2]<<" "<<trkpar[3]<<" "<<trkpar[4]<<endl;
701 Helix cgem_helix_0(pivot, trkpar);
702 double dPhi = cgem_helix_0.IntersectCylinder(r_M);
703 HepPoint3D pos = cgem_helix_0.x(dPhi);
704 double x_cross = pos.x();
705 double y_cross = pos.y();
706 double z_cross = pos.z();
707 double phi_cross = pos.phi(); //[-pi,pi)
708 while( phi_cross < 0) phi_cross += 2*M_PI;
709 while( phi_cross >= 2*M_PI) phi_cross -= 2*M_PI;
710 double r2 = pos.perp2();
711 //double dphi = phi_cluster - phi_cross;
712 double dphi = phi_cross - phi_cluster;
713 while(dphi < -M_PI) dphi += 2*M_PI;
714 while(dphi >= M_PI) dphi -= 2*M_PI;
715
716 //---get sigma of X and V strip from CgemCalibFunSvc
717 int iView(0), mode(1);//FIXME
718 double T(100);//FIXME
719 double Phi_tangent = cgem_helix_0.direction(dPhi).phi();
720 double Phi_position = phi_cross;//FIXME
721 double delta_phi=Phi_tangent - Phi_position;
722 while(delta_phi>M_PI) delta_phi-=CLHEP::twopi;
723 while(delta_phi<-M_PI) delta_phi+=CLHEP::twopi;
724 double sigma_X = _cgemCalibFunSvc->getSigma(layer,0,mode,delta_phi,Q,T)/10;// mm->cm
725 double sigma_V = _cgemCalibFunSvc->getSigma(layer,1,mode,delta_phi,Q,T)/10;// mm->cm
726
727 //---return the partial derivatives and residuals of X and V
728 int nPar = getParentRep()->traj().localTrajectory(0.,flt)->nPar();
729 XdeltaChi = dphi*r_X/sigma_X;//delta X
730 //VdeltaChi = ((z_cluster-z_cross)*sin(a_stero)+r_V*cos(a_stero)*dphi)/sigma_V;
731 VdeltaChi = ((z_cross-z_cluster)*sin(a_stero)+r_V*cos(a_stero)*dphi)/sigma_V;
732 //cout<<"X:"<<phi_cluster<<" "<<phi_cross<<" "<<sigma_V<<endl;
733 //cout<<"V:"<<z_cluster<<" "<<z_cross<<" "<<sigma_V<<endl;
734 if(nPar == 3){
735 VdeltaChi = 0;
736 }
738}
739//cout<<__FILE__<<" "<<__LINE__<<endl;
double tan(const BesAngle a)
Definition: BesAngle.h:216
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
const double a_stero[3]
double sigma2(0)
double length
Double_t x[10]
const double alpha
const double x_reso[3]
const double v_reso[3]
#define M_PI
Definition: TConstant.h:4
double getSigma(int layer, int xvFlag, int readoutMode, double angle, double Q, double T) const
double getLengthOfCgemLayer() const
Definition: CgemGeoLayer.h:22
CgemGeoLayer * getCgemLayer(int i) const
Definition: CgemGeomSvc.h:48
CgemGeoReadoutPlane * getReadoutPlane(int iLayer, int iSheet) const
Definition: CgemGeomSvc.h:140
void changeBase(RecCgemCluster *newBase)
double dcaToWire() const
double entranceAngleHit() const
double entranceAngle() const
void print(std::ostream &) const
virtual ~CgemHitOnTrack()
CgemHitOnTrack(const RecCgemCluster &baseHit, double fittime)
double dipAngle() const
TrkEnums::TrkViewInfo whatView() const
TrkErrCode getFitStuff(HepVector &derivs, HepVector &derivs2, double &sigma1, double &sigma2, double &deltaChi1, double &deltaChi2) const
virtual bool timeAbsolute(double &t, double &tErr) const
virtual bool timeResid(double &t, double &tErr) const
const RecCgemCluster * baseHit() const
virtual const Trajectory * hitTraj() const
virtual TrkHitOnTrk * clone(TrkRep *, const TrkDifTraj *trkTraj=0) const
double charge() const
void setT0(double t0)
static const double pi
Definition: Constants.h:38
static const double halfPi
Definition: Constants.h:40
HepVector & parameter()
Definition: DifIndepPar.h:51
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
double dr(void) const
returns an element of parameters.
Hep3Vector direction(double dPhi=0.) const
returns direction vector after rotating angle dPhi in phi direction.
virtual HepVector patPar2BesPar(const HepVector &helixPar) const =0
double getenergydeposit(void) const
double getRecZ(void) const
int getclusterid(void) const
int getlayerid(void) const
int getflag(void) const
double getrecphi(void) const
double getrecv(void) const
int getsheetid(void) const
virtual void getInfo(double fltLen, HepPoint3D &pos, Hep3Vector &direction) const =0
virtual Hep3Vector direction(double) const =0
virtual const TrkDifTraj & traj() const =0
virtual const TrkSimpTraj * localTrajectory(double fltLen, double &localFlt) const =0
int failure() const
Definition: TrkErrCode.h:61
void setHitResid(double newResid)
Definition: TrkHitOnTrk.h:176
double fltLen() const
Definition: TrkHitOnTrk.h:91
friend class TrkBase::Functors::updateMeasurement
Definition: TrkHitOnTrk.h:191
void setHitRms(double newRms)
Definition: TrkHitOnTrk.h:154
const TrkDifTraj * _trkTraj
Definition: TrkHitOnTrk.h:171
void setFltLen(double f)
Definition: TrkHitOnTrk.h:147
const TrkRep * getParentRep() const
Definition: TrkHitOnTrk.h:73
TrkPoca * _poca
Definition: TrkHitOnTrk.h:172
const TrkDifTraj * trkTraj() const
Definition: TrkHitOnTrk.h:77
const TrkErrCode & status() const
Definition: TrkPocaBase.h:62
double trackT0() const
Definition: TrkRecoTrk.cxx:140
Definition: TrkRep.h:43
virtual double arrivalTime(double fltL) const
Definition: TrkRep.cxx:192
TrkRecoTrk * parentTrack()
Definition: TrkRep.h:82
TrkParams * parameters()
Definition: TrkSimpTraj.h:80
virtual int nPar() const
Definition: TrkSimpTraj.h:88
TrkViewInfo
Definition: TrkEnums.h:22
int t()
Definition: t.c:1
const float rad
Definition: vector3.h:134