/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/BesExamples/DSemilepAlg/DSemilepAlg-00-00-01/src/DSemilepAlg.cxx

Go to the documentation of this file.
00001 #include "GaudiKernel/MsgStream.h"
00002 #include "GaudiKernel/AlgFactory.h"
00003 #include "GaudiKernel/ISvcLocator.h"
00004 #include "GaudiKernel/SmartDataPtr.h"
00005 #include "GaudiKernel/IDataProviderSvc.h"
00006 #include "GaudiKernel/PropertyMgr.h"
00007 
00008 #include "EventModel/EventModel.h"
00009 #include "EventModel/Event.h"
00010 #include "EventModel/EventHeader.h"
00011 
00012 #include "EvtRecEvent/EvtRecEvent.h"
00013 #include "EvtRecEvent/EvtRecTrack.h"
00014 #include "EvtRecEvent/EvtRecDTag.h"
00015 #include "EvtRecEvent/EvtRecVeeVertex.h"
00016 #include "EvtRecEvent/EvtRecPi0.h"
00017 #include "DstEvent/TofHitStatus.h"
00018 
00019 #include "TMath.h"
00020 #include "GaudiKernel/INTupleSvc.h"
00021 #include "GaudiKernel/NTuple.h"
00022 #include "GaudiKernel/Bootstrap.h"
00023 #include "GaudiKernel/IHistogramSvc.h"
00024 #include "CLHEP/Vector/ThreeVector.h"
00025 #include "CLHEP/Vector/LorentzVector.h"
00026 #include "CLHEP/Vector/TwoVector.h"
00027 #include "CLHEP/Geometry/Point3D.h"
00028 
00029 using CLHEP::Hep3Vector;
00030 using CLHEP::Hep2Vector;
00031 using CLHEP::HepLorentzVector;
00032 #ifndef ENABLE_BACKWARDS_COMPATIBILITY
00033 typedef HepGeom::Point3D<double> HepPoint3D;
00034 #endif
00035 
00036 
00037 #include "DSemilepAlg/DSemilepAlg.h"
00038 
00039 #include "VertexFit/KinematicFit.h"
00040 #include "VertexFit/Helix.h"
00041 #include "VertexFit/VertexFit.h"
00042 #include "McTruth/McParticle.h"
00043 
00044 #include <unistd.h>
00045 #include <fstream>
00046 #include <vector>
00047 typedef std::vector<int> Vint;
00048 typedef std::vector<HepLorentzVector> Vp4;
00049 
00050 //CONSTANTS
00051 const double me = 0.000511;
00052 const double mkaon = 0.4934;
00053 
00055 
00056 DSemilepAlg::DSemilepAlg(const std::string& name, ISvcLocator* pSvcLocator) : Algorithm(name, pSvcLocator){
00057 }
00058 
00059 //
00060 // INITIALIZE
00061 //
00062 StatusCode DSemilepAlg::initialize(){
00063 
00064         MsgStream log(msgSvc(), name());
00065         log << MSG::INFO << "in initialize()" << endmsg;
00066         StatusCode status;
00067 
00068         //NTUPLE
00069         NTuplePtr nt0(ntupleSvc(), "FILE1/dsemilep");
00070         if ( nt0 ) m_tuple0 = nt0;
00071         else {
00072                 m_tuple0 = ntupleSvc()->book ("FILE1/dsemilep", CLID_ColumnWiseTuple, "track N-Tuple example");
00073                 if ( m_tuple0 )    {
00074                         status = m_tuple0->addItem ("U", m_U);
00075                         status = m_tuple0->addItem ("MM2", m_MM2);
00076                         status = m_tuple0->addItem ("mBC", m_mBC);
00077                         status = m_tuple0->addItem ("q2", m_q2);
00078                         status = m_tuple0->addItem ("deltaE", m_deltaE);
00079                         status = m_tuple0->addItem ("mode", m_mode);
00080                 }
00081                 else    {
00082                         log << MSG::ERROR << "    Cannot book N-tuple:" << long(m_tuple0) << endmsg;
00083                         return StatusCode::FAILURE;
00084                 }
00085         }
00086 
00087         StatusCode sc = service("SimplePIDSvc", m_simplePIDSvc);
00088         if ( sc.isFailure())    {
00089                 log << MSG::FATAL << "Could not load SimplePIDSvc!" << endreq;
00090                 return sc;
00091         }
00092 
00093         log << MSG::INFO << "successfully return from initialize()" <<endmsg;
00094         return StatusCode::SUCCESS;
00095 }
00096 
00097 //
00098 // EXECUTE
00099 //
00100 StatusCode DSemilepAlg::execute() {
00101 
00102         MsgStream log(msgSvc(), name());
00103         log << MSG::INFO << "in execute()" << endreq;
00104 
00105         SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
00106         int runNo=eventHeader->runNumber();
00107         int eventNo=eventHeader->eventNumber();
00108 
00109         //
00110         //if(eventNo % 1000 == 0)
00111         //cout << "Event: "<< eventNo << endl;
00112 
00113         SmartDataPtr<EvtRecEvent> evtRecEvent(eventSvc(), "/Event/EvtRec/EvtRecEvent");
00114         if ( ! evtRecEvent ) {
00115                 log << MSG::FATAL << "Could not find EvtRecEvent" << endreq;
00116                 return StatusCode::FAILURE;
00117         }
00118 
00119         SmartDataPtr<EvtRecTrackCol> evtRecTrackCol( eventSvc(), "/Event/EvtRec/EvtRecTrackCol");
00120         if ( ! evtRecTrackCol ) {
00121                 log << MSG::FATAL << "Could not find EvtRecTrackCol" << endreq;
00122                 return StatusCode::FAILURE;
00123         }
00124 
00126         SmartDataPtr<EvtRecVeeVertexCol> evtRecVeeVertexCol(eventSvc(), "/Event/EvtRec/EvtRecVeeVertexCol");
00127         if ( ! evtRecVeeVertexCol ) {
00128                 log << MSG::FATAL << "Could not find EvtRecVeeVertexCol" << endreq;
00129                 return StatusCode::FAILURE;
00130         }
00131 
00133         SmartDataPtr<EvtRecPi0Col> recPi0Col(eventSvc(), "/Event/EvtRec/EvtRecPi0Col");
00134         if ( ! recPi0Col ) {
00135                 log << MSG::FATAL << "Could not find EvtRecPi0Col" << endreq;
00136                 return StatusCode::FAILURE;
00137 
00138         }
00139 
00140         //get primary vertex from db
00141         Hep3Vector xorigin(0,0,0);
00142         IVertexDbSvc*  vtxsvc;
00143         Gaudi::svcLocator()->service("VertexDbSvc", vtxsvc);
00144         if (vtxsvc->isVertexValid()) {
00145                 //vertex[0] = vx; vertex[1]= vy; vertex[2] = vz;
00146                 double* vertex = vtxsvc->PrimaryVertex();
00147                 xorigin.setX(vertex[0]);
00148                 xorigin.setY(vertex[1]);
00149                 xorigin.setZ(vertex[2]);
00150         }
00151 
00152         // DTAGTOOL
00153         DTagTool dtagTool;
00154 
00155 
00156         if( dtagTool.isDTagListEmpty() ){
00157                 // cout<<"no D candidates found"<<endl;
00158                 return StatusCode::SUCCESS;
00159         }
00160         //else{
00161         //   cout<<"found D candidates found"<<endl;
00162         //}
00163 
00164         DTagToolIterator iter_begin = dtagTool.modes_begin();
00165         DTagToolIterator iter_end = dtagTool.modes_end();
00166 
00167         //find semileptonic decay candidate
00168         vector<DTagToolIterator> vsditer;
00169 
00170         // Using modes 0,1 and 3 (D0->KPi, D0->KPiPi0, D0->KPiPiPi ) fill dtagtool
00171         // Combining three modes to look at the signal side of all of them
00172         if(dtagTool.findSTag( EvtRecDTag::kD0toKPi,1) && dtagTool.cosmicandleptonVeto())
00173                 vsditer.push_back(dtagTool.stag());
00174         if(dtagTool.findSTag( EvtRecDTag::kD0toKPi,-1) && dtagTool.cosmicandleptonVeto())
00175                 vsditer.push_back(dtagTool.stag());
00176         if(dtagTool.findSTag( EvtRecDTag::kD0toKPiPi0,1))
00177                 vsditer.push_back(dtagTool.stag());
00178         if(dtagTool.findSTag( EvtRecDTag::kD0toKPiPi0,-1))
00179                 vsditer.push_back(dtagTool.stag());
00180         if(dtagTool.findSTag( EvtRecDTag::kD0toKPiPiPi,1) )
00181                 vsditer.push_back(dtagTool.stag());
00182         if(dtagTool.findSTag( EvtRecDTag::kD0toKPiPiPi,-1) )
00183                 vsditer.push_back(dtagTool.stag());
00184 
00185 
00186         typedef vector<DTagToolIterator>::size_type vec_sz;
00187 
00188         //loop over single tag to reconstruct signal side
00189         for(vec_sz i = 0 ; i < vsditer.size() ; i++){
00190 
00191                 //fill single tags only before selection
00192                 m_deltaE = (*vsditer[i])->deltaE();
00193                 m_mode = (*vsditer[i])->decayMode();
00194                 m_mBC = (*vsditer[i])->mBC();
00195 
00196                 //Get the DTagToolIterator of the tag for easier usage in the code
00197                 DTagToolIterator sditer = vsditer[i];
00198 
00199                 // Check signal side for good tracks and charge of the tracks
00200                 SmartRefVector<EvtRecTrack> othertracks = (*sditer)->otherTracks();
00201                 vector<int> iGood;      int tcharge=0;
00202 
00203                 for(int i = 0 ; i < othertracks.size() ; i++){
00204                         if(isGoodTrack(othertracks[i],xorigin)){
00205                                 iGood.push_back(i);
00206                                 RecMdcKalTrack *mdcKalTrk = othertracks[i]->mdcKalTrack();
00207                                 tcharge += mdcKalTrk->charge();
00208                         }
00209                 }
00210 
00211                 // Keeping only events with 2 good signal tracks with zero total charge
00212                 if(iGood.size() != 2 || tcharge != 0)
00213                         continue;
00214 
00215                 // Use SimplePIDSvc package to identify the tracks
00216                 m_simplePIDSvc->preparePID(othertracks[iGood[0]]);
00217                 bool FtrkElectron = m_simplePIDSvc->iselectron(); 
00218                 bool FtrkKaon           = m_simplePIDSvc->iskaon();
00219 
00220                 m_simplePIDSvc->preparePID(othertracks[iGood[1]]);
00221                 bool StrkElectron = m_simplePIDSvc->iselectron();
00222                 bool StrkKaon           = m_simplePIDSvc->iskaon();
00223 
00224                 //
00225                 // As at the signal side tracks are not listed in a particular order, there are two senarios
00226                 //
00227                 // Senario 1: Track 0 is electron, track 1 is kaon
00228                 if(FtrkElectron && StrkKaon) {
00229 
00230                         RecMdcKalTrack* ftrk = othertracks[iGood[0]]->mdcKalTrack();
00231                         RecMdcKalTrack* strk = othertracks[iGood[1]]->mdcKalTrack();
00232 
00233                         SmartRefVector<EvtRecTrack> tracks = (*sditer)->tracks();   
00234                         RecMdcKalTrack* tagsidektrk = tracks[0]->mdcKalTrack();
00235 
00236                         //Requiring electron having the same charge as the tag side kaon
00237                         if(ftrk->charge() * tagsidektrk->charge() > 0){
00238                                 double U_1 = 0;
00239                                 double MM2_1 = 0;
00240                                 double q2_1 = 0;
00241         
00242                                 //Calculate U and MM2 using a function
00243                                 calU(sditer,strk,ftrk,U_1,MM2_1,q2_1);
00244 
00245                                 m_U = U_1;
00246                                 m_MM2 = MM2_1;
00247                                 m_q2 = q2_1;
00248 
00249                                 m_tuple0->write();
00250                         }
00251 
00252 
00253                 }//end of senario 1 
00254 
00255                 //Senario 2: Track 0 is kaon, track 1 is electon
00256                 if(StrkElectron && FtrkKaon){
00257 
00258                         RecMdcKalTrack* ftrk = othertracks[iGood[0]]->mdcKalTrack();
00259                         RecMdcKalTrack* strk = othertracks[iGood[1]]->mdcKalTrack();
00260 
00261                         SmartRefVector<EvtRecTrack> tracks = (*sditer)->tracks();  
00262 
00263                         RecMdcKalTrack* tagsidektrk = tracks[0]->mdcKalTrack();
00264 
00265                         //Requiring electron having the same charge as the tag side kaon
00266                         if(strk->charge() * tagsidektrk->charge() > 0){
00267 
00268                                 double U_1 = 0;
00269                                 double MM2_1 = 0;
00270                                 double q2_1 = 0;
00271         
00272                                 //Calculate U and MM2 using a function
00273                                 calU(sditer,strk,ftrk,U_1,MM2_1,q2_1);
00274 
00275                                 m_U = U_1;
00276                                 m_MM2 = MM2_1;
00277                                 m_q2 = q2_1;
00278 
00279                                 m_tuple0->write();
00280                         }
00281                 }//end of senario 2
00282 
00283         }
00284 
00285         //Clear DTagTool
00286         dtagTool.clear();
00287 }
00288 
00289 //
00290 // FINALIZE
00291 //
00292 StatusCode DSemilepAlg::finalize() {
00293         MsgStream log(msgSvc(), name());
00294         log << MSG::INFO << "in finalize()" << endmsg;
00295 
00296         return StatusCode::SUCCESS;
00297 }
00298 
00299 //
00300 // MEMBER FUNCTIONS
00301 //
00302 
00303 //
00304 // isGoodTrack
00305 bool DSemilepAlg::isGoodTrack(EvtRecTrack* trk, Hep3Vector xorigin){
00306         if(!(trk->isMdcKalTrackValid())) return false;
00307 
00308         RecMdcKalTrack *mdcKalTrk = trk->mdcKalTrack();
00309         mdcKalTrk->setPidType(RecMdcKalTrack::pion);
00310         HepVector    a  = mdcKalTrk->getZHelix();
00311         HepSymMatrix Ea = mdcKalTrk->getZError();
00312         HepPoint3D pivot(0.,0.,0.);
00313         HepPoint3D IP(xorigin[0],xorigin[1],xorigin[2]);
00314         VFHelix helixp(pivot,a,Ea);
00315         helixp.pivot(IP);
00316         HepVector vec    = helixp.a();
00317         double    vrl    = vec[0];
00318         double    vzl    = vec[3];
00319         double costheta  = cos(mdcKalTrk->theta());
00320 
00321         //Event selection criteria
00322         if(fabs(vrl) < 1 && fabs(vzl) < 10 && fabs(costheta) < 0.93)
00323                 return true;
00324         return false;
00325 }
00326 
00327 //
00328 //3 Momentum of the tagged D
00329 Hep3Vector DSemilepAlg::tagDP3(DTagToolIterator iter_dtag){
00330 
00331         SmartRefVector<EvtRecTrack> tracks=(*iter_dtag)->tracks();
00332         SmartRefVector<EvtRecTrack> showers=(*iter_dtag)->showers();
00333 
00334         HepLorentzVector p4=(*iter_dtag)->p4();
00335         p4.boost(-0.011,0,0);
00336         Hep3Vector p3=p4.v();
00337         return p3;
00338 }
00339 
00340 //
00341 // Calculate U = E_miss - P_miss and MM2 = U * (E_miss + P_miss)
00342 void DSemilepAlg::calU(DTagToolIterator sditer,RecMdcKalTrack* Etrack, RecMdcKalTrack* Ktrack,double& U, double& MM2, double& q2){
00343 
00344         Etrack->setPidType(RecMdcKalTrack::electron);
00345         Ktrack->setPidType(RecMdcKalTrack::kaon);
00346 
00347         Hep3Vector P3_tag = tagDP3(sditer);
00348 
00349         Hep3Vector P3_E(Etrack->px(), Etrack->py(),Etrack->pz());
00350         Hep3Vector P3_K(Ktrack->px(), Ktrack->py(),Ktrack->pz());
00351 
00352         HepLorentzVector P4_E(P3_E, sqrt( P3_E.mag2() + me * me));
00353         HepLorentzVector P4_K(P3_K, sqrt( P3_K.mag2() + mkaon * mkaon));
00354 
00355         // Boost
00356         P4_E.boost(-0.011,0,0);
00357         P4_K.boost(-0.011,0,0);
00358 
00359         double e_miss = (*sditer)->beamE() - P4_E.e() - P4_K.e();
00360         Hep3Vector P3_miss = -P3_tag - P4_E.vect() - P4_K.vect();
00361 
00362         U = e_miss - P3_miss.mag();
00363         MM2 = U * (e_miss + P3_miss.mag());
00364 
00365         HepLorentzVector P4_W(P3_E+P3_miss*fabs(e_miss/P3_miss.mag()),e_miss+P4_E.e());
00366   q2 = P4_W.m2();
00367 
00368 }

Generated on Tue Nov 29 22:57:47 2016 for BOSS_7.0.2 by  doxygen 1.4.7