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 
15 
18 #include <TFile.h>
19 #include <cmath>
20 using namespace edm;
21 using namespace reco;
22 using namespace std;
24 template<class Jet>
26 {
27  JetAlgorithm = cfg.getParameter<std::string> ("JetAlgorithm");
28  HistoFileName = cfg.getParameter<std::string> ("HistoFileName");
29  NJets = cfg.getParameter<int> ("NJets");
30 }
32 template<class Jet>
34 {
35  TString hname;
36  m_file = new TFile(HistoFileName.c_str(),"RECREATE");
38  hname = "JetPt";
39  m_HistNames1D[hname] = new TH1F(hname,hname,100,0,1000);
40  hname = "JetEta";
41  m_HistNames1D[hname] = new TH1F(hname,hname,120,-6,6);
42  hname = "JetPhi";
43  m_HistNames1D[hname] = new TH1F(hname,hname,100,-M_PI,M_PI);
44  hname = "NumberOfJets";
45  m_HistNames1D[hname] = new TH1F(hname,hname,100,0,100);
46 }
48 template<class Jet>
50 {
53  evt.getByLabel(JetAlgorithm,jets);
54  typename JetCollection::const_iterator i_jet;
55  int index = 0;
56  TString hname;
58  hname = "NumberOfJets";
59  FillHist1D(hname,jets->size());
61  for(i_jet = jets->begin(); i_jet != jets->end() && index < NJets; ++i_jet)
62  {
63  hname = "JetPt";
64  FillHist1D(hname,i_jet->pt());
65  hname = "JetEta";
66  FillHist1D(hname,i_jet->eta());
67  hname = "JetPhi";
68  FillHist1D(hname,i_jet->phi());
69  index++;
70  }
71 }
73 template<class Jet>
75 {
77  if (m_file !=0)
78  {
79  m_file->cd();
80  for (std::map<TString, TH1*>::iterator hid = m_HistNames1D.begin(); hid != m_HistNames1D.end(); hid++)
81  hid->second->Write();
82  delete m_file;
83  m_file = 0;
84  }
85 }
87 template<class Jet>
88 void JetPlotsExample<Jet>::FillHist1D(const TString& histName,const Double_t& value)
89 {
90  std::map<TString, TH1*>::iterator hid=m_HistNames1D.find(histName);
91  if (hid==m_HistNames1D.end())
92  std::cout << "%fillHist -- Could not find histogram with name: " << histName << std::endl;
93  else
94  hid->second->Fill(value);
95 }
T getParameter(std::string const &) const
JetPlotsExample< PFJet > PFJetPlotsExample
JetPlotsExample< GenJet > GenJetPlotsExample
void FillHist1D(const TString &histName, const Double_t &x)
JetPlotsExample< CaloJet > CaloJetPlotsExample
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void analyze(edm::Event const &e, edm::EventSetup const &iSetup)
JetPlotsExample< JPTJet > JPTJetPlotsExample
vector< PseudoJet > jets
JetPlotsExample(edm::ParameterSet const &cfg)
Definition: value.py:1
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:416
#define M_PI
fixed size matrix
HLT enums.