Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-31 23:17:22

0001 /** \class EcalRecHitProducer
0002  *   produce ECAL rechits from uncalibrated rechits
0003  *
0004  *  \author Shahram Rahatlou, University of Rome & INFN, March 2006
0005  *
0006  **/
0007 #include "RecoLocalCalo/EcalRecProducers/plugins/EcalRecHitProducer.h"
0008 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalCleaningAlgo.h"
0009 
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0013 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0014 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0015 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
0016 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
0017 #include "DataFormats/EcalDetId/interface/EcalScDetId.h"
0018 
0019 #include "RecoLocalCalo/EcalRecProducers/interface/EcalRecHitWorkerFactory.h"
0020 
0021 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0023 
0024 EcalRecHitProducer::EcalRecHitProducer(const edm::ParameterSet& ps)
0025     : doEB_(!ps.getParameter<edm::InputTag>("EBuncalibRecHitCollection").label().empty()),
0026       doEE_(!ps.getParameter<edm::InputTag>("EEuncalibRecHitCollection").label().empty()),
0027       recoverEBIsolatedChannels_(ps.getParameter<bool>("recoverEBIsolatedChannels")),
0028       recoverEEIsolatedChannels_(ps.getParameter<bool>("recoverEEIsolatedChannels")),
0029       recoverEBVFE_(ps.getParameter<bool>("recoverEBVFE")),
0030       recoverEEVFE_(ps.getParameter<bool>("recoverEEVFE")),
0031       recoverEBFE_(ps.getParameter<bool>("recoverEBFE")),
0032       recoverEEFE_(ps.getParameter<bool>("recoverEEFE")),
0033       killDeadChannels_(ps.getParameter<bool>("killDeadChannels")),
0034       ebRecHitToken_(produces<EBRecHitCollection>(ps.getParameter<std::string>("EBrechitCollection"))),
0035       eeRecHitToken_(produces<EERecHitCollection>(ps.getParameter<std::string>("EErechitCollection"))) {
0036   if (doEB_) {
0037     ebUncalibRecHitToken_ =
0038         consumes<EBUncalibratedRecHitCollection>(ps.getParameter<edm::InputTag>("EBuncalibRecHitCollection"));
0039 
0040     if (recoverEBIsolatedChannels_ || recoverEBFE_ || killDeadChannels_) {
0041       ebDetIdToBeRecoveredToken_ = consumes<std::set<EBDetId>>(ps.getParameter<edm::InputTag>("ebDetIdToBeRecovered"));
0042     }
0043 
0044     if (recoverEBFE_ || killDeadChannels_) {
0045       ebFEToBeRecoveredToken_ =
0046           consumes<std::set<EcalTrigTowerDetId>>(ps.getParameter<edm::InputTag>("ebFEToBeRecovered"));
0047     }
0048   }
0049 
0050   if (doEE_) {
0051     eeUncalibRecHitToken_ =
0052         consumes<EEUncalibratedRecHitCollection>(ps.getParameter<edm::InputTag>("EEuncalibRecHitCollection"));
0053 
0054     if (recoverEEIsolatedChannels_ || recoverEEFE_ || killDeadChannels_) {
0055       eeDetIdToBeRecoveredToken_ = consumes<std::set<EEDetId>>(ps.getParameter<edm::InputTag>("eeDetIdToBeRecovered"));
0056     }
0057 
0058     if (recoverEEFE_ || killDeadChannels_) {
0059       eeFEToBeRecoveredToken_ = consumes<std::set<EcalScDetId>>(ps.getParameter<edm::InputTag>("eeFEToBeRecovered"));
0060     }
0061   }
0062 
0063   if (recoverEBIsolatedChannels_ || recoverEBFE_ || recoverEEIsolatedChannels_ || recoverEEFE_ || killDeadChannels_) {
0064     ecalChannelStatusToken_ = esConsumes<EcalChannelStatus, EcalChannelStatusRcd>();
0065   }
0066 
0067   std::string componentType = ps.getParameter<std::string>("algo");
0068   edm::ConsumesCollector c{consumesCollector()};
0069   worker_ = EcalRecHitWorkerFactory::get()->create(componentType, ps, c);
0070 
0071   // to recover problematic channels
0072   componentType = ps.getParameter<std::string>("algoRecover");
0073   workerRecover_ = EcalRecHitWorkerFactory::get()->create(componentType, ps, c);
0074 
0075   edm::ParameterSet cleaningPs = ps.getParameter<edm::ParameterSet>("cleaningConfig");
0076   cleaningAlgo_ = std::make_unique<EcalCleaningAlgo>(cleaningPs);
0077 }
0078 
0079 EcalRecHitProducer::~EcalRecHitProducer() = default;
0080 
0081 void EcalRecHitProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
0082   using namespace edm;
0083 
0084   // collection of rechits to put in the event
0085   auto ebRecHits = std::make_unique<EBRecHitCollection>();
0086   auto eeRecHits = std::make_unique<EERecHitCollection>();
0087 
0088   worker_->set(es);
0089 
0090   if (recoverEBIsolatedChannels_ || recoverEEIsolatedChannels_ || recoverEBFE_ || recoverEEFE_ || recoverEBVFE_ ||
0091       recoverEEVFE_ || killDeadChannels_) {
0092     workerRecover_->set(es);
0093   }
0094 
0095   // Make EB rechits
0096   if (doEB_) {
0097     const auto& ebUncalibRecHits = evt.get(ebUncalibRecHitToken_);
0098     LogDebug("EcalRecHitDebug") << "total # EB uncalibrated rechits: " << ebUncalibRecHits.size();
0099 
0100     // loop over uncalibrated rechits to make calibrated ones
0101     for (const auto& uncalibRecHit : ebUncalibRecHits) {
0102       worker_->run(evt, uncalibRecHit, *ebRecHits);
0103     }
0104   }
0105 
0106   // Make EE rechits
0107   if (doEE_) {
0108     const auto& eeUncalibRecHits = evt.get(eeUncalibRecHitToken_);
0109     LogDebug("EcalRecHitDebug") << "total # EE uncalibrated rechits: " << eeUncalibRecHits.size();
0110 
0111     // loop over uncalibrated rechits to make calibrated ones
0112     for (const auto& uncalibRecHit : eeUncalibRecHits) {
0113       worker_->run(evt, uncalibRecHit, *eeRecHits);
0114     }
0115   }
0116 
0117   // sort collections before attempting recovery, to avoid insertion of double recHits
0118   ebRecHits->sort();
0119   eeRecHits->sort();
0120 
0121   if (recoverEBIsolatedChannels_ || recoverEBFE_ || killDeadChannels_) {
0122     const auto& detIds = evt.get(ebDetIdToBeRecoveredToken_);
0123     const auto& chStatus = es.getData(ecalChannelStatusToken_);
0124 
0125     for (const auto& detId : detIds) {
0126       // get channel status map to treat dead VFE separately
0127       EcalChannelStatusMap::const_iterator chit = chStatus.find(detId);
0128       EcalChannelStatusCode chStatusCode;
0129       if (chit != chStatus.end()) {
0130         chStatusCode = *chit;
0131       } else {
0132         edm::LogError("EcalRecHitProducerError") << "No channel status found for xtal " << detId.rawId()
0133                                                  << "! something wrong with EcalChannelStatus in your DB? ";
0134       }
0135       EcalUncalibratedRecHit urh;
0136       if (chStatusCode.getStatusCode() == EcalChannelStatusCode::kDeadVFE) {  // dead VFE (from DB info)
0137         // uses the EcalUncalibratedRecHit to pass the DetId info
0138         urh = EcalUncalibratedRecHit(detId, 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EB_VFE);
0139         if (recoverEBVFE_ || killDeadChannels_)
0140           workerRecover_->run(evt, urh, *ebRecHits);
0141       } else {
0142         // uses the EcalUncalibratedRecHit to pass the DetId info
0143         urh = EcalUncalibratedRecHit(detId, 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EB_single);
0144         if (recoverEBIsolatedChannels_ || killDeadChannels_)
0145           workerRecover_->run(evt, urh, *ebRecHits);
0146       }
0147     }
0148   }
0149 
0150   if (recoverEEIsolatedChannels_ || recoverEEVFE_ || killDeadChannels_) {
0151     const auto& detIds = evt.get(eeDetIdToBeRecoveredToken_);
0152     const auto& chStatus = es.getData(ecalChannelStatusToken_);
0153 
0154     for (const auto& detId : detIds) {
0155       // get channel status map to treat dead VFE separately
0156       EcalChannelStatusMap::const_iterator chit = chStatus.find(detId);
0157       EcalChannelStatusCode chStatusCode;
0158       if (chit != chStatus.end()) {
0159         chStatusCode = *chit;
0160       } else {
0161         edm::LogError("EcalRecHitProducerError") << "No channel status found for xtal " << detId.rawId()
0162                                                  << "! something wrong with EcalChannelStatus in your DB? ";
0163       }
0164       EcalUncalibratedRecHit urh;
0165       if (chStatusCode.getStatusCode() == EcalChannelStatusCode::kDeadVFE) {  // dead VFE (from DB info)
0166         // uses the EcalUncalibratedRecHit to pass the DetId info
0167         urh = EcalUncalibratedRecHit(detId, 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EE_VFE);
0168         if (recoverEEVFE_ || killDeadChannels_)
0169           workerRecover_->run(evt, urh, *eeRecHits);
0170       } else {
0171         // uses the EcalUncalibratedRecHit to pass the DetId info
0172         urh = EcalUncalibratedRecHit(detId, 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EE_single);
0173         if (recoverEEIsolatedChannels_ || killDeadChannels_)
0174           workerRecover_->run(evt, urh, *eeRecHits);
0175       }
0176     }
0177   }
0178 
0179   if (recoverEBFE_ || killDeadChannels_) {
0180     const auto& ttIds = evt.get(ebFEToBeRecoveredToken_);
0181 
0182     for (const auto& ttId : ttIds) {
0183       // uses the EcalUncalibratedRecHit to pass the DetId info
0184       int ieta = ((ttId.ietaAbs() - 1) * 5 + 1) * ttId.zside();  // from EcalTrigTowerConstituentsMap
0185       int iphi = ((ttId.iphi() - 1) * 5 + 11) % 360;             // from EcalTrigTowerConstituentsMap
0186       if (iphi <= 0)
0187         iphi += 360;  // from EcalTrigTowerConstituentsMap
0188       EcalUncalibratedRecHit urh(
0189           EBDetId(ieta, iphi, EBDetId::ETAPHIMODE), 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EB_FE);
0190       workerRecover_->run(evt, urh, *ebRecHits);
0191     }
0192   }
0193 
0194   if (recoverEEFE_ || killDeadChannels_) {
0195     const auto& scIds = evt.get(eeFEToBeRecoveredToken_);
0196 
0197     for (const auto& scId : scIds) {
0198       // uses the EcalUncalibratedRecHit to pass the DetId info
0199       if (EEDetId::validDetId((scId.ix() - 1) * 5 + 1, (scId.iy() - 1) * 5 + 1, scId.zside())) {
0200         EcalUncalibratedRecHit urh(EEDetId((scId.ix() - 1) * 5 + 1, (scId.iy() - 1) * 5 + 1, scId.zside()),
0201                                    0,
0202                                    0,
0203                                    0,
0204                                    0,
0205                                    EcalRecHitWorkerBaseClass::EE_FE);
0206         workerRecover_->run(evt, urh, *eeRecHits);
0207       }
0208     }
0209   }
0210 
0211   // without re-sorting, find (used below in cleaning) will lead
0212   // to undefined results
0213   ebRecHits->sort();
0214   eeRecHits->sort();
0215 
0216   // apply spike cleaning
0217   if (cleaningAlgo_) {
0218     cleaningAlgo_->setFlags(*ebRecHits);
0219     cleaningAlgo_->setFlags(*eeRecHits);
0220   }
0221 
0222   // put the collection of reconstructed hits in the event
0223   LogInfo("EcalRecHitInfo") << "total # EB calibrated rechits: " << ebRecHits->size();
0224   LogInfo("EcalRecHitInfo") << "total # EE calibrated rechits: " << eeRecHits->size();
0225 
0226   evt.put(ebRecHitToken_, std::move(ebRecHits));
0227   evt.put(eeRecHitToken_, std::move(eeRecHits));
0228 }
0229 
0230 void EcalRecHitProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0231   edm::ParameterSetDescription desc;
0232   desc.add<bool>("recoverEEVFE", false);
0233   desc.add<std::string>("EErechitCollection", "EcalRecHitsEE");
0234   desc.add<bool>("recoverEBIsolatedChannels", false);
0235   desc.add<bool>("recoverEBVFE", false);
0236   desc.add<bool>("laserCorrection", true);
0237   desc.add<double>("EBLaserMIN", 0.5);
0238   desc.add<bool>("killDeadChannels", true);
0239   {
0240     std::vector<int> temp1;
0241     temp1.reserve(3);
0242     temp1.push_back(14);
0243     temp1.push_back(78);
0244     temp1.push_back(142);
0245     desc.add<std::vector<int>>("dbStatusToBeExcludedEB", temp1);
0246   }
0247   desc.add<edm::InputTag>("EEuncalibRecHitCollection",
0248                           edm::InputTag("ecalMultiFitUncalibRecHit", "EcalUncalibRecHitsEE"));
0249   {
0250     std::vector<int> temp1;
0251     temp1.reserve(3);
0252     temp1.push_back(14);
0253     temp1.push_back(78);
0254     temp1.push_back(142);
0255     desc.add<std::vector<int>>("dbStatusToBeExcludedEE", temp1);
0256   }
0257   desc.add<double>("EELaserMIN", 0.5);
0258   desc.add<edm::InputTag>("ebFEToBeRecovered", edm::InputTag("ecalDetIdToBeRecovered", "ebFE"));
0259   {
0260     edm::ParameterSetDescription psd0;
0261     psd0.add<double>("e6e2thresh", 0.04);
0262     psd0.add<double>("tightenCrack_e6e2_double", 3);
0263     psd0.add<double>("e4e1Threshold_endcap", 0.3);
0264     psd0.add<double>("tightenCrack_e4e1_single", 3);
0265     psd0.add<double>("tightenCrack_e1_double", 2);
0266     psd0.add<double>("cThreshold_barrel", 4);
0267     psd0.add<double>("e4e1Threshold_barrel", 0.08);
0268     psd0.add<double>("tightenCrack_e1_single", 2);
0269     psd0.add<double>("e4e1_b_barrel", -0.024);
0270     psd0.add<double>("e4e1_a_barrel", 0.04);
0271     psd0.add<double>("ignoreOutOfTimeThresh", 1000000000.0);
0272     psd0.add<double>("cThreshold_endcap", 15);
0273     psd0.add<double>("e4e1_b_endcap", -0.0125);
0274     psd0.add<double>("e4e1_a_endcap", 0.02);
0275     psd0.add<double>("cThreshold_double", 10);
0276     desc.add<edm::ParameterSetDescription>("cleaningConfig", psd0);
0277   }
0278   desc.add<double>("logWarningEtThreshold_EE_FE", 50);
0279   desc.add<edm::InputTag>("eeDetIdToBeRecovered", edm::InputTag("ecalDetIdToBeRecovered", "eeDetId"));
0280   desc.add<bool>("recoverEBFE", true);
0281   desc.add<edm::InputTag>("eeFEToBeRecovered", edm::InputTag("ecalDetIdToBeRecovered", "eeFE"));
0282   desc.add<edm::InputTag>("ebDetIdToBeRecovered", edm::InputTag("ecalDetIdToBeRecovered", "ebDetId"));
0283   desc.add<double>("singleChannelRecoveryThreshold", 8);
0284   desc.add<double>("sum8ChannelRecoveryThreshold", 0.);
0285   desc.add<edm::FileInPath>("bdtWeightFileNoCracks",
0286                             edm::FileInPath("RecoLocalCalo/EcalDeadChannelRecoveryAlgos/data/BDTWeights/"
0287                                             "bdtgAllRH_8GT700MeV_noCracks_ZskimData2017_v1.xml"));
0288   desc.add<edm::FileInPath>("bdtWeightFileCracks",
0289                             edm::FileInPath("RecoLocalCalo/EcalDeadChannelRecoveryAlgos/data/BDTWeights/"
0290                                             "bdtgAllRH_8GT700MeV_onlyCracks_ZskimData2017_v1.xml"));
0291   {
0292     std::vector<std::string> temp1;
0293     temp1.reserve(9);
0294     temp1.push_back("kNoisy");
0295     temp1.push_back("kNNoisy");
0296     temp1.push_back("kFixedG6");
0297     temp1.push_back("kFixedG1");
0298     temp1.push_back("kFixedG0");
0299     temp1.push_back("kNonRespondingIsolated");
0300     temp1.push_back("kDeadVFE");
0301     temp1.push_back("kDeadFE");
0302     temp1.push_back("kNoDataNoTP");
0303     desc.add<std::vector<std::string>>("ChannelStatusToBeExcluded", temp1);
0304   }
0305   desc.add<std::string>("EBrechitCollection", "EcalRecHitsEB");
0306   desc.add<edm::InputTag>("triggerPrimitiveDigiCollection", edm::InputTag("ecalDigis", "EcalTriggerPrimitives"));
0307   desc.add<bool>("recoverEEFE", true);
0308   desc.add<std::string>("singleChannelRecoveryMethod", "NeuralNetworks");
0309   desc.add<double>("EBLaserMAX", 3.0);
0310   {
0311     edm::ParameterSetDescription psd0;
0312     {
0313       std::vector<std::string> temp2;
0314       temp2.reserve(4);
0315       temp2.push_back("kOk");
0316       temp2.push_back("kDAC");
0317       temp2.push_back("kNoLaser");
0318       temp2.push_back("kNoisy");
0319       psd0.add<std::vector<std::string>>("kGood", temp2);
0320     }
0321     {
0322       std::vector<std::string> temp2;
0323       temp2.reserve(3);
0324       temp2.push_back("kFixedG0");
0325       temp2.push_back("kNonRespondingIsolated");
0326       temp2.push_back("kDeadVFE");
0327       psd0.add<std::vector<std::string>>("kNeighboursRecovered", temp2);
0328     }
0329     {
0330       std::vector<std::string> temp2;
0331       temp2.reserve(1);
0332       temp2.push_back("kNoDataNoTP");
0333       psd0.add<std::vector<std::string>>("kDead", temp2);
0334     }
0335     {
0336       std::vector<std::string> temp2;
0337       temp2.reserve(3);
0338       temp2.push_back("kNNoisy");
0339       temp2.push_back("kFixedG6");
0340       temp2.push_back("kFixedG1");
0341       psd0.add<std::vector<std::string>>("kNoisy", temp2);
0342     }
0343     {
0344       std::vector<std::string> temp2;
0345       temp2.reserve(1);
0346       temp2.push_back("kDeadFE");
0347       psd0.add<std::vector<std::string>>("kTowerRecovered", temp2);
0348     }
0349     desc.add<edm::ParameterSetDescription>("flagsMapDBReco", psd0);
0350   }
0351   desc.add<edm::InputTag>("EBuncalibRecHitCollection",
0352                           edm::InputTag("ecalMultiFitUncalibRecHit", "EcalUncalibRecHitsEB"));
0353   desc.add<std::string>("algoRecover", "EcalRecHitWorkerRecover");
0354   desc.add<std::string>("algo", "EcalRecHitWorkerSimple");
0355   desc.add<double>("EELaserMAX", 8.0);
0356   desc.add<double>("logWarningEtThreshold_EB_FE", 50);
0357   desc.add<bool>("recoverEEIsolatedChannels", false);
0358   desc.add<bool>("skipTimeCalib", false);
0359   descriptions.add("ecalRecHit", desc);
0360 }
0361 
0362 #include "FWCore/Framework/interface/MakerMacros.h"
0363 DEFINE_FWK_MODULE(EcalRecHitProducer);