5#include "GaudiKernel/MsgStream.h"
6#include "GaudiKernel/AlgFactory.h"
7#include "GaudiKernel/ISvcLocator.h"
8#include "GaudiKernel/SmartDataPtr.h"
9#include "GaudiKernel/IDataProviderSvc.h"
10#include "GaudiKernel/PropertyMgr.h"
12#include "EventModel/EventHeader.h"
13#include "EventModel/Event.h"
14#include "EventModel/EventModel.h"
16#include "EvtRecEvent/EvtRecEvent.h"
17#include "EvtRecEvent/EvtRecTrack.h"
18#include "EvtRecEvent/EvtRecDTag.h"
19#include "EvtRecEvent/EvtRecPi0.h"
20#include "EvtRecEvent/EvtRecEtaToGG.h"
21#include "EvtRecEvent/EvtRecVeeVertex.h"
23#include "BesDChain/CDChargedPionList.h"
24#include "BesDChain/CDChargedKaonList.h"
25#include "BesDChain/CDPhotonList.h"
26#include "BesDChain/CDPi0List.h"
27#include "BesDChain/CDEtaList.h"
28#include "BesDChain/CDKsList.h"
29#include "BesDChain/CDDecayList.h"
31#include "McTruth/McParticle.h"
32#include "ParticleID/ParticleID.h"
33#include "VertexFit/VertexFit.h"
34#include "VertexFit/SecondVertexFit.h"
37#include "DTagAlg/DsReconstruction.h"
38#include "DTagAlg/LocalKaonSelector.h"
39#include "DTagAlg/LocalPionSelector.h"
40#include "DTagAlg/LocalPhotonSelector.h"
41#include "DTagAlg/LocalKsSelector.h"
42#include "DTagAlg/LocalPi0Selector.h"
43#include "DTagAlg/LocalEtatoGGSelector.h"
44#include "DTagAlg/LocalEtatoPiPiPi0Selector.h"
45#include "DTagAlg/LocalEptoPiPiEtaSelector.h"
46#include "DTagAlg/LocalEptoPiPiEta3PiSelector.h"
47#include "DTagAlg/LocalEptoRhoGamSelector.h"
48#include "DTagAlg/LocalRhotoPiPiSelector.h"
49#include "DTagAlg/DsSelector.h"
51#include "DTagAlg/utility.h"
57 Algorithm(name, pSvcLocator) {
59 declareProperty(
"debug", m_debug =
false );
60 declareProperty(
"ReadBeamEFromDB", m_ReadBeamEFromDB =
false );
61 declareProperty(
"UseCalibBeamE", m_usecalibBeamE =
false );
62 declareProperty(
"UseVertexfit", m_usevertexfit =
false );
63 declareProperty(
"BeamE", m_beamE=2.015 );
64 declareProperty(
"DsList", m_decaylist =
"test.txt" );
65 declareProperty(
"ReadMeasuredEcms", m_RdMeasuredEcms =
false);
70 MsgStream log(
msgSvc(), name());
71 log << MSG::INFO <<
"in initialize()" <<endreq;
81 StatusCode status=serviceLocator()->service(
"MeasuredEcmsSvc", ecmsSvc,
true);
82 if(!status.isSuccess()){
83 std::cout<<
"ERROR: Can not initial the IMeasuredEcmsSvc right"<<std::endl;
89 return StatusCode::SUCCESS;
94 MsgStream log(
msgSvc(), name());
95 log << MSG::INFO <<
"in finalize()" << endreq;
99 return StatusCode::SUCCESS;
102StatusCode DsReconstruction::registerEvtRecDTagCol(
104 StatusCode sc = eventSvc()->registerObject(
"/Event/EvtRec/EvtRecDTagCol",
106 if (sc != StatusCode::SUCCESS) {
107 log << MSG::FATAL <<
"Could not register EvtRecDTagCol in TDS!" << endreq;
114 MsgStream log(
msgSvc(), name());
115 log << MSG::INFO <<
"in execute()" << endreq;
122 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
123 int event= eventHeader->eventNumber();
129 log << MSG::DEBUG <<
"run and event = " << eventHeader->runNumber()
130 <<
" " << eventHeader->eventNumber() << endreq;
131 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
132 << recEvent->totalCharged() <<
" , "
133 << recEvent->totalNeutral() <<
" , "
134 << recEvent->totalTracks() <<endreq;
143 SmartDataPtr<EvtRecPi0Col> recPi0Col(eventSvc(),
"/Event/EvtRec/EvtRecPi0Col");
145 log << MSG::FATAL <<
"Could not find EvtRecPi0Col" << endreq;
146 return StatusCode::FAILURE;
149 SmartDataPtr<EvtRecEtaToGGCol> recEtaToGGCol(eventSvc(),
"/Event/EvtRec/EvtRecEtaToGGCol");
150 if ( ! recEtaToGGCol ) {
151 log << MSG::FATAL <<
"Could not find EvtRecEtaToGGCol" << endreq;
152 return StatusCode::FAILURE;
156 SmartDataPtr<EvtRecVeeVertexCol> recVeeVertexCol(eventSvc(),
"/Event/EvtRec/EvtRecVeeVertexCol");
157 if ( ! recVeeVertexCol ) {
158 log << MSG::FATAL <<
"Could not find EvtRecVeeVertexCol" << endreq;
159 return StatusCode::FAILURE;
165 log << MSG::FATAL <<
"EvtRecDTagCol is not registered yet" << endreq;
166 return StatusCode::FAILURE;
171 Hep3Vector xorigin(0,0,0);
173 Gaudi::svcLocator()->service(
"VertexDbSvc", vtxsvc);
178 xorigin.setX(vertex[0]);
179 xorigin.setY(vertex[1]);
180 xorigin.setZ(vertex[2]);
208 dc_fill(ksList, recVeeVertexCol->begin(), recVeeVertexCol->end());
212 map<EvtRecVeeVertex*, vector< double > > fitinfo;
213 for(
CDKsList::iterator ksit = ksList.particle_begin(); ksit != ksList.particle_end(); ++ksit ){
219 dc_fill(pi0List, recPi0Col->begin(), recPi0Col->end());
222 dc_fill(etaList, recEtaToGGCol->begin(), recEtaToGGCol->end());
231 int run = eventHeader->runNumber();
232 m_ievt = eventHeader->eventNumber();
233 m_nChrg = recEvent->totalCharged();
234 m_nNeu = recEvent->totalNeutral();
235 m_nPion = pionList.
size();
236 m_nKaon = kaonList.
size();
237 m_nPi0 = pi0List.size();
238 m_nKs = ksList.size();
245 if(m_RdMeasuredEcms&&m_irun!=run){
248 m_beta.setX(ecmsSvc->
getPx(run));
249 m_beta.setY(ecmsSvc->
getPy(run));
250 m_beta.setZ(ecmsSvc->
getPz(run));
253 log << MSG::INFO <<
"MeasuredEcmsSvc: " <<m_beamE<< endreq;
256 if(m_ReadBeamEFromDB && m_irun!=run){
260 m_beamE=m_readDb.
getbeamE(m_irun,m_beamE);
265 double ebeam=m_beamE;
272 for(
int list=0;list<chanlist.size();list++){
274 string channel=chanlist[list];
289 if(channel==
"DstoKsK") {
291 numchan.push_back(5);
292 numchan.push_back(1);
293 decaylist=ksList* kaonList.
plus();
295 else if(channel==
"DstoKKPi") {
297 numchan.push_back(1);
298 numchan.push_back(1);
299 numchan.push_back(2);
300 decaylist=kaonList.
minus()* kaonList.
plus()* pionList.
plus();
302 else if(channel==
"DstoKsKPi0") {
304 numchan.push_back(5);
305 numchan.push_back(1);
306 numchan.push_back(3);
307 decaylist=ksList* kaonList.
plus()* pi0List;
309 else if(channel==
"DstoKsKsPi") {
311 numchan.push_back(5);
312 numchan.push_back(5);
313 numchan.push_back(2);
314 decaylist=ksList* ksList* pionList.
plus();
316 else if(channel==
"DstoKKPiPi0") {
318 numchan.push_back(1);
319 numchan.push_back(1);
320 numchan.push_back(2);
321 numchan.push_back(3);
322 decaylist=kaonList.
minus()* kaonList.
plus()* pionList.
plus()* pi0List;
324 else if(channel==
"DstoKsKplusPiPi") {
326 numchan.push_back(5);
327 numchan.push_back(1);
328 numchan.push_back(2);
329 numchan.push_back(2);
330 decaylist=ksList* kaonList.
plus()* pionList.
plus()* pionList.
minus();
332 else if(channel==
"DstoKsKminusPiPi") {
334 numchan.push_back(5);
335 numchan.push_back(1);
336 numchan.push_back(2);
337 numchan.push_back(2);
338 decaylist=ksList* kaonList.
minus()* pionList.
plus()* pionList.
plus();
340 else if(channel==
"DstoKKPiPiPi") {
342 numchan.push_back(1);
343 numchan.push_back(1);
344 numchan.push_back(2);
345 numchan.push_back(2);
346 numchan.push_back(2);
349 else if(channel==
"DstoPiPi0") {
351 numchan.push_back(2);
352 numchan.push_back(3);
353 decaylist=pionList.
plus()* pi0List;
355 else if(channel==
"DstoPiPiPi") {
357 numchan.push_back(2);
358 numchan.push_back(2);
359 numchan.push_back(2);
360 decaylist=pionList.
plus()* pionList.
plus()* pionList.
minus();
362 else if(channel==
"DstoPiPiPiPi0") {
364 numchan.push_back(2);
365 numchan.push_back(2);
366 numchan.push_back(2);
367 numchan.push_back(3);
368 decaylist=pionList.
plus()* pionList.
plus()* pionList.
minus()* pi0List;
370 else if(channel==
"DstoPiPiPiPiPi") {
372 numchan.push_back(2);
373 numchan.push_back(2);
374 numchan.push_back(2);
375 numchan.push_back(2);
376 numchan.push_back(2);
379 else if(channel==
"DstoPiPiPiPiPiPi0") {
381 numchan.push_back(2);
382 numchan.push_back(2);
383 numchan.push_back(2);
384 numchan.push_back(2);
385 numchan.push_back(2);
386 numchan.push_back(3);
389 else if(channel==
"DstoPiPiPiPi0Pi0") {
391 numchan.push_back(2);
392 numchan.push_back(2);
393 numchan.push_back(2);
394 numchan.push_back(3);
395 numchan.push_back(3);
396 decaylist=pionList.
plus()* pionList.
plus()* pionList.
minus()* pi0List* pi0List;
398 else if(channel==
"DstoPiEta") {
400 numchan.push_back(2);
401 numchan.push_back(4);
402 decaylist=pionList.
plus()* etaList;
404 else if(channel==
"DstoPiEtaPiPiPi0") {
406 numchan.push_back(2);
407 numchan.push_back(9);
409 EtaList=pionList.
plus()* pionList.
minus()* pi0List;
410 decaylist=pionList.
plus()* EtaList;
412 else if(channel==
"DstoPiPi0Eta") {
414 numchan.push_back(2);
415 numchan.push_back(3);
416 numchan.push_back(4);
417 decaylist=pionList.
plus()* pi0List* etaList;
419 else if(channel==
"DstoPiPi0EtaPiPiPi0") {
421 numchan.push_back(2);
422 numchan.push_back(3);
423 numchan.push_back(9);
425 EtaList=pionList.
plus()* pionList.
minus()* pi0List;
426 decaylist=pionList.
plus()* pi0List* EtaList;
428 else if(channel==
"DstoPiPiPiEta") {
430 numchan.push_back(2);
431 numchan.push_back(2);
432 numchan.push_back(2);
433 numchan.push_back(4);
434 decaylist=pionList.
plus()* pionList.
plus()* pionList.
minus()* etaList;
436 else if(channel==
"DstoPiPiPiEtaPiPiPi0") {
438 numchan.push_back(2);
439 numchan.push_back(2);
440 numchan.push_back(2);
441 numchan.push_back(9);
443 EtaList=pionList.
plus()* pionList.
minus()* pi0List;
444 decaylist=pionList.
plus()* pionList.
plus()* pionList.
minus()* EtaList;
446 else if(channel==
"DstoPiEPPiPiEta") {
448 numchan.push_back(2);
449 numchan.push_back(6);
451 epList=pionList.
plus()* pionList.
minus()* etaList;
452 decaylist=pionList.
plus()* epList;
454 else if(channel==
"DstoPiPi0EPPiPiEta") {
456 numchan.push_back(2);
457 numchan.push_back(3);
458 numchan.push_back(6);
460 epList=pionList.
plus()* pionList.
minus()* etaList;
461 decaylist=pionList.
plus()* pi0List* epList;
463 else if(channel==
"DstoPiEPPiPiEtaPiPiPi0") {
465 numchan.push_back(2);
466 numchan.push_back(8);
468 EtaList=pionList.
plus()* pionList.
minus()* pi0List;
470 EtapList=pionList.
plus()* pionList.
minus()* EtaList;
471 decaylist=pionList.
plus()* EtapList;
473 else if(channel==
"DstoPiPi0EPPiPiEtaPiPiPi0") {
475 numchan.push_back(2);
476 numchan.push_back(3);
477 numchan.push_back(8);
479 EtaList=pionList.
plus()* pionList.
minus()* pi0List;
481 EtapList=pionList.
plus()* pionList.
minus()* EtaList;
482 decaylist=pionList.
plus()* pi0List* EtapList;
485 else if(channel==
"DstoPiEPRhoGam") {
487 numchan.push_back(2);
488 numchan.push_back(7);
490 rhoList=pionList.
plus()* pionList.
minus();
492 epList=rhoList* photonList;
493 decaylist=pionList.
plus()* epList;
495 else if(channel==
"DstoPiPi0EPRhoGam") {
497 numchan.push_back(2);
498 numchan.push_back(3);
499 numchan.push_back(7);
501 rhoList=pionList.
plus()* pionList.
minus();
503 epList=rhoList* photonList;
504 decaylist=pionList.
plus()* pi0List* epList;
506 else if(channel==
"DstoKsPi") {
508 numchan.push_back(5);
509 numchan.push_back(2);
510 decaylist=ksList* pionList.
plus();
512 else if(channel==
"DstoKsPiPi0") {
514 numchan.push_back(5);
515 numchan.push_back(2);
516 numchan.push_back(3);
517 decaylist=ksList* pionList.
plus()* pi0List;
519 else if(channel==
"DstoKPiPi") {
521 numchan.push_back(1);
522 numchan.push_back(2);
523 numchan.push_back(2);
524 decaylist=kaonList.
plus()* pionList.
plus()* pionList.
minus();
526 else if(channel==
"DstoKPiPiPi0") {
528 numchan.push_back(1);
529 numchan.push_back(2);
530 numchan.push_back(2);
531 numchan.push_back(3);
532 decaylist=kaonList.
plus()* pionList.
plus()* pionList.
minus()* pi0List;
534 else if(channel==
"DstoKKK") {
536 numchan.push_back(1);
537 numchan.push_back(1);
538 numchan.push_back(1);
539 decaylist=kaonList.
minus()* kaonList.
plus()* kaonList.
plus();
550 vector<int> trackid, showerid;
551 vector<int> kaonid, pionid;
552 int numofchildren=numchan.size()-1;
554 for(
int i=0; i< numofchildren;i++){
556 const CDCandidate& daughter=(*it).particle().child(i);
560 trackid.push_back(track->
trackId());
561 kaonid.push_back(track->
trackId());
563 else if(numchan[i+1]==2){
565 trackid.push_back(track->
trackId());
566 pionid.push_back(track->
trackId());
568 else if ( numchan[i+1]==3){
571 showerid.push_back(hiEnGamma->
trackId());
572 showerid.push_back(loEnGamma->
trackId());
574 else if ( numchan[i+1]==4){
577 showerid.push_back(hiEnGamma->
trackId());
578 showerid.push_back(loEnGamma->
trackId());
580 else if ( numchan[i+1]==5){
584 recDTag->
addToFitInfo(aKsCand->
mass(),fitinfo[aKsCand][0],fitinfo[aKsCand][1],fitinfo[aKsCand][2]);
588 trackid.push_back(pion1Trk->
trackId());
589 trackid.push_back(pion2Trk->
trackId());
591 else if (numchan[i+1]==6){
600 trackid.push_back(apiontrk->
trackId());
601 trackid.push_back(spiontrk->
trackId());
602 showerid.push_back(hiEnGamma->
trackId());
603 showerid.push_back(loEnGamma->
trackId());
606 else if (numchan[i+1]==7){
617 trackid.push_back(apiontrk->
trackId());
618 trackid.push_back(spiontrk->
trackId());
619 showerid.push_back(gammatrk->
trackId());
622 else if (numchan[i+1]==8){
638 trackid.push_back(apiontrk->
trackId());
639 trackid.push_back(spiontrk->
trackId());
640 trackid.push_back(e0piontrk->
trackId());
641 trackid.push_back(e1piontrk->
trackId());
642 showerid.push_back(hiEnGamma->
trackId());
643 showerid.push_back(loEnGamma->
trackId());
646 else if (numchan[i+1]==9){
655 trackid.push_back(apiontrk->
trackId());
656 trackid.push_back(spiontrk->
trackId());
657 showerid.push_back(hiEnGamma->
trackId());
658 showerid.push_back(loEnGamma->
trackId());
667 savetrack(trackid,showerid,charged_begin,charged_end,neutral_begin,neutral_end,recDTag);
668 pidtag(kaonid,pionid,kaonList_tight, pionList_tight,recDTag);
672 HepLorentzVector p4change_vfit=util.
vfit(channel, kaonid, pionid, xorigin, charged_begin);
673 recDTag->
setp4(recDTag->
p4()+p4change_vfit);
685 recDTagCol->push_back(recDTag);
695 return StatusCode::SUCCESS;
701 double mass = (*it).particle().mass();
702 int charge= (*it).particle().charge();
703 HepLorentzVector p4((*it).particle().momentum(), (*it).particle().energy());
707 double mbc2_CMS =
ebeam*
ebeam - p4.v().mag2();
708 double mbc_CMS = mbc2_CMS > 0 ? sqrt( mbc2_CMS ) : -10;
709 double deltaE_CMS = p4.t() -
ebeam;
711 if((*it).particle().userTag()==1)
728 vector<EvtRecTrackIterator> trktemp;
729 vector<EvtRecTrackIterator> shrtemp;
734 bool isothertrack=
true;
735 for(
int i=0; i<trackid.size(); i++){
736 if( (*trk)->trackId()==trackid[i] ){
737 trktemp.push_back(trk);
745 for(
int i=0; i<trackid.size();i++){
746 for(
int j=0; j<trktemp.size(); j++){
748 if( (*trk)->trackId()==trackid[i])
756 bool isothershower=
true;
757 for(
int i=0; i<showerid.size(); i++){
758 if( (*shr)->trackId()==showerid[i] ){
759 shrtemp.push_back(shr);
768 for(
int i=0; i<showerid.size();i++){
769 for(
int j=0; j<shrtemp.size(); j++){
771 if( (*shr)->trackId()==showerid[i])
781 bool iskaon=
false,ispion=
false;
787 recDTag->
addKaonId( (*kit).particle().track() );
791 recDTag->
addPionId( (*pit).particle().track() );
841 inFile.open(filename.c_str());
843 cout <<
"Unable to open decay list file";
847 while (inFile >> channel) {
848 temp.push_back(channel);
void dc_fill(DCFillableChargedList< Charged > &aFillableList, WitnessIterator first, WitnessIterator last)
ObjectVector< EvtRecDTag > EvtRecDTagCol
EvtRecTrackCol::iterator EvtRecTrackIterator
LocalEptoPiPiEta3PiSelector eptoPiPiEta3PiSelector
LocalEptoPiPiEtaSelector eptoPiPiEtaSelector
LocalEptoRhoGamSelector eptoRhoGamSelector
LocalEtatoGGSelector etatoGGSelector
LocalEtatoPiPiPi0Selector etatoPiPiPi0Selector
LocalKaonSelector kaonSelector
LocalKsSelector ksSelector
LocalPhotonSelector photonSelector
LocalPi0Selector pi0Selector
LocalPionSelector pionSelector
LocalRhotoPiPiSelector rhotoPiPiSelector
virtual const DecayEvidence & decay() const
virtual const EvtRecTrack * photon() const
virtual const EvtRecTrack * track() const
virtual const EvtRecVeeVertex * navKshort() const
virtual const EvtRecPi0 * navPi0() const
virtual const EvtRecEtaToGG * navEta() const
const CDCandidate & child(unsigned int aPosition) const
vector< string > getlist(string &filename)
void savetrack(vector< int >, vector< int >, EvtRecTrackIterator, EvtRecTrackIterator, EvtRecTrackIterator, EvtRecTrackIterator, EvtRecDTag *)
DsReconstruction(const std::string &name, ISvcLocator *pSvcLocator)
void pidtag(vector< int >, vector< int >, CDChargedKaonList &, CDChargedPionList &, EvtRecDTag *)
void saveDsInfo(CDDecayList::iterator, double, int, EvtRecDTag *)
void setbeta(Hep3Vector beta)
void setebeam(double ebeam)
@ kDstoPiPi0EPPiPiEtaPiPiPi0
@ kDstoPiEPPiPiEtaPiPiPi0
void addOtherTrack(const SmartRef< EvtRecTrack > track)
void settype(SelType type)
void setdecayMode(DecayMode decayMode)
HepLorentzVector p4() const
void setp4(HepLorentzVector p4)
void setmass(double mass)
void addToFitInfo(double ksmass, double chi2, double length, double error)
void addOtherShower(const SmartRef< EvtRecTrack > shower)
void addKaonId(const SmartRef< EvtRecTrack > kaonId)
void setdeltaE(double deltaE)
void setcharge(int charge)
void addPionId(const SmartRef< EvtRecTrack > pionId)
void setbeamE(double beamE)
void addShower(const SmartRef< EvtRecTrack > shower)
void setnumOfChildren(int numOfChildren)
void addTrack(const SmartRef< EvtRecTrack > track)
const EvtRecTrack * hiEnGamma() const
const EvtRecTrack * loEnGamma() const
const EvtRecTrack * loEnGamma() const
const EvtRecTrack * hiEnGamma() const
SmartRef< EvtRecTrack > & daughter(int i)
virtual double getPz(int runNo)=0
virtual bool isReadDBValid(int runNo, char *tab, char *col)=0
virtual double getPx(int runNo)=0
virtual double getInfo(int runNo, char *tab, char *col)=0
virtual bool isRunNoValid(int runNo)=0
virtual double getPy(int runNo)=0
virtual bool isVertexValid()=0
virtual double * PrimaryVertex()=0
void setpidtype(int type)
void setpidtype(int type)
bool setcalib(bool calib)
CLHEP::Hep3Vector getbeta()
ChosenChargeList< Charged, CandidateClass > & plus() const
ChosenChargeList< Charged, CandidateClass > & minus() const
iterator particle_begin()
virtual iterator particle_begin()
virtual iterator particle_end()
HepLorentzVector vfit(string channel, vector< int > kaonid, vector< int > pionid, HepPoint3D vx, EvtRecTrackIterator charged_begin)
vector< double > SecondaryVFit(EvtRecVeeVertex *ks, IVertexDbSvc *vtxsvc)
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecDTagCol
_EXTERN_ std::string EvtRecTrackCol