diff --git a/Configuration/PyReleaseValidation/python/relval_nano.py b/Configuration/PyReleaseValidation/python/relval_nano.py index 74fb42436e75a..221f7e85d536e 100644 --- a/Configuration/PyReleaseValidation/python/relval_nano.py +++ b/Configuration/PyReleaseValidation/python/relval_nano.py @@ -106,6 +106,9 @@ steps['NANO_data12.4']=merge([{'--era':'Run3,run3_nanoAOD_124', '--conditions':'auto:run3_data'}, _NANO_data]) +#prompt nano test +steps['NANO_data12.4_prompt']=merge([{'--customise' : 'PhysicsTools/NanoAOD/nano_cff.nanoL1TrigObjCustomize', '-n' : '1000'}, + steps['NANO_data12.4']]) ##12.6 workflows steps['TTBarMINIAOD12.6'] = {'INPUT':InputInfo(location='STD',ls=run3_lumis, @@ -134,6 +137,8 @@ #12.4 input workflows[2500.501] = ['NANOmc124Xrun3', ['TTbarMINIAOD12.4','NANO_mc12.4', 'HRV_NANO_mc']] workflows[2500.511] = ['NANOdata124Xrun3', ['MuonEG2022MINIAOD12.4','NANO_data12.4', 'HRV_NANO_data']] +workflows[2500.5111] = ['NANOdata124Xrun3', ['MuonEG2022MINIAOD12.4','NANO_data12.4_prompt', 'HRV_NANO_data']] + ################ #12.6 workflows diff --git a/PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h b/PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h index 41184463cc12a..85d63e7ca8948 100644 --- a/PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h +++ b/PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h @@ -10,6 +10,7 @@ #include "DataFormats/Common/interface/ValueMap.h" #include "DataFormats/NanoAOD/interface/FlatTable.h" #include "Utilities/General/interface/ClassName.h" +#include "DataFormats/L1Trigger/interface/BXVector.h" #include "CommonTools/Utils/interface/StringCutObjectSelector.h" #include "CommonTools/Utils/interface/StringObjectFunction.h" @@ -349,6 +350,78 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase>> extvars_; }; +template +class BXVectorSimpleFlatTableProducer : public SimpleFlatTableProducerBase> { +public: + BXVectorSimpleFlatTableProducer(edm::ParameterSet const ¶ms) + : SimpleFlatTableProducerBase>(params), + maxLen_(params.existsAs("maxLen") ? params.getParameter("maxLen") + : std::numeric_limits::max()), + cut_(params.getParameter("cut"), true), + minBX_(params.getParameter("minBX")), + maxBX_(params.getParameter("maxBX")), + alwaysWriteBXValue_(params.getParameter("alwaysWriteBXValue")), + bxVarName_("bx") { + edm::ParameterSet const &varsPSet = params.getParameter("variables"); + auto varNames = varsPSet.getParameterNamesForType(); + if (std::find(varNames.begin(), varNames.end(), bxVarName_) != varNames.end()) { + throw cms::Exception("Configuration", + "BXVectorSimpleFlatTableProducer already defines the " + bxVarName_ + + "internally and thus you should not specify it yourself"); + } + } + + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions) { + edm::ParameterSetDescription desc = SimpleFlatTableProducerBase>::baseDescriptions(); + desc.add("cut", "")->setComment( + "selection on the main input collection (but selection can not be bx based)"); + desc.addOptional("maxLen")->setComment( + "define the maximum length of the input collection to put in the branch"); + desc.add("minBX", -2)->setComment("min bx (inclusive) to include"); + desc.add("maxBX", 2)->setComment("max bx (inclusive) to include"); + desc.add("alwaysWriteBXValue", true) + ->setComment("always write the bx number (event when only one bx can be present, ie minBX==maxBX)"); + descriptions.addWithDefaultLabel(desc); + } + + std::unique_ptr fillTable(const edm::Event &iEvent, + const edm::Handle> &prod) const override { + std::vector selObjs; + std::vector selObjBXs; + + if (prod.isValid() || !(this->skipNonExistingSrc_)) { + const int minBX = std::max(minBX_, prod->getFirstBX()); + const int maxBX = std::min(maxBX_, prod->getLastBX()); + for (int bx = minBX; bx <= maxBX; bx++) { + for (size_t objNr = 0, nrObjs = prod->size(bx); objNr < nrObjs; ++objNr) { + const auto &obj = prod->at(bx, objNr); + if (cut_(obj)) { + selObjs.push_back(&obj); + selObjBXs.push_back(bx); + } + if (selObjs.size() >= maxLen_) + break; + } + } + } + auto out = std::make_unique(selObjs.size(), this->name_, false, this->extension_); + for (const auto &var : this->vars_) + var->fill(selObjs, *out); + if (alwaysWriteBXValue_ || minBX_ != maxBX_) { + out->template addColumn(bxVarName_, selObjBXs, "BX of the L1 candidate"); + } + return out; + } + +protected: + const unsigned int maxLen_; + const StringCutObjectSelector cut_; + const int minBX_; + const int maxBX_; + const bool alwaysWriteBXValue_; + const std::string bxVarName_; +}; + template class EventSingletonSimpleFlatTableProducer : public SimpleFlatTableProducerBase { public: diff --git a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc index cf30e060c442b..412f38d8eb129 100644 --- a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc +++ b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc @@ -24,6 +24,21 @@ typedef EventSingletonSimpleFlatTableProducer SimpleXYZPointFla #include "DataFormats/BeamSpot/interface/BeamSpot.h" typedef EventSingletonSimpleFlatTableProducer SimpleBeamspotFlatTableProducer; +#include "DataFormats/L1Trigger/interface/EGamma.h" +typedef BXVectorSimpleFlatTableProducer SimpleTriggerL1EGFlatTableProducer; + +#include "DataFormats/L1Trigger/interface/Jet.h" +typedef BXVectorSimpleFlatTableProducer SimpleTriggerL1JetFlatTableProducer; + +#include "DataFormats/L1Trigger/interface/Tau.h" +typedef BXVectorSimpleFlatTableProducer SimpleTriggerL1TauFlatTableProducer; + +#include "DataFormats/L1Trigger/interface/Muon.h" +typedef BXVectorSimpleFlatTableProducer SimpleTriggerL1MuonFlatTableProducer; + +#include "DataFormats/L1Trigger/interface/EtSum.h" +typedef BXVectorSimpleFlatTableProducer SimpleTriggerL1EtSumFlatTableProducer; + #include "FWCore/Framework/interface/MakerMacros.h" DEFINE_FWK_MODULE(SimpleCandidateFlatTableProducer); DEFINE_FWK_MODULE(SimpleGenEventFlatTableProducer); @@ -33,3 +48,8 @@ DEFINE_FWK_MODULE(SimpleProtonTrackFlatTableProducer); DEFINE_FWK_MODULE(SimpleLocalTrackFlatTableProducer); DEFINE_FWK_MODULE(SimpleXYZPointFlatTableProducer); DEFINE_FWK_MODULE(SimpleBeamspotFlatTableProducer); +DEFINE_FWK_MODULE(SimpleTriggerL1EGFlatTableProducer); +DEFINE_FWK_MODULE(SimpleTriggerL1JetFlatTableProducer); +DEFINE_FWK_MODULE(SimpleTriggerL1MuonFlatTableProducer); +DEFINE_FWK_MODULE(SimpleTriggerL1TauFlatTableProducer); +DEFINE_FWK_MODULE(SimpleTriggerL1EtSumFlatTableProducer); diff --git a/PhysicsTools/NanoAOD/python/l1trig_cff.py b/PhysicsTools/NanoAOD/python/l1trig_cff.py new file mode 100644 index 0000000000000..53ca6153e9c95 --- /dev/null +++ b/PhysicsTools/NanoAOD/python/l1trig_cff.py @@ -0,0 +1,179 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.nano_eras_cff import * +from PhysicsTools.NanoAOD.common_cff import * + +l1_float_precision_=12 + +l1PtVars = cms.PSet( + pt = Var("pt", float, precision=l1_float_precision_), + phi = Var("phi", float, precision=l1_float_precision_), +) +l1P3Vars = cms.PSet( + l1PtVars, + eta = Var("eta", float, precision=l1_float_precision_), +) + +l1ObjVars = cms.PSet( + l1P3Vars, + hwPt = Var("hwPt()","int16",doc="hardware pt"), + hwEta = Var("hwEta()","int16",doc="hardware eta"), + hwPhi = Var("hwPhi()","int16",doc="hardware phi"), + hwQual = Var("hwQual()","int16",doc="hardware qual"), + hwIso = Var("hwIso()","int16",doc="hardware iso") +) + +l1CaloObjVars = cms.PSet( + l1ObjVars, + towerIEta = Var("towerIEta()","int16",doc="the ieta of the tower"), + towerIPhi = Var("towerIPhi()","int16",doc="the iphi of the tower"), +) + +l1JetReducedVars = cms.PSet( + l1P3Vars +) + +l1EtSumReducedVars = cms.PSet( + l1PtVars, + etSumType = Var("getType()",int,doc="et sum type"), +) +l1EGReducedVars = cms.PSet( + l1P3Vars, + hwIso = Var("hwIso()","int16",doc="hardware iso") +) + +l1TauReducedVars = cms.PSet( + l1P3Vars, + hwIso = Var("hwIso()","int16",doc="hardware iso") +) + +l1MuonReducedVars = cms.PSet( + l1P3Vars, + hwQual = Var("hwQual()",int,doc="hardware qual"), + hwCharge = Var("hwCharge()","int16",doc="hardware charge"), + etaAtVtx = Var("etaAtVtx()",float,precision=l1_float_precision_,doc="eta estimated at the vertex"), + phiAtVtx = Var("phiAtVtx()",float,precision=l1_float_precision_,doc="phi estimated at the vertex"), + ptUnconstrained = Var("ptUnconstrained()",float,precision=l1_float_precision_,doc="pt when not constrained to the beamspot"), + hwDXY = Var("hwDXY()","int16",doc="hardware impact parameter"), +) + +l1MuTable = cms.EDProducer("SimpleTriggerL1MuonFlatTableProducer", + src = cms.InputTag("gmtStage2Digis","Muon"), + minBX = cms.int32(-2), + maxBX = cms.int32(2), + cut = cms.string(""), + name= cms.string("L1Mu"), + doc = cms.string(""), + extension = cms.bool(False), + variables = cms.PSet(l1ObjVars, + hwCharge = Var("hwCharge()","int16",doc="Charge (can be 0 if the charge measurement was not valid)"), + hwChargeValid = Var("hwChargeValid()","int16",doc=""), + tfMuonIndex = Var("tfMuonIndex()","uint16",doc="Index of muon at the uGMT input. 3 indices per link/sector/wedge. EMTF+ are 0-17, OMTF+ are 18-35, BMTF are 36-71, OMTF- are 72-89, EMTF- are 90-107"), + hwTag = Var("hwTag()","int16",doc="not in L1 ntuples"), + hwEtaAtVtx = Var("hwEtaAtVtx()","int16",doc="hardware eta estimated at the vertex"), + hwPhiAtVtx = Var("hwPhiAtVtx()","int16",doc="hardware phi estimated at the vertex"), + etaAtVtx = Var("etaAtVtx()",float,doc="eta estimated at the vertex"), + phiAtVtx = Var("phiAtVtx()",float,doc="phi estimated at the vertex"), + hwIsoSum = Var("hwIsoSum()","int16",doc="not in L1 ntuples"), + hwDPhiExtra = Var("hwDPhiExtra()","int16",doc="Delta between Pseudo-rapidity at the muon system and the projected coordinate at the vertex in HW unit (for future l1t-integration-tag"), + hwDEtaExtra = Var("hwDEtaExtra()","int16",doc="Delta between Azimuth at the muon system and the projected coordinate at the vertex in HW unit (for future l1t-integration-tag)"), + hwRank = Var("hwRank()","int16",doc="not in L1Ntuples"), + hwPtUnconstrained = Var("hwPtUnconstrained()","int16",doc=""), + ptUnconstrained = Var("ptUnconstrained()",float,doc=""), + hwDXY = Var("hwDXY()","uint16",doc=""), + ) +) + + +l1JetTable = cms.EDProducer("SimpleTriggerL1JetFlatTableProducer", + src = cms.InputTag("caloStage2Digis","Jet"), + minBX = cms.int32(-2), + maxBX = cms.int32(2), + cut = cms.string(""), + name= cms.string("L1Jet"), + doc = cms.string(""), + extension = cms.bool(False), + variables = cms.PSet(l1CaloObjVars, + rawEt = Var("rawEt()","int16",doc="raw (uncalibrated) et"), + seedEt = Var("seedEt()","int16",doc="et of the seed"), + puEt = Var("puEt()","int16",doc="pile up et "), + puDonutEt0 = Var("puDonutEt(0)","int16",doc=""), + puDonutEt1 = Var("puDonutEt(1)","int16",doc=""), + puDonutEt2 = Var("puDonutEt(2)","int16",doc=""), + puDonutEt3 = Var("puDonutEt(3)","int16",doc=""), + ) +) + +l1TauTable = cms.EDProducer("SimpleTriggerL1TauFlatTableProducer", + src = cms.InputTag("caloStage2Digis","Tau"), + minBX = cms.int32(-2), + maxBX = cms.int32(2), + cut = cms.string(""), + name= cms.string("L1Tau"), + doc = cms.string(""), + extension = cms.bool(False), # this is the main table for L1 EGs + variables = cms.PSet(l1CaloObjVars, + rawEt = Var("rawEt()","int16",doc="raw Et of tau"), + isoEt = Var("isoEt()","int16",doc="raw isolation sum - cluster sum"), + nTT = Var("nTT()","int16",doc=" nr towers above threshold"), + hasEM = Var("hasEM()",bool,doc="has an em component"), + isMerged = Var("isMerged()",bool,doc="is merged"), + + ) +) + +l1EtSumTable = cms.EDProducer("SimpleTriggerL1EtSumFlatTableProducer", + src = cms.InputTag("caloStage2Digis","EtSum"), + minBX = cms.int32(-2), + maxBX = cms.int32(2), + cut = cms.string(""), + name= cms.string("L1EtSum"), + doc = cms.string(""), + extension = cms.bool(False), + variables = cms.PSet(l1PtVars, + hwPt = Var("hwPt()",int,doc="hardware pt"), + hwPhi = Var("hwPhi()",int,doc="hardware phi"), + etSumType = Var("getType()",int,doc="the type of the ET Sum (https://github.com/cms-sw/cmssw/blob/master/DataFormats/L1Trigger/interface/EtSum.h#L27-L56)"), + ) +) + +l1EGTable = cms.EDProducer("SimpleTriggerL1EGFlatTableProducer", + src = cms.InputTag("caloStage2Digis","EGamma"), + minBX = cms.int32(-2), + maxBX = cms.int32(2), + cut = cms.string(""), + name= cms.string("L1EG"), + doc = cms.string(""), + extension = cms.bool(False), + variables = cms.PSet(l1CaloObjVars, + rawEt = Var("rawEt()","int16",doc="raw et"), + isoEt = Var("isoEt()","int16",doc="iso et"), + footprintEt = Var("footprintEt()","int16",doc=" footprint et"), + nTT = Var("nTT()","int16",doc="nr trig towers"), + shape = Var("shape()","int16",doc="shape"), + towerHoE = Var("towerHoE()","int16",doc="tower H/E"), + ) +) + +l1TablesTask = cms.Task(l1EGTable,l1EtSumTable,l1TauTable,l1JetTable,l1MuTable) + +def setL1NanoToReduced(process): + """ + sets the L1 objects only have reduced information which is necessary + for central nano + """ + #reduce the variables to the core variables + #note et sum variables are already reduced + process.l1EGTable.variables = cms.PSet(l1EGReducedVars) + process.l1MuTable.variables = cms.PSet(l1MuonReducedVars) + process.l1JetTable.variables = cms.PSet(l1JetReducedVars) + process.l1TauTable.variables = cms.PSet(l1TauReducedVars) + process.l1EtSumTable.variables = cms.PSet(l1EtSumReducedVars) + + #apply cuts + process.l1EGTable.cut="pt>=10" + process.l1TauTable.cut="pt>=24" + process.l1JetTable.cut="pt>=30" + process.l1MuTable.cut="pt>=3 && hwQual>=8" + process.l1EtSumTable.cut="(getType==8 || getType==1 || getType==2 || getType==3)" + + return process diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py index 4e9965a19b938..8eff7f79ed17f 100644 --- a/PhysicsTools/NanoAOD/python/nano_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -27,6 +27,7 @@ from PhysicsTools.NanoAOD.NanoAODEDMEventContent_cff import * from PhysicsTools.NanoAOD.fsrPhotons_cff import * from PhysicsTools.NanoAOD.softActivity_cff import * +from PhysicsTools.NanoAOD.l1trig_cff import * nanoMetadata = cms.EDProducer("UniqueStringProducer", strings = cms.PSet( @@ -210,3 +211,12 @@ def nanoWmassGenCustomize(process): etaPrecision="{} ? {} : {}".format(pdgSelection, CandVars.eta.precision.value(), genParticleTable.variables.eta.precision.value()) process.genParticleTable.variables.eta.precision=cms.string(etaPrecision) return process + +def nanoL1TrigObjCustomize(process): + process.nanoTableTaskCommon.add(process.l1TablesTask) + process = setL1NanoToReduced(process) + return process + +def nanoL1TrigObjCustomizeFull(process): + process.nanoTableTaskCommon.add(process.l1TablesTask) + return process