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/NeutralDReconstruction.h"
38#include "DTagAlg/LocalKaonSelector.h"
39#include "DTagAlg/LocalPionSelector.h"
40#include "DTagAlg/LocalKsSelector.h"
41#include "DTagAlg/LocalPi0Selector.h"
42#include "DTagAlg/LocalEtatoGGSelector.h"
43#include "DTagAlg/LocalPhotonSelector.h"
44#include "DTagAlg/LocalEptoPiPiEtaSelector.h"
45#include "DTagAlg/LocalEptoRhoGamSelector.h"
46#include "DTagAlg/LocalRhotoPiPiSelector.h"
47#include "DTagAlg/NeutralDSelector.h"
49#include "DTagAlg/utility.h"
58Algorithm(name, pSvcLocator) {
60 declareProperty(
"debug", m_debug =
false );
61 declareProperty(
"ReadBeamEFromDB", m_ReadBeamEFromDB =
false );
62 declareProperty(
"UseCalibBeamE", m_usecalibBeamE =
false );
63 declareProperty(
"UseVertexfit", m_usevertexfit =
false );
64 declareProperty(
"BeamE", m_beamE = 1.8865 );
65 declareProperty(
"D0List", m_decaylist =
"test.txt" );
66 declareProperty(
"ReadMeasuredEcms", m_RdMeasuredEcms =
false);
71 MsgStream log(
msgSvc(), name());
72 log << MSG::INFO <<
"in initialize()" <<endreq;
82 StatusCode status=serviceLocator()->service(
"MeasuredEcmsSvc", ecmsSvc,
true);
83 if(!status.isSuccess()){
84 std::cout<<
"ERROR: Can not initial the IMeasuredEcmsSvc right"<<std::endl;
90 return StatusCode::SUCCESS;
95 MsgStream log(
msgSvc(), name());
96 log << MSG::INFO <<
"in finalize()" << endreq;
100 return StatusCode::SUCCESS;
103StatusCode NeutralDReconstruction::registerEvtRecDTagCol(
105 StatusCode sc = eventSvc()->registerObject(
"/Event/EvtRec/EvtRecDTagCol",
107 if (sc != StatusCode::SUCCESS) {
108 log << MSG::FATAL <<
"Could not register EvtRecDTagCol in TDS!" << endreq;
115 MsgStream log(
msgSvc(), name());
116 log << MSG::INFO <<
"in execute()" << endreq;
123 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
124 int event= eventHeader->eventNumber();
130 log << MSG::DEBUG <<
"run and event = " << eventHeader->runNumber()
131 <<
" " << eventHeader->eventNumber() << endreq;
132 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
133 << recEvent->totalCharged() <<
" , "
134 << recEvent->totalNeutral() <<
" , "
135 << recEvent->totalTracks() <<endreq;
144 SmartDataPtr<EvtRecPi0Col> recPi0Col(eventSvc(),
"/Event/EvtRec/EvtRecPi0Col");
146 log << MSG::FATAL <<
"Could not find EvtRecPi0Col" << endreq;
147 return StatusCode::FAILURE;
152 SmartDataPtr<EvtRecEtaToGGCol> recEtaToGGCol(eventSvc(),
"/Event/EvtRec/EvtRecEtaToGGCol");
153 if ( ! recEtaToGGCol ) {
154 log << MSG::FATAL <<
"Could not find EvtRecEtaToGGCol" << endreq;
155 return StatusCode::FAILURE;
159 SmartDataPtr<EvtRecVeeVertexCol> recVeeVertexCol(eventSvc(),
"/Event/EvtRec/EvtRecVeeVertexCol");
160 if ( ! recVeeVertexCol ) {
161 log << MSG::FATAL <<
"Could not find EvtRecVeeVertexCol" << endreq;
162 return StatusCode::FAILURE;
168 log << MSG::FATAL <<
"EvtRecDTagCol is not registered in TDS" << endreq;
169 return StatusCode::FAILURE;
173 Hep3Vector xorigin(0,0,0);
175 Gaudi::svcLocator()->service(
"VertexDbSvc", vtxsvc);
180 xorigin.setX(vertex[0]);
181 xorigin.setY(vertex[1]);
182 xorigin.setZ(vertex[2]);
210 dc_fill(ksList, recVeeVertexCol->begin(), recVeeVertexCol->end());
213 map<EvtRecVeeVertex*, vector< double > > fitinfo;
214 for(
CDKsList::iterator ksit = ksList.particle_begin(); ksit != ksList.particle_end(); ++ksit ){
220 dc_fill(pi0List, recPi0Col->begin(), recPi0Col->end());
223 dc_fill(etaList, recEtaToGGCol->begin(), recEtaToGGCol->end());
232 int run = eventHeader->runNumber();
233 m_ievt = eventHeader->eventNumber();
234 m_nChrg = recEvent->totalCharged();
235 m_nNeu = recEvent->totalNeutral();
236 m_nPion = pionList.
size();
237 m_nKaon = kaonList.
size();
238 m_nPi0 = pi0List.size();
239 m_nKs = ksList.size();
246 if(m_RdMeasuredEcms&&m_irun!=run){
249 m_beta.setX(ecmsSvc->
getPx(run));
250 m_beta.setY(ecmsSvc->
getPy(run));
251 m_beta.setZ(ecmsSvc->
getPz(run));
254 log << MSG::INFO <<
"MeasuredEcmsSvc: " <<m_beamE<< endreq;
257 if(m_ReadBeamEFromDB && m_irun!=run){
261 m_beamE=m_readDb.
getbeamE(m_irun, m_beamE);
267 double ebeam=m_beamE;
275 for(
int list=0;list<chanlist.size();list++){
277 string channel=chanlist[list];
283 bool isFlavorMode=
false;
290 if(channel==
"D0toKPi") {
292 numchan.push_back(1);
293 numchan.push_back(2);
294 decaylist=kaonList.
minus() * pionList.
plus();
297 else if(channel==
"D0toKPiPi0"){
299 numchan.push_back(1);
300 numchan.push_back(2);
301 numchan.push_back(3);
302 decaylist=kaonList.
minus() * pionList.
plus() * pi0List;
305 else if(channel==
"D0toKPiPi0Pi0"){
307 numchan.push_back(1);
308 numchan.push_back(2);
309 numchan.push_back(3);
310 numchan.push_back(3);
311 decaylist=kaonList.
minus() * pionList.
plus() * pi0List * pi0List;
314 else if(channel==
"D0toKPiPiPi"){
316 numchan.push_back(1);
317 numchan.push_back(2);
318 numchan.push_back(2);
319 numchan.push_back(2);
323 else if(channel==
"D0toKPiPiPiPi0"){
325 numchan.push_back(1);
326 numchan.push_back(2);
327 numchan.push_back(2);
328 numchan.push_back(2);
329 numchan.push_back(3);
330 decaylist=kaonList.
minus()* pionList.
plus()* pionList.
plus()* pionList.
minus()* pi0List;
333 else if(channel==
"D0toKPiEta"){
335 numchan.push_back(1);
336 numchan.push_back(2);
337 numchan.push_back(4);
338 decaylist=kaonList.
minus() * pionList.
plus() * etaList;
341 else if(channel==
"D0toKsKPi"){
343 numchan.push_back(5);
344 numchan.push_back(1);
345 numchan.push_back(2);
346 decaylist=ksList* kaonList.
minus()* pionList.
plus();
348 else if(channel==
"D0toKsKPiPi0"){
350 numchan.push_back(5);
351 numchan.push_back(1);
352 numchan.push_back(2);
353 numchan.push_back(3);
354 decaylist=ksList* kaonList.
minus() * pionList.
plus()* pi0List;
356 else if(channel==
"D0toKsPiPi"){
358 numchan.push_back(5);
359 numchan.push_back(2);
360 numchan.push_back(2);
361 decaylist=ksList* pionList.
plus()* pionList.
minus();
363 else if(channel==
"D0toKsPiPiPi0"){
365 numchan.push_back(5);
366 numchan.push_back(2);
367 numchan.push_back(2);
368 numchan.push_back(3);
369 decaylist=ksList* pionList.
plus()* pionList.
minus()* pi0List;
371 else if(channel==
"D0toKsPi0"){
373 numchan.push_back(5);
374 numchan.push_back(3);
375 decaylist=ksList* pi0List;
377 else if(channel==
"D0toPiPiPi0"){
379 numchan.push_back(2);
380 numchan.push_back(2);
381 numchan.push_back(3);
382 decaylist=pionList.
plus()* pionList.
minus()* pi0List;
384 else if(channel==
"D0toPiPi"){
386 numchan.push_back(2);
387 numchan.push_back(2);
388 decaylist=pionList.
plus()* pionList.
minus();
390 else if(channel==
"D0toKK"){
392 numchan.push_back(1);
393 numchan.push_back(1);
394 decaylist=kaonList.
minus()* kaonList.
plus();
396 else if(channel==
"D0toKKPi0"){
398 numchan.push_back(1);
399 numchan.push_back(1);
400 numchan.push_back(3);
401 decaylist=kaonList.
minus()* kaonList.
plus()* pi0List;
403 else if(channel==
"D0toPi0Pi0"){
405 numchan.push_back(3);
406 numchan.push_back(3);
407 decaylist=pi0List* pi0List;
409 else if(channel==
"D0toKsKs"){
411 numchan.push_back(5);
412 numchan.push_back(5);
413 decaylist=ksList* ksList;
415 else if(channel==
"D0toKsKsPi0"){
417 numchan.push_back(5);
418 numchan.push_back(5);
419 numchan.push_back(3);
420 decaylist=ksList* ksList* pi0List;
422 else if(channel==
"D0toKsPi0Pi0"){
424 numchan.push_back(5);
425 numchan.push_back(3);
426 numchan.push_back(3);
427 decaylist=ksList* pi0List* pi0List;
429 else if(channel==
"D0toKsKK"){
431 numchan.push_back(5);
432 numchan.push_back(1);
433 numchan.push_back(1);
434 decaylist=ksList* kaonList.
minus()* kaonList.
plus();
436 else if(channel==
"D0toKsEta"){
438 numchan.push_back(5);
439 numchan.push_back(4);
440 decaylist=ksList* etaList;
442 else if(channel==
"D0toPi0Pi0Pi0"){
444 numchan.push_back(3);
445 numchan.push_back(3);
446 numchan.push_back(3);
447 decaylist=pi0List* pi0List* pi0List;
449 else if(channel==
"D0toKsKsKs"){
451 numchan.push_back(5);
452 numchan.push_back(5);
453 numchan.push_back(5);
454 decaylist=ksList* ksList* ksList;
456 else if(channel==
"D0toPiPiPiPi"){
458 numchan.push_back(2);
459 numchan.push_back(2);
460 numchan.push_back(2);
461 numchan.push_back(2);
464 else if(channel==
"D0toPiPiPi0Pi0"){
466 numchan.push_back(2);
467 numchan.push_back(2);
468 numchan.push_back(3);
469 numchan.push_back(3);
470 decaylist=pionList.
plus()* pionList.
minus()* pi0List* pi0List;
472 else if(channel==
"D0toKKPiPi"){
474 numchan.push_back(1);
475 numchan.push_back(1);
476 numchan.push_back(2);
477 numchan.push_back(2);
480 else if(channel==
"D0toKKPi0Pi0"){
482 numchan.push_back(1);
483 numchan.push_back(1);
484 numchan.push_back(3);
485 numchan.push_back(3);
486 decaylist=kaonList.
minus()* kaonList.
plus()* pi0List* pi0List;
488 else if(channel==
"D0toKsKsPiPi"){
490 numchan.push_back(5);
491 numchan.push_back(5);
492 numchan.push_back(2);
493 numchan.push_back(2);
494 decaylist=ksList* ksList* pionList.
plus()* pionList.
minus();
496 else if(channel==
"D0toPiPiPiPiPi0"){
498 numchan.push_back(2);
499 numchan.push_back(2);
500 numchan.push_back(2);
501 numchan.push_back(2);
502 numchan.push_back(3);
503 decaylist=pionList.
plus()* pionList.
plus()* pionList.
minus()* pionList.
minus()* pi0List;
505 else if(channel==
"D0toKsPiPiPiPi"){
507 numchan.push_back(5);
508 numchan.push_back(2);
509 numchan.push_back(2);
510 numchan.push_back(2);
511 numchan.push_back(2);
512 decaylist=ksList* pionList.
plus()* pionList.
plus()* pionList.
minus()* pionList.
minus();
514 else if(channel==
"D0toKKPiPiPi0"){
516 numchan.push_back(1);
517 numchan.push_back(1);
518 numchan.push_back(2);
519 numchan.push_back(2);
520 numchan.push_back(3);
521 decaylist=kaonList.
minus()* kaonList.
plus()* pionList.
plus()* pionList.
minus()* pi0List;
523 else if(channel==
"D0toKsPi0Eta"){
525 numchan.push_back(5);
526 numchan.push_back(3);
527 numchan.push_back(4);
528 decaylist=ksList* pi0List* etaList;
530 else if(channel==
"D0toKsEPPiPiEta"){
532 numchan.push_back(5);
533 numchan.push_back(6);
535 epList=pionList.
plus()* pionList.
minus()* etaList;
536 decaylist= ksList* epList;
538 else if(channel==
"D0toKsEPRhoGam"){
540 numchan.push_back(5);
541 numchan.push_back(7);
543 rhoList=pionList.
plus()* pionList.
minus();
545 epList=rhoList* photonList;
546 decaylist= ksList* epList;
548 else if(channel==
"D0toKsPi0Pi0Pi0"){
550 numchan.push_back(5);
551 numchan.push_back(3);
552 numchan.push_back(3);
553 numchan.push_back(3);
554 decaylist=ksList* pi0List* pi0List* pi0List;
567 vector<int> trackid, showerid;
568 vector<int> kaonid, pionid;
570 int numofchildren=numchan.size()-1;
572 for(
int i=0; i< numofchildren;i++){
574 const CDCandidate& daughter=(*it).particle().child(i);
575 if(isFlavorMode && i==0)
580 trackid.push_back(track->
trackId());
581 kaonid.push_back(track->
trackId());
583 else if(numchan[i+1]==2){
585 trackid.push_back(track->
trackId());
586 pionid.push_back(track->
trackId());
588 else if ( numchan[i+1]==3){
591 showerid.push_back(hiEnGamma->
trackId());
592 showerid.push_back(loEnGamma->
trackId());
594 else if ( numchan[i+1]==4){
597 showerid.push_back(hiEnGamma->
trackId());
598 showerid.push_back(loEnGamma->
trackId());
600 else if ( numchan[i+1]==5){
603 recDTag->
addToFitInfo(aKsCand->
mass(),fitinfo[aKsCand][0],fitinfo[aKsCand][1],fitinfo[aKsCand][2]);
607 trackid.push_back(pion1Trk->
trackId());
608 trackid.push_back(pion2Trk->
trackId());
610 else if (numchan[i+1]==6){
619 trackid.push_back(apiontrk->
trackId());
620 trackid.push_back(spiontrk->
trackId());
621 showerid.push_back(hiEnGamma->
trackId());
622 showerid.push_back(loEnGamma->
trackId());
625 else if (numchan[i+1]==7){
637 trackid.push_back(apiontrk->
trackId());
638 trackid.push_back(spiontrk->
trackId());
639 showerid.push_back(gammatrk->
trackId());
648 savetrack(trackid,showerid,charged_begin,charged_end,neutral_begin,neutral_end,recDTag);
649 pidtag(kaonid,pionid,kaonList_tight, pionList_tight,recDTag);
652 HepLorentzVector p4change_vfit=util.
vfit(channel, kaonid, pionid, xorigin, charged_begin);
653 recDTag->
setp4(recDTag->
p4()+p4change_vfit);
664 recDTagCol->push_back(recDTag);
673 return StatusCode::SUCCESS;
678 double mass = (*it).particle().mass();
679 HepLorentzVector p4((*it).particle().momentum(), (*it).particle().energy());
683 double mbc2_CMS =
ebeam*
ebeam - p4.v().mag2();
684 double mbc_CMS = mbc2_CMS > 0 ? sqrt( mbc2_CMS ) : -10;
685 double deltaE_CMS = p4.t() -
ebeam;
687 int tag=(*it).particle().userTag();
705 vector<EvtRecTrackIterator> trktemp;
706 vector<EvtRecTrackIterator> shrtemp;
711 bool isothertrack=
true;
712 for(
int i=0; i<trackid.size(); i++){
713 if( (*trk)->trackId()==trackid[i] ){
714 trktemp.push_back(trk);
722 for(
int i=0; i<trackid.size();i++){
723 for(
int j=0; j<trktemp.size(); j++){
725 if( (*trk)->trackId()==trackid[i])
733 bool isothershower=
true;
734 for(
int i=0; i<showerid.size(); i++){
735 if( (*shr)->trackId()==showerid[i] ){
736 shrtemp.push_back(shr);
745 for(
int i=0; i<showerid.size();i++){
746 for(
int j=0; j<shrtemp.size(); j++){
748 if( (*shr)->trackId()==showerid[i])
759 bool iskaon=
false,ispion=
false;
765 recDTag->
addKaonId( (*kit).particle().track() );
769 recDTag->
addPionId( (*pit).particle().track() );
821 inFile.open(filename.c_str());
823 cout <<
"Unable to open decay list file";
827 while (inFile >> channel) {
828 temp.push_back(channel);
void dc_fill(DCFillableChargedList< Charged > &aFillableList, WitnessIterator first, WitnessIterator last)
ObjectVector< EvtRecDTag > EvtRecDTagCol
EvtRecTrackCol::iterator EvtRecTrackIterator
LocalEptoPiPiEtaSelector eptoPiPiEtaSelector
LocalEptoRhoGamSelector eptoRhoGamSelector
LocalEtatoGGSelector etatoGGSelector
LocalKaonSelector kaonSelector
LocalKsSelector ksSelector
LocalPhotonSelector photonSelector
LocalPi0Selector pi0Selector
LocalPionSelector pionSelector
LocalRhotoPiPiSelector rhotoPiPiSelector
NeutralDSelector neutralDSelector
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
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)
NeutralDReconstruction(const std::string &name, ISvcLocator *pSvcLocator)
void savetrack(vector< int >, vector< int >, EvtRecTrackIterator, EvtRecTrackIterator, EvtRecTrackIterator, EvtRecTrackIterator, EvtRecDTag *)
vector< string > getlist(string &filename)
void pidtag(vector< int >, vector< int >, CDChargedKaonList &, CDChargedPionList &, EvtRecDTag *)
void saveD0Info(CDDecayList::iterator, double, int, int, EvtRecDTag *)
void setbeta(Hep3Vector beta)
void setebeam(double ebeam)
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