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