CMS 3D CMS Logo

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

Example class that can be used both within FWLite and within the full framework. More...

#include "PhysicsTools/UtilAlgos/interface/BasicMuonAnalyzer.h"

Inheritance diagram for BasicMuonAnalyzer:
edm::BasicAnalyzer

Public Member Functions

void analyze (const edm::EventBase &event) override
 everything that needs to be done during the event loop More...
 
 BasicMuonAnalyzer (const edm::ParameterSet &cfg, TFileDirectory &fs)
 default constructor More...
 
 BasicMuonAnalyzer (const edm::ParameterSet &cfg, TFileDirectory &fs, edm::ConsumesCollector &&iC)
 
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...
 
 ~BasicMuonAnalyzer () 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< reco::Muon > > muonsToken_
 

Detailed Description

Example class that can be used 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. The latter provides basic configuration file reading and event looping equivalent to the FWLiteHistograms executable of this package. You can see the FWLiteAnalyzerWrapper class at work in the FWLiteWithBasicAnalyzer executable of this package.

Definition at line 20 of file BasicMuonAnalyzer.h.

Constructor & Destructor Documentation

◆ BasicMuonAnalyzer() [1/2]

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

default constructor

Definition at line 6 of file BasicMuonAnalyzer.cc.

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  hists_["mumuMass"] = fs.make<TH1F>("mumuMass", "mass", 90, 30., 120.);
12 }

References hists_, and TFileDirectory::make().

◆ BasicMuonAnalyzer() [2/2]

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

Definition at line 13 of file BasicMuonAnalyzer.cc.

15  muons_(cfg.getParameter<edm::InputTag>("muons")),
16  muonsToken_(iC.consumes<std::vector<reco::Muon> >(muons_)) {
17  hists_["muonPt"] = fs.make<TH1F>("muonPt", "pt", 100, 0., 300.);
18  hists_["muonEta"] = fs.make<TH1F>("muonEta", "eta", 100, -3., 3.);
19  hists_["muonPhi"] = fs.make<TH1F>("muonPhi", "phi", 100, -5., 5.);
20  hists_["mumuMass"] = fs.make<TH1F>("mumuMass", "mass", 90, 30., 120.);
21 }

References hists_, and TFileDirectory::make().

◆ ~BasicMuonAnalyzer()

BasicMuonAnalyzer::~BasicMuonAnalyzer ( )
inlineoverride

default destructor

Definition at line 26 of file BasicMuonAnalyzer.h.

26 {};

Member Function Documentation

◆ analyze()

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

everything that needs to be done during the event loop

Implements edm::BasicAnalyzer.

Definition at line 24 of file BasicMuonAnalyzer.cc.

24  {
25  // define what muon you are using; this is necessary as FWLite is not
26  // capable of reading edm::Views
27  using reco::Muon;
28 
29  // Handle to the muon collection
31  event.getByLabel(muons_, muons);
32 
33  // loop muon collection and fill histograms
34  for (std::vector<Muon>::const_iterator mu1 = muons->begin(); mu1 != muons->end(); ++mu1) {
35  hists_["muonPt"]->Fill(mu1->pt());
36  hists_["muonEta"]->Fill(mu1->eta());
37  hists_["muonPhi"]->Fill(mu1->phi());
38  if (mu1->pt() > 20 && fabs(mu1->eta()) < 2.1) {
39  for (std::vector<Muon>::const_iterator mu2 = muons->begin(); mu2 != muons->end(); ++mu2) {
40  if (mu2 > mu1) { // prevent double conting
41  if (mu1->charge() * mu2->charge() < 0) { // check only muon pairs of unequal charge
42  if (mu2->pt() > 20 && fabs(mu2->eta()) < 2.1) {
43  hists_["mumuMass"]->Fill((mu1->p4() + mu2->p4()).mass());
44  }
45  }
46  }
47  }
48  }
49  }
50 }

References hists_, EgHLTOffHistBins_cfi::mass, dumpRecoGeometry_cfg::Muon, PDWG_BPHSkim_cff::muons, and muons_.

◆ beginJob()

void BasicMuonAnalyzer::beginJob ( void  )
inlineoverridevirtual

everything that needs to be done before the event loop

Implements edm::BasicAnalyzer.

Definition at line 28 of file BasicMuonAnalyzer.h.

28 {};

◆ endJob()

void BasicMuonAnalyzer::endJob ( void  )
inlineoverridevirtual

everything that needs to be done after the event loop

Implements edm::BasicAnalyzer.

Definition at line 30 of file BasicMuonAnalyzer.h.

30 {};

Member Data Documentation

◆ hists_

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

histograms

Definition at line 39 of file BasicMuonAnalyzer.h.

Referenced by analyze(), and BasicMuonAnalyzer().

◆ muons_

edm::InputTag BasicMuonAnalyzer::muons_
private

input tag for mouns

Definition at line 36 of file BasicMuonAnalyzer.h.

Referenced by analyze().

◆ muonsToken_

edm::EDGetTokenT<std::vector<reco::Muon> > BasicMuonAnalyzer::muonsToken_
private

Definition at line 37 of file BasicMuonAnalyzer.h.

PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
BasicMuonAnalyzer::hists_
std::map< std::string, TH1 * > hists_
histograms
Definition: BasicMuonAnalyzer.h:39
TFileDirectory::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileDirectory.h:53
edm::Handle
Definition: AssociativeIterator.h:50
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:55
dumpRecoGeometry_cfg.Muon
Muon
Definition: dumpRecoGeometry_cfg.py:190
looper.cfg
cfg
Definition: looper.py:297
BasicMuonAnalyzer::muonsToken_
edm::EDGetTokenT< std::vector< reco::Muon > > muonsToken_
Definition: BasicMuonAnalyzer.h:37
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
edm::BasicAnalyzer::BasicAnalyzer
BasicAnalyzer(const edm::ParameterSet &cfg, TFileDirectory &fileService)
default constructor
Definition: BasicAnalyzer.h:45
BasicMuonAnalyzer::muons_
edm::InputTag muons_
input tag for mouns
Definition: BasicMuonAnalyzer.h:36
edm::InputTag
Definition: InputTag.h:15