Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:59

0001 /*   A macro for making a histogram of Muon Pt with cuts
0002 This is a basic way to cut out muons of a certain Pt and Eta using an if statement
0003 This example creates a histogram of Muon Pt, using Muons 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/Muon.h"
0015 #include "PhysicsTools/SelectorUtils/interface/MuonVPlusJetsIDSelectionFunctor.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   MuonVPlusJetsIDSelectionFunctor muId(MuonVPlusJetsIDSelectionFunctor::SUMMER08);
0025 
0026   TFile* file = new TFile("PATLayer1_Output.fromAOD_full.root");
0027   TH1D* hist_muPt = new TH1D("hist_muPt", "Muon 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::Muon> > h_mu;
0033     h_mu.getByLabel(ev, "cleanLayer1Muons");
0034     if (!h_mu.isValid())
0035       continue;
0036     vector<pat::Muon> const& muons = *h_mu;
0037 
0038     //loop through each Muon
0039     vector<pat::Muon>::const_iterator iter;
0040     for (iter = muons.begin(); iter != muons.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_muPt->Fill(iter->pt());
0046         }
0047       }
0048 
0049     }  //end Muon loop
0050   }    //end event loop
0051 
0052   hist_muPt->Draw();
0053 }