CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
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
Analysis-level Photon class.
Definition: Photon.h:46
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EDGetTokenT< edm::View< T > > srcRaw_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
EGMEnergyVarProducer< pat::Photon > PhotonEnergyVarProducer
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
bool matchByCommonParentSuperClusterRef(const C1 &c1, const C2 &c2)
Definition: MatchingUtils.h:21
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:224
EGMEnergyVarProducer< pat::Electron > ElectronEnergyVarProducer
def move
Definition: eostools.py:511
EGMEnergyVarProducer(const edm::ParameterSet &iConfig)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Analysis-level electron class.
Definition: Electron.h:51
edm::EDGetTokenT< edm::View< T > > srcCorr_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
long double T