From 0344ed83089da761d28f3b2658126941f689a725 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Sauvan Date: Tue, 28 Sep 2021 22:23:33 +0200 Subject: [PATCH] Add backward compatible nutple interface --- .../L1THGCal/interface/HGCalTriggerTools.h | 5 +++ L1Trigger/L1THGCal/src/HGCalTriggerTools.cc | 11 ++++++ .../interface/HGCalTriggerNtupleBase.h | 36 +++++++++++-------- .../ntuples/HGCalTriggerNtupleEvent.cc | 4 ++- .../plugins/ntuples/HGCalTriggerNtupleGen.cc | 4 ++- .../ntuples/HGCalTriggerNtupleGenJet.cc | 4 ++- .../ntuples/HGCalTriggerNtupleGenTau.cc | 4 ++- .../ntuples/HGCalTriggerNtupleHGCClusters.cc | 4 ++- .../HGCalTriggerNtupleHGCConcentratorData.cc | 4 ++- .../ntuples/HGCalTriggerNtupleHGCDigis.cc | 1 + .../HGCalTriggerNtupleHGCMulticlusters.cc | 4 ++- .../HGCalTriggerNtupleHGCTriggerCells.cc | 4 ++- .../HGCalTriggerNtupleHGCTriggerSums.cc | 4 ++- .../ntuples/HGCalTriggerNtupleManager.cc | 6 +++- .../ntuples/HGCalTriggerNtupleTowers.cc | 5 +-- 15 files changed, 73 insertions(+), 27 deletions(-) diff --git a/L1Trigger/L1THGCal/interface/HGCalTriggerTools.h b/L1Trigger/L1THGCal/interface/HGCalTriggerTools.h index d8690ed3f7df9..b677124c2b4ce 100644 --- a/L1Trigger/L1THGCal/interface/HGCalTriggerTools.h +++ b/L1Trigger/L1THGCal/interface/HGCalTriggerTools.h @@ -23,12 +23,17 @@ #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h" #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h" +namespace edm { + class EventSetup; +} + class HGCalTriggerTools { public: HGCalTriggerTools() : geom_(nullptr), eeLayers_(0), fhLayers_(0), bhLayers_(0), noseLayers_(0), totalLayers_(0) {} ~HGCalTriggerTools() {} void setGeometry(const HGCalTriggerGeometryBase* const); + void eventSetup(const edm::EventSetup&); // Kept for backward compatibility: used in L1Trigger/L1CaloTrigger/test GlobalPoint getTCPosition(const DetId& id) const; unsigned layers(ForwardSubdetector type) const; unsigned layers(DetId::Detector type) const; diff --git a/L1Trigger/L1THGCal/src/HGCalTriggerTools.cc b/L1Trigger/L1THGCal/src/HGCalTriggerTools.cc index e7fe7bbd0b071..58cc087664d17 100644 --- a/L1Trigger/L1THGCal/src/HGCalTriggerTools.cc +++ b/L1Trigger/L1THGCal/src/HGCalTriggerTools.cc @@ -10,6 +10,10 @@ #include "Geometry/Records/interface/CaloGeometryRecord.h" #include "SimDataFormats/CaloTest/interface/HGCalTestNumbering.h" +#include "FWCore/Framework/interface/ESHandle.h" + +#include "FWCore/Framework/interface/EventSetup.h" + namespace { template inline void check_ddd(const DDD* ddd) { @@ -26,6 +30,13 @@ namespace { } } // namespace +// Kept for backward compatibility: used in L1Trigger/L1CaloTrigger/test +void HGCalTriggerTools::eventSetup(const edm::EventSetup& es) { + edm::ESHandle triggerGeometry; + es.get().get(triggerGeometry); + setGeometry(triggerGeometry.product()); +} + void HGCalTriggerTools::setGeometry(const HGCalTriggerGeometryBase* const geom) { geom_ = geom; eeLayers_ = geom_->eeTopology().dddConstants().layers(true); diff --git a/L1Trigger/L1THGCalUtilities/interface/HGCalTriggerNtupleBase.h b/L1Trigger/L1THGCalUtilities/interface/HGCalTriggerNtupleBase.h index 0fe3d3868ac38..33cbd3b76aed4 100644 --- a/L1Trigger/L1THGCalUtilities/interface/HGCalTriggerNtupleBase.h +++ b/L1Trigger/L1THGCalUtilities/interface/HGCalTriggerNtupleBase.h @@ -6,21 +6,9 @@ #include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/Framework/interface/ConsumesCollector.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" -// #include "SimGeneral/HepPDTRecord/interface/PDTRecord.h" -// #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h" -// #include "MagneticField/Engine/interface/MagneticField.h" -// #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" #include "TTree.h" -// #include "MagneticField/Engine/interface/MagneticField.h" -// #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" -// #include "TrackPropagation/RungeKutta/interface/defaultRKPropagator.h" -// #include "TrackPropagation/RungeKutta/interface/RKPropagatorInS.h" -// #include "FastSimulation/Event/interface/FSimEvent.h" -// #include "SimGeneral/HepPDTRecord/interface/PDTRecord.h" -// -// #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" - namespace HepPDT { class ParticleDataTable; } @@ -35,13 +23,31 @@ struct HGCalTriggerNtupleEventSetup { class HGCalTriggerNtupleBase { public: - HGCalTriggerNtupleBase(const edm::ParameterSet& conf){}; + HGCalTriggerNtupleBase(const edm::ParameterSet& conf) : name_(conf.getParameter("NtupleName")){}; virtual ~HGCalTriggerNtupleBase(){}; + const std::string& name() const { return name_; } virtual void initialize(TTree&, const edm::ParameterSet&, edm::ConsumesCollector&&) = 0; - virtual void fill(const edm::Event&, const HGCalTriggerNtupleEventSetup&) = 0; + virtual void fill(const edm::Event&, const HGCalTriggerNtupleEventSetup&) { + edm::LogWarning("NotImplemented") << "Calling ntuplizer fill(edm::Event, HGCalTriggerNtupleEventSetup), but it is " + "not implemented in the concrete class '" + << name() << "'. " + << "You might want to set 'accessEventSetup_' to true in order to call " + "fill(edm::Event, edm::EventSetup) instead."; + } + // Kept for backward compatibility: used in L1Trigger/L1CaloTrigger/test + virtual void fill(const edm::Event&, const edm::EventSetup&) { + edm::LogWarning("NotImplemented") + << "Calling ntuplizer fill(edm::Event, edm::EventSetup), but it is not implemented in the concrete class '" + << name() << "'. " + << "You might want to set 'accessEventSetup_' to false in order to call fill(edm::Event, " + "HGCalTriggerNtupleEventSetup) instead."; + } + bool accessEventSetup() const { return accessEventSetup_; } protected: virtual void clear() = 0; + bool accessEventSetup_ = true; + const std::string name_; }; #include "FWCore/PluginManager/interface/PluginFactory.h" diff --git a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleEvent.cc b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleEvent.cc index 6ce44ad9fe4ca..e5ab2cfa684f5 100644 --- a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleEvent.cc +++ b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleEvent.cc @@ -17,7 +17,9 @@ class HGCalTriggerNtupleEvent : public HGCalTriggerNtupleBase { DEFINE_EDM_PLUGIN(HGCalTriggerNtupleFactory, HGCalTriggerNtupleEvent, "HGCalTriggerNtupleEvent"); -HGCalTriggerNtupleEvent::HGCalTriggerNtupleEvent(const edm::ParameterSet& conf) : HGCalTriggerNtupleBase(conf) {} +HGCalTriggerNtupleEvent::HGCalTriggerNtupleEvent(const edm::ParameterSet& conf) : HGCalTriggerNtupleBase(conf) { + accessEventSetup_ = false; +} void HGCalTriggerNtupleEvent::initialize(TTree& tree, const edm::ParameterSet&, edm::ConsumesCollector&&) { clear(); diff --git a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleGen.cc b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleGen.cc index c18861ac22bd6..4b1cbdf02f372 100644 --- a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleGen.cc +++ b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleGen.cc @@ -189,7 +189,9 @@ class HGCalTriggerNtupleGen : public HGCalTriggerNtupleBase { DEFINE_EDM_PLUGIN(HGCalTriggerNtupleFactory, HGCalTriggerNtupleGen, "HGCalTriggerNtupleGen"); -HGCalTriggerNtupleGen::HGCalTriggerNtupleGen(const edm::ParameterSet &conf) : HGCalTriggerNtupleBase(conf) {} +HGCalTriggerNtupleGen::HGCalTriggerNtupleGen(const edm::ParameterSet &conf) : HGCalTriggerNtupleBase(conf) { + accessEventSetup_ = false; +} void HGCalTriggerNtupleGen::initialize(TTree &tree, const edm::ParameterSet &conf, edm::ConsumesCollector &&collector) { edm::ParameterSet particleFilter_(conf.getParameter("particleFilter")); diff --git a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleGenJet.cc b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleGenJet.cc index bae254f647b8d..6d49fc282e16d 100644 --- a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleGenJet.cc +++ b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleGenJet.cc @@ -25,7 +25,9 @@ class HGCalTriggerNtupleGenJet : public HGCalTriggerNtupleBase { DEFINE_EDM_PLUGIN(HGCalTriggerNtupleFactory, HGCalTriggerNtupleGenJet, "HGCalTriggerNtupleGenJet"); -HGCalTriggerNtupleGenJet::HGCalTriggerNtupleGenJet(const edm::ParameterSet& conf) : HGCalTriggerNtupleBase(conf) {} +HGCalTriggerNtupleGenJet::HGCalTriggerNtupleGenJet(const edm::ParameterSet& conf) : HGCalTriggerNtupleBase(conf) { + accessEventSetup_ = false; +} void HGCalTriggerNtupleGenJet::initialize(TTree& tree, const edm::ParameterSet& conf, diff --git a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleGenTau.cc b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleGenTau.cc index b745e97e8f1bb..90c24807aebad 100644 --- a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleGenTau.cc +++ b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleGenTau.cc @@ -58,7 +58,9 @@ class HGCalTriggerNtupleGenTau : public HGCalTriggerNtupleBase { DEFINE_EDM_PLUGIN(HGCalTriggerNtupleFactory, HGCalTriggerNtupleGenTau, "HGCalTriggerNtupleGenTau"); -HGCalTriggerNtupleGenTau::HGCalTriggerNtupleGenTau(const edm::ParameterSet& conf) : HGCalTriggerNtupleBase(conf) {} +HGCalTriggerNtupleGenTau::HGCalTriggerNtupleGenTau(const edm::ParameterSet& conf) : HGCalTriggerNtupleBase(conf) { + accessEventSetup_ = false; +} void HGCalTriggerNtupleGenTau::initialize(TTree& tree, const edm::ParameterSet& conf, diff --git a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCClusters.cc b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCClusters.cc index e49f31649e330..049a3b12e217a 100644 --- a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCClusters.cc +++ b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCClusters.cc @@ -39,7 +39,9 @@ DEFINE_EDM_PLUGIN(HGCalTriggerNtupleFactory, HGCalTriggerNtupleHGCClusters, "HGC HGCalTriggerNtupleHGCClusters::HGCalTriggerNtupleHGCClusters(const edm::ParameterSet& conf) : HGCalTriggerNtupleBase(conf), - filter_clusters_in_multiclusters_(conf.getParameter("FilterClustersInMulticlusters")) {} + filter_clusters_in_multiclusters_(conf.getParameter("FilterClustersInMulticlusters")) { + accessEventSetup_ = false; +} void HGCalTriggerNtupleHGCClusters::initialize(TTree& tree, const edm::ParameterSet& conf, diff --git a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCConcentratorData.cc b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCConcentratorData.cc index 863e060c0c9ba..ada98e6777a1b 100644 --- a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCConcentratorData.cc +++ b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCConcentratorData.cc @@ -39,7 +39,9 @@ DEFINE_EDM_PLUGIN(HGCalTriggerNtupleFactory, "HGCalTriggerNtupleHGCConcentratorData"); HGCalTriggerNtupleHGCConcentratorData::HGCalTriggerNtupleHGCConcentratorData(const edm::ParameterSet& conf) - : HGCalTriggerNtupleBase(conf) {} + : HGCalTriggerNtupleBase(conf) { + accessEventSetup_ = false; +} void HGCalTriggerNtupleHGCConcentratorData::initialize(TTree& tree, const edm::ParameterSet& conf, diff --git a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCDigis.cc b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCDigis.cc index e2d6902992029..1f3e52d907e71 100644 --- a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCDigis.cc +++ b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCDigis.cc @@ -68,6 +68,7 @@ class HGCalTriggerNtupleHGCDigis : public HGCalTriggerNtupleBase { DEFINE_EDM_PLUGIN(HGCalTriggerNtupleFactory, HGCalTriggerNtupleHGCDigis, "HGCalTriggerNtupleHGCDigis"); HGCalTriggerNtupleHGCDigis::HGCalTriggerNtupleHGCDigis(const edm::ParameterSet& conf) : HGCalTriggerNtupleBase(conf) { + accessEventSetup_ = false; is_Simhit_comp_ = conf.getParameter("isSimhitComp"); digiBXselect_ = conf.getParameter>("digiBXselect"); diff --git a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCMulticlusters.cc b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCMulticlusters.cc index 1e5679b4c50c5..34c72aa4df886 100644 --- a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCMulticlusters.cc +++ b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCMulticlusters.cc @@ -62,7 +62,9 @@ DEFINE_EDM_PLUGIN(HGCalTriggerNtupleFactory, HGCalTriggerNtupleHGCMulticlusters, HGCalTriggerNtupleHGCMulticlusters::HGCalTriggerNtupleHGCMulticlusters(const edm::ParameterSet& conf) : HGCalTriggerNtupleBase(conf), fill_layer_info_(conf.getParameter("FillLayerInfo")), - fill_interpretation_info_(conf.getParameter("FillInterpretationInfo")) {} + fill_interpretation_info_(conf.getParameter("FillInterpretationInfo")) { + accessEventSetup_ = false; +} void HGCalTriggerNtupleHGCMulticlusters::initialize(TTree& tree, const edm::ParameterSet& conf, diff --git a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCTriggerCells.cc b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCTriggerCells.cc index aa3407bb00e44..1fdcb9e1975de 100644 --- a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCTriggerCells.cc +++ b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCTriggerCells.cc @@ -83,7 +83,9 @@ HGCalTriggerNtupleHGCTriggerCells::HGCalTriggerNtupleHGCTriggerCells(const edm:: keV2fC_(conf.getParameter("keV2fC")), fcPerMip_(conf.getParameter>("fcPerMip")), layerWeights_(conf.getParameter>("layerWeights")), - thicknessCorrections_(conf.getParameter>("thicknessCorrections")) {} + thicknessCorrections_(conf.getParameter>("thicknessCorrections")) { + accessEventSetup_ = false; +} void HGCalTriggerNtupleHGCTriggerCells::initialize(TTree& tree, const edm::ParameterSet& conf, diff --git a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCTriggerSums.cc b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCTriggerSums.cc index ebc21022c31a9..7ca8a32288ebd 100644 --- a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCTriggerSums.cc +++ b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleHGCTriggerSums.cc @@ -45,7 +45,9 @@ class HGCalTriggerNtupleHGCTriggerSums : public HGCalTriggerNtupleBase { DEFINE_EDM_PLUGIN(HGCalTriggerNtupleFactory, HGCalTriggerNtupleHGCTriggerSums, "HGCalTriggerNtupleHGCTriggerSums"); HGCalTriggerNtupleHGCTriggerSums::HGCalTriggerNtupleHGCTriggerSums(const edm::ParameterSet& conf) - : HGCalTriggerNtupleBase(conf) {} + : HGCalTriggerNtupleBase(conf) { + accessEventSetup_ = false; +} void HGCalTriggerNtupleHGCTriggerSums::initialize(TTree& tree, const edm::ParameterSet& conf, diff --git a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleManager.cc b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleManager.cc index 8580be87f3e89..c90a5f7712914 100644 --- a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleManager.cc +++ b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleManager.cc @@ -58,7 +58,11 @@ void HGCalTriggerNtupleManager::beginRun(const edm::Run& run, const edm::EventSe void HGCalTriggerNtupleManager::analyze(const edm::Event& e, const edm::EventSetup& es) { for (auto& hgc_ntuple : hgc_ntuples_) { - hgc_ntuple->fill(e, ntuple_es_); + if (hgc_ntuple->accessEventSetup()) { + hgc_ntuple->fill(e, es); + } else { + hgc_ntuple->fill(e, ntuple_es_); + } } tree_->Fill(); diff --git a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleTowers.cc b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleTowers.cc index 1c0282af1a7c9..9f328400f9a21 100644 --- a/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleTowers.cc +++ b/L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleTowers.cc @@ -26,8 +26,9 @@ class HGCalTriggerNtupleHGCTowers : public HGCalTriggerNtupleBase { DEFINE_EDM_PLUGIN(HGCalTriggerNtupleFactory, HGCalTriggerNtupleHGCTowers, "HGCalTriggerNtupleHGCTowers"); -HGCalTriggerNtupleHGCTowers::HGCalTriggerNtupleHGCTowers(const edm::ParameterSet& conf) - : HGCalTriggerNtupleBase(conf) {} +HGCalTriggerNtupleHGCTowers::HGCalTriggerNtupleHGCTowers(const edm::ParameterSet& conf) : HGCalTriggerNtupleBase(conf) { + accessEventSetup_ = false; +} void HGCalTriggerNtupleHGCTowers::initialize(TTree& tree, const edm::ParameterSet& conf,