BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcHit.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: MdcHit.cxx,v 1.37 2012/08/13 00:01:16 zhangy Exp $
4//
5// Description:
6// Class Implementation |MdcHit|
7//
8// Environment:
9// Software developed for the BESIII Detector at the BEPCII
10//
11// Author List:
12// S. Schaffner - Original
13// A. Snyder - Mods
14// S. Sen Feb 17 1998 New digi()->MCPtr() references
15//
16// Copyright Information:
17// Copyright (C) 1996 SLAC
18//
19// History:
20// Migration for BESIII MDC
21//
22//------------------------------------------------------------------------
23
24#include "MdcData/MdcHit.h"
25#include "TrkBase/TrkHitOnTrk.h"
26#include "TrkBase/TrkRecoTrk.h"
28#include "Identifier/MdcID.h"
29
30bool MdcHit::m_cosmicFit= false;
31bool MdcHit::m_countPropTime = true;
32
33MdcHit::MdcHit( const MdcDigi*& aDigi, const MdcDetector*& det):
34 TrkFundHit(), _digiPtr(aDigi), _geomPtr(det)
35{
36 _digiPtr = aDigi;
37 _geomPtr = det;
38 assert( _digiPtr != NULL);
39 assert( _geomPtr != NULL);
40 _id = aDigi->identify();
41 _layerPtr = det->Layer(_id);
42 _wirePtr = det->Wire(_id);
43 assert( _layerPtr != NULL);
44 assert( _wirePtr != NULL);
45 m_mdcCalibFunSvc = NULL;
46 _layer = MdcID::layer(_id);
47 _wire = MdcID::wire (_id);
48 _iTdc = _digiPtr->getTimeChannel();
49 _iAdc = _digiPtr->getChargeChannel();
50 _rawTime = RawDataUtil::MdcTime(_iTdc);
51 _charge = RawDataUtil::MdcCharge(_iAdc);
52 _rmid = _wirePtr->rMid();
53 _zlen = _layerPtr->zLength();
54 _phi = _wirePtr->phi();
55 _cosphi = cos(_phi);
56 _sinphi = sin(_phi);
57 _status = 0;
58}
59
60MdcHit::MdcHit(const MdcHit& other) :
61 TrkFundHit() , _digiPtr(other._digiPtr), _geomPtr(other._geomPtr),
62 _layerPtr(other._layerPtr), _wirePtr(other._wirePtr), _id(other._id),
63 _layer(other._layer), _wire(other._wire),
64 _iTdc(other._iTdc), _iAdc(other._iAdc),
65 _rawTime(other._rawTime), _charge(other._charge),
66 _rmid(other._rmid), _zlen(other._zlen),
67 _phi(other._phi), _cosphi(other._cosphi), _sinphi(other._sinphi),
68 _status(other._status), _T0Walk(other._T0Walk)
69{
70 m_mdcCalibFunSvc = other.m_mdcCalibFunSvc;
71}
72
73MdcHit&
75 if(&other != this){
76 _digiPtr = other._digiPtr;
77 _geomPtr = other._geomPtr;
78 _layerPtr = other._layerPtr;
79 _wirePtr = other._wirePtr;
80 m_mdcCalibFunSvc = other.m_mdcCalibFunSvc;
81 _id = other._id;
82 _layer = other._layer;
83 _wire = other._wire;
84 _iTdc = other._iTdc;
85 _iAdc = other._iAdc;
86 _rawTime = other._rawTime;
87 _charge = other._charge;
88 _digiPtr = other._digiPtr;
89 _rmid = other._rmid;
90 _zlen = other._zlen;
91 _phi = other._phi;
92 _cosphi = other._cosphi;
93 _sinphi = other._sinphi;
94 _status = other._status;
95 _T0Walk = other._T0Walk;
96 }
97 return *this;
98}
99
100
101//Destructor
103 // This is ugly and inefficient. This, along with the rest of
104 // the hitList mess, should be cleaned up by handling the
105 // association in an external map
106
107 // Not written as a loop because removeHit() modifies TrkFundHit::_hitList
108 short count = 0;
109 while (nUsedHits() > count) {
110 bool removed = _hitList[count]->parentTrack()->hits()->removeHit(this);
111 if (!removed) count++;
112 }
113}
114
115bool
116MdcHit::operator==( const MdcHit& rhs ) const {
117 return (this == &rhs);
118}
119
120void
121MdcHit::print( ostream& o ) const {
122 o << "(" << _layer << ","<< _wire <<","<<digi()->getTrackIndex()<<")";
123}
124
125void
126MdcHit::printAll( ostream& o ) const {
127 o << "Hit:(" << _layer << "," << _wire
128 << ") x:" << x() << " y:" << y()
129 << " rt:" << rawTime()
130 << " dt:" <<driftTime(0.0,0)
131 << " dd:" <<driftDist(0.0,1)
132 << endl;
133}
134
135void
137 m_mdcCalibFunSvc = calibSvc;
138 _T0Walk = m_mdcCalibFunSvc->getT0(_layer,_wire) + m_mdcCalibFunSvc->getTimeWalk(_layer, _iAdc);
139}
140
141double
142MdcHit::driftTime(double tof, double z) const {
143 // t prop
144 double tprop = 0.;
145 if (m_countPropTime){ tprop = m_mdcCalibFunSvc->getTprop(_layer,z*10.); }
146
147 //tof in s, driftTime in ns, _T0Walk in ns
148 double driftT = _rawTime - _T0Walk -1.e9*tof - tprop;
149
150 //if(driftT >10000)
151 //std::cout<< "driftTime ("<<_layer<<","<<_wire<<") dt "<<driftT<<" rawTime "<<_rawTime<<" z "<<z<<" tprop "<<tprop <<" t0walk "<<_T0Walk<<" tof "<<1.e9*tof<< std::endl;//yzhang debug
152 return driftT;
153}
154
155double
156MdcHit::driftDist(double tof, int ambig, double entranceAngle,
157 double /*dipAngle*/, double z) const
158{
159 double driftD;
160 //drift time ns, layer id begin with 0, entrance angle rads,
161 //lr ambig: wire ambig 1,-1,0 -> Calib 0,1,2
162 int lrCalib=2;
163 if (ambig==1) lrCalib = 0;
164 else if (ambig==-1) lrCalib = 1;
165
166 // tof in s, driftDist in cm, dirftTime in ns
167 if (fabs(z)>150. || fabs(driftTime(tof,z))>1500.){
168 return 9999.;
169 }
170 driftD = 0.1 * m_mdcCalibFunSvc->driftTimeToDist(driftTime(tof,z),_layer,_wire,lrCalib,entranceAngle);//to cm
171 //std::cout<<"driftDist "<<"("<<_layer <<","<<_wire <<") dd "<<driftD<<" dt "<<driftTime(tof,z) <<" lr "<<lrCalib <<" eAng "<<entranceAngle <<" tof "<<tof*1.e9<<" z "<<z <<" t0walk "<<_T0Walk<<" rawT "<<_rawTime <<" tprop "<< _rawTime - driftTime(tof,z)- _T0Walk-1.e9*tof<<std::endl;
172
173 if (abs(driftD)<Constants::epsilon) driftD = 0.00001;
174 return driftD;
175}
176
177double
178MdcHit::driftDist(double bunchTime, int ambig) const {
179 return driftDist(bunchTime+crudeTof(), ambig, 0., 0., 0. );
180}
181
182
183double
184MdcHit::sigma(double driftdist, int ambig, double entranceAngle,
185 double dipAngle, double z) const {
186 double sig = 9999.;
187
188#ifdef MDCPATREC_RESLAYER
189 if (_layer == m_resLayer){
190 //give a huge sigma to skip this layer when fit track
191 return 9999.;
192 }
193#endif
194 //if(fabs(z)>150. || driftdist==9999. ) {
195 // return 9999.;
196 //}
197 if ( m_mdcCalibFunSvc ) {
198 //layid begin with 0, entrance angle in rads,
199 //distance: cm ->Calib mm //z: cm -> Calib mm
200 //Q: MonteCalo eV -> Calib fC FIXME
201 //lr ambig: wire ambig 1,-1,0 -> Calib 0,1,2
202 int lrCalib=2;
203 if (ambig==1) lrCalib = 0;
204 else if (ambig==-1) lrCalib = 1;
205
206 //std::cout<<"layer "<<_layer<< " lrCalib "<< lrCalib<< " driftdist "<< driftdist << " eAngle "<<entranceAngle
207 //<<" tan(dipAngle) "<<tan(dipAngle)<< " z "<<z <<" iAdc "<<_iAdc<<std::endl;
208 sig = 0.1 * m_mdcCalibFunSvc->getSigma(_layer,lrCalib,driftdist*10.,entranceAngle,
209 tan(dipAngle),z*10.,_iAdc); //Calib special resolution mm -> cm
210
211 if(fabs(sig)<Constants::epsilon){
212 sig = 999.;
213 }
214 //if(sig<=0){
215 //std::cout<<__FILE__<<" "<<__LINE__ <<" sigma "<<sig
216 //<<" layer "<<_layer <<" lrCalib "<<lrCalib <<" driftdist "<<driftdist*10
217 //<<" eAngle "<<entranceAngle<<" dipAngle "<<(dipAngle) <<" tanl "<<tan(dipAngle)
218 //<<" z "<<z <<" iAdc "<<_iAdc <<std::endl;
219 //}
220 }
221 //if (_layer<4) sig /=5.;//yzhang TEST 2011-05-27
222 return sig;
223}
224
225double
226MdcHit::sigma(double driftdist, int ambig) const {
227 return sigma(driftdist, ambig, 0., 0., 0.);// cm
228}
229
230const Trajectory*
233}
234
235extern ostream&
236operator<<( ostream &o, const MdcHit& hit ) {
237 hit.print(o);
238 return o;
239}
240
double tan(const BesAngle a)
Definition: BesAngle.h:216
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
double abs(const EvtComplex &c)
Definition: EvtComplex.hh:212
ostream & operator<<(ostream &o, const MdcHit &hit)
Definition: MdcHit.cxx:236
static const double epsilon
Definition: Constants.h:46
double getSigma(int layid, int lr, double dist, double entrance=0.0, double tanlam=0.0, double z=0.0, double Q=1000.0) const
double getT0(int layid, int cellid) const
double driftTimeToDist(double drifttime, int layid, int cellid, int lr, double entrance=0.0) const
double getTprop(int lay, double z) const
double getTimeWalk(int layid, double Q) const
const MdcLayer * Layer(unsigned id) const
Definition: MdcDetector.h:33
const MdcSWire * Wire(unsigned id) const
Definition: MdcDetector.h:28
Definition: MdcHit.h:44
const MdcDigi * digi() const
Definition: MdcHit.h:55
MdcHit(const MdcDigi *&digi, const MdcDetector *&det)
Definition: MdcHit.cxx:33
void setCalibSvc(const MdcCalibFunSvc *calibSvc)
Definition: MdcHit.cxx:136
unsigned wirenumber() const
Definition: MdcHit.h:62
void print(std::ostream &o) const
Definition: MdcHit.cxx:121
double x() const
Definition: MdcHit.h:76
virtual ~MdcHit()
Definition: MdcHit.cxx:102
double rawTime() const
Definition: MdcHit.h:66
bool operator==(const MdcHit &) const
Definition: MdcHit.cxx:116
const MdcCalibFunSvc * calibSvc() const
Definition: MdcHit.h:59
double driftTime(double tof, double z) const
Definition: MdcHit.cxx:142
double sigma(double, int, double, double, double) const
Definition: MdcHit.cxx:184
double y() const
Definition: MdcHit.h:77
MdcHit & operator=(const MdcHit &)
Definition: MdcHit.cxx:74
const Trajectory * hitTraj() const
Definition: MdcHit.cxx:231
double driftDist(double, int, double, double, double) const
Definition: MdcHit.cxx:156
const MdcLayer * layer() const
Definition: MdcHit.h:56
void printAll(std::ostream &o) const
Definition: MdcHit.cxx:126
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
Definition: MdcID.cxx:49
static int wire(const Identifier &id)
Definition: MdcID.cxx:54
const Trajectory * makeHitTrajInGlobalCoords(int wire, double z=0) const
Definition: MdcLayer.cxx:132
double zLength(void) const
Definition: MdcLayer.h:44
double phi(void) const
Definition: MdcSWire.h:52
double rMid(void) const
Definition: MdcSWire.h:50
static double MdcTime(int timeChannel)
Definition: RawDataUtil.h:8
static double MdcCharge(int chargeChannel)
Definition: RawDataUtil.h:11
virtual Identifier identify() const
Definition: RawData.cxx:15
unsigned int getChargeChannel() const
Definition: RawData.cxx:45
int getTrackIndex() const
Definition: RawData.cxx:50
unsigned int getTimeChannel() const
Definition: RawData.cxx:40
std::vector< const TrkHitOnTrk * > _hitList
Definition: TrkFundHit.h:97
int nUsedHits() const
Definition: TrkFundHit.cxx:89