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 
54 
55  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
57 
58 private:
59  void beginJob() override;
60  void analyze(const edm::Event &, const edm::EventSetup &) override;
61 
62  // ----------member data ---------------------------
63 
64  // input tags
70  std::vector<edm::EDGetTokenT<edm::ValueMap<double> > > isoValTokens_;
72 
73  // debug
75 
76  // histograms
77  TH1F *h1_pt_;
78  TH1F *h1_pt_veto_;
79  TH1F *h1_pt_loose_;
81  TH1F *h1_pt_tight_;
82  TH1F *h1_pt_trig_;
84 };
85 
86 //
87 // static data member definitions
88 //
89 
90 //
91 // constructors and destructor
92 //
94  // get input parameters
95  electronsToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronsInputTag"));
96  conversionsToken_ = consumes<reco::ConversionCollection>(iConfig.getParameter<edm::InputTag>("conversionsInputTag"));
97  beamSpotToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotInputTag"));
98  rhoIsoToken_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rhoIsoInputTag"));
99  primaryVertexToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertexInputTag"));
100  isoValTokens_ =
101  edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >("isoValInputTags"),
102  [this](edm::InputTag const &tag) { return consumes<edm::ValueMap<double> >(tag); });
104  "EAtarget"); //EleEANoCorr, EleEAData2011, EleEASummer11MC,EleEAFall11MC, EleEAData2012/
105 
106  // debug
107  printDebug_ = iConfig.getParameter<bool>("printDebug");
108 
109  // output histograms
111 
112  h1_pt_ = fs->make<TH1F>("h1_pt", "pt", 100, 0.0, 100.0);
113  h1_pt_veto_ = fs->make<TH1F>("h1_pt_veto", "pt (veto)", 100, 0.0, 100.0);
114  h1_pt_loose_ = fs->make<TH1F>("h1_pt_loose", "pt (loose)", 100, 0.0, 100.0);
115  h1_pt_medium_ = fs->make<TH1F>("h1_pt_medium", "pt (medium)", 100, 0.0, 100.0);
116  h1_pt_tight_ = fs->make<TH1F>("h1_pt_tight", "pt (tight)", 100, 0.0, 100.0);
117  h1_pt_trig_ = fs->make<TH1F>("h1_pt_trig", "pt (trig)", 100, 0.0, 100.0);
118  h1_pt_fbremeopin_ = fs->make<TH1F>("h1_pt_fbremeopin", "pt (fbremeopin)", 100, 0.0, 100.0);
119 }
120 
121 //
122 // member functions
123 //
124 
125 // ------------ method called for each event ------------
127  // electrons
129  iEvent.getByToken(electronsToken_, els_h);
130 
131  // conversions
133  iEvent.getByToken(conversionsToken_, conversions_h);
134 
135  // iso deposits
136  IsoDepositVals isoVals(isoValTokens_.size());
137  for (size_t j = 0; j < isoValTokens_.size(); ++j) {
138  iEvent.getByToken(isoValTokens_[j], isoVals[j]);
139  }
140 
141  // beam spot
142  edm::Handle<reco::BeamSpot> beamspot_h;
143  iEvent.getByToken(beamSpotToken_, beamspot_h);
144  const reco::BeamSpot &beamSpot = *(beamspot_h.product());
145 
146  // vertices
148  iEvent.getByToken(primaryVertexToken_, vtx_h);
149 
150  // rho for isolation
151  edm::Handle<double> rhoIso_h;
152  iEvent.getByToken(rhoIsoToken_, rhoIso_h);
153  double rhoIso = *(rhoIso_h.product());
154 
155  // loop on electrons
156  unsigned int n = els_h->size();
157  for (unsigned int i = 0; i < n; ++i) {
158  // get reference to electron
159  reco::GsfElectronRef ele(els_h, i);
160 
161  //
162  // get particle flow isolation
163  //
164 
165  double iso_ch = (*(isoVals)[0])[ele];
166  double iso_em = (*(isoVals)[1])[ele];
167  double iso_nh = (*(isoVals)[2])[ele];
168 
169  //
170  // test ID
171  //
172 
173  // working points
175  EgammaCutBasedEleId::VETO, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso, EAtarget);
177  EgammaCutBasedEleId::LOOSE, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso, EAtarget);
178  bool medium = EgammaCutBasedEleId::PassWP(
179  EgammaCutBasedEleId::MEDIUM, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso, EAtarget);
180  bool tight = EgammaCutBasedEleId::PassWP(
181  EgammaCutBasedEleId::TIGHT, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso, EAtarget);
182 
183  // eop/fbrem cuts for extra tight ID
184  bool fbremeopin = EgammaCutBasedEleId::PassEoverPCuts(ele);
185 
186  // cuts to match tight trigger requirements
188 
189  // for 2011 WP70 trigger
191 
192  //
193  // fill histograms
194  //
195 
196  h1_pt_->Fill(ele->pt());
197  if (veto)
198  h1_pt_veto_->Fill(ele->pt());
199  if (loose)
200  h1_pt_loose_->Fill(ele->pt());
201  if (medium)
202  h1_pt_medium_->Fill(ele->pt());
203  if (tight)
204  h1_pt_tight_->Fill(ele->pt());
205  if (trigtight)
206  h1_pt_trig_->Fill(ele->pt());
207  if (fbremeopin)
208  h1_pt_fbremeopin_->Fill(ele->pt());
209 
210  //
211  // print decisions
212  //
213 
214  if (printDebug_) {
215  printf("%u %u %llu : ", iEvent.id().run(), iEvent.luminosityBlock(), iEvent.id().event());
216  printf("veto(%i), ", veto);
217  printf("loose(%i), ", loose);
218  printf("medium(%i), ", medium);
219  printf("tight(%i), ", tight);
220  printf("trigtight(%i), ", trigtight);
221  printf("trigwp70(%i), ", trigwp70);
222  printf("fbremeopin(%i)\n", fbremeopin);
223  }
224  }
225 }
226 
227 // ------------ method called once each job just before starting event loop ------------
229  if (EAtargetToken_ == "EleEANoCorr")
231  else if (EAtargetToken_ == "EleEAData2011")
233  else if (EAtargetToken_ == "EleEASummer11MC")
235  else if (EAtargetToken_ == "EleEAFall11MC")
237  else if (EAtargetToken_ == "EleEAData2012")
239  else
241 }
242 
243 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
245  //The following says we do not know what parameters are allowed so do no validation
246  // Please change this to state exactly what you do use, even if it is no parameters
248  desc.setUnknown();
249  descriptions.addDefault(desc);
250 }
251 
252 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
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_
edm::EDGetTokenT< double > rhoIsoToken_
std::vector< edm::Handle< edm::ValueMap< reco::IsoDeposit > > > IsoDepositMaps