File indexing completed on 2024-04-06 12:25:26
0001
0002
0003
0004
0005 #include "RecoJets/JetAnalyzers/interface/JetPlotsExample.h"
0006 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
0007 #include "DataFormats/JetReco/interface/PFJetCollection.h"
0008 #include "DataFormats/JetReco/interface/GenJetCollection.h"
0009 #include "DataFormats/JetReco/interface/CaloJet.h"
0010 #include "DataFormats/JetReco/interface/PFJet.h"
0011 #include "DataFormats/JetReco/interface/GenJet.h"
0012 #include "DataFormats/JetReco/interface/JPTJet.h"
0013 #include "DataFormats/JetReco/interface/JPTJetCollection.h"
0014
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include <TFile.h>
0018 #include <cmath>
0019 using namespace edm;
0020 using namespace reco;
0021 using namespace std;
0022
0023 template <class Jet>
0024 JetPlotsExample<Jet>::JetPlotsExample(edm::ParameterSet const& cfg) {
0025 JetAlgorithm = cfg.getParameter<std::string>("JetAlgorithm");
0026 HistoFileName = cfg.getParameter<std::string>("HistoFileName");
0027 NJets = cfg.getParameter<int>("NJets");
0028 }
0029
0030 template <class Jet>
0031 void JetPlotsExample<Jet>::beginJob() {
0032 TString hname;
0033 m_file = new TFile(HistoFileName.c_str(), "RECREATE");
0034
0035 hname = "JetPt";
0036 m_HistNames1D[hname] = new TH1F(hname, hname, 100, 0, 1000);
0037 hname = "JetEta";
0038 m_HistNames1D[hname] = new TH1F(hname, hname, 120, -6, 6);
0039 hname = "JetPhi";
0040 m_HistNames1D[hname] = new TH1F(hname, hname, 100, -M_PI, M_PI);
0041 hname = "NumberOfJets";
0042 m_HistNames1D[hname] = new TH1F(hname, hname, 100, 0, 100);
0043 }
0044
0045 template <class Jet>
0046 void JetPlotsExample<Jet>::analyze(edm::Event const& evt, edm::EventSetup const& iSetup) {
0047
0048 Handle<JetCollection> jets;
0049 evt.getByLabel(JetAlgorithm, jets);
0050 typename JetCollection::const_iterator i_jet;
0051 int index = 0;
0052 TString hname;
0053
0054 hname = "NumberOfJets";
0055 FillHist1D(hname, jets->size());
0056
0057 for (i_jet = jets->begin(); i_jet != jets->end() && index < NJets; ++i_jet) {
0058 hname = "JetPt";
0059 FillHist1D(hname, i_jet->pt());
0060 hname = "JetEta";
0061 FillHist1D(hname, i_jet->eta());
0062 hname = "JetPhi";
0063 FillHist1D(hname, i_jet->phi());
0064 index++;
0065 }
0066 }
0067
0068 template <class Jet>
0069 void JetPlotsExample<Jet>::endJob() {
0070
0071 if (m_file != nullptr) {
0072 m_file->cd();
0073 for (std::map<TString, TH1*>::iterator hid = m_HistNames1D.begin(); hid != m_HistNames1D.end(); hid++)
0074 hid->second->Write();
0075 delete m_file;
0076 m_file = nullptr;
0077 }
0078 }
0079
0080 template <class Jet>
0081 void JetPlotsExample<Jet>::FillHist1D(const TString& histName, const Double_t& value) {
0082 std::map<TString, TH1*>::iterator hid = m_HistNames1D.find(histName);
0083 if (hid == m_HistNames1D.end())
0084 std::cout << "%fillHist -- Could not find histogram with name: " << histName << std::endl;
0085 else
0086 hid->second->Fill(value);
0087 }
0088
0089 #include "FWCore/Framework/interface/MakerMacros.h"
0090
0091 typedef JetPlotsExample<CaloJet> CaloJetPlotsExample;
0092 DEFINE_FWK_MODULE(CaloJetPlotsExample);
0093
0094 typedef JetPlotsExample<GenJet> GenJetPlotsExample;
0095 DEFINE_FWK_MODULE(GenJetPlotsExample);
0096
0097 typedef JetPlotsExample<PFJet> PFJetPlotsExample;
0098 DEFINE_FWK_MODULE(PFJetPlotsExample);
0099
0100 typedef JetPlotsExample<JPTJet> JPTJetPlotsExample;
0101 DEFINE_FWK_MODULE(JPTJetPlotsExample);