BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcxHit.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: MdcxHit.cxx,v 1.20 2012/07/20 05:48:16 zhangy Exp $
4//
5// Description:
6// Class Implementation for |MdcxHit|: drift chamber hit that can compute
7// derivatives and plot itself.
8//
9// Environment:
10// Software developed for the BaBar Detector at the SLAC B-Factory.
11//
12// Author List:
13// A. Snyder
14//
15// Copyright Information:
16// Copyright (C) 1995 BEPCII
17//
18// History:
19// Migration for BESIII MDC
20//
21//------------------------------------------------------------------------
22#include "CLHEP/Alist/AIterator.h"
23#include "EventModel/Event.h"
24#include "GaudiKernel/Bootstrap.h"
25#include "GaudiKernel/IDataProviderSvc.h"
26#include "GaudiKernel/IService.h"
27#include "GaudiKernel/ISvcLocator.h"
28#include "GaudiKernel/SmartDataPtr.h"
29#include "Identifier/MdcID.h"
30#include "MdcData/MdcHit.h"
31#include "MdcGeom/Constants.h"
32#include "MdcGeom/EntranceAngle.h"
33#include "MdcRawEvent/MdcDigi.h"
34#include "MdcxReco/MdcxHel.h"
35#include "MdcxReco/MdcxHits.h"
36#include "RawEvent/RawDataUtil.h"
37#include <iomanip>
38
39using std::endl;
40using std::ostream;
41#ifdef MDCXRECO_RESLAYER
42extern int g_resLayer;
43#endif
44const IMdcCalibFunSvc* MdcxHit::m_mdcCalibFunSvc = 0;
45bool MdcxHit::m_countPropTime = true;
46const MdcDetector* MdcxHit::m_gm = 0;
47
48MdcxHit::MdcxHit( const MdcDigi* pdcdatum, float c0, float cresol )
49 : _mdcHit( 0 ), _mdcDigi( pdcdatum ), _c0( c0 ), _cresol( cresol ) {
50 process();
51}
52
53MdcxHit::MdcxHit( const MdcHit* pdchhit, float c0, float cresol )
54 : _mdcHit( pdchhit ), _mdcDigi( pdchhit->digi() ), _c0( c0 ), _cresol( cresol ) {
55 process();
56}
57
59 m_mdcCalibFunSvc = calibSvc;
60}
61
62void MdcxHit::setCountPropTime( bool countPropTime ) { m_countPropTime = countPropTime; }
63
64void MdcxHit::setMdcDetector( const MdcDetector* gm ) { m_gm = gm; }
65
67 assert( m_gm );
68 assert( m_mdcCalibFunSvc );
69 Identifier _id = ( *_mdcDigi ).identify();
71 _wirenumber = MdcID::wire( _id );
72 _superlayer = ( _layernumber ) / 4;
73 _iTdc = _mdcDigi->getTimeChannel();
74 _iAdc = _mdcDigi->getChargeChannel();
77 _T0Walk = m_mdcCalibFunSvc->getT0( _layernumber, _wirenumber ) +
78 m_mdcCalibFunSvc->getTimeWalk( _layernumber, _iAdc );
79 // pointer to layer
80 const MdcLayer* layerPtr = m_gm->Layer( _layernumber );
81 _L = layerPtr->zLength();
82 _x = layerPtr->xWire( _wirenumber );
83 _y = layerPtr->yWire( _wirenumber );
84 _r = sqrt( _x * _x + _y * _y );
85 _s = layerPtr->stereo();
86 _p = layerPtr->phiOffset() + _wirenumber * layerPtr->dPhi();
87 // double deltaz = m_gm->zOffSet(); //yzhang to BESIII
88 // double deltaz = 0.0;
89 double tst = _s;
90 double pw = atan2( _y, _x );
91 _pw = pw;
92 _wx = -tst * sin( pw );
93 _wy = tst * cos( pw );
94 _wz = ( tst * tst < 1.0 ) ? sqrt( 1.0 - tst * tst ) : 0.0;
95 _sp = sin( _p );
96 _cp = cos( _p );
97 _consterr = 0; // zoujh FIXME
98 _e = _cresol;
99 _d = d();
100 // note _v is a total cludge
101 _v = ( _t - _c0 > 0.0 ) ? _d / ( _t - _c0 ) : 0.0013; // yzhang 2009-11-03
102 _xneg = _x + _d * _sp;
103 _yneg = _y - _d * _cp;
104 _xpos = _x - _d * _sp;
105 _ypos = _y + _d * _cp;
106 usedonhel = 0;
108}
109
110float MdcxHit::tcor( float z, float tof, float tzero ) const {
111 // drift time
112 double tprop = 0.;
113 if ( m_countPropTime ) { tprop = m_mdcCalibFunSvc->getTprop( _layernumber, z * 10 ); }
114 double dt = ( _t - _T0Walk - _c0 - tprop - tof - tzero );
115 /*
116 std::cout<<"("<<_layernumber<<","<<_wirenumber<<") dt "<<dt
117 <<" rt "<<_t
118 <<" t0walk "<< _T0Walk
119 <<" z "<<z
120 <<" _c0 "<<_c0
121 <<" tzero "<<tzero
122 <<" tof "<<tof
123 <<" tprop "<<tprop
124 <<std::endl;
125 */
126 return dt;
127}
128
129float MdcxHit::d( float z, float tof, float tzero, int wamb, float entranceAngle ) const {
130
131 // std::cout<<__FILE__<<" "<<__LINE__<<" call entrance "<< entranceAngle<< std::endl;
132 // tof = hel.Doca_Tof();//yzhang delete for csmc temp FIXME
133 float t_corr = tcor( z, tof, tzero );
134 double eAngle = EntranceAngle( entranceAngle );
135
136 // yzhang add for 64-bit
137 if ( fabs( z ) > 150. || fabs( t_corr ) > 1500. || fabs( eAngle ) > 999 ) { return 9999.; }
138 // zhangy
139
140 int lrCalib = 2;
141 if ( wamb == 1 ) lrCalib = 0;
142 else if ( wamb == -1 ) lrCalib = 1;
143
144 double driftD = 0.1 * m_mdcCalibFunSvc->driftTimeToDist( t_corr, _layernumber, _wirenumber,
145 lrCalib, eAngle ); // to
146 // cm
147 // std::cout<<"MdcxHit ("<<_layernumber<<","<<_wirenumber<<" dd "<<driftD<<" dt "<<t_corr<<"
148 // lr "<<lrCalib<<" eAngle
149 // "<<eAngle<<std::endl;
150
151 if ( fabs( driftD ) <= 0.0001 ) driftD = 0.001;
152 return driftD;
153}
154
155float MdcxHit::d( MdcxHel& hel ) const {
156 float doca = hel.Doca( *this ); // changes hel's internal state...
157 return d( hel.Doca_Zh(), hel.Doca_Tof(), hel.T0(), hel.Doca_Wamb(), hel.Doca_Eang() );
158} // endof d
159
160float MdcxHit::e( float dd ) const {
161 // if (0!=_consterr) return _cresol;//yzhang delete 2009-11-03
162 float errTemp = fabs( getSigma( dd ) );
163 // protect against resolution = 0; set min resol to 1 nm
164 float errMin = 1.0e-7;
165 return errTemp < errMin ? errMin : errTemp;
166}
167
168float MdcxHit::pull( MdcxHel& hel ) const {
169 // compute pulls for |hel|
170 float doca = hel.Doca( *this );
171 if ( hel.Mode() == 0 ) doca = fabs( doca );
172 return ( d( hel.Doca_Zh(), hel.Doca_Tof(), hel.T0(), hel.Doca_Wamb(), hel.Doca_Eang() ) -
173 doca ) /
174 e( doca );
175 // return residual(hel)/e();
176}
177
178float MdcxHit::residual( MdcxHel& hel ) const {
179 // compute residuals for |hel|
180 float doca = hel.Doca( _wx, _wy, _wz, _x, _y );
181 if ( hel.Mode() == 0 ) doca = fabs( doca );
182 doca += v() * hel.T0();
183 return d( hel.Doca_Zh(), hel.Doca_Tof(), hel.T0(), hel.Doca_Wamb(), hel.Doca_Eang() ) - doca;
184 // return d(hel) - doca;
185}
186
187std::vector<float> MdcxHit::derivatives( MdcxHel& hel ) const {
188 // compute derivatives for |hel|
189 std::vector<float> deriv = hel.derivatives( *this );
190 float dtemp = d( hel.Doca_Zh(), hel.Doca_Tof(), hel.T0(), hel.Doca_Wamb(), hel.Doca_Eang() );
191 // float dtemp = d(hel);
192 deriv[0] = dtemp - deriv[0];
193 // deriv[0] -= v()*hel.T0();
194 float ewire = e( dtemp );
195 for ( uint32_t i = 0; i < deriv.size(); i++ ) deriv[i] /= ewire;
196 return deriv;
197} // endof derivatives
198
199void MdcxHit::print( ostream& o, int i ) const {
200 o << "(" << Layer() << "," << WireNo() << ",id " << getDigi()->getTrackIndex() << ") ";
201}
202
203void MdcxHit::printAll( ostream& o, int i ) const {
204 o << " hit" << i << " (" << Layer() << "," << WireNo() << ") ";
205 if ( getMdcHit() ) o << " phi " << getMdcHit()->phi();
206 o << "dd " << d() << " dde " << e() << " rt " << t() << endl;
207}
208
209double MdcxHit::getSigma( float driftDist, int ambig, double entranceAngle, double dipAngle,
210 double z ) const {
211 int lrCalib = 2;
212 if ( ambig != 0 ) lrCalib = ( ambig == 1 ) ? 0 : 1;
213 double eAngle = EntranceAngle( entranceAngle );
214 // std::cout<<_layernumber<<" "<<lrCalib<<" dd "<<driftDist<<" "<<eAngle<<" "<<dipAngle<<"
215 // "<<z<<"
216 // "<<_iAdc<<std::endl;
217 double sig = 0.1 * m_mdcCalibFunSvc->getSigma( _layernumber, lrCalib, driftDist * 10.,
218 eAngle, tan( dipAngle ), z * 10., _iAdc );
219 // double sig = 0.1 * m_mdcCalibFunSvc->getSigma(_layernumber, _wirenumber, lrCalib,
220 // driftDist*10., eAngle, tan(dipAngle), z*10., _iAdc);
221#ifdef MDCXRECO_RESLAYER
222 if ( Layer() == g_resLayer )
223 {
224 // give a huge sigma to skip this layer when fit track
225 return 9999.;
226 }
227#endif
228 return sig;
229}
TGraph2DErrors * dt
Definition McCor.cxx:41
static int layer(const Identifier &id)
Values of different levels (failure returns 0).
Definition MdcID.cxx:47
static int wire(const Identifier &id)
Definition MdcID.cxx:52
double yWire(int cell) const
Definition MdcLayer.cxx:79
double xWire(int cell) const
Definition MdcLayer.cxx:68
double Doca(double WX, double WY, double WZ, double X, double Y, double Z=0.0)
Definition MdcxHel.cxx:261
std::vector< float > derivatives(const MdcxHit &h)
Definition MdcxHel.cxx:368
float d(MdcxHel &hel) const
Definition MdcxHit.cxx:155
float pull(MdcxHel &hel) const
Definition MdcxHit.cxx:168
void printAll(std::ostream &o, int i=0) const
static void setMdcCalibFunSvc(const IMdcCalibFunSvc *calibSvc)
Definition MdcxHit.cxx:58
float tcor(float zh=0.0, float tof=0.0, float tzero=0.0) const
Definition MdcxHit.cxx:110
std::vector< float > derivatives(MdcxHel &hel) const
Definition MdcxHit.cxx:187
void process()
Definition MdcxHit.cxx:66
float e(float dd=0.0) const
Definition MdcxHit.cxx:160
void print(std::ostream &o, int i=0) const
static void setMdcDetector(const MdcDetector *gm)
Definition MdcxHit.cxx:64
float residual(MdcxHel &hel) const
Definition MdcxHit.cxx:178
MdcxHit(const MdcDigi *pdcdatum, float c0=0, float cresol=.0180)
Definition MdcxHit.cxx:48
static void setCountPropTime(bool countPropTime)
Definition MdcxHit.cxx:62
static double MdcTime(int timeChannel)
static double MdcCharge(int chargeChannel)
int getTrackIndex() const
Definition RawData.cxx:38