Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-05 07:05:21

0001 // -*- C++ -*-
0002 //
0003 // Package:    EGammaCutBasedEleIdAnalyzer
0004 // Class:      EGammaCutBasedEleIdAnalyzer
0005 //
0006 /**\class EGammaCutBasedEleIdAnalyzer EGammaCutBasedEleIdAnalyzer.cc EGamma/EGammaCutBasedEleIdAnalyzer/src/EGammaCutBasedEleIdAnalyzer.cc
0007 
0008 Description: [one line class summary]
0009 
0010 Implementation:
0011 [Notes on implementation]
0012  */
0013 //
0014 // Original Author:  Dave Evans,510 1-015,+41227679496,
0015 //         Created:  Tue Apr 10 11:17:29 CEST 2012
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/MakerMacros.h"
0027 #include "FWCore/Utilities/interface/transform.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0030 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0031 #include "DataFormats/EgammaCandidates/interface/Conversion.h"
0032 #include "DataFormats/VertexReco/interface/Vertex.h"
0033 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0034 #include "DataFormats/Common/interface/ValueMap.h"
0035 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
0036 #include "EgammaAnalysis/ElectronTools/interface/EGammaCutBasedEleId.h"
0037 #include "EgammaAnalysis/ElectronTools/interface/ElectronEffectiveArea.h"
0038 #include "FWCore/ServiceRegistry/interface/Service.h"
0039 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0040 
0041 #include <TFile.h>
0042 #include <TH1F.h>
0043 
0044 //
0045 // class declaration
0046 //
0047 
0048 class EGammaCutBasedEleIdAnalyzer : public edm::one::EDAnalyzer<> {
0049 public:
0050   typedef std::vector<edm::Handle<edm::ValueMap<reco::IsoDeposit> > > IsoDepositMaps;
0051   typedef std::vector<edm::Handle<edm::ValueMap<double> > > IsoDepositVals;
0052 
0053   explicit EGammaCutBasedEleIdAnalyzer(const edm::ParameterSet &);
0054   ~EGammaCutBasedEleIdAnalyzer() override;
0055 
0056   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0057   ElectronEffectiveArea::ElectronEffectiveAreaTarget EAtarget;
0058 
0059 private:
0060   void beginJob() override;
0061   void analyze(const edm::Event &, const edm::EventSetup &) override;
0062   void endJob() override;
0063 
0064   /*
0065   void beginRun(edm::Run const &, edm::EventSetup const &) override;
0066   void endRun(edm::Run const &, edm::EventSetup const &) override;
0067   void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override;
0068   void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override;
0069   */
0070   // ----------member data ---------------------------
0071 
0072   // input tags
0073   edm::EDGetTokenT<reco::GsfElectronCollection> electronsToken_;
0074   edm::EDGetTokenT<reco::ConversionCollection> conversionsToken_;
0075   edm::EDGetTokenT<reco::BeamSpot> beamSpotToken_;
0076   edm::EDGetTokenT<double> rhoIsoToken_;
0077   edm::EDGetTokenT<reco::VertexCollection> primaryVertexToken_;
0078   std::vector<edm::EDGetTokenT<edm::ValueMap<double> > > isoValTokens_;
0079   std::string EAtargetToken_;
0080 
0081   // debug
0082   bool printDebug_;
0083 
0084   // histograms
0085   TH1F *h1_pt_;
0086   TH1F *h1_pt_veto_;
0087   TH1F *h1_pt_loose_;
0088   TH1F *h1_pt_medium_;
0089   TH1F *h1_pt_tight_;
0090   TH1F *h1_pt_trig_;
0091   TH1F *h1_pt_fbremeopin_;
0092 };
0093 
0094 //
0095 // static data member definitions
0096 //
0097 
0098 //
0099 // constructors and destructor
0100 //
0101 EGammaCutBasedEleIdAnalyzer::EGammaCutBasedEleIdAnalyzer(const edm::ParameterSet &iConfig) {
0102   // get input parameters
0103   electronsToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronsInputTag"));
0104   conversionsToken_ = consumes<reco::ConversionCollection>(iConfig.getParameter<edm::InputTag>("conversionsInputTag"));
0105   beamSpotToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotInputTag"));
0106   rhoIsoToken_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rhoIsoInputTag"));
0107   primaryVertexToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertexInputTag"));
0108   isoValTokens_ =
0109       edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >("isoValInputTags"),
0110                             [this](edm::InputTag const &tag) { return consumes<edm::ValueMap<double> >(tag); });
0111   EAtargetToken_ = iConfig.getParameter<std::string>(
0112       "EAtarget");  //EleEANoCorr, EleEAData2011, EleEASummer11MC,EleEAFall11MC, EleEAData2012/
0113 
0114   // debug
0115   printDebug_ = iConfig.getParameter<bool>("printDebug");
0116 
0117   // output histograms
0118   edm::Service<TFileService> fs;
0119 
0120   h1_pt_ = fs->make<TH1F>("h1_pt", "pt", 100, 0.0, 100.0);
0121   h1_pt_veto_ = fs->make<TH1F>("h1_pt_veto", "pt (veto)", 100, 0.0, 100.0);
0122   h1_pt_loose_ = fs->make<TH1F>("h1_pt_loose", "pt (loose)", 100, 0.0, 100.0);
0123   h1_pt_medium_ = fs->make<TH1F>("h1_pt_medium", "pt (medium)", 100, 0.0, 100.0);
0124   h1_pt_tight_ = fs->make<TH1F>("h1_pt_tight", "pt (tight)", 100, 0.0, 100.0);
0125   h1_pt_trig_ = fs->make<TH1F>("h1_pt_trig", "pt (trig)", 100, 0.0, 100.0);
0126   h1_pt_fbremeopin_ = fs->make<TH1F>("h1_pt_fbremeopin", "pt (fbremeopin)", 100, 0.0, 100.0);
0127 }
0128 
0129 EGammaCutBasedEleIdAnalyzer::~EGammaCutBasedEleIdAnalyzer() {
0130   // do anything here that needs to be done at desctruction time
0131   // (e.g. close files, deallocate resources etc.)
0132 }
0133 
0134 //
0135 // member functions
0136 //
0137 
0138 // ------------ method called for each event  ------------
0139 void EGammaCutBasedEleIdAnalyzer::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0140   // electrons
0141   edm::Handle<reco::GsfElectronCollection> els_h;
0142   iEvent.getByToken(electronsToken_, els_h);
0143 
0144   // conversions
0145   edm::Handle<reco::ConversionCollection> conversions_h;
0146   iEvent.getByToken(conversionsToken_, conversions_h);
0147 
0148   // iso deposits
0149   IsoDepositVals isoVals(isoValTokens_.size());
0150   for (size_t j = 0; j < isoValTokens_.size(); ++j) {
0151     iEvent.getByToken(isoValTokens_[j], isoVals[j]);
0152   }
0153 
0154   // beam spot
0155   edm::Handle<reco::BeamSpot> beamspot_h;
0156   iEvent.getByToken(beamSpotToken_, beamspot_h);
0157   const reco::BeamSpot &beamSpot = *(beamspot_h.product());
0158 
0159   // vertices
0160   edm::Handle<reco::VertexCollection> vtx_h;
0161   iEvent.getByToken(primaryVertexToken_, vtx_h);
0162 
0163   // rho for isolation
0164   edm::Handle<double> rhoIso_h;
0165   iEvent.getByToken(rhoIsoToken_, rhoIso_h);
0166   double rhoIso = *(rhoIso_h.product());
0167 
0168   // loop on electrons
0169   unsigned int n = els_h->size();
0170   for (unsigned int i = 0; i < n; ++i) {
0171     // get reference to electron
0172     reco::GsfElectronRef ele(els_h, i);
0173 
0174     //
0175     // get particle flow isolation
0176     //
0177 
0178     double iso_ch = (*(isoVals)[0])[ele];
0179     double iso_em = (*(isoVals)[1])[ele];
0180     double iso_nh = (*(isoVals)[2])[ele];
0181 
0182     //
0183     // test ID
0184     //
0185 
0186     // working points
0187     bool veto = EgammaCutBasedEleId::PassWP(
0188         EgammaCutBasedEleId::VETO, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso, EAtarget);
0189     bool loose = EgammaCutBasedEleId::PassWP(
0190         EgammaCutBasedEleId::LOOSE, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso, EAtarget);
0191     bool medium = EgammaCutBasedEleId::PassWP(
0192         EgammaCutBasedEleId::MEDIUM, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso, EAtarget);
0193     bool tight = EgammaCutBasedEleId::PassWP(
0194         EgammaCutBasedEleId::TIGHT, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso, EAtarget);
0195 
0196     // eop/fbrem cuts for extra tight ID
0197     bool fbremeopin = EgammaCutBasedEleId::PassEoverPCuts(ele);
0198 
0199     // cuts to match tight trigger requirements
0200     bool trigtight = EgammaCutBasedEleId::PassTriggerCuts(EgammaCutBasedEleId::TRIGGERTIGHT, ele);
0201 
0202     // for 2011 WP70 trigger
0203     bool trigwp70 = EgammaCutBasedEleId::PassTriggerCuts(EgammaCutBasedEleId::TRIGGERWP70, ele);
0204 
0205     //
0206     // fill histograms
0207     //
0208 
0209     h1_pt_->Fill(ele->pt());
0210     if (veto)
0211       h1_pt_veto_->Fill(ele->pt());
0212     if (loose)
0213       h1_pt_loose_->Fill(ele->pt());
0214     if (medium)
0215       h1_pt_medium_->Fill(ele->pt());
0216     if (tight)
0217       h1_pt_tight_->Fill(ele->pt());
0218     if (trigtight)
0219       h1_pt_trig_->Fill(ele->pt());
0220     if (fbremeopin)
0221       h1_pt_fbremeopin_->Fill(ele->pt());
0222 
0223     //
0224     // print decisions
0225     //
0226 
0227     if (printDebug_) {
0228       printf("%u %u %llu : ", iEvent.id().run(), iEvent.luminosityBlock(), iEvent.id().event());
0229       printf("veto(%i), ", veto);
0230       printf("loose(%i), ", loose);
0231       printf("medium(%i), ", medium);
0232       printf("tight(%i), ", tight);
0233       printf("trigtight(%i), ", trigtight);
0234       printf("trigwp70(%i), ", trigwp70);
0235       printf("fbremeopin(%i)\n", fbremeopin);
0236     }
0237   }
0238 }
0239 
0240 // ------------ method called once each job just before starting event loop  ------------
0241 void EGammaCutBasedEleIdAnalyzer::beginJob() {
0242   if (EAtargetToken_ == "EleEANoCorr")
0243     EAtarget = ElectronEffectiveArea::kEleEANoCorr;
0244   else if (EAtargetToken_ == "EleEAData2011")
0245     EAtarget = ElectronEffectiveArea::kEleEAData2011;
0246   else if (EAtargetToken_ == "EleEASummer11MC")
0247     EAtarget = ElectronEffectiveArea::kEleEASummer11MC;
0248   else if (EAtargetToken_ == "EleEAFall11MC")
0249     EAtarget = ElectronEffectiveArea::kEleEAFall11MC;
0250   else if (EAtargetToken_ == "EleEAData2012")
0251     EAtarget = ElectronEffectiveArea::kEleEAData2012;
0252   else
0253     EAtarget = ElectronEffectiveArea::kEleEAData2012;
0254 }
0255 
0256 // ------------ method called once each job just after ending the event loop  ------------
0257 void EGammaCutBasedEleIdAnalyzer::endJob() {}
0258 /*
0259 // ------------ method called when starting to processes a run  ------------
0260 void EGammaCutBasedEleIdAnalyzer::beginRun(edm::Run const &, edm::EventSetup const &) {}
0261 
0262 // ------------ method called when ending the processing of a run  ------------
0263 void EGammaCutBasedEleIdAnalyzer::endRun(edm::Run const &, edm::EventSetup const &) {}
0264 
0265 // ------------ method called when starting to processes a luminosity block  ------------
0266 void EGammaCutBasedEleIdAnalyzer::beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) {}
0267 
0268 // ------------ method called when ending the processing of a luminosity block  ------------
0269 void EGammaCutBasedEleIdAnalyzer::endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) {}
0270 */
0271 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0272 void EGammaCutBasedEleIdAnalyzer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0273   //The following says we do not know what parameters are allowed so do no validation
0274   // Please change this to state exactly what you do use, even if it is no parameters
0275   edm::ParameterSetDescription desc;
0276   desc.setUnknown();
0277   descriptions.addDefault(desc);
0278 }
0279 
0280 //define this as a plug-in
0281 DEFINE_FWK_MODULE(EGammaCutBasedEleIdAnalyzer);