CMS 3D CMS Logo

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 }
CaloJetCollection.h
GenJetCollection.h
CaloJet.h
JetPlotsExample
Definition: JetPlotsExample.h:15
JetPlotsExample::JetPlotsExample
JetPlotsExample(edm::ParameterSet const &cfg)
Definition: JetPlotsExample.cc:24
edm
HLT enums.
Definition: AlignableModifier.h:19
GenJetPlotsExample
JetPlotsExample< GenJet > GenJetPlotsExample
Definition: JetPlotsExample.cc:94
gather_cfg.cout
cout
Definition: gather_cfg.py:144
PFJet.h
PFJetCollection.h
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
JetPlotsExample::analyze
void analyze(edm::Event const &e, edm::EventSetup const &iSetup) override
Definition: JetPlotsExample.cc:46
MakerMacros.h
JetPlotsExample.h
CaloJetPlotsExample
JetPlotsExample< CaloJet > CaloJetPlotsExample
Definition: JetPlotsExample.cc:91
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::Event::getByLabel
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:496
JPTJetCollection.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
JetPlotsExample::FillHist1D
void FillHist1D(const TString &histName, const Double_t &x)
Definition: JetPlotsExample.cc:81
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
JetPlotsExample::endJob
void endJob() override
Definition: JetPlotsExample.cc:69
value
Definition: value.py:1
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
edm::EventSetup
Definition: EventSetup.h:58
looper.cfg
cfg
Definition: looper.py:297
PFJetPlotsExample
JetPlotsExample< PFJet > PFJetPlotsExample
Definition: JetPlotsExample.cc:97
std
Definition: JetResolutionObject.h:76
JPTJetPlotsExample
JetPlotsExample< JPTJet > JPTJetPlotsExample
Definition: JetPlotsExample.cc:100
JetPlotsExample::beginJob
void beginJob() override
Definition: JetPlotsExample.cc:31
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
GenJet.h
ParameterSet.h
edm::Event
Definition: Event.h:73
JPTJet.h