Go to the documentation of this file.00001
00002
00003
00004
00005 #include "RecoJets/JetAnalyzers/interface/JetPlotsExample.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 <TFile.h>
00015 #include <cmath>
00016 using namespace edm;
00017 using namespace reco;
00018 using namespace std;
00020 template<class Jet>
00021 JetPlotsExample<Jet>::JetPlotsExample(edm::ParameterSet const& cfg)
00022 {
00023 JetAlgorithm = cfg.getParameter<std::string> ("JetAlgorithm");
00024 HistoFileName = cfg.getParameter<std::string> ("HistoFileName");
00025 NJets = cfg.getParameter<int> ("NJets");
00026 }
00028 template<class Jet>
00029 void JetPlotsExample<Jet>::beginJob()
00030 {
00031 TString hname;
00032 m_file = new TFile(HistoFileName.c_str(),"RECREATE");
00034 hname = "JetPt";
00035 m_HistNames1D[hname] = new TH1F(hname,hname,100,0,1000);
00036 hname = "JetEta";
00037 m_HistNames1D[hname] = new TH1F(hname,hname,120,-6,6);
00038 hname = "JetPhi";
00039 m_HistNames1D[hname] = new TH1F(hname,hname,100,-M_PI,M_PI);
00040 hname = "NumberOfJets";
00041 m_HistNames1D[hname] = new TH1F(hname,hname,100,0,100);
00042 }
00044 template<class Jet>
00045 void JetPlotsExample<Jet>::analyze(edm::Event const& evt, edm::EventSetup const& iSetup)
00046 {
00048 Handle<JetCollection> jets;
00049 evt.getByLabel(JetAlgorithm,jets);
00050 typename JetCollection::const_iterator i_jet;
00051 int index = 0;
00052 TString hname;
00054 hname = "NumberOfJets";
00055 FillHist1D(hname,jets->size());
00057 for(i_jet = jets->begin(); i_jet != jets->end() && index < NJets; ++i_jet)
00058 {
00059 hname = "JetPt";
00060 FillHist1D(hname,i_jet->pt());
00061 hname = "JetEta";
00062 FillHist1D(hname,i_jet->eta());
00063 hname = "JetPhi";
00064 FillHist1D(hname,i_jet->phi());
00065 index++;
00066 }
00067 }
00069 template<class Jet>
00070 void JetPlotsExample<Jet>::endJob()
00071 {
00073 if (m_file !=0)
00074 {
00075 m_file->cd();
00076 for (std::map<TString, TH1*>::iterator hid = m_HistNames1D.begin(); hid != m_HistNames1D.end(); hid++)
00077 hid->second->Write();
00078 delete m_file;
00079 m_file = 0;
00080 }
00081 }
00083 template<class Jet>
00084 void JetPlotsExample<Jet>::FillHist1D(const TString& histName,const Double_t& value)
00085 {
00086 std::map<TString, TH1*>::iterator hid=m_HistNames1D.find(histName);
00087 if (hid==m_HistNames1D.end())
00088 std::cout << "%fillHist -- Could not find histogram with name: " << histName << std::endl;
00089 else
00090 hid->second->Fill(value);
00091 }
00093 #include "FWCore/Framework/interface/MakerMacros.h"
00095 typedef JetPlotsExample<CaloJet> CaloJetPlotsExample;
00096 DEFINE_FWK_MODULE(CaloJetPlotsExample);
00098 typedef JetPlotsExample<GenJet> GenJetPlotsExample;
00099 DEFINE_FWK_MODULE(GenJetPlotsExample);
00101 typedef JetPlotsExample<PFJet> PFJetPlotsExample;
00102 DEFINE_FWK_MODULE(PFJetPlotsExample);