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