CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
JetPlotsExample.cc
Go to the documentation of this file.
1 // Implementation of template class: JetPlotsExample
2 // Description: Example of simple EDAnalyzer for jets.
3 // Author: K. Kousouris
4 // Date: 25 - August - 2008
14 
17 #include <TFile.h>
18 #include <cmath>
19 using namespace edm;
20 using namespace reco;
21 using namespace std;
23 template <class Jet>
25  JetAlgorithm = cfg.getParameter<std::string>("JetAlgorithm");
26  HistoFileName = cfg.getParameter<std::string>("HistoFileName");
27  NJets = cfg.getParameter<int>("NJets");
28 }
30 template <class Jet>
32  TString hname;
33  m_file = new TFile(HistoFileName.c_str(), "RECREATE");
35  hname = "JetPt";
36  m_HistNames1D[hname] = new TH1F(hname, hname, 100, 0, 1000);
37  hname = "JetEta";
38  m_HistNames1D[hname] = new TH1F(hname, hname, 120, -6, 6);
39  hname = "JetPhi";
40  m_HistNames1D[hname] = new TH1F(hname, hname, 100, -M_PI, M_PI);
41  hname = "NumberOfJets";
42  m_HistNames1D[hname] = new TH1F(hname, hname, 100, 0, 100);
43 }
45 template <class Jet>
46 void JetPlotsExample<Jet>::analyze(edm::Event const& evt, edm::EventSetup const& iSetup) {
49  evt.getByLabel(JetAlgorithm, jets);
50  typename JetCollection::const_iterator i_jet;
51  int index = 0;
52  TString hname;
54  hname = "NumberOfJets";
55  FillHist1D(hname, jets->size());
57  for (i_jet = jets->begin(); i_jet != jets->end() && index < NJets; ++i_jet) {
58  hname = "JetPt";
59  FillHist1D(hname, i_jet->pt());
60  hname = "JetEta";
61  FillHist1D(hname, i_jet->eta());
62  hname = "JetPhi";
63  FillHist1D(hname, i_jet->phi());
64  index++;
65  }
66 }
68 template <class Jet>
71  if (m_file != nullptr) {
72  m_file->cd();
73  for (std::map<TString, TH1*>::iterator hid = m_HistNames1D.begin(); hid != m_HistNames1D.end(); hid++)
74  hid->second->Write();
75  delete m_file;
76  m_file = nullptr;
77  }
78 }
80 template <class Jet>
81 void JetPlotsExample<Jet>::FillHist1D(const TString& histName, const Double_t& value) {
82  std::map<TString, TH1*>::iterator hid = m_HistNames1D.find(histName);
83  if (hid == m_HistNames1D.end())
84  std::cout << "%fillHist -- Could not find histogram with name: " << histName << std::endl;
85  else
86  hid->second->Fill(value);
87 }
JetPlotsExample< PFJet > PFJetPlotsExample
JetPlotsExample< GenJet > GenJetPlotsExample
void FillHist1D(const TString &histName, const Double_t &x)
tuple cfg
Definition: looper.py:296
JetPlotsExample< CaloJet > CaloJetPlotsExample
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
JetPlotsExample< JPTJet > JPTJetPlotsExample
vector< PseudoJet > jets
JetPlotsExample(edm::ParameterSet const &cfg)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
#define M_PI
void analyze(edm::Event const &e, edm::EventSetup const &iSetup) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void beginJob() override
tuple cout
Definition: gather_cfg.py:144
void endJob() override