CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
TrkHitOnTrk.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: TrkHitOnTrk.cxx,v 1.5 2010/09/26 00:31:59 zhangy Exp $
4//
5// Description:
6//
7//
8// Environment:
9// Software developed for the BaBar Detector at the SLAC B-Factory.
10//
11// Author(s): Steve Schaffner
12//
13//
14// Modified 3-july-97 by Leon Rochester to add '<' & '==' operators for
15// Roguewave Sorted Vector
16//------------------------------------------------------------------------
17#include "TrkBase/TrkHitOnTrk.h"
18#include <assert.h>
19#include "TrkBase/TrkRecoTrk.h"
20#include "TrkBase/TrkFundHit.h"
21#include "TrkBase/TrkRep.h"
22#include "TrkBase/TrkDifTraj.h"
23#include "TrkBase/TrkPoca.h"
24#include "TrkBase/TrkDifPoca.h"
25#include "TrkBase/TrkSimpTraj.h"
26//#include "MdcData/MdcHit.h"//yzhang debug
27using std::endl;
28using std::ostream;
29
30const MdcHitOnTrack* TrkHitOnTrk::mdcHitOnTrack() const {return 0;}
31const SvtHitOnTrack* TrkHitOnTrk::svtHitOnTrack() const {return 0;}
32
33TrkHitOnTrk::TrkHitOnTrk(const TrkFundHit* hit,double tolerance) :
34 _parentRep(0),
35 _theHit(const_cast<TrkFundHit*>(hit)),
36 _isActive(true),
37 _isUsable(true),
38 //make caches invalid
39 _hitRms(-9.e50),
40 _trkLen(0.0),
41 _hitLen(0.0),
42 _trkTraj(0),
43 _poca(0),
44 _tolerance(tolerance)
45{ }
46
47// This is effectively a copy ctor:
49 const TrkDifTraj *trkTraj)
50 : _parentRep(newRep),
51 _theHit(oldHit._theHit),
52 _isActive(oldHit._isActive),
53 _isUsable(oldHit._isUsable),
54 _hitRms(oldHit._hitRms),
55 _trkLen(oldHit._trkLen),
56 _hitLen(oldHit._hitLen),
57 _resid(9999.9),
58 _trkTraj(0),
59 _poca(0),
60 _tolerance(oldHit._tolerance)
61{
62 assert (0 != newRep);
63 if( oldHit._trkTraj!=0 && trkTraj!=0 && oldHit._trkTraj == trkTraj ) {
64 // re-use cache as traj are the same
65 _resid=oldHit._resid;
67 _poca = (oldHit._poca==0 ? 0 :new TrkPoca(*oldHit._poca));
68 } else {
69 double fl = oldHit.fltLen();
70 double dum;
71 const TrkSimpTraj *t1= (oldHit._trkTraj==0?0:oldHit._trkTraj->localTrajectory(fl,dum));
72 const TrkSimpTraj *t2= (trkTraj==0?0:trkTraj->localTrajectory(fl,dum));
73 if( t1 != 0 && t2 != 0 && t1->parameters()->parameter() == t2->parameters()->parameter() ) {
74 // re-use cache as traj are sufficiently equiv
75 _resid=oldHit._resid;
77 _poca = (oldHit._poca==0 ? 0: new TrkPoca(*oldHit._poca));
78
79 }
80 }
81 // Only record hots if on default TrkRep
83 setUsedHit();
84 }
85}
86
88{
89 delete _poca;
90 if ( hit() != 0 && getParentRep() != 0 ) {
92 }
93}
94
95void
97{
98 if (!isUsable() || isActive()==turnOn) return;
99 if (getParentRep() != 0) { // needed until Rep-less HoTs go away
100 turnOn ? parentRep()->activateHot(this)
101 : parentRep()->deactivateHot(this);
102 } else {
103 _isActive = turnOn;
104 }
105}
106
107void
109{
110 _isUsable = usability;
111 if (isActive() && !isUsable()) {
112 _isActive = false;
113 if(getParentRep() != 0)parentRep()->deactivateHot(this);
114 }
115 if (!isActive() && mustUse()) {
116 _isActive = true;
117 if(getParentRep() != 0)parentRep()->activateHot(this);
118 }
119}
120
121double
123{
124 // could be cached
125 double rms=hitRms();
126 assert(rms > 0);
127 return double(1) / ( rms * rms );
128}
129
130void
131TrkHitOnTrk::print(ostream& o) const
132{
133 hit()->printAll(o);
134 o << " hitlen " << hitLen()
135 << " fltlen " << fltLen()
136 << " act " << (isActive() != 0) << endl;
137}
138
139void
140TrkHitOnTrk::printAll(ostream& o) const
141{
142 print(o);
143}
144
147{
148 return parentRep()->parentTrack();
149}
150
151const TrkRecoTrk*
153{
154 return getParentRep()->parentTrack();
155}
156
159{
160 return getParentRep()->particleType();
161}
162
163 void
165{
166 if (hit() != 0) hit()->setUsedHit(this);
167}
168
169 void
171{
172 if (hit() != 0) hit()->setUnusedHit(this);
173}
174
176{
177 return this == &rhs;
178}
179
180int
182{
183 return 0;// by default no ambiguity
184}
185
186 void
188{} // by default nothing to set
189
190double
191TrkHitOnTrk::resid(bool exclude) const
192{
193 double r(-99999.9),re(-9999.9);
194 bool s=getParentRep()->resid(this,r,re,exclude);
195 if (!s && r<-99999.8) {
196#ifdef MDCPATREC_ROUTINE
197 std::cout<<"ErrMsg(routine) "
198 << "error calling parentRep()->residual()" << std::endl;
199#endif
200 }
201 return r;
202}
203
204bool
205TrkHitOnTrk::resid(double &resid, double &residErr, bool exclude) const
206{
207 assert(getParentRep()!=0);
208 return getParentRep()->resid(this,resid,residErr,exclude);
209}
210
211double
213{
214 assert (_trkTraj == &(getParentRep()->traj()));
215 return _resid;
216}
217
219TrkHitOnTrk::updatePoca(const TrkDifTraj* trkTraj, bool maintainAmb)
220{
222 if (_poca==0) {
223 _poca = new TrkPoca(*_trkTraj,fltLen(),
225 } else {
228 }
229 if(_poca->status().failure()) {
230 if(isActive()){
231#ifdef MDCPATREC_WARNING
232 std::cout<<"ErrMsg(warning) "
233 << " TrkPoca failed in TrkHitOnTrk::updatePoca"
234 << std::endl;
235#endif
236 }
237 delete _poca; _poca=0;
239 }
240 _trkLen = _poca->flt1();
241 _hitLen = _poca->flt2();
242 double dca=_poca->doca();
243 if (!maintainAmb) setAmbig(dca>0?+1:-1);
245}
246
248TrkHitOnTrk::getFitStuff(HepVector &derivs, double &deltaChi ) const
249{
250 if (_poca==0 || _poca->status().failure()) {
252 }
253 // FIXME: I wish I could tell poca to NOT iterate
254 // and ONLY compute the distance & derivatives...
256 if (poca.status().failure()) {
258 }
259 if (derivs.num_row() != 0) {
260 poca.fetchDerivs(derivs);
261 } else {
262 derivs = poca.derivs();
263 }
264 double sigInv = 1. / hitRms();
265 deltaChi = _resid * sigInv; // NOTE: use _INTERNAL_ residual
266 derivs *= sigInv;
268}
269
271TrkHitOnTrk::getFitStuff(double &deltaChi) const
272{
273 assert (_trkTraj == &(getParentRep()->traj()));
274 deltaChi=_resid/hitRms(); // NOTE: use _INTERNAL_ residual
276}
277
278
279 ostream&
280operator<<(ostream& o, const TrkHitOnTrk& x)
281{
282 x.print(o); return o;
283}
Double_t x[10]
XmlRpcServer s
Definition: HelloServer.cpp:11
ostream & operator<<(ostream &o, const TrkHitOnTrk &x)
HepVector & parameter()
Definition: DifIndepPar.h:51
PidType
Definition: PdtPid.h:11
virtual const TrkDifTraj & traj() const =0
void fetchDerivs(HepVector &) const
Definition: TrkDifPoca.h:67
const HepVector derivs() const
Definition: TrkDifPoca.h:66
virtual const TrkSimpTraj * localTrajectory(double fltLen, double &localFlt) const =0
int failure() const
Definition: TrkErrCode.h:61
const TrkHitOnTrk * setUnusedHit(const TrkHitOnTrk *hit)
Definition: TrkFundHit.cxx:75
const TrkHitOnTrk * setUsedHit(const TrkHitOnTrk *hit)
Definition: TrkFundHit.cxx:58
virtual void printAll(std::ostream &os) const
Definition: TrkFundHit.cxx:103
void setActivity(bool turnOn)
Definition: TrkHitOnTrk.cxx:96
double fltLen() const
Definition: TrkHitOnTrk.h:91
double _hitLen
Definition: TrkHitOnTrk.h:169
TrkErrCode updatePoca(const TrkDifTraj *trkTraj, bool maintainAmbiguity)
double residual() const
virtual void printAll(std::ostream &) const
void setUsability(int usability)
TrkRep * parentRep() const
Definition: TrkHitOnTrk.h:177
double resid(bool exclude=false) const
virtual void setAmbig(int newambig)
TrkHitOnTrk(const TrkFundHit *, double tolerance)
Definition: TrkHitOnTrk.cxx:33
bool isUsable() const
Definition: TrkHitOnTrk.h:201
virtual const Trajectory * hitTraj() const =0
const TrkRecoTrk * getParentTrack() const
double hitRms() const
Definition: TrkHitOnTrk.h:89
bool mustUse() const
Definition: TrkHitOnTrk.h:202
double _trkLen
Definition: TrkHitOnTrk.h:168
virtual const SvtHitOnTrack * svtHitOnTrack() const
Definition: TrkHitOnTrk.cxx:31
virtual const MdcHitOnTrack * mdcHitOnTrack() const
Definition: TrkHitOnTrk.cxx:30
double weight() const
const TrkDifTraj * _trkTraj
Definition: TrkHitOnTrk.h:171
PdtPid::PidType particleType() const
double hitLen() const
Definition: TrkHitOnTrk.h:92
double _resid
Definition: TrkHitOnTrk.h:170
TrkRecoTrk * parentTrack() const
const TrkRep * getParentRep() const
Definition: TrkHitOnTrk.h:73
bool operator==(const TrkHitOnTrk &) const
const TrkFundHit * hit() const
Definition: TrkHitOnTrk.h:75
virtual void print(std::ostream &) const
virtual ~TrkHitOnTrk()
Definition: TrkHitOnTrk.cxx:87
bool isActive() const
Definition: TrkHitOnTrk.h:200
void setUnusedHit()
TrkPoca * _poca
Definition: TrkHitOnTrk.h:172
bool _isActive
Definition: TrkHitOnTrk.h:165
void setUsedHit()
virtual int ambig() const
TrkErrCode getFitStuff(HepVector &derivs, double &deltaChi) const
double _tolerance
Definition: TrkHitOnTrk.h:173
const TrkDifTraj * trkTraj() const
Definition: TrkHitOnTrk.h:77
const TrkErrCode & status() const
Definition: TrkPocaBase.h:62
double flt2() const
Definition: TrkPocaBase.h:68
double flt1() const
Definition: TrkPocaBase.h:65
double doca() const
Definition: TrkPoca.h:56
PdtPid::PidType defaultType() const
Definition: TrkRecoTrk.h:78
Definition: TrkRep.h:43
TrkRecoTrk * parentTrack()
Definition: TrkRep.h:82
virtual PdtPid::PidType particleType() const
Definition: TrkRep.cxx:308
virtual void deactivateHot(TrkHitOnTrk *theHot)
Definition: TrkRep.cxx:167
virtual void activateHot(TrkHitOnTrk *theHot)
Definition: TrkRep.cxx:154
virtual bool resid(const TrkHitOnTrk *theHot, double &residual, double &residErr, bool exclude=false) const
Definition: TrkRep.cxx:348
TrkParams * parameters()
Definition: TrkSimpTraj.h:80