BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
DSemilepAlg.cxx
Go to the documentation of this file.
1#include "CLHEP/Geometry/Point3D.h"
2#include "CLHEP/Vector/LorentzVector.h"
3#include "CLHEP/Vector/ThreeVector.h"
4#include "GaudiKernel/Bootstrap.h"
5#include "GaudiKernel/INTupleSvc.h"
6#include "GaudiKernel/ISvcLocator.h"
7#include "GaudiKernel/MsgStream.h"
8#include "GaudiKernel/NTuple.h"
9#include "GaudiKernel/SmartDataPtr.h"
10#include <unistd.h>
11#include <vector>
12
13#include "EventModel/EventHeader.h"
14#include "EvtRecEvent/EvtRecDTag.h"
15#include "EvtRecEvent/EvtRecEvent.h"
16#include "EvtRecEvent/EvtRecPi0.h"
17#include "EvtRecEvent/EvtRecTrack.h"
18#include "EvtRecEvent/EvtRecVeeVertex.h"
19#include "VertexDbSvc/IVertexDbSvc.h"
20#include "VertexFit/Helix.h"
21
22using CLHEP::Hep3Vector;
23using CLHEP::HepLorentzVector;
24#ifndef ENABLE_BACKWARDS_COMPATIBILITY
25typedef HepGeom::Point3D<double> HepPoint3D;
26#endif
27
28#include "DSemilepAlg.h"
29
30typedef std::vector<int> Vint;
31typedef std::vector<HepLorentzVector> Vp4;
32
33// CONSTANTS
34const double me = 0.000511;
35const double mkaon = 0.4934;
36
37///////////////////////////
39DSemilepAlg::DSemilepAlg( const std::string& name, ISvcLocator* pSvcLocator )
40 : Algorithm( name, pSvcLocator ) {}
41
42//
43// INITIALIZE
44//
46
47 MsgStream log( msgSvc(), name() );
48 log << MSG::INFO << "in initialize()" << endmsg;
49 StatusCode status;
50
51 // NTUPLE
52 NTuplePtr nt0( ntupleSvc(), "FILE1/dsemilep" );
53 if ( nt0 ) m_tuple0 = nt0;
54 else
55 {
56 m_tuple0 =
57 ntupleSvc()->book( "FILE1/dsemilep", CLID_ColumnWiseTuple, "track N-Tuple example" );
58 if ( m_tuple0 )
59 {
60 status = m_tuple0->addItem( "U", m_U );
61 status = m_tuple0->addItem( "MM2", m_MM2 );
62 status = m_tuple0->addItem( "mBC", m_mBC );
63 status = m_tuple0->addItem( "q2", m_q2 );
64 status = m_tuple0->addItem( "deltaE", m_deltaE );
65 status = m_tuple0->addItem( "mode", m_mode );
66 }
67 else
68 {
69 log << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple0 ) << endmsg;
70 return StatusCode::FAILURE;
71 }
72 }
73
74 StatusCode sc = service( "SimplePIDSvc", m_simplePIDSvc );
75 if ( sc.isFailure() )
76 {
77 log << MSG::FATAL << "Could not load SimplePIDSvc!" << endmsg;
78 return sc;
79 }
80
81 log << MSG::INFO << "successfully return from initialize()" << endmsg;
82 return StatusCode::SUCCESS;
83}
84
85//
86// EXECUTE
87//
89
90 MsgStream log( msgSvc(), name() );
91 log << MSG::INFO << "in execute()" << endmsg;
92
93 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
94 int runNo = eventHeader->runNumber();
95 int eventNo = eventHeader->eventNumber();
96
97 //
98 // if(eventNo % 1000 == 0)
99 // cout << "Event: "<< eventNo << endl;
100
101 SmartDataPtr<EvtRecEvent> evtRecEvent( eventSvc(), "/Event/EvtRec/EvtRecEvent" );
102 if ( !evtRecEvent )
103 {
104 log << MSG::FATAL << "Could not find EvtRecEvent" << endmsg;
105 return StatusCode::FAILURE;
106 }
107
108 SmartDataPtr<EvtRecTrackCol> evtRecTrackCol( eventSvc(), "/Event/EvtRec/EvtRecTrackCol" );
109 if ( !evtRecTrackCol )
110 {
111 log << MSG::FATAL << "Could not find EvtRecTrackCol" << endmsg;
112 return StatusCode::FAILURE;
113 }
114
115 /// Accessing Ks list
116 SmartDataPtr<EvtRecVeeVertexCol> evtRecVeeVertexCol( eventSvc(),
117 "/Event/EvtRec/EvtRecVeeVertexCol" );
118 if ( !evtRecVeeVertexCol )
119 {
120 log << MSG::FATAL << "Could not find EvtRecVeeVertexCol" << endmsg;
121 return StatusCode::FAILURE;
122 }
123
124 /// Accessing pi0 list
125 SmartDataPtr<EvtRecPi0Col> recPi0Col( eventSvc(), "/Event/EvtRec/EvtRecPi0Col" );
126 if ( !recPi0Col )
127 {
128 log << MSG::FATAL << "Could not find EvtRecPi0Col" << endmsg;
129 return StatusCode::FAILURE;
130 }
131
132 // get primary vertex from db
133 Hep3Vector xorigin( 0, 0, 0 );
134 IVertexDbSvc* vtxsvc;
135 Gaudi::svcLocator()->service( "VertexDbSvc", vtxsvc ).ignore();
136 if ( vtxsvc->isVertexValid() )
137 {
138 // vertex[0] = vx; vertex[1]= vy; vertex[2] = vz;
139 double* vertex = vtxsvc->PrimaryVertex();
140 xorigin.setX( vertex[0] );
141 xorigin.setY( vertex[1] );
142 xorigin.setZ( vertex[2] );
143 }
144
145 // DTAGTOOL
146 DTagTool dtagTool;
147
148 if ( dtagTool.isDTagListEmpty() )
149 {
150 // cout<<"no D candidates found"<<endl;
151 return StatusCode::SUCCESS;
152 }
153 // else{
154 // cout<<"found D candidates found"<<endl;
155 // }
156
157 DTagToolIterator iter_begin = dtagTool.modes_begin();
158 DTagToolIterator iter_end = dtagTool.modes_end();
159
160 // find semileptonic decay candidate
161 vector<DTagToolIterator> vsditer;
162
163 // Using modes 0,1 and 3 (D0->KPi, D0->KPiPi0, D0->KPiPiPi ) fill dtagtool
164 // Combining three modes to look at the signal side of all of them
165 if ( dtagTool.findSTag( EvtRecDTag::kD0toKPi, 1 ) && dtagTool.cosmicandleptonVeto() )
166 vsditer.push_back( dtagTool.stag() );
167 if ( dtagTool.findSTag( EvtRecDTag::kD0toKPi, -1 ) && dtagTool.cosmicandleptonVeto() )
168 vsditer.push_back( dtagTool.stag() );
169 if ( dtagTool.findSTag( EvtRecDTag::kD0toKPiPi0, 1 ) ) vsditer.push_back( dtagTool.stag() );
170 if ( dtagTool.findSTag( EvtRecDTag::kD0toKPiPi0, -1 ) ) vsditer.push_back( dtagTool.stag() );
171 if ( dtagTool.findSTag( EvtRecDTag::kD0toKPiPiPi, 1 ) ) vsditer.push_back( dtagTool.stag() );
172 if ( dtagTool.findSTag( EvtRecDTag::kD0toKPiPiPi, -1 ) )
173 vsditer.push_back( dtagTool.stag() );
174
175 typedef vector<DTagToolIterator>::size_type vec_sz;
176
177 // loop over single tag to reconstruct signal side
178 for ( vec_sz i = 0; i < vsditer.size(); i++ )
179 {
180
181 // fill single tags only before selection
182 m_deltaE = ( *vsditer[i] )->deltaE();
183 m_mode = ( *vsditer[i] )->decayMode();
184 m_mBC = ( *vsditer[i] )->mBC();
185
186 // Get the DTagToolIterator of the tag for easier usage in the code
187 DTagToolIterator sditer = vsditer[i];
188
189 // Check signal side for good tracks and charge of the tracks
190 SmartRefVector<EvtRecTrack> othertracks = ( *sditer )->otherTracks();
191 vector<int> iGood;
192 int tcharge = 0;
193
194 for ( int i = 0; i < othertracks.size(); i++ )
195 {
196 if ( isGoodTrack( othertracks[i], xorigin ) )
197 {
198 iGood.push_back( i );
199 RecMdcKalTrack* mdcKalTrk = othertracks[i]->mdcKalTrack();
200 tcharge += mdcKalTrk->charge();
201 }
202 }
203
204 // Keeping only events with 2 good signal tracks with zero total charge
205 if ( iGood.size() != 2 || tcharge != 0 ) continue;
206
207 // Use SimplePIDSvc package to identify the tracks
208 m_simplePIDSvc->preparePID( othertracks[iGood[0]] );
209 bool FtrkElectron = m_simplePIDSvc->iselectron();
210 bool FtrkKaon = m_simplePIDSvc->iskaon();
211
212 m_simplePIDSvc->preparePID( othertracks[iGood[1]] );
213 bool StrkElectron = m_simplePIDSvc->iselectron();
214 bool StrkKaon = m_simplePIDSvc->iskaon();
215
216 //
217 // As at the signal side tracks are not listed in a particular order, there are two
218 // senarios
219 //
220 // Senario 1: Track 0 is electron, track 1 is kaon
221 if ( FtrkElectron && StrkKaon )
222 {
223
224 RecMdcKalTrack* ftrk = othertracks[iGood[0]]->mdcKalTrack();
225 RecMdcKalTrack* strk = othertracks[iGood[1]]->mdcKalTrack();
226
227 SmartRefVector<EvtRecTrack> tracks = ( *sditer )->tracks();
228 RecMdcKalTrack* tagsidektrk = tracks[0]->mdcKalTrack();
229
230 // Requiring electron having the same charge as the tag side kaon
231 if ( ftrk->charge() * tagsidektrk->charge() > 0 )
232 {
233 double U_1 = 0;
234 double MM2_1 = 0;
235 double q2_1 = 0;
236
237 // Calculate U and MM2 using a function
238 calU( sditer, strk, ftrk, U_1, MM2_1, q2_1 );
239
240 m_U = U_1;
241 m_MM2 = MM2_1;
242 m_q2 = q2_1;
243
244 m_tuple0->write().ignore();
245 }
246
247 } // end of senario 1
248
249 // Senario 2: Track 0 is kaon, track 1 is electon
250 if ( StrkElectron && FtrkKaon )
251 {
252
253 RecMdcKalTrack* ftrk = othertracks[iGood[0]]->mdcKalTrack();
254 RecMdcKalTrack* strk = othertracks[iGood[1]]->mdcKalTrack();
255
256 SmartRefVector<EvtRecTrack> tracks = ( *sditer )->tracks();
257
258 RecMdcKalTrack* tagsidektrk = tracks[0]->mdcKalTrack();
259
260 // Requiring electron having the same charge as the tag side kaon
261 if ( strk->charge() * tagsidektrk->charge() > 0 )
262 {
263
264 double U_1 = 0;
265 double MM2_1 = 0;
266 double q2_1 = 0;
267
268 // Calculate U and MM2 using a function
269 calU( sditer, strk, ftrk, U_1, MM2_1, q2_1 );
270
271 m_U = U_1;
272 m_MM2 = MM2_1;
273 m_q2 = q2_1;
274
275 m_tuple0->write().ignore();
276 }
277 } // end of senario 2
278 }
279
280 // Clear DTagTool
281 dtagTool.clear();
282
283 return StatusCode::SUCCESS;
284}
285
286//
287// FINALIZE
288//
290 MsgStream log( msgSvc(), name() );
291 log << MSG::INFO << "in finalize()" << endmsg;
292
293 return StatusCode::SUCCESS;
294}
295
296//
297// MEMBER FUNCTIONS
298//
299
300//
301// isGoodTrack
302bool DSemilepAlg::isGoodTrack( EvtRecTrack* trk, Hep3Vector xorigin ) {
303 if ( !( trk->isMdcKalTrackValid() ) ) return false;
304
305 RecMdcKalTrack* mdcKalTrk = trk->mdcKalTrack();
306 mdcKalTrk->setPidType( RecMdcKalTrack::pion );
307 HepVector a = mdcKalTrk->getZHelix();
308 HepSymMatrix Ea = mdcKalTrk->getZError();
309 HepPoint3D pivot( 0., 0., 0. );
310 HepPoint3D IP( xorigin[0], xorigin[1], xorigin[2] );
311 VFHelix helixp( pivot, a, Ea );
312 helixp.pivot( IP );
313 HepVector vec = helixp.a();
314 double vrl = vec[0];
315 double vzl = vec[3];
316 double costheta = cos( mdcKalTrk->theta() );
317
318 // Event selection criteria
319 if ( fabs( vrl ) < 1 && fabs( vzl ) < 10 && fabs( costheta ) < 0.93 ) return true;
320 return false;
321}
322
323//
324// 3 Momentum of the tagged D
325Hep3Vector DSemilepAlg::tagDP3( DTagToolIterator iter_dtag ) {
326
327 SmartRefVector<EvtRecTrack> tracks = ( *iter_dtag )->tracks();
328 SmartRefVector<EvtRecTrack> showers = ( *iter_dtag )->showers();
329
330 HepLorentzVector p4 = ( *iter_dtag )->p4();
331 p4.boost( -0.011, 0, 0 );
332 Hep3Vector p3 = p4.v();
333 return p3;
334}
335
336//
337// Calculate U = E_miss - P_miss and MM2 = U * (E_miss + P_miss)
339 RecMdcKalTrack* Ktrack, double& U, double& MM2, double& q2 ) {
340
343
344 Hep3Vector P3_tag = tagDP3( sditer );
345
346 Hep3Vector P3_E( Etrack->px(), Etrack->py(), Etrack->pz() );
347 Hep3Vector P3_K( Ktrack->px(), Ktrack->py(), Ktrack->pz() );
348
349 HepLorentzVector P4_E( P3_E, sqrt( P3_E.mag2() + me * me ) );
350 HepLorentzVector P4_K( P3_K, sqrt( P3_K.mag2() + mkaon * mkaon ) );
351
352 // Boost
353 P4_E.boost( -0.011, 0, 0 );
354 P4_K.boost( -0.011, 0, 0 );
355
356 double e_miss = ( *sditer )->beamE() - P4_E.e() - P4_K.e();
357 Hep3Vector P3_miss = -P3_tag - P4_E.vect() - P4_K.vect();
358
359 U = e_miss - P3_miss.mag();
360 MM2 = U * ( e_miss + P3_miss.mag() );
361
362 HepLorentzVector P4_W( P3_E + P3_miss * fabs( e_miss / P3_miss.mag() ), e_miss + P4_E.e() );
363 q2 = P4_W.m2();
364}
EvtRecDTagCol::iterator DTagToolIterator
DECLARE_COMPONENT(BesBdkRc)
dble_vec_t vec[12]
HepGeom::Point3D< double > HepPoint3D
int runNo
Definition DQA_TO_DB.cxx:13
const double mkaon
double me
std::vector< HepLorentzVector > Vp4
Definition Gam4pikp.cxx:38
std::vector< int > Vint
Definition Gam4pikp.cxx:37
int eventNo
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
StatusCode finalize()
bool isGoodTrack(EvtRecTrack *trk, Hep3Vector xorigin)
Hep3Vector tagDP3(DTagToolIterator iter_dtag)
StatusCode initialize()
StatusCode execute()
DSemilepAlg(const std::string &name, ISvcLocator *pSvcLocator)
void calU(DTagToolIterator sditer, RecMdcKalTrack *Etrack, RecMdcKalTrack *Ktrack, double &U, double &MM2, double &q2)
EvtRecDTagCol::iterator modes_begin()
EvtRecDTagCol::iterator modes_end()
void clear()
Definition DTagTool.cxx:118
bool findSTag(EvtRecDTag::DecayMode mode, int tagcharm)
Definition DTagTool.cxx:208
bool cosmicandleptonVeto(bool emc=true)
virtual bool isVertexValid()=0
virtual double * PrimaryVertex()=0
const HepPoint3D & pivot(void) const
returns pivot position.
const HepVector & a(void) const
returns helix parameters.