13#ifdef TRKRECO_DEBUG_DETAIL
18#include "TrkReco/T3DLineFitter.h"
19#include "TrkReco/T3DLine.h"
25#include "CLHEP/Matrix/Matrix.h"
26#include "CLHEP/Matrix/SymMatrix.h"
27#include "CLHEP/Matrix/Vector.h"
28#include "MdcTables/MdcTables.h"
29#include "TrkReco/TMLink.h"
30#include "TrkReco/TTrackBase.h"
32#include "MdcCalibFunSvc/IMdcCalibFunSvc.h"
35#include "GaudiKernel/Bootstrap.h"
36#include "GaudiKernel/IDataManagerSvc.h"
37#include "GaudiKernel/IDataProviderSvc.h"
38#include "GaudiKernel/IMessageSvc.h"
39#include "GaudiKernel/ISvcLocator.h"
40#include "GaudiKernel/MsgStream.h"
41#include "GaudiKernel/PropertyMgr.h"
42#include "GaudiKernel/SmartDataPtr.h"
43#include "GaudiKernel/StatusCode.h"
45#include "EventModel/EventModel.h"
46#include "GaudiKernel/ContainedObject.h"
47#include "GaudiKernel/ObjectVector.h"
48#include "GaudiKernel/SmartRef.h"
49#include "GaudiKernel/SmartRefVector.h"
51#include "EvTimeEvent/RecEsTime.h"
53using CLHEP::HepMatrix;
54using CLHEP::HepSymMatrix;
55using CLHEP::HepVector;
77 :
TMFitter(
name ), _sag( false ), _propagation( 0 ), _tof( true ) {}
88void T3DLineFitter::drift(
const T3DLine&
t,
const TMLink& l,
float t0Offset,
double& distance,
94 Gaudi::svcLocator()->service(
"MessageSvc",
msgSvc );
95 MsgStream log(
msgSvc,
"TCosmicFitter" );
97 IDataProviderSvc* eventSvc = NULL;
98 Gaudi::svcLocator()->service(
"EventDataSvc", eventSvc );
100 SmartDataPtr<RecEsTimeCol> aevtimeCol( eventSvc,
"/Event/Recon/RecEsTimeCol" );
103 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
104 _t0_bes = ( *iter_evt )->getTest();
106 else { log << MSG::WARNING <<
"Could not find RecEsTimeCol" << endmsg; }
109 const TMDCWireHit& h = *l.
hit();
114 if ( ( onWire.x() * onTrack.y() - onWire.y() * onTrack.x() ) < 0 ) leftRight =
WireHitLeft;
148 double Tfly = _t0_bes / 220. * ( 110. - onWire.y() );
155 int side = leftRight;
163 IMdcCalibFunSvc* l_mdcCalFunSvc;
164 Gaudi::svcLocator()->service(
"MdcCalibFunSvc", l_mdcCalFunSvc );
165 double T0 = l_mdcCalFunSvc->
getT0( layerId, wire );
169 double timeWalk = l_mdcCalFunSvc->
getTimeWalk( layerId, rawadc );
171 double drifttime =
time - T0 - timeWalk;
173 dist = l_mdcCalFunSvc->
driftTimeToDist( drifttime, layerId, wire, side, 0.0 );
174 edist = l_mdcCalFunSvc->
getSigma( layerId, side, dist, 0.0 );
177 edist = edist / 10.0;
188 distance = (double)dist;
208 unsigned nCores = cores.length();
213 if ( ( nStereoCores == 0 ) && ( nCores > 3 ) ) flag2D =
true;
214 else if ( ( nStereoCores < 2 ) || ( nCores - nStereoCores < 3 ) )
return TFitErrorFewHits;
239 while ( nTrial < 100 )
244 for (
unsigned j = 0; j < 4; j++ ) dchi2da[j] = 0;
249 while (
TMLink* l = cores[i++] )
254 t.approach( *l, _sag );
258 if ( onWire.cross( onTrack ).z() < 0. ) leftRight =
WireHitLeft;
263 drift(
t, *l, t0Offset, distance, eDistance );
264 l->
drift( distance, 0 );
265 l->
drift( distance, 1 );
266 l->
dDrift( eDistance, 0 );
267 l->
dDrift( eDistance, 1 );
268 double eDistance2 = eDistance * eDistance;
273 double vmag =
v.mag();
274 double dDistance = vmag - distance;
278 this->dxda( *l,
t, dxda, dyda, dzda, vw );
281 dDda = ( vmag > 0. ) ? ( (
v.x() * ( 1. - vw.x() * vw.x() ) -
v.y() * vw.x() * vw.y() -
282 v.z() * vw.x() * vw.z() ) *
284 (
v.y() * ( 1. - vw.y() * vw.y() ) -
v.z() * vw.y() * vw.z() -
285 v.x() * vw.y() * vw.x() ) *
287 (
v.z() * ( 1. - vw.z() * vw.z() ) -
v.x() * vw.z() * vw.x() -
288 v.y() * vw.z() * vw.y() ) *
294 std::cout <<
" in fit " << onTrack <<
", " << onWire;
297 dchi2da += ( dDistance / eDistance2 ) * dDda;
298 d2chi2d2a += vT_times_v( dDda ) / eDistance2;
299 double pChi2 = dDistance * dDistance / eDistance2;
303 l->
update( onTrack, onWire, leftRight, pChi2 );
307 double change = chi2Old - chi2;
309 if ( fabs( change ) < 1.0e-5 )
break;
320 f = dchi2da.sub( 1, 2 );
321 e = d2chi2d2a.sub( 1, 2 );
331 da = solve( d2chi2d2a, dchi2da );
346 Eb = d2chi2d2a.sub( 1, 3 );
347 Ec = Eb.inverse( err );
358 Ea = d2chi2d2a.inverse( err );
371 t._ndf = nCores - dim;
375 t.pivot( pivot_bak );
387 const double cosPhi0 =
t.cosPhi0();
388 const double sinPhi0 =
t.sinPhi0();
389 const double dr =
t.dr();
393 const double t_t = ( onWire -
t.x0() ).dot( k ) / k.mag2();
397 HepPoint3D wireBackwardPosition =
w.backwardPosition();
398 wireDirection =
w.direction();
400 w.wirePosition( onWire.z(), xw, wireBackwardPosition, (
HepVector3D&)wireDirection );
406 const double v_k =
v.dot( k );
407 const double tvk = v_k * v_k - k.mag2();
408 if ( tvk == 0 )
return ( -1 );
414 HepVector3D( -dr * sinPhi0 - t_t * cosPhi0, dr * cosPhi0 - t_t * sinPhi0, 0 ),
427 for (
int i = 0; i < 4; i++ )
429 const double v_dkda =
v.dot( dkda[i] );
432 dx0da[i].dot( kvkv ) / tvk + d.dot( dkda[i] - v_dkda *
v ) / tvk -
433 d.dot( kvkv ) * 2 * ( v_k * v_dkda - k.dot( dkda[i] ) ) / ( tvk * tvk );
435 const HepVector3D dxda3D = dxda_t[i] + dtda * dxdt_a;
437 dxda[i] = dxda3D.x();
438 dyda[i] = dxda3D.y();
439 dzda[i] = dxda3D.z();
HepGeom::Vector3D< double > HepVector3D
HepGeom::Point3D< double > HepPoint3D
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
NTuple::Array< double > m_tof
CLHEP::HepSymMatrix SymMatrix
const HepPoint3D ORIGIN
Constants.
#define TFitAlreadyFitted
unsigned NStereoHits(const AList< TMLink > &links)
returns # of stereo hits.
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
HepGeom::Vector3D< double > HepVector3D
virtual double driftTimeToDist(double drifttime, int layid, int cellid, int lr, double entrance=0.0) const =0
virtual double getSigma(int layid, int lr, double dist, double entrance=0.0, double tanlam=0.0, double z=0.0, double Q=1000.0) const =0
virtual double getT0(int layid, int cellid) const =0
virtual double getTimeWalk(int layid, double Q) const =0
T3DLineFitter(const std::string &name)
Constructor.
virtual int fit(TTrackBase &) const
virtual ~T3DLineFitter()
Destructor.
A class to represent a track in tracking.
struct MdcRec_wirhit * reccdc(void) const
returns a pointer to RECMDC_WIRHIT.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
const TMDCWire *const wire(void) const
returns a pointer to a TMDCWire.
A class to represent a wire in MDC.
unsigned localId(void) const
returns local id in a wire layer.
unsigned layerId(void) const
returns layer id.
const std::string & name(void) const
returns name.
TMFitter(const std::string &name)
Constructor.
A class to relate TMDCWireHit and TTrack objects.
const HepPoint3D & positionOnWire(void) const
returns the closest point on wire to a track.
const HepPoint3D & positionOnTrack(void) const
returns the closest point on track to wire.
const TMDCWireHit * hit(void) const
returns a pointer to a hit.
void update(const HepPoint3D &onTrack, const HepPoint3D &onWire, unsigned leftRight, double pull)
sets results of fitting.
float dDrift(void) const
returns/sets drift distance error.
float drift(void) const
returns/sets drift distance.
const TMDCWire *const wire(void) const
returns a pointer to a wire.
A virtual class for a track class in tracking.
virtual unsigned objectType(void) const
returns object type.