From 4ae9346cd2aeeb0552b7049ffe517fd463faeaa7 Mon Sep 17 00:00:00 2001 From: mmusich Date: Thu, 16 Jun 2022 09:34:37 +0200 Subject: [PATCH] CalibTracker: fallback to the OnlineLuminosityRecord when SCAL is not available --- .../plugins/ShallowEventDataProducer.cc | 12 +++++++--- .../plugins/ShallowEventDataProducer.h | 2 ++ .../python/ShallowEventDataProducer_cfi.py | 3 ++- .../SiStripHitEfficiency/plugins/HitEff.cc | 19 +++++++++++---- .../SiStripHitEfficiency/plugins/HitEff.h | 2 ++ .../plugins/SiStripHitEfficiencyWorker.cc | 23 +++++++++++++++---- .../python/SiStripHitEff_cff.py | 1 + 7 files changed, 48 insertions(+), 14 deletions(-) diff --git a/CalibTracker/SiStripCommon/plugins/ShallowEventDataProducer.cc b/CalibTracker/SiStripCommon/plugins/ShallowEventDataProducer.cc index 305b067dff969..135ef3988a8ff 100644 --- a/CalibTracker/SiStripCommon/plugins/ShallowEventDataProducer.cc +++ b/CalibTracker/SiStripCommon/plugins/ShallowEventDataProducer.cc @@ -20,6 +20,7 @@ ShallowEventDataProducer::ShallowEventDataProducer(const edm::ParameterSet& iCon #endif scalerToken_ = consumes(iConfig.getParameter("lumiScalers")); + metaDataToken_ = consumes(iConfig.getParameter("metadata")); } void ShallowEventDataProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const { @@ -57,15 +58,20 @@ void ShallowEventDataProducer::produce(edm::StreamID, edm::Event& iEvent, const #endif // Luminosity informations - edm::Handle lumiScalers; + edm::Handle lumiScalers = iEvent.getHandle(scalerToken_); + edm::Handle metaData = iEvent.getHandle(metaDataToken_); + float instLumi_ = 0; float PU_ = 0; - iEvent.getByToken(scalerToken_, lumiScalers); - if (lumiScalers.isValid()) { + + if (lumiScalers.isValid() && !lumiScalers->empty()) { if (lumiScalers->begin() != lumiScalers->end()) { instLumi_ = lumiScalers->begin()->instantLumi(); PU_ = lumiScalers->begin()->pileup(); } + } else if (metaData.isValid()) { + instLumi_ = metaData->instLumi(); + PU_ = metaData->avgPileUp(); } else { edm::LogInfo("ShallowEventDataProducer") << "LumiScalers collection not found in the event; will write dummy values"; diff --git a/CalibTracker/SiStripCommon/plugins/ShallowEventDataProducer.h b/CalibTracker/SiStripCommon/plugins/ShallowEventDataProducer.h index a810f17b7743e..e112ecb7c5d8d 100644 --- a/CalibTracker/SiStripCommon/plugins/ShallowEventDataProducer.h +++ b/CalibTracker/SiStripCommon/plugins/ShallowEventDataProducer.h @@ -5,6 +5,7 @@ #include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Utilities/interface/EDPutToken.h" #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h" +#include "DataFormats/OnlineMetaData/interface/OnlineLuminosityRecord.h" #include "DataFormats/Scalers/interface/LumiScalers.h" #include @@ -15,6 +16,7 @@ class ShallowEventDataProducer : public edm::global::EDProducer<> { private: void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override; edm::EDGetTokenT scalerToken_; + edm::EDGetTokenT metaDataToken_; edm::EDPutTokenT runPut_; edm::EDPutTokenT eventPut_; diff --git a/CalibTracker/SiStripCommon/python/ShallowEventDataProducer_cfi.py b/CalibTracker/SiStripCommon/python/ShallowEventDataProducer_cfi.py index c8dfe742849fc..b61a17fd9b0ae 100644 --- a/CalibTracker/SiStripCommon/python/ShallowEventDataProducer_cfi.py +++ b/CalibTracker/SiStripCommon/python/ShallowEventDataProducer_cfi.py @@ -3,5 +3,6 @@ shallowEventRun = cms.EDProducer( "ShallowEventDataProducer", trigRecord = cms.InputTag('gtDigis'), - lumiScalers = cms.InputTag("scalersRawToDigi") + lumiScalers = cms.InputTag("scalersRawToDigi"), + metadata = cms.InputTag('onlineMetaDataDigis') ) diff --git a/CalibTracker/SiStripHitEfficiency/plugins/HitEff.cc b/CalibTracker/SiStripHitEfficiency/plugins/HitEff.cc index 94a2400a61227..e046142acc80c 100644 --- a/CalibTracker/SiStripHitEfficiency/plugins/HitEff.cc +++ b/CalibTracker/SiStripHitEfficiency/plugins/HitEff.cc @@ -72,6 +72,7 @@ using namespace std; HitEff::HitEff(const edm::ParameterSet& conf) : scalerToken_(consumes(conf.getParameter("lumiScalers"))), + metaDataToken_(consumes(conf.getParameter("metadata"))), commonModeToken_(mayConsume >(conf.getParameter("commonMode"))), siStripClusterInfo_(consumesCollector()), combinatorialTracks_token_( @@ -181,14 +182,22 @@ void HitEff::analyze(const edm::Event& e, const edm::EventSetup& es) { int bunch_nr = e.bunchCrossing(); // Luminosity informations - edm::Handle lumiScalers; + edm::Handle lumiScalers = e.getHandle(scalerToken_); + edm::Handle metaData = e.getHandle(metaDataToken_); + instLumi = 0; PU = 0; if (addLumi_) { - e.getByToken(scalerToken_, lumiScalers); - if (lumiScalers->begin() != lumiScalers->end()) { - instLumi = lumiScalers->begin()->instantLumi(); - PU = lumiScalers->begin()->pileup(); + if (lumiScalers.isValid() && !lumiScalers->empty()) { + if (lumiScalers->begin() != lumiScalers->end()) { + instLumi = lumiScalers->begin()->instantLumi(); + PU = lumiScalers->begin()->pileup(); + } + } else if (metaData.isValid()) { + instLumi = metaData->instLumi(); + PU = metaData->avgPileUp(); + } else { + edm::LogWarning("SiStripHitEfficiencyWorker") << "could not find a source for the Luminosity and PU"; } } diff --git a/CalibTracker/SiStripHitEfficiency/plugins/HitEff.h b/CalibTracker/SiStripHitEfficiency/plugins/HitEff.h index 7d1f55dd501e1..bdf4e176ed44f 100644 --- a/CalibTracker/SiStripHitEfficiency/plugins/HitEff.h +++ b/CalibTracker/SiStripHitEfficiency/plugins/HitEff.h @@ -11,6 +11,7 @@ #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementError.h" #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementVector.h" #include "DataFormats/GeometryVector/interface/GlobalPoint.h" +#include "DataFormats/OnlineMetaData/interface/OnlineLuminosityRecord.h" #include "DataFormats/Scalers/interface/LumiScalers.h" #include "DataFormats/SiStripCluster/interface/SiStripCluster.h" #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h" @@ -61,6 +62,7 @@ class HitEff : public edm::one::EDAnalyzer<> { // ----------member data --------------------------- const edm::EDGetTokenT scalerToken_; + const edm::EDGetTokenT metaDataToken_; const edm::EDGetTokenT > commonModeToken_; SiStripClusterInfo siStripClusterInfo_; diff --git a/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEfficiencyWorker.cc b/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEfficiencyWorker.cc index 202fa7929ac66..07278c375cdea 100644 --- a/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEfficiencyWorker.cc +++ b/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEfficiencyWorker.cc @@ -23,6 +23,7 @@ #include "DataFormats/GeometryVector/interface/GlobalPoint.h" #include "DataFormats/GeometryVector/interface/GlobalVector.h" #include "DataFormats/GeometryVector/interface/LocalVector.h" +#include "DataFormats/OnlineMetaData/interface/OnlineLuminosityRecord.h" #include "DataFormats/Scalers/interface/LumiScalers.h" #include "DataFormats/SiStripCluster/interface/SiStripCluster.h" #include "DataFormats/SiStripCommon/interface/ConstantsForHardwareSystems.h" /* for STRIPS_PER_APV*/ @@ -85,6 +86,7 @@ class SiStripHitEfficiencyWorker : public DQMEDAnalyzer { // event data tokens const edm::EDGetTokenT scalerToken_; + const edm::EDGetTokenT metaDataToken_; const edm::EDGetTokenT> commonModeToken_; const edm::EDGetTokenT combinatorialTracks_token_; const edm::EDGetTokenT> trajectories_token_; @@ -180,6 +182,7 @@ class SiStripHitEfficiencyWorker : public DQMEDAnalyzer { SiStripHitEfficiencyWorker::SiStripHitEfficiencyWorker(const edm::ParameterSet& conf) : scalerToken_(consumes(conf.getParameter("lumiScalers"))), + metaDataToken_(consumes(conf.getParameter("metadata"))), commonModeToken_(mayConsume>(conf.getParameter("commonMode"))), combinatorialTracks_token_( consumes(conf.getParameter("combinatorialTracks"))), @@ -363,16 +366,25 @@ void SiStripHitEfficiencyWorker::analyze(const edm::Event& e, const edm::EventSe // Step A: Get Inputs // Luminosity informations - edm::Handle lumiScalers; + edm::Handle lumiScalers = e.getHandle(scalerToken_); + edm::Handle metaData = e.getHandle(metaDataToken_); + float instLumi = 0; float PU = 0; if (addLumi_) { - e.getByToken(scalerToken_, lumiScalers); - if (lumiScalers->begin() != lumiScalers->end()) { - instLumi = lumiScalers->begin()->instantLumi(); - PU = lumiScalers->begin()->pileup(); + if (lumiScalers.isValid() && !lumiScalers->empty()) { + if (lumiScalers->begin() != lumiScalers->end()) { + instLumi = lumiScalers->begin()->instantLumi(); + PU = lumiScalers->begin()->pileup(); + } + } else if (metaData.isValid()) { + instLumi = metaData->instLumi(); + PU = metaData->avgPileUp(); + } else { + edm::LogWarning("SiStripHitEfficiencyWorker") << "could not find a source for the Luminosity and PU"; } } + h_bx->Fill(e.bunchCrossing()); h_instLumi->Fill(instLumi); h_PU->Fill(PU); @@ -989,6 +1001,7 @@ void SiStripHitEfficiencyWorker::fillDescriptions(edm::ConfigurationDescriptions desc.add("combinatorialTracks", edm::InputTag{"generalTracks"}); desc.add("commonMode", edm::InputTag{"siStripDigis", "CommonMode"}); desc.add("lumiScalers", edm::InputTag{"scalersRawToDigi"}); + desc.add("metadata", edm::InputTag{"onlineMetaDataDigis"}); desc.add("siStripClusters", edm::InputTag{"siStripClusters"}); desc.add("siStripDigis", edm::InputTag{"siStripDigis"}); desc.add("trackerEvent", edm::InputTag{"MeasurementTrackerEvent"}); diff --git a/CalibTracker/SiStripHitEfficiency/python/SiStripHitEff_cff.py b/CalibTracker/SiStripHitEfficiency/python/SiStripHitEff_cff.py index d5790a9876e2f..6c6e487a11af0 100644 --- a/CalibTracker/SiStripHitEfficiency/python/SiStripHitEff_cff.py +++ b/CalibTracker/SiStripHitEfficiency/python/SiStripHitEff_cff.py @@ -24,6 +24,7 @@ siStripDigis = cms.InputTag("siStripDigis"), trackerEvent = cms.InputTag("MeasurementTrackerEvent"), lumiScalers = cms.InputTag("scalersRawToDigi"), + metadata = cms.InputTag('onlineMetaDataDigis'), addLumi = cms.untracked.bool(False), commonMode = cms.InputTag("siStripDigis", "CommonMode"), addCommonMode = cms.untracked.bool(False),