BOSS 7.0.2
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)
 
- 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
 
virtual int fit (TTrackBase &) const =0
 
 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
 
virtual int fit (TTrackBase &) const =0
 

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)
 

Detailed Description

A class to fit a TTrackBase object to a helix.

Definition at line 45 of file InstallArea/include/TrkReco/TrkReco/TCosmicFitter.h.

Constructor & Destructor Documentation

◆ TCosmicFitter() [1/2]

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

Constructor.

Definition at line 84 of file TCosmicFitter.cxx.

84 : TMFitter(name) {
85//jialk
86 StatusCode scmgn = Gaudi::svcLocator()->service("MagneticFieldSvc",m_pmgnIMF);
87 if(scmgn!=StatusCode::SUCCESS) {
88 std::cout<< "Unable to open Magnetic field service"<<std::endl;
89 }
90
91}
A class to fit a TTrackBase object.
const std::string & name(void) const
returns name.

◆ ~TCosmicFitter() [1/2]

TCosmicFitter::~TCosmicFitter ( )
virtual

Destructor.

Definition at line 93 of file TCosmicFitter.cxx.

93 {
94}

◆ TCosmicFitter() [2/2]

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

Constructor.

◆ ~TCosmicFitter() [2/2]

virtual TCosmicFitter::~TCosmicFitter ( )
virtual

Destructor.

Member Function Documentation

◆ dump() [1/2]

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

dumps debug information.

◆ dump() [2/2]

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

dumps debug information.

◆ fit() [1/4]

int TCosmicFitter::fit ( TTrackBase b) const
virtual

Implements TMFitter.

Definition at line 97 of file TCosmicFitter.cxx.

97 {
98
99// double t0_bes;
100// TrkReco::t0(t0_bes);
101// const double t0_bes = TrkReco::t0();
102
103 //...Already fitted ?...
104 if (b.fitted()) return TFitAlreadyFitted;
105
106 int err = fit(b, 0.);
107 if (! err) b._fitted = true;
108
109 return err;
110}
int fit(TTrackBase &) const
bool fitted(void) const
returns true if fitted.

Referenced by TBuilderCosmic::buildStereo(), TBuilder0::fit(), and fit().

◆ fit() [2/4]

int TCosmicFitter::fit ( TTrackBase ) const
virtual

Implements TMFitter.

◆ fit() [3/4]

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

Definition at line 113 of file TCosmicFitter.cxx.

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

◆ fit() [4/4]

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

◆ fitWithCathode() [1/2]

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

◆ fitWithCathode() [2/2]

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: