Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:44

0001 #include <memory>
0002 #include "FWCore/Framework/interface/ModuleFactory.h"
0003 #include "FWCore/Framework/interface/ESProducer.h"
0004 #include "FWCore/Framework/interface/ESProductHost.h"
0005 #include "FWCore/Framework/interface/ESHandle.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/Utilities/interface/ReusableObjectHolder.h"
0008 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
0009 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
0010 #include "RecoEcal/EgammaCoreTools/interface/EcalNextToDeadChannel.h"
0011 #include "RecoEcal/EgammaCoreTools/interface/EcalNextToDeadChannelRcd.h"
0012 #include "RecoEcal/EgammaCoreTools/interface/EcalTools.h"
0013 
0014 /**
0015    ESProducer to fill the EcalNextToDeadChannel record
0016    starting from EcalChannelStatus information
0017    
0018 
0019    \author Stefano Argiro
0020    \date 18 May 2011
0021 */
0022 
0023 class EcalNextToDeadChannelESProducer : public edm::ESProducer {
0024 public:
0025   EcalNextToDeadChannelESProducer(const edm::ParameterSet& iConfig);
0026 
0027   typedef std::shared_ptr<EcalNextToDeadChannel> ReturnType;
0028 
0029   ReturnType produce(const EcalNextToDeadChannelRcd& iRecord);
0030 
0031 private:
0032   void setupNextToDeadChannels(const EcalChannelStatusRcd&, EcalNextToDeadChannel*);
0033 
0034   using HostType = edm::ESProductHost<EcalNextToDeadChannel, EcalChannelStatusRcd>;
0035 
0036   edm::ReusableObjectHolder<HostType> holder_;
0037 
0038   edm::ESGetToken<EcalChannelStatus, EcalChannelStatusRcd> const channelToken_;
0039   // threshold above which a channel will be considered "dead"
0040   int statusThreshold_;
0041 };
0042 
0043 EcalNextToDeadChannelESProducer::EcalNextToDeadChannelESProducer(const edm::ParameterSet& iConfig)
0044     : channelToken_(setWhatProduced(this).consumesFrom<EcalChannelStatus, EcalChannelStatusRcd>()) {
0045   statusThreshold_ = iConfig.getParameter<int>("channelStatusThresholdForDead");
0046 }
0047 
0048 EcalNextToDeadChannelESProducer::ReturnType EcalNextToDeadChannelESProducer::produce(
0049     const EcalNextToDeadChannelRcd& iRecord) {
0050   auto host = holder_.makeOrGet([]() { return new HostType; });
0051 
0052   host->ifRecordChanges<EcalChannelStatusRcd>(
0053       iRecord, [this, h = host.get()](auto const& rec) { setupNextToDeadChannels(rec, h); });
0054 
0055   return host;
0056 }
0057 
0058 void EcalNextToDeadChannelESProducer::setupNextToDeadChannels(const EcalChannelStatusRcd& chs,
0059                                                               EcalNextToDeadChannel* rcd) {
0060   rcd->clear();
0061 
0062   // Find channels next to dead ones and fill corresponding record
0063 
0064   EcalChannelStatus const& h = chs.get(channelToken_);
0065 
0066   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
0067     if (ieta == 0)
0068       continue;
0069     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
0070       if (EBDetId::validDetId(ieta, iphi)) {
0071         EBDetId detid(ieta, iphi);
0072 
0073         if (EcalTools::isNextToDeadFromNeighbours(detid, h, statusThreshold_)) {
0074           rcd->setValue(detid, 1);
0075         };
0076       }
0077     }  // for phi
0078   }    // for eta
0079 
0080   // endcap
0081 
0082   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0083     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0084       if (EEDetId::validDetId(iX, iY, 1)) {
0085         EEDetId detid(iX, iY, 1);
0086 
0087         if (EcalTools::isNextToDeadFromNeighbours(detid, h, statusThreshold_)) {
0088           rcd->setValue(detid, 1);
0089         };
0090       }
0091 
0092       if (EEDetId::validDetId(iX, iY, -1)) {
0093         EEDetId detid(iX, iY, -1);
0094 
0095         if (EcalTools::isNextToDeadFromNeighbours(detid, h, statusThreshold_)) {
0096           rcd->setValue(detid, 1);
0097         };
0098       }
0099     }  // for iy
0100   }    // for ix
0101 }
0102 
0103 //define this as a plug-in
0104 DEFINE_FWK_EVENTSETUP_MODULE(EcalNextToDeadChannelESProducer);