/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/EventFilter/HltUtilities/HltAlgorithms/HltAlgorithms-01-03-01/src/EFFlightTime.cxx

Go to the documentation of this file.
00001 #include <cmath>
00002 #include "GaudiKernel/MsgStream.h"
00003 //#include "GaudiKernel/AlgFactory.h"
00004 #include "GaudiKernel/SmartDataPtr.h"
00005 //#include "GaudiKernel/PropertyMgr.h"
00006 #include "EventModel/Event.h"
00007 #include "EventModel/EventHeader.h"
00008 #include "Identifier/Identifier.h"
00009 //#include "TofRawEvent/TofDigi.h"
00010 //#include "Identifier/TofID.h"
00011 //#include "RawEvent/RawDataUtil.h"
00012 #include "RawDataProviderSvc/TofData.h"
00013 
00014 #include "HltAlgorithms/EFFlightTime.h"
00015 
00016 //using namespace Event;
00017 typedef std::vector<EFTofHitsCol> VTOF;
00018 
00019 EFFlightTime::EFFlightTime(const std::string& name, ISvcLocator* pSvcLocator) :
00020   IEFAlgorithm(name, pSvcLocator) {
00021   int output = (m_output%10)/1;
00022   //declareProperty("OutputLevel",m_output = MSG::NIL);
00023   MsgStream log(msgSvc(), name);
00024   msgSvc()->setOutputLevel(name,output);
00025   m_dtof1 = new CriteriaItemValue;
00026   m_dphi1 = new CriteriaItemValue;
00027   m_dtof2 = new CriteriaItemValue;
00028   m_dphi2 = new CriteriaItemValue;
00029 }
00030 
00031 EFFlightTime::~EFFlightTime() {
00032   delete m_dtof1;
00033   delete m_dphi1;
00034   delete m_dtof2;
00035   delete m_dphi2;
00036 }
00037 
00038 StatusCode EFFlightTime::initialize(){
00039 
00040   MsgStream log(msgSvc(), name());
00041   log << MSG::INFO << "in initialize()" << endreq;
00042   
00043   IEFAlgorithm::initialize();
00044 
00045   StatusCode sc;
00046   sc = m_HltStoreSvc->put("dtof1", m_dtof1);
00047   if ( sc.isFailure() ) {
00048     log << MSG::ERROR << "m_HltStoreSvc->put(dtof1) wrong" << endreq;
00049     return sc;
00050   }
00051   sc = m_HltStoreSvc->put("dphi1", m_dphi1);
00052   if ( sc.isFailure() ) {
00053     log << MSG::ERROR << "m_HltStoreSvc->put(dphi1) wrong" << endreq;
00054     return sc;
00055   }
00056   sc = m_HltStoreSvc->put("dtof2", m_dtof2);
00057   if ( sc.isFailure() ) {
00058     log << MSG::ERROR << "m_HltStoreSvc->put(dtof2) wrong" << endreq;
00059     return sc;
00060   }
00061   sc = m_HltStoreSvc->put("dphi2", m_dphi2);
00062   if ( sc.isFailure() ) {
00063     log << MSG::ERROR << "m_HltStoreSvc->put(dphi2) wrong" << endreq;
00064     return sc;
00065   }
00066 
00067   log << MSG::DEBUG << "finish initialize()" << endreq;
00068   return StatusCode::SUCCESS;
00069 }
00070 
00071 StatusCode EFFlightTime::execute() {
00072 
00073   reset();
00074 
00075   MsgStream log(msgSvc(), name());
00076   //DataObject*  pObject;
00077 
00078   // Part 1: Get the event header, print out event and run number
00079   SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
00080   if (!eventHeader) {
00081     log << MSG::FATAL << "Could not find Event Header" << endreq;
00082     return( StatusCode::FAILURE);
00083   }
00084   
00085   //Part 2: Retrieve Hits Collection 
00086   //SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc(),"/Event/Digi/TofDigiCol");
00087   //if (!tofDigiCol) {
00088   //  log << MSG::FATAL << "EmcRec could not find Tof digi!!" << endreq;
00089   //  return( StatusCode::FAILURE);
00090   //}
00091   //Part 3: Calculate time difference and back-to-back
00092   //TofDigiCol::iterator iterTOF=tofDigiCol->begin();
00093   VTOF topTOF;
00094   VTOF bottomTOF;
00095   topTOF.clear();
00096   bottomTOF.clear();
00097   Identifier id;
00098   unsigned int idBarrel_Endcap,iphi;
00099   double tdc;
00100 
00101   TofDataVector tofDataVec=m_rawDigiSvc->tofDataVectorOnlineMode();
00102   //TofDataVec tofDataVec=m_rawDigiSvc->tofDataVector(false,false,false,true);
00103   if(tofDataVec.size()>1){
00104     TofDataVector::iterator iterTOF=tofDataVec.begin();
00105     for(;iterTOF!= tofDataVec.end();iterTOF++) {
00106       if((*iterTOF)->barrel()) {
00107         idBarrel_Endcap=1;
00108         int id=(*iterTOF)->tofId();
00109         iphi = id%88;
00110         int ilayer = id/88;
00111         double t1=(*iterTOF)->tdc1();
00112         double t2=(*iterTOF)->tdc2();
00113         double tof=-999;
00114         if(t1<1500&&t2<1500&&t1>0&&t2>0)  tof=0.5*(t1+t2);
00115         else if(t1<1500&&t1>0)   tof=t1;
00116         else if(t2<1500&&t2>0)   tof=t2;
00117         else            continue;
00118         log <<MSG::DEBUG<< "hit: " <<"("<<idBarrel_Endcap<<","<<ilayer<<","<<iphi<<")-->"<< tof <<" ns"<<endreq;
00119         //if(idBarrel_Endcap!=1&&idBarrel_Endcap!=0&&idBarrel_Endcap!=2)
00120         //log << MSG::WARNING <<"TOF(" <<idBarrel_Endcap <<","<< ilayer << "," << iphi << ")=>"
00121         //    << tdc <<endreq;
00122         if(iphi<41&&iphi>2){
00123           topTOF.push_back(EFTofHitsCol(idBarrel_Endcap,ilayer,iphi,tof));
00124         }
00125         else if(iphi>46&&iphi<85){
00126           bottomTOF.push_back(EFTofHitsCol(idBarrel_Endcap,ilayer,iphi,tof));
00127         }
00128       }
00129       else{
00130         int iphi=(*iterTOF)->tofId();
00131         double tof=(*iterTOF)->tdc();
00132         if(iphi>=48) {
00133           idBarrel_Endcap=2;
00134           iphi %=48;
00135         }
00136         else  idBarrel_Endcap=0;
00137         if(iphi>1&&iphi<22&&tof>0&&tof<1500){
00138           topTOF.push_back(EFTofHitsCol(idBarrel_Endcap,0,iphi,tof));
00139         }
00140         else if(iphi>25&&iphi<46&&tof>0&&tof<1500){
00141           bottomTOF.push_back(EFTofHitsCol(idBarrel_Endcap,0,iphi,tof));
00142         }
00143       }    
00144     }
00145   }
00146   double dtof1=99;
00147   double dphi1=180;
00148   double dtof2=99;
00149   double dphi2=180;
00150   if(topTOF.size()>=1&&bottomTOF.size()>=1){
00151     for(unsigned int i=0;i<topTOF.size();i++){
00152       double topPhi=0.;
00153       if(topTOF[i].ib_e()==1){
00154         topPhi=topTOF[i].iphi()*360./88.;
00155       }
00156       else if(topTOF[i].ib_e()==0||topTOF[i].ib_e()==2){
00157         topPhi=topTOF[i].iphi()*360./48.;
00158       }
00159       else{
00160         log << MSG::ERROR << "TOF Barrel_Encap ID not right!" << endreq;
00161       }
00162       for(unsigned int j=0;j<bottomTOF.size();j++){
00163         double bottomPhi=0.;
00164         if(bottomTOF[j].ib_e()==1){
00165           bottomPhi=bottomTOF[j].iphi()*360./88.;
00166         }
00167         else if(bottomTOF[j].ib_e()==0||bottomTOF[j].ib_e()==2){
00168           bottomPhi=bottomTOF[j].iphi()*360./48.;
00169         }
00170         else{
00171           log << MSG::ERROR << "TOF Barrel_Encap ID not right!" << endreq;
00172         }       
00173         double tmp1=fabs(topTOF[i].GetT()-bottomTOF[j].GetT());
00174         double tmp2=fabs(topTOF[i].GetT()-bottomTOF[j].GetT()+7.);
00175         if(tmp2<fabs(dtof2+7.)){
00176           dtof2=topTOF[i].GetT()-bottomTOF[j].GetT();
00177           dphi2=abs(fabs(topPhi-bottomPhi)-180.);
00178         }
00179         if(tmp1<fabs(dtof1)){
00180           dphi1=abs(fabs(topPhi-bottomPhi)-180.);
00181           dtof1=topTOF[i].GetT()-bottomTOF[j].GetT();
00182         }
00183       }
00184     }
00185   }
00186 
00187   log << MSG::INFO << "dtof1=" << dtof1 << ", dphi1=" << dphi1 
00188       << "dtof2=" << dtof2 << ", dphi2=" << dphi2 <<endreq;
00189 
00190   //Part 4: Put the criteria item(s) to HltStoreSvc here
00191   m_dtof1->setValue(dtof1);
00192   m_dphi1->setValue(dphi1);
00193   m_dtof2->setValue(dtof2);
00194   m_dphi2->setValue(dphi2);
00195   m_ef->appToEFVec(dtof1, 26);
00196   m_ef->appToEFVec(dphi1, 27);
00197   m_ef->appToEFVec(dtof2, 28);
00198   m_ef->appToEFVec(dphi2, 29);
00199   m_ef->setVecBit(true, 0, 5);
00200   m_ef->addToEFVec(4<<8, 1);
00201 
00202   m_run=1;
00203   return StatusCode::SUCCESS;
00204 }
00205 
00206 StatusCode EFFlightTime::finalize() {
00207   MsgStream log(msgSvc(), name());
00208   log << MSG::INFO << "in finalize()" << endmsg;
00209   return StatusCode::SUCCESS;
00210 }
00211 
00212 void EFFlightTime::reset() {
00213 
00214   if(m_run){
00215     m_dtof1->reset();
00216     m_dphi1->reset();
00217     m_dtof2->reset();
00218     m_dphi2->reset();
00219     m_run=0;
00220   }
00221   return;
00222 }
00223 
00224 VTOF::iterator EFFlightTime::FindHit(VTOF& tof,
00225                                      const unsigned int ilayer,const unsigned int iphi,const unsigned int ibe){
00226   VTOF::iterator it=tof.begin();
00227   for(;it!=tof.end();it++){
00228     if(ibe!=it->ib_e())continue;
00229     if(ilayer==it->ilayer()){
00230       if(iphi==it->iphi()) return it;
00231       if(iphi+1==it->iphi()) return it;
00232       if(iphi-1==it->iphi()) return it;
00233     }
00234     else{
00235       if(iphi==it->iphi()) return it;
00236       if(iphi+(it->ilayer()-ilayer)==it->iphi()) return it;
00237     }
00238   }
00239   return it;
00240 }

Generated on Tue Nov 29 23:12:06 2016 for BOSS_7.0.2 by  doxygen 1.4.7