CMS 3D CMS Logo

PatZjetsJetAnalyzer.cc
Go to the documentation of this file.
1 #include <map>
2 #include <string>
3 
4 #include "TH1.h"
5 
12 
14 
15 class PatZjetsJetAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
16 public:
17  explicit PatZjetsJetAnalyzer(const edm::ParameterSet&);
18  ~PatZjetsJetAnalyzer() override;
19 
20 private:
21  void beginJob() override;
22  void analyze(const edm::Event&, const edm::EventSetup&) override;
23  void endJob() override;
24 
25  // simple map to contain all histograms;
26  // histograms are booked in the beginJob()
27  // method
28  std::map<std::string, TH1F*> histContainer_;
29 
30  // input tags
32 };
33 
35  : histContainer_(), srcToken_(consumes<edm::View<pat::Jet> >(iConfig.getUntrackedParameter<edm::InputTag>("src"))) {
36  usesResource(TFileService::kSharedResource);
37 }
38 
40 
42  // get electron collection
44  iEvent.getByToken(srcToken_, jets);
45 
46  // loop jets
47  for (edm::View<pat::Jet>::const_iterator ijet = jets->begin(); ijet != jets->end(); ++ijet) {
48  // fill simple histograms
49  pat::Jet jet = ijet->correctedJet("had", "uds");
50  histContainer_["pt"]->Fill(jet.pt());
51  histContainer_["eta"]->Fill(jet.eta());
52  histContainer_["phi"]->Fill(jet.phi());
53  histContainer_["emf"]->Fill(jet.emEnergyFraction());
54  for (unsigned int i = 0; i < jet.getCaloConstituents().size(); ++i) {
55  histContainer_["dEta"]->Fill(jet.getCaloConstituent(i)->eta() - jet.eta());
56  }
57  }
58 }
59 
61  // register to the TFileService
63 
64  // book histograms:
65  histContainer_["pt"] = fs->make<TH1F>("pt", "pt", 150, 0., 150.);
66  histContainer_["eta"] = fs->make<TH1F>("eta", "eta", 50, 0., 5.);
67  histContainer_["phi"] = fs->make<TH1F>("phi", "phi", 60, 3.14, 3.14);
68  histContainer_["emf"] = fs->make<TH1F>("emf", "emf", 40, 0., 1.);
69  histContainer_["dEta"] = fs->make<TH1F>("dEta", "dEta", 40, 0., 1.);
70 }
71 
73 
static const std::string kSharedResource
Definition: TFileService.h:76
PatZjetsJetAnalyzer(const edm::ParameterSet &)
void analyze(const edm::Event &, const edm::EventSetup &) override
void beginJob() override
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
Definition: Jet.py:1
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< edm::View< pat::Jet > > srcToken_
Analysis-level calorimeter jet class.
Definition: Jet.h:77
HLT enums.
std::map< std::string, TH1F * > histContainer_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88