Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedding update for run3 #47299

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
23 changes: 19 additions & 4 deletions TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import FWCore.ParameterSet.Config as cms
from Configuration.Eras.Modifier_run2_HLTconditions_2016_cff import (
run2_HLTconditions_2016,
)
from Configuration.Eras.Modifier_run2_HLTconditions_2017_cff import (
run2_HLTconditions_2017,
)
from Configuration.Eras.Modifier_run2_HLTconditions_2018_cff import (
run2_HLTconditions_2018,
)
from Configuration.StandardSequences.PAT_cff import *

from PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi import patMuons
from HLTrigger.HLTfilters.triggerResultsFilter_cfi import *
from Configuration.Eras.Modifier_run2_HLTconditions_2016_cff import run2_HLTconditions_2016
from PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi import patMuons

## Trigger requirements
doubleMuonHLTTrigger = cms.EDFilter("TriggerResultsFilter",
hltResults = cms.InputTag("TriggerResults","","HLT"),
l1tResults = cms.InputTag(""),
throw = cms.bool(False),
triggerConditions = cms.vstring("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_v* OR HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_Mass8_v*") # from 2017 on (up to Run 3, it seems)
triggerConditions = cms.vstring("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_Mass3p8_v*") # unprescaled trigger for 2018,22,23,24 (see https://twiki.cern.ch/twiki/bin/view/CMS/MuonHLT2018, https://twiki.cern.ch/twiki/bin/view/CMS/MuonHLT2022, https://twiki.cern.ch/twiki/bin/view/CMS/MuonHLT2023, https://twiki.cern.ch/twiki/bin/view/CMS/MuonHLT2024)
)

#### change the used triggers for run2 ####
# Use two different triggers as the Mass8 one has a higer luminosity in 2017 according to https://cmshltinfo.app.cern.ch/summary?search=HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_Mass&year=2017&paths=true&prescaled=true&stream-types=Physics
# probably because he was already active in earlier runs than the Mass3p8 trigger
# Both are unprescaled
run2_HLTconditions_2017.toModify(doubleMuonHLTTrigger,
triggerConditions = ["HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_v* OR HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_Mass8_v*"])

# Both are unprescaled according to https://cmshltinfo.app.cern.ch/summary?search=HLT_Mu17_TrkIsoVVL_&year=2016&paths=true&prescaled=true&stream-types=Physics
run2_HLTconditions_2016.toModify(doubleMuonHLTTrigger,
triggerConditions = ["HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_v* OR HLT_Mu17_TrkIsoVVL_TkMu8_TrkIsoVVL_DZ_v*"])

Expand Down
137 changes: 62 additions & 75 deletions TauAnalysis/MCEmbeddingTools/python/customisers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

# Various set of customise functions needed for embedding
import FWCore.ParameterSet.Config as cms

from Configuration.Eras.Modifier_run2_common_cff import run2_common
from Configuration.Eras.Modifier_run3_common_cff import run3_common
from PhysicsTools.NanoAOD.common_cff import ExtVar

