00001 #include "GaudiKernel/IDataProviderSvc.h"
00002 #include "GaudiKernel/MsgStream.h"
00003 #include "GaudiKernel/SmartDataPtr.h"
00004 #include "EventModel/EventModel.h"
00005 #include "EvtRecEvent/EvtRecEvent.h"
00006 #include "EvtRecEvent/EvtRecDTag.h"
00007 #include "VertexFit/Helix.h"
00008 #include "BestDTagSvc/BestDTagSvc.h"
00009
00010 BestDTagSvc::BestDTagSvc(const std::string& name, ISvcLocator* svcLoc)
00011 : Service(name, svcLoc)
00012 {
00013
00014 declareProperty("pidTight", m_isPidTight = true);
00015 }
00016
00017 BestDTagSvc::~BestDTagSvc()
00018 {
00019 }
00020
00021 StatusCode BestDTagSvc::initialize()
00022 {
00023 MsgStream log(messageService(), name());
00024 log << MSG::INFO << "@initialize()" << endreq;
00025
00026 StatusCode sc = Service::initialize();
00027
00028 sc = serviceLocator()->service("EventDataSvc", eventSvc_, true);
00029 sc = serviceLocator()->service("VertexDbSvc", vtxSvc_, true);
00030
00031 return sc;
00032 }
00033
00034 StatusCode BestDTagSvc::finalize()
00035 {
00036 MsgStream log(messageService(), name());
00037 log << MSG::INFO << "@initialize()" << endreq;
00038
00039 StatusCode sc = Service::finalize();
00040
00041 return sc;
00042 }
00043
00044 StatusCode BestDTagSvc::queryInterface(const InterfaceID& riid, void** ppvIF)
00045 {
00046 if ( IBestDTagSvc::interfaceID().versionMatch(riid) ) {
00047 *ppvIF = dynamic_cast<IBestDTagSvc*>(this);
00048 }
00049 else {
00050 return Service::queryInterface(riid, ppvIF);
00051 }
00052 addRef();
00053 return StatusCode::SUCCESS;
00054 }
00055
00056 EvtRecDTag* BestDTagSvc::getSingleTag(int modeid, int charm)
00057 {
00058 MsgStream log(messageService(), name());
00059
00060 SmartDataPtr<EvtRecDTagCol> dtags(eventSvc_, EventModel::EvtRec::EvtRecDTagCol);
00061 if ( !dtags ) {
00062 log << MSG::ERROR << "Can't retrieve the EvtRecDTagCol!" << endreq;
00063 return NULL;
00064 }
00065
00066 EvtRecDTag* pbest = NULL;
00067
00068 double bestDE = 999.;
00069
00070 for (EvtRecDTagCol::iterator it = dtags->begin(); it != dtags->end(); ++it) {
00071 if (m_isPidTight ) {
00072 if ( (*it)->type() != EvtRecDTag::Tight) continue;
00073 }
00074 if ( modeid >= 0 && (*it)->decayMode() != modeid ) {
00075 continue;
00076 }
00077 if ( charm != 0 && (*it)->charm() != charm ) {
00078 continue;
00079 }
00080 if ( fabs((*it)->deltaE()) < bestDE ) {
00081 bestDE = fabs((*it)->deltaE());
00082 pbest = (*it);
00083 }
00084 }
00085
00086 return pbest;
00087 }
00088
00089 EvtRecDTag** BestDTagSvc::getDoubleTag(int modeid1, int modeid2, int charm)
00090 {
00091 static EvtRecDTag** tagpp = new EvtRecDTag*[2];
00092
00093
00094
00095
00096 if ( false ) {
00097 return tagpp;
00098 }
00099
00100 return NULL;
00101 }
00102
00103 bool BestDTagSvc::isCosmicOrLepton()
00104 {
00105 SmartDataPtr<EvtRecEvent> evt(eventSvc_, "/Event/EvtRec/EvtRecEvent");
00106 SmartDataPtr<EvtRecTrackCol> trks(eventSvc_, EventModel::EvtRec::EvtRecTrackCol);
00107 if ( !evt || !trks ) {
00108 return false;
00109 }
00110
00111 std::vector<EvtRecTrack*> gtrks;
00112 for (int i = 0; i < evt->totalCharged(); ++i) {
00113 EvtRecTrack* trk = *(trks->begin() + i);
00114 if ( isGoodTrack(trk) ) {
00115 gtrks.push_back(trk);
00116 }
00117 }
00118 if ( gtrks.size() != 2 ) return false;
00119
00120 double time[2] = { -100., -100.};
00121 for ( int i = 0; i < 2; ++i ) {
00122 if ( gtrks[i]->isTofTrackValid() ){
00123 SmartRefVector<RecTofTrack> tofTrks = gtrks[i]->tofTrack();
00124 for ( SmartRefVector<RecTofTrack>::iterator it = tofTrks.begin(); it != tofTrks.end(); ++it ) {
00125 if ( ( (*it)->status() & 0x8 ) == 0x8 ) {
00126 time[i] = (*it)->tof();
00127 break;
00128 }
00129 }
00130 }
00131 }
00132 if ( time[0] > -99. && time[1] > -99. && fabs(time[0]-time[1]) > 5 ) return true;
00133
00134 if ( isElectron(gtrks[0]) && isElectron(gtrks[1]) ) return true;
00135 if ( isMuon(gtrks[0]) && isMuon(gtrks[1]) ) return true;
00136
00137 return false;
00138 }
00139
00140 bool BestDTagSvc::isGoodTrack(EvtRecTrack* atrk)
00141 {
00142 Hep3Vector xorigin(0,0,0);
00143 if(vtxSvc_->isVertexValid()){
00144 double* dbv = vtxSvc_->PrimaryVertex();
00145 double* vv = vtxSvc_->SigmaPrimaryVertex();
00146 xorigin.setX(dbv[0]);
00147 xorigin.setY(dbv[1]);
00148 xorigin.setZ(dbv[2]);
00149 }
00150
00151 if ( atrk->isMdcKalTrackValid() ) {
00152 RecMdcKalTrack *mdcKalTrk = atrk->mdcKalTrack();
00153 mdcKalTrk->setPidType(RecMdcKalTrack::pion);
00154 HepVector a = mdcKalTrk->getZHelix();
00155 HepSymMatrix Ea = mdcKalTrk->getZError();
00156 HepPoint3D pivot(0., 0., 0.);
00157 HepPoint3D IP(xorigin[0], xorigin[1], xorigin[2]);
00158 VFHelix helixp(pivot, a, Ea);
00159 helixp.pivot(IP);
00160 HepVector vec = helixp.a();
00161 double vrl = vec[0];
00162 double vzl = vec[3];
00163 double costheta = cos( mdcKalTrk->theta() );
00164
00165 if ( fabs(vrl) < 1 && fabs(vzl) < 10 && fabs(costheta) < 0.93 ) {
00166 return true;
00167 }
00168 }
00169
00170 return false;
00171 }
00172
00173 bool BestDTagSvc::isElectron(EvtRecTrack* atrk)
00174 {
00175 if ( atrk->isMdcDedxValid() && atrk->isMdcKalTrackValid() && atrk->isEmcShowerValid() ) {
00176 double trkP = atrk->mdcKalTrack()->p();
00177 double emcE = atrk->emcShower()->energy();
00178 double dedxChi = atrk->mdcDedx()->chiE();
00179
00180 if ( emcE/trkP > 0.8 && fabs(dedxChi) < 5 ) return true;
00181 }
00182
00183 return false;
00184 }
00185
00186 bool BestDTagSvc::isMuon(EvtRecTrack* atrk)
00187 {
00188 if ( atrk->isMucTrackValid() ) {
00189 if ( atrk->mucTrack()->depth() >= 5 ) {
00190 return true;
00191 }
00192 }
00193
00194 return false;
00195 }
00196