00001
00011 #include <vector>
00012 #include <string>
00013 #include <algorithm>
00014
00015 #include "DQMServices/Core/interface/DQMStore.h"
00016 #include "DQMServices/Core/interface/MonitorElement.h"
00017 #include "FWCore/Framework/interface/Event.h"
00018 #include "FWCore/Framework/interface/EventSetup.h"
00019 #include "FWCore/Framework/interface/LuminosityBlock.h"
00020 #include "FWCore/Framework/interface/Run.h"
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 #include "FWCore/Utilities/interface/Exception.h"
00023 #include "DataFormats/Common/interface/Handle.h"
00024 #include "DataFormats/Common/interface/View.h"
00025 #include "DataFormats/Common/interface/TriggerResults.h"
00026 #include "DataFormats/BTauReco/interface/SoftLeptonTagInfo.h"
00027 #include "DataFormats/BTauReco/interface/JetTag.h"
00028 #include "DataFormats/TrackReco/interface/Track.h"
00029 #include "DataFormats/MuonReco/interface/Muon.h"
00030 #include "DataFormats/JetReco/interface/Jet.h"
00031 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00032 #include "HLTMonBTagMuSource.h"
00033
00034 HLTMonBTagMuSource::HLTMonBTagMuSource(const edm::ParameterSet & config) :
00035 m_L1Filter( config.getParameter<edm::InputTag>("L1Filter") ),
00036 m_L2Filter( config.getParameter<edm::InputTag>("L2Filter") ),
00037 m_L25Filter( config.getParameter<edm::InputTag>("L25Filter") ),
00038 m_L3Filter( config.getParameter<edm::InputTag>("L3Filter") ),
00039 m_L2Jets( config.getParameter<edm::InputTag>("L2Jets") ),
00040 m_L25TagInfo( config.getParameter<edm::InputTag>("L25TagInfo") ),
00041 m_L25JetTags( config.getParameter<edm::InputTag>("L25JetTags") ),
00042 m_L3TagInfo( config.getParameter<edm::InputTag>("L3TagInfo") ),
00043 m_L3JetTags( config.getParameter<edm::InputTag>("L3JetTags") ),
00044 m_triggerResults( config.getParameter<edm::InputTag>("triggerResults") ),
00045 m_processName( config.getParameter<std::string>("processName") ),
00046 m_pathName( config.getParameter<std::string>("pathName") ),
00047 m_monitorName( config.getParameter<std::string>("monitorName" ) ),
00048 m_outputFile( config.getUntrackedParameter<std::string>("outputFile", "HLTBJetDQM.root") ),
00049 m_storeROOT( config.getUntrackedParameter<bool>("storeROOT", false) ),
00050 m_size( config.getParameter<unsigned int>("interestingJets") ),
00051 m_dbe(),
00052 m_init( false ),
00053 m_pathIndex( (unsigned int) -1 ),
00054 m_L1FilterIndex( (unsigned int) -1 ),
00055 m_L2FilterIndex( (unsigned int) -1 ),
00056 m_L25FilterIndex( (unsigned int) -1 ),
00057 m_L3FilterIndex( (unsigned int) -1 ),
00058
00059
00060 m_plotRates(0),
00061
00062 m_plotL2JetsEnergy(0),
00063 m_plotL2JetsET(0),
00064 m_plotL2JetsEta(0),
00065 m_plotL2JetsPhi(0),
00066 m_plotL2JetsEtaPhi(0),
00067 m_plotL2JetsEtaET(0),
00068 m_plotL25JetsEnergy(0),
00069 m_plotL25JetsET(0),
00070 m_plotL25JetsEta(0),
00071 m_plotL25JetsPhi(0),
00072 m_plotL25JetsEtaPhi(0),
00073 m_plotL25JetsEtaET(0),
00074 m_plotL25MuonMultiplicity(0),
00075 m_plotL25MuonHits(0),
00076 m_plotL25MuonChi2(0),
00077 m_plotL25MuonEtaPhi(0),
00078 m_plotL25MuonEtaPT(0),
00079 m_plotL25MuonIP2dSig(0),
00080 m_plotL25MuonIP3dSig(0),
00081 m_plotL25MuonPtRel(0),
00082 m_plotL25MuonDeltaR(0),
00083 m_plotL25Discriminator(0),
00084 m_plotL3JetsEnergy(0),
00085 m_plotL3JetsET(0),
00086 m_plotL3JetsEta(0),
00087 m_plotL3JetsPhi(0),
00088 m_plotL3JetsEtaPhi(0),
00089 m_plotL3JetsEtaET(0),
00090 m_plotL3MuonMultiplicity(0),
00091 m_plotL3MuonHits(0),
00092 m_plotL3MuonChi2(0),
00093 m_plotL3MuonEtaPhi(0),
00094 m_plotL3MuonEtaPT(0),
00095 m_plotL3MuonIP2dSig(0),
00096 m_plotL3MuonIP3dSig(0),
00097 m_plotL3MuonPtRel(0),
00098 m_plotL3MuonDeltaR(0),
00099 m_plotL3Discriminator(0)
00100 {
00101 }
00102
00103 HLTMonBTagMuSource::~HLTMonBTagMuSource(void) {
00104 }
00105
00106 void HLTMonBTagMuSource::beginJob() {
00107 if (not m_dbe.isAvailable())
00108 return;
00109
00110 m_dbe->setVerbose(0);
00111 m_dbe->setCurrentFolder(m_monitorName + "/" + m_pathName);
00112
00113 m_plotRates = book("Rates", "Rates", 6, 0., 6);
00114
00115 m_plotL2JetsEnergy = book("L2_jet_energy", "L2 jet energy", 300, 0., 300., "GeV");
00116 m_plotL2JetsET = book("L2_jet_eT", "L2 jet eT", 300, 0., 300., "GeV");
00117 m_plotL2JetsEta = book("L2_jet_eta", "L2 jet eta", 60, -3.0, 3.0, "#eta");
00118 m_plotL2JetsPhi = book("L2_jet_phi", "L2 jet phi", 64, -3.2, 3.2, "#phi");
00119 m_plotL2JetsEtaPhi = book("L2_jet_eta_phi", "L2 jet eta vs. phi", 60, -3.0, 3.0, 64, -3.2, 3.2, "#eta", "#phi");
00120 m_plotL2JetsEtaET = book("L2_jet_eta_et", "L2 jet eta vs. eT", 60, -3.0, 3.0, 300, 0., 300., "#eta", "GeV");
00121 m_plotL25JetsEnergy = book("L25_jet_energy", "L2.5 jet Energy", 300, 0., 300., "GeV");
00122 m_plotL25JetsET = book("L25_jet_eT", "L2.5 jet ET", 300, 0., 300., "GeV");
00123 m_plotL25JetsEta = book("L25_jet_eta", "L2.5 jet eta", 60, -3.0, 3.0, "#eta");
00124 m_plotL25JetsPhi = book("L25_jet_phi", "L2.5 jet phi", 64, -3.2, 3.2, "#phi");
00125 m_plotL25JetsEtaPhi = book("L25_jet_eta_phi", "L2.5 jet eta vs. phi", 60, -3.0, 3.0, 64, -3.2, 3.2, "#eta", "#phi");
00126 m_plotL25JetsEtaET = book("L25_jet_eta_et", "L2.5 jet eta vs. eT", 60, -3.0, 3.0, 300, 0., 300., "#eta", "GeV");
00127 m_plotL25MuonMultiplicity = book("L25_muon_multiplicity", "L2.5 muons multiplicity", 5, 0, 5);
00128 m_plotL25MuonHits = book("L25_muon_hits", "L2.5 muons n. of hits", 40, 0, 40);
00129 m_plotL25MuonChi2 = book("L25_muon_chi2", "L2.5 muons chi2/DoF", 20, 0., 20., "#chi^2/DoF");
00130 m_plotL25MuonEtaPhi = book("L25_muon_eta_phi", "L2.5 muons eta vs. phi", 60, -3.0, 3.0, 64, -3.2, 3.2, "#eta", "#phi");
00131 m_plotL25MuonEtaPT = book("L25_muon_eta_pt", "L2.5 muons eta vs. pT", 60, -3.0, 3.0, 50, 0., 50., "#eta", "GeV");
00132 m_plotL25MuonIP2dSig = book("L25_muon_IP2dSig", "L2.5 muons 2D SIP", 80, -30., 50.);
00133 m_plotL25MuonIP3dSig = book("L25_muon_IP3dSig", "L2.5 muons 3D SIP", 80, -30., 50.);
00134 m_plotL25MuonPtRel = book("L25_muon_PtRel", "L2.5 muons pT_rel", 40, 0., 20., "GeV");
00135 m_plotL25MuonDeltaR = book("L25_muon_DeltaR", "L2.5 muons DeltaR", 50, 0., 0.5);
00136 m_plotL25Discriminator = book("L25_discriminator", "L2.5 b-tag discriminator", 80, -30., 50.);
00137 m_plotL3JetsEnergy = book("L3_jet_energy", "L3 jet Energy", 300, 0., 300., "GeV");
00138 m_plotL3JetsET = book("L3_jet_eT", "L3 jet ET", 300, 0., 300., "GeV");
00139 m_plotL3JetsEta = book("L3_jet_eta", "L3 jet eta", 60, -3.0, 3.0, "#eta");
00140 m_plotL3JetsPhi = book("L3_jet_phi", "L3 jet phi", 64, -3.2, 3.2, "#phi");
00141 m_plotL3JetsEtaPhi = book("L3_jet_eta_phi", "L3 jet eta vs. phi", 60, -3.0, 3.0, 64, -3.2, 3.2, "#eta", "#phi");
00142 m_plotL3JetsEtaET = book("L3_jet_eta_et", "L3 jet eta vs. eT", 60, -3.0, 3.0, 300, 0., 300., "#eta", "GeV");
00143 m_plotL3MuonMultiplicity = book("L3_muon_multiplicity", "L3 muons multiplicity", 25, 0, 25);
00144 m_plotL3MuonHits = book("L3_muon_hits", "L3 muons n. of hits", 20, 0, 20);
00145 m_plotL3MuonChi2 = book("L3_muon_chi2", "L3 muons chi2/DoF", 20, 0., 20., "#chi^2/DoF");
00146 m_plotL3MuonEtaPhi = book("L3_muon_eta_phi", "L3 muons eta vs. phi", 60, -3.0, 3.0, 64, -3.2, 3.2, "#eta", "#phi");
00147 m_plotL3MuonEtaPT = book("L3_muon_eta_pt", "L3 muons eta vs. pT", 60, -3.0, 3.0, 50, 0., 50., "#eta", "GeV");
00148 m_plotL3MuonIP2dSig = book("L3_muon_IP2dSig", "L3 muons 2D SIP", 80, -30., 50.);
00149 m_plotL3MuonIP3dSig = book("L3_muon_IP3dSig", "L3 muons 3D SIP", 80, -30., 50.);
00150 m_plotL3MuonPtRel = book("L3_muon_PtRel", "L3 muons pT_rel", 40, 0., 20., "GeV");
00151 m_plotL3MuonDeltaR = book("L3_muon_DeltaR", "L3 muons DeltaR", 50, 0., 0.5);
00152 m_plotL3Discriminator = book("L3_discriminator", "L3 b-tag discriminator", 80, -30., 50.);
00153 }
00154
00155 void HLTMonBTagMuSource::endJob() {
00156 if (m_dbe.isAvailable() and m_storeROOT)
00157 m_dbe->save(m_outputFile);
00158 }
00159
00160 void HLTMonBTagMuSource::beginRun(const edm::Run & run, const edm::EventSetup & setup) {
00161
00162 HLTConfigProvider configProvider;
00163
00164 bool changed = false;
00165 if (not configProvider.init(run, setup, m_processName, changed))
00166 {
00167 edm::LogWarning("ConfigurationError") << "process name \"" << m_processName << "\" is not valid.";
00168 m_init = false;
00169 return;
00170 }
00171
00172 m_pathIndex = configProvider.triggerIndex( m_pathName );
00173 if (m_pathIndex == configProvider.size())
00174 {
00175 edm::LogWarning("ConfigurationError") << "trigger name \"" << m_pathName << "\" is not valid.";
00176 m_init = false;
00177 return;
00178 }
00179
00180 m_init = true;
00181
00182
00183
00184 unsigned int size = configProvider.size( m_pathIndex );
00185
00186 m_L1FilterIndex = configProvider.moduleIndex( m_pathIndex, m_L1Filter.encode() );
00187 if (m_L1FilterIndex == size)
00188 edm::LogWarning("ConfigurationError") << "L1 filter \"" << m_L1Filter << "\" is not valid.";
00189
00190 m_L2FilterIndex = configProvider.moduleIndex( m_pathIndex, m_L2Filter.encode() );
00191 if (m_L2FilterIndex == size)
00192 edm::LogWarning("ConfigurationError") << "L2 filter \"" << m_L2Filter << "\" is not valid.";
00193
00194 m_L25FilterIndex = configProvider.moduleIndex( m_pathIndex, m_L25Filter.encode() );
00195 if (m_L25FilterIndex == size)
00196 edm::LogWarning("ConfigurationError") << "L2.5 filter \"" << m_L25Filter << "\" is not valid.";
00197
00198 m_L3FilterIndex = configProvider.moduleIndex( m_pathIndex, m_L3Filter.encode() );
00199 if (m_L3FilterIndex == size)
00200 edm::LogWarning("ConfigurationError") << "L3 filter \"" << m_L3Filter << "\" is not valid.";
00201 }
00202
00203 void HLTMonBTagMuSource::endRun(const edm::Run & run, const edm::EventSetup & setup) {
00204 }
00205
00206 void HLTMonBTagMuSource::beginLuminosityBlock(const edm::LuminosityBlock & lumi, const edm::EventSetup & setup) {
00207 }
00208
00209 void HLTMonBTagMuSource::endLuminosityBlock(const edm::LuminosityBlock & lumi, const edm::EventSetup & setup) {
00210 }
00211
00212 void HLTMonBTagMuSource::analyze(const edm::Event & event, const edm::EventSetup & setup) {
00213 if (not m_dbe.isAvailable())
00214 return;
00215
00216 if (not m_init)
00217 return;
00218
00219 edm::Handle<edm::TriggerResults> h_triggerResults;
00220 edm::Handle<edm::View<reco::Jet> > h_L2Jets;
00221 edm::Handle<reco::SoftLeptonTagInfoCollection> h_L25TagInfo;
00222 edm::Handle<reco::JetTagCollection> h_L25JetTags;
00223 edm::Handle<reco::SoftLeptonTagInfoCollection> h_L3TagInfo;
00224 edm::Handle<reco::JetTagCollection> h_L3JetTags;
00225
00226 event.getByLabel(m_triggerResults, h_triggerResults);
00227 event.getByLabel(m_L2Jets, h_L2Jets);
00228 event.getByLabel(m_L25TagInfo, h_L25TagInfo);
00229 event.getByLabel(m_L25JetTags, h_L25JetTags);
00230 event.getByLabel(m_L3TagInfo, h_L3TagInfo);
00231 event.getByLabel(m_L3JetTags, h_L3JetTags);
00232
00233
00234 bool wasrun = false;
00235 unsigned int latest = 0;
00236 bool accept = false;
00237 if (h_triggerResults.isValid()) {
00238 wasrun = h_triggerResults->wasrun( m_pathIndex );
00239 latest = h_triggerResults->index( m_pathIndex );
00240 accept = h_triggerResults->accept( m_pathIndex );
00241 }
00242 if (wasrun)
00243 m_plotRates->Fill( 0. );
00244 if (latest > m_L1FilterIndex)
00245 m_plotRates->Fill( 1. );
00246 if (latest > m_L2FilterIndex)
00247 m_plotRates->Fill( 2. );
00248 if (latest > m_L25FilterIndex)
00249 m_plotRates->Fill( 3. );
00250 if (latest > m_L3FilterIndex)
00251 m_plotRates->Fill( 4. );
00252 if (accept)
00253 m_plotRates->Fill( 5. );
00254
00255 if ((latest > m_L1FilterIndex) and h_L2Jets.isValid()) {
00256 unsigned int size = std::min((unsigned int) h_L2Jets->size(), m_size);
00257 for (unsigned int i = 0; i < size; ++i) {
00258 const reco::Jet & jet = (*h_L2Jets)[i];
00259 m_plotL2JetsEnergy->Fill( jet.energy() );
00260 m_plotL2JetsET->Fill( jet.et() );
00261 m_plotL2JetsEta->Fill( jet.eta() );
00262 m_plotL2JetsPhi->Fill( jet.phi() );
00263 m_plotL2JetsEtaPhi->Fill( jet.eta(), jet.phi() );
00264 m_plotL2JetsEtaET->Fill( jet.eta(), jet.et() );
00265 }
00266 }
00267 if ((latest > m_L2FilterIndex) and h_L25TagInfo.isValid() and h_L25JetTags.isValid()) {
00268 unsigned int size = std::min((unsigned int) h_L25TagInfo->size(), m_size);
00269 for (unsigned int i = 0; i < size; ++i) {
00270 const reco::SoftLeptonTagInfo & info = (*h_L25TagInfo)[i];
00271 const reco::Jet & jet = * info.jet();
00272 const reco::JetTag & tag = (*h_L25JetTags)[info.jet().key()];
00273 m_plotL25JetsEnergy->Fill( jet.energy() );
00274 m_plotL25JetsET->Fill( jet.et() );
00275 m_plotL25JetsEta->Fill( jet.eta() );
00276 m_plotL25JetsPhi->Fill( jet.phi() );
00277 m_plotL25JetsEtaPhi->Fill( jet.eta(), jet.phi() );
00278 m_plotL25JetsEtaET->Fill( jet.eta(), jet.et() );
00279 m_plotL25MuonMultiplicity->Fill( info.leptons() );
00280 for (unsigned int t = 0; t < info.leptons(); ++t) {
00281 m_plotL25MuonHits->Fill( info.lepton(t)->numberOfValidHits() );
00282 m_plotL25MuonChi2->Fill( info.lepton(t)->normalizedChi2() );
00283 m_plotL25MuonEtaPhi->Fill( info.lepton(t)->eta(), info.lepton(t)->phi() );
00284 m_plotL25MuonEtaPT->Fill( info.lepton(t)->eta(), info.lepton(t)->pt() );
00285 m_plotL25MuonIP2dSig->Fill( info.properties(t).sip2d );
00286 m_plotL25MuonIP3dSig->Fill( info.properties(t).sip3d );
00287 m_plotL25MuonPtRel->Fill( info.properties(t).ptRel );
00288 m_plotL25MuonDeltaR->Fill( info.properties(t).deltaR );
00289 }
00290 m_plotL25Discriminator->Fill( tag.second );
00291 }
00292 }
00293 if ((latest > m_L25FilterIndex) and h_L3TagInfo.isValid() and h_L3JetTags.isValid()) {
00294 unsigned int size = std::min((unsigned int) h_L3TagInfo->size(), m_size);
00295 for (unsigned int i = 0; i < size; ++i) {
00296 const reco::SoftLeptonTagInfo & info = (*h_L3TagInfo)[i];
00297 const reco::Jet & jet = * info.jet();
00298 const reco::JetTag & tag = (*h_L3JetTags)[info.jet().key()];
00299 m_plotL3JetsEnergy->Fill( jet.energy() );
00300 m_plotL3JetsET->Fill( jet.et() );
00301 m_plotL3JetsEta->Fill( jet.eta() );
00302 m_plotL3JetsPhi->Fill( jet.phi() );
00303 m_plotL3JetsEtaPhi->Fill( jet.eta(), jet.phi() );
00304 m_plotL3JetsEtaET->Fill( jet.eta(), jet.et() );
00305 m_plotL3MuonMultiplicity->Fill( info.leptons() );
00306 for (unsigned int t = 0; t < info.leptons(); ++t) {
00307 m_plotL3MuonHits->Fill( info.lepton(t)->numberOfValidHits() );
00308 m_plotL3MuonChi2->Fill( info.lepton(t)->normalizedChi2() );
00309 m_plotL3MuonEtaPhi->Fill( info.lepton(t)->eta(), info.lepton(t)->phi() );
00310 m_plotL3MuonEtaPT->Fill( info.lepton(t)->eta(), info.lepton(t)->pt() );
00311 m_plotL3MuonIP2dSig->Fill( info.properties(t).sip2d );
00312 m_plotL3MuonIP3dSig->Fill( info.properties(t).sip3d );
00313 m_plotL3MuonPtRel->Fill( info.properties(t).ptRel );
00314 m_plotL3MuonDeltaR->Fill( info.properties(t).deltaR );
00315 }
00316 m_plotL3Discriminator->Fill( tag.second );
00317 }
00318 }
00319 }
00320
00321 MonitorElement * HLTMonBTagMuSource::book(const std::string & name, const std::string & title , int x_bins, double x_min, double x_max, const char * x_axis) {
00322 MonitorElement * element = m_dbe->book1D(name, title, x_bins, x_min, x_max);
00323 if (x_axis)
00324 element->setAxisTitle(x_axis, 1);
00325 return element;
00326 }
00327
00328 MonitorElement * HLTMonBTagMuSource::book(const std::string & name, const std::string & title , int x_bins, double x_min, double x_max, int y_bins, double y_min, double y_max, const char * x_axis, const char * y_axis) {
00329 MonitorElement * element = m_dbe->book2D(name, title, x_bins, x_min, x_max, y_bins, y_min, y_max);
00330 if (x_axis)
00331 element->setAxisTitle(x_axis, 1);
00332 if (y_axis)
00333 element->setAxisTitle(y_axis, 2);
00334 return element;
00335 }
00336
00337
00338 #include "FWCore/Framework/interface/MakerMacros.h"
00339 DEFINE_FWK_MODULE(HLTMonBTagMuSource);