Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:03

0001 /*   A macro for making a histogram of Electron Pt with cuts
0002 This is a basic way to cut out electrons of a certain Pt and Eta using an if statement
0003 This example creates a histogram of Electron Pt, using Electrons with Pt above 30 and ETA above -2.1 and below 2.1
0004 */
0005 
0006 #include "DataFormats/FWLite/interface/Handle.h"
0007 #include "DataFormats/FWLite/interface/Event.h"
0008 #include "TFile.h"
0009 #include "TH1.h"
0010 #include "TCanvas.h"
0011 #include "TLegend.h"
0012 
0013 #if !defined(__CINT__) && !defined(__MAKECINT__)
0014 #include "DataFormats/PatCandidates/interface/Electron.h"
0015 #include "PhysicsTools/SelectorUtils/interface/ElectronVPlusJetsIDSelectionFunctor.h"
0016 #endif
0017 
0018 #include <iostream>
0019 #include <cmath>  //necessary for absolute function fabs()
0020 
0021 using namespace std;
0022 
0023 void sk_fwlitecuts() {
0024   ElectronVPlusJetsIDSelectionFunctor muId(ElectronVPlusJetsIDSelectionFunctor::SUMMER08);
0025 
0026   TFile* file = new TFile("PATLayer1_Output.fromAOD_full.root");
0027   TH1D* hist_ePt = new TH1D("hist_ePt", "Electron p_{T}", 20, 0, 100);
0028   fwlite::Event ev(file);
0029 
0030   //loop through each event
0031   for (ev.toBegin(); !ev.atEnd(); ++ev) {
0032     fwlite::Handle<std::vector<pat::Electron> > h_mu;
0033     h_mu.getByLabel(ev, "cleanLayer1Electrons");
0034     if (!h_mu.isValid())
0035       continue;
0036     vector<pat::Electron> const& electrons = *h_mu;
0037 
0038     //loop through each Electron
0039     vector<pat::Electron>::const_iterator iter;
0040     for (iter = electrons.begin(); iter != electrons.end(); ++iter) {
0041       if ((iter->pt() > 30) && (fabs(iter->eta()) < 2.1)) {
0042         cout << "Passed kin" << endl;
0043         if (muId(*iter)) {
0044           cout << "Passed ID" << endl;
0045           hist_ePt->Fill(iter->pt());
0046         }
0047       }
0048 
0049     }  //end Electron loop
0050   }    //end event loop
0051 
0052   hist_ePt->Draw();
0053 }