################################ Customizer for skimming ###########################
Expand Down Expand Up @@ -61,6 +62,7 @@ def __init__(
module_name="generalTracks", manipulator_name="Track", steps=["SIM", "MERGE"]
)
)
# needed by the PFLinker:particleFlow to create MuonProducer:muons
to_bemanipulate.append(
module_manipulate(
module_name="cosmicsVetoTracksRaw", manipulator_name="Track", steps=["SIM", "MERGE"]
Expand All @@ -80,27 +82,15 @@ def __init__(
steps=["SIM", "MERGE"],
)
)
to_bemanipulate.append(
module_manipulate(
module_name="conversionStepTracks",
manipulator_name="Track",
steps=["SIM", "MERGE"],
)
)
# This is needed by displacedMuonReducedTrackExtras which is specifically added in the merging_step
to_bemanipulate.append(
module_manipulate(
module_name="displacedTracks",
manipulator_name="Track",
steps=["SIM", "MERGE"],
)
)
to_bemanipulate.append(
module_manipulate(
module_name="ckfInOutTracksFromConversions",
manipulator_name="Track",
steps=["SIM", "MERGE"],
)
)
# This is needed by the conversion producer which is run by the highlevelreco task
to_bemanipulate.append(
module_manipulate(
module_name="ckfOutInTracksFromConversions",
Expand All @@ -114,6 +104,7 @@ def __init__(
module_name="muons1stStep", manipulator_name="Muon", steps=["SIM", "MERGE"]
)
)
# needed by MuIsoDepositCopyProducer/'muIsoDepositTkDisplaced'
to_bemanipulate.append(
module_manipulate(
module_name="displacedMuons1stStep", manipulator_name="Muon", steps=["SIM", "MERGE"]
Expand All @@ -133,6 +124,7 @@ def __init__(
steps=["SIM", "MERGE"],
)
)
# needed by the PFLinker:particleFlow to create MuonProducer:muons
to_bemanipulate.append(
module_manipulate(
module_name="particleFlowTmp",
Expand All @@ -155,25 +147,12 @@ def __init__(
module_name="ecalDigis", manipulator_name="EcalSrFlag", steps=["SIM", "MERGE"]
)
)
# this is needed by the HcalNoiseInfoProducer/'hcalnoise'
to_bemanipulate.append(
module_manipulate(
module_name="hcalDigis", manipulator_name="HcalDigi", steps=["SIM", "MERGE"]
)
)
to_bemanipulate.append(
module_manipulate(
module_name="electronMergedSeeds",
manipulator_name="ElectronSeed",
steps=["SIM", "MERGE"],
)
)
to_bemanipulate.append(
module_manipulate(
module_name="ecalDrivenElectronSeeds",
manipulator_name="EcalDrivenElectronSeed",
steps=["SIM", "MERGE"],
)
)

to_bemanipulate.append(
module_manipulate(
Expand All @@ -190,15 +169,9 @@ def __init__(
)
)

to_bemanipulate.append(
module_manipulate(module_name="hbheprereco", manipulator_name="HBHERecHit")
winterchristian marked this conversation as resolved.
Show resolved Hide resolved
)
to_bemanipulate.append(
module_manipulate(module_name="hbhereco", manipulator_name="HBHERecHit")
)
to_bemanipulate.append(
module_manipulate(module_name="zdcreco", manipulator_name="ZDCRecHit")
)

to_bemanipulate.append(
module_manipulate(module_name="horeco", manipulator_name="HORecHit")
Expand Down Expand Up @@ -263,6 +236,41 @@ def __init__(
)
)

# add some collections for run2
# The era Modifier/ModifierChain is specified with the cmsDriver `--era` option or the cms.Process('NAME', era=...) constructor in the python config.
# The `Modifier.toModify` method is executed if the Modifier is in the ModifierChain. (see https://github.com/cms-sw/cmssw/blob/master/FWCore/ParameterSet/python/Config.py#L1831)
# The Run3 ModifierChain is based on the Run2 ModifierChain. Therefore the `run2_common` Modifier is included in both ModifierChains.
# Those Modifiers allow bool operators to combine them. With `(run2_common & ~run3_common)` the `toModify` function is only executed if the era ModifierChain contains `run2_common` but not `run3_common`.
(run2_common & ~run3_common).toModify(
to_bemanipulate,
lambda l: l.extend(
[
module_manipulate(
module_name="conversionStepTracks",
manipulator_name="Track",
steps=["SIM", "MERGE"],
),
module_manipulate(
module_name="ckfInOutTracksFromConversions",
manipulator_name="Track",
steps=["SIM", "MERGE"],
),
module_manipulate(
module_name="electronMergedSeeds",
manipulator_name="ElectronSeed",
steps=["SIM", "MERGE"],
),
module_manipulate(
module_name="ecalDrivenElectronSeeds",
manipulator_name="EcalDrivenElectronSeed",
steps=["SIM", "MERGE"],
),
module_manipulate(module_name="hbheprereco", manipulator_name="HBHERecHit"),
module_manipulate(module_name="zdcreco", manipulator_name="ZDCRecHit"),
]
),
)


def modify_outputModules(process, keep_drop_list=[], module_veto_list=[]):
outputModulesList = [key for key, value in process.outputModules.items()]
Expand Down Expand Up @@ -353,7 +361,7 @@ def keepCleaned(dataTier):
"keep *_l1extraParticles_*_" + dataTier,
"keep TrajectorySeeds_*_*_*",
"keep recoElectronSeeds_*_*_*",
"drop recoIsoDepositedmValueMap_muIsoDepositTk_*_*" ,
"drop recoIsoDepositedmValueMap_muIsoDepositTk_*_*",
"drop recoIsoDepositedmValueMap_muIsoDepositTkDisplaced_*_*",
"drop *_ctppsProtons_*_*",
"drop *_ctppsLocalTrackLiteProducer_*_*",
Expand Down Expand Up @@ -582,9 +590,9 @@ def customiseGenerator_preHLT(process, changeProcessname=True, reselect=False):
"Correcting Vertex in genEvent to one from input. Replaced 'VtxSmeared' with the Corrector."
)

# Disable noise simulation
process.mix.digitizers.castor.doNoise = cms.bool(False)

#### Disable noise simulation ####
# Castor was a detector in CMS till 2018.
(run2_common & ~run3_common).toModify(process, lambda p: setattr(p.mix.digitizers.castor, "doNoise", cms.bool(False)))
process.mix.digitizers.ecal.doESNoise = cms.bool(False)
process.mix.digitizers.ecal.doENoise = cms.bool(False)

Expand Down Expand Up @@ -639,6 +647,18 @@ def customiseGenerator_HLT(process, changeProcessname=True, reselect=False):
process.embeddingHltPixelVertices.clone()
)

# Replace the original detector state filters in the HLT with a dummy module with 100% efficiency.
# Those original filters have a efficiency of 0% for embedding samples.
# This is due to the fact that the simulation of the tau decay happens in an empty detector.
# For more info see https://github.com/cms-sw/cmssw/pull/47299#discussion_r1949023230
process.hltPixelTrackerHVOn = cms.EDFilter("HLTBool",
result = cms.bool(True)
)

process.hltStripTrackerHVOn = cms.EDFilter("HLTBool",
result = cms.bool(True)
)

process = customisoptions(process)
##process = fix_input_tags(process)

Expand Down Expand Up @@ -801,12 +821,10 @@ def customiseMerging(process, changeProcessname=True, reselect=False):

print("**** Attention: overriding behaviour of 'removeMCMatching' ****")

import PhysicsTools.PatAlgos.tools.coreTools
from PhysicsTools.PatAlgos.slimming.miniAOD_tools import miniAOD_customizeMC
def performMCMatching(process, names, postfix, outputModules):
miniAOD_customizeMC(process)

import PhysicsTools.PatAlgos.tools.coreTools
PhysicsTools.PatAlgos.tools.coreTools.removeMCMatching = performMCMatching
PhysicsTools.PatAlgos.tools.coreTools.removeMCMatching = lambda process, names, postfix, outputModules : miniAOD_customizeMC(process)

if changeProcessname:
process._Process__name = "MERGE"
Expand Down Expand Up @@ -893,42 +911,10 @@ def performMCMatching(process, names, postfix, outputModules):
)
process.dedxHitInfo.clusterShapeCache = cms.InputTag("")

# process.muons.FillDetectorBasedIsolation = cms.bool(False)
# process.muons.FillSelectorMaps = cms.bool(False)
# process.muons.FillShoweringInfo = cms.bool(False)
# process.muons.FillCosmicsIdMap = cms.bool(False)

# process.displacedMuons.FillDetectorBasedIsolation = cms.bool(False)
# process.displacedMuons.FillSelectorMaps = cms.bool(False)
# process.displacedMuons.FillShoweringInfo = cms.bool(False)
# process.displacedMuons.FillCosmicsIdMap = cms.bool(False)

# seed configuration needed for seedmerger
#process.load(
# "RecoEgamma.EgammaElectronProducers.ecalDrivenElectronSeedsParameters_cff"
#)
#process.ecalDrivenElectronSeeds.SeedConfiguration = cms.PSet(
# process.ecalDrivenElectronSeedsParameters
#)

process.merge_step += process.highlevelreco
# process.merge_step.remove(process.reducedEcalRecHitsEE)
# process.merge_step.remove(process.reducedEcalRecHitsEB)

# process.merge_step.remove(process.ak4JetTracksAssociatorExplicit)

# process.merge_step.remove(process.cosmicsVeto)
# process.merge_step.remove(process.cosmicsVetoTrackCandidates)
# process.merge_step.remove(process.ecalDrivenGsfElectronCores)
# process.merge_step.remove(process.ecalDrivenGsfElectrons)
# process.merge_step.remove(process.gedPhotonsTmp)
# process.merge_step.remove(process.particleFlowTmp)

# process.merge_step.remove(process.hcalnoise)

process.load("CommonTools.ParticleFlow.genForPF2PAT_cff")

# process.muonsFromCosmics.ShowerDigiFillerParameters.dtDigiCollectionLabel = cms.InputTag("simMuonDTDigis")

process.merge_step += process.genForPF2PATSequence

Expand Down Expand Up @@ -970,6 +956,7 @@ def performMCMatching(process, names, postfix, outputModules):
if name in reconstruction_modules_list:
modules_to_be_ordered[name] = reconstruction_modules_list.index(name)
else:
import sys
print("ERROR:",name,"not prepared in modules list. Please adapt 'customiseMerging'")
sys.exit(1)

Expand Down
1 change: 1 addition & 0 deletions TauAnalysis/MCEmbeddingTools/test/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<test name="testTauEmbeddingWorkflow2016preVFP" command="run_2016postVFPUL_workflow_tests.sh"/>
<test name="testTauEmbeddingWorkflow2017" command="run_2017UL_workflow_tests.sh"/>
<test name="testTauEmbeddingWorkflow2018" command="run_2018UL_workflow_tests.sh"/>
<test name="testTauEmbeddingWorkflow2022postEE" command="run_2022_workflow_tests.sh"/>

Loading