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" );
70 MsgStream log(
msgSvc(), name());
71 log << MSG::INFO <<
"in initialize()" <<endreq;
80 return StatusCode::SUCCESS;
85 MsgStream log(
msgSvc(), name());
86 log << MSG::INFO <<
"in finalize()" << endreq;
90 return StatusCode::SUCCESS;
93StatusCode NeutralDReconstruction::registerEvtRecDTagCol(
95 StatusCode sc = eventSvc()->registerObject(
"/Event/EvtRec/EvtRecDTagCol",
97 if (sc != StatusCode::SUCCESS) {
98 log << MSG::FATAL <<
"Could not register EvtRecDTagCol in TDS!" << endreq;
105 MsgStream log(
msgSvc(), name());
106 log << MSG::INFO <<
"in execute()" << endreq;
113 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
114 int event= eventHeader->eventNumber();
120 log << MSG::DEBUG <<
"run and event = " << eventHeader->runNumber()
121 <<
" " << eventHeader->eventNumber() << endreq;
122 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
123 << recEvent->totalCharged() <<
" , "
124 << recEvent->totalNeutral() <<
" , "
125 << recEvent->totalTracks() <<endreq;
134 SmartDataPtr<EvtRecPi0Col> recPi0Col(eventSvc(),
"/Event/EvtRec/EvtRecPi0Col");
136 log << MSG::FATAL <<
"Could not find EvtRecPi0Col" << endreq;
137 return StatusCode::FAILURE;
142 SmartDataPtr<EvtRecEtaToGGCol> recEtaToGGCol(eventSvc(),
"/Event/EvtRec/EvtRecEtaToGGCol");
143 if ( ! recEtaToGGCol ) {
144 log << MSG::FATAL <<
"Could not find EvtRecEtaToGGCol" << endreq;
145 return StatusCode::FAILURE;
149 SmartDataPtr<EvtRecVeeVertexCol> recVeeVertexCol(eventSvc(),
"/Event/EvtRec/EvtRecVeeVertexCol");
150 if ( ! recVeeVertexCol ) {
151 log << MSG::FATAL <<
"Could not find EvtRecVeeVertexCol" << endreq;
152 return StatusCode::FAILURE;
158 log << MSG::FATAL <<
"EvtRecDTagCol is not registered in TDS" << endreq;
159 return StatusCode::FAILURE;
163 Hep3Vector xorigin(0,0,0);
165 Gaudi::svcLocator()->service(
"VertexDbSvc", vtxsvc);
170 xorigin.setX(vertex[0]);
171 xorigin.setY(vertex[1]);
172 xorigin.setZ(vertex[2]);
200 dc_fill(ksList, recVeeVertexCol->begin(), recVeeVertexCol->end());
203 map<EvtRecVeeVertex*, vector< double > > fitinfo;
204 for(
CDKsList::iterator ksit = ksList.particle_begin(); ksit != ksList.particle_end(); ++ksit ){
210 dc_fill(pi0List, recPi0Col->begin(), recPi0Col->end());
213 dc_fill(etaList, recEtaToGGCol->begin(), recEtaToGGCol->end());
222 int run = eventHeader->runNumber();
223 m_ievt = eventHeader->eventNumber();
224 m_nChrg = recEvent->totalCharged();
225 m_nNeu = recEvent->totalNeutral();
226 m_nPion = pionList.
size();
227 m_nKaon = kaonList.
size();
228 m_nPi0 = pi0List.size();
229 m_nKs = ksList.size();
235 if(m_ReadBeamEFromDB && m_irun!=run){
239 m_beamE=m_readDb.
getbeamE(m_irun, m_beamE);
245 double ebeam=m_beamE;
253 for(
int list=0;list<chanlist.size();list++){
255 string channel=chanlist[list];
261 bool isFlavorMode=
false;
268 if(channel==
"D0toKPi") {
270 numchan.push_back(1);
271 numchan.push_back(2);
272 decaylist=kaonList.
minus() * pionList.
plus();
275 else if(channel==
"D0toKPiPi0"){
277 numchan.push_back(1);
278 numchan.push_back(2);
279 numchan.push_back(3);
280 decaylist=kaonList.
minus() * pionList.
plus() * pi0List;
283 else if(channel==
"D0toKPiPi0Pi0"){
285 numchan.push_back(1);
286 numchan.push_back(2);
287 numchan.push_back(3);
288 numchan.push_back(3);
289 decaylist=kaonList.
minus() * pionList.
plus() * pi0List * pi0List;
292 else if(channel==
"D0toKPiPiPi"){
294 numchan.push_back(1);
295 numchan.push_back(2);
296 numchan.push_back(2);
297 numchan.push_back(2);
301 else if(channel==
"D0toKPiPiPiPi0"){
303 numchan.push_back(1);
304 numchan.push_back(2);
305 numchan.push_back(2);
306 numchan.push_back(2);
307 numchan.push_back(3);
308 decaylist=kaonList.
minus()* pionList.
plus()* pionList.
plus()* pionList.
minus()* pi0List;
311 else if(channel==
"D0toKPiEta"){
313 numchan.push_back(1);
314 numchan.push_back(2);
315 numchan.push_back(4);
316 decaylist=kaonList.
minus() * pionList.
plus() * etaList;
319 else if(channel==
"D0toKsKPi"){
321 numchan.push_back(5);
322 numchan.push_back(1);
323 numchan.push_back(2);
324 decaylist=ksList* kaonList.
minus()* pionList.
plus();
326 else if(channel==
"D0toKsKPiPi0"){
328 numchan.push_back(5);
329 numchan.push_back(1);
330 numchan.push_back(2);
331 numchan.push_back(3);
332 decaylist=ksList* kaonList.
minus() * pionList.
plus()* pi0List;
334 else if(channel==
"D0toKsPiPi"){
336 numchan.push_back(5);
337 numchan.push_back(2);
338 numchan.push_back(2);
339 decaylist=ksList* pionList.
plus()* pionList.
minus();
341 else if(channel==
"D0toKsPiPiPi0"){
343 numchan.push_back(5);
344 numchan.push_back(2);
345 numchan.push_back(2);
346 numchan.push_back(3);
347 decaylist=ksList* pionList.
plus()* pionList.
minus()* pi0List;
349 else if(channel==
"D0toKsPi0"){
351 numchan.push_back(5);
352 numchan.push_back(3);
353 decaylist=ksList* pi0List;
355 else if(channel==
"D0toPiPiPi0"){
357 numchan.push_back(2);
358 numchan.push_back(2);
359 numchan.push_back(3);
360 decaylist=pionList.
plus()* pionList.
minus()* pi0List;
362 else if(channel==
"D0toPiPi"){
364 numchan.push_back(2);
365 numchan.push_back(2);
366 decaylist=pionList.
plus()* pionList.
minus();
368 else if(channel==
"D0toKK"){
370 numchan.push_back(1);
371 numchan.push_back(1);
372 decaylist=kaonList.
minus()* kaonList.
plus();
374 else if(channel==
"D0toKKPi0"){
376 numchan.push_back(1);
377 numchan.push_back(1);
378 numchan.push_back(3);
379 decaylist=kaonList.
minus()* kaonList.
plus()* pi0List;
381 else if(channel==
"D0toPi0Pi0"){
383 numchan.push_back(3);
384 numchan.push_back(3);
385 decaylist=pi0List* pi0List;
387 else if(channel==
"D0toKsKs"){
389 numchan.push_back(5);
390 numchan.push_back(5);
391 decaylist=ksList* ksList;
393 else if(channel==
"D0toKsKsPi0"){
395 numchan.push_back(5);
396 numchan.push_back(5);
397 numchan.push_back(3);
398 decaylist=ksList* ksList* pi0List;
400 else if(channel==
"D0toKsPi0Pi0"){
402 numchan.push_back(5);
403 numchan.push_back(3);
404 numchan.push_back(3);
405 decaylist=ksList* pi0List* pi0List;
407 else if(channel==
"D0toKsKK"){
409 numchan.push_back(5);
410 numchan.push_back(1);
411 numchan.push_back(1);
412 decaylist=ksList* kaonList.
minus()* kaonList.
plus();
414 else if(channel==
"D0toKsEta"){
416 numchan.push_back(5);
417 numchan.push_back(4);
418 decaylist=ksList* etaList;
420 else if(channel==
"D0toPi0Pi0Pi0"){
422 numchan.push_back(3);
423 numchan.push_back(3);
424 numchan.push_back(3);
425 decaylist=pi0List* pi0List* pi0List;
427 else if(channel==
"D0toKsKsKs"){
429 numchan.push_back(5);
430 numchan.push_back(5);
431 numchan.push_back(5);
432 decaylist=ksList* ksList* ksList;
434 else if(channel==
"D0toPiPiPiPi"){
436 numchan.push_back(2);
437 numchan.push_back(2);
438 numchan.push_back(2);
439 numchan.push_back(2);
442 else if(channel==
"D0toPiPiPi0Pi0"){
444 numchan.push_back(2);
445 numchan.push_back(2);
446 numchan.push_back(3);
447 numchan.push_back(3);
448 decaylist=pionList.
plus()* pionList.
minus()* pi0List* pi0List;
450 else if(channel==
"D0toKKPiPi"){
452 numchan.push_back(1);
453 numchan.push_back(1);
454 numchan.push_back(2);
455 numchan.push_back(2);
458 else if(channel==
"D0toKKPi0Pi0"){
460 numchan.push_back(1);
461 numchan.push_back(1);
462 numchan.push_back(3);
463 numchan.push_back(3);
464 decaylist=kaonList.
minus()* kaonList.
plus()* pi0List* pi0List;
466 else if(channel==
"D0toKsKsPiPi"){
468 numchan.push_back(5);
469 numchan.push_back(5);
470 numchan.push_back(2);
471 numchan.push_back(2);
472 decaylist=ksList* ksList* pionList.
plus()* pionList.
minus();
474 else if(channel==
"D0toPiPiPiPiPi0"){
476 numchan.push_back(2);
477 numchan.push_back(2);
478 numchan.push_back(2);
479 numchan.push_back(2);
480 numchan.push_back(3);
481 decaylist=pionList.
plus()* pionList.
plus()* pionList.
minus()* pionList.
minus()* pi0List;
483 else if(channel==
"D0toKsPiPiPiPi"){
485 numchan.push_back(5);
486 numchan.push_back(2);
487 numchan.push_back(2);
488 numchan.push_back(2);
489 numchan.push_back(2);
490 decaylist=ksList* pionList.
plus()* pionList.
plus()* pionList.
minus()* pionList.
minus();
492 else if(channel==
"D0toKKPiPiPi0"){
494 numchan.push_back(1);
495 numchan.push_back(1);
496 numchan.push_back(2);
497 numchan.push_back(2);
498 numchan.push_back(3);
499 decaylist=kaonList.
minus()* kaonList.
plus()* pionList.
plus()* pionList.
minus()* pi0List;
501 else if(channel==
"D0toKsPi0Eta"){
503 numchan.push_back(5);
504 numchan.push_back(3);
505 numchan.push_back(4);
506 decaylist=ksList* pi0List* etaList;
508 else if(channel==
"D0toKsEPPiPiEta"){
510 numchan.push_back(5);
511 numchan.push_back(6);
513 epList=pionList.
plus()* pionList.
minus()* etaList;
514 decaylist= ksList* epList;
516 else if(channel==
"D0toKsEPRhoGam"){
518 numchan.push_back(5);
519 numchan.push_back(7);
521 rhoList=pionList.
plus()* pionList.
minus();
523 epList=rhoList* photonList;
524 decaylist= ksList* epList;
526 else if(channel==
"D0toKsPi0Pi0Pi0"){
528 numchan.push_back(5);
529 numchan.push_back(3);
530 numchan.push_back(3);
531 numchan.push_back(3);
532 decaylist=ksList* pi0List* pi0List* pi0List;
545 vector<int> trackid, showerid;
546 vector<int> kaonid, pionid;
548 int numofchildren=numchan.size()-1;
550 for(
int i=0; i< numofchildren;i++){
552 const CDCandidate& daughter=(*it).particle().child(i);
553 if(isFlavorMode && i==0)
558 trackid.push_back(track->
trackId());
559 kaonid.push_back(track->
trackId());
561 else if(numchan[i+1]==2){
563 trackid.push_back(track->
trackId());
564 pionid.push_back(track->
trackId());
566 else if ( numchan[i+1]==3){
569 showerid.push_back(hiEnGamma->
trackId());
570 showerid.push_back(loEnGamma->
trackId());
572 else if ( numchan[i+1]==4){
575 showerid.push_back(hiEnGamma->
trackId());
576 showerid.push_back(loEnGamma->
trackId());
578 else if ( numchan[i+1]==5){
581 recDTag->
addToFitInfo(aKsCand->
mass(),fitinfo[aKsCand][0],fitinfo[aKsCand][1],fitinfo[aKsCand][2]);
585 trackid.push_back(pion1Trk->
trackId());
586 trackid.push_back(pion2Trk->
trackId());
588 else if (numchan[i+1]==6){
597 trackid.push_back(apiontrk->
trackId());
598 trackid.push_back(spiontrk->
trackId());
599 showerid.push_back(hiEnGamma->
trackId());
600 showerid.push_back(loEnGamma->
trackId());
603 else if (numchan[i+1]==7){
615 trackid.push_back(apiontrk->
trackId());
616 trackid.push_back(spiontrk->
trackId());
617 showerid.push_back(gammatrk->
trackId());
626 savetrack(trackid,showerid,charged_begin,charged_end,neutral_begin,neutral_end,recDTag);
627 pidtag(kaonid,pionid,kaonList_tight, pionList_tight,recDTag);
630 HepLorentzVector p4change_vfit=util.
vfit(channel, kaonid, pionid, xorigin, charged_begin);
631 recDTag->
setp4(recDTag->
p4()+p4change_vfit);
642 recDTagCol->push_back(recDTag);
651 return StatusCode::SUCCESS;
656 double mass = (*it).particle().mass();
657 HepLorentzVector p4((*it).particle().momentum(), (*it).particle().energy());
661 double mbc2_CMS =
ebeam*
ebeam - p4.v().mag2();
662 double mbc_CMS = mbc2_CMS > 0 ? sqrt( mbc2_CMS ) : -10;
663 double deltaE_CMS = p4.t() -
ebeam;
665 int tag=(*it).particle().userTag();
683 vector<EvtRecTrackIterator> trktemp;
684 vector<EvtRecTrackIterator> shrtemp;
689 bool isothertrack=
true;
690 for(
int i=0; i<trackid.size(); i++){
691 if( (*trk)->trackId()==trackid[i] ){
692 trktemp.push_back(trk);
700 for(
int i=0; i<trackid.size();i++){
701 for(
int j=0; j<trktemp.size(); j++){
703 if( (*trk)->trackId()==trackid[i])
711 bool isothershower=
true;
712 for(
int i=0; i<showerid.size(); i++){
713 if( (*shr)->trackId()==showerid[i] ){
714 shrtemp.push_back(shr);
723 for(
int i=0; i<showerid.size();i++){
724 for(
int j=0; j<shrtemp.size(); j++){
726 if( (*shr)->trackId()==showerid[i])
737 bool iskaon=
false,ispion=
false;
743 recDTag->
addKaonId( (*kit).particle().track() );
747 recDTag->
addPionId( (*pit).particle().track() );
799 inFile.open(filename.c_str());
801 cout <<
"Unable to open decay list file";
805 while (inFile >> channel) {
806 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 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