BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcHitOnTrack.cxx
Go to the documentation of this file.
1// $Id: MdcHitOnTrack.cxx,v 1.22 2012/08/13 00:01:16 zhangy Exp $
2//
4#include "MdcData/MdcHit.h"
5#include "MdcGeom/Constants.h"
6#include "MdcGeom/BesAngle.h"
7// MdcGeom needed to verify if hit is inside of chamber...
8// and to find the trajectory describing the hit, i.e. wire
9#include "MdcGeom/MdcLayer.h"
10#include "MdcGeom/MdcSWire.h"
11#include "TrkBase/TrkPoca.h"
12#include "TrkBase/TrkDifTraj.h"
13#include "TrkBase/TrkRep.h"
14#include "TrkBase/TrkSimpTraj.h"
15#include "TrkBase/TrkRecoTrk.h"
17using std::cout;
18using std::endl;
19/*
20#include "GaudiKernel/NTuple.h"
21extern NTuple::Tuple* g_tupleHit;
22extern NTuple::Item<int> g_hitLayer;
23extern NTuple::Item<int> g_hitWire;
24extern NTuple::Item<double> g_hitAmbig;
25extern NTuple::Item<double> g_hitEAngle;
26extern NTuple::Item<double> g_hitZ;
27extern NTuple::Item<double> g_hitAmbigMc;
28extern NTuple::Item<double> g_hitEAngleMc;
29extern NTuple::Item<double> g_hitZMc;
30extern NTuple::Item<double> g_hitDrift;
31extern NTuple::Item<double> g_hitDriftMc;
32extern NTuple::Item<int> g_hitTkIdMc;
33extern NTuple::Item<double> g_hitPhiPoca;
34extern NTuple::Item<double> g_hitPhiHit;
35extern NTuple::Item<double> g_hitPhiHit0;
36extern NTuple::Item<double> g_hitPhiHitDel;
37extern int haveDigiTk[43][288];
38extern int haveDigiMcLr[43][288];
39extern double haveDigiEAngle[43][288];
40extern double haveDigiZ[43][288];
41extern double haveDigiDrift[43][288];
42*/
43
44//-------------
45// Constructors
46//-------------
48 const MdcHit& baseHit,
49 int ambig, double t0)
50: TrkHitOnTrk(&fundHit,10.e-4),
51 _ambig(ambig),
52 _hitTraj(baseHit.hitTraj()),
53 _fitTime(baseHit.rawTime()-t0*1e-9),
54 _dHit(&baseHit)
55{
56 // need to flag somehow that that we haven't computed things yet...
57 // now, we know that _drift[0] is for ambig <0, and _drift[1] is ambig >0
58 // and _drift is signed according to ambig. Thus _drift[0] should be -tive
59 // and _drift[1] should be +tive. To indicate this are not yet initialized,
60 // put 'impossible' values here...
61 _drift[0] = +9999;
62 _drift[1] = -9999;
63 setHitResid(-21212121.0);
64 setHitRms( 0.02 );
65 setHitLen(0.5 * baseHit.layer()->zLength());
66 setFltLen(0.);
67 _startLen = hitTraj()->lowRange() - 5.;
68 _endLen = hitTraj()->hiRange() + 5.;
69}
70
71//MdcHitOnTrack::MdcHitOnTrack(const TrkFundHit *fundHit, int ambig, double fittime,
72// int layer, int wire)
73// : TrkHitOnTrk(fundHit,10.e-4),
74// _ambig(ambig), _fitTime(fittime)
75//{
76// cout << "using old MdcHitOnTrack constructor..." << endl;
77
78// IService* ser;
79// StatusCode sc = Gaudi::svcLocator()->getService("MdcGeomSvc",ser);
80// if (!sc.isSuccess())
81// cout <<"MdcHitOnTrack::Could not open Geometry Service"<<endl;
82// MdcGeomSvc *m_gmSvc = dynamic_cast<MdcGeomSvc*> (ser);
83// if(!m_gmSvc) cout <<"MdcHitOnTrack::Could not open Geometry Service"<<endl;
84
85
86
87// _drift[0] = +9999;
88// _drift[1] = -9999;
89// _hitTraj = gblEnv->getMdc()->getMdcLayer(layer)->makeHitTrajInGlobalCoords(wire);
90// _hitTraj = m_gmSvc->Layer(layer)->makeHitTrajInGlobalCoords(wire);
91// setHitResid(-21212121.0);
92// setHitRms( 0.01 );
93// setHitLen(2.);
94// setFltLen(0.);
95// _startLen = hitTraj()->lowRange() - 5.;
96// _endLen = hitTraj()->hiRange() + 5.;
97//}
98
100 const TrkDifTraj* trkTraj, const MdcHit *hb)
101: TrkHitOnTrk(hot,newRep,trkTraj)
102{
103 _ambig = hot._ambig;
104 _hitTraj = hot._hitTraj;
105 _fitTime = hot._fitTime;
106 _drift[0] = hot._drift[0];
107 _drift[1] = hot._drift[1];
108 _startLen = hot._startLen;
109 _endLen = hot._endLen;
110 _dHit = (hb==0?hot._dHit:hb);
111}
112
115
116 void
118{
119 _fitTime= _dHit->rawTime()-t0*1e-9;
120}
121
122double
124{
125 double dca = -9999.;
126 if ( getParentRep() == 0 ) {
127 // cout << "no parent rep" << endl;
128 return dca;
129 }
130 // WARNING: cannot use the internal _poca, as it lags one iteration
131 // behind the fit... therfore use _EXTERNAL_ residual
132 if (isActive()) { // FIXME: currently can only use 'resid()' if isActive..
133 dca = resid()+drift();
134 } else {
135 TrkPoca poca(getParentRep()->traj(), fltLen(), *hitTraj(), hitLen(),
136 _tolerance);
137 if (poca.status().success()) dca = poca.doca();
138 }
139 return dca;
140}
141
142 bool
144{
145 if (dca < 0 && ambig() >= 0) {
146 setAmbig(-1); return isActive();
147 } else if (dca > 0 && ambig() <= 0) {
148 setAmbig(1); return isActive();
149 } else {
150 return false;
151 }
152}
153
154const MdcHitOnTrack*
156{
157 return this;
158}
159
160double
162{
163 static Hep3Vector dir;
164 static HepPoint3D pos;
165 if (getParentRep() == 0) return 0.;
166 getParentRep()->traj().getInfo(fltLen(), pos, dir);
167
168 return BesAngle(dir.phi() - pos.phi());
169}
170
171double
173{
174 static Hep3Vector dir;
175 static HepPoint3D pos;
176 if (getParentRep() == 0) return 0.;
177 getParentRep()->traj().getInfo(fltLen(), pos, dir);
178
179 return entranceAngle(pos, dir);
180}
181
182double
183MdcHitOnTrack::entranceAngle(const HepPoint3D pos, const Hep3Vector dir) const
184{
185 double angle = EntranceAngle(dir.phi() - _dHit->phi(pos.z()));
186 //std::cout<< "eAngle("<<layernumber()<<","<<wire()<<") dir.phi() "<<dir.phi()*180./3.14<<" hit phi "<<_dHit->phi(pos.z())*180./3.14<<" eAngle "<<angle*180./3.14<<" degree "<<angle<<std::endl;
187
188 //std::cout<< __FILE__ << " " << __LINE__ << " ("<<layernumber()<<","<<wire()<<") "<<
189 //" phiPoca "<<dir.phi()*180/3.14<< " phiWire "<<_dHit->phi(pos.z())*180/3.14<<" z "<<pos.z()<<
190 //" dPhiz "<<_dHit->wire()->dPhizDC(pos.z())*180/3.14<< " eAngle "<<angle*180/3.14<< " angle "<<(dir.phi() - _dHit->phi(pos.z()))*180./3.14<<std::endl;
191 /*
192 if(g_tupleHit && fabs(angle)>0.0001){
193 int layer = layernumber();
194 int wireId = wire();
195 g_hitLayer = layer;
196 g_hitWire = wireId;
197
198 int lrCalib=2;
199 if (ambig()==1) lrCalib = 0;
200 else if (ambig()==-1) lrCalib = 1;
201 g_hitAmbig = lrCalib;
202 g_hitAmbigMc = haveDigiMcLr[layer][wireId];
203 g_hitEAngle = angle*180./3.14;
204 g_hitEAngleMc = haveDigiEAngle[layer][wireId]*180./3.14;
205 g_hitZ = pos.z();
206 g_hitZMc = haveDigiZ[layer][wireId];
207 g_hitDrift = _drift[ambig()];
208 g_hitDriftMc = haveDigiDrift[layer][wireId];
209 g_hitTkIdMc = haveDigiTk[layer][wireId];
210 g_hitPhiPoca = dir.phi()*180./3.41;
211 g_hitPhiHit = _dHit->phi(pos.z())*180./3.41;
212 g_hitPhiHit0 = _dHit->phi()*180./3.41;
213 g_hitPhiHitDel = _dHit->wire()->dPhiz()*180./3.41;
214 g_tupleHit->write();
215 }
216 */
217 return angle;
218}
219
220unsigned
222{
223 return layernumber();
224}
225
226double
228{
229 return getParentRep()==0?0:Constants::pi/2-getParentRep()->traj().direction(fltLen()).theta();
230}
231
233MdcHitOnTrack::updateMeasurement(const TrkDifTraj* traj, bool maintainAmb)
234{
235 TrkErrCode status=updatePoca(traj,maintainAmb);
236 if (status.failure()) {
237#ifdef MDCPATREC_DEBUG
238 std::cout<<" ErrMsg(warning) " << "MdcHitOnTrack::updateMeasurement failed " << status << std::endl;
239#endif
240 return status;
241 }
242 assert (_poca!=0);
243 double dca=_poca->doca();
244 bool forceIteration = (maintainAmb&&ambig()!=0)?false:updateAmbiguity(dca);
245 //std::cout<< __FILE__ << " " << __LINE__ << " maintainAmb "<< maintainAmb
246 //<< " maintain&& ambig "<<(maintainAmb&&ambig()!=0)
247 //<< " forceIteration "<<forceIteration<<std::endl;
248 assert(ambig()!=0);
249 // Check for hits beyond end plates. !!Turn off hit if it is == temp. hack
250 if (isBeyondEndflange()) setUsability(false);
251 if (forceIteration || !driftCurrent() ) {
252 updateCorrections(); // force recomputation of drift for current ambig(), setting of hitRms
253 forceIteration=true;
254 }
255 setHitResid(dca-drift());
256 return !forceIteration?status:
257 TrkErrCode(TrkErrCode::succeed, 11, "Ambiguity flipped");
258}
259
260 void
261MdcHitOnTrack::updateCorrections()
262{
263 const TrkRep* tkRep = getParentRep();
264 assert(tkRep != 0);
265 static HepPoint3D pos; static Hep3Vector dir;
266 _trkTraj->getInfo(fltLen(), pos, dir);
267
268 // for bes3 cosmic test
269 int wireAmb = wireAmbig();
270 double tof = tkRep->arrivalTime(fltLen());
271 // at this point, since dcaToWire is computed, _ambig must be either -1 or +1
272 assert( ambig() == -1 || ambig() == 1 );
273 double eAngle = entranceAngle(pos, dir);//2011-11-22
274 double dAngle = Constants::pi/2 - dir.theta();
275 double z = pos.z();
276 // note the special case for INCOMING tracks:
277 // wire left of track implies hit on the right side of wire
278 //int wireAmb= fabs(eAngle)<Constants::pi/2?_ambig:-_ambig; //yzhang delete 2012-07-17
279
280 // provide the underlying hit with the *external* information
281 // needed to compute the drift distance, i.e. those numbers that
282 // the hit cannot figure out by itself...
283 double dist = _dHit->driftDist(tof, wireAmb, eAngle, dAngle, z);
284 //<<" dir "<<dir<<" pos "<<pos
285 //assert(dist>0);//yzhang 2011-12-05 delete
286 _fitTime = _dHit->driftTime(tof,z);
287 //std::cout<<" MdcHitOnTrack ("<<layernumber()<<","<<wire()<<") "<<mdcHit()->isCosmicFit()<<" fltLen "<<fltLen() <<" eAngle "<<eAngle<<" ambig "<<ambig()<<" wireAmb "<<wireAmb<<" tof "<<tof<<" dd "<<dist<<" dt "<<_fitTime<<std::endl;
288 _drift[ambig()<0?0:1] = ambig() * dist;
289 assert( driftCurrent() );
290
291 double newSig = _dHit->sigma(dist, wireAmb, eAngle, dAngle, z);
292
293 //assert(newSig>0);//yzhang 2011-12-05 delete
294 setHitRms(newSig);
295}
296
297double
298MdcHitOnTrack::driftVelocity() const
299{
300 const TrkRep* tkRep = getParentRep();
301 assert(tkRep != 0);
302 double tof = tkRep->arrivalTime(fltLen());
303 static HepPoint3D pos; static Hep3Vector dir;
304 _trkTraj->getInfo(fltLen(), pos, dir);
305 double eAngle = entranceAngle(pos, dir);//2011-11-22
306 double dAngle = Constants::pi/2 - dir.theta();
307 double z = pos.z();
308 // note the special case for INCOMING tracks:
309 // wire left of track implies hit on the right side of wire
310 int wireAmb= fabs(eAngle)<Constants::pi/2?_ambig:-_ambig;
311
312 static const double epsilon = 0.5e-9; // tof are in s;
313 double dist1 = _dHit->driftDist(tof+epsilon, wireAmb, eAngle, dAngle, z);
314 double dist2 = _dHit->driftDist(tof-epsilon, wireAmb, eAngle, dAngle, z);
315
316 return (dist2-dist1)/(2*epsilon); // velocity in cm/s
317}
318
319bool
320MdcHitOnTrack::timeResid(double &t, double &tErr) const
321{
322 double v = driftVelocity();
323 if (v <= 0) return false;
324 t = (fabs(drift())-fabs(dcaToWire()))/v;
325 tErr= hitRms()/v;
326 return true;
327}
328
329bool
330MdcHitOnTrack::timeAbsolute(double &t, double &tErr) const
331{
332 double tresid(-1.0);
333 if(timeResid(tresid,tErr)){
334 // add back the track time
335 t = tresid + getParentRep()->parentTrack()->trackT0();
336 return true;
337 } else
338 return false;
339}
340
343{
344 return _dHit->whatView();
345}
346
347int
349{
350 return _dHit->layernumber();
351}
352
353const MdcLayer*
355{
356 return _dHit->layer();
357}
358
359int
361{
362 return _dHit->wirenumber();
363}
364
365int
367{
368 return _dHit->whichView();
369}
370
371double
373{
374 return _dHit->rawTime();
375}
376
377double
379{
380 return _dHit->charge();
381}
382
383const Trajectory*
385{
386 return _hitTraj;
387}
388
389const MdcHit*
391{
392 return 0;
393}
394
395
396// Replace underlying hit pointer (base class doesn't own it)
397
398 void
400{
401 _dHit = newBase;
402}
403
404/*
405 MdcHitOnTrack::isBeyondEndflange() const {
406 std::cout<<__FILE__<<" "<<__LINE__
407 <<" hitLen "<<hitLen()
408 <<" startLen "<<_startLen
409 <<" endLen "<<_endLen
410 << std::endl;
411 return (hitLen() < _startLen || hitLen() > _endLen);
412 }
413 */
414
416 // hit wrt the wire location
417
418 //return fabs(entranceAngle())<Constants::pi/2?ambig():-ambig();
419 const TrkRep* tkRep = getParentRep();
420 static Hep3Vector dir;
421 static HepPoint3D pos;
422 if (getParentRep() == 0) return 0.;
423 getParentRep()->traj().getInfo(fltLen(), pos, dir);
424
425 double wireAmb = ambig();
426 if (mdcHit()->isCosmicFit()){
427 HepPoint3D poca = tkRep->position(0.);
428 if ( pos.y() > poca.y()){
429 wireAmb = -1.*_ambig;//yzhang 2012-07-17
430 //std::cout<<"MdcHitOnTrack CosmicFit up ambig *-1"<<std::endl;
431 }
432 }
433
434 return wireAmb;
435}
**********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
const double epsilon
TTree * t
Definition binning.cxx:23
static const double pi
Definition Constants.h:38
virtual const MdcHit * mdcHit() const
void changeBase(MdcHit *newBase)
int wireAmbig() const
bool isBeyondEndflange() const
virtual bool timeAbsolute(double &t, double &tErr) const
int ambig() const
virtual const Trajectory * hitTraj() const
unsigned layerNumber() const
double entranceAngleHit() const
bool updateAmbiguity(double dca)
int wire() const
virtual bool timeResid(double &t, double &tErr) const
double rawTime() const
double dcaToWire() const
virtual const MdcHitOnTrack * mdcHitOnTrack() const
double drift() const
double charge() const
virtual unsigned status() const =0
void setAmbig(int a)
TrkEnums::TrkViewInfo whatView() const
const MdcHit * baseHit() const
virtual ~MdcHitOnTrack()
double entranceAngle() const
int whichView() const
double dipAngle() const
const MdcLayer * layer() const
int layernumber() const
MdcHitOnTrack(const TrkFundHit &fundHit, const MdcHit &baseHit, int ambig, double fittime)
void setT0(double t0)
unsigned layernumber() const
Definition MdcHit.h:61
unsigned wirenumber() const
Definition MdcHit.h:62
double rawTime() const
Definition MdcHit.h:66
int whichView() const
Definition MdcHit.h:72
TrkEnums::TrkViewInfo whatView() const
Definition MdcHit.h:74
double phi() const
Definition MdcHit.h:75
double charge() const
Definition MdcHit.h:65
double driftTime(double tof, double z) const
Definition MdcHit.cxx:142
double sigma(double, int, double, double, double) const
Definition MdcHit.cxx:184
double driftDist(double, int, double, double, double) const
Definition MdcHit.cxx:156
const MdcLayer * layer() const
Definition MdcHit.h:56
double zLength(void) const
Definition MdcLayer.h:44
double lowRange() const
Definition Trajectory.h:91
virtual void getInfo(double fltLen, HepPoint3D &pos, Hep3Vector &direction) const =0
virtual Hep3Vector direction(double) const =0
double hiRange() const
Definition Trajectory.h:92
virtual const TrkDifTraj & traj() const =0
int success() const
Definition TrkErrCode.h:62
void setHitResid(double newResid)
double fltLen() const
Definition TrkHitOnTrk.h:91
friend class TrkBase::Functors::updateMeasurement
TrkErrCode updatePoca(const TrkDifTraj *trkTraj, bool maintainAmbiguity)
void setHitRms(double newRms)
void setUsability(int usability)
double resid(bool exclude=false) const
double hitRms() const
Definition TrkHitOnTrk.h:89
const TrkDifTraj * _trkTraj
void setFltLen(double f)
double hitLen() const
Definition TrkHitOnTrk.h:92
void setHitLen(double h)
const TrkRep * getParentRep() const
Definition TrkHitOnTrk.h:73
bool isActive() const
TrkPoca * _poca
double _tolerance
const TrkErrCode & status() const
Definition TrkPocaBase.h:62
double doca() const
Definition TrkPoca.h:56
double trackT0() const
virtual HepPoint3D position(double fltL) const
Definition TrkRep.cxx:180
virtual double arrivalTime(double fltL) const
Definition TrkRep.cxx:192
TrkRecoTrk * parentTrack()
Definition TrkRep.h:82