Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-23 03:16:55

0001 #include "FWCore/Framework/interface/stream/EDProducer.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 
0006 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0007 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
0008 #include "DataFormats/Common/interface/ValueMap.h"
0009 #include "RecoEcal/EgammaClusterAlgos/interface/SCEnergyCorrectorSemiParm.h"
0010 
0011 #include <vector>
0012 
0013 //A simple producer which produces a set of corrected superclusters
0014 //Note this is more for testing and development and is not really meant for production
0015 //although its perfectly possible somebody could use it in some prod workflow
0016 //author S. Harper (RAL/CERN)
0017 
0018 class SCEnergyCorrectorProducer : public edm::stream::EDProducer<> {
0019 public:
0020   explicit SCEnergyCorrectorProducer(const edm::ParameterSet& iConfig);
0021 
0022   void beginLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup) override;
0023   void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0024 
0025   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0026 
0027 private:
0028   SCEnergyCorrectorSemiParm energyCorrector_;
0029   const edm::EDGetTokenT<reco::SuperClusterCollection> inputSCToken_;
0030   const bool writeFeatures_;
0031 };
0032 
0033 SCEnergyCorrectorProducer::SCEnergyCorrectorProducer(const edm::ParameterSet& iConfig)
0034     : energyCorrector_(iConfig.getParameterSet("correctorCfg"), consumesCollector()),
0035       inputSCToken_(consumes<reco::SuperClusterCollection>(iConfig.getParameter<edm::InputTag>("inputSCs"))),
0036       writeFeatures_(iConfig.getParameter<bool>("writeFeatures")) {
0037   produces<reco::SuperClusterCollection>();
0038   if (writeFeatures_) {
0039     produces<edm::ValueMap<std::vector<float>>>("features");
0040   }
0041 }
0042 
0043 void SCEnergyCorrectorProducer::beginLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup) {
0044   energyCorrector_.setEventSetup(iSetup);
0045 }
0046 
0047 void SCEnergyCorrectorProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0048   energyCorrector_.setEvent(iEvent);
0049 
0050   auto inputSCs = iEvent.get(inputSCToken_);
0051   auto corrSCs = std::make_unique<reco::SuperClusterCollection>();
0052   std::vector<std::vector<float>> scFeatures;
0053   for (const auto& inputSC : inputSCs) {
0054     corrSCs->push_back(inputSC);
0055     energyCorrector_.modifyObject(corrSCs->back());
0056     if (writeFeatures_) {
0057       scFeatures.emplace_back(energyCorrector_.getRegData(corrSCs->back()));
0058     }
0059   }
0060 
0061   auto scHandle = iEvent.put(std::move(corrSCs));
0062 
0063   if (writeFeatures_) {
0064     auto valMap = std::make_unique<edm::ValueMap<std::vector<float>>>();
0065     edm::ValueMap<std::vector<float>>::Filler filler(*valMap);
0066     filler.insert(scHandle, scFeatures.begin(), scFeatures.end());
0067     filler.fill();
0068     iEvent.put(std::move(valMap), "features");
0069   }
0070 }
0071 
0072 void SCEnergyCorrectorProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0073   edm::ParameterSetDescription desc;
0074   desc.add<edm::ParameterSetDescription>("correctorCfg", SCEnergyCorrectorSemiParm::makePSetDescription());
0075   desc.add<bool>("writeFeatures", false);
0076   desc.add<edm::InputTag>("inputSCs", edm::InputTag("particleFlowSuperClusterECAL"));
0077   descriptions.add("scEnergyCorrectorProducer", desc);
0078 }
0079 
0080 DEFINE_FWK_MODULE(SCEnergyCorrectorProducer);