CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
PatMuonAnalyzer Class Reference

Example class that can be used to analyze pat::Muons both within FWLite and within the full framework. More...

#include "PhysicsTools/PatExamples/interface/PatMuonAnalyzer.h"

Inheritance diagram for PatMuonAnalyzer:
edm::BasicAnalyzer

Public Member Functions

void analyze (const edm::EventBase &event) override
 everything that needs to be done during the event loop More...
 
void beginJob () override
 everything that needs to be done before the event loop More...
 
void endJob () override
 everything that needs to be done after the event loop More...
 
 PatMuonAnalyzer (const edm::ParameterSet &cfg, TFileDirectory &fs)
 default constructor More...
 
 PatMuonAnalyzer (const edm::ParameterSet &cfg, TFileDirectory &fs, edm::ConsumesCollector &&iC)
 
 ~PatMuonAnalyzer () override
 default destructor More...
 
- Public Member Functions inherited from edm::BasicAnalyzer
 BasicAnalyzer (const edm::ParameterSet &cfg, TFileDirectory &fileService)
 default constructor More...
 
 BasicAnalyzer (const edm::ParameterSet &cfg, TFileDirectory &fileService, edm::ConsumesCollector &&iC)
 
virtual ~BasicAnalyzer ()
 default destructor More...
 

Private Attributes

std::map< std::string, TH1 * > hists_
 histograms More...
 
edm::InputTag muons_
 input tag for mouns More...
 
edm::EDGetTokenT< std::vector< pat::Muon > > muonsToken_
 

Detailed Description

Example class that can be used to analyze pat::Muons both within FWLite and within the full framework.

This is an example for keeping classes that can be used both within FWLite and within the full framework. The class is derived from the BasicAnalyzer base class, which is an interface for the two wrapper classes EDAnalyzerWrapper and FWLiteAnalyzerWrapper. You can fin more information on this on WorkBookFWLiteExamples::ExampleFive.

Definition at line 18 of file PatMuonAnalyzer.h.

Constructor & Destructor Documentation

◆ PatMuonAnalyzer() [1/2]

PatMuonAnalyzer::PatMuonAnalyzer ( const edm::ParameterSet cfg,
TFileDirectory fs 
)

default constructor

Definition at line 6 of file PatMuonAnalyzer.cc.

References compareTotals::fs, and hists_.

7  : edm::BasicAnalyzer::BasicAnalyzer(cfg, fs), muons_(cfg.getParameter<edm::InputTag>("muons")) {
8  hists_["muonPt"] = fs.make<TH1F>("muonPt", "pt", 100, 0., 300.);
9  hists_["muonEta"] = fs.make<TH1F>("muonEta", "eta", 100, -3., 3.);
10  hists_["muonPhi"] = fs.make<TH1F>("muonPhi", "phi", 100, -5., 5.);
11 }
edm::InputTag muons_
input tag for mouns
std::map< std::string, TH1 * > hists_
histograms
BasicAnalyzer(const edm::ParameterSet &cfg, TFileDirectory &fileService)
default constructor
Definition: BasicAnalyzer.h:45

◆ PatMuonAnalyzer() [2/2]

PatMuonAnalyzer::PatMuonAnalyzer ( const edm::ParameterSet cfg,
TFileDirectory fs,
edm::ConsumesCollector &&  iC 
)

Definition at line 12 of file PatMuonAnalyzer.cc.

References compareTotals::fs, and hists_.

14  muons_(cfg.getParameter<edm::InputTag>("muons")),
15  muonsToken_(iC.consumes<std::vector<pat::Muon> >(muons_)) {
16  hists_["muonPt"] = fs.make<TH1F>("muonPt", "pt", 100, 0., 300.);
17  hists_["muonEta"] = fs.make<TH1F>("muonEta", "eta", 100, -3., 3.);
18  hists_["muonPhi"] = fs.make<TH1F>("muonPhi", "phi", 100, -5., 5.);
19 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::InputTag muons_
input tag for mouns
edm::EDGetTokenT< std::vector< pat::Muon > > muonsToken_
std::map< std::string, TH1 * > hists_
histograms
BasicAnalyzer(const edm::ParameterSet &cfg, TFileDirectory &fileService)
default constructor
Definition: BasicAnalyzer.h:45

◆ ~PatMuonAnalyzer()

PatMuonAnalyzer::~PatMuonAnalyzer ( )
inlineoverride

default destructor

Definition at line 24 of file PatMuonAnalyzer.h.

24 {};

Member Function Documentation

◆ analyze()

void PatMuonAnalyzer::analyze ( const edm::EventBase event)
overridevirtual

everything that needs to be done during the event loop

Implements edm::BasicAnalyzer.

Definition at line 22 of file PatMuonAnalyzer.cc.

References hists_, DiMuonV_cfg::muons, and muons_.

22  {
23  // define what muon you are using; this is necessary as FWLite is not
24  // capable of reading edm::Views
25  using pat::Muon;
26 
27  // Handle to the muon collection
29  event.getByLabel(muons_, muons);
30 
31  // loop muon collection and fill histograms
32  for (std::vector<Muon>::const_iterator mu1 = muons->begin(); mu1 != muons->end(); ++mu1) {
33  hists_["muonPt"]->Fill(mu1->pt());
34  hists_["muonEta"]->Fill(mu1->eta());
35  hists_["muonPhi"]->Fill(mu1->phi());
36  }
37 }
edm::InputTag muons_
input tag for mouns
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:212
std::map< std::string, TH1 * > hists_
histograms
Analysis-level muon class.
Definition: Muon.h:51

◆ beginJob()

void PatMuonAnalyzer::beginJob ( void  )
inlineoverridevirtual

everything that needs to be done before the event loop

Implements edm::BasicAnalyzer.

Definition at line 26 of file PatMuonAnalyzer.h.

26 {};

◆ endJob()

void PatMuonAnalyzer::endJob ( void  )
inlineoverridevirtual

everything that needs to be done after the event loop

Implements edm::BasicAnalyzer.

Definition at line 28 of file PatMuonAnalyzer.h.

28 {};

Member Data Documentation

◆ hists_

std::map<std::string, TH1*> PatMuonAnalyzer::hists_
private

histograms

Definition at line 37 of file PatMuonAnalyzer.h.

Referenced by analyze(), and PatMuonAnalyzer().

◆ muons_

edm::InputTag PatMuonAnalyzer::muons_
private

input tag for mouns

Definition at line 34 of file PatMuonAnalyzer.h.

Referenced by analyze().

◆ muonsToken_

edm::EDGetTokenT<std::vector<pat::Muon> > PatMuonAnalyzer::muonsToken_
private

Definition at line 35 of file PatMuonAnalyzer.h.