1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/AlgFactory.h"
3#include "GaudiKernel/SmartDataPtr.h"
4#include "GaudiKernel/IDataProviderSvc.h"
5#include "GaudiKernel/PropertyMgr.h"
6#include "GaudiKernel/Service.h"
7#include "GaudiKernel/ISvcLocator.h"
8#include "GaudiKernel/SvcFactory.h"
20#include "GaudiKernel/INTupleSvc.h"
21#include "GaudiKernel/NTuple.h"
22#include "GaudiKernel/Bootstrap.h"
23#include "GaudiKernel/IHistogramSvc.h"
33 m_iterstag(0), m_iterdtag1(0), m_iterdtag2(0),
34 m_chargebegin(0),m_chargeend(0),m_showerbegin(0),m_showerend(0){
36 SmartDataPtr<EvtRecEvent> evtRecEvent(
eventSvc(),
"/Event/EvtRec/EvtRecEvent");
37 if ( ! evtRecEvent ) {
38 cout << MSG::FATAL <<
"Could not find EvtRecEvent" << endl;
42 SmartDataPtr<EvtRecTrackCol> evtRecTrackCol(
eventSvc(),
"/Event/EvtRec/EvtRecTrackCol");
43 if ( ! evtRecTrackCol ) {
44 cout << MSG::FATAL <<
"Could not find EvtRecTrackCol" << endl;
49 StatusCode sc = Gaudi::svcLocator()->service(
"SimplePIDSvc", m_simplePIDSvc);
58 m_chargebegin=evtRecTrackCol->begin();
59 m_chargeend=evtRecTrackCol->begin()+evtRecEvent->totalCharged();
60 m_showerbegin=evtRecTrackCol->begin()+evtRecEvent->totalCharged();
61 m_showerend=evtRecTrackCol->begin()+evtRecEvent->totalTracks();
65 if ( ! evtRecDTagCol ) {
66 cout <<
"Could not find EvtRecDTagCol" << endl;
71 SmartDataPtr<EvtRecVeeVertexCol> evtRecVeeVertexCol(
eventSvc(),
"/Event/EvtRec/EvtRecVeeVertexCol");
72 if ( ! evtRecVeeVertexCol ) {
73 cout<<
"Could not find EvtRecVeeVertexCol" << endl;
78 SmartDataPtr<EvtRecPi0Col> recPi0Col(
eventSvc(),
"/Event/EvtRec/EvtRecPi0Col");
80 cout<<
"Could not find EvtRecPi0Col" << endl;
86 m_iterbegin=evtRecDTagCol->begin();
87 m_iterend=evtRecDTagCol->end();
88 m_pi0iterbegin=recPi0Col->begin();
89 m_pi0iterend=recPi0Col->end();
90 m_ksiterbegin=evtRecVeeVertexCol->begin();
91 m_ksiterend=evtRecVeeVertexCol->end();
93 if(evtRecDTagCol->size() > 0)
94 m_isdtaglistempty=
false;
96 m_isdtaglistempty=
true;
104 for(EvtRecDTagCol::iterator
iter=m_iterbegin;
iter != m_iterend;
iter++){
106 if( (
int)( (*iter)->decayMode())< 200 )
107 m_d0modes.push_back( index );
108 else if( (
int)( (*iter)->decayMode())< 400 )
109 m_dpmodes.push_back( index );
110 else if( (
int)( (*iter)->decayMode())< 1000 )
111 m_dsmodes.push_back( index );
139 for(EvtRecDTagCol::iterator
iter=m_iterbegin;
iter != m_iterend;
iter++){
142 if( (*iter)->decayMode() == decaymode && (*iter)->type() == 1 )
143 mode.push_back( index );
146 if( (*iter)->decayMode() == decaymode )
147 mode.push_back( index );
161 for(EvtRecDTagCol::iterator
iter=m_iterbegin;
iter != m_iterend;
iter++){
164 if( (*iter)->decayMode() == decaymode && (*iter)->type() == 1 )
165 mode.push_back( index );
168 if( (*iter)->decayMode() == decaymode )
169 mode.push_back( index );
204 EvtRecDTagCol::iterator iter_dtag=m_iterbegin;
205 for ( ; iter_dtag != m_iterend; iter_dtag++){
208 if( (*iter_dtag)->type()!=1 || (*iter_dtag)->decayMode() !=
mode || (*iter_dtag)->charm() != tagcharm )
212 if( (*iter_dtag)->decayMode() !=
mode || (*iter_dtag)->charm() != tagcharm )
215 if(fabs((*iter_dtag)->deltaE())<fabs(de_min)){
217 m_iterstag=iter_dtag;
218 de_min=(*iter_dtag)->deltaE();
234 EvtRecDTagCol::iterator iter_dtag=m_iterbegin;
235 for ( ; iter_dtag != m_iterend; iter_dtag++){
238 if( (*iter_dtag)->type()!=1 || (*iter_dtag)->decayMode() !=
mode )
242 if( (*iter_dtag)->decayMode() !=
mode )
246 if(fabs((*iter_dtag)->deltaE())<fabs(de_min)){
248 m_iterstag=iter_dtag;
249 de_min=(*iter_dtag)->deltaE();
267 return findDTag(
static_cast<int>(mode1),
static_cast<int>(mode2), smass);
273 return findDTag(
static_cast<int>(mode1), tagcharm1,
static_cast<int>(mode2), tagcharm2, smass);
281 return findADTag(
static_cast<int>(mode1),
static_cast<int>(mode2));
287 return findADTag(
static_cast<int>(mode1), tagcharm1,
static_cast<int>(mode2), tagcharm2);
297 int tagcharm1= (mode1<10 || mode1>=200)?+1:0;
298 int tagcharm2= (mode2<10 || mode2>=200)?-1:0;
300 if(tagcharm1*tagcharm2>0){
301 cout<<
"double tagging warning! two modes can't have same nonzero charmness"<<endl;
307 if( mode1 < 200 && mode2 < 200)
309 else if ( mode1>=200 && mode1 < 400 && mode2>=200 && mode2 < 400)
311 else if ( mode1>=400 && mode1 < 1000 && mode2>=400 && mode2 < 1000)
314 cout<<
"double tag modes are not from same particle ! "<<endl;
319 vector<int> igood1, igood2;
320 igood1.clear(),igood2.clear();
322 EvtRecDTagCol::iterator iter_dtag=m_iterbegin;
325 for ( ; iter_dtag != m_iterend; iter_dtag++){
326 int iter_mode=(*iter_dtag)->decayMode();
327 int iter_charm=(*iter_dtag)->charm();
328 int iter_type=(*iter_dtag)->type();
331 if( iter_mode == mode1 && iter_charm == tagcharm1 && iter_type==1 )
332 igood1.push_back(index);
333 if( tagcharm1!=0 && iter_mode == mode1 && iter_charm == -tagcharm1 && iter_type==1 )
334 igood1.push_back(index);
336 if( iter_mode == mode2 && iter_charm == tagcharm2 && iter_type==1 )
337 igood2.push_back(index);
338 if( tagcharm2!=0 && iter_mode == mode2 && iter_charm == -tagcharm2 && iter_type==1 )
339 igood2.push_back(index);
342 if( iter_mode == mode1 && iter_charm == tagcharm1 )
343 igood1.push_back(index);
344 if( tagcharm1!=0 && iter_mode == mode1 && iter_charm == -tagcharm1 )
345 igood1.push_back(index);
347 if( iter_mode == mode2 && iter_charm == tagcharm2 )
348 igood2.push_back(index);
349 if( tagcharm2!=0 && iter_mode == mode2 && iter_charm == -tagcharm2 )
350 igood2.push_back(index);
360 int index_i=0, index_j=0;
361 EvtRecDTagCol::iterator iter_i, iter_j;
363 for(
int i=0; i<igood1.size(); i++){
365 iter_i=m_iterbegin+igood1[i];
366 double mass_i=(*iter_i)->mBC();
368 mass_i=(*iter_i)->mass();
369 int charm_i=(*iter_i)->charm();
370 for(
int j=0;j<igood2.size();j++){
371 iter_j=m_iterbegin+igood2[j];
372 double mass_j=(*iter_j)->mBC();
374 mass_j=(*iter_j)->mass();
375 int charm_j=(*iter_j)->charm();
376 if( charm_i*charm_j>0 || igood2[j] == igood1[i] )
continue;
380 if( fabs(0.5*(mass_i+mass_j)-mDcand) < deltaM){
381 deltaM = fabs(0.5*(mass_i+mass_j)-mDcand);
391 m_iterdtag1=m_iterbegin+igood1[index_i];
392 m_iterdtag2=m_iterbegin+igood2[index_j];
401 if(tagcharm1*tagcharm2>0){
402 cout<<
"double tagging warning! two modes can't have same nonzero charmness"<<endl;
408 if( mode1 < 200 && mode2 < 200)
410 else if (mode1>=200 && mode1 < 400 && mode2>=200 && mode2 < 400)
412 else if (mode1>=400 && mode1 < 1000 && mode2>=400 && mode2 < 1000)
415 cout<<
"double tag modes are not from same particle ! "<<endl;
420 vector<int> igood1, igood2;
421 igood1.clear(),igood2.clear();
423 EvtRecDTagCol::iterator iter_dtag=m_iterbegin;
425 for ( ; iter_dtag != m_iterend; iter_dtag++){
426 int iter_mode=(*iter_dtag)->decayMode();
427 int iter_charm=(*iter_dtag)->charm();
428 int iter_type=(*iter_dtag)->type();
431 if( iter_mode == mode1 && iter_charm == tagcharm1 && iter_type==1 )
432 igood1.push_back(index);
434 if( iter_mode == mode2 && iter_charm == tagcharm2 && iter_type==1)
435 igood2.push_back(index);
438 if( iter_mode == mode1 && iter_charm == tagcharm1)
439 igood1.push_back(index);
441 if( iter_mode == mode2 && iter_charm == tagcharm2)
442 igood2.push_back(index);
453 int index_i=0, index_j=0;
454 EvtRecDTagCol::iterator iter_i, iter_j;
456 for(
int i=0; i<igood1.size(); i++){
458 iter_i=m_iterbegin+igood1[i];
459 double mass_i=(*iter_i)->mBC();
461 mass_i=(*iter_i)->mass();
462 int charm_i=(*iter_i)->charm();
463 for(
int j=0;j<igood2.size();j++){
464 iter_j=m_iterbegin+igood2[j];
465 double mass_j=(*iter_j)->mBC();
467 mass_j=(*iter_j)->mass();
468 int charm_j=(*iter_j)->charm();
469 if( charm_i*charm_j>0 || igood2[j] == igood1[i] )
continue;
473 if( fabs(0.5*(mass_i+mass_j)-mDcand) < deltaM){
474 deltaM = fabs(0.5*(mass_i+mass_j)-mDcand);
484 m_iterdtag1=m_iterbegin+igood1[index_i];
485 m_iterdtag2=m_iterbegin+igood2[index_j];
494 int tagcharm1= (mode1<10 || mode1>=200)?+1:0;
495 int tagcharm2= (mode2<10 || mode2>=200)?-1:0;
497 if(tagcharm1*tagcharm2>0){
498 cout<<
"double tagging warning! two modes can't have same nonzero charmness"<<endl;
504 if( mode1 < 200 && mode2 < 200)
506 else if ( mode1>=200 && mode1 < 400 && mode2>=200 && mode2 < 400)
508 else if ( mode1>=400 && mode1 < 1000 && mode2>=400 && mode2 < 1000)
511 cout<<
"double tag modes are not from same particle ! "<<endl;
516 vector<int> igood1, igood2;
517 igood1.clear(),igood2.clear();
519 EvtRecDTagCol::iterator iter_dtag=m_iterbegin;
522 for ( ; iter_dtag != m_iterend; iter_dtag++){
523 int iter_mode=(*iter_dtag)->decayMode();
524 int iter_charm=(*iter_dtag)->charm();
525 int iter_type=(*iter_dtag)->type();
528 if( iter_mode == mode1 && iter_charm == tagcharm1 && iter_type==1 )
529 igood1.push_back(index);
530 if( tagcharm1!=0 && iter_mode == mode1 && iter_charm == -tagcharm1 && iter_type==1 )
531 igood1.push_back(index);
533 if( iter_mode == mode2 && iter_charm == tagcharm2 && iter_type==1 )
534 igood2.push_back(index);
535 if( tagcharm2!=0 && iter_mode == mode2 && iter_charm == -tagcharm2 && iter_type==1 )
536 igood2.push_back(index);
539 if( iter_mode == mode1 && iter_charm == tagcharm1 )
540 igood1.push_back(index);
541 if( tagcharm1!=0 && iter_mode == mode1 && iter_charm == -tagcharm1 )
542 igood1.push_back(index);
544 if( iter_mode == mode2 && iter_charm == tagcharm2 )
545 igood2.push_back(index);
546 if( tagcharm2!=0 && iter_mode == mode2 && iter_charm == -tagcharm2 )
547 igood2.push_back(index);
556 EvtRecDTagCol::iterator iter_i, iter_j;
558 for(
int i=0; i<igood1.size(); i++){
560 iter_i=m_iterbegin+igood1[i];
561 int charm_i=(*iter_i)->charm();
563 for(
int j=0;j<igood2.size();j++){
564 iter_j=m_iterbegin+igood2[j];
565 int charm_j=(*iter_j)->charm();
566 if( charm_i*charm_j>0 || igood2[j] == igood1[i] )
continue;
569 m_viterdtag1.push_back(m_iterbegin+igood1[i]);
570 m_viterdtag2.push_back(m_iterbegin+igood2[j]);
576 if(m_viterdtag1.size()>0){
585 if(tagcharm1*tagcharm2>0){
586 cout<<
"double tagging warning! two modes can't have same nonzero charmness"<<endl;
592 if( mode1 < 200 && mode2 < 200)
594 else if (mode1>=200 && mode1 < 400 && mode2>=200 && mode2 < 400)
596 else if (mode1>=400 && mode1 < 1000 && mode2>=400 && mode2 < 1000)
599 cout<<
"double tag modes are not from same particle ! "<<endl;
604 vector<int> igood1, igood2;
605 igood1.clear(),igood2.clear();
607 EvtRecDTagCol::iterator iter_dtag=m_iterbegin;
609 for ( ; iter_dtag != m_iterend; iter_dtag++){
610 int iter_mode=(*iter_dtag)->decayMode();
611 int iter_charm=(*iter_dtag)->charm();
612 int iter_type=(*iter_dtag)->type();
615 if( iter_mode == mode1 && iter_charm == tagcharm1 && iter_type==1 )
616 igood1.push_back(index);
618 if( iter_mode == mode2 && iter_charm == tagcharm2 && iter_type==1)
619 igood2.push_back(index);
622 if( iter_mode == mode1 && iter_charm == tagcharm1)
623 igood1.push_back(index);
625 if( iter_mode == mode2 && iter_charm == tagcharm2)
626 igood2.push_back(index);
637 int index_i=0, index_j=0;
638 EvtRecDTagCol::iterator iter_i, iter_j;
640 for(
int i=0; i<igood1.size(); i++){
642 iter_i=m_iterbegin+igood1[i];
643 int charm_i=(*iter_i)->charm();
644 for(
int j=0;j<igood2.size();j++){
645 iter_j=m_iterbegin+igood2[j];
646 int charm_j=(*iter_j)->charm();
647 if( charm_i*charm_j>0 || igood2[j] == igood1[i] )
continue;
651 m_viterdtag1.push_back(m_iterbegin+igood1[i]);
652 m_viterdtag2.push_back(m_iterbegin+igood2[j]);
657 if(m_viterdtag1.size()>0)
674 cout<<
" print mode:"<< (*iter)->decayMode()<<endl;
675 cout<<
"beam energy is:"<< (*iter)->beamE()<<endl;
676 cout<<
"mBC is:"<< (*iter)->mBC()<<endl;
677 cout<<
"deltaE is:"<< (*iter)->deltaE()<<endl;
678 cout<<
"inv mass is:"<< (*iter)->mass()<<endl;
679 cout<<
"charge is:"<< (*iter)->charge()<<endl;
680 cout<<
"charm is:"<< (*iter)->charm()<<endl;
681 cout<<
"num of children is:"<< (*iter)->numOfChildren()<<endl;
683 cout<<
"found "<< (*iter)->tracks().size()<<
" same side tracks."<<endl;
684 cout<<
"found "<< (*iter)->otherTracks().size()<<
" other side tracks."<<endl;
685 cout<<
"found "<< (*iter)->showers().size()<<
" same side showers."<<endl;
686 cout<<
"found "<< (*iter)->otherShowers().size()<<
" other side showers."<<endl;
694 HepLorentzVector p41= (*pi0Itr)->hiPfit();
695 HepLorentzVector p42= (*pi0Itr)->loPfit();
705 HepLorentzVector p41=
p4shower(emctrk1);
706 HepLorentzVector p42=
p4shower(emctrk2);
716 SmartRefVector<EvtRecTrack> showers=(*iter_dtag)->showers();
717 if(showers.size()<2*numpi0){
718 cout<<
"too many pi0 required"<<endl;
725 for(EvtRecPi0Col::iterator pi0Itr = m_pi0iterbegin;
726 pi0Itr < m_pi0iterend; pi0Itr++){
732 int heGammaTrkId = heGammaTrk->
trackId();
733 int leGammaTrkId = leGammaTrk->
trackId();
735 for(
int index=0; index<numpi0; ++index){
739 for(
int i=index*2; i<index*2+2; ++i){
741 if(!isheid && heGammaTrkId == showers[i]->trackId())
743 if(!isleid && leGammaTrkId == showers[i]->trackId())
748 canid.push_back( pi0Itr - m_pi0iterbegin);
752 if(canid.size()==numpi0){
765 SmartRefVector<EvtRecTrack> tracks=(*iter_dtag)->tracks();
766 if(tracks.size()<2*numks){
767 cout<<
"too many kshort required"<<endl;
777 for(EvtRecVeeVertexCol::iterator ksItr = m_ksiterbegin;
778 ksItr < m_ksiterend; ksItr++){
781 if((*ksItr)->vertexId() != 310)
continue;
786 int ksChild1TrkId = aKsChild1Trk->
trackId();
787 int ksChild2TrkId = aKsChild2Trk->
trackId();
789 for(
int index=0; index<numks; ++index){
793 for(
int i=index*2; i<index*2+2; ++i){
794 if(!isc1id && ksChild1TrkId == tracks[i]->trackId())
796 if(!isc2id && ksChild2TrkId == tracks[i]->trackId())
801 canid.push_back( ksItr - m_ksiterbegin);
804 if(canid.size()==numks){
815 double Eemc=shower->
energy();
816 double phi=shower->
phi();
817 double theta=shower->
theta();
818 HepLorentzVector
p4(Eemc*
sin(theta)*
cos(phi),Eemc*
sin(theta)*
sin(phi),Eemc*
cos(theta),Eemc);
848 double dr(0),phi0(0),kappa(0),dz(0),tanl(0);
857 if (kappa > 0.0000000001)
859 else if (kappa < -0.0000000001)
863 if(kappa!=0) pxy = 1.0/fabs(kappa);
865 double px = pxy * (-
sin(phi0));
866 double py = pxy *
cos(phi0);
867 double pz = pxy * tanl;
869 double e = sqrt( pxy*pxy + pz*pz +
mass*
mass );
871 return HepLorentzVector(px, py, pz, e);
878 SmartRefVector<EvtRecTrack> pionid=(*m_iterbegin)->pionId();
880 for(
int i=0; i < pionid.size() ;i++){
881 if( trk->
trackId() == pionid[i]->trackId()){
892 SmartRefVector<EvtRecTrack> kaonid=(*m_iterbegin)->kaonId();
894 for(
int i=0; i < kaonid.size() ;i++){
895 if( trk->
trackId() == kaonid[i]->trackId()){
950 dedxchi=dedxTrk->
chiMu();
955 ptrk= mdcKalTrk->
p();
962 double eop = Eemc/ptrk;
966 depth=mucTrk->
depth();
969 if( fabs(dedxchi)<5 && fabs(Eemc)>0.15 && fabs(Eemc)<0.3 && (depth>=80*ptrk-60 || depth>40))
980 Hep3Vector xorigin(0,0,0);
982 Gaudi::svcLocator()->service(
"VertexDbSvc", vtxsvc);
986 xorigin.setX(dbv[0]);
987 xorigin.setY(dbv[1]);
988 xorigin.setZ(dbv[2]);
995 HepSymMatrix Ea = mdcKalTrk->
getZError();
997 HepPoint3D IP(xorigin[0],xorigin[1],xorigin[2]);
1000 HepVector
vec = helixp.
a();
1001 double vrl =
vec[0];
1002 double vzl =
vec[3];
1003 double costheta =
cos(mdcKalTrk->
theta());
1005 if(fabs(vrl)<1 && fabs(vzl)<10 && fabs(costheta)<0.93)
1012 double eraw = emcTrk->
energy();
1014 double costh =
cos(emcTrk->
theta());
1016 (fabs(costh)<0.80 && eraw>0.025)
1017 || (fabs(costh)>0.84 && eraw>0.05)
1027 vector<EvtRecTrackIterator> iGood;
1031 iGood.push_back(
iter);
1034 if(iGood.size() != 2)
1038 double time1=-99,time2=-99;
1039 for(vector<EvtRecTrackIterator>::size_type i=0;i<2;i++){
1040 if( (*iGood[i])->isTofTrackValid() ){
1041 SmartRefVector<RecTofTrack> tofTrkCol= (*iGood[i])->tofTrack();
1042 SmartRefVector<RecTofTrack>::iterator iter_tof=tofTrkCol.begin();
1044 for(;iter_tof!=tofTrkCol.end();iter_tof++){
1046 status->
setStatus( (*iter_tof)->status() );
1049 time1=(*iter_tof)->tof();
1051 time2=(*iter_tof)->tof();
1057 if( time1!=-99 && time2!=-99 && fabs(time1-time2)>5)
1073 SmartRefVector<EvtRecTrack> tracks1=(*iter1)->tracks();
1074 SmartRefVector<EvtRecTrack> showers1=(*iter1)->showers();
1075 SmartRefVector<EvtRecTrack> tracks2=(*iter2)->tracks();
1076 SmartRefVector<EvtRecTrack> showers2=(*iter2)->showers();
1079 for(
int i=0; i<tracks1.size(); i++){
1080 for(
int j=0; j<tracks2.size(); j++){
1081 if(tracks1[i]==tracks2[j])
1087 for(
int i=0; i<showers1.size(); i++){
1088 for(
int j=0; j<showers2.size(); j++){
1089 if(showers1[i]==showers2[j])
1101 StatusCode sc = Gaudi::svcLocator()->service (
"EventDataSvc", m_evtSvc,
true);
1102 if( sc.isFailure() ) {
double sin(const BesAngle a)
double cos(const BesAngle a)
EvtRecTrackCol::iterator EvtRecTrackIterator
const double theta() const
static void setPidType(PidType pidType)
bool isMdcKalTrackValid()
RecEmcShower * emcShower()
RecMdcKalTrack * mdcKalTrack()
virtual void preparePID(EvtRecTrack *track)=0
virtual bool iselectron(bool eop=false)=0
virtual bool isVertexValid()=0
virtual double * SigmaPrimaryVertex()=0
virtual double * PrimaryVertex()=0
const HepVector & getZHelix() const
HepVector & getZHelixMu()
const HepSymMatrix & getZError() const
void setStatus(unsigned int status)
const HepPoint3D & pivot(void) const
returns pivot position.
const HepVector & a(void) const
returns helix parameters.
_EXTERN_ std::string EvtRecDTagCol