Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:24:21

0001 #include "RecoLocalCalo/EcalRecProducers/plugins/EcalDetIdToBeRecoveredProducer.h"
0002 
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 
0006 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0011 
0012 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0013 
0014 #include <set>
0015 
0016 #include <sys/types.h>
0017 #include <csignal>
0018 
0019 EcalDetIdToBeRecoveredProducer::EcalDetIdToBeRecoveredProducer(const edm::ParameterSet& ps) {
0020   ecalMappingToken_ = esConsumes<EcalElectronicsMapping, EcalMappingRcd, edm::Transition::BeginRun>();
0021   channelStatusToken_ = esConsumes<EcalChannelStatusMap, EcalChannelStatusRcd, edm::Transition::BeginRun>();
0022   ttMapToken_ = esConsumes<EcalTrigTowerConstituentsMap, IdealGeometryRecord, edm::Transition::BeginRun>();
0023   // SRP collections
0024   ebSrFlagToken_ = consumes<EBSrFlagCollection>(ps.getParameter<edm::InputTag>("ebSrFlagCollection"));
0025   eeSrFlagToken_ = consumes<EESrFlagCollection>(ps.getParameter<edm::InputTag>("eeSrFlagCollection"));
0026 
0027   // Integrity for xtal data
0028   ebIntegrityGainErrorsToken_ = consumes<EBDetIdCollection>(ps.getParameter<edm::InputTag>("ebIntegrityGainErrors"));
0029   ebIntegrityGainSwitchErrorsToken_ =
0030       consumes<EBDetIdCollection>(ps.getParameter<edm::InputTag>("ebIntegrityGainSwitchErrors"));
0031   ebIntegrityChIdErrorsToken_ = consumes<EBDetIdCollection>(ps.getParameter<edm::InputTag>("ebIntegrityChIdErrors"));
0032 
0033   // Integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
0034   eeIntegrityGainErrorsToken_ = consumes<EEDetIdCollection>(ps.getParameter<edm::InputTag>("eeIntegrityGainErrors"));
0035   eeIntegrityGainSwitchErrorsToken_ =
0036       consumes<EEDetIdCollection>(ps.getParameter<edm::InputTag>("eeIntegrityGainSwitchErrors"));
0037   eeIntegrityChIdErrorsToken_ = consumes<EEDetIdCollection>(ps.getParameter<edm::InputTag>("eeIntegrityChIdErrors"));
0038 
0039   // Integrity Errors
0040   integrityTTIdErrorsToken_ =
0041       consumes<EcalElectronicsIdCollection>(ps.getParameter<edm::InputTag>("integrityTTIdErrors"));
0042   integrityBlockSizeErrorsToken_ =
0043       consumes<EcalElectronicsIdCollection>(ps.getParameter<edm::InputTag>("integrityBlockSizeErrors"));
0044 
0045   // output collections
0046   ebDetIdCollection_ = ps.getParameter<std::string>("ebDetIdToBeRecovered");
0047   eeDetIdCollection_ = ps.getParameter<std::string>("eeDetIdToBeRecovered");
0048   ttDetIdCollection_ = ps.getParameter<std::string>("ebFEToBeRecovered");
0049   scDetIdCollection_ = ps.getParameter<std::string>("eeFEToBeRecovered");
0050 
0051   produces<std::set<EBDetId>>(ebDetIdCollection_);
0052   produces<std::set<EEDetId>>(eeDetIdCollection_);
0053   produces<std::set<EcalTrigTowerDetId>>(ttDetIdCollection_);
0054   produces<std::set<EcalScDetId>>(scDetIdCollection_);
0055 }
0056 
0057 EcalDetIdToBeRecoveredProducer::~EcalDetIdToBeRecoveredProducer() {}
0058 
0059 void EcalDetIdToBeRecoveredProducer::beginRun(edm::Run const& run, const edm::EventSetup& es) {
0060   edm::ESHandle<EcalElectronicsMapping> pEcalMapping = es.getHandle(ecalMappingToken_);
0061   ecalMapping_ = pEcalMapping.product();
0062 
0063   edm::ESHandle<EcalChannelStatusMap> pChStatus = es.getHandle(channelStatusToken_);
0064   chStatus_ = pChStatus.product();
0065 
0066   ttMap_ = es.getHandle(ttMapToken_);
0067 }
0068 
0069 // fuction return true if "coll" have "item"
0070 template <typename CollT, typename ItemT>
0071 bool include(const CollT& coll, const ItemT& item) {
0072   typename CollT::const_iterator res = std::find(coll.begin(), coll.end(), item);
0073   return (res != coll.end());
0074 }
0075 
0076 void EcalDetIdToBeRecoveredProducer::produce(edm::Event& ev, const edm::EventSetup& es) {
0077   std::vector<edm::Handle<EBDetIdCollection>> ebDetIdColls;
0078   std::vector<edm::Handle<EEDetIdCollection>> eeDetIdColls;
0079   std::vector<edm::Handle<EcalElectronicsIdCollection>> ttColls;
0080 
0081   auto ebDetIdToRecover = std::make_unique<std::set<EBDetId>>();               // isolated channels to be recovered
0082   auto eeDetIdToRecover = std::make_unique<std::set<EEDetId>>();               // isolated channels to be recovered
0083   auto ebTTDetIdToRecover = std::make_unique<std::set<EcalTrigTowerDetId>>();  // tt to be recovered
0084   auto eeSCDetIdToRecover = std::make_unique<std::set<EcalScDetId>>();         // sc to be recovered
0085 
0086   /*
0087          * get collections
0088          */
0089 
0090   // Selective Readout Flags
0091   edm::Handle<EBSrFlagCollection> ebSrFlags;
0092   ev.getByToken(ebSrFlagToken_, ebSrFlags);
0093 
0094   edm::Handle<EESrFlagCollection> eeSrFlags;
0095   ev.getByToken(eeSrFlagToken_, eeSrFlags);
0096 
0097   // Integrity errors
0098   edm::Handle<EBDetIdCollection> ebIntegrityGainErrors;
0099   ev.getByToken(ebIntegrityGainErrorsToken_, ebIntegrityGainErrors);
0100 
0101   ebDetIdColls.push_back(ebIntegrityGainErrors);
0102 
0103   edm::Handle<EBDetIdCollection> ebIntegrityGainSwitchErrors;
0104   ev.getByToken(ebIntegrityGainSwitchErrorsToken_, ebIntegrityGainSwitchErrors);
0105   ebDetIdColls.push_back(ebIntegrityGainSwitchErrors);
0106 
0107   edm::Handle<EBDetIdCollection> ebIntegrityChIdErrors;
0108   ev.getByToken(ebIntegrityChIdErrorsToken_, ebIntegrityChIdErrors);
0109   ebDetIdColls.push_back(ebIntegrityChIdErrors);
0110 
0111   edm::Handle<EEDetIdCollection> eeIntegrityGainErrors;
0112   ev.getByToken(eeIntegrityGainErrorsToken_, eeIntegrityGainErrors);
0113   eeDetIdColls.push_back(eeIntegrityGainErrors);
0114 
0115   edm::Handle<EEDetIdCollection> eeIntegrityGainSwitchErrors;
0116   ev.getByToken(eeIntegrityGainSwitchErrorsToken_, eeIntegrityGainSwitchErrors);
0117   eeDetIdColls.push_back(eeIntegrityGainSwitchErrors);
0118 
0119   edm::Handle<EEDetIdCollection> eeIntegrityChIdErrors;
0120   ev.getByToken(eeIntegrityChIdErrorsToken_, eeIntegrityChIdErrors);
0121   eeDetIdColls.push_back(eeIntegrityChIdErrors);
0122 
0123   edm::Handle<EcalElectronicsIdCollection> integrityTTIdErrors;
0124   ev.getByToken(integrityTTIdErrorsToken_, integrityTTIdErrors);
0125   ttColls.push_back(integrityTTIdErrors);
0126 
0127   edm::Handle<EcalElectronicsIdCollection> integrityBlockSizeErrors;
0128   ev.getByToken(integrityBlockSizeErrorsToken_, integrityBlockSizeErrors);
0129   ttColls.push_back(integrityBlockSizeErrors);
0130 
0131   /*
0132          *  get regions of interest from SRP
0133          */
0134   // -- Barrel
0135   EBDetIdCollection ebSrpDetId;
0136   EcalTrigTowerDetIdCollection ebSrpTTDetId;
0137   for (EBSrFlagCollection::const_iterator it = ebSrFlags->begin(); it != ebSrFlags->end(); ++it) {
0138     const int flag = it->value();
0139     if (flag == EcalSrFlag::SRF_FULL || (flag == EcalSrFlag::SRF_FORCED_MASK)) {
0140       const EcalTrigTowerDetId ttId = it->id();
0141       ebSrpTTDetId.push_back(ttId);
0142 
0143       const std::vector<DetId> vid = ttMap_->constituentsOf(ttId);
0144 
0145       for (std::vector<DetId>::const_iterator itId = vid.begin(); itId != vid.end(); ++itId) {
0146         ebSrpDetId.push_back(*itId);
0147       }
0148     }
0149   }
0150   // -- Endcap
0151   EEDetIdCollection eeSrpDetId;
0152   //EcalTrigTowerDetIdCollection eeSrpTTDetId;
0153   for (EESrFlagCollection::const_iterator it = eeSrFlags->begin(); it != eeSrFlags->end(); ++it) {
0154     const int flag = it->value();
0155     if (flag == EcalSrFlag::SRF_FULL || (flag == EcalSrFlag::SRF_FORCED_MASK)) {
0156       //EcalTrigTowerDetId ttId = it->id();
0157       //eeSrpTTDetId.push_back( ttId );
0158       const EcalScDetId scId(it->id());
0159       // not clear how to get the vector of DetId constituents of a SC...
0160       //////////EcalElectronicsId eId( scId.rawId() );
0161       //std::vector<DetId> vid = ecalMapping_->dccTowerConstituents( eId.dccId(), eId.towerId() );
0162       std::vector<DetId> vid;
0163       for (int dx = 1; dx <= 5; ++dx) {
0164         for (int dy = 1; dy <= 5; ++dy) {
0165           const int ix = (scId.ix() - 1) * 5 + dx;
0166           const int iy = (scId.iy() - 1) * 5 + dy;
0167           const int iz = scId.zside();
0168           if (EEDetId::validDetId(ix, iy, iz)) {
0169             vid.push_back(EEDetId(ix, iy, iz));
0170           }
0171         }
0172       }
0173       ////eeSrpDetId.insert( interestingDetId.end(), vid.begin(), vid.end() );
0174       //std::vector<DetId> vid = ttMap_->constituentsOf( ttId );
0175       for (std::vector<DetId>::const_iterator itId = vid.begin(); itId != vid.end(); ++itId) {
0176         eeSrpDetId.push_back(*itId);
0177       }
0178     }
0179   }
0180   // SRP switched off: get the list from the DB
0181   if (ebSrFlags->empty()) {
0182   }
0183   // SRP switched off: get the list from the DB
0184   if (eeSrFlags->empty()) {
0185   }
0186 
0187   /*
0188          *  get OR of integrity error collections
0189          *  in interesting regions flagged by SRP
0190          *  and insert them in the list of DetId to recover
0191          */
0192   // -- Barrel
0193   for (std::vector<edm::Handle<EBDetIdCollection>>::const_iterator it = ebDetIdColls.begin(); it != ebDetIdColls.end();
0194        ++it) {
0195     const EBDetIdCollection* idc = it->product();
0196     for (EBDetIdCollection::const_iterator jt = idc->begin(); jt != idc->end(); ++jt)
0197       if (include(ebSrpDetId, *jt))
0198         ebDetIdToRecover->insert(*jt);
0199   }
0200   // -- Endcap
0201   for (std::vector<edm::Handle<EEDetIdCollection>>::const_iterator it = eeDetIdColls.begin(); it != eeDetIdColls.end();
0202        ++it) {
0203     const EEDetIdCollection* idc = it->product();
0204     for (EEDetIdCollection::const_iterator jt = idc->begin(); jt != idc->end(); ++jt)
0205       if (include(eeSrpDetId, *jt))
0206         eeDetIdToRecover->insert(*jt);
0207   }
0208 
0209   /* 
0210          * find isolated dead channels (from DB info)           --> chStatus 10, 11, 12
0211          * and group of dead channels w/ trigger(from DB info)  --> chStatus 13
0212          * in interesting regions flagged by SRP
0213          */
0214   // -- Barrel
0215   for (EBDetIdCollection::const_iterator itId = ebSrpDetId.begin(); itId != ebSrpDetId.end(); ++itId) {
0216     EcalChannelStatusMap::const_iterator chit = chStatus_->find(*itId);
0217     if (chit != chStatus_->end()) {
0218       const int flag = (*chit).getStatusCode();
0219       if (flag >= 10 && flag <= 12) {  // FIXME -- avoid hardcoded values...
0220         ebDetIdToRecover->insert(*itId);
0221       } else if (flag == 13 || flag == 14) {  // FIXME -- avoid hardcoded values...
0222         ebTTDetIdToRecover->insert((*itId).tower());
0223       }
0224     } else {
0225       edm::LogError("EcalDetIdToBeRecoveredProducer") << "No channel status found for xtal " << (*itId).rawId()
0226                                                       << "! something wrong with EcalChannelStatus in your DB? ";
0227     }
0228   }
0229   // -- Endcap
0230   for (EEDetIdCollection::const_iterator itId = eeSrpDetId.begin(); itId != eeSrpDetId.end(); ++itId) {
0231     EcalChannelStatusMap::const_iterator chit = chStatus_->find(*itId);
0232     if (chit != chStatus_->end()) {
0233       int flag = (*chit).getStatusCode();
0234       if (flag >= 10 && flag <= 12) {  // FIXME -- avoid hardcoded values...
0235         eeDetIdToRecover->insert(*itId);
0236       } else if (flag == 13 || flag == 14) {  // FIXME -- avoid hardcoded values...
0237         eeSCDetIdToRecover->insert(
0238             EcalScDetId(1 + ((*itId).ix() - 1) / 5, 1 + ((*itId).iy() - 1) / 5, (*itId).zside()));
0239       }
0240     } else {
0241       edm::LogError("EcalDetIdToBeRecoveredProducer") << "No channel status found for xtal " << (*itId).rawId()
0242                                                       << "! something wrong with EcalChannelStatus in your DB? ";
0243     }
0244   }
0245 
0246   // loop over electronics id associated with TT and SC
0247   for (size_t t = 0; t < ttColls.size(); ++t) {
0248     const EcalElectronicsIdCollection& coll = *(ttColls[t]);
0249 
0250     for (size_t i = 0; i < coll.size(); ++i) {
0251       const EcalElectronicsId elId = coll[i];
0252       const EcalSubdetector subdet = elId.subdet();
0253       const DetId detId = ecalMapping_->getDetId(elId);
0254 
0255       if (subdet == EcalBarrel) {  // elId pointing to TT
0256         // get list of crystals corresponding to TT
0257         const EcalTrigTowerDetId ttId(ttMap_->towerOf(detId));
0258         const std::vector<DetId>& vid = ttMap_->constituentsOf(ttId);
0259 
0260         for (size_t j = 0; j < vid.size(); ++j) {
0261           const EBDetId ebdi(vid[j]);
0262           if (include(ebSrpDetId, ebdi)) {
0263             ebDetIdToRecover->insert(ebdi);
0264             ebTTDetIdToRecover->insert(ebdi.tower());
0265           }
0266         }
0267       } else if (subdet == EcalEndcap) {  // elId pointing to SC
0268         // extract list of crystals corresponding to SC
0269         const EcalScDetId scId(detId);
0270         std::vector<DetId> vid;
0271         for (int dx = 1; dx <= 5; ++dx) {
0272           for (int dy = 1; dy <= 5; ++dy) {
0273             const int ix = (scId.ix() - 1) * 5 + dx;
0274             const int iy = (scId.iy() - 1) * 5 + dy;
0275             const int iz = scId.zside();
0276             if (EEDetId::validDetId(ix, iy, iz))
0277               vid.push_back(EEDetId(ix, iy, iz));
0278           }
0279         }
0280 
0281         for (size_t j = 0; j < vid.size(); ++j) {
0282           const EEDetId eedi(vid[i]);
0283           if (include(eeSrpDetId, eedi)) {
0284             eeDetIdToRecover->insert(eedi);
0285             eeSCDetIdToRecover->insert(EcalScDetId(eedi));
0286           }
0287         }
0288       } else
0289         edm::LogWarning("EcalDetIdToBeRecoveredProducer")
0290             << "Incorrect EcalSubdetector = " << subdet << " in EcalElectronicsIdCollection collection ";
0291     }
0292   }
0293 
0294   // return the collections
0295   ev.put(std::move(ebDetIdToRecover), ebDetIdCollection_);
0296   ev.put(std::move(eeDetIdToRecover), eeDetIdCollection_);
0297   ev.put(std::move(ebTTDetIdToRecover), ttDetIdCollection_);
0298   ev.put(std::move(eeSCDetIdToRecover), scDetIdCollection_);
0299 }
0300 
0301 void EcalDetIdToBeRecoveredProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0302   edm::ParameterSetDescription desc;
0303   desc.add<edm::InputTag>("ebIntegrityChIdErrors", edm::InputTag("ecalDigis", "EcalIntegrityChIdErrors"));
0304   desc.add<std::string>("ebDetIdToBeRecovered", "ebDetId");
0305   desc.add<edm::InputTag>("integrityTTIdErrors", edm::InputTag("ecalDigis", "EcalIntegrityTTIdErrors"));
0306   desc.add<edm::InputTag>("eeIntegrityGainErrors", edm::InputTag("ecalDigis", "EcalIntegrityGainErrors"));
0307   desc.add<std::string>("ebFEToBeRecovered", "ebFE");
0308   desc.add<edm::InputTag>("ebIntegrityGainErrors", edm::InputTag("ecalDigis", "EcalIntegrityGainErrors"));
0309   desc.add<std::string>("eeDetIdToBeRecovered", "eeDetId");
0310   desc.add<edm::InputTag>("eeIntegrityGainSwitchErrors", edm::InputTag("ecalDigis", "EcalIntegrityGainSwitchErrors"));
0311   desc.add<edm::InputTag>("eeIntegrityChIdErrors", edm::InputTag("ecalDigis", "EcalIntegrityChIdErrors"));
0312   desc.add<edm::InputTag>("ebIntegrityGainSwitchErrors", edm::InputTag("ecalDigis", "EcalIntegrityGainSwitchErrors"));
0313   desc.add<edm::InputTag>("ebSrFlagCollection", edm::InputTag("ecalDigis"));
0314   desc.add<std::string>("eeFEToBeRecovered", "eeFE");
0315   desc.add<edm::InputTag>("integrityBlockSizeErrors", edm::InputTag("ecalDigis", "EcalIntegrityBlockSizeErrors"));
0316   desc.add<edm::InputTag>("eeSrFlagCollection", edm::InputTag("ecalDigis"));
0317   descriptions.add("ecalDetIdToBeRecovered", desc);
0318 }
0319 
0320 #include "FWCore/Framework/interface/MakerMacros.h"
0321 DEFINE_FWK_MODULE(EcalDetIdToBeRecoveredProducer);