CMS 3D CMS Logo

PatBasicAnalyzer.cc
Go to the documentation of this file.
1 #include <map>
2 #include <string>
3 
4 #include "TH1.h"
5 
12 
19 
21 public:
23  explicit PatBasicAnalyzer(const edm::ParameterSet&);
25  ~PatBasicAnalyzer() override;
26 
27 private:
29  void beginJob() override;
31  void analyze(const edm::Event&, const edm::EventSetup&) override;
33  void endJob() override;
34 
35  // simple map to contain all histograms;
36  // histograms are booked in the beginJob()
37  // method
38  std::map<std::string, TH1F*> histContainer_;
39  // plot number of towers per jet
40  TH1F* jetTowers_;
41 
42  // input tokens
49 };
50 
52  : histContainer_(),
53  photonSrcToken_(consumes<edm::View<pat::Photon>>(iConfig.getUntrackedParameter<edm::InputTag>("photonSrc"))),
54  elecSrcToken_(consumes<edm::View<pat::Electron>>(iConfig.getUntrackedParameter<edm::InputTag>("electronSrc"))),
55  muonSrcToken_(consumes<edm::View<pat::Muon>>(iConfig.getUntrackedParameter<edm::InputTag>("muonSrc"))),
56  tauSrcToken_(consumes<edm::View<pat::Tau>>(iConfig.getUntrackedParameter<edm::InputTag>("tauSrc"))),
57  jetSrcToken_(consumes<edm::View<pat::Jet>>(iConfig.getUntrackedParameter<edm::InputTag>("jetSrc"))),
58  metSrcToken_(consumes<edm::View<pat::MET>>(iConfig.getUntrackedParameter<edm::InputTag>("metSrc"))) {}
59 
61 
63  // get electron collection
65  iEvent.getByToken(elecSrcToken_, electrons);
66 
67  // get muon collection
69  iEvent.getByToken(muonSrcToken_, muons);
70 
71  // get tau collection
73  iEvent.getByToken(tauSrcToken_, taus);
74 
75  // get jet collection
77  iEvent.getByToken(jetSrcToken_, jets);
78 
79  // get met collection
81  iEvent.getByToken(metSrcToken_, mets);
82 
83  // get photon collection
85  iEvent.getByToken(photonSrcToken_, photons);
86 
87  // loop over jets
88  size_t nJets = 0;
89  for (edm::View<pat::Jet>::const_iterator jet = jets->begin(); jet != jets->end(); ++jet) {
90  if (jet->pt() > 50) {
91  ++nJets;
92  }
93  // uncomment the following line to fill the
94  // jetTowers_ histogram
95  // jetTowers_->Fill(jet->getCaloConstituents().size());
96  }
97  histContainer_["jets"]->Fill(nJets);
98 
99  // do something similar for the other candidates
100  histContainer_["photons"]->Fill(photons->size());
101  histContainer_["elecs"]->Fill(electrons->size());
102  histContainer_["muons"]->Fill(muons->size());
103  histContainer_["taus"]->Fill(taus->size());
104  histContainer_["met"]->Fill(mets->empty() ? 0 : (*mets)[0].et());
105 }
106 
108  // register to the TFileService
110 
111  // book histograms:
112  // uncomment the following line to book the jetTowers_ histogram
113  //jetTowers_= fs->make<TH1F>("jetTowers", "towers per jet", 90, 0, 90);
114  histContainer_["photons"] = fs->make<TH1F>("photons", "photon multiplicity", 10, 0, 10);
115  histContainer_["elecs"] = fs->make<TH1F>("elecs", "electron multiplicity", 10, 0, 10);
116  histContainer_["muons"] = fs->make<TH1F>("muons", "muon multiplicity", 10, 0, 10);
117  histContainer_["taus"] = fs->make<TH1F>("taus", "tau multiplicity", 10, 0, 10);
118  histContainer_["jets"] = fs->make<TH1F>("jets", "jet multiplicity", 10, 0, 10);
119  histContainer_["met"] = fs->make<TH1F>("met", "missing E_{T}", 20, 0, 100);
120 }
121 
123 
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
sistrip::View
View
Definition: ConstantsForView.h:26
edm::EDGetTokenT
Definition: EDGetToken.h:33
Tau3MuMonitor_cff.taus
taus
Definition: Tau3MuMonitor_cff.py:7
Electron
Definition: Electron.py:1
PatBasicAnalyzer
Definition: PatBasicAnalyzer.cc:20
edm
HLT enums.
Definition: AlignableModifier.h:19
PatBasicAnalyzer::jetSrcToken_
edm::EDGetTokenT< edm::View< pat::Jet > > jetSrcToken_
Definition: PatBasicAnalyzer.cc:47
Muon.h
Photon.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
PatBasicAnalyzer::~PatBasicAnalyzer
~PatBasicAnalyzer() override
default destructor
Definition: PatBasicAnalyzer.cc:60
EDAnalyzer.h
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
singleTopDQM_cfi.mets
mets
Definition: singleTopDQM_cfi.py:43
Tau
Definition: Tau.py:1
PatBasicAnalyzer::elecSrcToken_
edm::EDGetTokenT< edm::View< pat::Electron > > elecSrcToken_
Definition: PatBasicAnalyzer.cc:44
PatBasicAnalyzer::PatBasicAnalyzer
PatBasicAnalyzer(const edm::ParameterSet &)
default constructor
Definition: PatBasicAnalyzer.cc:51
edm::Handle
Definition: AssociativeIterator.h:50
Tau.h
Muon
Definition: Muon.py:1
PatBasicAnalyzer::metSrcToken_
edm::EDGetTokenT< edm::View< pat::MET > > metSrcToken_
Definition: PatBasicAnalyzer.cc:48
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
PatBasicAnalyzer::histContainer_
std::map< std::string, TH1F * > histContainer_
Definition: PatBasicAnalyzer.cc:38
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Jet
Definition: Jet.py:1
Service.h
PatBasicAnalyzer::jetTowers_
TH1F * jetTowers_
Definition: PatBasicAnalyzer.cc:40
PatBasicAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
everything that needs to be done during the event loop
Definition: PatBasicAnalyzer.cc:62
PatBasicAnalyzer::beginJob
void beginJob() override
everything that needs to be done before the event loop
Definition: PatBasicAnalyzer.cc:107
TFileService.h
PatBasicAnalyzer::muonSrcToken_
edm::EDGetTokenT< edm::View< pat::Muon > > muonSrcToken_
Definition: PatBasicAnalyzer.cc:45
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
Photon
Definition: Photon.py:1
edm::Service< TFileService >
iEvent
int iEvent
Definition: GenABIO.cc:224
BPHMonitor_cfi.photons
photons
Definition: BPHMonitor_cfi.py:91
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
MET.h
Jet.h
InputTag.h
PatBasicAnalyzer::endJob
void endJob() override
everything that needs to be done after the event loop
Definition: PatBasicAnalyzer.cc:122
pwdgSkimBPark_cfi.electrons
electrons
Definition: pwdgSkimBPark_cfi.py:6
metsig::jet
Definition: SignAlgoResolutions.h:47
PatBasicAnalyzer::tauSrcToken_
edm::EDGetTokenT< edm::View< pat::Tau > > tauSrcToken_
Definition: PatBasicAnalyzer.cc:46
MET
Electron.h
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
PatBasicAnalyzer::photonSrcToken_
edm::EDGetTokenT< edm::View< pat::Photon > > photonSrcToken_
Definition: PatBasicAnalyzer.cc:43
ParameterSet.h
edm::Event
Definition: Event.h:73
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64