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 
20 class PatBasicAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
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  usesResource(TFileService::kSharedResource);
60 }
61 
63 
65  // get electron collection
67  iEvent.getByToken(elecSrcToken_, electrons);
68 
69  // get muon collection
71  iEvent.getByToken(muonSrcToken_, muons);
72 
73  // get tau collection
75  iEvent.getByToken(tauSrcToken_, taus);
76 
77  // get jet collection
79  iEvent.getByToken(jetSrcToken_, jets);
80 
81  // get met collection
83  iEvent.getByToken(metSrcToken_, mets);
84 
85  // get photon collection
87  iEvent.getByToken(photonSrcToken_, photons);
88 
89  // loop over jets
90  size_t nJets = 0;
91  for (edm::View<pat::Jet>::const_iterator jet = jets->begin(); jet != jets->end(); ++jet) {
92  if (jet->pt() > 50) {
93  ++nJets;
94  }
95  // uncomment the following line to fill the
96  // jetTowers_ histogram
97  // jetTowers_->Fill(jet->getCaloConstituents().size());
98  }
99  histContainer_["jets"]->Fill(nJets);
100 
101  // do something similar for the other candidates
102  histContainer_["photons"]->Fill(photons->size());
103  histContainer_["elecs"]->Fill(electrons->size());
104  histContainer_["muons"]->Fill(muons->size());
105  histContainer_["taus"]->Fill(taus->size());
106  histContainer_["met"]->Fill(mets->empty() ? 0 : (*mets)[0].et());
107 }
108 
110  // register to the TFileService
112 
113  // book histograms:
114  // uncomment the following line to book the jetTowers_ histogram
115  //jetTowers_= fs->make<TH1F>("jetTowers", "towers per jet", 90, 0, 90);
116  histContainer_["photons"] = fs->make<TH1F>("photons", "photon multiplicity", 10, 0, 10);
117  histContainer_["elecs"] = fs->make<TH1F>("elecs", "electron multiplicity", 10, 0, 10);
118  histContainer_["muons"] = fs->make<TH1F>("muons", "muon multiplicity", 10, 0, 10);
119  histContainer_["taus"] = fs->make<TH1F>("taus", "tau multiplicity", 10, 0, 10);
120  histContainer_["jets"] = fs->make<TH1F>("jets", "jet multiplicity", 10, 0, 10);
121  histContainer_["met"] = fs->make<TH1F>("met", "missing E_{T}", 20, 0, 100);
122 }
123 
125 
static const std::string kSharedResource
Definition: TFileService.h:76
edm::EDGetTokenT< edm::View< pat::Tau > > tauSrcToken_
Definition: Photon.py:1
edm::EDGetTokenT< edm::View< pat::Jet > > jetSrcToken_
void analyze(const edm::Event &, const edm::EventSetup &) override
everything that needs to be done during the event loop
static constexpr int nJets
std::map< std::string, TH1F * > histContainer_
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:212
Definition: HeavyIon.h:7
PatBasicAnalyzer(const edm::ParameterSet &)
default constructor
edm::EDGetTokenT< edm::View< pat::Muon > > muonSrcToken_
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::View< pat::MET > > metSrcToken_
Definition: Muon.py:1
Definition: Jet.py:1
edm::EDGetTokenT< edm::View< pat::Electron > > elecSrcToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Definition: Tau.py:1
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
~PatBasicAnalyzer() override
default destructor
void beginJob() override
everything that needs to be done before the event loop
void endJob() override
everything that needs to be done after the event loop
edm::EDGetTokenT< edm::View< pat::Photon > > photonSrcToken_