/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/RawDataProviderSvc/RawDataProviderSvc-00-03-46/src/EmcRawDataProvider.cxx

Go to the documentation of this file.
00001 //*******************************
00002 #include "GaudiKernel/MsgStream.h"
00003 //#include "GaudiKernel/Bootstrap.h"
00004 #include "GaudiKernel/SmartDataPtr.h"
00005 //#include "GaudiKernel/Service.h"
00006 //#include "GaudiKernel/DataSvc.h"
00007 #include "Identifier/Identifier.h"
00008 #include "Identifier/EmcID.h"
00009 #include "RawEvent/RawDataUtil.h"
00010 #include "EmcRawEvent/EmcDigi.h"
00011 //#include <exception>
00012 // tianhl for mt
00013 #include "GaudiKernel/ThreadGaudi.h"
00014 // tianhl for mt
00015 
00016 #include "RawDataProviderSvc/EmcRawDataProvider.h"
00017 
00018 EmcRawDataProvider::EmcRawDataProvider():
00019   RawDataProviderBase(),
00020   m_adcLowThreshold(0), m_tLowThreshold(0), m_tHighThreshold(60),
00021   m_hotCrystals(0), m_deadCrystals(0),
00022   m_emcDigiVec(){
00023   m_emcCalibConstSvc=0;
00024 }
00025 
00026 EmcRawDataProvider::EmcRawDataProvider(const char* name, uint32_t elow, uint32_t tlow, uint32_t thigh):
00027   RawDataProviderBase(name),
00028   m_adcLowThreshold(elow), m_tLowThreshold(tlow), m_tHighThreshold(thigh),
00029   m_hotCrystals(0), m_deadCrystals(0),
00030   m_emcDigiVec(){
00031   m_emcCalibConstSvc=0;
00032 }
00033 
00034 EmcRawDataProvider::EmcRawDataProvider(const char* name,std::vector<uint32_t>& hot, std::vector<uint32_t>& dead,
00035                                        uint32_t elow, uint32_t tlow, uint32_t thigh):
00036   RawDataProviderBase(name),
00037   m_adcLowThreshold(elow), m_tLowThreshold(tlow), m_tHighThreshold(thigh),
00038   m_hotCrystals(hot), m_deadCrystals(dead),
00039   m_emcDigiVec(){
00040   m_emcCalibConstSvc=0;
00041 }
00042 
00043 void EmcRawDataProvider::handle(const Incident& inc){
00044   MsgStream log(m_msgSvc, m_name);
00045   log << MSG::DEBUG << "inc.type=" << inc.type() << endreq;
00046   if ( inc.type() == "BeginEvent" ){
00047     EmcDigiCol empty;
00048     m_emcDigiVec=empty;
00049   }
00050   return;
00051 }
00052 
00053 StatusCode EmcRawDataProvider::initialize(bool mode, ISvcLocator* pSvcLoc, IMessageSvc* pMsg){
00054 
00055   RawDataProviderBase::initialize(pSvcLoc,pMsg);
00056   // test cut value
00057   MsgStream log(m_msgSvc, m_name);
00058   if(log.level()<=MSG::INFO){
00059     std::cout << "EmcRawDataProvider::    " << "elow=" << m_adcLowThreshold << ", tlow=" << m_tLowThreshold
00060               << ", thigh=" << m_tHighThreshold << std::endl;
00061     std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
00062     std::cout << "     hot crystals       ";
00063     for(;it!=m_hotCrystals.end();it++){
00064       std::cout << *it << "    ";  
00065     }
00066     std::cout << std::endl << "    dead crystals       ";
00067     for(it=m_deadCrystals.begin();it!=m_deadCrystals.end();it++){
00068       std::cout << *it << "    ";
00069     }
00070     std::cout << std::endl;
00071   }
00072 
00073   // get point of EMC calibration service
00074   StatusCode sc = m_svcLocator->service("EmcCalibConstSvc", m_emcCalibConstSvc);
00075   if(sc != StatusCode::SUCCESS) {
00076     log << MSG::ERROR << "Can't get EmcCalibConstSvc." << endreq;
00077     m_emcCalibConstSvc=0;
00078   }
00079   else if(mode)   m_emcCalibConstSvc->getDigiCalibConst(0);
00080 
00081   return StatusCode::SUCCESS;
00082 }
00083 
00084 bool EmcRawDataProvider::isGoodEmcDigi(uint32_t control, uint32_t id, uint32_t measure,
00085                                        uint32_t adc, uint32_t tdc){
00086   if(control&DropLow) {
00087     if(measure==0&&adc<m_adcLowThreshold) return false;
00088   }
00089   if(control&DropFull) {
00090     if(measure==3) return false;
00091   }
00092   if(control&CutTime) {
00093     if(tdc<m_tLowThreshold||tdc>m_tHighThreshold) return false;
00094   }
00095   if(control&DropHot) {
00096     std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
00097     for(;it!=m_hotCrystals.end();it++){
00098       if((*it)==id) return false;
00099     }
00100   }
00101   if(control&DropDead) {
00102     std::vector<uint32_t>::iterator it=m_deadCrystals.begin();
00103     for(;it!=m_deadCrystals.end();it++){
00104       if((*it)==id) return false;
00105     }
00106   }
00107   return true;
00108 }
00109 
00110 bool EmcRawDataProvider::isGoodEmcDigi(uint32_t control, EmcDigi* emcDigi){
00111   uint32_t adc=emcDigi->getChargeChannel();
00112   uint32_t measure=emcDigi->getMeasure();
00113   uint32_t tdc=emcDigi->getTimeChannel();
00114   Identifier id=emcDigi->identify();
00115   return isGoodEmcDigi(control,id.get_value(),measure,adc,tdc);
00116 }
00117 
00118 void EmcRawDataProvider::doCalib(Identifier& id, uint32_t& measure, uint32_t& adc){
00119   
00120   uint32_t part = EmcID::barrel_ec(id);
00121   uint32_t itheta = EmcID::theta_module(id);
00122   uint32_t iphi   = EmcID::phi_module(id);
00123   int index = m_emcCalibConstSvc->getIndex(part,itheta,iphi);
00124   double adc2e = m_emcCalibConstSvc->getDigiCalibConst(index);
00125   double e = RawDataUtil::EmcCharge(measure, adc)*adc2e;
00126 
00127   measure =RawDataUtil::EmcChargeMeasure(e);
00128   adc     =RawDataUtil::EmcChargeChannel(e);
00129 }
00130 
00131 void EmcRawDataProvider::doCalib(EmcDigi* emcDigi){
00132   Identifier id=emcDigi->identify();
00133   uint32_t adc=emcDigi->getChargeChannel();
00134   uint32_t measure=emcDigi->getMeasure();
00135   doCalib(id,measure,adc);
00136   emcDigi->setChargeChannel(adc);
00137   emcDigi->setMeasure(measure);
00138 }
00139 
00140 EmcDigiCol& EmcRawDataProvider::getEmcDigiVec(uint32_t control){
00141   MsgStream log(m_msgSvc, m_name);
00142   log << MSG::INFO << "EmcRawDataProvider::getEmcDigiVec..." << endreq;
00143   log << MSG::DEBUG << "vector size=" << m_emcDigiVec.size() << endreq;
00144 
00145   if(m_emcDigiVec.size()>0){
00146     if(control&Redo) m_emcDigiVec=EmcDigiCol();
00147     else             return m_emcDigiVec;
00148   }
00149   // Retrieve Hits Collection 
00150     // tianhl for mt
00151     std::string evtDataSvc_name("EventDataSvc");
00152     if(isGaudiThreaded(m_name)){
00153       evtDataSvc_name += getGaudiThreadIDfromName(m_name);
00154     }
00155     // tianhl for mt
00156   IDataProviderSvc* evtSvc;
00157   StatusCode sc = m_svcLocator->service(evtDataSvc_name.c_str(),evtSvc,true);
00158   if (!sc.isSuccess()){
00159     log << MSG::FATAL << "EmcRawDataProvider: ERROR Could not load EventDataSvc" << endreq;
00160   }
00161 
00162   SmartDataPtr<EmcDigiCol> emcDigiCol(evtSvc,"/Event/Digi/EmcDigiCol");
00163   if (!emcDigiCol) {
00164     log << MSG::FATAL << "Could not find Emc digi!!" << endreq;
00165     return m_emcDigiVec;
00166   }
00167   log << MSG::DEBUG << "start dealing with EmcRawCol " << emcDigiCol->size() << endreq; 
00168   EmcDigiCol::iterator iterEMC=emcDigiCol->begin();
00169   for(;iterEMC!= emcDigiCol->end();iterEMC++) {
00170     log << MSG::NIL << "vector size=" << m_emcDigiVec.size() << endreq;
00171     if(isGoodEmcDigi(control,*iterEMC)) m_emcDigiVec.insert(m_emcDigiVec.end(),*iterEMC);
00172     if(control&DoCalib) {
00173       if(m_emcCalibConstSvc!=0) doCalib(*iterEMC);
00174       else {
00175         log << MSG::WARNING << "require EMC calibration, but none service, ignore." << endreq; 
00176       }
00177     }
00178     if(control&DoOther) { }
00179   }
00180   log << MSG::VERBOSE << "ready for return" << endreq;
00181   return m_emcDigiVec;
00182 }
00183 
00184 bool EmcRawDataProvider::removeHotCrystal(uint32_t teid){
00185   std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
00186   for(;it!=m_hotCrystals.end();it++){
00187     if((*it)==teid) {
00188       m_hotCrystals.erase(it);
00189       break;
00190     }
00191   }
00192   if(it==m_hotCrystals.end()) return false;
00193 
00194   return true;
00195 }
00196 
00197 bool EmcRawDataProvider::removeDeadCrystal(uint32_t teid){
00198   std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
00199   for(;it!=m_deadCrystals.end();it++){
00200     if((*it)==teid) {
00201       m_deadCrystals.erase(it);
00202       break;
00203     }
00204   }
00205   if(it==m_deadCrystals.end()) return false;
00206   
00207   return true;
00208 }
00209 
00210 void EmcRawDataProvider::addHotCrystal(uint32_t teid){
00211   std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
00212   for(;it!=m_hotCrystals.end();it++){
00213     if((*it)==teid) break;
00214   }
00215   if(it==m_hotCrystals.end()) m_hotCrystals.push_back(teid);
00216 
00217   return;
00218 }
00219  
00220 void EmcRawDataProvider::addDeadCrystal(uint32_t teid){
00221   std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
00222   for(;it!=m_deadCrystals.end();it++){
00223     if((*it)==teid) break;
00224   }
00225   if(it==m_deadCrystals.end()) m_deadCrystals.push_back(teid);
00226   
00227   return;
00228 }

Generated on Tue Nov 29 22:58:35 2016 for BOSS_7.0.2 by  doxygen 1.4.7