diff --git a/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py b/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py index d142fd56a9f81..14468297b14e3 100644 --- a/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py +++ b/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py @@ -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*"]) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 47f5d5d23fe05..5785077f2b955 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -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 ########################### @@ -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"] @@ -80,13 +82,7 @@ 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", @@ -94,13 +90,7 @@ def __init__( 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", @@ -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"] @@ -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", @@ -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( @@ -190,15 +169,9 @@ def __init__( ) ) -to_bemanipulate.append( - module_manipulate(module_name="hbheprereco", manipulator_name="HBHERecHit") -) 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") @@ -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()] @@ -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_*_*", @@ -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) @@ -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) @@ -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" @@ -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 @@ -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) diff --git a/TauAnalysis/MCEmbeddingTools/test/BuildFile.xml b/TauAnalysis/MCEmbeddingTools/test/BuildFile.xml index 1fc12a955bbc7..735e65bc6cf7a 100644 --- a/TauAnalysis/MCEmbeddingTools/test/BuildFile.xml +++ b/TauAnalysis/MCEmbeddingTools/test/BuildFile.xml @@ -2,4 +2,5 @@ + diff --git a/TauAnalysis/MCEmbeddingTools/test/run_2022_workflow_tests.sh b/TauAnalysis/MCEmbeddingTools/test/run_2022_workflow_tests.sh new file mode 100755 index 0000000000000..dc0e44454bbcc --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/test/run_2022_workflow_tests.sh @@ -0,0 +1,132 @@ +#!/bin/bash +# This script runs all the steps of the embedding workflow +# author: Christian Winter (christian.winter@cern.ch) +# TODO: move the dataset to a more persistent and for cmssw accessible place than a private EOS user folder + +# print the exit status before exiting +function die { + echo $1: status $2 + exit $2 +} + +## This is a PRE SKIMED dataset +dataset="root://eoscms.cern.ch//store/group/phys_tau/embedding_test_files/2022_G_RAW.root" + +echo "################ Selection ################" +cmsDriver.py RECO \ + --step RAW2DIGI,L1Reco,RECO,PAT \ + --data \ + --scenario pp \ + --conditions auto:run3_data \ + --era Run3 \ + --eventcontent RAWRECO \ + --datatier RAWRECO \ + --customise TauAnalysis/MCEmbeddingTools/customisers.customiseSelecting \ + --filein $dataset \ + --fileout file:selection.root \ + -n -1 \ + --python_filename selection.py || die 'Failure during selecting step' $? + +echo "################ LHE production and cleaning ################" +cmsDriver.py LHEprodandCLEAN \ + --step RAW2DIGI,RECO,PAT \ + --data \ + --scenario pp \ + --conditions auto:run3_data \ + --era Run3 \ + --eventcontent RAWRECO \ + --datatier RAWRECO \ + --customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2018,TauAnalysis/MCEmbeddingTools/customisers.customiseLHEandCleaning \ + --filein file:selection.root \ + --fileout file:lhe_and_cleaned.root \ + -n -1 \ + --python_filename lheprodandcleaning.py || die 'Failure during LHE and Cleaning step' $? + +# Simulation (MC & Detector) +echo "################ Simulation (MC & Detector) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step GEN,SIM,DIGI,L1,DIGI2RAW \ + --mc \ + --beamspot Realistic25ns13p6TeVEarly2022Collision \ + --geometry DB:Extended \ + --era Run3 \ + --conditions auto:phase1_2022_realistic_postEE \ + --eventcontent RAWSIM \ + --datatier RAWSIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_preHLT \ + --customise_commands 'process.generator.HepMCFilter.filterParameters.MuMuCut = cms.string("(Mu.Pt > 18 && Had.Pt > 18 && Mu.Eta < 2.2 && Had.Eta < 2.4)");process.generator.HepMCFilter.filterParameters.Final_States = cms.vstring("MuHad");process.generator.nAttempts = cms.uint32(1000);' \ + --filein file:lhe_and_cleaned.root \ + --fileout file:simulated_and_cleaned_prehlt.root \ + -n -1 \ + --python_filename generator_preHLT.py || die 'Failure during MC & Detector simulation step' $? + +# Simulation (Trigger) +echo "################ Simulation (Trigger) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step HLT:Fake2 \ + --mc \ + --beamspot Realistic25ns13p6TeVEarly2022Collision \ + --geometry DB:Extended \ + --era Run3 \ + --conditions auto:phase1_2022_realistic_postEE \ + --eventcontent RAWSIM \ + --datatier RAWSIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_HLT \ + --customise_commands 'process.source.bypassVersionCheck = cms.untracked.bool(True);' \ + --filein file:simulated_and_cleaned_prehlt.root \ + --fileout file:simulated_and_cleaned_hlt.root \ + -n -1 \ + --python_filename generator_HLT.py || die 'Failure during Fake Trigger simulation step' $? + +# Simulation (Reconstruction) +echo "################ Simulation (Reconstruction) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step RAW2DIGI,L1Reco,RECO,RECOSIM \ + --mc \ + --beamspot Realistic25ns13p6TeVEarly2022Collision \ + --geometry DB:Extended \ + --era Run3 \ + --conditions auto:phase1_2022_realistic_postEE \ + --eventcontent RAWRECOSIMHLT \ + --datatier RAW-RECO-SIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_postHLT \ + --customise_commands 'process.source.bypassVersionCheck = cms.untracked.bool(True);' \ + --filein file:simulated_and_cleaned_hlt.root \ + --fileout file:simulated_and_cleaned_posthlt.root \ + -n -1 \ + --python_filename generator_postHLT.py || die 'Failure during reconstruction simulation step' $? + +# Merging +echo "################ Merging ################" +cmsDriver.py PAT \ + --step PAT \ + --data \ + --scenario pp \ + --conditions auto:run3_data \ + --era Run3 \ + --eventcontent MINIAODSIM \ + --datatier USER \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseMerging \ + --filein file:simulated_and_cleaned_posthlt.root \ + --fileout file:merged.root \ + -n -1 \ + --python_filename merging.py || die 'Failure during the merging step' $? + +# NanoAOD Production +echo "################ NanoAOD Production ################" +cmsDriver.py \ + --step NANO \ + --data \ + --conditions auto:run3_data \ + --era Run3 \ + --eventcontent NANOAODSIM \ + --datatier NANOAODSIM \ + --customise TauAnalysis/MCEmbeddingTools/customisers.customiseNanoAOD \ + --filein file:merged.root \ + --fileout file:merged_nano.root \ + -n -1 \ + --python_filename embedding_nanoAOD.py || die 'Failure during the nanoAOD step' $?