CMS 3D CMS Logo

EGammaCutBasedEleIdAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EGammaCutBasedEleIdAnalyzer
4 // Class: EGammaCutBasedEleIdAnalyzer
5 //
13 //
14 // Original Author: Dave Evans,510 1-015,+41227679496,
15 // Created: Tue Apr 10 11:17:29 CEST 2012
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
40 
41 #include <TFile.h>
42 #include <TH1F.h>
43 
44 //
45 // class declaration
46 //
47 
49 public:
50  typedef std::vector<edm::Handle<edm::ValueMap<reco::IsoDeposit> > > IsoDepositMaps;
51  typedef std::vector<edm::Handle<edm::ValueMap<double> > > IsoDepositVals;
52 
55 
56  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
58 
59 private:
60  void beginJob() override;
61  void analyze(const edm::Event &, const edm::EventSetup &) override;
62  void endJob() override;
63 
64  /*
65  void beginRun(edm::Run const &, edm::EventSetup const &) override;
66  void endRun(edm::Run const &, edm::EventSetup const &) override;
67  void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override;
68  void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override;
69  */
70  // ----------member data ---------------------------
71 
72  // input tags
78  std::vector<edm::EDGetTokenT<edm::ValueMap<double> > > isoValTokens_;
80 
81  // debug
83 
84  // histograms
85  TH1F *h1_pt_;
86  TH1F *h1_pt_veto_;
87  TH1F *h1_pt_loose_;
89  TH1F *h1_pt_tight_;
90  TH1F *h1_pt_trig_;
92 };
93 
94 //
95 // static data member definitions
96 //
97 
98 //
99 // constructors and destructor
100 //
102  // get input parameters
103  electronsToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronsInputTag"));
104  conversionsToken_ = consumes<reco::ConversionCollection>(iConfig.getParameter<edm::InputTag>("conversionsInputTag"));
105  beamSpotToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotInputTag"));
106  rhoIsoToken_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rhoIsoInputTag"));
107  primaryVertexToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertexInputTag"));
108  isoValTokens_ =
109  edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >("isoValInputTags"),
110  [this](edm::InputTag const &tag) { return consumes<edm::ValueMap<double> >(tag); });
112  "EAtarget"); //EleEANoCorr, EleEAData2011, EleEASummer11MC,EleEAFall11MC, EleEAData2012/
113 
114  // debug
115  printDebug_ = iConfig.getParameter<bool>("printDebug");
116 
117  // output histograms
119 
120  h1_pt_ = fs->make<TH1F>("h1_pt", "pt", 100, 0.0, 100.0);
121  h1_pt_veto_ = fs->make<TH1F>("h1_pt_veto", "pt (veto)", 100, 0.0, 100.0);
122  h1_pt_loose_ = fs->make<TH1F>("h1_pt_loose", "pt (loose)", 100, 0.0, 100.0);
123  h1_pt_medium_ = fs->make<TH1F>("h1_pt_medium", "pt (medium)", 100, 0.0, 100.0);
124  h1_pt_tight_ = fs->make<TH1F>("h1_pt_tight", "pt (tight)", 100, 0.0, 100.0);
125  h1_pt_trig_ = fs->make<TH1F>("h1_pt_trig", "pt (trig)", 100, 0.0, 100.0);
126  h1_pt_fbremeopin_ = fs->make<TH1F>("h1_pt_fbremeopin", "pt (fbremeopin)", 100, 0.0, 100.0);
127 }
128 
130  // do anything here that needs to be done at desctruction time
131  // (e.g. close files, deallocate resources etc.)
132 }
133 
134 //
135 // member functions
136 //
137 
138 // ------------ method called for each event ------------
140  // electrons
142  iEvent.getByToken(electronsToken_, els_h);
143 
144  // conversions
146  iEvent.getByToken(conversionsToken_, conversions_h);
147 
148  // iso deposits
149  IsoDepositVals isoVals(isoValTokens_.size());
150  for (size_t j = 0; j < isoValTokens_.size(); ++j) {
151  iEvent.getByToken(isoValTokens_[j], isoVals[j]);
152  }
153 
154  // beam spot
155  edm::Handle<reco::BeamSpot> beamspot_h;
156  iEvent.getByToken(beamSpotToken_, beamspot_h);
157  const reco::BeamSpot &beamSpot = *(beamspot_h.product());
158 
159  // vertices
161  iEvent.getByToken(primaryVertexToken_, vtx_h);
162 
163  // rho for isolation
164  edm::Handle<double> rhoIso_h;
165  iEvent.getByToken(rhoIsoToken_, rhoIso_h);
166  double rhoIso = *(rhoIso_h.product());
167 
168  // loop on electrons
169  unsigned int n = els_h->size();
170  for (unsigned int i = 0; i < n; ++i) {
171  // get reference to electron
172  reco::GsfElectronRef ele(els_h, i);
173 
174  //
175  // get particle flow isolation
176  //
177 
178  double iso_ch = (*(isoVals)[0])[ele];
179  double iso_em = (*(isoVals)[1])[ele];
180  double iso_nh = (*(isoVals)[2])[ele];
181 
182  //
183  // test ID
184  //
185 
186  // working points
188  EgammaCutBasedEleId::VETO, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso, EAtarget);
190  EgammaCutBasedEleId::LOOSE, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso, EAtarget);
191  bool medium = EgammaCutBasedEleId::PassWP(
192  EgammaCutBasedEleId::MEDIUM, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso, EAtarget);
193  bool tight = EgammaCutBasedEleId::PassWP(
194  EgammaCutBasedEleId::TIGHT, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso, EAtarget);
195 
196  // eop/fbrem cuts for extra tight ID
197  bool fbremeopin = EgammaCutBasedEleId::PassEoverPCuts(ele);
198 
199  // cuts to match tight trigger requirements
201 
202  // for 2011 WP70 trigger
204 
205  //
206  // fill histograms
207  //
208 
209  h1_pt_->Fill(ele->pt());
210  if (veto)
211  h1_pt_veto_->Fill(ele->pt());
212  if (loose)
213  h1_pt_loose_->Fill(ele->pt());
214  if (medium)
215  h1_pt_medium_->Fill(ele->pt());
216  if (tight)
217  h1_pt_tight_->Fill(ele->pt());
218  if (trigtight)
219  h1_pt_trig_->Fill(ele->pt());
220  if (fbremeopin)
221  h1_pt_fbremeopin_->Fill(ele->pt());
222 
223  //
224  // print decisions
225  //
226 
227  if (printDebug_) {
228  printf("%u %u %llu : ", iEvent.id().run(), iEvent.luminosityBlock(), iEvent.id().event());
229  printf("veto(%i), ", veto);
230  printf("loose(%i), ", loose);
231  printf("medium(%i), ", medium);
232  printf("tight(%i), ", tight);
233  printf("trigtight(%i), ", trigtight);
234  printf("trigwp70(%i), ", trigwp70);
235  printf("fbremeopin(%i)\n", fbremeopin);
236  }
237  }
238 }
239 
240 // ------------ method called once each job just before starting event loop ------------
242  if (EAtargetToken_ == "EleEANoCorr")
244  else if (EAtargetToken_ == "EleEAData2011")
246  else if (EAtargetToken_ == "EleEASummer11MC")
248  else if (EAtargetToken_ == "EleEAFall11MC")
250  else if (EAtargetToken_ == "EleEAData2012")
252  else
254 }
255 
256 // ------------ method called once each job just after ending the event loop ------------
258 /*
259 // ------------ method called when starting to processes a run ------------
260 void EGammaCutBasedEleIdAnalyzer::beginRun(edm::Run const &, edm::EventSetup const &) {}
261 
262 // ------------ method called when ending the processing of a run ------------
263 void EGammaCutBasedEleIdAnalyzer::endRun(edm::Run const &, edm::EventSetup const &) {}
264 
265 // ------------ method called when starting to processes a luminosity block ------------
266 void EGammaCutBasedEleIdAnalyzer::beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) {}
267 
268 // ------------ method called when ending the processing of a luminosity block ------------
269 void EGammaCutBasedEleIdAnalyzer::endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) {}
270 */
271 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
273  //The following says we do not know what parameters are allowed so do no validation
274  // Please change this to state exactly what you do use, even if it is no parameters
276  desc.setUnknown();
277  descriptions.addDefault(desc);
278 }
279 
280 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void analyze(const edm::Event &, const edm::EventSetup &) override
bool PassWP(const WorkingPoint workingPoint, const reco::GsfElectronRef &ele, const edm::Handle< reco::ConversionCollection > &conversions, const reco::BeamSpot &beamspot, const edm::Handle< reco::VertexCollection > &vtxs, const double &iso_ch, const double &iso_em, const double &iso_nh, const double &rho, ElectronEffectiveArea::ElectronEffectiveAreaTarget EAtarget)
T const * product() const
Definition: Handle.h:70
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
EGammaCutBasedEleIdAnalyzer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< reco::ConversionCollection > conversionsToken_
void addDefault(ParameterSetDescription const &psetDescription)
bool PassTriggerCuts(const TriggerWorkingPoint triggerWorkingPoint, const reco::GsfElectronRef &ele)
edm::EDGetTokenT< reco::GsfElectronCollection > electronsToken_
bool PassEoverPCuts(const reco::GsfElectronRef &ele)
ElectronEffectiveArea::ElectronEffectiveAreaTarget EAtarget
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< edm::Handle< edm::ValueMap< double > > > IsoDepositVals
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< reco::VertexCollection > primaryVertexToken_
std::vector< edm::EDGetTokenT< edm::ValueMap< double > > > isoValTokens_
constexpr auto loose
edm::EDGetTokenT< double > rhoIsoToken_
std::vector< edm::Handle< edm::ValueMap< reco::IsoDeposit > > > IsoDepositMaps