00001 #ifndef HLTriggerOffline_BJet_JetPlots_h
00002 #define HLTriggerOffline_BJet_JetPlots_h
00003
00004
00005 #include <vector>
00006 #include <string>
00007
00008
00009 #include <TDirectory.h>
00010 #include <TH1F.h>
00011
00012
00013 #include "PhysicsTools/UtilAlgos/interface/TFileService.h"
00014 #include "FWCore/ServiceRegistry/interface/Service.h"
00015 #include "DataFormats/JetReco/interface/Jet.h"
00016 #include "DataFormats/JetReco/interface/JetTracksAssociation.h"
00017 #include "DataFormats/TrackReco/interface/Track.h"
00018
00019 static const unsigned int jetEnergyBins = 100;
00020 static const unsigned int jetGeometryBins = 100;
00021 static const unsigned int vertex1DBins = 1000;
00022 static const unsigned int vertex3DBins = 100;
00023
00024
00025 struct JetPlots {
00026 JetPlots()
00027 { }
00028
00029
00030 ~JetPlots()
00031 { }
00032
00033 void init(const std::string & name, const std::string & title, unsigned int energyBins, double minEnergy, double maxEnergy, unsigned int geometryBins, double maxEta, bool hasTracks = false)
00034 {
00035 m_overall = 0.0;
00036 m_name = name;
00037 m_title = title;
00038 m_energyBins = energyBins;
00039 m_minEnergy = minEnergy;
00040 m_maxEnergy = maxEnergy;
00041 m_geometryBins = geometryBins;
00042 m_maxEta = maxEta;
00043 m_hasTracks = hasTracks;
00044
00045
00046 edm::Service<TFileService> fileservice;
00047
00048
00049 bool sumw2 = TH1::GetDefaultSumw2();
00050 TH1::SetDefaultSumw2(true);
00051
00052 m_jetEnergy = fileservice->make<TH1F>((m_name + "_jets_energy").c_str(), (m_title + " jets energy").c_str(), m_energyBins, m_minEnergy, m_maxEnergy);
00053 m_jetET = fileservice->make<TH1F>((m_name + "_jets_ET").c_str(), (m_title + " jets ET").c_str(), m_energyBins, m_minEnergy, m_maxEnergy);
00054 m_jetEta = fileservice->make<TH1F>((m_name + "_jets_eta").c_str(), (m_title + " jets eta").c_str(), m_geometryBins, -m_maxEta, m_maxEta);
00055 m_jetPhi = fileservice->make<TH1F>((m_name + "_jets_phi").c_str(), (m_title + " jets phi").c_str(), m_geometryBins, -M_PI, M_PI);
00056 if (m_hasTracks) {
00057 m_tracksEnergy = fileservice->make<TH1F>((m_name + "_tracks_energy").c_str(), ("Tracks in " + m_title + " jets vs. jet energy").c_str(), m_energyBins, m_minEnergy, m_maxEnergy);
00058 m_tracksET = fileservice->make<TH1F>((m_name + "_tracks_ET").c_str(), ("Tracks in " + m_title + " jets vs. jet ET").c_str(), m_energyBins, m_minEnergy, m_maxEnergy);
00059 m_tracksEta = fileservice->make<TH1F>((m_name + "_tracks_eta").c_str(), ("Tracks in " + m_title + " jets vs. jet eta").c_str(), m_geometryBins, -m_maxEta, m_maxEta);
00060 m_tracksPhi = fileservice->make<TH1F>((m_name + "_tracks_phi").c_str(), ("Tracks in " + m_title + " jets vs. jet phi").c_str(), m_geometryBins, -M_PI, M_PI);
00061 }
00062
00063
00064 TH1::SetDefaultSumw2(sumw2);
00065 }
00066
00067 void fill(const reco::Jet & jet) {
00068 ++m_overall;
00069 m_jetEnergy->Fill(jet.energy());
00070 m_jetET->Fill(jet.et());
00071 m_jetEta->Fill(jet.eta());
00072 m_jetPhi->Fill(jet.phi());
00073 }
00074
00075 void fill(const reco::Jet & jet, const reco::TrackRefVector & tracks) {
00076 fill(jet);
00077 if (m_hasTracks) {
00078 m_tracksEnergy->Fill(jet.energy(), tracks.size());
00079 m_tracksET->Fill(jet.et(), tracks.size());
00080 m_tracksEta->Fill(jet.eta(), tracks.size());
00081 m_tracksPhi->Fill(jet.phi(), tracks.size());
00082 }
00083 }
00084
00085 void save(TDirectory & file) {
00086 m_jetEnergy->SetDirectory(&file);
00087 m_jetET->SetDirectory(&file);
00088 m_jetEta->SetDirectory(&file);
00089 m_jetPhi->SetDirectory(&file);
00090 if (m_hasTracks) {
00091
00092 m_tracksEnergy->Divide(m_jetEnergy);
00093 m_tracksEnergy->SetDirectory(&file);
00094 m_tracksET->Divide(m_jetET);
00095 m_tracksET->SetDirectory(&file);
00096 m_tracksEta->Divide(m_jetEta);
00097 m_tracksEta->SetDirectory(&file);
00098 m_tracksPhi->Divide(m_jetPhi);
00099 m_tracksPhi->SetDirectory(&file);
00100 }
00101 }
00102
00103 JetPlots efficiency(const JetPlots & denominator)
00104 {
00105
00106
00107 JetPlots efficiency;
00108 efficiency.init(m_name + "_vs_" + denominator.m_name, m_title + " vs. " + denominator.m_title, m_energyBins, m_minEnergy, m_maxEnergy, m_geometryBins, m_maxEta, false);
00109 if (denominator.m_overall != 0.0) {
00110 efficiency.m_overall = m_overall / denominator.m_overall;
00111
00112 } else {
00113 efficiency.m_overall = NAN;
00114
00115 }
00116
00117
00118 efficiency.m_jetEnergy->Divide(m_jetEnergy, denominator.m_jetEnergy, 1., 1., "B");
00119 efficiency.m_jetEnergy->SetMinimum(0.0);
00120 efficiency.m_jetEnergy->SetMaximum(1.0);
00121 efficiency.m_jetET->Divide(m_jetET, denominator.m_jetET, 1., 1., "B");
00122 efficiency.m_jetET->SetMinimum(0.0);
00123 efficiency.m_jetET->SetMaximum(1.0);
00124 efficiency.m_jetEta->Divide(m_jetEta, denominator.m_jetEta, 1., 1., "B");
00125 efficiency.m_jetEta->SetMinimum(0.0);
00126 efficiency.m_jetEta->SetMaximum(1.0);
00127 efficiency.m_jetPhi->Divide(m_jetPhi, denominator.m_jetPhi, 1., 1., "B");
00128 efficiency.m_jetPhi->SetMinimum(0.0);
00129 efficiency.m_jetPhi->SetMaximum(1.0);
00130 return efficiency;
00131 }
00132
00133 TH1F * m_jetEnergy;
00134 TH1F * m_jetET;
00135 TH1F * m_jetEta;
00136 TH1F * m_jetPhi;
00137 TH1F * m_tracksEnergy;
00138 TH1F * m_tracksET;
00139 TH1F * m_tracksEta;
00140 TH1F * m_tracksPhi;
00141 double m_overall;
00142 std::string m_name;
00143 std::string m_title;
00144 unsigned int m_geometryBins;
00145 unsigned int m_energyBins;
00146 double m_minEnergy;
00147 double m_maxEnergy;
00148 double m_maxEta;
00149
00150 bool m_hasTracks;
00151 };
00152
00153 #endif // HLTriggerOffline_BJet_JetPlots_h