File indexing completed on 2024-06-27 02:06:26
0001
0002
0003
0004
0005 import FWCore.ParameterSet.Config as cms
0006
0007 from PhysicsTools.NanoAOD.common_cff import ExtVar
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 class module_manipulate:
0024 def __init__(
0025 self,
0026 module_name,
0027 manipulator_name,
0028 steps=["SELECT", "CLEAN", "SIM", "MERGE"],
0029 instance=[""],
0030 merge_prefix="",
0031 ):
0032 self.module_name = module_name
0033 self.manipulator_name = manipulator_name
0034 self.steps = steps
0035 self.instance = instance
0036 self.merger_name = manipulator_name + "ColMerger"
0037 self.cleaner_name = manipulator_name + "ColCleaner"
0038 self.merge_prefix = merge_prefix
0039
0040
0041 to_bemanipulate = []
0042
0043
0044 to_bemanipulate.append(
0045 module_manipulate(
0046 module_name="siPixelClusters",
0047 manipulator_name="Pixel",
0048 steps=["SELECT", "CLEAN"],
0049 )
0050 )
0051 to_bemanipulate.append(
0052 module_manipulate(
0053 module_name="siStripClusters",
0054 manipulator_name="Strip",
0055 steps=["SELECT", "CLEAN"],
0056 )
0057 )
0058
0059 to_bemanipulate.append(
0060 module_manipulate(
0061 module_name="generalTracks", manipulator_name="Track", steps=["SIM", "MERGE"]
0062 )
0063 )
0064 to_bemanipulate.append(
0065 module_manipulate(
0066 module_name="cosmicsVetoTracksRaw", manipulator_name="Track", steps=["SIM", "MERGE"]
0067 )
0068 )
0069 to_bemanipulate.append(
0070 module_manipulate(
0071 module_name="electronGsfTracks",
0072 manipulator_name="GsfTrack",
0073 steps=["SIM", "MERGE"],
0074 )
0075 )
0076 to_bemanipulate.append(
0077 module_manipulate(
0078 module_name="lowPtGsfEleGsfTracks",
0079 manipulator_name="GsfTrack",
0080 steps=["SIM", "MERGE"],
0081 )
0082 )
0083 to_bemanipulate.append(
0084 module_manipulate(
0085 module_name="conversionStepTracks",
0086 manipulator_name="Track",
0087 steps=["SIM", "MERGE"],
0088 )
0089 )
0090 to_bemanipulate.append(
0091 module_manipulate(
0092 module_name="displacedTracks",
0093 manipulator_name="Track",
0094 steps=["SIM", "MERGE"],
0095 )
0096 )
0097 to_bemanipulate.append(
0098 module_manipulate(
0099 module_name="ckfInOutTracksFromConversions",
0100 manipulator_name="Track",
0101 steps=["SIM", "MERGE"],
0102 )
0103 )
0104 to_bemanipulate.append(
0105 module_manipulate(
0106 module_name="ckfOutInTracksFromConversions",
0107 manipulator_name="Track",
0108 steps=["SIM", "MERGE"],
0109 )
0110 )
0111
0112 to_bemanipulate.append(
0113 module_manipulate(
0114 module_name="muons1stStep", manipulator_name="Muon", steps=["SIM", "MERGE"]
0115 )
0116 )
0117 to_bemanipulate.append(
0118 module_manipulate(
0119 module_name="displacedMuons1stStep", manipulator_name="Muon", steps=["SIM", "MERGE"]
0120 )
0121 )
0122
0123
0124 to_bemanipulate.append(
0125 module_manipulate(
0126 module_name="conversions", manipulator_name="Conversion", steps=["SIM", "MERGE"]
0127 )
0128 )
0129 to_bemanipulate.append(
0130 module_manipulate(
0131 module_name="allConversions",
0132 manipulator_name="Conversion",
0133 steps=["SIM", "MERGE"],
0134 )
0135 )
0136 to_bemanipulate.append(
0137 module_manipulate(
0138 module_name="particleFlowTmp",
0139 manipulator_name="PF",
0140 steps=["SIM", "MERGE"],
0141 instance=[
0142 "",
0143 "CleanedHF",
0144 "CleanedCosmicsMuons",
0145 "CleanedTrackerAndGlobalMuons",
0146 "CleanedFakeMuons",
0147 "CleanedPunchThroughMuons",
0148 "CleanedPunchThroughNeutralHadrons",
0149 "AddedMuonsAndHadrons",
0150 ],
0151 )
0152 )
0153 to_bemanipulate.append(
0154 module_manipulate(
0155 module_name="ecalDigis", manipulator_name="EcalSrFlag", steps=["SIM", "MERGE"]
0156 )
0157 )
0158 to_bemanipulate.append(
0159 module_manipulate(
0160 module_name="hcalDigis", manipulator_name="HcalDigi", steps=["SIM", "MERGE"]
0161 )
0162 )
0163 to_bemanipulate.append(
0164 module_manipulate(
0165 module_name="electronMergedSeeds",
0166 manipulator_name="ElectronSeed",
0167 steps=["SIM", "MERGE"],
0168 )
0169 )
0170 to_bemanipulate.append(
0171 module_manipulate(
0172 module_name="ecalDrivenElectronSeeds",
0173 manipulator_name="EcalDrivenElectronSeed",
0174 steps=["SIM", "MERGE"],
0175 )
0176 )
0177
0178 to_bemanipulate.append(
0179 module_manipulate(
0180 module_name="ecalRecHit",
0181 manipulator_name="EcalRecHit",
0182 instance=["EcalRecHitsEB", "EcalRecHitsEE"],
0183 )
0184 )
0185 to_bemanipulate.append(
0186 module_manipulate(
0187 module_name="ecalPreshowerRecHit",
0188 manipulator_name="EcalRecHit",
0189 instance=["EcalRecHitsES"],
0190 )
0191 )
0192
0193 to_bemanipulate.append(
0194 module_manipulate(module_name="hbheprereco", manipulator_name="HBHERecHit")
0195 )
0196 to_bemanipulate.append(
0197 module_manipulate(module_name="hbhereco", manipulator_name="HBHERecHit")
0198 )
0199 to_bemanipulate.append(
0200 module_manipulate(module_name="zdcreco", manipulator_name="ZDCRecHit")
0201 )
0202
0203 to_bemanipulate.append(
0204 module_manipulate(module_name="horeco", manipulator_name="HORecHit")
0205 )
0206 to_bemanipulate.append(
0207 module_manipulate(module_name="hfreco", manipulator_name="HFRecHit")
0208 )
0209
0210
0211 to_bemanipulate.append(
0212 module_manipulate(
0213 module_name="dt1DRecHits",
0214 manipulator_name="DTRecHit",
0215 steps=["SELECT", "CLEAN"],
0216 )
0217 )
0218 to_bemanipulate.append(
0219 module_manipulate(
0220 module_name="dt1DCosmicRecHits",
0221 manipulator_name="DTRecHit",
0222 steps=["SELECT", "CLEAN"],
0223 )
0224 )
0225
0226 to_bemanipulate.append(
0227 module_manipulate(
0228 module_name="dt4DSegments",
0229 manipulator_name="DTRecSegment4D",
0230 steps=["SELECT", "CLEAN"],
0231 )
0232 )
0233
0234 to_bemanipulate.append(
0235 module_manipulate(
0236 module_name="dt4DCosmicSegments",
0237 manipulator_name="DTRecSegment4D",
0238 steps=["SELECT", "CLEAN"],
0239 )
0240 )
0241
0242 to_bemanipulate.append(
0243 module_manipulate(
0244 module_name="csc2DRecHits",
0245 manipulator_name="CSCRecHit",
0246 steps=["SELECT", "CLEAN"],
0247 )
0248 )
0249
0250 to_bemanipulate.append(
0251 module_manipulate(
0252 module_name="cscSegments",
0253 manipulator_name="CSCSegment",
0254 steps=["SELECT", "CLEAN"],
0255 )
0256 )
0257
0258 to_bemanipulate.append(
0259 module_manipulate(
0260 module_name="rpcRecHits",
0261 manipulator_name="RPCRecHit",
0262 steps=["SELECT", "CLEAN"],
0263 )
0264 )
0265
0266
0267 def modify_outputModules(process, keep_drop_list=[], module_veto_list=[]):
0268 outputModulesList = [key for key, value in process.outputModules.items()]
0269 for outputModule in outputModulesList:
0270 if outputModule in module_veto_list:
0271 continue
0272 outputModule = getattr(process, outputModule)
0273 for add_element in keep_drop_list:
0274 outputModule.outputCommands.extend(add_element)
0275 return process
0276
0277
0278
0279
0280
0281 def keepSelected(dataTier):
0282 ret_vstring = cms.untracked.vstring(
0283
0284 "keep *_patMuonsAfterID_*_" + dataTier,
0285 "keep *_slimmedMuons_*_" + dataTier,
0286 "keep *_slimmedMuonTrackExtras_*_" + dataTier,
0287 "keep *_selectedMuonsForEmbedding_*_" + dataTier,
0288 "keep recoVertexs_offlineSlimmedPrimaryVertices_*_" + dataTier,
0289 "keep *_firstStepPrimaryVertices_*_" + dataTier,
0290 "keep *_offlineBeamSpot_*_" + dataTier,
0291 "keep *_ecalDrivenElectronSeeds_*_" + dataTier,
0292 )
0293 for akt_manimod in to_bemanipulate:
0294 if "CLEAN" in akt_manimod.steps:
0295 ret_vstring.append("keep *_" + akt_manimod.module_name + "_*_" + dataTier)
0296 return ret_vstring
0297
0298
0299 def customiseSelecting(process, reselect=False):
0300 if reselect:
0301 process._Process__name = "RESELECT"
0302 dataTier = "RESELECT"
0303
0304
0305
0306
0307 else:
0308 process._Process__name = "SELECT"
0309 dataTier = "SELECT"
0310
0311 process.load("TauAnalysis.MCEmbeddingTools.SelectingProcedure_cff")
0312 process.patMuonsAfterKinCuts.src = cms.InputTag("slimmedMuons", "", dataTier)
0313 process.selectedMuonsForEmbedding.PuppiMet = cms.InputTag(
0314 "slimmedMETsPuppi", "", dataTier
0315 )
0316 process.selectedMuonsForEmbedding.Met = cms.InputTag("slimmedMETs", "", dataTier)
0317 process.patMuonsAfterID = process.patMuonsAfterLooseID.clone()
0318
0319 process.selecting = cms.Path(process.makePatMuonsZmumuSelection)
0320 process.schedule.insert(-1, process.selecting)
0321
0322 outputModulesList = [key for key, value in process.outputModules.items()]
0323 for outputModule in outputModulesList:
0324 outputModule = getattr(process, outputModule)
0325 outputModule.SelectEvents = cms.untracked.PSet(
0326 SelectEvents=cms.vstring("selecting")
0327 )
0328 outputModule.outputCommands.extend(keepSelected(dataTier))
0329
0330 process = customisoptions(process)
0331 return modify_outputModules(process, [keepSelected(dataTier)])
0332
0333
0334 def customiseSelecting_Reselect(process):
0335 return customiseSelecting(process, reselect=True)
0336
0337
0338
0339
0340
0341 def keepCleaned(dataTier):
0342 ret_vstring = cms.untracked.vstring(
0343
0344
0345 "drop *_*_*_" + dataTier,
0346 "keep *_patMuonsAfterID_*_" + dataTier,
0347 "keep *_slimmedMuons_*_" + dataTier,
0348
0349 "keep *_selectedMuonsForEmbedding_*_" + dataTier,
0350 "keep recoVertexs_offlineSlimmedPrimaryVertices_*_" + dataTier,
0351 "keep *_firstStepPrimaryVertices_*_" + dataTier,
0352 "keep *_offlineBeamSpot_*_" + dataTier,
0353 "keep *_l1extraParticles_*_" + dataTier,
0354 "keep TrajectorySeeds_*_*_*",
0355 "keep recoElectronSeeds_*_*_*",
0356 "drop recoIsoDepositedmValueMap_muIsoDepositTk_*_*" ,
0357 "drop recoIsoDepositedmValueMap_muIsoDepositTkDisplaced_*_*",
0358 "drop *_ctppsProtons_*_*",
0359 "drop *_ctppsLocalTrackLiteProducer_*_*",
0360 "drop *_ctppsDiamondLocalTracks_*_*",
0361 "drop *_ctppsDiamondRecHits_*_*",
0362 "drop *_ctppsDiamondRawToDigi_*_*",
0363 "drop *_ctppsPixelLocalTracks_*_*",
0364 "drop *_ctppsPixelRecHits_*_*",
0365 "drop *_ctppsPixelClusters_*_*",
0366 "drop *_ctppsPixelDigis_*_*",
0367 "drop *_totemRPLocalTrackFitter_*_*",
0368 "drop *_totemRPUVPatternFinder_*_*",
0369 "drop *_totemRPRecHitProducer_*_*",
0370 "drop *_totemRPClusterProducer_*_*",
0371 "drop *_totemRPRawToDigi_*_*",
0372 "drop *_muonSimClassifier_*_*",
0373
0374
0375 )
0376
0377 for akt_manimod in to_bemanipulate:
0378 if "MERGE" in akt_manimod.steps:
0379 ret_vstring.append(
0380 "keep *_" + akt_manimod.module_name + "_*_LHEembeddingCLEAN"
0381 )
0382 ret_vstring.append("keep *_" + akt_manimod.module_name + "_*_CLEAN")
0383 ret_vstring.append("keep *_standAloneMuons_*_LHEembeddingCLEAN")
0384 ret_vstring.append("keep *_glbTrackQual_*_LHEembeddingCLEAN")
0385 return ret_vstring
0386
0387
0388 def customiseCleaning(process, changeProcessname=True, reselect=False):
0389 if changeProcessname:
0390 process._Process__name = "CLEAN"
0391 if reselect:
0392 dataTier = "RESELECT"
0393 else:
0394 dataTier = "SELECT"
0395
0396 from TrackingTools.TrackAssociator.default_cfi import TrackAssociatorParameterBlock
0397
0398 TrackAssociatorParameterBlock.TrackAssociatorParameters.CSCSegmentCollectionLabel = cms.InputTag(
0399 "cscSegments", "", dataTier
0400 )
0401 TrackAssociatorParameterBlock.TrackAssociatorParameters.CaloTowerCollectionLabel = (
0402 cms.InputTag("towerMaker", "", dataTier)
0403 )
0404 TrackAssociatorParameterBlock.TrackAssociatorParameters.DTRecSegment4DCollectionLabel = cms.InputTag(
0405 "dt4DSegments", "", dataTier
0406 )
0407 TrackAssociatorParameterBlock.TrackAssociatorParameters.EBRecHitCollectionLabel = (
0408 cms.InputTag("ecalRecHit", "EcalRecHitsEB", dataTier)
0409 )
0410 TrackAssociatorParameterBlock.TrackAssociatorParameters.EERecHitCollectionLabel = (
0411 cms.InputTag("ecalRecHit", "EcalRecHitsEE", dataTier)
0412 )
0413 TrackAssociatorParameterBlock.TrackAssociatorParameters.HBHERecHitCollectionLabel = cms.InputTag(
0414 "hbhereco", "", dataTier
0415 )
0416 TrackAssociatorParameterBlock.TrackAssociatorParameters.HORecHitCollectionLabel = (
0417 cms.InputTag("horeco", "", dataTier)
0418 )
0419 TrackAssociatorParameterBlock.TrackAssociatorParameters.ME0HitCollectionLabel = (
0420 cms.InputTag("me0RecHits", "", dataTier)
0421 )
0422 TrackAssociatorParameterBlock.TrackAssociatorParameters.ME0SegmentCollectionLabel = (
0423 cms.InputTag("me0Segments", "", dataTier)
0424 )
0425 TrackAssociatorParameterBlock.TrackAssociatorParameters.RPCHitCollectionLabel = (
0426 cms.InputTag("rpcRecHits", "", dataTier)
0427 )
0428
0429 MuonImput = cms.InputTag("selectedMuonsForEmbedding", "", "")
0430 for akt_manimod in to_bemanipulate:
0431 if "CLEAN" in akt_manimod.steps:
0432 oldCollections_in = cms.VInputTag()
0433 for instance in akt_manimod.instance:
0434 oldCollections_in.append(
0435 cms.InputTag(akt_manimod.module_name, instance, dataTier)
0436 )
0437 setattr(
0438 process,
0439 akt_manimod.module_name,
0440 cms.EDProducer(
0441 akt_manimod.cleaner_name,
0442 MuonCollection=MuonImput,
0443 TrackAssociatorParameters=TrackAssociatorParameterBlock.TrackAssociatorParameters,
0444 oldCollection=oldCollections_in,
0445 cscDigiCollectionLabel = cms.InputTag("muonCSCDigis","MuonCSCStripDigi"),
0446 digiMaxDistanceX = cms.double(25.0),
0447 dtDigiCollectionLabel = cms.InputTag("muonDTDigis"),
0448 ),
0449 )
0450 process.ecalPreshowerRecHit.TrackAssociatorParameters.usePreshower = cms.bool(True)
0451 process = customisoptions(process)
0452 return modify_outputModules(
0453 process, [keepSelected(dataTier), keepCleaned(dataTier)], ["MINIAODoutput"]
0454 )
0455
0456
0457
0458
0459
0460 def keepLHE():
0461 ret_vstring = cms.untracked.vstring()
0462 ret_vstring.append("keep *_externalLHEProducer_*_LHEembedding")
0463 ret_vstring.append("keep *_externalLHEProducer_*_LHEembeddingCLEAN")
0464 return ret_vstring
0465
0466
0467 def customiseLHE(process, changeProcessname=True, reselect=False):
0468 if reselect:
0469 dataTier = "RESELECT"
0470 else:
0471 dataTier = "SELECT"
0472 if changeProcessname:
0473 process._Process__name = "LHEembedding"
0474 process.load("TauAnalysis.MCEmbeddingTools.EmbeddingLHEProducer_cfi")
0475 if reselect:
0476 process.externalLHEProducer.vertices = cms.InputTag(
0477 "offlineSlimmedPrimaryVertices", "", "RESELECT"
0478 )
0479 process.lheproduction = cms.Path(process.makeexternalLHEProducer)
0480 process.schedule.insert(0, process.lheproduction)
0481
0482 process = customisoptions(process)
0483 return modify_outputModules(
0484 process,
0485 [keepSelected(dataTier), keepCleaned(dataTier), keepLHE()],
0486 ["MINIAODoutput"],
0487 )
0488
0489
0490 def customiseLHEandCleaning(process, reselect=False):
0491 process._Process__name = "LHEembeddingCLEAN"
0492 process = customiseCleaning(process, changeProcessname=False, reselect=reselect)
0493 process = customiseLHE(process, changeProcessname=False, reselect=reselect)
0494 return process
0495
0496
0497 def customiseLHEandCleaning_Reselect(process):
0498 return customiseLHEandCleaning(process, reselect=True)
0499
0500
0501
0502
0503
0504 def keepSimulated(process, processname="SIMembedding"):
0505 ret_vstring = cms.untracked.vstring()
0506 for akt_manimod in to_bemanipulate:
0507 if "MERGE" in akt_manimod.steps:
0508 ret_vstring.append(
0509 "keep *_" + akt_manimod.module_name + "_*_{}".format(processname)
0510 )
0511 ret_vstring.append("keep *_genParticles_*_{}".format(processname))
0512 ret_vstring.append("keep *_standAloneMuons_*_{}".format(processname))
0513 ret_vstring.append("keep *_glbTrackQual_*_{}".format(processname))
0514 ret_vstring.append("keep *_generator_*_{}".format(processname))
0515 ret_vstring.append("keep *_addPileupInfo_*_{}".format(processname))
0516 ret_vstring.append("keep *_selectedMuonsForEmbedding_*_*")
0517 ret_vstring.append("keep *_slimmedAddPileupInfo_*_*")
0518 ret_vstring.append("keep *_embeddingHltPixelVertices_*_*")
0519 ret_vstring.append("keep *_*_vertexPosition_*")
0520 ret_vstring.append("keep recoMuons_muonsFromCosmics_*_*")
0521 ret_vstring.append("keep recoTracks_cosmicMuons1Leg_*_*")
0522 ret_vstring.append("keep recoMuons_muonsFromCosmics1Leg_*_*")
0523 ret_vstring.append("keep *_muonDTDigis_*_*")
0524 ret_vstring.append("keep *_muonCSCDigis_*_*")
0525 ret_vstring.append("keep TrajectorySeeds_*_*_*")
0526 ret_vstring.append("keep recoElectronSeeds_*_*_*")
0527 ret_vstring.append("drop recoIsoDepositedmValueMap_muIsoDepositTk_*_*")
0528 ret_vstring.append("drop recoIsoDepositedmValueMap_muIsoDepositTkDisplaced_*_*")
0529 ret_vstring.append("drop *_ctppsProtons_*_*")
0530 ret_vstring.append("drop *_ctppsLocalTrackLiteProducer_*_*")
0531 ret_vstring.append("drop *_ctppsDiamondLocalTracks_*_*")
0532 ret_vstring.append("drop *_ctppsDiamondRecHits_*_*")
0533 ret_vstring.append("drop *_ctppsDiamondRawToDigi_*_*")
0534 ret_vstring.append("drop *_ctppsPixelLocalTracks_*_*")
0535 ret_vstring.append("drop *_ctppsPixelRecHits_*_*")
0536 ret_vstring.append("drop *_ctppsPixelClusters_*_*")
0537 ret_vstring.append("drop *_ctppsPixelDigis_*_*")
0538 ret_vstring.append("drop *_totemRPLocalTrackFitter_*_*")
0539 ret_vstring.append("drop *_totemRPUVPatternFinder_*_*")
0540 ret_vstring.append("drop *_totemRPRecHitProducer_*_*")
0541 ret_vstring.append("drop *_totemRPClusterProducer_*_*")
0542 ret_vstring.append("drop *_totemRPRawToDigi_*_*")
0543 ret_vstring.append("drop *_muonSimClassifier_*_*")
0544
0545
0546
0547 if processname == "SIMembeddingpreHLT" or processname == "SIMembeddingHLT":
0548 rawreco_commands = set(process.RAWRECOEventContent.outputCommands)
0549 rawreco_commands_excl = rawreco_commands - set(
0550 process.RAWSIMEventContent.outputCommands
0551 )
0552 for entry in rawreco_commands_excl:
0553 if (
0554 processname == "SIMembeddingpreHLT"
0555 and "muonReducedTrackExtras" in entry
0556 ):
0557 continue
0558 if not any(
0559 x in entry
0560 for x in [
0561 "TotemTimingLocalTrack",
0562 "ForwardProton",
0563 "ctppsDiamondLocalTracks",
0564 ]
0565 ):
0566 ret_vstring.append(entry)
0567 return ret_vstring
0568
0569 def customiseGenerator_preHLT(process, changeProcessname=True, reselect=False):
0570 if reselect:
0571 dataTier = "RESELECT"
0572 else:
0573 dataTier = "SELECT"
0574 if changeProcessname:
0575 process._Process__name = "SIMembeddingpreHLT"
0576
0577
0578
0579 process.load("TauAnalysis.MCEmbeddingTools.EmbeddingVertexCorrector_cfi")
0580 process.VtxSmeared = process.VtxCorrectedToInput.clone()
0581 print(
0582 "Correcting Vertex in genEvent to one from input. Replaced 'VtxSmeared' with the Corrector."
0583 )
0584
0585
0586 process.mix.digitizers.castor.doNoise = cms.bool(False)
0587
0588 process.mix.digitizers.ecal.doESNoise = cms.bool(False)
0589 process.mix.digitizers.ecal.doENoise = cms.bool(False)
0590
0591 process.mix.digitizers.hcal.doNoise = cms.bool(False)
0592 process.mix.digitizers.hcal.doThermalNoise = cms.bool(False)
0593 process.mix.digitizers.hcal.doHPDNoise = cms.bool(False)
0594
0595 process.mix.digitizers.pixel.AddNoisyPixels = cms.bool(False)
0596 process.mix.digitizers.pixel.AddNoise = cms.bool(False)
0597
0598 process.mix.digitizers.strip.Noise = cms.bool(False)
0599
0600 process = customisoptions(process)
0601
0602
0603 return modify_outputModules(
0604 process,
0605 [
0606 keepSelected(dataTier),
0607 keepCleaned(dataTier),
0608 keepSimulated(process, processname="SIMembeddingpreHLT"),
0609 ],
0610 ["AODSIMoutput"],
0611 )
0612
0613
0614 def customiseGenerator_preHLT_Reselect(process):
0615 return customiseGenerator_preHLT(process, reselect=True)
0616
0617
0618 def customiseGenerator_HLT(process, changeProcessname=True, reselect=False):
0619 if reselect:
0620 dataTier = "RESELECT"
0621 else:
0622 dataTier = "SELECT"
0623 if changeProcessname:
0624 process._Process__name = "SIMembeddingHLT"
0625
0626
0627 process.load("TauAnalysis.MCEmbeddingTools.EmbeddingBeamSpotOnline_cfi")
0628 process.hltOnlineBeamSpot = process.onlineEmbeddingBeamSpotProducer.clone()
0629 print(
0630 "Setting online beam spot in HLTSchedule to the one from input data. Replaced 'hltOnlineBeamSpot' with the offline beam spot."
0631 )
0632
0633
0634 process.load("TauAnalysis.MCEmbeddingTools.EmbeddingHltPixelVerticesProducer_cfi")
0635 process.hltPixelVertices = process.embeddingHltPixelVertices.clone()
0636 process.offlinePrimaryVertices = process.embeddingHltPixelVertices.clone()
0637 process.firstStepPrimaryVerticesUnsorted = process.embeddingHltPixelVertices.clone()
0638 process.firstStepPrimaryVerticesPreSplitting = (
0639 process.embeddingHltPixelVertices.clone()
0640 )
0641
0642 process = customisoptions(process)
0643
0644
0645 return modify_outputModules(
0646 process,
0647 [
0648 keepSelected(dataTier),
0649 keepCleaned(dataTier),
0650 keepLHE(),
0651 keepSimulated(process, processname="SIMembeddingpreHLT"),
0652 keepSimulated(process, processname="SIMembeddingHLT"),
0653 ],
0654 ["AODSIMoutput"],
0655 )
0656
0657
0658 def customiseGenerator_HLT_Reselect(process):
0659 return customiseGenerator_HLT(process, reselect=True)
0660
0661
0662 def customiseGenerator_postHLT(process, changeProcessname=True, reselect=False):
0663 if reselect:
0664 dataTier = "RESELECT"
0665 else:
0666 dataTier = "SELECT"
0667 if changeProcessname:
0668 process._Process__name = "SIMembedding"
0669
0670
0671
0672
0673
0674
0675
0676
0677
0678
0679
0680 process.reconstruction.remove(process.offlineBeamSpot)
0681
0682 process = customisoptions(process)
0683
0684
0685 return modify_outputModules(
0686 process,
0687 [
0688 keepSelected(dataTier),
0689 keepCleaned(dataTier),
0690 keepLHE(),
0691 keepSimulated(process, processname="SIMembeddingpreHLT"),
0692 keepSimulated(process, processname="SIMembeddingHLT"),
0693 keepSimulated(process, processname="SIMembedding"),
0694 ],
0695 ["AODSIMoutput"],
0696 )
0697
0698
0699 def customiseGenerator_postHLT_Reselect(process):
0700 return customiseGenerator_postHLT(process, reselect=True)
0701
0702
0703
0704
0705
0706 def keepMerged(dataTier="SELECT"):
0707 ret_vstring = cms.untracked.vstring()
0708 ret_vstring.append("drop *_*_*_" + dataTier)
0709 ret_vstring.append("keep *_prunedGenParticles_*_MERGE")
0710 ret_vstring.append("keep *_generator_*_SIMembeddingpreHLT")
0711 ret_vstring.append("keep *_generator_*_SIMembeddingHLT")
0712 ret_vstring.append("keep *_generator_*_SIMembedding")
0713 ret_vstring.append("keep *_selectedMuonsForEmbedding_*_*")
0714 ret_vstring.append("keep *_unpackedPatTrigger_*_*")
0715 ret_vstring.extend(cms.untracked.vstring(
0716 'keep patPackedGenParticles_packedGenParticles_*_*',
0717 'keep recoGenParticles_prunedGenParticles_*_*',
0718 'keep *_packedPFCandidateToGenAssociation_*_*',
0719 'keep *_lostTracksToGenAssociation_*_*',
0720 'keep LHEEventProduct_*_*_*',
0721 'keep GenFilterInfo_*_*_*',
0722 'keep GenLumiInfoHeader_generator_*_*',
0723 'keep GenLumiInfoProduct_*_*_*',
0724 'keep GenEventInfoProduct_generator_*_*',
0725 'keep recoGenParticles_genPUProtons_*_*',
0726 'keep *_slimmedGenJetsFlavourInfos_*_*',
0727 'keep *_slimmedGenJets__*',
0728 'keep *_slimmedGenJetsAK8__*',
0729 'keep *_slimmedGenJetsAK8SoftDropSubJets__*',
0730 'keep *_genMetTrue_*_*',
0731
0732 'keep LHERunInfoProduct_*_*_*',
0733 'keep GenRunInfoProduct_*_*_*',
0734 'keep *_genParticles_xyz0_*',
0735 'keep *_genParticles_t0_*'))
0736 return ret_vstring
0737
0738
0739 def customiseKeepPrunedGenParticles(process, reselect=False):
0740 if reselect:
0741 dataTier = "RESELECT"
0742 else:
0743 dataTier = "SELECT"
0744
0745 process.keep_step = cms.Path()
0746
0747 process.load("PhysicsTools.PatAlgos.slimming.genParticles_cff")
0748 process.keep_step += process.prunedGenParticlesWithStatusOne
0749 process.load("PhysicsTools.PatAlgos.slimming.prunedGenParticles_cfi")
0750 process.keep_step += process.prunedGenParticles
0751 process.load("PhysicsTools.PatAlgos.slimming.packedGenParticles_cfi")
0752 process.keep_step += process.packedGenParticles
0753 process.load("PhysicsTools.PatAlgos.slimming.slimmedGenJets_cfi")
0754 process.keep_step += process.slimmedGenJets
0755
0756 process.load("PhysicsTools.PatAlgos.mcMatchLayer0.muonMatch_cfi")
0757 process.keep_step += process.muonMatch
0758 process.load("PhysicsTools.PatAlgos.mcMatchLayer0.electronMatch_cfi")
0759 process.keep_step += process.electronMatch
0760 process.load("PhysicsTools.PatAlgos.mcMatchLayer0.photonMatch_cfi")
0761 process.keep_step += process.photonMatch
0762 process.load("PhysicsTools.PatAlgos.mcMatchLayer0.tauMatch_cfi")
0763 process.keep_step += process.tauMatch
0764 process.load("PhysicsTools.JetMCAlgos.TauGenJets_cfi")
0765 process.keep_step += process.tauGenJets
0766 process.load("PhysicsTools.PatAlgos.mcMatchLayer0.jetFlavourId_cff")
0767 process.keep_step += process.patJetPartons
0768 process.load("PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi")
0769 process.keep_step += process.patJetPartonMatch
0770
0771 process.muonMatch.matched = "prunedGenParticles"
0772 process.electronMatch.matched = "prunedGenParticles"
0773 process.electronMatch.src = cms.InputTag("reducedEgamma", "reducedGedGsfElectrons")
0774 process.photonMatch.matched = "prunedGenParticles"
0775 process.photonMatch.src = cms.InputTag("reducedEgamma", "reducedGedPhotons")
0776 process.tauMatch.matched = "prunedGenParticles"
0777 process.tauGenJets.GenParticles = "prunedGenParticles"
0778
0779
0780
0781 process.patJetPartons.particles = "prunedGenParticles"
0782 process.patJetPartonMatch.matched = "prunedGenParticles"
0783 process.patJetPartonMatch.mcStatus = [3, 23]
0784 process.patJetGenJetMatch.matched = "slimmedGenJets"
0785 process.patJetGenJetMatchAK8.matched = "slimmedGenJetsAK8"
0786 process.patMuons.embedGenMatch = False
0787 process.patElectrons.embedGenMatch = False
0788 process.patPhotons.embedGenMatch = False
0789 process.patTaus.embedGenMatch = False
0790 process.patTausBoosted.embedGenMatch = False
0791 process.patJets.embedGenPartonMatch = False
0792
0793 process.patJetFlavourAssociation.rParam = 0.4
0794
0795 process.schedule.insert(0, process.keep_step)
0796 process = customisoptions(process)
0797 return modify_outputModules(process, [keepMerged(dataTier)])
0798
0799
0800 def customiseMerging(process, changeProcessname=True, reselect=False):
0801
0802 print("**** Attention: overriding behaviour of 'removeMCMatching' ****")
0803
0804 from PhysicsTools.PatAlgos.slimming.miniAOD_tools import miniAOD_customizeMC
0805 def performMCMatching(process, names, postfix, outputModules):
0806 miniAOD_customizeMC(process)
0807
0808 import PhysicsTools.PatAlgos.tools.coreTools
0809 PhysicsTools.PatAlgos.tools.coreTools.removeMCMatching = performMCMatching
0810
0811 if changeProcessname:
0812 process._Process__name = "MERGE"
0813 if reselect:
0814 dataTier = "RESELECT"
0815 else:
0816 dataTier = "SELECT"
0817
0818 process.source.inputCommands = cms.untracked.vstring()
0819 process.source.inputCommands.append("keep *_*_*_*")
0820 process.load("PhysicsTools.PatAlgos.slimming.unpackedPatTrigger_cfi")
0821 process.unpackedPatTrigger.triggerResults = cms.InputTag("TriggerResults::SIMembeddingHLT")
0822
0823
0824
0825
0826
0827
0828
0829 process.load('Configuration.StandardSequences.RawToDigi_cff')
0830 process.load("Configuration.StandardSequences.Reconstruction_Data_cff")
0831 process.merge_step = cms.Path()
0832
0833 process.load("RecoPPS.Configuration.recoCTPPS_cff")
0834 process.totemRPRawToDigi.rawDataTag = cms.InputTag("rawDataCollector", "", "LHC")
0835 process.ctppsDiamondRawToDigi.rawDataTag = cms.InputTag("rawDataCollector", "", "LHC")
0836 process.ctppsPixelDigis.inputLabel = cms.InputTag("rawDataCollector", "", "LHC")
0837 process.merge_step += process.totemRPRawToDigi
0838 process.merge_step += process.ctppsDiamondRawToDigi
0839 process.merge_step += process.ctppsPixelDigis
0840 process.merge_step += cms.Sequence(process.recoCTPPSTask)
0841
0842 process.load("RecoLocalCalo.Configuration.RecoLocalCalo_cff")
0843 process.merge_step += process.calolocalreco
0844
0845 process.merge_step += process.reducedHcalRecHitsSequence
0846
0847
0848 process.load("RecoLocalCalo.CaloTowersCreator.calotowermaker_cfi")
0849 process.merge_step += process.calotowermaker
0850 process.merge_step += process.towerMaker
0851
0852
0853 process.load("RecoEcal.Configuration.RecoEcal_cff")
0854 process.merge_step += process.ecalClusters
0855
0856
0857 process.load("RecoParticleFlow.PFClusterProducer.particleFlowCluster_cff")
0858 process.merge_step += process.particleFlowCluster
0859 process.load(
0860 "RecoEcal.EgammaClusterProducers.particleFlowSuperClusteringSequence_cff"
0861 )
0862 process.merge_step += process.particleFlowSuperClusteringSequence
0863
0864
0865 process.load("RecoMuon.MuonIdentification.muons1stStep_cfi")
0866 process.merge_step += process.muonEcalDetIds
0867 process.merge_step += process.muonShowerInformation
0868
0869
0870 process.load("RecoMuon.MuonIsolationProducers.muIsolation_cff")
0871 process.merge_step += process.muIsolation
0872 process.merge_step += process.muIsolationDisplaced
0873
0874
0875 process.load("RecoMuon.MuonIdentification.muonSelectionTypeValueMapProducer_cff")
0876 process.merge_step += process.muonSelectionTypeSequence
0877
0878
0879 process.load("RecoMuon.MuonIdentification.displacedMuonReducedTrackExtras_cfi")
0880 process.merge_step += process.displacedMuonReducedTrackExtras
0881
0882 process.load("RecoMuon.Configuration.MergeDisplacedTrackCollections_cff")
0883 process.merge_step += process.displacedTracksSequence
0884
0885
0886 process.merge_step += process.doAlldEdXEstimators
0887 process.merge_step += process.vertexreco
0888 process.unsortedOfflinePrimaryVertices.beamSpotLabel = cms.InputTag(
0889 "offlineBeamSpot", "", dataTier
0890 )
0891 process.ak4CaloJetsForTrk.srcPVs = cms.InputTag(
0892 "firstStepPrimaryVertices", "", dataTier
0893 )
0894 process.dedxHitInfo.clusterShapeCache = cms.InputTag("")
0895
0896
0897
0898
0899
0900
0901
0902
0903
0904
0905
0906
0907
0908
0909
0910
0911
0912
0913
0914 process.merge_step += process.highlevelreco
0915
0916
0917
0918
0919
0920
0921
0922
0923
0924
0925
0926
0927
0928
0929 process.load("CommonTools.ParticleFlow.genForPF2PAT_cff")
0930
0931
0932
0933 process.merge_step += process.genForPF2PATSequence
0934
0935
0936
0937 modules_to_be_ordered = {}
0938
0939 reconstruction_modules_list = str(process.RawToDigi).split(",")
0940 reconstruction_modules_list += str(process.reconstruction).split(",")
0941 for akt_manimod in to_bemanipulate:
0942 if "MERGE" in akt_manimod.steps:
0943 mergCollections_in = cms.VInputTag()
0944 for instance in akt_manimod.instance:
0945 mergCollections_in.append(
0946 cms.InputTag(
0947 akt_manimod.merge_prefix + akt_manimod.module_name,
0948 instance,
0949 "SIMembedding",
0950 )
0951 )
0952 mergCollections_in.append(
0953 cms.InputTag(
0954 akt_manimod.merge_prefix + akt_manimod.module_name,
0955 instance,
0956 "LHEembeddingCLEAN",
0957 )
0958 )
0959 setattr(
0960 process,
0961 akt_manimod.module_name,
0962 cms.EDProducer(
0963 akt_manimod.merger_name, mergCollections=mergCollections_in
0964 ),
0965 )
0966 if not process.merge_step.contains(getattr(process, akt_manimod.module_name)):
0967 modules_to_be_ordered[akt_manimod.module_name] = -1
0968
0969 for name,index in modules_to_be_ordered.items():
0970 if name in reconstruction_modules_list:
0971 modules_to_be_ordered[name] = reconstruction_modules_list.index(name)
0972 else:
0973 print("ERROR:",name,"not prepared in modules list. Please adapt 'customiseMerging'")
0974 sys.exit(1)
0975
0976 modules_ordered = sorted(list(modules_to_be_ordered.items()), key=lambda x : -x[1])
0977 for m in modules_ordered:
0978 process.merge_step.insert(0, getattr(process, m[0]))
0979
0980
0981 process.schedule.insert(0, process.merge_step)
0982
0983 process = customisoptions(process)
0984 return modify_outputModules(process, [keepMerged(dataTier)])
0985
0986
0987 def customiseMerging_Reselect(process, changeProcessname=True):
0988 return customiseMerging(process, changeProcessname=changeProcessname, reselect=True)
0989
0990
0991
0992
0993
0994 def customiseNanoAOD(process):
0995
0996 process.load("PhysicsTools.NanoAOD.nano_cff")
0997 process.nanoAOD_step.insert(0, cms.Sequence(process.nanoTableTaskFS))
0998
0999
1000 for outputModule in process.outputModules.values():
1001 outputModule.outputCommands.append("keep edmTriggerResults_*_*_SIMembeddingpreHLT")
1002 outputModule.outputCommands.append("keep edmTriggerResults_*_*_SIMembeddingHLT")
1003 outputModule.outputCommands.append("keep edmTriggerResults_*_*_SIMembedding")
1004 outputModule.outputCommands.append("keep edmTriggerResults_*_*_MERGE")
1005 outputModule.outputCommands.append("keep edmTriggerResults_*_*_NANO")
1006 outputModule.outputCommands.remove("keep edmTriggerResults_*_*_*")
1007
1008 process.load("PhysicsTools.NanoAOD.l1trig_cff")
1009 process.nanoAOD_step.insert(0, cms.Sequence(process.l1TablesTask))
1010
1011 process.embeddingTable = cms.EDProducer(
1012 "GlobalVariablesTableProducer",
1013 name=cms.string("TauEmbedding"),
1014
1015 variables=cms.PSet(
1016 nInitialPairCandidates=ExtVar(
1017 cms.InputTag("selectedMuonsForEmbedding", "nPairCandidates"),
1018 float,
1019 doc="number of muons pairs suitable for selection (for internal studies only)",
1020 ),
1021 SelectionOldMass=ExtVar(
1022 cms.InputTag("selectedMuonsForEmbedding", "oldMass"),
1023 float,
1024 doc="Mass of the Dimuon pair using the old selection algorithm (for internal studies only)",
1025 ),
1026 SelectionNewMass=ExtVar(
1027 cms.InputTag("selectedMuonsForEmbedding", "newMass"),
1028 float,
1029 doc="Mass of the Dimuon pair using the new selection algorithm (for internal studies only)",
1030 ),
1031 isMediumLeadingMuon=ExtVar(
1032 cms.InputTag("selectedMuonsForEmbedding", "isMediumLeadingMuon"),
1033 bool,
1034 doc="leading muon ID (medium)",
1035 ),
1036 isMediumTrailingMuon=ExtVar(
1037 cms.InputTag("selectedMuonsForEmbedding", "isMediumTrailingMuon"),
1038 bool,
1039 doc="trailing muon ID (medium)",
1040 ),
1041 isTightLeadingMuon=ExtVar(
1042 cms.InputTag("selectedMuonsForEmbedding", "isTightLeadingMuon"),
1043 bool,
1044 doc="leading muon ID (tight)",
1045 ),
1046 isTightTrailingMuon=ExtVar(
1047 cms.InputTag("selectedMuonsForEmbedding", "isTightTrailingMuon"),
1048 bool,
1049 doc="trailing muon ID (tight)",
1050 ),
1051 initialMETEt=ExtVar(
1052 cms.InputTag("selectedMuonsForEmbedding", "initialMETEt"),
1053 float,
1054 doc="MET Et of selected event",
1055 ),
1056 initialMETphi=ExtVar(
1057 cms.InputTag("selectedMuonsForEmbedding", "initialMETphi"),
1058 float,
1059 doc="MET phi of selected event",
1060 ),
1061 initialPuppiMETEt=ExtVar(
1062 cms.InputTag("selectedMuonsForEmbedding", "initialPuppiMETEt"),
1063 float,
1064 doc="PuppiMET Et of selected event",
1065 ),
1066 initialPuppiMETphi=ExtVar(
1067 cms.InputTag("selectedMuonsForEmbedding", "initialPuppiMETphi"),
1068 float,
1069 doc="PuppiMET phi of selected event",
1070 ),
1071 ),
1072 )
1073 process.embeddingTableTask = cms.Task(process.embeddingTable)
1074 process.schedule.associate(process.embeddingTableTask)
1075
1076 return process
1077
1078
1079
1080
1081
1082
1083
1084
1085 def customisoptions(process):
1086 if not hasattr(process, "options"):
1087 process.options = cms.untracked.PSet()
1088 process.options.emptyRunLumiMode = cms.untracked.string(
1089 "doNotHandleEmptyRunsAndLumis"
1090 )
1091 if not hasattr(process, "bunchSpacingProducer"):
1092 process.bunchSpacingProducer = cms.EDProducer("BunchSpacingProducer")
1093 process.bunchSpacingProducer.bunchSpacingOverride = cms.uint32(25)
1094 process.bunchSpacingProducer.overrideBunchSpacing = cms.bool(True)
1095 process.options.numberOfThreads = cms.untracked.uint32(1)
1096 process.options.numberOfStreams = cms.untracked.uint32(0)
1097 return process
1098
1099
1100
1101
1102
1103 def customiseFilterZToMuMu(process):
1104 process.load("TauAnalysis.MCEmbeddingTools.DYToMuMuGenFilter_cfi")
1105 process.ZToMuMuFilter = cms.Path(process.dYToMuMuGenFilter)
1106 process.schedule.insert(-1, process.ZToMuMuFilter)
1107 return process
1108
1109
1110 def customiseFilterTTbartoMuMu(process):
1111 process.load("TauAnalysis.MCEmbeddingTools.TTbartoMuMuGenFilter_cfi")
1112 process.MCFilter = cms.Path(process.TTbartoMuMuGenFilter)
1113 return customiseMCFilter(process)
1114
1115
1116 def customiseMCFilter(process):
1117 process.schedule.insert(-1, process.MCFilter)
1118 outputModulesList = [key for key, value in process.outputModules.items()]
1119 for outputModule in outputModulesList:
1120 outputModule = getattr(process, outputModule)
1121 outputModule.SelectEvents = cms.untracked.PSet(
1122 SelectEvents=cms.vstring("MCFilter")
1123 )
1124 return process
1125
1126
1127 def fix_input_tags(
1128 process, formodules=["generalTracks", "cscSegments", "dt4DSegments", "rpcRecHits"]
1129 ):
1130 def change_tags_process(test_input):
1131 if isinstance(test_input, cms.InputTag):
1132 if test_input.getModuleLabel() in formodules:
1133 test_input.setProcessName(process._Process__name)
1134
1135 def search_for_tags(pset):
1136 if isinstance(pset, dict):
1137 for key in pset:
1138 if isinstance(pset[key], cms.VInputTag):
1139 for akt_inputTag in pset[key]:
1140 change_tags_process(akt_inputTag)
1141 elif isinstance(pset[key], cms.PSet):
1142 search_for_tags(pset[key].__dict__)
1143 elif isinstance(pset[key], cms.VPSet):
1144 for akt_pset in pset[key]:
1145 search_for_tags(akt_pset.__dict__)
1146 else:
1147 change_tags_process(pset[key])
1148 else:
1149 print("must be python dict not a {}".format(type(pset)))
1150
1151 for module in process.producers_():
1152 search_for_tags(getattr(process, module).__dict__)
1153 for module in process.filters_():
1154 search_for_tags(getattr(process, module).__dict__)
1155 for module in process.analyzers_():
1156 search_for_tags(getattr(process, module).__dict__)
1157
1158 return process