BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
T3DLineFitter Class Reference

A class to fit a TTrackBase object to a 3D line. More...

#include <T3DLineFitter.h>

+ Inheritance diagram for T3DLineFitter:

Public Member Functions

 T3DLineFitter (const std::string &name)
 Constructor.
 
 T3DLineFitter (const std::string &name, bool m_sag, int m_prop, bool m_tof)
 
virtual ~T3DLineFitter ()
 Destructor.
 
void dump (const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
 dumps debug information.
 
virtual int fit (TTrackBase &) const
 
virtual int fit (TTrackBase &, float t0Offset) const
 
void sag (bool)
 
void propagation (int)
 
void tof (bool)
 
- 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
 

Additional Inherited Members

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

Detailed Description

A class to fit a TTrackBase object to a 3D line.

Definition at line 41 of file T3DLineFitter.h.

Constructor & Destructor Documentation

◆ T3DLineFitter() [1/2]

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

Constructor.

Definition at line 80 of file T3DLineFitter.cxx.

81 : TMFitter(name),
82// _sag(true),_propagation(1),_tof(false){
83 _sag(false),_propagation(0),_tof(true){ //Liuqg, tmp
84
85}
A class to fit a TTrackBase object.
Definition: TMFitter.h:34
const std::string & name(void) const
returns name.
Definition: TMFitter.h:73

◆ T3DLineFitter() [2/2]

T3DLineFitter::T3DLineFitter ( const std::string &  name,
bool  m_sag,
int  m_prop,
bool  m_tof 
)

Definition at line 86 of file T3DLineFitter.cxx.

88 : TMFitter(name),
89 _sag(m_sag),_propagation(m_prop),_tof(m_tof){
90}
NTuple::Array< double > m_tof
Definition: MdcHistItem.h:105

◆ ~T3DLineFitter()

T3DLineFitter::~T3DLineFitter ( )
virtual

Destructor.

Definition at line 92 of file T3DLineFitter.cxx.

92 {
93}

Member Function Documentation

◆ dump()

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

dumps debug information.

◆ fit() [1/2]

int T3DLineFitter::fit ( TTrackBase tb) const
virtual

Implements TMFitter.

Definition at line 211 of file T3DLineFitter.cxx.

211 {
212 return fit(tb,0);
213}
virtual int fit(TTrackBase &) const

Referenced by fit().

◆ fit() [2/2]

int T3DLineFitter::fit ( TTrackBase tb,
float  t0Offset 
) const
virtual

Definition at line 215 of file T3DLineFitter.cxx.

215 {
216
217 //std::cout<<"T3DLineFitter::fit start"<<std::endl;
218
219 //...Type check...
220 if(tb.objectType() != Line3D) return TFitUnavailable;
221 T3DLine& t = (T3DLine&) tb;
222
223 //...Already fitted ?...
224 if(t.fitted()) return TFitAlreadyFitted;
225
226 //...Count # of hits...
227 AList<TMLink> cores = t.cores();
228 unsigned nCores = cores.length();
229 unsigned nStereoCores = NStereoHits(cores);
230
231
232 //...Check # of hits...
233 bool flag2D = false;
234 if ((nStereoCores == 0) && (nCores > 3)) flag2D = true;
235 else if ((nStereoCores < 2) || (nCores - nStereoCores < 3))
236 return TFitErrorFewHits;
237
238 //...Move pivot to ORIGIN...
239 const HepPoint3D pivot_bak = t.pivot();
240 t.pivot(ORIGIN);
241
242 //...Setup...
243 Vector a(4),da(4);
244 a = t.a();
245 Vector dxda(4);
246 Vector dyda(4);
247 Vector dzda(4);
248 Vector dDda(4);
249 Vector dchi2da(4);
250 SymMatrix d2chi2d2a(4,0);
251 static const SymMatrix zero4(4,0);
252 double chi2;
253 double chi2Old = DBL_MAX;
254 double factor = 1.0;
255 int err = 0;
256 SymMatrix e(2,0);
257 Vector f(2);
258
259 //...Fitting loop...
260 unsigned nTrial = 0;
261 while(nTrial < 100){
262
263 //...Set up...
264 chi2 = 0;
265 for (unsigned j=0;j<4;j++) dchi2da[j]=0;
266 d2chi2d2a=zero4;
267
268 //...Loop with hits...
269 unsigned i=0;
270 while(TMLink* l = cores[i++]){
271 const TMDCWireHit& h = *l->hit();
272
273 //...Cal. closest points...
274 t.approach(*l,_sag);
275 const HepPoint3D& onTrack=l->positionOnTrack();
276 const HepPoint3D& onWire=l->positionOnWire();
277 unsigned leftRight = WireHitRight;
278 if (onWire.cross(onTrack).z() < 0.) leftRight = WireHitLeft;
279
280 //...Obtain drift distance and its error...
281 double distance;
282 double eDistance;
283 drift(t, * l, t0Offset, distance, eDistance);
284 l->drift(distance,0);
285 l->drift(distance,1);
286 l->dDrift(eDistance,0);
287 l->dDrift(eDistance,1);
288 double eDistance2 = eDistance * eDistance;
289 //cout<<"distance: "<< distance << " eDistance: " << eDistance << endl;
290
291 //...Residual...
292 HepVector3D v = onTrack - onWire;
293 double vmag = v.mag();
294 double dDistance = vmag - distance;
295
296 HepVector3D vw;
297 //...dxda...
298 this->dxda(*l, t, dxda, dyda, dzda, vw);
299
300 //...Chi2 related...
301 dDda = (vmag > 0.)
302 ? ((v.x() * (1. - vw.x() * vw.x()) -
303 v.y() * vw.x() * vw.y() - v.z() * vw.x() * vw.z())
304 * dxda +
305 (v.y() * (1. - vw.y() * vw.y()) -
306 v.z() * vw.y() * vw.z() - v.x() * vw.y() * vw.x())
307 * dyda +
308 (v.z() * (1. - vw.z() * vw.z()) -
309 v.x() * vw.z() * vw.x() - v.y() * vw.z() * vw.y())
310 * dzda) / vmag : Vector(4,0);
311 if (vmag <= 0.0) {
312 std::cout << " in fit " << onTrack << ", " << onWire;
313 h.dump();
314 }
315 dchi2da += (dDistance / eDistance2) * dDda;
316 d2chi2d2a += vT_times_v(dDda) / eDistance2;
317 double pChi2 = dDistance * dDistance / eDistance2;
318 chi2 += pChi2;
319
320 //...Store results...
321 l->update(onTrack, onWire, leftRight, pChi2);
322 }
323
324 //...Check condition...
325 double change = chi2Old - chi2;
326
327 if (fabs(change) < 1.0e-5) break;
328 if (change < 0.) {
329 a += factor * da; //recover
330 factor *= 0.1;
331 }else{
332 chi2Old = chi2;
333 if(flag2D){
334 f = dchi2da.sub(1,2);
335 e = d2chi2d2a.sub(1,2);
336 f = solve(e,f);
337 da[0]=f[0];
338 da[1]=f[1];
339 da[2]= 0;
340 da[3]= 0;
341 }else{
342 //...Cal. helix parameters for next loop...
343 da = solve(d2chi2d2a, dchi2da);
344 }
345 }
346 a -= factor * da;
347 t.a(a);
348 ++nTrial;
349 }
350
351 //...Cal. error matrix...
352 SymMatrix Ea(4,0);
353 unsigned dim;
354 if(flag2D){
355 dim=2;
356 SymMatrix Eb(3,0),Ec(3,0);
357 Eb = d2chi2d2a.sub(1,3);
358 Ec = Eb.inverse(err);
359 Ea[0][0] = Ec[0][0];
360 Ea[0][1] = Ec[0][1];
361 Ea[0][2] = Ec[0][2];
362 Ea[1][1] = Ec[1][1];
363 Ea[1][2] = Ec[1][2];
364 Ea[2][2] = Ec[2][2];
365 }else{
366 dim=4;
367 Ea = d2chi2d2a.inverse(err);
368 }
369
370 //...Store information...
371 if(! err){
372 t.a(a);
373 t.Ea(Ea);
374 t._fitted = true;
375 if (flag2D) err = T3DLine2DFit;
376 }else{
377 err = TFitFailed;
378 }
379
380 t._ndf = nCores - dim;
381 t._chi2 = chi2;
382
383 //...Recover pivot...
384 t.pivot(pivot_bak);
385
386 return err;
387}
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
#define DBL_MAX
Definition: KalFitAlg.h:13
**********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 T3DLine2DFit
#define Line3D
Definition: T3DLine.h:21
const HepPoint3D ORIGIN
Constants.
Definition: TMDCUtil.cxx:47
#define WireHitLeft
Definition: TMDCWireHit.h:21
#define WireHitRight
Definition: TMDCWireHit.h:22
#define TFitAlreadyFitted
Definition: TMFitter.h:28
#define TFitFailed
Definition: TMFitter.h:30
#define TFitUnavailable
Definition: TMFitter.h:31
#define TFitErrorFewHits
Definition: TMFitter.h:29
TTree * t
Definition: binning.cxx:23
A class to represent a track in tracking.
Definition: T3DLine.h:50
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
Definition: TMDCWireHit.cxx:64
virtual unsigned objectType(void) const
returns object type.
Definition: TTrackBase.h:268

◆ propagation()

void T3DLineFitter::propagation ( int  _in)

Definition at line 98 of file T3DLineFitter.cxx.

98 {
99 _propagation = _in;
100}

◆ sag()

void T3DLineFitter::sag ( bool  _in)

Definition at line 95 of file T3DLineFitter.cxx.

95 {
96 _sag = _in;
97}

◆ tof()

void T3DLineFitter::tof ( bool  _in)

Definition at line 101 of file T3DLineFitter.cxx.

101 {
102 _tof = _in;
103}

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