CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/EgammaAnalysis/ElectronTools/src/EGammaCutBasedEleIdAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    EGammaCutBasedEleIdAnalyzer
00004 // Class:      EGammaCutBasedEleIdAnalyzer
00005 // 
00013 //
00014 // Original Author:  Dave Evans,510 1-015,+41227679496,
00015 //         Created:  Tue Apr 10 11:17:29 CEST 2012
00016 // $Id: EGammaCutBasedEleIdAnalyzer.cc,v 1.1 2012/12/03 20:51:02 tjkim Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 #include "FWCore/Framework/interface/Event.h"
00028 #include "FWCore/Framework/interface/MakerMacros.h"
00029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00030 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00031 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00032 #include "DataFormats/EgammaCandidates/interface/Conversion.h"
00033 #include "DataFormats/VertexReco/interface/Vertex.h"
00034 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00035 #include "DataFormats/Common/interface/ValueMap.h"
00036 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
00037 #include "EgammaAnalysis/ElectronTools/interface/EGammaCutBasedEleId.h"
00038 #include "FWCore/ServiceRegistry/interface/Service.h"
00039 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00040 
00041 #include <TFile.h>
00042 #include <TH1F.h>
00043 
00044 //
00045 // class declaration
00046 //
00047 
00048 class EGammaCutBasedEleIdAnalyzer : public edm::EDAnalyzer {
00049     public:
00050         explicit EGammaCutBasedEleIdAnalyzer(const edm::ParameterSet&);
00051         ~EGammaCutBasedEleIdAnalyzer();
00052 
00053         static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
00054 
00055 
00056     private:
00057         virtual void beginJob() ;
00058         virtual void analyze(const edm::Event&, const edm::EventSetup&);
00059         virtual void endJob() ;
00060 
00061         virtual void beginRun(edm::Run const&, edm::EventSetup const&);
00062         virtual void endRun(edm::Run const&, edm::EventSetup const&);
00063         virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00064         virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00065 
00066         // ----------member data ---------------------------
00067 
00068         // input tags
00069         edm::InputTag               electronsInputTag_;
00070         edm::InputTag               conversionsInputTag_;
00071         edm::InputTag               beamSpotInputTag_;
00072         edm::InputTag               rhoIsoInputTag;
00073         edm::InputTag               primaryVertexInputTag_;
00074         std::vector<edm::InputTag>  isoValInputTags_;
00075 
00076         // debug
00077         bool printDebug_;
00078 
00079         // histograms
00080         TH1F *h1_pt_;
00081         TH1F *h1_pt_veto_;
00082         TH1F *h1_pt_loose_;
00083         TH1F *h1_pt_medium_;
00084         TH1F *h1_pt_tight_;
00085         TH1F *h1_pt_trig_;
00086         TH1F *h1_pt_fbremeopin_;
00087 
00088 };
00089 
00090 //
00091 // constants, enums and typedefs
00092 //
00093 
00094 typedef std::vector< edm::Handle< edm::ValueMap<reco::IsoDeposit> > >   IsoDepositMaps;
00095 typedef std::vector< edm::Handle< edm::ValueMap<double> > >             IsoDepositVals;
00096 
00097 //
00098 // static data member definitions
00099 //
00100 
00101 //
00102 // constructors and destructor
00103 //
00104 EGammaCutBasedEleIdAnalyzer::EGammaCutBasedEleIdAnalyzer(const edm::ParameterSet& iConfig)
00105 {
00106 
00107     // get input parameters
00108     electronsInputTag_      = iConfig.getParameter<edm::InputTag>("electronsInputTag");
00109     conversionsInputTag_    = iConfig.getParameter<edm::InputTag>("conversionsInputTag");
00110     beamSpotInputTag_       = iConfig.getParameter<edm::InputTag>("beamSpotInputTag");
00111     rhoIsoInputTag          = iConfig.getParameter<edm::InputTag>("rhoIsoInputTag");
00112     primaryVertexInputTag_  = iConfig.getParameter<edm::InputTag>("primaryVertexInputTag");
00113     isoValInputTags_        = iConfig.getParameter<std::vector<edm::InputTag> >("isoValInputTags");
00114 
00115     // debug
00116     printDebug_             = iConfig.getParameter<bool>("printDebug");
00117 
00118     // output histograms
00119     edm::Service<TFileService> fs;
00120 
00121     h1_pt_               = fs->make<TH1F>("h1_pt",               "pt",              100, 0.0, 100.0);
00122     h1_pt_veto_          = fs->make<TH1F>("h1_pt_veto",          "pt (veto)",       100, 0.0, 100.0);
00123     h1_pt_loose_         = fs->make<TH1F>("h1_pt_loose",         "pt (loose)",      100, 0.0, 100.0);
00124     h1_pt_medium_        = fs->make<TH1F>("h1_pt_medium",        "pt (medium)",     100, 0.0, 100.0);
00125     h1_pt_tight_         = fs->make<TH1F>("h1_pt_tight",         "pt (tight)",      100, 0.0, 100.0);
00126     h1_pt_trig_          = fs->make<TH1F>("h1_pt_trig",          "pt (trig)",       100, 0.0, 100.0); 
00127     h1_pt_fbremeopin_    = fs->make<TH1F>("h1_pt_fbremeopin",    "pt (fbremeopin)", 100, 0.0, 100.0);
00128 
00129 }
00130 
00131 
00132 EGammaCutBasedEleIdAnalyzer::~EGammaCutBasedEleIdAnalyzer()
00133 {
00134 
00135     // do anything here that needs to be done at desctruction time
00136     // (e.g. close files, deallocate resources etc.)
00137 
00138 }
00139 
00140 
00141 //
00142 // member functions
00143 //
00144 
00145 // ------------ method called for each event  ------------
00146     void
00147 EGammaCutBasedEleIdAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00148 {
00149     // electrons
00150     edm::Handle<reco::GsfElectronCollection> els_h;
00151     iEvent.getByLabel(electronsInputTag_, els_h);
00152 
00153     // conversions
00154     edm::Handle<reco::ConversionCollection> conversions_h;
00155     iEvent.getByLabel(conversionsInputTag_, conversions_h);
00156 
00157     // iso deposits
00158     IsoDepositVals isoVals(isoValInputTags_.size());
00159     for (size_t j = 0; j < isoValInputTags_.size(); ++j) {
00160         iEvent.getByLabel(isoValInputTags_[j], isoVals[j]);
00161     }
00162 
00163     // beam spot
00164     edm::Handle<reco::BeamSpot> beamspot_h;
00165     iEvent.getByLabel(beamSpotInputTag_, beamspot_h);
00166     const reco::BeamSpot &beamSpot = *(beamspot_h.product());
00167 
00168     // vertices
00169     edm::Handle<reco::VertexCollection> vtx_h;
00170     iEvent.getByLabel(primaryVertexInputTag_, vtx_h);
00171 
00172     // rho for isolation
00173     edm::Handle<double> rhoIso_h;
00174     iEvent.getByLabel(rhoIsoInputTag, rhoIso_h);
00175     double rhoIso = *(rhoIso_h.product());
00176 
00177     // loop on electrons
00178     unsigned int n = els_h->size();
00179     for(unsigned int i = 0; i < n; ++i) {
00180 
00181         // get reference to electron
00182         reco::GsfElectronRef ele(els_h, i);
00183 
00184         //
00185         // get particle flow isolation
00186         //
00187 
00188         double iso_ch =  (*(isoVals)[0])[ele];
00189         double iso_em = (*(isoVals)[1])[ele];
00190         double iso_nh = (*(isoVals)[2])[ele];
00191 
00192         //
00193         // test ID
00194         //
00195 
00196         // working points
00197         bool veto       = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::VETO, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso);
00198         bool loose      = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::LOOSE, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso);
00199         bool medium     = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::MEDIUM, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso);
00200         bool tight      = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::TIGHT, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso);
00201 
00202         // eop/fbrem cuts for extra tight ID
00203         bool fbremeopin = EgammaCutBasedEleId::PassEoverPCuts(ele);
00204 
00205         // cuts to match tight trigger requirements
00206         bool trigtight = EgammaCutBasedEleId::PassTriggerCuts(EgammaCutBasedEleId::TRIGGERTIGHT, ele);
00207 
00208         // for 2011 WP70 trigger
00209         bool trigwp70 = EgammaCutBasedEleId::PassTriggerCuts(EgammaCutBasedEleId::TRIGGERWP70, ele);
00210 
00211         //
00212         // fill histograms
00213         //
00214 
00215         h1_pt_->Fill(ele->pt());
00216         if (veto)       h1_pt_veto_         ->Fill(ele->pt());
00217         if (loose)      h1_pt_loose_        ->Fill(ele->pt());
00218         if (medium)     h1_pt_medium_       ->Fill(ele->pt());
00219         if (tight)      h1_pt_tight_        ->Fill(ele->pt());
00220         if (trigtight)  h1_pt_trig_         ->Fill(ele->pt());
00221         if (fbremeopin) h1_pt_fbremeopin_   ->Fill(ele->pt());
00222 
00223         //
00224         // print decisions
00225         //
00226 
00227         if (printDebug_) {
00228             printf("%u %u %u : ",       iEvent.id().run(), iEvent.luminosityBlock(), iEvent.id().event());
00229             printf("veto(%i), ",        veto);
00230             printf("loose(%i), ",       loose);
00231             printf("medium(%i), ",      medium);
00232             printf("tight(%i), ",       tight);
00233             printf("trigtight(%i), ",   trigtight);
00234             printf("trigwp70(%i), ",    trigwp70);
00235             printf("fbremeopin(%i)\n",  fbremeopin);
00236         }
00237 
00238     }
00239 
00240 }
00241 
00242 
00243 // ------------ method called once each job just before starting event loop  ------------
00244     void 
00245 EGammaCutBasedEleIdAnalyzer::beginJob()
00246 {
00247 }
00248 
00249 // ------------ method called once each job just after ending the event loop  ------------
00250     void 
00251 EGammaCutBasedEleIdAnalyzer::endJob() 
00252 {
00253 }
00254 
00255 // ------------ method called when starting to processes a run  ------------
00256     void 
00257 EGammaCutBasedEleIdAnalyzer::beginRun(edm::Run const&, edm::EventSetup const&)
00258 {
00259 }
00260 
00261 // ------------ method called when ending the processing of a run  ------------
00262     void 
00263 EGammaCutBasedEleIdAnalyzer::endRun(edm::Run const&, edm::EventSetup const&)
00264 {
00265 }
00266 
00267 // ------------ method called when starting to processes a luminosity block  ------------
00268     void 
00269 EGammaCutBasedEleIdAnalyzer::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00270 {
00271 }
00272 
00273 // ------------ method called when ending the processing of a luminosity block  ------------
00274     void 
00275 EGammaCutBasedEleIdAnalyzer::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00276 {
00277 }
00278 
00279 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00280 void
00281 EGammaCutBasedEleIdAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00282     //The following says we do not know what parameters are allowed so do no validation
00283     // Please change this to state exactly what you do use, even if it is no parameters
00284     edm::ParameterSetDescription desc;
00285     desc.setUnknown();
00286     descriptions.addDefault(desc);
00287 }
00288 
00289 //define this as a plug-in
00290 DEFINE_FWK_MODULE(EGammaCutBasedEleIdAnalyzer);