Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-26 00:02:52

0001 #include "CommonTools/CandAlgos/interface/ModifyObjectValueBase.h"
0002 #include "FWCore/Utilities/interface/InputTag.h"
0003 #include "FWCore/Utilities/interface/EDGetToken.h"
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "DataFormats/Common/interface/Handle.h"
0007 #include "Geometry/CaloTopology/interface/CaloTopology.h"
0008 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0009 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0010 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h"
0011 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0012 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0013 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0014 
0015 #include <vdt/vdtMath.h>
0016 
0017 //this modifier fills variables where not present in CMSSW_8X
0018 //use case is when reading older 80X samples in newer releases, aka legacy
0019 
0020 class EG8XObjectUpdateModifier : public ModifyObjectValueBase {
0021 public:
0022   EG8XObjectUpdateModifier(const edm::ParameterSet& conf, edm::ConsumesCollector& cc);
0023   ~EG8XObjectUpdateModifier() override {}
0024 
0025   void setEvent(const edm::Event&) final;
0026   void setEventContent(const edm::EventSetup&) final;
0027 
0028   void modifyObject(reco::GsfElectron& ele) const final;
0029   void modifyObject(reco::Photon& pho) const final;
0030 
0031   void modifyObject(pat::Electron& ele) const final { return modifyObject(static_cast<reco::GsfElectron&>(ele)); }
0032   void modifyObject(pat::Photon& pho) const final { return modifyObject(static_cast<reco::Photon&>(pho)); }
0033 
0034 private:
0035   std::pair<int, bool> getSaturationInfo(const reco::SuperCluster& superClus) const;
0036 
0037   CaloTopology const* caloTopo_ = nullptr;
0038   EcalRecHitCollection const* ecalRecHitsEB_ = nullptr;
0039   EcalRecHitCollection const* ecalRecHitsEE_ = nullptr;
0040 
0041   edm::ESGetToken<CaloTopology, CaloTopologyRecord> caloTopoToken_;
0042   edm::EDGetTokenT<EcalRecHitCollection> ecalRecHitsEBToken_;
0043   edm::EDGetTokenT<EcalRecHitCollection> ecalRecHitsEEToken_;
0044 };
0045 
0046 EG8XObjectUpdateModifier::EG8XObjectUpdateModifier(const edm::ParameterSet& conf, edm::ConsumesCollector& cc)
0047     : ModifyObjectValueBase(conf),
0048       caloTopoToken_{cc.esConsumes()},
0049       ecalRecHitsEBToken_(cc.consumes(conf.getParameter<edm::InputTag>("ecalRecHitsEB"))),
0050       ecalRecHitsEEToken_(cc.consumes(conf.getParameter<edm::InputTag>("ecalRecHitsEE"))) {}
0051 
0052 void EG8XObjectUpdateModifier::setEvent(const edm::Event& iEvent) {
0053   ecalRecHitsEB_ = &iEvent.get(ecalRecHitsEBToken_);
0054   ecalRecHitsEE_ = &iEvent.get(ecalRecHitsEEToken_);
0055 }
0056 
0057 void EG8XObjectUpdateModifier::setEventContent(const edm::EventSetup& iSetup) {
0058   caloTopo_ = &iSetup.getData(caloTopoToken_);
0059 }
0060 
0061 void EG8XObjectUpdateModifier::modifyObject(reco::GsfElectron& ele) const {
0062   const reco::CaloCluster& seedClus = *(ele.superCluster()->seed());
0063   const EcalRecHitCollection* ecalRecHits = ele.isEB() ? ecalRecHitsEB_ : ecalRecHitsEE_;
0064 
0065   auto full5x5ShowerShapes = ele.full5x5_showerShape();
0066   full5x5ShowerShapes.e2x5Left = noZS::EcalClusterTools::e2x5Left(seedClus, ecalRecHits, caloTopo_);
0067   full5x5ShowerShapes.e2x5Right = noZS::EcalClusterTools::e2x5Right(seedClus, ecalRecHits, caloTopo_);
0068   full5x5ShowerShapes.e2x5Top = noZS::EcalClusterTools::e2x5Top(seedClus, ecalRecHits, caloTopo_);
0069   full5x5ShowerShapes.e2x5Bottom = noZS::EcalClusterTools::e2x5Bottom(seedClus, ecalRecHits, caloTopo_);
0070   ele.full5x5_setShowerShape(full5x5ShowerShapes);
0071 
0072   auto showerShapes = ele.showerShape();
0073   showerShapes.e2x5Left = EcalClusterTools::e2x5Left(seedClus, ecalRecHits, caloTopo_);
0074   showerShapes.e2x5Right = EcalClusterTools::e2x5Right(seedClus, ecalRecHits, caloTopo_);
0075   showerShapes.e2x5Top = EcalClusterTools::e2x5Top(seedClus, ecalRecHits, caloTopo_);
0076   showerShapes.e2x5Bottom = EcalClusterTools::e2x5Bottom(seedClus, ecalRecHits, caloTopo_);
0077   ele.setShowerShape(showerShapes);
0078 
0079   reco::GsfElectron::SaturationInfo eleSatInfo;
0080   auto satInfo = getSaturationInfo(*ele.superCluster());
0081   eleSatInfo.nSaturatedXtals = satInfo.first;
0082   eleSatInfo.isSeedSaturated = satInfo.second;
0083   ele.setSaturationInfo(eleSatInfo);
0084 }
0085 
0086 void EG8XObjectUpdateModifier::modifyObject(reco::Photon& pho) const {
0087   reco::Photon::SaturationInfo phoSatInfo;
0088   auto satInfo = getSaturationInfo(*pho.superCluster());
0089   phoSatInfo.nSaturatedXtals = satInfo.first;
0090   phoSatInfo.isSeedSaturated = satInfo.second;
0091   pho.setSaturationInfo(phoSatInfo);
0092 }
0093 
0094 std::pair<int, bool> EG8XObjectUpdateModifier::getSaturationInfo(const reco::SuperCluster& superClus) const {
0095   bool isEB = superClus.seed()->seed().subdetId() == EcalBarrel;
0096   const auto& ecalRecHits = isEB ? *ecalRecHitsEB_ : *ecalRecHitsEE_;
0097 
0098   int nrSatCrys = 0;
0099   bool seedSaturated = false;
0100   const auto& hitsAndFractions = superClus.seed()->hitsAndFractions();
0101   for (const auto& hitFractionPair : hitsAndFractions) {
0102     auto ecalRecHitIt = ecalRecHits.find(hitFractionPair.first);
0103     if (ecalRecHitIt != ecalRecHits.end() && ecalRecHitIt->checkFlag(EcalRecHit::Flags::kSaturated)) {
0104       nrSatCrys++;
0105       if (hitFractionPair.first == superClus.seed()->seed())
0106         seedSaturated = true;
0107     }
0108   }
0109   return {nrSatCrys, seedSaturated};
0110 }
0111 
0112 DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, EG8XObjectUpdateModifier, "EG8XObjectUpdateModifier");