From 2c9d5bd1cee93cae7bb9cf2e2352d285c0493671 Mon Sep 17 00:00:00 2001 From: Carlo Battilana Date: Thu, 23 Mar 2023 20:52:59 +0100 Subject: [PATCH] Implement cross-POG suggetsions --- DPGAnalysis/MuonTools/BuildFile.xml | 3 + ...ller.cc => MuDTTPGPhiFlatTableProducer.cc} | 31 +-- ...Filler.h => MuDTTPGPhiFlatTableProducer.h} | 16 +- ...er.cc => MuDTTPGThetaFlatTableProducer.cc} | 26 +-- ...ller.h => MuDTTPGThetaFlatTableProducer.h} | 16 +- .../plugins/MuDigiFlatTableProducers.cc | 34 +++ .../MuonTools/plugins/MuRecoTableProducers.cc | 43 ++++ DPGAnalysis/MuonTools/python/common_cff.py | 42 ++++ .../MuonTools/python/muNtupleProducer_cff.py | 66 +++--- .../MuonTools/python/nano_mu_digi_cff.py | 78 +++++++ .../MuonTools/python/nano_mu_l1t_cff.py | 19 ++ .../python/nano_mu_local_reco_cff.py | 153 +++++++++++++ .../MuonTools/python/nano_mu_reco_cff.py | 62 +++++ .../MuonTools/src/MuBaseFlatTableProducer.cc | 22 ++ .../MuonTools/src/MuBaseFlatTableProducer.h | 73 ++++++ .../MuonTools/src/MuDigiBaseProducer.h | 118 ++++++++++ .../MuonTools/src/MuNtupleBaseFiller.h | 1 + .../MuonTools/src/MuRecObjBaseProducer.h | 216 ++++++++++++++++++ ...gNtuples_cfg.py => muDpgNtuplesZMu_cfg.py} | 4 +- 19 files changed, 950 insertions(+), 73 deletions(-) rename DPGAnalysis/MuonTools/plugins/{MuNtupleDTTPGPhiFiller.cc => MuDTTPGPhiFlatTableProducer.cc} (77%) rename DPGAnalysis/MuonTools/plugins/{MuNtupleDTTPGPhiFiller.h => MuDTTPGPhiFlatTableProducer.h} (65%) rename DPGAnalysis/MuonTools/plugins/{MuNtupleDTTPGThetaFiller.cc => MuDTTPGThetaFlatTableProducer.cc} (71%) rename DPGAnalysis/MuonTools/plugins/{MuNtupleDTTPGThetaFiller.h => MuDTTPGThetaFlatTableProducer.h} (59%) create mode 100644 DPGAnalysis/MuonTools/plugins/MuDigiFlatTableProducers.cc create mode 100644 DPGAnalysis/MuonTools/plugins/MuRecoTableProducers.cc create mode 100644 DPGAnalysis/MuonTools/python/common_cff.py create mode 100644 DPGAnalysis/MuonTools/python/nano_mu_digi_cff.py create mode 100644 DPGAnalysis/MuonTools/python/nano_mu_l1t_cff.py create mode 100644 DPGAnalysis/MuonTools/python/nano_mu_local_reco_cff.py create mode 100644 DPGAnalysis/MuonTools/python/nano_mu_reco_cff.py create mode 100644 DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.cc create mode 100644 DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.h create mode 100644 DPGAnalysis/MuonTools/src/MuDigiBaseProducer.h create mode 100644 DPGAnalysis/MuonTools/src/MuRecObjBaseProducer.h rename DPGAnalysis/MuonTools/test/{muDpgNtuples_cfg.py => muDpgNtuplesZMu_cfg.py} (94%) diff --git a/DPGAnalysis/MuonTools/BuildFile.xml b/DPGAnalysis/MuonTools/BuildFile.xml index 13cf66377b213..6977478d3e4af 100644 --- a/DPGAnalysis/MuonTools/BuildFile.xml +++ b/DPGAnalysis/MuonTools/BuildFile.xml @@ -5,8 +5,10 @@ + + @@ -25,6 +27,7 @@ + diff --git a/DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGPhiFiller.cc b/DPGAnalysis/MuonTools/plugins/MuDTTPGPhiFlatTableProducer.cc similarity index 77% rename from DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGPhiFiller.cc rename to DPGAnalysis/MuonTools/plugins/MuDTTPGPhiFlatTableProducer.cc index 616f267e4e92f..ef9f1f70f63ac 100644 --- a/DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGPhiFiller.cc +++ b/DPGAnalysis/MuonTools/plugins/MuDTTPGPhiFlatTableProducer.cc @@ -1,42 +1,42 @@ -/** \class MuNtupleDTTPGPhiFiller MuNtupleDTTPGPhiFiller.cc DPGAnalysis/MuonTools/src/MuNtupleDTTPGPhiFiller.cc +/** \class MuDTTPGPhiFlatTableProducer MuDTTPGPhiFlatTableProducer.cc DPGAnalysis/MuonTools/src/MuDTTPGPhiFlatTableProducer.cc * - * Helper class : the Phase-1 local trigger filler for TwinMux in/out and BMTF in (the DataFormat is the same) + * Helper class : the Phase-1 local trigger FlatTableProducer for TwinMux in/out and BMTF in (the DataFormat is the same) * * \author C. Battilana (INFN BO) * * */ -#include "DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGPhiFiller.h" +#include "DPGAnalysis/MuonTools/plugins/MuDTTPGPhiFlatTableProducer.h" #include "FWCore/ParameterSet/interface/allowedValues.h" #include #include -MuNtupleDTTPGPhiFiller::MuNtupleDTTPGPhiFiller(const edm::ParameterSet& config) - : MuNtupleBaseFiller{config}, +MuDTTPGPhiFlatTableProducer::MuDTTPGPhiFlatTableProducer(const edm::ParameterSet& config) + : MuBaseFlatTableProducer{config}, m_tag{getTag(config)}, - m_token{config, consumesCollector(), "dtTpTag"}, + m_token{config, consumesCollector(), "src"}, m_trigGeomUtils{consumesCollector()} { produces(); } -void MuNtupleDTTPGPhiFiller::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { +void MuDTTPGPhiFlatTableProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("label", "ltBmtfIn"); + desc.add("name", "ltBmtfIn"); desc.ifValue(edm::ParameterDescription("tag", "BMTF_IN", true), edm::allowedValues("BMTF_IN", "TM_IN", "TM_OUT")); - desc.add("dtTpTag", edm::InputTag{"bmtfDigis"}); + desc.add("src", edm::InputTag{"bmtfDigis"}); descriptions.addWithDefaultLabel(desc); } -void MuNtupleDTTPGPhiFiller::getFromES(const edm::Run& run, const edm::EventSetup& environment) { +void MuDTTPGPhiFlatTableProducer::getFromES(const edm::Run& run, const edm::EventSetup& environment) { m_trigGeomUtils.getFromES(run, environment); } -void MuNtupleDTTPGPhiFiller::fill(edm::Event& ev) { +void MuDTTPGPhiFlatTableProducer::fillTable(edm::Event& ev) { unsigned int nTrigs{0}; std::vector wheel; @@ -86,7 +86,7 @@ void MuNtupleDTTPGPhiFiller::fill(edm::Event& ev) { } } - auto table = std::make_unique(nTrigs, m_label, false, false); + auto table = std::make_unique(nTrigs, m_name, false, false); table->setDoc("DT trigger primitive information (phi view)"); @@ -145,13 +145,14 @@ void MuNtupleDTTPGPhiFiller::fill(edm::Event& ev) { ev.put(std::move(table)); } -MuNtupleDTTPGPhiFiller::TriggerTag MuNtupleDTTPGPhiFiller::getTag(const edm::ParameterSet& config) { +MuDTTPGPhiFlatTableProducer::TriggerTag MuDTTPGPhiFlatTableProducer::getTag(const edm::ParameterSet& config) { auto tag{TriggerTag::TM_IN}; auto tagName = config.getParameter("tag"); if (tagName != "TM_IN" && tagName != "TM_OUT" && tagName != "BMTF_IN") - edm::LogError("") << "[MuNtupleDTTPGPhiFiller]::getTag: " << tagName << " is not a valid tag, defaulting to TM_IN"; + edm::LogError("") << "[MuDTTPGPhiFlatTableProducer]::getTag: " << tagName + << " is not a valid tag, defaulting to TM_IN"; if (tagName == "TM_OUT") { tag = TriggerTag::TM_OUT; @@ -165,4 +166,4 @@ MuNtupleDTTPGPhiFiller::TriggerTag MuNtupleDTTPGPhiFiller::getTag(const edm::Par #include "FWCore/PluginManager/interface/ModuleDef.h" #include "FWCore/Framework/interface/MakerMacros.h" -DEFINE_FWK_MODULE(MuNtupleDTTPGPhiFiller); +DEFINE_FWK_MODULE(MuDTTPGPhiFlatTableProducer); diff --git a/DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGPhiFiller.h b/DPGAnalysis/MuonTools/plugins/MuDTTPGPhiFlatTableProducer.h similarity index 65% rename from DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGPhiFiller.h rename to DPGAnalysis/MuonTools/plugins/MuDTTPGPhiFlatTableProducer.h index 9b009cb9e6f26..b825631ba1ecf 100644 --- a/DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGPhiFiller.h +++ b/DPGAnalysis/MuonTools/plugins/MuDTTPGPhiFlatTableProducer.h @@ -1,35 +1,35 @@ -#ifndef MuNtuple_MuNtupleDTTPGPhiFiller_h -#define MuNtuple_MuNtupleDTTPGPhiFiller_h +#ifndef Mu_MuDTTPGPhiFlatTableProducer_h +#define Mu_MuDTTPGPhiFlatTableProducer_h -/** \class MuNtupleDTTPGPhiFiller MuNtupleDTTPGPhiFiller.h DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGPhiFiller.h +/** \class MuDTTPGPhiFlatTableProducer MuDTTPGPhiFlatTableProducer.h DPGAnalysis/MuonTools/plugins/MuDTTPGPhiFlatTableProducer.h * - * Helper class : the Phase-1 local trigger filler for TwinMux in/out and BMTF in (the DataFormat is the same) + * Helper class : the Phase-1 local trigger FlatTableProducer for TwinMux in/out and BMTF in (the DataFormat is the same) * * \author C. Battilana (INFN BO) * * */ -#include "DPGAnalysis/MuonTools/src/MuNtupleBaseFiller.h" +#include "DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h" -class MuNtupleDTTPGPhiFiller : public MuNtupleBaseFiller { +class MuDTTPGPhiFlatTableProducer : public MuBaseFlatTableProducer { public: enum class TriggerTag { TM_IN = 0, TM_OUT, BMTF_IN }; /// Constructor - MuNtupleDTTPGPhiFiller(const edm::ParameterSet&); + MuDTTPGPhiFlatTableProducer(const edm::ParameterSet&); /// Fill descriptors static void fillDescriptions(edm::ConfigurationDescriptions&); protected: /// Fill tree branches for a given event - void fill(edm::Event&) final; + void fillTable(edm::Event&) final; /// Get info from the ES by run void getFromES(const edm::Run&, const edm::EventSetup&) final; diff --git a/DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGThetaFiller.cc b/DPGAnalysis/MuonTools/plugins/MuDTTPGThetaFlatTableProducer.cc similarity index 71% rename from DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGThetaFiller.cc rename to DPGAnalysis/MuonTools/plugins/MuDTTPGThetaFlatTableProducer.cc index 1af9dc3ab3869..9f6a1e7b7b2bb 100644 --- a/DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGThetaFiller.cc +++ b/DPGAnalysis/MuonTools/plugins/MuDTTPGThetaFlatTableProducer.cc @@ -1,35 +1,35 @@ -/** \class MuNtupleDTTPGThetaFiller MuNtupleDTTPGThetaFiller.cc DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGThetaFiller.cc +/** \class MuDTTPGThetaFlatTableProducer MuDTTPGThetaFlatTableProducer.cc DPGAnalysis/MuonTools/plugins/MuDTTPGThetaFlatTableProducer.cc * - * Helper class : the Phase-1 local trigger filler for TwinMux in/out and BMTF in (the DataFormat is the same) + * Helper class : the Phase-1 local trigger FlatTableProducer for TwinMux in/out and BMTF in (the DataFormat is the same) * * \author C. Battilana (INFN BO) * * */ -#include "DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGThetaFiller.h" +#include "DPGAnalysis/MuonTools/plugins/MuDTTPGThetaFlatTableProducer.h" #include "FWCore/ParameterSet/interface/allowedValues.h" #include #include -MuNtupleDTTPGThetaFiller::MuNtupleDTTPGThetaFiller(const edm::ParameterSet& config) - : MuNtupleBaseFiller{config}, m_tag{getTag(config)}, m_token{config, consumesCollector(), "dtTpTag"} { +MuDTTPGThetaFlatTableProducer::MuDTTPGThetaFlatTableProducer(const edm::ParameterSet& config) + : MuBaseFlatTableProducer{config}, m_tag{getTag(config)}, m_token{config, consumesCollector(), "src"} { produces(); } -void MuNtupleDTTPGThetaFiller::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { +void MuDTTPGThetaFlatTableProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("label", "ltBmtfInTh"); + desc.add("name", "ltBmtfInTh"); desc.ifValue(edm::ParameterDescription("tag", "BMTF_IN", true), edm::allowedValues("BMTF_IN", "TM_IN")); - desc.add("dtTpTag", edm::InputTag{"bmtfDigis"}); + desc.add("src", edm::InputTag{"bmtfDigis"}); descriptions.addWithDefaultLabel(desc); } -void MuNtupleDTTPGThetaFiller::fill(edm::Event& ev) { +void MuDTTPGThetaFlatTableProducer::fillTable(edm::Event& ev) { unsigned int nTrigs{0}; std::vector wheel; @@ -72,7 +72,7 @@ void MuNtupleDTTPGThetaFiller::fill(edm::Event& ev) { } } - auto table = std::make_unique(nTrigs, m_label, false, false); + auto table = std::make_unique(nTrigs, m_name, false, false); table->setDoc("DT trigger primitive information (theta view)"); @@ -103,13 +103,13 @@ void MuNtupleDTTPGThetaFiller::fill(edm::Event& ev) { ev.put(std::move(table)); } -MuNtupleDTTPGThetaFiller::TriggerTag MuNtupleDTTPGThetaFiller::getTag(const edm::ParameterSet& config) { +MuDTTPGThetaFlatTableProducer::TriggerTag MuDTTPGThetaFlatTableProducer::getTag(const edm::ParameterSet& config) { auto tag{TriggerTag::TM_IN}; auto tagName = config.getParameter("tag"); if (tagName != "TM_IN" && tagName != "BMTF_IN") - edm::LogError("") << "[MuNtupleDTTPGThetaFiller]::getTag: " << tagName + edm::LogError("") << "[MuDTTPGThetaFlatTableProducer]::getTag: " << tagName << " is not a valid tag, defaulting to TM_IN"; if (tagName == "BMTF_IN") @@ -121,4 +121,4 @@ MuNtupleDTTPGThetaFiller::TriggerTag MuNtupleDTTPGThetaFiller::getTag(const edm: #include "FWCore/PluginManager/interface/ModuleDef.h" #include "FWCore/Framework/interface/MakerMacros.h" -DEFINE_FWK_MODULE(MuNtupleDTTPGThetaFiller); \ No newline at end of file +DEFINE_FWK_MODULE(MuDTTPGThetaFlatTableProducer); \ No newline at end of file diff --git a/DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGThetaFiller.h b/DPGAnalysis/MuonTools/plugins/MuDTTPGThetaFlatTableProducer.h similarity index 59% rename from DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGThetaFiller.h rename to DPGAnalysis/MuonTools/plugins/MuDTTPGThetaFlatTableProducer.h index 9bb7d8a55d70d..dee3aac832607 100644 --- a/DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGThetaFiller.h +++ b/DPGAnalysis/MuonTools/plugins/MuDTTPGThetaFlatTableProducer.h @@ -1,35 +1,35 @@ -#ifndef MuNtuple_MuNtupleDTTPGThetaFiller_h -#define MuNtuple_MuNtupleDTTPGThetaFiller_h +#ifndef Mu_MuDTTPGThetaFlatTableProducer_h +#define Mu_MuDTTPGThetaFlatTableProducer_h -/** \class MuNtupleDTTPGThetaFiller MuNtupleDTTPGThetaFiller.h DPGAnalysis/MuonTools/plugins/MuNtupleDTTPGThetaFiller.h +/** \class MuDTTPGThetaFlatTableProducer MuDTTPGThetaFlatTableProducer.h DPGAnalysis/MuonTools/plugins/MuDTTPGThetaFlatTableProducer.h * - * Helper class : the Phase-1 local trigger filler for TwinMux and BMTF in (the DataFormat is the same) + * Helper class : the Phase-1 local trigger FlatTableProducer for TwinMux and BMTF in (the DataFormat is the same) * * \author C. Battilana (INFN BO) * * */ -#include "DPGAnalysis/MuonTools/src/MuNtupleBaseFiller.h" +#include "DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThContainer.h" -class MuNtupleDTTPGThetaFiller : public MuNtupleBaseFiller { +class MuDTTPGThetaFlatTableProducer : public MuBaseFlatTableProducer { public: enum class TriggerTag { TM_IN = 0, BMTF_IN }; /// Constructor - MuNtupleDTTPGThetaFiller(const edm::ParameterSet&); + MuDTTPGThetaFlatTableProducer(const edm::ParameterSet&); /// Fill descriptors static void fillDescriptions(edm::ConfigurationDescriptions&); protected: /// Fill tree branches for a given events - void fill(edm::Event&) final; + void fillTable(edm::Event&) final; private: /// Enum to activate "flavour-by-flavour" diff --git a/DPGAnalysis/MuonTools/plugins/MuDigiFlatTableProducers.cc b/DPGAnalysis/MuonTools/plugins/MuDigiFlatTableProducers.cc new file mode 100644 index 0000000000000..d701ad4d939e8 --- /dev/null +++ b/DPGAnalysis/MuonTools/plugins/MuDigiFlatTableProducers.cc @@ -0,0 +1,34 @@ +/** \class MuDigiFlatTableProducers.cc MuDigiFlatTableProducers.cc DPGAnalysis/MuonTools/src/MuDigiFlatTableProducers.cc + * + * EDProducers : the flat table producers for CSC, DT, GEM and RPC digis + * + * \author C. Battilana (INFN BO) + * + * + */ + +#include "DPGAnalysis/MuonTools/src/MuDigiBaseProducer.h" + +#include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h" +using CSCWireDigiFlatTableProducer = MuDigiBaseProducer; + +#include "DataFormats/CSCDigi/interface/CSCALCTDigiCollection.h" +using CSCALCTDigiFlatTableProducer = MuDigiBaseProducer; + +#include "DataFormats/DTDigi/interface/DTDigiCollection.h" +using DTDigiFlatTableProducer = MuDigiBaseProducer; + +#include "DataFormats/RPCDigi/interface/RPCDigiCollection.h" +using RPCDigiFlatTableProducer = MuDigiBaseProducer; + +#include "DataFormats/GEMDigi/interface/GEMDigiCollection.h" +using GEMDigiFlatTableProducer = MuDigiBaseProducer; + +#include "FWCore/PluginManager/interface/ModuleDef.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +DEFINE_FWK_MODULE(CSCWireDigiFlatTableProducer); +DEFINE_FWK_MODULE(CSCALCTDigiFlatTableProducer); +DEFINE_FWK_MODULE(DTDigiFlatTableProducer); +DEFINE_FWK_MODULE(RPCDigiFlatTableProducer); +DEFINE_FWK_MODULE(GEMDigiFlatTableProducer); diff --git a/DPGAnalysis/MuonTools/plugins/MuRecoTableProducers.cc b/DPGAnalysis/MuonTools/plugins/MuRecoTableProducers.cc new file mode 100644 index 0000000000000..5ed3f01ef38bf --- /dev/null +++ b/DPGAnalysis/MuonTools/plugins/MuRecoTableProducers.cc @@ -0,0 +1,43 @@ +/** \class MuRecoFlatTableProducers.ccMuRecoFlatTableProducers DPGAnalysis/MuonTools/src/MuRecoFlatTableProducers.cc + * + * EDProducers : the flat table producers for DT, GEM and RPC RecHits and Segments + * + * \author C. Battilana (INFN BO) + * + * + */ + +#include "DPGAnalysis/MuonTools/src/MuRecObjBaseProducer.h" + + +#include "Geometry/DTGeometry/interface/DTGeometry.h" +#include "Geometry/Records/interface/MuonGeometryRecord.h" +#include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h" + +using DTSegmentFlatTableProducer = MuRecObjBaseProducer; + +#include "Geometry/RPCGeometry/interface/RPCGeometry.h" +#include "Geometry/Records/interface/MuonGeometryRecord.h" +#include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h" + +using RPCRecHitFlatTableProducer = MuRecObjBaseProducer; + +#include "Geometry/GEMGeometry/interface/GEMGeometry.h" +#include "Geometry/Records/interface/MuonGeometryRecord.h" +#include "DataFormats/GEMRecHit/interface/GEMRecHitCollection.h" + +using GEMRecHitFlatTableProducer = MuRecObjBaseProducer; + +#include "Geometry/GEMGeometry/interface/GEMGeometry.h" +#include "Geometry/Records/interface/MuonGeometryRecord.h" +#include "DataFormats/GEMRecHit/interface/GEMSegmentCollection.h" + +using GEMSegmentFlatTableProducer = MuRecObjBaseProducer; + +#include "FWCore/PluginManager/interface/ModuleDef.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +DEFINE_FWK_MODULE(DTSegmentFlatTableProducer); +DEFINE_FWK_MODULE(RPCRecHitFlatTableProducer); +DEFINE_FWK_MODULE(GEMRecHitFlatTableProducer); +DEFINE_FWK_MODULE(GEMSegmentFlatTableProducer); diff --git a/DPGAnalysis/MuonTools/python/common_cff.py b/DPGAnalysis/MuonTools/python/common_cff.py new file mode 100644 index 0000000000000..b217515add89c --- /dev/null +++ b/DPGAnalysis/MuonTools/python/common_cff.py @@ -0,0 +1,42 @@ +from PhysicsTools.NanoAOD.common_cff import * +from typing import NamedTuple + +class DEFAULT_VAL(NamedTuple): + INT: int = -999 + INT8: int = -99 + INT_POS: int = -1 + FLOAT: int = -999.0 + FLOAT_POS: int = -1.0 + +defaults = DEFAULT_VAL() + +def DetIdVar(expr, type, doc=None): + """ Create a PSet for a DetId variable in the tree: + - expr is the expression to evaluate to compute the variable, + - type of the value (int, bool, or a string that the table producer understands), + - doc is a docstring, that will be passed to the table producer + """ + if type == float: type = "float" + elif type == bool: type = "bool" + elif type == int: type = "int" + return cms.PSet( + type = cms.string(type), + expr = cms.string(expr), + doc = cms.string(doc if doc else expr) + ) + +def GlobGeomVar(expr, doc=None, precision=-1): + """ Create a PSet for a Global position/direction variable in the tree , + - expr is the expression to evaluate to compute the variable, + - doc is a docstring, that will be passed to the table producer, + - precision is an int handling mantissa reduction. + """ + return cms.PSet( + expr = cms.string(expr), + doc = cms.string(doc if doc else expr), + precision=cms.string(precision) if type(precision)==str else cms.int32(precision) + ) + + + + diff --git a/DPGAnalysis/MuonTools/python/muNtupleProducer_cff.py b/DPGAnalysis/MuonTools/python/muNtupleProducer_cff.py index fa7c4f488b0e2..cddb1df9c08a6 100644 --- a/DPGAnalysis/MuonTools/python/muNtupleProducer_cff.py +++ b/DPGAnalysis/MuonTools/python/muNtupleProducer_cff.py @@ -18,30 +18,42 @@ from DPGAnalysis.MuonTools.muNtupleCSCTnPFiller_cfi import muNtupleCSCTnPFiller muNtupleCSCTnPFiller.ServiceParameters = MuonServiceProxy.ServiceParameters -from DPGAnalysis.MuonTools.muNtupleDTTPGPhiFiller_cfi import muNtupleDTTPGPhiFiller - -muNtupleBmtfInFiller = muNtupleDTTPGPhiFiller.clone() -muNtupleTwinMuxInFiller = muNtupleDTTPGPhiFiller.clone(tag = 'TM_IN', label = 'ltTwinMuxIn', dtTpTag = cms.InputTag('twinMuxStage2Digis','PhIn')) -muNtupleTwinMuxOutFiller = muNtupleDTTPGPhiFiller.clone(tag = 'TM_OUT', label = 'ltTwinMuxOut', dtTpTag = cms.InputTag('twinMuxStage2Digis','PhOut')) - -from DPGAnalysis.MuonTools.muNtupleDTTPGThetaFiller_cfi import muNtupleDTTPGThetaFiller - -muNtupleBmtfInThFiller = muNtupleDTTPGThetaFiller.clone() -muNtupleTwinMuxInThFiller = muNtupleDTTPGThetaFiller.clone(tag = 'TM_IN', label = 'ltTwinMuxInTh', dtTpTag = cms.InputTag('twinMuxStage2Digis','ThIn')) - -muNtupleProducer = cms.Sequence(muNtupleDTDigiFiller - + muNtupleRPCDigiFiller - + muNtupleGEMDigiFiller - + muNtupleRPCRecHitFiller - + muNtupleGEMRecHitFiller - + muNtupleDTSegmentFiller - + muNtupleGEMSegmentFiller - + muNtupleTwinMuxInFiller - + muNtupleTwinMuxOutFiller - + muNtupleBmtfInFiller - + muNtupleTwinMuxInThFiller - + muNtupleBmtfInThFiller - + muNtupleMuonFiller - + muNtupleGEMMuonFiller - + muNtupleCSCTnPFiller - ) \ No newline at end of file +from PhysicsTools.NanoAOD.common_cff import * + +from DPGAnalysis.MuonTools.nano_mu_digi_cff import * +from DPGAnalysis.MuonTools.nano_mu_local_reco_cff import * +from DPGAnalysis.MuonTools.nano_mu_reco_cff import * +from DPGAnalysis.MuonTools.nano_mu_l1t_cff import * + +muNtupleBaseProducer = cms.Sequence(muNtupleDTDigiFiller + + muNtupleRPCDigiFiller + + muNtupleGEMDigiFiller + + muNtupleRPCRecHitFiller + + muNtupleGEMRecHitFiller + + muNtupleDTSegmentFiller + + muNtupleGEMSegmentFiller + + muNtupleMuonFiller + + muNtupleGEMMuonFiller + + muNtupleCSCTnPFiller + ) + +muNtupleProducer = cms.Sequence(muNtupleBaseProducer + + muDigiProducers + + muLocalRecoProducers + + muRecoProducers + + muL1TriggerProducers) + +def nanoAOD_customizeData(process) : + + if hasattr(process, "muNtupleGEMMuonFiller") or hasattr(process, "muNtupleCSCTnPFiller"): + process.load("TrackingTools/TransientTrack/TransientTrackBuilder_cfi") + process.load("TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAny_cfi") + process.load("TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi") + process.load("TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi") + + if hasattr(process, "NANOAODoutput"): + process.NANOAODoutput.outputCommands.append("keep nanoaodFlatTable_*Table*_*_*") + process.NANOAODoutput.outputCommands.append("drop edmTriggerResults_*_*_*") + print(process.NANOAODoutput.outputCommands) + + return process diff --git a/DPGAnalysis/MuonTools/python/nano_mu_digi_cff.py b/DPGAnalysis/MuonTools/python/nano_mu_digi_cff.py new file mode 100644 index 0000000000000..bcb88d073f9a2 --- /dev/null +++ b/DPGAnalysis/MuonTools/python/nano_mu_digi_cff.py @@ -0,0 +1,78 @@ +import FWCore.ParameterSet.Config as cms + +from PhysicsTools.NanoAOD.common_cff import * +from DPGAnalysis.MuonTools.common_cff import * + +from DPGAnalysis.MuonTools.dtDigiFlatTableProducer_cfi import dtDigiFlatTableProducer + +dtDigiFlatTableProducer.name = "dtDigi_t" +dtDigiFlatTableProducer.src = "muonDTDigis" + +dtDigiFlatTableProducer.variables = cms.PSet( + time = Var("time()", float, doc = "digi time"), + wire = Var("wire()", int, doc="wire - [1:X] range" + "
X varies for different chambers SLs and layers") +) + +dtDigiFlatTableProducer.detIdVariables = cms.PSet( + wheel = DetIdVar("wheel()", int, doc = "wheel - [-2:2] range"), + sector = DetIdVar("sector()", int, doc = "sector - [1:14] range" + "
sector 13 used for the second MB4 of sector 4" + "
sector 14 used for the second MB4 of sector 10"), + station = DetIdVar("station()", int, doc = "station - [1:4] range"), + superLayer = DetIdVar("superLayer()", int, doc = "superlayer - [1:3] range" + "
SL 1 and 3 are phi SLs" + "
SL 2 is theta SL"), + layer = DetIdVar("layer()", int, doc = "layer - [1:4] range") +) + + +from DPGAnalysis.MuonTools.rpcDigiFlatTableProducer_cfi import rpcDigiFlatTableProducer + +rpcDigiFlatTableProducer.name = "rpcDigi_t" +rpcDigiFlatTableProducer.src = "muonRPCDigis" + +rpcDigiFlatTableProducer.variables = cms.PSet( + strip = Var("strip()", int, doc = "strip number fired in a given BX"), + bx = Var("bx()", int, doc="bunch crossing number") +) + +rpcDigiFlatTableProducer.detIdVariables = cms.PSet( + region = DetIdVar("region()", int, doc = "0: barrel, +-1: endcap"), + ring = DetIdVar("ring()", int, doc = "ring id:" + "
wheel number in barrel (from -2 to +2)" + "
ring number in endcap (from 1 to 3)"), + station = DetIdVar("station()", int, doc = "chambers at same R in barrel, chambers at same Z ion endcap"), + layer = DetIdVar("layer()", int, doc = "layer id:" + "
in station 1 and 2 for barrel, we have two layers of chambers:" + "
layer 1 is the inner chamber and layer 2 is the outer chamber"), + sector = DetIdVar("sector()", int, doc = "group of chambers at same phi"), + subsector = DetIdVar("subsector()", int, doc = "Some sectors are divided along the phi direction in subsectors " + "(from 1 to 4 in Barrel, from 1 to 6 in Endcap)"), + roll = DetIdVar("roll()", int, doc = "roll id (also known as eta partition):" + "
each chamber is divided along the strip direction"), + rawId = DetIdVar("rawId()", int, doc = "unique detector unit ID") +) + +from DPGAnalysis.MuonTools.gemDigiFlatTableProducer_cfi import gemDigiFlatTableProducer + +gemDigiFlatTableProducer.name = "gemDigi_t" +gemDigiFlatTableProducer.src = "muonGEMDigis" + +gemDigiFlatTableProducer.variables = cms.PSet( + strip = Var("strip()", int, doc = "index of the readout strip associated to the digi"), + bx = Var("bx()", int, doc="bunch crossing number") +) + +gemDigiFlatTableProducer.detIdVariables = cms.PSet( + station = DetIdVar("station()", int, doc = "GEM station
always 1 for GE1/1)"), + region = DetIdVar("region()", int, doc = "GE11 region where the digi is detected" + "
(int, positive endcap: +1, negative endcap: -1"), + roll = DetIdVar("roll()", int, doc = "roll id (also known as eta partition)" + "
(partitions numbered from 1 to 8") +) + +muDigiProducers = cms.Sequence(dtDigiFlatTableProducer + + rpcDigiFlatTableProducer + + gemDigiFlatTableProducer + ) diff --git a/DPGAnalysis/MuonTools/python/nano_mu_l1t_cff.py b/DPGAnalysis/MuonTools/python/nano_mu_l1t_cff.py new file mode 100644 index 0000000000000..b36d88a283583 --- /dev/null +++ b/DPGAnalysis/MuonTools/python/nano_mu_l1t_cff.py @@ -0,0 +1,19 @@ +import FWCore.ParameterSet.Config as cms + +from DPGAnalysis.MuonTools.muDTTPGPhiFlatTableProducer_cfi import muDTTPGPhiFlatTableProducer + +muBmtfInFlatTableProducer = muDTTPGPhiFlatTableProducer.clone() +muTwinMuxInFlatTableProducer = muDTTPGPhiFlatTableProducer.clone(tag = 'TM_IN', name = 'ltTwinMuxIn', src = cms.InputTag('twinMuxStage2Digis','PhIn')) +muTwinMuxOutFlatTableProducer = muDTTPGPhiFlatTableProducer.clone(tag = 'TM_OUT', name = 'ltTwinMuxOut', src = cms.InputTag('twinMuxStage2Digis','PhOut')) + +from DPGAnalysis.MuonTools.muDTTPGThetaFlatTableProducer_cfi import muDTTPGThetaFlatTableProducer + +muBmtfInThFlatTableProducer = muDTTPGThetaFlatTableProducer.clone() +muTwinMuxInThFlatTableProducer = muDTTPGThetaFlatTableProducer.clone(tag = 'TM_IN', name = 'ltTwinMuxInTh', src = cms.InputTag('twinMuxStage2Digis','ThIn')) + +muL1TriggerProducers = cms.Sequence(muTwinMuxInFlatTableProducer + + muTwinMuxOutFlatTableProducer + + muBmtfInFlatTableProducer + + muTwinMuxInThFlatTableProducer + + muBmtfInThFlatTableProducer + ) diff --git a/DPGAnalysis/MuonTools/python/nano_mu_local_reco_cff.py b/DPGAnalysis/MuonTools/python/nano_mu_local_reco_cff.py new file mode 100644 index 0000000000000..b7ed50515da11 --- /dev/null +++ b/DPGAnalysis/MuonTools/python/nano_mu_local_reco_cff.py @@ -0,0 +1,153 @@ +import FWCore.ParameterSet.Config as cms + +from DPGAnalysis.MuonTools.dtSegmentFlatTableProducer_cfi import dtSegmentFlatTableProducer + +from PhysicsTools.NanoAOD.common_cff import * +from DPGAnalysis.MuonTools.common_cff import * + +dtSegmentFlatTableProducer.name = "dtSeg_t" +dtSegmentFlatTableProducer.src = "dt4DSegments" + +dtSegmentFlatTableProducer.variables = cms.PSet( + seg4D_hasPhi = Var("hasPhi()", bool, doc = "has segment phi view - bool"), + seg4D_hasZed = Var("hasZed()", bool, doc = "has segment zed view - bool"), + seg4D_posLoc_x = Var("localPosition().x()", float, doc = "position x in local coordinates - cm"), + seg4D_posLoc_y = Var("localPosition().y()", float, doc = "position y in local coordinates - cm"), + seg4D_posLoc_z = Var("localPosition().z()", float, doc = "position z in local coordinates - cm"), + seg4D_dirLoc_x = Var("localDirection().x()", float, doc = "direction x in local coordinates"), + seg4D_dirLoc_y = Var("localDirection().y()", float, doc = "direction y in local coordinates"), + seg4D_dirLoc_z = Var("localDirection().z()", float, doc = "direction z in local coordinates"), + + seg2D_phi_t0 = Var(f"? hasPhi() ? phiSegment().t0() : {defaults.FLOAT}", float, doc = "t0 from segments with phi view - ns"), + seg2D_phi_nHits = Var(f"? hasPhi() ? phiSegment().specificRecHits().size() : 0", int, doc = "# hits in phi view - [0:8] range"), + seg2D_phi_vDrift = Var(f"? hasPhi() ? phiSegment().vDrift() : {defaults.FLOAT_POS}", float, doc = "v_drift from segments with phi view"), + seg2D_phi_normChi2 = Var(f"? hasPhi() ? (phiSegment().chi2() / phiSegment().degreesOfFreedom()) : {defaults.FLOAT_POS}", float, doc = "chi2/n.d.o.f. from segments with phi view"), + + seg2D_z_t0 = Var(f"? hasZed() ? zSegment().t0() : {defaults.FLOAT}", float, doc = "t0 from segments with z view - ns"), + seg2D_z_nHits = Var(f"? hasZed() ? zSegment().specificRecHits().size() : 0", int, doc = "# hits in z view - [0:4] range"), + seg2D_z_normChi2 = Var(f"? hasZed() ? (zSegment().chi2() / zSegment().degreesOfFreedom()) : {defaults.FLOAT_POS}", float, doc = "chi2/n.d.o.f. from segments with z view"), +) + +dtSegmentFlatTableProducer.detIdVariables = cms.PSet( + wheel = DetIdVar("wheel()", int, doc = "wheel - [-2:2] range"), + sector = DetIdVar("sector()", int, doc = "sector - [1:14] range" + "
sector 13 used for the second MB4 of sector 4" + "
sector 14 used for the second MB4 of sector 10"), + station = DetIdVar("station()", int, doc = "station - [1:4] range") +) + +dtSegmentFlatTableProducer.globalPosVariables = cms.PSet( + seg4D_posGlb_phi = GlobGeomVar("phi().value()", doc = "position phi in global coordinates - radians [-pi:pi]"), + seg4D_posGlb_eta = GlobGeomVar("eta()", doc = "position eta in global coordinates"), +) + +dtSegmentFlatTableProducer.globalDirVariables = cms.PSet( + seg4D_dirGlb_phi = GlobGeomVar("phi().value()", doc = "direction phi in global coordinates - radians [-pi:pi]"), + seg4D_dirGlb_eta = GlobGeomVar("eta()", doc = "direction eta in global coordinates"), +) + +from DPGAnalysis.MuonTools.rpcRecHitFlatTableProducer_cfi import rpcRecHitFlatTableProducer + +rpcRecHitFlatTableProducer.name = "rpcRecHit_t" +rpcRecHitFlatTableProducer.src = "rpcRecHits" + +rpcRecHitFlatTableProducer.variables = cms.PSet( + bx = Var("BunchX()", int, doc="bunch crossing number"), + time = Var("time()", float, doc = "time information in ns"), + firstClusterStrip = Var("firstClusterStrip()", int, doc = "lowest-numbered strip in the cluster"), + clusterSize = Var("clusterSize()", int, doc = "number of strips in the cluster"), + coordX = Var("localPosition().x()", float, doc = "position x in local coordinates - cm"), + coordY = Var("localPosition().y()", float, doc = "position y in local coordinates - cm"), + coordZ = Var("localPosition().z()", float, doc = "position z in local coordinates - cm"), +) + +rpcRecHitFlatTableProducer.detIdVariables = cms.PSet( + region = DetIdVar("region()", int, doc = "0: barrel, +-1: endcap"), + ring = DetIdVar("ring()", int, doc = "ring id:" + "
wheel number in barrel (from -2 to +2)" + "
ring number in endcap (from 1 to 3)"), + station = DetIdVar("station()", int, doc = "chambers at same R in barrel, chambers at same Z ion endcap"), + layer = DetIdVar("layer()", int, doc = "layer id:" + "
in station 1 and 2 for barrel, we have two layers of chambers:" + "
layer 1 is the inner chamber and layer 2 is the outer chamber"), + sector = DetIdVar("sector()", int, doc = "group of chambers at same phi"), + subsector = DetIdVar("subsector()", int, doc = "Some sectors are divided along the phi direction in subsectors " + "(from 1 to 4 in Barrel, from 1 to 6 in Endcap)"), + roll = DetIdVar("roll()", int, doc = "roll id (also known as eta partition):" + "
each chamber is divided along the strip direction"), + rawId = DetIdVar("rawId()", int, doc = "unique detector unit ID") +) + +from DPGAnalysis.MuonTools.gemRecHitFlatTableProducer_cfi import gemRecHitFlatTableProducer + +gemRecHitFlatTableProducer.name = "gemRecHit_t" +gemRecHitFlatTableProducer.src = "gemRecHits" + +gemRecHitFlatTableProducer.variables = cms.PSet( + loc_r = Var("localPosition().perp()", float, doc = "hit position r in local coordinates - cm"), + loc_phi = Var("localPosition().phi().value()", float, doc = "hit position phi in local coordinates - rad"), + loc_x = Var("localPosition().x()", float, doc = "hit position x in local coordinates - cm"), + loc_y = Var("localPosition().y()", float, doc = "hit position y in local coordinates - cm"), + loc_z = Var("localPosition().z()", float, doc = "hit position z in local coordinates - cm"), +) + +gemRecHitFlatTableProducer.detIdVariables = cms.PSet( + roll = DetIdVar("roll()", int, doc = "roll id, also known as eta partition:" + "
(partitions numbered from 1 to 8"), + region = DetIdVar("region()", int, doc = "GE11 region where the hit is reconstructed" + "
(int, positive endcap: +1, negative endcap: -1"), + chamber = DetIdVar("chamber()", int, doc = "GE11 superchamber where the hit is reconstructed" + "
(chambers numbered from 0 to 35"), + layer = DetIdVar("layer()", int, doc = "GE11 layer where the hit is reconstructed" + "
(layer1: 1, layer2: 2") +) + +gemRecHitFlatTableProducer.globalPosVariables = cms.PSet( + g_r = GlobGeomVar("perp()", doc = "hit position r in global coordinates - cm"), + g_phi = GlobGeomVar("phi().value()", doc = "hit position phi in global coordinates - rad"), + g_x = GlobGeomVar("x()", doc = "hit position x in global coordinates - cm"), + g_y = GlobGeomVar("y()", doc = "hit position y in global coordinates - cm"), + g_z = GlobGeomVar("z()", doc = "hit position z in global coordinates - cm") +) + +from DPGAnalysis.MuonTools.gemSegmentFlatTableProducer_cfi import gemSegmentFlatTableProducer + +gemSegmentFlatTableProducer.name = "gemSeg_t" +gemSegmentFlatTableProducer.src = "gemSegments" + +gemSegmentFlatTableProducer.variables = cms.PSet( + chi2 = Var("chi2()", int, doc = ""), + time = Var("buncX()", int, doc="bunch crossing number"), + posLoc_x = Var("localPosition().x()", float, doc = "position x in local coordinates - cm"), + posLoc_y = Var("localPosition().y()", float, doc = "position y in local coordinates - cm"), + posLoc_z = Var("localPosition().z()", float, doc = "position z in local coordinates - cm"), + dirLoc_x = Var("localDirection().x()", float, doc = "direction x in local coordinates"), + dirLoc_y = Var("localDirection().y()", float, doc = "direction y in local coordinates"), + dirLoc_z = Var("localDirection().z()", float, doc = "direction z in local coordinates"), +) + +gemSegmentFlatTableProducer.detIdVariables = cms.PSet( + region = DetIdVar("region()", int, doc = "GE11 region where the hit is reconstructed" + "
(int, positive endcap: +1, negative endcap: -1"), + ring = DetIdVar("ring()", int, doc = ""), + station = DetIdVar("station()", int, doc = "GEM station
always 1 for GE1/1)"), +) + +gemSegmentFlatTableProducer.globalPosVariables = cms.PSet( + posGlb_x = GlobGeomVar("x()", doc = "position x in global coordinates - cm"), + posGlb_y = GlobGeomVar("y()", doc = "position y in global coordinates - cm"), + posGlb_z = GlobGeomVar("z()", doc = "position z in global coordinates - cm"), + posGlb_phi = GlobGeomVar("phi().value()", doc = "position phi in global coordinates - radians [-pi:pi]"), + posGlb_eta = GlobGeomVar("eta()", doc = "position eta in global coordinates"), +) + +gemSegmentFlatTableProducer.globalDirVariables = cms.PSet( + dirGlb_phi = GlobGeomVar("phi().value()", doc = "direction phi in global coordinates - radians [-pi:pi]"), + dirGlb_eta = GlobGeomVar("eta()", doc = "direction eta in global coordinates"), +) + +muLocalRecoProducers = cms.Sequence(rpcRecHitFlatTableProducer + + gemRecHitFlatTableProducer + + dtSegmentFlatTableProducer + + gemSegmentFlatTableProducer + ) diff --git a/DPGAnalysis/MuonTools/python/nano_mu_reco_cff.py b/DPGAnalysis/MuonTools/python/nano_mu_reco_cff.py new file mode 100644 index 0000000000000..5dea5b1a5c707 --- /dev/null +++ b/DPGAnalysis/MuonTools/python/nano_mu_reco_cff.py @@ -0,0 +1,62 @@ +import FWCore.ParameterSet.Config as cms + +from PhysicsTools.NanoAOD.common_cff import * +from DPGAnalysis.MuonTools.common_cff import * + +from RecoMuon.TrackingTools.MuonServiceProxy_cff import MuonServiceProxy +from PhysicsTools.NanoAOD.simpleCandidateFlatTableProducer_cfi import simpleCandidateFlatTableProducer + +from PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi import * + +muonFlatTableProducer = simpleCandidateFlatTableProducer.clone( + src = cms.InputTag("patMuons"), + name = cms.string("muon_t"), + doc = cms.string("..."), + + variables = cms.PSet(CandVars, # CB is this including eta + isGlobal = Var("isGlobalMuon", bool, doc="muon is global muon"), + isTracker = Var("isTrackerMuon", bool, doc="muon is tracker muon"), + # isTrackerArb = Var("muon::isGoodMuon(muon, muon::TrackerMuonArbitrated)", bool, doc="muon is tracker muon arbitrated"), + isStandalone = Var("isStandAloneMuon", bool, doc="muon is a standalone muon"), + isRPC = Var("isRPCMuon", bool, doc="muon is an RPC muon"), + isGEM = Var("isGEMMuon", bool, doc="muon is a GEM muon"), + + isLoose = Var("passed('CutBasedIdLoose')", bool, doc="Loose muon ID"), + sMedium = Var("passed('CutBasedIdMedium')", bool, doc="Medium muon ID"), + isTight = Var("passed('CutBasedIdTight')", bool, doc="Tight muon ID"), + + pfIso04 = Var("(pfIsolationR04().sumChargedHadronPt + max(pfIsolationR04().sumNeutralHadronEt + pfIsolationR04().sumPhotonEt - pfIsolationR04().sumPUPt/2,0.0))/pt", float, doc="Relative tracker isolation (0.3 cone)", precision=6), + trkIso03 = Var("isolationR03().sumPt/tunePMuonBestTrack().pt", float, doc="Relative PF-isolation (delta beta corrected, 0.4 cone)", precision=6), + + trk_dz = Var(f"?!innerTrack().isNull()? dB('PVDZ') : {defaults.FLOAT}", float, doc="dz (with sign) wrt first PV - cm", precision=10), + trk_dxy = Var(f"?!innerTrack().isNull()? dB('PV2D') : {defaults.FLOAT}", float, doc="dxy (with sign) wrt first PV - cm", precision=10), + + trk_algo = Var(f"?!innerTrack().isNull()? innerTrack().algo() : {defaults.INT_POS}", "int8", doc="iterative tracking algorithm used to build the inner track"), + trk_origAlgo = Var(f"?!innerTrack().isNull()? innerTrack().originalAlgo() : {defaults.INT_POS}", "int8", doc="original (pre muon iterations) iterative tracking algorithm used to build the inner track"), + + trk_numberOfValidPixelHits = Var(f"?!innerTrack().isNull()? innerTrack().hitPattern().numberOfValidPixelHits() : {defaults.INT_POS}", "int8", doc="number of valid pixel hits"), + trk_numberOfValidTrackerLayers = Var(f"?!innerTrack().isNull()? innerTrack().hitPattern().trackerLayersWithMeasurement() : {defaults.INT_POS}", "int8", doc="number of valid tracker layers"), + trk_validFraction = Var(f"?!innerTrack().isNull()? innerTrack().validFraction() : {defaults.FLOAT_POS}", "int8", doc="number of valid pixel hits"), + + trkMu_stationMask = Var("stationMask()", "uint8", doc="bit map of stations with tracks within given distance (in cm) of chamber edges"), + trkMu_numberOfMatchedStations = Var("numberOfMatchedStations()", "int8", doc="number of matched DT/CSC stations"), + rpcMu_numberOfMatchedRPCLayers = Var("numberOfMatchedRPCLayers()", "int8", doc="number of matched RPC layers"), + + staMu_numberOfValidMuonHits = Var(f"?isStandAloneMuon()? outerTrack().hitPattern().numberOfValidMuonHits() : {defaults.INT_POS}", "int8", doc="Number of valid muon hits"), + + staMu_normChi2 = Var(f"?isStandAloneMuon()? outerTrack().chi2()/outerTrack().ndof() : {defaults.FLOAT_POS}", float, doc="chi2/ndof (standalone track)", precision=10), + glbMu_normChi2 = Var(f"?isGlobalMuon()? globalTrack().chi2()/globalTrack().ndof() : {defaults.FLOAT_POS}", float, doc="chi2/ndof (global track)", precision=10) + ) +) + +from DPGAnalysis.MuonTools.muNtupleMuonFiller_cfi import muNtupleMuonFiller + +from DPGAnalysis.MuonTools.muNtupleGEMMuonFiller_cfi import muNtupleGEMMuonFiller +muNtupleGEMMuonFiller.ServiceParameters = MuonServiceProxy.ServiceParameters + +from DPGAnalysis.MuonTools.muNtupleCSCTnPFiller_cfi import muNtupleCSCTnPFiller +muNtupleCSCTnPFiller.ServiceParameters = MuonServiceProxy.ServiceParameters + +muRecoProducers = cms.Sequence(patMuons + + muonFlatTableProducer + ) diff --git a/DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.cc b/DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.cc new file mode 100644 index 0000000000000..0ce9cb3c36937 --- /dev/null +++ b/DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.cc @@ -0,0 +1,22 @@ +/** \class MuBaseFlatTableProducer MuBaseFlatTableProducer.cc DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.cc + * + * Helper class defining the generic interface of a FlatTableProducer + * + * \author C. Battilana (INFN BO) + * + * + */ + +#include "DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.h" + +MuBaseFlatTableProducer::MuBaseFlatTableProducer(const edm::ParameterSet &config) + : m_name{config.getParameter("name")} {} + +void MuBaseFlatTableProducer::beginRun(const edm::Run &run, const edm::EventSetup &environment) { + getFromES(run, environment); +} + +void MuBaseFlatTableProducer::produce(edm::Event &ev, const edm::EventSetup &environment) { + getFromES(environment); + fillTable(ev); +} diff --git a/DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.h b/DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.h new file mode 100644 index 0000000000000..086f180133747 --- /dev/null +++ b/DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.h @@ -0,0 +1,73 @@ +#ifndef Mu_MuBaseFlatTableProducer_h +#define Mu_MuBaseFlatTableProducer_h + +/** \class MuBaseFlatTableProducer MuBaseFlatTableProducer.h DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.h + * + * Helper class defining the generic interface of a FlatTableProducer + * + * \author C. Battilana (INFN BO) + * + * + */ + +#include "DPGAnalysis/MuonTools/src/MuNtupleUtils.h" + +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" + +#include "DataFormats/NanoAOD/interface/FlatTable.h" + +#include + +class MuBaseFlatTableProducer : public edm::stream::EDProducer<> { +public: + /// Constructor + explicit MuBaseFlatTableProducer(const edm::ParameterSet &); + + /// Configure event setup for each run + void beginRun(const edm::Run &run, const edm::EventSetup &config) final; + + /// Fill ntuples event by event + void produce(edm::Event &, const edm::EventSetup &) final; + + /// Empty, needed by interface + void endRun(const edm::Run &, const edm::EventSetup &) final {} + +protected: + /// The label name of the FlatTableProducer + std::string m_name; + + /// Get info from the ES by run + virtual void getFromES(const edm::Run &run, const edm::EventSetup &environment) {} + + /// Get info from the ES for a given event + virtual void getFromES(const edm::EventSetup &environment) {} + + /// Fill ntuple + virtual void fillTable(edm::Event &ev) = 0; + + /// Definition of default values for int variables + static constexpr int DEFAULT_INT_VAL{-999}; + + /// Definition of default values for int8 variables + static constexpr int8_t DEFAULT_INT8_VAL{-99}; + + /// Definition of default values for positive int variables + static constexpr int DEFAULT_INT_VAL_POS{-1}; + + /// Definition of default values for float variables + static constexpr double DEFAULT_DOUBLE_VAL{-999.0}; + + /// Definition of default values for positive float variables + static constexpr double DEFAULT_DOUBLE_VAL_POS{-1.0}; + + template + void addColumn(std::unique_ptr &table, + const std::string name, + const std::vector &vec, + const std::string descr) { + table->template addColumn>(name, vec, descr); + } +}; + +#endif diff --git a/DPGAnalysis/MuonTools/src/MuDigiBaseProducer.h b/DPGAnalysis/MuonTools/src/MuDigiBaseProducer.h new file mode 100644 index 0000000000000..e521415c1cca5 --- /dev/null +++ b/DPGAnalysis/MuonTools/src/MuDigiBaseProducer.h @@ -0,0 +1,118 @@ +#ifndef MuonTools_MuDigiBaseProducer_h +#define MuonTools_MuDigiBaseProducer_h + +/** \class MuDigiBaseProducer MuDigiBaseProducer.h DPGAnalysis/MuonTools/src/MuDigiBaseProducer.h + * + * Helper class defining the generic interface of a muon digi Producer + * + * \author C. Battilana (INFN BO) + * + * + */ + +#include "DataFormats/MuonData/interface/MuonDigiCollection.h" +#include "PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include +#include +#include + +template +class MuDigiBaseProducer : public SimpleFlatTableProducerBase> { + using COLLECTION = MuonDigiCollection; + + using IntDetVar = FuncVariable, int>; + using UIntDetVar = FuncVariable, unsigned int>; + using Int8DetVar = FuncVariable, int8_t>; + using UInt8DetVar = FuncVariable, uint8_t>; + + std::vector>> detIdVars_; + +public: + MuDigiBaseProducer(edm::ParameterSet const ¶ms) : SimpleFlatTableProducerBase(params) { + const auto &varCfgs = params.getParameter("detIdVariables"); + const auto &varNames = varCfgs.getParameterNamesForType(); + + std::transform(varNames.begin(), varNames.end(), std::back_inserter(detIdVars_), [&](const auto &name) { + const edm::ParameterSet &varCfg = varCfgs.getParameter(name); + const std::string &type = varCfg.getParameter("type"); + + std::unique_ptr> detVarPtr; + + if (type == "int") { + detVarPtr = std::move(std::make_unique(name, varCfg)); + } else if (type == "uint") { + detVarPtr = std::move(std::make_unique(name, varCfg)); + } else if (type == "int8") { + detVarPtr = std::move(std::make_unique(name, varCfg)); + } else if (type == "uint8") { + detVarPtr = std::move(std::make_unique(name, varCfg)); + } else { + throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + name); + } + + return detVarPtr; + }); + } + + ~MuDigiBaseProducer() override {} + + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions) { + edm::ParameterSetDescription desc = SimpleFlatTableProducerBase::baseDescriptions(); + + edm::ParameterSetDescription variable; + edm::Comment comType{"the c++ type of the branch in the flat table"}; + edm::Comment comPrecision{"the precision with which to store the value in the flat table"}; + + variable.add("expr")->setComment("a function to define the content of the branch in the flat table"); + variable.add("doc")->setComment("few words description of the branch content"); + + variable.ifValue(edm::ParameterDescription("type", "int", true, comType), + edm::allowedValues("int", "unit", "int8", "uint8")); + + edm::ParameterSetDescription variables; + + variables.setComment("a parameters set to define all variable taken form detId to fill the flat table"); + + edm::ParameterWildcard variableWildCard{"*", edm::RequireZeroOrMore, true, variable}; + variables.addNode(variableWildCard); + + desc.add("detIdVariables", variables); + + descriptions.addWithDefaultLabel(desc); + } + + std::unique_ptr fillTable(const edm::Event &iEvent, + const edm::Handle &prod) const override { + std::vector digis; + std::vector detIds; + std::list detIdObjs; // CB needed to store DetIds (they are transient) + + if (prod.isValid()) { + auto detIdIt = prod->begin(); + auto detIdEnd = prod->end(); + + for (; detIdIt != detIdEnd; ++detIdIt) { + const auto &[detId, range] = (*detIdIt); + detIdObjs.push_back(detId); + std::fill_n(std::back_inserter(detIds), range.second - range.first, &detIdObjs.back()); + std::transform(range.first, range.second, std::back_inserter(digis),[](const auto & digi){ return &digi; }); + } + } + + auto table = std::make_unique(digis.size(), this->name_, false, this->extension_); + + for (const auto &var : this->vars_) { + var->fill(digis, *table); + } + + for (const auto &var : detIdVars_) { + var->fill(detIds, *table); + } + + return table; + } +}; + +#endif diff --git a/DPGAnalysis/MuonTools/src/MuNtupleBaseFiller.h b/DPGAnalysis/MuonTools/src/MuNtupleBaseFiller.h index 8ab1a68e2c8a9..921a5d854cd7e 100644 --- a/DPGAnalysis/MuonTools/src/MuNtupleBaseFiller.h +++ b/DPGAnalysis/MuonTools/src/MuNtupleBaseFiller.h @@ -69,4 +69,5 @@ class MuNtupleBaseFiller : public edm::stream::EDProducer<> { table->template addColumn>(name, vec, descr); } }; + #endif diff --git a/DPGAnalysis/MuonTools/src/MuRecObjBaseProducer.h b/DPGAnalysis/MuonTools/src/MuRecObjBaseProducer.h new file mode 100644 index 0000000000000..b02d36230b5e8 --- /dev/null +++ b/DPGAnalysis/MuonTools/src/MuRecObjBaseProducer.h @@ -0,0 +1,216 @@ +#ifndef MuonTools_MuRecObjBaseProducer_h +#define MuonTools_MuRecObjBaseProducer_h + +/** \class MuRecObjBaseProducer MuRecObjBaseProducer.h DPGAnalysis/MuonTools/src/MuRecObjBaseProducer.h + * + * Helper class defining the generic interface of a muon digi Producer + * + * \author C. Battilana (INFN BO) + * + * + */ + +#include "DataFormats/Common/interface/RangeMap.h" +#include "DataFormats/Common/interface/ClonePolicy.h" +#include "DataFormats/Common/interface/OwnVector.h" + +#include "PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "FWCore/Framework/interface/ESHandle.h" + +#include "FWCore/Utilities/interface/ESGetToken.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" +#include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h" +#include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h" + +// CB non servono davvero mi sa (i primi due) +#include "DataFormats/GeometryVector/interface/GlobalPoint.h" +#include "DataFormats/GeometryVector/interface/GlobalVector.h" +#include "DataFormats/TrackingRecHit/interface/RecSegment.h" + +#include +#include +#include +#include + +template +class MuRecObjBaseProducer + : public SimpleFlatTableProducerBase>> { + using COLLECTION = edm::RangeMap>; + + edm::ESGetToken m_token; + edm::ESHandle m_geometry; + + using IntDetVar = FuncVariable, int>; + using UIntDetVar = FuncVariable, unsigned int>; + using Int8DetVar = FuncVariable, int8_t>; + using UInt8DetVar = FuncVariable, uint8_t>; + + std::vector>> detIdVars_; + + using GlobalPosVar = FuncVariable, float>; + using GlobalDirVar = FuncVariable, float>; + + std::vector>> globalPosVars_; + std::vector>> globalDirVars_; + +public: + MuRecObjBaseProducer(edm::ParameterSet const ¶ms) + : SimpleFlatTableProducerBase(params), m_token{this->template esConsumes()} { + auto varCfgs = params.getParameter("detIdVariables"); + auto varNames = varCfgs.getParameterNamesForType(); + + std::transform(varNames.begin(), varNames.end(), std::back_inserter(detIdVars_), [&](const auto &name) { + const edm::ParameterSet &varCfg = varCfgs.getParameter(name); + const std::string &type = varCfg.getParameter("type"); + + std::unique_ptr> detVarPtr; + + if (type == "int") { + detVarPtr = std::move(std::make_unique(name, varCfg)); // Cb can improve? + } else if (type == "uint") { + detVarPtr = std::move(std::make_unique(name, varCfg)); + } else if (type == "int8") { + detVarPtr = std::move(std::make_unique(name, varCfg)); + } else if (type == "uint8") { + detVarPtr = std::move(std::make_unique(name, varCfg)); + } else { + throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + name); + } + + return detVarPtr; + }); + + varCfgs = params.getParameter("globalPosVariables"); + varNames = varCfgs.getParameterNamesForType(); + + std::transform(varNames.begin(), varNames.end(), std::back_inserter(globalPosVars_), [&](const auto &name) { + return std::make_unique(name, varCfgs.getParameter(name)); + }); + + if constexpr (std::is_base_of_v) { + varCfgs = params.getParameter("globalDirVariables"); + varNames = varCfgs.getParameterNamesForType(); + + std::transform(varNames.begin(), varNames.end(), std::back_inserter(globalDirVars_), [&](const auto &name) { + return std::make_unique(name, varCfgs.getParameter(name)); + }); + } + } + + ~MuRecObjBaseProducer() override {} + + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions) { + edm::ParameterSetDescription desc = SimpleFlatTableProducerBase::baseDescriptions(); + + auto baseDescription = []() { + edm::ParameterSetDescription varBase; + + varBase.add("expr")->setComment("a function to define the content of the branch in the flat table"); + varBase.add("doc")->setComment("few words description of the branch content"); + + return varBase; + }; + + auto fullDescription = [](auto const &var, std::string const label) { + edm::ParameterSetDescription fullDesc; + + edm::ParameterWildcard detIdVarWildCard{"*", edm::RequireZeroOrMore, true, var}; + fullDesc.setComment("a parameters set to define all " + label + " variables to the flat table"); + fullDesc.addNode(detIdVarWildCard); + + return fullDesc; + }; + + auto detIdVar{baseDescription()}; + auto globalGeomVar{baseDescription()}; + + edm::Comment comType{"the c++ type of the branch in the flat table"}; + detIdVar.ifValue(edm::ParameterDescription{"type", "int", true, comType}, + edm::allowedValues("int", "unit", "int8", "uint8")); + + edm::Comment comPrecision{"the precision with which to store the value in the flat table"}; + globalGeomVar.addOptionalNode(edm::ParameterDescription{"precision", true, comPrecision}, false); + + desc.add("detIdVariables", fullDescription(detIdVar, "DetId")); + desc.add("globalPosVariables", fullDescription(globalGeomVar, "Global Position")); + + if constexpr (std::is_base_of_v) { + desc.add("globalDirVariables", fullDescription(globalGeomVar, "Global Direction")); + } + + descriptions.addWithDefaultLabel(desc); + } + + std::unique_ptr fillTable(const edm::Event &iEvent, + const edm::Handle &product) const override { + std::vector objs; + std::vector detIds; + std::vector globalPositions; + std::vector globalDirections; + + // CB needed to store DetIds, global points and vectors (they are transient) + std::list detIdObjs; + std::list globalPointObjs; + std::list globalVectorObjs; + + if (product.isValid()) { + auto detIdIt = product->id_begin(); + const auto detIdEnd = product->id_end(); + + for (; detIdIt != detIdEnd; ++detIdIt) { + const auto &range = product->get(*detIdIt); + const GeomDet *geomDet = m_geometry->idToDet(*detIdIt); + + detIdObjs.push_back(*detIdIt); + std::fill_n(std::back_inserter(detIds), range.second - range.first, &detIdObjs.back()); + + for (auto objIt{range.first}; objIt != range.second; ++objIt) { + objs.push_back(&(*objIt)); + globalPointObjs.push_back(geomDet->toGlobal(objIt->localPosition())); + globalPositions.push_back(&globalPointObjs.back()); + if constexpr (std::is_base_of_v) { + globalVectorObjs.push_back(geomDet->toGlobal(objIt->localDirection())); + globalDirections.push_back(&globalVectorObjs.back()); + } + } + } + } + + auto table = std::make_unique(objs.size(), this->name_, false, this->extension_); + + for (const auto &var : this->vars_) { + var->fill(objs, *table); + } + + for (const auto &var : detIdVars_) { + var->fill(detIds, *table); + } + + for (const auto &var : globalPosVars_) { + var->fill(globalPositions, *table); + } + + if constexpr (std::is_base_of_v) { + for (const auto &var : globalDirVars_) { + var->fill(globalDirections, *table); + } + } + + return table; + } + + void produce(edm::Event &event, const edm::EventSetup &environment) override { + edm::Handle src; + event.getByToken(this->src_, src); + + m_geometry = environment.getHandle(m_token); + std::unique_ptr out = fillTable(event, src); + out->setDoc(this->doc_); + + event.put(std::move(out)); + } +}; + +#endif diff --git a/DPGAnalysis/MuonTools/test/muDpgNtuples_cfg.py b/DPGAnalysis/MuonTools/test/muDpgNtuplesZMu_cfg.py similarity index 94% rename from DPGAnalysis/MuonTools/test/muDpgNtuples_cfg.py rename to DPGAnalysis/MuonTools/test/muDpgNtuplesZMu_cfg.py index 09ba292252801..089cfeca4783a 100644 --- a/DPGAnalysis/MuonTools/test/muDpgNtuples_cfg.py +++ b/DPGAnalysis/MuonTools/test/muDpgNtuplesZMu_cfg.py @@ -9,7 +9,7 @@ options = VarParsing.VarParsing() options.register('globalTag', - '124X_dataRun3_Prompt_v4', #default value + '125X_dataRun3_relval_v4', #default value VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string, "Global Tag") @@ -21,7 +21,7 @@ "Maximum number of processed events") options.register('inputFile', - '/store/data/Run2022E/Muon/RAW-RECO/ZMu-PromptReco-v1/000/359/751/00000/7f3b707b-dabb-437f-a731-0303e3030e8f.root', #default value + '/store/relval/CMSSW_12_6_0_pre5/SingleMuon/FEVTDEBUGHLT/125X_dataRun3_HLT_relval_v3_RelVal_2022C-v2/2590000//053845fa-aa05-48a3-8bc0-c833cfdd3e53.root', #default value VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string, "EOS folder with input files")