BOSS 8.0.0
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 "TrkBase/TrkRep.h"
19#include "MdcGeom/Constants.h"
20#include "MdcRecoUtil/DifIndepPar.h"
21#include "MdcRecoUtil/DifPoint.h"
22#include "MdcRecoUtil/DifVector.h"
23#include "MdcRecoUtil/Pdt.h"
24#include "MdcRecoUtil/PdtEntry.h"
25#include "ProbTools/ChisqConsistency.h"
26#include "ProxyDict/IfdIntKey.h"
27#include "TrkBase/TrkDifTraj.h"
28#include "TrkBase/TrkErrCode.h"
29#include "TrkBase/TrkExchangePar.h"
30#include "TrkBase/TrkFunctors.h"
31#include "TrkBase/TrkHitOnTrk.h"
32#include "TrkBase/TrkHotListEmpty.h"
33#include "TrkBase/TrkHotListFull.h"
34#include "TrkBase/TrkRecoTrk.h"
35#include <algorithm>
36#include <assert.h>
37#include <iostream>
38using std::cout;
39using std::endl;
40
41TrkRep::TrkRep( TrkRecoTrk* trk, PdtPid::PidType hypo, bool createHotList )
42 : _hotList( createHotList ? new TrkHotListFull : 0 ) {
43 init( trk, hypo );
44}
45
47 : _hotList( hotlist.clone( TrkBase::Functors::cloneHot( this ) ) ) {
48 init( trk, hypo );
49}
50
51TrkRep::TrkRep( TrkHotList& hotlist, TrkRecoTrk* trk, PdtPid::PidType hypo, bool stealHots ) {
52 init( trk, hypo );
53 if ( !stealHots ) { _hotList.reset( hotlist.clone( TrkBase::Functors::cloneHot( this ) ) ); }
54 else { _hotList.reset( new TrkHotListFull( hotlist, setParent( this ) ) ); }
55}
56
57TrkRep::TrkRep( const TrkHotList* hotlist, TrkRecoTrk* trk, PdtPid::PidType hypo ) {
58 // yzhang SegGrouperAx::storePar newTrack come here
59 // yzhang SegGrouperSt::storePar addZValue come here too and hotlist!=0 do clone()
60 init( trk, hypo );
61 _hotList.reset( hotlist != 0 ? hotlist->clone( TrkBase::Functors::cloneHot( this ) )
62 : new TrkHotListFull );
63}
64
66 bool takeownership ) {
67 init( trk, hypo );
68 if ( !takeownership )
69 {
70 _hotList.reset( hotlist != 0 ? hotlist->clone( TrkBase::Functors::cloneHot( this ) )
71 : new TrkHotListFull );
72 }
73 else
74 {
75 assert( hotlist != 0 );
76 _hotList.reset( hotlist->resetParent( setParent( this ) ) );
77 }
78}
79
80// Ctor for reps without hits
81TrkRep::TrkRep( TrkRecoTrk* trk, PdtPid::PidType hypo, int nact, int nsv, int ndc,
82 double stFndRng, double endFndRng )
83 : _hotList( new TrkHotListEmpty( nact, nsv, ndc, stFndRng, endFndRng ) ) {
84 // cout << " in TrkRep copy ctor 1" << endl;//yzhang debug
85
86 init( trk, hypo );
87}
88
89// copy ctor
90TrkRep::TrkRep( const TrkRep& oldRep, TrkRecoTrk* trk, PdtPid::PidType hypo )
91 : TrkFitStatus( oldRep ) {
92 // cout << " in TrkRep copy ctor 2" << endl;//yzhang debug
93
94 init( trk, hypo );
95 // Hots and hotlist have to be cloned in the derived classes
96}
97
99 if ( &right != this )
100 {
101 init( right._parentTrack, right._partHypo );
102 _hotList.reset( right._hotList->clone( this ) );
104 }
105 return *this;
106}
107
108void TrkRep::init( TrkRecoTrk* trk, PdtPid::PidType hypo ) {
109 _parentTrack = trk;
110 _partHypo = hypo;
111 _betainv = -999999.;
112}
113
115
116bool TrkRep::operator==( const TrkRep& rhs ) { return ( &rhs == this ); }
117
119 if ( newHot->isActive() ) setCurrent( false );
120 hotList()->append( newHot );
121}
122
124 if ( theHot->isActive() ) setCurrent( false ); // fit no longer current
125 hotList()->remove( theHot );
126}
127
129 if ( !hot->isActive() )
130 {
131 // make sure this is my hot we're talking about
132 if ( this == hot->getParentRep() )
133 {
134 setCurrent( false );
135 // actually activate the hot; this is now the rep's job
136 hot->setActive( true );
137 }
138 }
139}
140
142 if ( hot->isActive() )
143 {
144 // make sure this is my hot we're talking about
145 if ( this == hot->getParentRep() )
146 {
147 setCurrent( false );
148 // actually deactivate the hot; this is now the rep's job
149 hot->setActive( false );
150 }
151 }
152}
153
154HepPoint3D TrkRep::position( double fltL ) const { return traj().position( fltL ); }
155
156Hep3Vector TrkRep::direction( double fltL ) const { return traj().direction( fltL ); }
157
158double TrkRep::arrivalTime( double fltL ) const {
159 static double cinv = 1. / Constants::c;
160 // Initialize cache
161 if ( _betainv < 0.0 )
162 {
163 double mass2 = Pdt::lookup( particleType() )->mass();
164 mass2 = mass2 * mass2;
165 double ptot2 = momentum( 0. ).mag2();
166 assert( ptot2 != 0.0 );
167 _betainv = sqrt( ( ptot2 + mass2 ) / ptot2 );
168 }
169 double tof = fltL * _betainv * cinv;
170 return trackT0() + tof;
171}
172
173double TrkRep::trackT0() const { return parentTrack()->trackT0(); }
174
175BesPointErr TrkRep::positionErr( double fltL ) const {
176 static DifPoint posD;
177 static DifVector dirD;
178 traj().getDFInfo2( fltL, posD, dirD );
179 HepMatrix err = posD.errorMatrix( posD.x.indepPar()->covariance() );
180 HepPoint3D point( posD.x.number(), posD.y.number(), posD.z.number() );
181 BesError symErr( 3 );
182 symErr.assign( err );
183
184 if ( false )
185 {
186#ifdef MDCPATREC_ROUTINE
187 cout << "ErrMsg(routine) "
188 << "Pos " << err.num_row() << " " << err.num_col() << endl
189 << "output:"
190 << endl
191 // << err(1,1) << endl
192 // << err(2,1) << " " << err(2,2) << endl
193 // << err(3,1) << " " << err(3,2) << " " << err(3,3) << endl
194 << "x deriv: " << endl
195 << posD.x.derivatives() << endl
196 << "y deriv: " << endl
197 << posD.y.derivatives() << endl
198 << endl;
199#endif
200 // }
201
202 Hep3Vector pointDir( point.x(), point.y() );
203 double dirMag = pointDir.mag();
204 double dist = 5.e-3;
205 double delx = dist * point.x() / dirMag;
206 double dely = dist * point.y() / dirMag;
207 int ierr = 0;
208 HepMatrix weight = err.inverse( ierr );
209 double chisq = weight( 1, 1 ) * delx * delx + 2 * weight( 2, 1 ) * delx * dely +
210 weight( 2, 2 ) * dely * dely;
211#ifdef MDCPATREC_DEBUG
212 cout << point << endl;
213 cout << symErr << endl;
214 cout << "delta: " << delx << " " << dely << endl;
215 cout << "chisq: " << chisq << endl;
216#endif
217 double phi0 = helix( fltL ).phi0();
218 delx = dist * cos( phi0 );
219 dely = dist * sin( phi0 );
220 chisq = weight( 1, 1 ) * delx * delx + 2 * weight( 2, 1 ) * delx * dely +
221 weight( 2, 2 ) * dely * dely;
222#ifdef MDCPATREC_DEBUG
223 cout << "delta: " << delx << " " << dely << endl;
224 cout << "chisq: " << chisq << endl;
225 cout << endl << endl;
226#endif
227 }
228 return BesPointErr( point, symErr );
229}
230
231BesVectorErr TrkRep::directionErr( double fltL ) const {
232 static DifPoint posD;
233 static DifVector dirD;
234 traj().getDFInfo2( fltL, posD, dirD );
235 BesError symErr( 3 );
236 symErr.assign( dirD.errorMatrix( dirD.x.indepPar()->covariance() ) );
237 Hep3Vector dir( dirD.x.number(), dirD.y.number(), dirD.z.number() );
238 return BesVectorErr( dir, symErr );
239}
240
241double TrkRep::startValidRange() const { return traj().lowRange(); }
242
243double TrkRep::endValidRange() const { return traj().hiRange(); }
244
245double TrkRep::startFoundRange() const { return hotList()->startFoundRange(); }
246
247double TrkRep::endFoundRange() const { return hotList()->endFoundRange(); }
248
249PdtPid::PidType TrkRep::particleType() const { return _partHypo; }
250
251const IfdKey& TrkRep::myKey() const {
252 // This provides a default key (used to provide Rep-specific interfaces
253 // to TrkRecoTrk consumers).
254 static IfdIntKey _theKey( 0 );
255 return _theKey;
256}
257
259 setCurrent( false );
260 hotList()->updateHots();
261}
262
263int TrkRep::nActive() const { return hotList()->nActive(); }
264
265int TrkRep::nSvt() const { return hotList()->nSvt(); }
266
267int TrkRep::nMdc() const { return hotList()->nMdc(); }
268
269bool TrkRep::resid( const TrkHitOnTrk* h, double& residual, double& residErr,
270 bool exclude ) const {
271 assert( h != 0 );
272 if ( h->parentRep() != this ) return false; // HOT must belong to Rep
273 if ( !h->hasResidual() ) return false; // Residual must be available
274 if ( exclude ) return false; // FIXME: Can't do unbiased residuals (yet!)
275
276 residual = h->residual();
277 residErr = h->hitRms();
278 return true;
279}
280
282 if ( fitValid() ) return ChisqConsistency( chisq(), nDof() );
283 else return ChisqConsistency();
284}
**********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
HepGeom::Point3D< double > HepPoint3D
*********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
HepVector derivatives() const
Definition DifNumber.cxx:45
HepSymMatrix errorMatrix(const HepSymMatrix &e) const
Definition DifVector.cxx:43
static PdtEntry * lookup(const std::string &name)
Definition Pdt.cxx:183
virtual HepPoint3D position(double) const =0
virtual Hep3Vector direction(double) const =0
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
TrkFitStatus & operator=(const TrkFitStatus &)
virtual TrkExchangePar helix(double fltL) const =0
double residual() const
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)
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
virtual void removeHot(TrkHitOnTrk *theHot)
Definition TrkRep.cxx:123
virtual HepPoint3D position(double fltL) const
Definition TrkRep.cxx:154
double trackT0() const
Definition TrkRep.cxx:173
virtual ~TrkRep()
Definition TrkRep.cxx:114
virtual double arrivalTime(double fltL) const
Definition TrkRep.cxx:158
virtual int nSvt() const
Definition TrkRep.cxx:265
virtual int nActive() const
Definition TrkRep.cxx:263
virtual BesPointErr positionErr(double fltL) const
Definition TrkRep.cxx:175
virtual double endFoundRange() const
Definition TrkRep.cxx:247
TrkRep & operator=(const TrkRep &)
Definition TrkRep.cxx:98
virtual PdtPid::PidType particleType() const
Definition TrkRep.cxx:249
virtual void deactivateHot(TrkHitOnTrk *theHot)
Definition TrkRep.cxx:141
virtual TrkRep * clone(TrkRecoTrk *newTrack) const =0
virtual const IfdKey & myKey() const
Definition TrkRep.cxx:251
virtual void activateHot(TrkHitOnTrk *theHot)
Definition TrkRep.cxx:128
TrkRep(const TrkHotList &inHots, TrkRecoTrk *trk, PdtPid::PidType hypo)
Definition TrkRep.cxx:46
virtual bool resid(const TrkHitOnTrk *theHot, double &residual, double &residErr, bool exclude=false) const
Definition TrkRep.cxx:269
virtual void updateHots()
Definition TrkRep.cxx:258
double endValidRange() const
Definition TrkRep.cxx:243
virtual ChisqConsistency chisqConsistency() const
Definition TrkRep.cxx:281
double startValidRange() const
Definition TrkRep.cxx:241
virtual BesVectorErr directionErr(double fltL) const
Definition TrkRep.cxx:231
virtual void addHot(TrkHitOnTrk *theHot)
Definition TrkRep.cxx:118
virtual double startFoundRange() const
Definition TrkRep.cxx:245
virtual Hep3Vector direction(double fltL) const
Definition TrkRep.cxx:156
virtual int nMdc() const
Definition TrkRep.cxx:267
bool operator==(const TrkRep &)
Definition TrkRep.cxx:116