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 
18 // system include files
19 #include <memory>
20 
21 // user include files
24 
27 
30 
33 
34 #include "TLorentzVector.h"
36 
38 
39 //
40 // class declaration
41 //
42 
43 template <typename T>
45 public:
46  explicit EGMEnergyVarProducer(const edm::ParameterSet &iConfig):
47  srcRaw_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("srcRaw"))),
48  srcCorr_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("srcCorr")))
49  {
50  produces<edm::ValueMap<float>>("eCorr");
51  }
52  ~EGMEnergyVarProducer() override {};
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
55 
56 private:
57  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
58 
59  // ----------member data ---------------------------
60 
63 };
64 
65 //
66 // constants, enums and typedefs
67 //
68 
69 
70 //
71 // static data member definitions
72 //
73 
74 //
75 // member functions
76 //
77 
78 // ------------ method called to produce the data ------------
79 template <typename T>
80 void
82 {
84  iEvent.getByToken(srcRaw_, srcRaw);
86  iEvent.getByToken(srcCorr_, srcCorr);
87 
88  unsigned nSrcRaw = srcRaw->size();
89  unsigned nSrcCorr = srcCorr->size();
90 
91  std::vector<float> eCorr(nSrcCorr,-1);
92 
93  for (unsigned int ir = 0; ir<nSrcRaw; ir++){
94  auto egm_raw = srcRaw->ptrAt(ir);
95  for (unsigned int ic = 0; ic<nSrcCorr; ic++){
96  auto egm_corr = srcCorr->ptrAt(ic);
97  if(matchByCommonParentSuperClusterRef(*egm_raw,*egm_corr)){
98  eCorr[ir] = egm_corr->energy()/egm_raw->energy();
99  break;
100  }
101  }
102  }
103 
104  std::unique_ptr<edm::ValueMap<float>> eCorrV(new edm::ValueMap<float>());
105  edm::ValueMap<float>::Filler fillerCorr(*eCorrV);
106  fillerCorr.insert(srcRaw,eCorr.begin(),eCorr.end());
107  fillerCorr.fill();
108  iEvent.put(std::move(eCorrV),"eCorr");
109 
110 }
111 
112 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
113 template <typename T>
114 void
117  desc.add<edm::InputTag>("srcRaw")->setComment("input raw physics object collection");
118  desc.add<edm::InputTag>("srcCorr")->setComment("input corrected physics object collection");
119  std::string modname;
120  if (typeid(T) == typeid(pat::Electron)) modname+="Electron";
121  else if (typeid(T) == typeid(pat::Photon)) modname+="Photon";
122  modname+="EnergyVarProducer";
123  descriptions.add(modname,desc);
124 }
125 
128 
129 //define this as a plug-in
Analysis-level Photon class.
Definition: Photon.h:47
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
edm::EDGetTokenT< edm::View< T > > srcRaw_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
EGMEnergyVarProducer< pat::Photon > PhotonEnergyVarProducer
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
bool matchByCommonParentSuperClusterRef(const C1 &c1, const C2 &c2)
Definition: MatchingUtils.h:20
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:230
EGMEnergyVarProducer< pat::Electron > ElectronEnergyVarProducer
EGMEnergyVarProducer(const edm::ParameterSet &iConfig)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Analysis-level electron class.
Definition: Electron.h:52
edm::EDGetTokenT< edm::View< T > > srcCorr_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
long double T
def move(src, dest)
Definition: eostools.py:510