CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoLocalCalo/EcalRecProducers/plugins/EcalTPSkimmer.cc

Go to the documentation of this file.
00001 
00011 #include "RecoLocalCalo/EcalRecProducers/plugins/EcalTPSkimmer.h"
00012 
00013 #include "DataFormats/Common/interface/Handle.h"
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 
00018 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00019 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00020 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00021 
00022 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00023 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
00024 
00025 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00026 
00027 EcalTPSkimmer::EcalTPSkimmer(const edm::ParameterSet& ps)
00028 {
00029         skipModule_         = ps.getParameter<bool>("skipModule");
00030 
00031         doBarrel_           = ps.getParameter<bool>("doBarrel");
00032         doEndcap_           = ps.getParameter<bool>("doEndcap");
00033 
00034         chStatusToSelectTP_ = ps.getParameter<std::vector<uint32_t> >("chStatusToSelectTP");
00035 
00036         tpOutputCollection_ = ps.getParameter<std::string>("tpOutputCollection");
00037         tpInputCollection_  = ps.getParameter<edm::InputTag>("tpInputCollection");
00038 
00039         produces< EcalTrigPrimDigiCollection >(tpOutputCollection_);
00040 }
00041 
00042 EcalTPSkimmer::~EcalTPSkimmer()
00043 {
00044 }
00045 
00046 void
00047 EcalTPSkimmer::produce(edm::Event& evt, const edm::EventSetup& es)
00048 {
00049         insertedTP_.clear();
00050         
00051         using namespace edm;
00052 
00053         es.get<IdealGeometryRecord>().get(ttMap_);
00054 
00055         // collection of rechits to put in the event
00056         std::auto_ptr< EcalTrigPrimDigiCollection > tpOut( new EcalTrigPrimDigiCollection );
00057         
00058         if ( skipModule_ ) {
00059                 evt.put( tpOut, tpOutputCollection_ );
00060                 return;
00061         }
00062 
00063         edm::ESHandle<EcalChannelStatus> chStatus;
00064         es.get<EcalChannelStatusRcd>().get(chStatus);
00065 
00066         edm::Handle<EcalTrigPrimDigiCollection> tpIn;
00067         evt.getByLabel(tpInputCollection_, tpIn);
00068 
00069         if ( ! tpIn.isValid() ) {
00070                 edm::LogError("EcalTPSkimmer") << "Can't get the product " << tpInputCollection_.instance()
00071                         << " with label " << tpInputCollection_.label();
00072                 return;
00073         }
00074 
00075         if ( doBarrel_ ) {
00076                 EcalChannelStatusMap::const_iterator chit;
00077                 uint16_t code = 0;
00078                 for ( int i = 0; i < EBDetId::kSizeForDenseIndexing; ++i )
00079                 {
00080                         if ( ! EBDetId::validDenseIndex( i ) ) continue;
00081                         EBDetId id = EBDetId::detIdFromDenseIndex( i );
00082                         chit = chStatus->find( id );
00083                         // check if the channel status means TP to be kept
00084                         if ( chit != chStatus->end() ) {
00085                                 code = (*chit).getStatusCode() & 0x001F;
00086                                 if ( std::find( chStatusToSelectTP_.begin(), chStatusToSelectTP_.end(), code ) != chStatusToSelectTP_.end() ) {
00087                                         // retrieve the TP DetId
00088                                         EcalTrigTowerDetId ttDetId( ((EBDetId)id).tower() );
00089                                         // insert the TP if not done already
00090                                         if ( ! alreadyInserted( ttDetId ) ) insertTP( ttDetId, tpIn, *tpOut );
00091                                 }
00092                         } else {
00093                                 edm::LogError("EcalDetIdToBeRecoveredProducer") << "No channel status found for xtal "
00094                                         << id.rawId()
00095                                         << "! something wrong with EcalChannelStatus in your DB? ";
00096                         }
00097                 }
00098         }
00099 
00100         if ( doEndcap_ ) {
00101                 EcalChannelStatusMap::const_iterator chit;
00102                 uint16_t code = 0;
00103                 for ( int i = 0; i < EEDetId::kSizeForDenseIndexing; ++i )
00104                 {
00105                         if ( ! EEDetId::validDenseIndex( i ) ) continue;
00106                         EEDetId id = EEDetId::detIdFromDenseIndex( i );
00107                         chit = chStatus->find( id );
00108                         // check if the channel status means TP to be kept
00109                         if ( chit != chStatus->end() ) {
00110                                 code = (*chit).getStatusCode() & 0x001F;
00111                                 if ( std::find( chStatusToSelectTP_.begin(), chStatusToSelectTP_.end(), code ) != chStatusToSelectTP_.end() ) {
00112                                         // retrieve the TP DetId
00113                                         EcalTrigTowerDetId ttDetId = ttMap_->towerOf( id );
00114                                         // insert the TP if not done already
00115                                         if ( ! alreadyInserted( ttDetId ) ) insertTP( ttDetId, tpIn, *tpOut );
00116                                 }
00117                         } else {
00118                                 edm::LogError("EcalDetIdToBeRecoveredProducer") << "No channel status found for xtal "
00119                                         << id.rawId()
00120                                         << "! something wrong with EcalChannelStatus in your DB? ";
00121                         }
00122                 }
00123         }
00124 
00125         // put the collection of reconstructed hits in the event   
00126         LogInfo("EcalTPSkimmer") << "total # of TP inserted: " << tpOut->size();
00127 
00128         evt.put( tpOut, tpOutputCollection_ );
00129 }
00130 
00131 
00132 bool EcalTPSkimmer::alreadyInserted( EcalTrigTowerDetId ttId )
00133 {
00134         return ( insertedTP_.find( ttId ) != insertedTP_.end() );
00135 }
00136 
00137 
00138 void EcalTPSkimmer::insertTP( EcalTrigTowerDetId ttId, edm::Handle<EcalTrigPrimDigiCollection> &tpIn, EcalTrigPrimDigiCollection &tpOut )
00139 {
00140         EcalTrigPrimDigiCollection::const_iterator tpIt = tpIn->find( ttId );
00141         if ( tpIt != tpIn->end() ) {
00142                 tpOut.push_back( *tpIt );
00143                 insertedTP_.insert( ttId );
00144         }
00145 }
00146 
00147 
00148 #include "FWCore/Framework/interface/MakerMacros.h"
00149 DEFINE_FWK_MODULE( EcalTPSkimmer );
00150