BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
KalFitTrack2.cxx
Go to the documentation of this file.
1// #include "KalFitAlg/KalFitAlg.h"
2#include "CLHEP/Matrix/SymMatrix.h"
3#include "EventModel/Event.h"
4#include "GaudiKernel/Algorithm.h"
5#include "GaudiKernel/Bootstrap.h"
6#include "GaudiKernel/IDataProviderSvc.h"
7#include "GaudiKernel/ISvcLocator.h"
8#include "GaudiKernel/MsgStream.h"
9#include "GaudiKernel/SmartDataPtr.h"
10#include "Identifier/Identifier.h"
11#include "Identifier/MdcID.h"
12#include "KalFitAlg/KalFitTrack.h"
13#include "KalFitAlg/KalFitWire.h"
14#include "MagneticFieldSvc/IBesMagFieldSvc.h"
15#include "MdcRawEvent/MdcDigi.h"
16#include "RawEvent/RawDataUtil.h"
17
18double KalFitTrack::EventT0_ = 0.;
19HepSymMatrix KalFitTrack::initMatrix_( 5, 0 );
20const IMdcCalibFunSvc* KalFitTrack::CalibFunSvc_ = 0;
21const IBesMagFieldSvc* KalFitTrack::MFSvc_ = 0;
22IMdcGeomSvc* KalFitTrack::iGeomSvc_ = 0;
23MdcDigiCol* KalFitTrack::mdcDigiCol_ = 0;
25
26// KalFitAlg* alg;
27// IDataProviderSvc* eventSvc = alg->eventDataService();
28/* SmartDataPtr<MdcDigiCol> mdcDigiCol(alg->eventSvc(),"/Event/Digi/MdcDigiCol");
29 if (!mdcDigiCol) {
30 log << MSG::ERROR << "Could not find event in MdcDigiCol" << endmsg;
31 return( StatusCode::FAILURE);
32 }
33 */
34
35void KalFitTrack::setInitMatrix( HepSymMatrix m ) { initMatrix_ = m; }
36
37HepSymMatrix KalFitTrack::getInitMatrix() const { return initMatrix_; }
38
39void KalFitTrack::setT0( double eventstart ) {
40 //------------------set event start time-----------
41
42 EventT0_ = eventstart;
43 if ( debug_ == 4 )
44 { std::cout << "in function KalFitTrack::setT0(...), EventT0_ = " << EventT0_ << std::endl; }
45}
46
47double KalFitTrack::getT0( void ) const {
48 //------------------get event start time-----------
49
50 if ( debug_ == 4 )
51 { std::cout << "in function KalFitTrack::getT0 ( ), EventT0_ = " << EventT0_ << std::endl; }
52 return EventT0_;
53}
54
55//
56/* double KalFitTrack::get_T0(void) const
57 {
58 return 0;
59 }
60 */
61
62double KalFitTrack::getDriftTime( KalFitHitMdc& hitmdc, double toftime ) const {
63 const double vinner = 220.0e8; // cm/s
64 const double vouter = 240.0e8; // cm/s
65
66 int layerid = hitmdc.wire().layer().layerId();
67 double zhit = ( hitmdc.rechitptr() )->getZhit();
68 const KalFitWire* wire = &( hitmdc.wire() );
69 HepPoint3D fPoint = wire->fwd();
70 HepPoint3D bPoint = wire->bck();
71
72 // unit is centimeter
73 double wireLen = ( fPoint - bPoint ).x() * ( fPoint - bPoint ).x() +
74 ( fPoint - bPoint ).y() * ( fPoint - bPoint ).y() +
75 ( fPoint - bPoint ).z() * ( fPoint - bPoint ).z();
76 wireLen = sqrt( wireLen );
77 double wireZLen = fabs( fPoint.z() - bPoint.z() );
78 double tp = 0.;
79 double vp = 0.;
80 // west readout
81 if ( 0 == layerid % 2 )
82 {
83 // inner chamber
84 if ( layerid < 8 ) { vp = vinner; }
85 else { vp = vouter; }
86 tp = wireLen * fabs( zhit - bPoint.z() ) / wireZLen / vp;
87 }
88
89 // east readout
90 if ( 1 == layerid % 2 )
91 {
92 // inner chamber
93 if ( layerid < 8 ) { vp = vinner; }
94 else { vp = vouter; }
95 tp = wireLen * fabs( zhit - fPoint.z() ) / wireZLen / vp;
96 }
97
98 // s to ns
99 tp = 1.0e9 * tp;
100
101 if ( 0 == tprop_ ) tp = 0.;
102
103 // std::cout<<"propogation time: "<<tp<<std::endl;
104
105 int wireid = hitmdc.wire().geoID();
106 double drifttime1( 0. );
107 double drifttime2( 0. );
108 double drifttime3( 0. );
109
110 MdcDigiCol::iterator iter = mdcDigiCol_->begin();
111 for ( ; iter != mdcDigiCol_->end(); iter++ )
112 {
113 if ( ( *iter )->identify() == ( hitmdc.rechitptr() )->getMdcId() ) break;
114 }
115 // double t0 = get_T0();
116 // see the code of wulh in /Mdc/MdcCalibFunSvc/MdcCalibFunSvc/MdcCalibFunSvc.h,
117 // double getT0(int wireid) const { return m_t0[wireid]; }
118
119 // double getTimeWalk(int layid, double Q) const ;
120 double Q = RawDataUtil::MdcCharge( ( *iter )->getChargeChannel() );
121 double timewalk = CalibFunSvc_->getTimeWalk( layerid, Q );
122
123 if ( debug_ == 4 )
124 { std::cout << "CalibFunSvc_->getTimeWalk, timewalk =" << timewalk << std::endl; }
125
126 double timeoffset = CalibFunSvc_->getT0( wireid );
127 if ( debug_ == 4 )
128 { std::cout << "CalibFunSvc_->getT0, timeoffset =" << timeoffset << std::endl; }
129
130 double eventt0 = getT0();
131
132 if ( debug_ == 4 )
133 {
134 std::cout << "the Event T0 we get in the function getDriftTime(...) is " << eventt0
135 << std::endl;
136 }
137
138 // this tdc value come from MdcRecHit assigned by zhangyao
139 double tdctime1 = hitmdc.tdc();
140 double tdctime2( 0. );
141 double tdctime3( 0. );
142
143 if ( debug_ == 4 ) { std::cout << "tdctime1 be here is .." << tdctime1 << std::endl; }
144
145 // this tdc value come from MdcDigiCol time channel
146 // attention, if we use the iter like this: for(MdcDigiCol::iterator iter =
147 // mdcDigiCol_->begin(); iter != mdcDigiCol_->end(); iter++) it cannot pass the gmake , throw
148 // an error !
149 if ( debug_ == 4 )
150 {
151 // std::cout<<"the size of the mdcDigiCol_ is "<<mdcDigiCol_.size()<<std::endl;
152 }
153 // MdcDigiCol::iterator iter = mdcDigiCol_->begin();
154 // for(; iter != mdcDigiCol_->end(); iter++ ) {
155 // if((*iter)->identify() == (hitmdc.rechitptr())->getMdcId()) break;
156 // }
157 if ( debug_ == 4 )
158 {
159 std::cout << "the time channel be here is .." << ( *iter )->getTimeChannel() << std::endl;
160 }
161 tdctime2 = RawDataUtil::MdcTime( ( *iter )->getTimeChannel() );
162 tdctime3 = hitmdc.rechitptr()->getTdc();
163 drifttime1 = tdctime1 - eventt0 - toftime - timewalk - timeoffset - tp;
164 drifttime2 = tdctime2 - eventt0 - toftime - timewalk - timeoffset - tp;
165 drifttime3 = tdctime3 - eventt0 - toftime - timewalk - timeoffset - tp;
166 if ( debug_ == 4 )
167 {
168 std::cout << "we now compare the three kind of tdc , the tdc get from timeChannel() is "
169 << tdctime2 << " the tdc get from KalFitHitMdc is " << tdctime1
170 << " the tdc from MdcRecHit is " << tdctime3 << " the drifttime1 is ..."
171 << drifttime1 << " the drifttime 2 is ..." << drifttime2
172 << " the drifttime3 is ..." << drifttime3 << std::endl;
173 }
174 // return drifttime3;
175 // return drifttime1;
176 if ( drifttime_choice_ == 0 ) return drifttime2;
177 if ( drifttime_choice_ == 1 )
178 // use the driftT caluculated by track-finding
179 return hitmdc.rechitptr()->getDriftT();
180
181 std::cerr << __FILE__ << ":" << __LINE__ << ": should not reach here" << std::endl;
182 exit( 1 );
183}
184
185// attention , the unit of the driftdist is mm
186double KalFitTrack::getDriftDist( KalFitHitMdc& hitmdc, double drifttime, int lr ) const {
187 int layerid = hitmdc.wire().layer().layerId();
188 int cellid = MdcID::wire( hitmdc.rechitptr()->getMdcId() );
189 if ( debug_ == 4 ) { std::cout << "the cellid is .." << cellid << std::endl; }
190 double entrangle = hitmdc.rechitptr()->getEntra();
191
192 // std::cout<<" entrangle: "<<entrangle<<std::endl;
193
194 return CalibFunSvc_->driftTimeToDist( drifttime, layerid, cellid, lr, entrangle );
195}
196
197// attention , the unit of the sigma is mm
198double KalFitTrack::getSigma( KalFitHitMdc& hitmdc, double tanlam, int lr,
199 double dist ) const {
200 int layerid = hitmdc.wire().layer().layerId();
201 double entrangle = hitmdc.rechitptr()->getEntra();
202 // double tanlam = hitmdc.rechitptr()->getTanl();
203 double z = hitmdc.rechitptr()->getZhit();
204 double Q = hitmdc.rechitptr()->getAdc();
205 // std::cout<<" the driftdist before getsigma is "<<dist<<" the layer
206 // is"<<layerid<<std::endl; cout<<"layerid, lr, dist, entrangle, tanlam, z , Q =
207 // "<<layerid<<", "<<lr<<", "<<dist<<", "<<entrangle<<",
208 // "<<tanlam<<", "<<z<<", "<<Q<<endl;//wangll
209 double temp = CalibFunSvc_->getSigma( layerid, lr, dist, entrangle, tanlam, z, Q );
210 // std::cout<<" the sigma is "<<temp<<std::endl;
211 return temp;
212}
213
215 CalibFunSvc_ = calibsvc;
216}
217
219 /*ISvcLocator* svcLocator = Gaudi::svcLocator();
220 StatusCode sc = svcLocator->service("MagneticFieldSvc",MFSvc_);
221 if (sc.isFailure()){
222 std::cout << "Could not load MagneticFieldSvc!" << std::endl;
223 }*/
224 MFSvc_ = mf;
225 if ( MFSvc_ == 0 ) cout << "KalFitTrack2:: Could not load MagneticFieldSvc!" << endl;
226}
227
228void KalFitTrack::setIMdcGeomSvc( IMdcGeomSvc* igeomsvc ) { iGeomSvc_ = igeomsvc; }
229
230void KalFitTrack::setMdcDigiCol( MdcDigiCol* digicol ) { mdcDigiCol_ = digicol; }
HepGeom::Point3D< double > HepPoint3D
Double_t x[10]
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
static void setMdcDigiCol(MdcDigiCol *digicol)
double getDriftTime(KalFitHitMdc &hitmdc, double toftime) const
HepSymMatrix getInitMatrix(void) const
static void setInitMatrix(HepSymMatrix m)
double getSigma(int layerId, double driftDist) const
double getT0(void) const
static int tprop_
for signal propagation correction
static void setMdcCalibFunSvc(const IMdcCalibFunSvc *calibsvc)
double getDriftDist(KalFitHitMdc &hitmdc, double drifttime, int lr) const
static void setT0(double t0)
static void setMagneticFieldSvc(IBesMagFieldSvc *)
static void setIMdcGeomSvc(IMdcGeomSvc *igeomsvc)
static int wire(const Identifier &id)
Definition MdcID.cxx:52
static double MdcTime(int timeChannel)
static double MdcCharge(int chargeChannel)