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