CMS 3D CMS Logo

EGMEnergyVarProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PhysicsTools/NanoAOD
4 // Class: EGMEnergyVarProducer
5 //
11 //
12 // Original Author: Emanuele Di Marco
13 // Created: Wed, 06 Sep 2017 12:34:38 GMT
14 //
15 //
16 
17 // system include files
18 #include <memory>
19 
20 // user include files
23 
26 
29 
32 
33 #include "TLorentzVector.h"
35 
37 
38 //
39 // class declaration
40 //
41 
42 template <typename T>
44 public:
45  explicit EGMEnergyVarProducer(const edm::ParameterSet& iConfig)
46  : srcRaw_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("srcRaw"))),
47  srcCorr_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("srcCorr"))) {
48  produces<edm::ValueMap<float>>("eCorr");
49  }
50  ~EGMEnergyVarProducer() override{};
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54 private:
55  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
56 
57  // ----------member data ---------------------------
58 
61 };
62 
63 //
64 // constants, enums and typedefs
65 //
66 
67 //
68 // static data member definitions
69 //
70 
71 //
72 // member functions
73 //
74 
75 // ------------ method called to produce the data ------------
76 template <typename T>
79  iEvent.getByToken(srcRaw_, srcRaw);
80  edm::Handle<edm::View<T>> srcCorr;
81  iEvent.getByToken(srcCorr_, srcCorr);
82 
83  unsigned nSrcRaw = srcRaw->size();
84  unsigned nSrcCorr = srcCorr->size();
85 
86  std::vector<float> eCorr(nSrcCorr, -1);
87 
88  for (unsigned int ir = 0; ir < nSrcRaw; ir++) {
89  auto egm_raw = srcRaw->ptrAt(ir);
90  for (unsigned int ic = 0; ic < nSrcCorr; ic++) {
91  auto egm_corr = srcCorr->ptrAt(ic);
92  if (matchByCommonParentSuperClusterRef(*egm_raw, *egm_corr)) {
93  eCorr[ir] = egm_corr->energy() / egm_raw->energy();
94  break;
95  }
96  }
97  }
98 
99  std::unique_ptr<edm::ValueMap<float>> eCorrV(new edm::ValueMap<float>());
100  edm::ValueMap<float>::Filler fillerCorr(*eCorrV);
101  fillerCorr.insert(srcRaw, eCorr.begin(), eCorr.end());
102  fillerCorr.fill();
103  iEvent.put(std::move(eCorrV), "eCorr");
104 }
105 
106 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
107 template <typename T>
110  desc.add<edm::InputTag>("srcRaw")->setComment("input raw physics object collection");
111  desc.add<edm::InputTag>("srcCorr")->setComment("input corrected physics object collection");
113  if (typeid(T) == typeid(pat::Electron))
114  modname += "Electron";
115  else if (typeid(T) == typeid(pat::Photon))
116  modname += "Photon";
117  modname += "EnergyVarProducer";
118  descriptions.add(modname, desc);
119 }
120 
123 
124 //define this as a plug-in
EGMEnergyVarProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: EGMEnergyVarProducer.cc:108
edm::StreamID
Definition: StreamID.h:30
matchByCommonParentSuperClusterRef
bool matchByCommonParentSuperClusterRef(const C1 &c1, const C2 &c2)
Definition: MatchingUtils.h:21
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
sistrip::View
View
Definition: ConstantsForView.h:26
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
Photon.h
pat::Photon
Analysis-level Photon class.
Definition: Photon.h:46
edm::helper::Filler::fill
void fill()
Definition: ValueMap.h:65
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EGMEnergyVarProducer::~EGMEnergyVarProducer
~EGMEnergyVarProducer() override
Definition: EGMEnergyVarProducer.cc:50
EGMEnergyVarProducer::srcRaw_
edm::EDGetTokenT< edm::View< T > > srcRaw_
Definition: EGMEnergyVarProducer.cc:59
edm::Handle
Definition: AssociativeIterator.h:50
ElectronEnergyVarProducer
EGMEnergyVarProducer< pat::Electron > ElectronEnergyVarProducer
Definition: EGMEnergyVarProducer.cc:121
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EGMEnergyVarProducer::srcCorr_
edm::EDGetTokenT< edm::View< T > > srcCorr_
Definition: EGMEnergyVarProducer.cc:60
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
iEvent
int iEvent
Definition: GenABIO.cc:224
MatchingUtils.h
EGMEnergyVarProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: EGMEnergyVarProducer.cc:77
PhotonEnergyVarProducer
EGMEnergyVarProducer< pat::Photon > PhotonEnergyVarProducer
Definition: EGMEnergyVarProducer.cc:122
edm::EventSetup
Definition: EventSetup.h:57
EGMEnergyVarProducer::EGMEnergyVarProducer
EGMEnergyVarProducer(const edm::ParameterSet &iConfig)
Definition: EGMEnergyVarProducer.cc:45
EGMEnergyVarProducer
Definition: EGMEnergyVarProducer.cc:43
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
electrons_cff.eCorr
eCorr
Definition: electrons_cff.py:420
T
long double T
Definition: Basic3DVectorLD.h:48
edm::ValueMap< float >
Electron.h
edm::helper::Filler
Definition: ValueMap.h:22
pat::Electron
Analysis-level electron class.
Definition: Electron.h:51
View.h
ParameterSet.h
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:126
EDProducer.h
edm::Event
Definition: Event.h:73
StreamID.h
timingPdfMaker.modname
modname
Definition: timingPdfMaker.py:218
edm::InputTag
Definition: InputTag.h:15