CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetCorExample.cc
Go to the documentation of this file.
1 // Implementation of template class: JetCorExample
2 // Description: Example of simple EDAnalyzer correcting jets "on the fly".
3 // Author: K. Kousouris
4 // Date: 25 - August - 2008
15 #include <TFile.h>
16 #include <cmath>
17 using namespace edm;
18 using namespace reco;
19 using namespace std;
21 template<class Jet>
23 {
24  JetAlgorithm = cfg.getParameter<std::string> ("JetAlgorithm");
25  HistoFileName = cfg.getParameter<std::string> ("HistoFileName");
26  JetCorrectionService = cfg.getParameter<std::string> ("JetCorrectionService");
27 }
29 template<class Jet>
31 {
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 = "CorJetPt";
38  m_HistNames1D[hname] = new TH1F(hname,hname,100,0,1000);
39 }
41 template<class Jet>
42 void JetCorExample<Jet>::analyze(edm::Event const& evt, edm::EventSetup const& iSetup)
43 {
46  evt.getByLabel(JetAlgorithm,jets);
47  typename JetCollection::const_iterator i_jet;
48  TString hname;
49  const JetCorrector* corrector = JetCorrector::getJetCorrector (JetCorrectionService,iSetup);
50  double scale;
52  for(i_jet = jets->begin(); i_jet != jets->end(); i_jet++)
53  {
54  scale = corrector->correction(i_jet->p4());
55  hname = "JetPt";
56  FillHist1D(hname,i_jet->pt());
57  hname = "CorJetPt";
58  FillHist1D(hname,scale*i_jet->pt());
59  }
60 }
62 template<class Jet>
64 {
66  if (m_file !=0)
67  {
68  m_file->cd();
69  for (std::map<TString, TH1*>::iterator hid = m_HistNames1D.begin(); hid != m_HistNames1D.end(); hid++)
70  hid->second->Write();
71  delete m_file;
72  m_file = 0;
73  }
74 }
76 template<class Jet>
77 void JetCorExample<Jet>::FillHist1D(const TString& histName,const Double_t& value)
78 {
79  std::map<TString, TH1*>::iterator hid=m_HistNames1D.find(histName);
80  if (hid==m_HistNames1D.end())
81  std::cout << "%fillHist -- Could not find histogram with name: " << histName << std::endl;
82  else
83  hid->second->Fill(value);
84 }
T getParameter(std::string const &) const
JetCorExample(edm::ParameterSet const &cfg)
virtual double correction(const LorentzVector &fJet) const =0
get correction using Jet information only
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void analyze(edm::Event const &e, edm::EventSetup const &iSetup)
vector< PseudoJet > jets
JetCorExample< CaloJet > CaloJetCorExample
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
static const JetCorrector * getJetCorrector(const std::string &fName, const edm::EventSetup &fSetup)
retrieve corrector from the event setup. troughs exception if something is missing ...
Definition: JetCorrector.cc:51
JetCorExample< PFJet > PFJetCorExample
tuple cout
Definition: gather_cfg.py:121
void FillHist1D(const TString &histName, const Double_t &x)