BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
TrkRep.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: TrkRep.cxx,v 1.3 2005/12/01 06:18:42 zhangy Exp $
4//
5// Description:
6//
7// Environment:
8// Software developed for the BaBar Detector at the SLAC B-Factory.
9//
10// Authors: Steve Schaffner
11//
12// Revision History (started 2002/05/22)
13// 20020522 M. Kelsey -- Remove assert() from resid(HOT*...). Replace
14// with sanity checks on HOT/Rep association and whether HOT
15// has already-computed residual. Return value used to
16// flag sanity checks and "trustworthiness" of results.
17//------------------------------------------------------------------------
18#include "MdcGeom/Constants.h"
19#include <assert.h>
20#include <algorithm>
21#include <iostream>
22#include "TrkBase/TrkRep.h"
23#include "MdcRecoUtil/Pdt.h"
25#include "TrkBase/TrkDifTraj.h"
28#include "TrkBase/TrkHitOnTrk.h"
29#include "TrkBase/TrkRecoTrk.h"
30#include "TrkBase/TrkFunctors.h"
31#include "TrkBase/TrkErrCode.h"
36#include "ProxyDict/IfdIntKey.h"
38using std::cout;
39using std::endl;
40
41TrkRep::TrkRep(TrkRecoTrk* trk, PdtPid::PidType hypo,bool createHotList)
42 : _hotList( createHotList?new TrkHotListFull:0 )
43{
44 init(trk, hypo);
45}
46
48 PdtPid::PidType hypo)
49 :_hotList( hotlist.clone(TrkBase::Functors::cloneHot(this)) )
50{
51 init(trk, hypo);
52}
53
55 PdtPid::PidType hypo, bool stealHots)
56{
57 init(trk, hypo);
58 if (!stealHots) {
59 _hotList.reset( hotlist.clone(TrkBase::Functors::cloneHot(this)) );
60 } else {
61 _hotList.reset( new TrkHotListFull(hotlist,setParent(this)) );
62 }
63}
64
66 PdtPid::PidType hypo)
67{
68 //yzhang SegGrouperAx::storePar newTrack come here
69 //yzhang SegGrouperSt::storePar addZValue come here too and hotlist!=0 do clone()
70 init(trk, hypo);
71 _hotList.reset( hotlist!=0?
72 hotlist->clone(TrkBase::Functors::cloneHot(this)):
73 new TrkHotListFull );
74}
75
77 PdtPid::PidType hypo,bool takeownership)
78{
79 init(trk, hypo);
80 if (!takeownership) {
81 _hotList.reset( hotlist!=0?
82 hotlist->clone(TrkBase::Functors::cloneHot(this)):
83 new TrkHotListFull );
84 } else {
85 assert(hotlist!=0);
86 _hotList.reset( hotlist->resetParent(setParent(this)) );
87 }
88}
89
90// Ctor for reps without hits
91TrkRep::TrkRep(TrkRecoTrk* trk, PdtPid::PidType hypo, int nact, int nsv,
92 int ndc, double stFndRng, double endFndRng)
93 :_hotList(new TrkHotListEmpty(nact, nsv, ndc, stFndRng, endFndRng))
94{
95// cout << " in TrkRep copy ctor 1" << endl;//yzhang debug
96
97 init(trk, hypo);
98}
99
100// copy ctor
102 TrkFitStatus(oldRep)
103{
104// cout << " in TrkRep copy ctor 2" << endl;//yzhang debug
105
106 init(trk, hypo);
107 // Hots and hotlist have to be cloned in the derived classes
108}
109
110TrkRep&
112{
113 if(&right != this){
114 init(right._parentTrack, right._partHypo);
115 _hotList.reset( right._hotList->clone(this) );
117 }
118 return *this;
119}
120
121void
122TrkRep::init(TrkRecoTrk* trk, PdtPid::PidType hypo)
123{
124 _parentTrack = trk;
125 _partHypo = hypo;
126 _betainv = -999999.;
127}
128
130{
131}
132
133bool
135{
136 return (&rhs == this);
137}
138
139void
141{
142 if (newHot->isActive()) setCurrent(false);
143 hotList()->append(newHot);
144}
145
146void
148{
149 if(theHot->isActive()) setCurrent(false); // fit no longer current
150 hotList()->remove(theHot);
151}
152
153void
155{
156 if(!hot->isActive()){
157// make sure this is my hot we're talking about
158 if(this == hot->getParentRep()){
159 setCurrent(false);
160// actually activate the hot; this is now the rep's job
161 hot->setActive(true);
162 }
163 }
164}
165
166void
168{
169 if(hot->isActive()){
170// make sure this is my hot we're talking about
171 if(this == hot->getParentRep()){
172 setCurrent(false);
173// actually deactivate the hot; this is now the rep's job
174 hot->setActive(false);
175 }
176 }
177}
178
180TrkRep::position(double fltL) const
181{
182 return traj().position(fltL);
183}
184
185Hep3Vector
186TrkRep::direction(double fltL) const
187{
188 return traj().direction(fltL);
189}
190
191double
192TrkRep::arrivalTime(double fltL) const
193{
194 static double cinv = 1./Constants::c;
195 // Initialize cache
196 if (_betainv < 0.0) {
197 double mass2 = Pdt::lookup(particleType())->mass();
198 mass2 = mass2 * mass2;
199 double ptot2 = momentum(0.).mag2();
200 assert(ptot2 != 0.0);
201 _betainv = sqrt( (ptot2 + mass2)/ ptot2);
202 }
203 double tof = fltL * _betainv * cinv;
204 return trackT0() + tof;
205}
206
207double
209{
210 return parentTrack()->trackT0();
211}
212
214TrkRep::positionErr(double fltL) const
215{
216 static DifPoint posD;
217 static DifVector dirD;
218 traj().getDFInfo2(fltL, posD, dirD);
219 HepMatrix err = posD.errorMatrix( posD.x.indepPar()->covariance() );
220 HepPoint3D point(posD.x.number(), posD.y.number(), posD.z.number());
221 BesError symErr(3);
222 symErr.assign(err);
223
224 if (false) {
225#ifdef MDCPATREC_ROUTINE
226 cout<< "ErrMsg(routine) " << "Pos "
227 << err.num_row() << " " << err.num_col() << endl
228 << "output:" << endl
229 // << err(1,1) << endl
230 // << err(2,1) << " " << err(2,2) << endl
231 // << err(3,1) << " " << err(3,2) << " " << err(3,3) << endl
232 << "x deriv: " << endl
233 << posD.x.derivatives() << endl
234 << "y deriv: " << endl
235 << posD.y.derivatives() << endl
236 << endl;
237#endif
238 // }
239
240 Hep3Vector pointDir(point.x(), point.y());
241 double dirMag = pointDir.mag();
242 double dist = 5.e-3;
243 double delx = dist * point.x() / dirMag;
244 double dely = dist * point.y() / dirMag;
245 int ierr = 0;
246 HepMatrix weight = err.inverse(ierr);
247 double chisq = weight(1,1) * delx * delx +
248 2 * weight(2,1) * delx * dely +
249 weight(2,2) * dely * dely;
250#ifdef MDCPATREC_DEBUG
251 cout << point << endl;
252 cout << symErr << endl;
253 cout << "delta: " << delx << " " << dely << endl;
254 cout << "chisq: " << chisq << endl;
255#endif
256 double phi0 = helix(fltL).phi0();
257 delx = dist * cos(phi0);
258 dely = dist * sin(phi0);
259 chisq = weight(1,1) * delx * delx +
260 2 * weight(2,1) * delx * dely +
261 weight(2,2) * dely * dely;
262#ifdef MDCPATREC_DEBUG
263 cout << "delta: " << delx << " " << dely << endl;
264 cout << "chisq: " << chisq << endl;
265 cout << endl << endl;
266#endif
267 }
268 return BesPointErr(point, symErr);
269}
270
272TrkRep::directionErr(double fltL) const
273{
274 static DifPoint posD;
275 static DifVector dirD;
276 traj().getDFInfo2(fltL, posD, dirD);
277 BesError symErr(3);
278 symErr.assign( dirD.errorMatrix( dirD.x.indepPar()->covariance() ));
279 Hep3Vector dir(dirD.x.number(), dirD.y.number(), dirD.z.number());
280 return BesVectorErr(dir, symErr);
281}
282
283double
285{
286 return traj().lowRange();
287}
288
289double
291{
292 return traj().hiRange();
293}
294
295double
297{
298 return hotList()->startFoundRange();
299}
300
301double
303{
304 return hotList()->endFoundRange();
305}
306
309{
310 return _partHypo;
311}
312
313const IfdKey&
315{
316 // This provides a default key (used to provide Rep-specific interfaces
317 // to TrkRecoTrk consumers).
318 static IfdIntKey _theKey(0);
319 return _theKey;
320}
321
322void
324{
325 setCurrent(false);
326 hotList()->updateHots();
327}
328
329int
331{
332 return hotList()->nActive();
333}
334
335int
337{
338 return hotList()->nSvt();
339}
340
341int
343{
344 return hotList()->nMdc();
345}
346
347bool
349 double& residual, double& residErr,
350 bool exclude) const
351{
352 assert (h != 0);
353 if (h->parentRep() != this) return false; // HOT must belong to Rep
354 if (!h->hasResidual()) return false; // Residual must be available
355 if (exclude) return false; // FIXME: Can't do unbiased residuals (yet!)
356
357 residual=h->residual();
358 residErr=h->hitRms();
359 return true;
360}
361
364 if(fitValid())
365 return ChisqConsistency(chisq(),nDof());
366 else
367 return ChisqConsistency();
368}
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
**********INTEGER nmxhep !maximum number of particles DOUBLE PRECISION vhep INTEGER jdahep COMMON hepevt $ !serial number $ !number of particles $ !status code $ !particle ident KF $ !parent particles $ !childreen particles $ !four momentum
*********Class see also m_nmax DOUBLE PRECISION m_MasPhot DOUBLE PRECISION m_phsu DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_r2 DOUBLE PRECISION m_WtMass INTEGER m_nmax INTEGER m_Nevgen INTEGER m_IsFSR INTEGER m_MarTot *COMMON c_KarFin $ !Output file $ !Event serial number $ !alpha QED at Thomson limit $ !minimum energy at CMS for remooval $ !infrared dimensionless $ !dummy photon IR regulator $ !crude photon multiplicity enhancement factor *EVENT $ !MC crude volume of PhhSpace *Sfactors $ !YFS formfactor IR part only $ !YFS formfactor non IR finite part $ !mass weight
Definition: KarFin.h:34
static const double c
Definition: Constants.h:43
HepSymMatrix & covariance()
Definition: DifIndepPar.h:53
double number() const
Definition: DifNumber.h:87
HepVector derivatives() const
Definition: DifNumber.cxx:46
const DifIndepPar * indepPar() const
Definition: DifNumber.h:93
DifNumber y
Definition: DifVector.h:149
DifNumber x
Definition: DifVector.h:148
DifNumber z
Definition: DifVector.h:150
HepSymMatrix errorMatrix(const HepSymMatrix &e) const
Definition: DifVector.cxx:54
Definition: IfdKey.h:48
float mass() const
Definition: PdtEntry.h:55
PidType
Definition: PdtPid.h:11
static PdtEntry * lookup(const std::string &name)
Definition: Pdt.cxx:207
virtual HepPoint3D position(double) const =0
double lowRange() const
Definition: Trajectory.h:91
virtual Hep3Vector direction(double) const =0
double hiRange() const
Definition: Trajectory.h:92
virtual double chisq() const =0
virtual int nDof() const =0
virtual const TrkDifTraj & traj() const =0
virtual void getDFInfo2(double fltLen, DifPoint &pos, DifVector &direction) const
Definition: TrkDifTraj.cxx:25
double phi0() const
bool fitValid() const
Definition: TrkFitStatus.h:34
void setCurrent(bool c)
Definition: TrkFitStatus.h:39
TrkFitStatus & operator=(const TrkFitStatus &)
virtual TrkExchangePar helix(double fltL) const =0
void setParent(TrkHitOnTrk &hot, TrkRep *parent) const
double residual() const
TrkRep * parentRep() const
Definition: TrkHitOnTrk.h:177
bool hasResidual() const
Definition: TrkHitOnTrk.h:104
double hitRms() const
Definition: TrkHitOnTrk.h:89
const TrkRep * getParentRep() const
Definition: TrkHitOnTrk.h:73
bool isActive() const
Definition: TrkHitOnTrk.h:200
virtual void remove(TrkHitOnTrk *)=0
virtual void append(TrkHitOnTrk *)=0
virtual double endFoundRange() const =0
virtual int nSvt(TrkEnums::TrkViewInfo view=TrkEnums::bothView) const =0
virtual TrkHotList * clone(TrkBase::Functors::cloneHot) const =0
virtual TrkHotList * resetParent(TrkBase::Functors::setParent)
Definition: TrkHotList.cxx:64
virtual double startFoundRange() const =0
virtual int nActive(TrkEnums::TrkViewInfo view=TrkEnums::bothView) const =0
virtual int nMdc(TrkEnums::TrkViewInfo view=TrkEnums::bothView) const =0
virtual void updateHots()=0
double trackT0() const
Definition: TrkRecoTrk.cxx:140
Definition: TrkRep.h:43
std::auto_ptr< TrkHotList > _hotList
Definition: TrkRep.h:131
virtual void removeHot(TrkHitOnTrk *theHot)
Definition: TrkRep.cxx:147
virtual HepPoint3D position(double fltL) const
Definition: TrkRep.cxx:180
double trackT0() const
Definition: TrkRep.cxx:208
virtual ~TrkRep()
Definition: TrkRep.cxx:129
virtual double arrivalTime(double fltL) const
Definition: TrkRep.cxx:192
TrkRecoTrk * parentTrack()
Definition: TrkRep.h:82
virtual int nSvt() const
Definition: TrkRep.cxx:336
virtual int nActive() const
Definition: TrkRep.cxx:330
virtual BesPointErr positionErr(double fltL) const
Definition: TrkRep.cxx:214
virtual double endFoundRange() const
Definition: TrkRep.cxx:302
TrkRep & operator=(const TrkRep &)
Definition: TrkRep.cxx:111
virtual PdtPid::PidType particleType() const
Definition: TrkRep.cxx:308
virtual void deactivateHot(TrkHitOnTrk *theHot)
Definition: TrkRep.cxx:167
virtual const IfdKey & myKey() const
Definition: TrkRep.cxx:314
virtual void activateHot(TrkHitOnTrk *theHot)
Definition: TrkRep.cxx:154
TrkRep(const TrkHotList &inHots, TrkRecoTrk *trk, PdtPid::PidType hypo)
Definition: TrkRep.cxx:47
virtual bool resid(const TrkHitOnTrk *theHot, double &residual, double &residErr, bool exclude=false) const
Definition: TrkRep.cxx:348
virtual void updateHots()
Definition: TrkRep.cxx:323
double endValidRange() const
Definition: TrkRep.cxx:290
virtual ChisqConsistency chisqConsistency() const
Definition: TrkRep.cxx:363
double startValidRange() const
Definition: TrkRep.cxx:284
virtual BesVectorErr directionErr(double fltL) const
Definition: TrkRep.cxx:272
virtual TrkHotList * hotList()
Definition: TrkRep.h:109
virtual void addHot(TrkHitOnTrk *theHot)
Definition: TrkRep.cxx:140
virtual double startFoundRange() const
Definition: TrkRep.cxx:296
virtual Hep3Vector direction(double fltL) const
Definition: TrkRep.cxx:186
virtual int nMdc() const
Definition: TrkRep.cxx:342
bool operator==(const TrkRep &)
Definition: TrkRep.cxx:134