BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcCalRecTrk.cxx
Go to the documentation of this file.
2
3#include "CLHEP/Units/PhysicalConstants.h"
4#include "GaudiKernel/Bootstrap.h"
5#include "GaudiKernel/IDataProviderSvc.h"
6#include "GaudiKernel/IMessageSvc.h"
7#include "GaudiKernel/ISvcLocator.h"
8#include "GaudiKernel/MsgStream.h"
9#include "GaudiKernel/SmartDataPtr.h"
10#include "GaudiKernel/StatusCode.h"
11#include "McTruth/MdcMcHit.h"
12#include "MdcRawEvent/MdcDigi.h"
13
14MdcCalRecTrk::MdcCalRecTrk( int pid ) { m_pid = pid; }
15
17 unsigned int i;
18 for ( i = 0; i < m_rechit.size(); i++ ) { delete m_rechit[i]; }
19 m_rechit.clear();
20}
21
22void MdcCalRecTrk::setRecTrk( RecMdcTrackCol::iterator it_trk ) {
23 IMessageSvc* msgSvc;
24 Gaudi::svcLocator()->service( "MessageSvc", msgSvc );
25 MsgStream log( msgSvc, "MdcCalRecTrk" );
26 log << MSG::DEBUG << "MdcCalRecTrk::setRecTrk()" << endmsg;
27
28 m_dr = ( *it_trk )->helix( 0 );
29 m_phi0 = ( *it_trk )->helix( 1 );
30 m_kappa = ( *it_trk )->helix( 2 );
31 m_dz = ( *it_trk )->helix( 3 );
32 m_tanl = ( *it_trk )->helix( 4 );
33 m_chisq = ( *it_trk )->chi2();
34 m_nhits = ( *it_trk )->getNhits();
35 m_helix = ( *it_trk )->helix();
36 m_helixerr = ( *it_trk )->err();
37 m_fgNoiseRatio = fgNoiseRatio( m_phi0 );
38
39 double mass;
40 if ( 0 == m_pid ) mass = 0.000511;
41 else if ( 1 == m_pid ) mass = 0.105658;
42 else if ( 2 == m_pid ) mass = 0.139570;
43 else if ( 3 == m_pid ) mass = 0.493677;
44 else if ( 4 == m_pid ) mass = 0.938272;
45 else if ( 5 == m_pid ) mass = 0.139570; // cosmic-ray
46 else log << MSG::FATAL << "wrong particle type" << endmsg;
47 m_p4 = ( *it_trk )->p4( mass );
48
49 m_dr *= 10.0; // cm -> mm
50 m_dz *= 10.0; // cm -> mm
51
52 m_pt = 1.0 / m_kappa;
53 m_p = m_pt * sqrt( m_tanl * m_tanl + 1.0 );
54
55 HitRefVec gothits = ( *it_trk )->getVecHits();
56 HitRefVec::iterator it_hit = gothits.begin();
57 MdcCalRecHit* rechit;
58 for ( ; it_hit != gothits.end(); it_hit++ )
59 {
60 rechit = new MdcCalRecHit();
61 rechit->setRecHit( it_hit );
62 m_rechit.push_back( rechit );
63 }
64}
65
66void MdcCalRecTrk::setKalTrk( RecMdcKalTrackCol::iterator it_trk ) {
67 IMessageSvc* msgSvc;
68 Gaudi::svcLocator()->service( "MessageSvc", msgSvc );
69 MsgStream log( msgSvc, "MdcCalRecTrk" );
70 log << MSG::DEBUG << "MdcCalRecTrk::setKalTrk()" << endmsg;
71
73 else if ( 1 == m_pid ) RecMdcKalTrack::setPidType( RecMdcKalTrack::muon );
74 else if ( 2 == m_pid ) RecMdcKalTrack::setPidType( RecMdcKalTrack::pion );
75 else if ( 3 == m_pid ) RecMdcKalTrack::setPidType( RecMdcKalTrack::kaon );
76 else if ( 4 == m_pid ) RecMdcKalTrack::setPidType( RecMdcKalTrack::proton );
77 else if ( 5 == m_pid ) RecMdcKalTrack::setPidType( RecMdcKalTrack::muon ); // cosmic-ray
78 else log << MSG::FATAL << "wrong particle type" << endmsg;
79
80 m_dr = ( *it_trk )->dr();
81 m_phi0 = ( *it_trk )->fi0();
82 m_kappa = ( *it_trk )->kappa();
83 m_dz = ( *it_trk )->dz();
84 m_tanl = ( *it_trk )->tanl();
85 m_chisq = ( *it_trk )->chi2();
86 m_fgNoiseRatio = fgNoiseRatio( m_phi0 );
87
88 m_p4.setPx( -sin( m_phi0 ) / fabs( m_kappa ) );
89 m_p4.setPy( cos( m_phi0 ) / fabs( m_kappa ) );
90 m_p4.setPz( m_tanl / fabs( m_kappa ) );
91 double p3 = m_p4.mag();
92 double mass;
93 if ( 0 == m_pid ) mass = 0.000511;
94 else if ( 1 == m_pid ) mass = 0.105658;
95 else if ( 2 == m_pid ) mass = 0.139570;
96 else if ( 3 == m_pid ) mass = 0.493677;
97 else if ( 4 == m_pid ) mass = 0.938272;
98 else if ( 5 == m_pid ) mass = 0.139570; // cosmic-ray
99 m_p4.setE( sqrt( p3 * p3 + mass * mass ) );
100
101 m_dr *= 10.0; // cm -> mm
102 m_dz *= 10.0; // cm -> mm
103
104 m_pt = 1.0 / m_kappa;
105 m_p = m_pt * sqrt( m_tanl * m_tanl + 1.0 );
106
107 // cout << setw(15) << m_p << setw(15) << m_dr << setw(15) << m_phi0
108 // << setw(15) << m_kappa << setw(15) << m_dz << setw(15) << m_tanl << endl;
109
110 HelixSegRefVec gothelixsegs = ( *it_trk )->getVecHelixSegs();
111 HelixSegRefVec::iterator it_hit = gothelixsegs.begin();
112 MdcCalRecHit* rechit;
113
114 int k = 0;
115 for ( ; it_hit != gothelixsegs.end(); it_hit++ )
116 {
117 rechit = new MdcCalRecHit();
118 rechit->setKalHit( it_hit );
119 m_rechit.push_back( rechit );
120
121 k++;
122 }
123 m_nhits = k;
124 // cout<<"hits "<<m_nhits <<endl;
125}
126
127bool MdcCalRecTrk::fgNoiseRatio( double phi0 ) {
128 IMessageSvc* msgSvc;
129 Gaudi::svcLocator()->service( "MessageSvc", msgSvc );
130 MsgStream log( msgSvc, "MdcCalib" );
131
132 IDataProviderSvc* eventSvc = NULL;
133 Gaudi::svcLocator()->service( "EventDataSvc", eventSvc );
134 SmartDataPtr<MdcDigiCol> mdcDigiCol( eventSvc, "/Event/Digi/MdcDigiCol" );
135 if ( !mdcDigiCol ) { log << MSG::FATAL << "Could not find event" << endmsg; }
136
137 int lay;
138 int cel;
139 bool hitCel[43][288];
140 for ( lay = 0; lay < 43; lay++ )
141 {
142 for ( cel = 0; cel < 288; cel++ ) { hitCel[lay][cel] = false; }
143 }
144
145 MdcDigiCol::iterator iter = mdcDigiCol->begin();
146 unsigned fgOverFlow;
147 int digiId = 0;
148 Identifier id;
149 for ( ; iter != mdcDigiCol->end(); iter++, digiId++ )
150 {
151 MdcDigi* aDigi = ( *iter );
152 id = ( aDigi )->identify();
153 lay = MdcID::layer( id );
154 cel = MdcID::wire( id );
155 fgOverFlow = ( aDigi )->getOverflow();
156
157 bool goodTQ = true;
158 if ( ( ( fgOverFlow & 3 ) != 0 ) || ( ( fgOverFlow & 12 ) != 0 ) ||
159 ( aDigi->getTimeChannel() == 0x7FFFFFFF ) ||
160 ( aDigi->getChargeChannel() == 0x7FFFFFFF ) )
161 goodTQ = false;
162
163 bool goodT = true;
164 if ( ( ( fgOverFlow & 1 ) != 0 ) || ( aDigi->getTimeChannel() == 0x7FFFFFFF ) )
165 goodT = false;
166
167 // if(!goodTQ) continue;
168 if ( !goodT ) continue;
169
170 hitCel[lay][cel] = true;
171 }
172
173 SmartDataPtr<RecMdcTrackCol> newtrkCol( eventSvc, "/Event/Recon/RecMdcTrackCol" );
174 if ( !newtrkCol )
175 {
176 log << MSG::ERROR << "Could not find RecMdcTrackCol" << endmsg;
177 return -1;
178 }
179
180 int nNoiRange = 4; // number of cells
181 double dphi = 1.0;
182 RecMdcTrackCol::iterator it_trk = newtrkCol->begin();
183 for ( it_trk = newtrkCol->begin(); it_trk != newtrkCol->end(); it_trk++ )
184 {
185 HitRefVec gothits = ( *it_trk )->getVecHits();
186 HitRefVec::iterator it_hit = gothits.begin();
187 HepVector helix = ( *it_trk )->helix();
188 HepSymMatrix helixErr = ( *it_trk )->err();
189 double phi0Rec = ( *it_trk )->helix( 1 );
190 double delphi;
191 if ( phi0Rec > phi0 ) delphi = phi0Rec - phi0;
192 else delphi = phi0 - phi0Rec;
193 if ( delphi > CLHEP::pi ) delphi -= CLHEP::pi;
194 if ( delphi > ( CLHEP::pi * 0.17 ) ) continue;
195
196 int nhitLay1 = 0; // lay0-3
197 int nhitLay2 = 0; // lay4-7
198 int nhitLay3 = 0; // lay8-19
199 int nhitLay4 = 0; // lay20-42
200 int nhitT1 = 0;
201 int nhitT2 = 0;
202 int nhitT3 = 0;
203 int nhitT4 = 0;
204 for ( lay = 0; lay < 8; lay++ )
205 {
206 double docamin = 0.7; // cm
207 if ( lay > 7 ) docamin = 0.9;
208 int celmin = -1;
209 int ncel = m_mdcGeomSvc->Layer( lay )->NCell();
210 for ( cel = 0; cel < ncel; cel++ )
211 {
212 double wphi;
213 const MdcGeoWire* pWire = m_mdcGeomSvc->Wire( lay, cel );
214 double xx = pWire->Backward().x();
215 double yy = pWire->Backward().y();
216 double rr = sqrt( ( xx * xx ) + ( yy * yy ) );
217 if ( yy >= 0 ) wphi = acos( xx / rr );
218 else wphi = CLHEP::twopi - acos( xx / rr );
219
220 double phiTrk = phi0 + CLHEP::halfpi;
221 if ( phiTrk > CLHEP::twopi ) phiTrk -= CLHEP::twopi;
222 if ( !( ( fabs( wphi - phiTrk ) < dphi ) ||
223 ( fabs( wphi + CLHEP::twopi - phiTrk ) < dphi ) ||
224 ( fabs( wphi - CLHEP::twopi - phiTrk ) < dphi ) ) )
225 { continue; }
226
227 double doca = m_mdcUtilitySvc->doca( lay, cel, helix, helixErr );
228 // cout << setw(5) << lay << setw(5) << cel << setw(15) << doca <<
229 // endl;
230 if ( fabs( doca ) < fabs( docamin ) )
231 {
232 docamin = doca;
233 celmin = cel;
234 }
235 }
236 if ( celmin > -1 )
237 {
238 if ( lay < 4 ) nhitLay1++;
239 else if ( lay < 8 ) nhitLay2++;
240 else if ( lay < 20 ) nhitLay3++;
241 else nhitLay4++;
242 for ( int ii = ( -nNoiRange ); ii <= nNoiRange; ii++ )
243 {
244 if ( 0 == ii ) continue;
245 int icell = celmin + ii;
246 if ( icell >= ncel ) icell -= ncel;
247 if ( icell < 0 ) icell += ncel;
248 // cout << "hit " << setw(5) << lay << setw(5) << celmin <<
249 // setw(5) << icell << setw(5) << hitCel[lay][icell]<<endl;
250 if ( hitCel[lay][icell] )
251 {
252 if ( lay < 4 ) nhitT1++;
253 else if ( lay < 8 ) nhitT2++;
254 else if ( lay < 20 ) nhitT3++;
255 else nhitT4++;
256 }
257 }
258 }
259 }
260 if ( ( nhitLay1 <= 0 ) || ( nhitLay2 <= 0 ) || ( nhitLay3 <= 0 ) || ( nhitLay4 <= 0 ) )
261 return false;
262 double ratio1 = (double)nhitT1 / ( (double)nhitLay1 * (double)nNoiRange * 2.0 );
263 double ratio2 = (double)nhitT2 / ( (double)nhitLay2 * (double)nNoiRange * 2.0 );
264 double ratio3 = (double)nhitT3 / ( (double)nhitLay3 * (double)nNoiRange * 2.0 );
265 double ratio4 = (double)nhitT4 / ( (double)nhitLay4 * (double)nNoiRange * 2.0 );
266
267 if ( ( ratio1 > 0.08 ) || ( ratio2 > 0.08 ) || ( ratio3 > 0.03 ) || ( ratio4 > 0.03 ) )
268 return false;
269 else return true;
270 }
271 return false;
272}
double mass
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
SmartRefVector< RecMdcKalHelixSeg > HelixSegRefVec
IMessageSvc * msgSvc()
void setKalHit(HelixSegRefVec::iterator it_hit)
void setRecHit(HitRefVec::iterator it_hit)
MdcCalRecTrk(int pid)
bool m_fgNoiseRatio
void setRecTrk(RecMdcTrackCol::iterator it_trk)
bool fgNoiseRatio(double phi0)
void setKalTrk(RecMdcKalTrackCol::iterator it_trk)
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
unsigned int getChargeChannel() const
Definition RawData.cxx:35
unsigned int getTimeChannel() const
Definition RawData.cxx:32