BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TCosmicFitter Class Reference

A class to fit a TTrackBase object to a helix. More...

#include <TCosmicFitter.h>

Inheritance diagram for TCosmicFitter:

Public Member Functions

 TCosmicFitter (const std::string &name)
 Constructor.
virtual ~TCosmicFitter ()
 Destructor.
void dump (const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
 dumps debug information.
int fit (TTrackBase &) const
int fit (TTrackBase &, float t0Offset) const
int fitWithCathode (TTrackBase &, float t0Offset=0., float windowSize=0.6, int SysCorr=0)
 TCosmicFitter (const std::string &name)
 Constructor.
virtual ~TCosmicFitter ()
 Destructor.
void dump (const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
 dumps debug information.
int fit (TTrackBase &) const
int fit (TTrackBase &, float t0Offset) const
int fitWithCathode (TTrackBase &, float t0Offset=0., float windowSize=0.6, int SysCorr=0)
 TCosmicFitter (const std::string &name)
 Constructor.
virtual ~TCosmicFitter ()
 Destructor.
void dump (const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
 dumps debug information.
int fit (TTrackBase &) const
int fit (TTrackBase &, float t0Offset) const
int fitWithCathode (TTrackBase &, float t0Offset=0., float windowSize=0.6, int SysCorr=0)
Public Member Functions inherited from TMFitter
 TMFitter (const std::string &name)
 Constructor.
virtual ~TMFitter ()
 Destructor.
const std::string & name (void) const
 returns name.
void dump (const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
 TMFitter (const std::string &name)
 Constructor.
virtual ~TMFitter ()
 Destructor.
const std::string & name (void) const
 returns name.
void dump (const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
 TMFitter (const std::string &name)
 Constructor.
virtual ~TMFitter ()
 Destructor.
const std::string & name (void) const
 returns name.
void dump (const std::string &message=std::string(""), const std::string &prefix=std::string("")) const

Additional Inherited Members

Protected Member Functions inherited from TMFitter
void fitDone (TTrackBase &) const
 sets the fitted flag. (Bad implementation)
void fitDone (TTrackBase &) const
 sets the fitted flag. (Bad implementation)
void fitDone (TTrackBase &) const
 sets the fitted flag. (Bad implementation)

Detailed Description

A class to fit a TTrackBase object to a helix.

Definition at line 44 of file InstallArea/x86_64-el9-gcc13-dbg/include/TrkReco/TCosmicFitter.h.

Constructor & Destructor Documentation

◆ TCosmicFitter() [1/3]

TCosmicFitter::TCosmicFitter ( const std::string & name)

Constructor.

Definition at line 78 of file TCosmicFitter.cxx.

79 : TMFitter( name ), m_pmgnIMF( nullptr ) {}
const std::string & name(void) const
returns name.
TMFitter(const std::string &name)
Constructor.
Definition TMFitter.cxx:17

◆ ~TCosmicFitter() [1/3]

TCosmicFitter::~TCosmicFitter ( )
virtual

Destructor.

Definition at line 81 of file TCosmicFitter.cxx.

81{}

◆ TCosmicFitter() [2/3]

TCosmicFitter::TCosmicFitter ( const std::string & name)

Constructor.

◆ ~TCosmicFitter() [2/3]

virtual TCosmicFitter::~TCosmicFitter ( )
virtual

Destructor.

◆ TCosmicFitter() [3/3]

TCosmicFitter::TCosmicFitter ( const std::string & name)

Constructor.

◆ ~TCosmicFitter() [3/3]

virtual TCosmicFitter::~TCosmicFitter ( )
virtual

Destructor.

Member Function Documentation

◆ dump() [1/3]

void TCosmicFitter::dump ( const std::string & message = std::string(""),
const std::string & prefix = std::string("") ) const

dumps debug information.

◆ dump() [2/3]

void TCosmicFitter::dump ( const std::string & message = std::string(""),
const std::string & prefix = std::string("") ) const

dumps debug information.

◆ dump() [3/3]

void TCosmicFitter::dump ( const std::string & message = std::string(""),
const std::string & prefix = std::string("") ) const

dumps debug information.

◆ fit() [1/6]

int TCosmicFitter::fit ( TTrackBase & b) const
virtual

Implements TMFitter.

Definition at line 83 of file TCosmicFitter.cxx.

83 {
84
85 // double t0_bes;
86 // TrkReco::t0(t0_bes);
87 // const double t0_bes = TrkReco::t0();
88
89 //...Already fitted ?...
90 if ( b.fitted() ) return TFitAlreadyFitted;
91
92 int err = fit( b, 0. );
93 if ( !err ) b._fitted = true;
94
95 return err;
96}
int fit(TTrackBase &) const
bool fitted(void) const
returns true if fitted.

Referenced by fit().

◆ fit() [2/6]

int TCosmicFitter::fit ( TTrackBase & ) const
virtual

Implements TMFitter.

◆ fit() [3/6]

int TCosmicFitter::fit ( TTrackBase & ) const
virtual

Implements TMFitter.

◆ fit() [4/6]

int TCosmicFitter::fit ( TTrackBase & b,
float t0Offset ) const

Definition at line 98 of file TCosmicFitter.cxx.

98 {
99
100#ifdef TRKRECO_DEBUG_DETAIL
101 std::cout << " TCosmicFitter::fit ..." << std::endl;
102#endif
103
104 IMdcCalibFunSvc* l_mdcCalFunSvc;
105 Gaudi::svcLocator()->service( "MdcCalibFunSvc", l_mdcCalFunSvc );
106
107 //...Check # of hits...
108 if ( b.links().length() < 5 ) return TFitErrorFewHits;
109 unsigned nValid = 0;
110 for ( unsigned i = 0; i < b.links().length(); i++ )
111 {
112 unsigned state = b.links()[i]->hit()->state();
113 if ( state & WireHitInvalidForFit ) continue;
114 if ( state & WireHitFittingValid ) ++nValid;
115 }
116 if ( nValid < 5 ) return TFitErrorFewHits;
117
118 //...Type check...
119 // if (b.type() != Track) return TFitUnavailable;
120 if ( b.objectType() != Track ) return TFitUnavailable;
121 TTrack& t = (TTrack&)b;
122
123 // read t0 from TDS-------------------------------------//
124 double _t0_bes = -1.;
125 IMessageSvc* msgSvc;
126 Gaudi::svcLocator()->service( "MessageSvc", msgSvc );
127 MsgStream log( msgSvc, "TCosmicFitter" );
128
129 IDataProviderSvc* eventSvc = NULL;
130 Gaudi::svcLocator()->service( "EventDataSvc", eventSvc );
131
132 SmartDataPtr<RecEsTimeCol> aevtimeCol( eventSvc, "/Event/Recon/RecEsTimeCol" );
133 if ( aevtimeCol )
134 {
135 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
136 _t0_bes = ( *iter_evt )->getTest();
137 // cout<<" tev: "<<setw(4)<<_t0_bes<<endl;
138 }
139 else { log << MSG::WARNING << "Could not find RecEsTimeCol" << endmsg; }
140 // if (_t0_bes < 7.) _t0_bes = 7.;
141 //----------------------------------------------------//
142
143 //...Setup...
144 Vector a( 5 ), da( 5 );
145 a = t.helix().a();
146 Vector dxda( 5 );
147 Vector dyda( 5 );
148 Vector dzda( 5 );
149 Vector dDda( 5 );
150 Vector dchi2da( 5 );
151 SymMatrix d2chi2d2a( 5, 0 );
152 double chi2;
153 // double chi2Old = 10e99;
154 double chi2Old = DBL_MAX;
155 const double convergence = Convergence;
156 bool allAxial = true;
157 Matrix e( 3, 3 );
158 Vector f( 3 );
159 int err = 0;
160 double factor = 1.0; // jtanaka0715
161
162 Vector maxDouble( 5 );
163 for ( unsigned i = 0; i < 5; i++ ) maxDouble[i] = ( FLT_MAX );
164
165 //...Fitting loop...
166 unsigned nTrial = 0;
167 while ( nTrial < NTrailMax )
168 {
169
170 //...Set up...
171 chi2 = 0.;
172 for ( unsigned j = 0; j < 5; j++ ) dchi2da[j] = 0.;
173 d2chi2d2a = SymMatrix( 5, 0 );
174
175#if CAL_TOF_HELIX
176 // cal the time pass through the chamber
177 const float Rad = 81; // cm
178 float dRho = t.helix().a()[0];
179 float Lproj = sqrt( Rad * Rad - dRho * dRho );
180 float tlmd = t.helix().a()[4];
181 float fct = sqrt( 1. + tlmd * tlmd );
182#endif
183
184 //...Loop with hits...
185 unsigned i = 0;
186 while ( TMLink* l = t.links()[i++] )
187 {
188 const TMDCWireHit& h = *l->hit();
189
190 //...Check state...
191 if ( h.state() & WireHitInvalidForFit ) continue;
192 if ( !( h.state() & WireHitFittingValid ) ) continue;
193
194 //...Check wire...
195 if ( !nTrial )
196 if ( h.wire()->stereo() ) allAxial = false;
197
198 //...Cal. closest points...
199 int doSagCorrection = 0;
200 // if(nTrial && !allAxial ) doSagCorrection = 1; //Liuqg
201 t.approach( *l, doSagCorrection );
202 double dPhi = l->dPhi();
203 const HepPoint3D& onTrack = l->positionOnTrack();
204 const HepPoint3D& onWire = l->positionOnWire();
205
206#ifdef TRKRECO_DEBUG_DETAIL
207// std::cout << " in fit " << onTrack << ", " << onWire;
208// h.dump();
209#endif
210
211 //...Obtain drift distance and its error...
212 unsigned leftRight = WireHitRight;
213 if ( onWire.cross( onTrack ).z() < 0. ) leftRight = WireHitLeft;
214 double distance = h.drift( leftRight );
215 double eDistance = h.dDrift( leftRight );
216 //...
217 if ( nTrial && !allAxial )
218 {
219 int side = leftRight;
220
221 double Tfly = _t0_bes / 220. * ( 110. - onWire.y() );
222#if CAL_TOF_HELIX
223 float Rad_wire = sqrt( x[0] * x[0] + x[1] * x[1] ); // cm
224 float L_wire = sqrt( Rad_wire * Rad_wire - dRho * dRho );
225 float flyLength = Lproj - L_wire;
226 if ( x[1] < 0 ) flyLength = Lproj + L_wire;
227 Tfly = flyLength / 29.98 * sqrt( 1.0 + ( 0.105 / 0.5 ) * ( 0.105 / 0.5 ) ) *
228 fct; // approxiate... cm/ns
229#endif
230 float time = l->hit()->reccdc()->tdc - Tfly;
231
232 int wire = h.wire()->localId();
233 int layerId = h.wire()->layerId();
234 float dist = distance;
235 float edist = eDistance;
236 double T0 = l_mdcCalFunSvc->getT0( layerId, wire );
237 double rawadc = 0.;
238 rawadc = l->hit()->reccdc()->adc;
239
240 double timeWalk = l_mdcCalFunSvc->getTimeWalk( layerId, rawadc );
241 double drifttime = time - T0 - timeWalk;
242 dist = l_mdcCalFunSvc->driftTimeToDist( drifttime, layerId, wire, side, 0.0 );
243 edist = l_mdcCalFunSvc->getSigma( layerId, side, dist, 0.0 );
244 dist = dist / 10.0; // mm->cm
245 edist = edist / 10.0;
246 // if(layerId<20) edist = 9999.;
247
248 // zsl calcdc_driftdist_(&doPropDelay,&wire,&side,p,x,&time,&dist,&edist);
249
250 distance = (double)dist;
251 eDistance = (double)edist;
252
253 l->drift( distance, 0 ); // update
254 l->drift( distance, 1 );
255 l->dDrift( eDistance, 0 );
256 l->dDrift( eDistance, 1 );
257 l->tof( Tfly );
258 }
259 double eDistance2 = eDistance * eDistance;
260
261 //...Residual...
262 HepVector3D v = onTrack - onWire;
263 double vmag = v.mag();
264 double dDistance = vmag - distance;
265
266 //...dxda...
267 this->dxda( *l, t.helix(), dPhi, dxda, dyda, dzda, doSagCorrection );
268
269 //...Chi2 related...
270 // dDda = (v.x() * dxda + v.y() * dyda + v.z() * dzda) / vmag;
271 HepVector3D vw = h.wire()->direction();
272 dDda = ( vmag > 0. ) ? ( ( v.x() * ( 1. - vw.x() * vw.x() ) - v.y() * vw.x() * vw.y() -
273 v.z() * vw.x() * vw.z() ) *
274 dxda +
275 ( v.y() * ( 1. - vw.y() * vw.y() ) - v.z() * vw.y() * vw.z() -
276 v.x() * vw.y() * vw.x() ) *
277 dyda +
278 ( v.z() * ( 1. - vw.z() * vw.z() ) - v.x() * vw.z() * vw.x() -
279 v.y() * vw.z() * vw.y() ) *
280 dzda ) /
281 vmag
282 : Vector( 5, 0 );
283 if ( vmag <= 0.0 )
284 {
285 std::cout << " in fit " << onTrack << ", " << onWire;
286 h.dump();
287 }
288 dchi2da += ( dDistance / eDistance2 ) * dDda;
289 d2chi2d2a += vT_times_v( dDda ) / eDistance2;
290 double pChi2 = dDistance * dDistance / eDistance2;
291 chi2 += pChi2;
292
293 //...Store results...
294 l->update( onTrack, onWire, leftRight, pChi2 );
295 }
296
297 //...Check condition...
298 double change = chi2Old - chi2;
299 if ( fabs( change ) < convergence ) break;
300 // if (change < 0.) break;
301 // jtanaka -- from traffs -- Ozaki-san added this part to traffs.
302 if ( change < 0. )
303 {
304#ifdef TRKRECO_DEBUG_DETAIL
305 std::cout << "chi2Old, chi2=" << chi2Old << " " << chi2 << std::endl;
306#endif
307 // change to the old value.
308 a += factor * da;
309 // a[2] = 0.000000001;
310 t._helix->a( a );
311
312 chi2 = 0.;
313 for ( unsigned j = 0; j < 5; j++ ) dchi2da[j] = 0.;
314 d2chi2d2a = SymMatrix( 5, 0 );
315
316 //...Loop with hits...
317 unsigned i = 0;
318 while ( TMLink* l = t.links()[i++] )
319 {
320 const TMDCWireHit& h = *l->hit();
321
322 //...Check state...
323 if ( h.state() & WireHitInvalidForFit ) continue;
324 if ( !( h.state() & WireHitFittingValid ) ) continue;
325
326 //...Check wire...
327 if ( !nTrial )
328 if ( h.wire()->stereo() ) allAxial = false;
329
330 //...Cal. closest points...
331 int doSagCorrection = 0;
332 // if( nTrial && !allAxial ) doSagCorrection = 1; //Liuqg
333 t.approach( *l, doSagCorrection );
334 double dPhi = l->dPhi();
335 const HepPoint3D& onTrack = l->positionOnTrack();
336 const HepPoint3D& onWire = l->positionOnWire();
337
338#ifdef TRKRECO_DEBUG_DETAIL
339 // std::cout << " in fit in case of change < 0. " << onTrack << ", " << onWire;
340 // h.dump();
341#endif
342
343 //...Obtain drift distance and its error...
344 unsigned leftRight = WireHitRight;
345 if ( onWire.cross( onTrack ).z() < 0. ) leftRight = WireHitLeft;
346 double distance = h.drift( leftRight );
347 double eDistance = h.dDrift( leftRight );
348 if ( nTrial && !allAxial )
349 {
350 int side = leftRight;
351
352 double Tfly = _t0_bes / 220. * ( 110. - onWire.y() );
353#if CAL_TOF_HELIX
354 float Rad_wire = sqrt( x[0] * x[0] + x[1] * x[1] ); // cm
355 float L_wire = sqrt( Rad_wire * Rad_wire - dRho * dRho );
356 float flyLength = Lproj - L_wire;
357 if ( x[1] < 0 ) flyLength = Lproj + L_wire;
358 Tfly = flyLength / 29.98 * sqrt( 1.0 + ( 0.105 / 10 ) * ( 0.105 / 10 ) ) *
359 fct; // approxiate... cm/ns
360#endif
361
362 float time = l->hit()->reccdc()->tdc - Tfly;
363
364 int wire = h.wire()->localId();
365 int layerId = h.wire()->layerId();
366 float dist = distance;
367 float edist = eDistance;
368 // int doPropDelay = 1; //
369
370 double T0 = l_mdcCalFunSvc->getT0( layerId, wire );
371 double rawadc = 0.;
372 rawadc = l->hit()->reccdc()->adc;
373 double timeWalk = l_mdcCalFunSvc->getTimeWalk( layerId, rawadc );
374 double drifttime = time - T0 - timeWalk;
375 dist = l_mdcCalFunSvc->driftTimeToDist( drifttime, layerId, wire, side, 0.0 );
376 edist = l_mdcCalFunSvc->getSigma( layerId, side, dist, 0.0 );
377 dist = dist / 10.0; // mm->cm
378 edist = edist / 10.0;
379 // if (layerId<20) edist = 9999.;
380
381 // zsl calcdc_driftdist_(&doPropDelay,&wire,&side,p,x,&time,&dist,&edist);
382
383 distance = (double)dist;
384 eDistance = (double)edist;
385
386 l->drift( distance, 0 ); // update
387 l->drift( distance, 1 );
388 l->dDrift( eDistance, 0 );
389 l->dDrift( eDistance, 1 );
390 l->tof( Tfly );
391 }
392 double eDistance2 = eDistance * eDistance;
393
394 //...Residual...
395 HepVector3D v = onTrack - onWire;
396 double vmag = v.mag();
397 double dDistance = vmag - distance;
398
399 //...dxda...
400 this->dxda( *l, t.helix(), dPhi, dxda, dyda, dzda, doSagCorrection );
401
402 //...Chi2 related...
403 // dDda = (v.x() * dxda + v.y() * dyda + v.z() * dzda) / vmag;
404 HepVector3D vw = h.wire()->direction();
405 dDda = ( vmag > 0. ) ? ( ( v.x() * ( 1. - vw.x() * vw.x() ) - v.y() * vw.x() * vw.y() -
406 v.z() * vw.x() * vw.z() ) *
407 dxda +
408 ( v.y() * ( 1. - vw.y() * vw.y() ) - v.z() * vw.y() * vw.z() -
409 v.x() * vw.y() * vw.x() ) *
410 dyda +
411 ( v.z() * ( 1. - vw.z() * vw.z() ) - v.x() * vw.z() * vw.x() -
412 v.y() * vw.z() * vw.y() ) *
413 dzda ) /
414 vmag
415 : Vector( 5, 0 );
416 if ( vmag <= 0.0 )
417 {
418 std::cout << " in fit " << onTrack << ", " << onWire;
419 h.dump();
420 }
421 dchi2da += ( dDistance / eDistance2 ) * dDda;
422 d2chi2d2a += vT_times_v( dDda ) / eDistance2;
423 double pChi2 = dDistance * dDistance / eDistance2;
424 chi2 += pChi2;
425
426 //...Store results...
427 l->update( onTrack, onWire, leftRight, pChi2 );
428 }
429 // break;
430 factor *= 0.75;
431#ifdef TRKRECO_DEBUG_DETAIL
432 std::cout << "factor = " << factor << std::endl;
433 std::cout << "chi2 = " << chi2 << std::endl;
434#endif
435 if ( factor < 0.01 ) break;
436 }
437
438 chi2Old = chi2;
439
440 //...Cal. helix parameters for next loop...
441 if ( allAxial )
442 {
443 f = dchi2da.sub( 1, 3 );
444 e = d2chi2d2a.sub( 1, 3 );
445 f = solve( e, f );
446 da[0] = f[0];
447 da[1] = f[1];
448 da[2] = f[2];
449 da[3] = 0.;
450 da[4] = 0.;
451 }
452 else { da = solve( d2chi2d2a, dchi2da ); }
453
454#ifdef TRKRECO_DEBUG_DETAIL
455 // std::cout << " fit " << nTrial << " : " << da << std::endl;
456 // std::cout << " d2chi " << d2chi2d2a << std::endl;
457 // std::cout << " dchi2 " << dchi2da << std::endl;
458#endif
459
460 a -= factor * da;
461 // a[2] = 0.000000001;
462 t._helix->a( a );
463 ++nTrial;
464 }
465
466 //...Cal. error matrix...
467 SymMatrix Ea( 5, 0 );
468 unsigned dim;
469 if ( allAxial )
470 {
471 dim = 3;
472 SymMatrix Eb( 3, 0 ), Ec( 3, 0 );
473 Eb = d2chi2d2a.sub( 1, 3 );
474 Ec = Eb.inverse( err );
475 Ea[0][0] = Ec[0][0];
476 Ea[0][1] = Ec[0][1];
477 Ea[0][2] = Ec[0][2];
478 Ea[1][1] = Ec[1][1];
479 Ea[1][2] = Ec[1][2];
480 Ea[2][2] = Ec[2][2];
481 }
482 else
483 {
484 dim = 5;
485 Ea = d2chi2d2a.inverse( err );
486 }
487
488 //...Store information...
489 if ( !err )
490 {
491 t._helix->a( a );
492 t._helix->Ea( Ea );
493 }
494 else { err = TFitFailed; }
495
496 t._ndf = nValid - dim;
497 t._chi2 = chi2;
498 // t._fitted = true;
499
500 return err;
501}
HepGeom::Vector3D< double > HepVector3D
HepGeom::Point3D< double > HepPoint3D
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
Double_t x[10]
Double_t time
**********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
Definition KarLud.h:35
IMessageSvc * msgSvc()
#define Convergence
#define NTrailMax
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
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
float dDrift(unsigned) const
returns drift distance error.
float drift(unsigned) const
returns drift distance.
const TMDCWire *const wire(void) const
returns a pointer to a TMDCWire.
unsigned localId(void) const
returns local id in a wire layer.
unsigned layerId(void) const
returns layer id.
const HepVector3D & direction(void) const
returns direction vector of the wire.
bool stereo(void) const
returns true if this wire is in a stereo layer.
const AList< TMLink > & links(unsigned mask=0) const
virtual unsigned objectType(void) const
returns object type.
int t()
Definition t.c:1

◆ fit() [5/6]

int TCosmicFitter::fit ( TTrackBase & ,
float t0Offset ) const

◆ fit() [6/6]

int TCosmicFitter::fit ( TTrackBase & ,
float t0Offset ) const

◆ fitWithCathode() [1/3]

int TCosmicFitter::fitWithCathode ( TTrackBase & ,
float t0Offset = 0.,
float windowSize = 0.6,
int SysCorr = 0 )

◆ fitWithCathode() [2/3]

int TCosmicFitter::fitWithCathode ( TTrackBase & ,
float t0Offset = 0.,
float windowSize = 0.6,
int SysCorr = 0 )

◆ fitWithCathode() [3/3]

int TCosmicFitter::fitWithCathode ( TTrackBase & ,
float t0Offset = 0.,
float windowSize = 0.6,
int SysCorr = 0 )

The documentation for this class was generated from the following files: