CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
20 // system include files
21 #include <memory>
22 
23 // user include files
40 
41 #include <TFile.h>
42 #include <TH1F.h>
43 
44 //
45 // class declaration
46 //
47 
49  public:
50 
51  typedef std::vector< edm::Handle< edm::ValueMap<reco::IsoDeposit> > > IsoDepositMaps;
52  typedef std::vector< edm::Handle< edm::ValueMap<double> > > IsoDepositVals;
53 
54 
57 
58  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
59 
60 
61  private:
62  virtual void beginJob() ;
63  virtual void analyze(const edm::Event&, const edm::EventSetup&);
64  virtual void endJob() ;
65 
66  virtual void beginRun(edm::Run const&, edm::EventSetup const&);
67  virtual void endRun(edm::Run const&, edm::EventSetup const&);
68  virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
69  virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
70 
71  // ----------member data ---------------------------
72 
73  // input tags
79  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 //
96 // static data member definitions
97 //
98 
99 //
100 // constructors and destructor
101 //
103 {
104 
105  // get input parameters
106  electronsToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronsInputTag"));
107  conversionsToken_ = consumes<reco::ConversionCollection>(iConfig.getParameter<edm::InputTag>("conversionsInputTag"));
108  beamSpotToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotInputTag"));
109  rhoIsoToken_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rhoIsoInputTag"));
110  primaryVertexToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertexInputTag"));
111  isoValTokens_ = edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >("isoValInputTags"), [this](edm::InputTag const & tag){return consumes<edm::ValueMap<double> >(tag);});
112 
113  // debug
114  printDebug_ = iConfig.getParameter<bool>("printDebug");
115 
116  // output histograms
118 
119  h1_pt_ = fs->make<TH1F>("h1_pt", "pt", 100, 0.0, 100.0);
120  h1_pt_veto_ = fs->make<TH1F>("h1_pt_veto", "pt (veto)", 100, 0.0, 100.0);
121  h1_pt_loose_ = fs->make<TH1F>("h1_pt_loose", "pt (loose)", 100, 0.0, 100.0);
122  h1_pt_medium_ = fs->make<TH1F>("h1_pt_medium", "pt (medium)", 100, 0.0, 100.0);
123  h1_pt_tight_ = fs->make<TH1F>("h1_pt_tight", "pt (tight)", 100, 0.0, 100.0);
124  h1_pt_trig_ = fs->make<TH1F>("h1_pt_trig", "pt (trig)", 100, 0.0, 100.0);
125  h1_pt_fbremeopin_ = fs->make<TH1F>("h1_pt_fbremeopin", "pt (fbremeopin)", 100, 0.0, 100.0);
126 
127 }
128 
129 
131 {
132 
133  // do anything here that needs to be done at desctruction time
134  // (e.g. close files, deallocate resources etc.)
135 
136 }
137 
138 
139 //
140 // member functions
141 //
142 
143 // ------------ method called for each event ------------
144  void
146 {
147  // electrons
149  iEvent.getByToken(electronsToken_, els_h);
150 
151  // conversions
153  iEvent.getByToken(conversionsToken_, conversions_h);
154 
155  // iso deposits
156  IsoDepositVals isoVals(isoValTokens_.size());
157  for (size_t j = 0; j < isoValTokens_.size(); ++j) {
158  iEvent.getByToken(isoValTokens_[j], isoVals[j]);
159  }
160 
161  // beam spot
162  edm::Handle<reco::BeamSpot> beamspot_h;
163  iEvent.getByToken(beamSpotToken_, beamspot_h);
164  const reco::BeamSpot &beamSpot = *(beamspot_h.product());
165 
166  // vertices
168  iEvent.getByToken(primaryVertexToken_, vtx_h);
169 
170  // rho for isolation
171  edm::Handle<double> rhoIso_h;
172  iEvent.getByToken(rhoIsoToken_, rhoIso_h);
173  double rhoIso = *(rhoIso_h.product());
174 
175  // loop on electrons
176  unsigned int n = els_h->size();
177  for(unsigned int i = 0; i < n; ++i) {
178 
179  // get reference to electron
180  reco::GsfElectronRef ele(els_h, i);
181 
182  //
183  // get particle flow isolation
184  //
185 
186  double iso_ch = (*(isoVals)[0])[ele];
187  double iso_em = (*(isoVals)[1])[ele];
188  double iso_nh = (*(isoVals)[2])[ele];
189 
190  //
191  // test ID
192  //
193 
194  // working points
195  bool veto = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::VETO, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso);
196  bool loose = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::LOOSE, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso);
197  bool medium = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::MEDIUM, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso);
198  bool tight = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::TIGHT, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso);
199 
200  // eop/fbrem cuts for extra tight ID
201  bool fbremeopin = EgammaCutBasedEleId::PassEoverPCuts(ele);
202 
203  // cuts to match tight trigger requirements
205 
206  // for 2011 WP70 trigger
208 
209  //
210  // fill histograms
211  //
212 
213  h1_pt_->Fill(ele->pt());
214  if (veto) h1_pt_veto_ ->Fill(ele->pt());
215  if (loose) h1_pt_loose_ ->Fill(ele->pt());
216  if (medium) h1_pt_medium_ ->Fill(ele->pt());
217  if (tight) h1_pt_tight_ ->Fill(ele->pt());
218  if (trigtight) h1_pt_trig_ ->Fill(ele->pt());
219  if (fbremeopin) h1_pt_fbremeopin_ ->Fill(ele->pt());
220 
221  //
222  // print decisions
223  //
224 
225  if (printDebug_) {
226  printf("%u %u %u : ", iEvent.id().run(), iEvent.luminosityBlock(), iEvent.id().event());
227  printf("veto(%i), ", veto);
228  printf("loose(%i), ", loose);
229  printf("medium(%i), ", medium);
230  printf("tight(%i), ", tight);
231  printf("trigtight(%i), ", trigtight);
232  printf("trigwp70(%i), ", trigwp70);
233  printf("fbremeopin(%i)\n", fbremeopin);
234  }
235 
236  }
237 
238 }
239 
240 
241 // ------------ method called once each job just before starting event loop ------------
242  void
244 {
245 }
246 
247 // ------------ method called once each job just after ending the event loop ------------
248  void
250 {
251 }
252 
253 // ------------ method called when starting to processes a run ------------
254  void
256 {
257 }
258 
259 // ------------ method called when ending the processing of a run ------------
260  void
262 {
263 }
264 
265 // ------------ method called when starting to processes a luminosity block ------------
266  void
268 {
269 }
270 
271 // ------------ method called when ending the processing of a luminosity block ------------
272  void
274 {
275 }
276 
277 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
278 void
280  //The following says we do not know what parameters are allowed so do no validation
281  // Please change this to state exactly what you do use, even if it is no parameters
283  desc.setUnknown();
284  descriptions.addDefault(desc);
285 }
286 
287 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:42
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< edm::Handle< edm::ValueMap< reco::IsoDeposit > > > IsoDepositMaps
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
virtual void analyze(const edm::Event &, const edm::EventSetup &)
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
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
EGammaCutBasedEleIdAnalyzer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:243
edm::EDGetTokenT< reco::ConversionCollection > conversionsToken_
void addDefault(ParameterSetDescription const &psetDescription)
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)
bool PassTriggerCuts(const TriggerWorkingPoint triggerWorkingPoint, const reco::GsfElectronRef &ele)
edm::EDGetTokenT< reco::GsfElectronCollection > electronsToken_
bool PassEoverPCuts(const reco::GsfElectronRef &ele)
int j
Definition: DBlmapReader.cc:9
std::vector< edm::Handle< edm::ValueMap< double > > > IsoDepositVals
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T const * product() const
Definition: Handle.h:81
edm::EventID id() const
Definition: EventBase.h:56
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
edm::EDGetTokenT< reco::VertexCollection > primaryVertexToken_
std::vector< edm::EDGetTokenT< edm::ValueMap< double > > > isoValTokens_
virtual void endRun(edm::Run const &, edm::EventSetup const &)
Definition: Run.h:41
edm::EDGetTokenT< double > rhoIsoToken_
virtual void beginRun(edm::Run const &, edm::EventSetup const &)