Go to the documentation of this file.00001
00002
00003
00004
00005 #include "RecoJets/JetAnalyzers/interface/JetCorExample.h"
00006 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00007 #include "DataFormats/JetReco/interface/PFJetCollection.h"
00008 #include "DataFormats/JetReco/interface/GenJetCollection.h"
00009 #include "DataFormats/JetReco/interface/CaloJet.h"
00010 #include "DataFormats/JetReco/interface/PFJet.h"
00011 #include "DataFormats/JetReco/interface/GenJet.h"
00012 #include "FWCore/Framework/interface/Event.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
00015 #include <TFile.h>
00016 #include <cmath>
00017 using namespace edm;
00018 using namespace reco;
00019 using namespace std;
00021 template<class Jet>
00022 JetCorExample<Jet>::JetCorExample(edm::ParameterSet const& cfg)
00023 {
00024 JetAlgorithm = cfg.getParameter<std::string> ("JetAlgorithm");
00025 HistoFileName = cfg.getParameter<std::string> ("HistoFileName");
00026 JetCorrectionService = cfg.getParameter<std::string> ("JetCorrectionService");
00027 }
00029 template<class Jet>
00030 void JetCorExample<Jet>::beginJob()
00031 {
00032 TString hname;
00033 m_file = new TFile(HistoFileName.c_str(),"RECREATE");
00035 hname = "JetPt";
00036 m_HistNames1D[hname] = new TH1F(hname,hname,100,0,1000);
00037 hname = "CorJetPt";
00038 m_HistNames1D[hname] = new TH1F(hname,hname,100,0,1000);
00039 }
00041 template<class Jet>
00042 void JetCorExample<Jet>::analyze(edm::Event const& evt, edm::EventSetup const& iSetup)
00043 {
00045 Handle<JetCollection> jets;
00046 evt.getByLabel(JetAlgorithm,jets);
00047 typename JetCollection::const_iterator i_jet;
00048 TString hname;
00049 const JetCorrector* corrector = JetCorrector::getJetCorrector (JetCorrectionService,iSetup);
00050 double scale;
00052 for(i_jet = jets->begin(); i_jet != jets->end(); i_jet++)
00053 {
00054 scale = corrector->correction(i_jet->p4());
00055 hname = "JetPt";
00056 FillHist1D(hname,i_jet->pt());
00057 hname = "CorJetPt";
00058 FillHist1D(hname,scale*i_jet->pt());
00059 }
00060 }
00062 template<class Jet>
00063 void JetCorExample<Jet>::endJob()
00064 {
00066 if (m_file !=0)
00067 {
00068 m_file->cd();
00069 for (std::map<TString, TH1*>::iterator hid = m_HistNames1D.begin(); hid != m_HistNames1D.end(); hid++)
00070 hid->second->Write();
00071 delete m_file;
00072 m_file = 0;
00073 }
00074 }
00076 template<class Jet>
00077 void JetCorExample<Jet>::FillHist1D(const TString& histName,const Double_t& value)
00078 {
00079 std::map<TString, TH1*>::iterator hid=m_HistNames1D.find(histName);
00080 if (hid==m_HistNames1D.end())
00081 std::cout << "%fillHist -- Could not find histogram with name: " << histName << std::endl;
00082 else
00083 hid->second->Fill(value);
00084 }
00086 #include "FWCore/Framework/interface/MakerMacros.h"
00088 typedef JetCorExample<CaloJet> CaloJetCorExample;
00089 DEFINE_FWK_MODULE(CaloJetCorExample);
00091 typedef JetCorExample<PFJet> PFJetCorExample;
00092 DEFINE_FWK_MODULE(PFJetCorExample);