Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-09-12 10:21:41

0001 import FWCore.ParameterSet.Config as cms
0002 
0003 # handle normal mixing or premixing
0004 def getHcalDigitizer(process):
0005     if hasattr(process,'mixData'):
0006         return process.mixData
0007     if hasattr(process,'mix') and hasattr(process.mix,'digitizers') and hasattr(process.mix.digitizers,'hcal'):
0008         return process.mix.digitizers.hcal
0009     return None
0010 
0011 def getHGCalDigitizer(process,section):
0012     if hasattr(process,'mix') and hasattr(process.mix,'digitizers'):
0013         if section == 'EE' and hasattr(process.mix.digitizers,'hgceeDigitizer'):
0014             return process.mix.digitizers.hgceeDigitizer
0015         elif section == 'FH' and hasattr(process.mix.digitizers,'hgchefrontDigitizer'):
0016             return process.mix.digitizers.hgchefrontDigitizer
0017         elif section == 'BH' and hasattr(process.mix.digitizers,'hgchebackDigitizer'):
0018             return process.mix.digitizers.hgchebackDigitizer
0019         elif section == 'HFNose' and hasattr(process.mix.digitizers,'hfnoseDigitizer'):
0020             return process.mix.digitizers.hfnoseDigitizer
0021     return None
0022 
0023 # change assumptions about lumi rate
0024 def setScenarioHLLHC(module,scenarioHLLHC):
0025     if scenarioHLLHC=="nominal":
0026         from CalibCalorimetry.HcalPlugins.HBHEDarkening_cff import _years_LHC, _years_HLLHC_nominal
0027         module.years = _years_LHC + _years_HLLHC_nominal
0028     elif scenarioHLLHC=="ultimate":
0029         from CalibCalorimetry.HcalPlugins.HBHEDarkening_cff import _years_LHC, _years_HLLHC_ultimate
0030         module.years = _years_LHC + _years_HLLHC_ultimate
0031     return module
0032 
0033 # turnon = True enables default, False disables
0034 # recalibration and darkening always together
0035 def ageHB(process,turnon,scenarioHLLHC):
0036     if turnon:
0037         from CalibCalorimetry.HcalPlugins.HBHEDarkening_cff import HBDarkeningEP
0038         process.HBDarkeningEP = HBDarkeningEP
0039         process.HBDarkeningEP = setScenarioHLLHC(process.HBDarkeningEP,scenarioHLLHC)
0040     hcaldigi = getHcalDigitizer(process)
0041     if hcaldigi is not None: hcaldigi.HBDarkening = cms.bool(turnon)
0042     if hasattr(process,'es_hardcode'):
0043         process.es_hardcode.HBRecalibration = cms.bool(turnon)
0044     return process
0045 
0046 def ageHE(process,turnon,scenarioHLLHC):
0047     if turnon:
0048         from CalibCalorimetry.HcalPlugins.HBHEDarkening_cff import HEDarkeningEP
0049         process.HEDarkeningEP = HEDarkeningEP
0050         process.HEDarkeningEP = setScenarioHLLHC(process.HEDarkeningEP,scenarioHLLHC)
0051     hcaldigi = getHcalDigitizer(process)
0052     if hcaldigi is not None: hcaldigi.HEDarkening = cms.bool(turnon)
0053     if hasattr(process,'es_hardcode'):
0054         process.es_hardcode.HERecalibration = cms.bool(turnon)
0055     return process
0056 
0057 def ageHF(process,turnon):
0058     hcaldigi = getHcalDigitizer(process)
0059     if hcaldigi is not None: hcaldigi.HFDarkening = cms.bool(turnon)
0060     if hasattr(process,'es_hardcode'):
0061         process.es_hardcode.HFRecalibration = cms.bool(turnon)
0062     return process
0063 
0064 def agedHFNose(process,algo=0):
0065     from SimCalorimetry.HGCalSimProducers.hgcalDigitizer_cfi import HFNose_setEndOfLifeNoise
0066     process = HFNose_setEndOfLifeNoise(process,byDose=True,byDoseAlgo=algo)
0067     return process
0068 
0069 def agedHGCal(process,algo=0):
0070     from SimCalorimetry.HGCalSimProducers.hgcalDigitizer_cfi import HGCal_setEndOfLifeNoise
0071     process = HGCal_setEndOfLifeNoise(process,byDose=True,byDoseAlgo=algo)
0072     return process
0073 
0074 def realisticHGCalStartup(process):
0075     from SimCalorimetry.HGCalSimProducers.hgcalDigitizer_cfi import HGCal_setRealisticStartupNoise
0076     process = HGCal_setRealisticStartupNoise(process)
0077     return process
0078 
0079 # needs lumi to set proper ZS thresholds (tbd)
0080 def ageSiPM(process,turnon,lumi):
0081     process.es_hardcode.hbUpgrade.doRadiationDamage = turnon
0082     process.es_hardcode.heUpgrade.doRadiationDamage = turnon
0083 
0084     # todo: determine ZS threshold adjustments
0085 
0086     # adjust PF thresholds for increased noise
0087     # based on: https://baylor.box.com/s/w32ja75krcbxcycyifexu28dwlgrj7wg
0088     hcal_lumis = [300, 1000, 3000, 4500, 1e10]
0089     hcal_thresholds = {
0090         300: {
0091             "seed": [0.5, 0.625, 0.75, 0.75],
0092             "rec": [0.4, 0.5, 0.6, 0.6],
0093         },
0094         1000: {
0095             "seed": [1.0, 1.5, 1.5, 1.5],
0096             "rec": [0.8, 1.2, 1.2, 1.2],
0097         },
0098         3000: {
0099             "seed": [1.25, 2.5, 2.5, 2.5],
0100             "rec": [1.0, 2.0, 2.0, 2.0],
0101         },
0102         4500: {
0103             "seed": [1.5, 3.0, 3.0, 3.0],
0104             "rec": [1.25, 2.5, 2.5, 2.5],
0105         },
0106     }
0107     ctmodules = ['calotowermaker','caloTowerForTrk','caloTowerForTrkPreSplitting','towerMaker','towerMakerWithHO','hltPhase2TowerMakerForAll',' hltTowerMaker']
0108     for ilumi, hcal_lumi in enumerate(hcal_lumis[:-1]):
0109         if lumi >= hcal_lumi and lumi < hcal_lumis[ilumi+1]:
0110             pfclushbhemodules = ['particleFlowClusterHBHE','hltParticleFlowClusterHBHE']
0111             for pfhbhemod in pfclushbhemodules:
0112                 if hasattr(process,pfhbhemod):
0113                     getattr(process,pfhbhemod).seedFinder.thresholdsByDetector[0].seedingThreshold              = hcal_thresholds[hcal_lumi]["seed"]
0114                     getattr(process,pfhbhemod).initialClusteringStep.thresholdsByDetector[0].gatheringThreshold = hcal_thresholds[hcal_lumi]["rec"]
0115                     getattr(process,pfhbhemod).pfClusterBuilder.recHitEnergyNorms[0].recHitEnergyNorm           = hcal_thresholds[hcal_lumi]["rec"]
0116                     getattr(process,pfhbhemod).pfClusterBuilder.positionCalc.logWeightDenominatorByDetector[0].logWeightDenominator = hcal_thresholds[hcal_lumi]["rec"]
0117                     getattr(process,pfhbhemod).pfClusterBuilder.allCellsPositionCalc.logWeightDenominatorByDetector[0].logWeightDenominator = hcal_thresholds[hcal_lumi]["rec"]
0118             pfclushcalmodules = ['particleFlowClusterHCAL','hltParticleFlowClusterHCAL']
0119             for pfhcalmod in  pfclushcalmodules:
0120                 if hasattr(process,pfhcalmod):
0121                     getattr(process,pfhcalmod).pfClusterBuilder.allCellsPositionCalc.logWeightDenominatorByDetector[0].logWeightDenominator = hcal_thresholds[hcal_lumi]["rec"]
0122             pfrechithbhemodules = ['particleFlowRecHitHBHE', 'hltParticleFlowRecHitHBHE']
0123             for pfrechitmod in pfrechithbhemodules:
0124                 if hasattr(process,pfrechitmod):
0125                     getattr(process,pfrechitmod).producers[0].qualityTests[0].cuts[0].threshold = hcal_thresholds[hcal_lumi]["rec"]
0126             for ctmod in ctmodules:
0127                 if hasattr(process,ctmod):
0128                     getattr(process,ctmod).HBThreshold1 = hcal_thresholds[hcal_lumi]["rec"][0]
0129                     getattr(process,ctmod).HBThreshold2 = hcal_thresholds[hcal_lumi]["rec"][1]
0130                     getattr(process,ctmod).HBThreshold = hcal_thresholds[hcal_lumi]["rec"][-1]
0131             break
0132 
0133     return process
0134 
0135 def ageHcal(process,lumi,instLumi,scenarioHLLHC):
0136     hcaldigi = getHcalDigitizer(process)
0137     if hcaldigi is not None: hcaldigi.DelivLuminosity = cms.double(float(lumi))  # integrated lumi in fb-1
0138 
0139     # these lines need to be further activated by turning on 'complete' aging for HF
0140     if hasattr(process,'g4SimHits'):
0141         process.g4SimHits.HCalSD.InstLuminosity = cms.double(float(instLumi))
0142         process.g4SimHits.HCalSD.DelivLuminosity = cms.double(float(lumi))
0143 
0144     # recalibration and darkening always together
0145     if hasattr(process,'es_hardcode'):
0146         process.es_hardcode.iLumi = cms.double(float(lumi))
0147 
0148     # functions to enable individual subdet aging
0149     process = ageHB(process,True,scenarioHLLHC)
0150     process = ageHE(process,True,scenarioHLLHC)
0151     process = ageHF(process,True)
0152     process = ageSiPM(process,True,lumi)
0153 
0154     return process
0155 
0156 def turn_on_HB_aging(process):
0157     process = ageHB(process,True,"")
0158     return process
0159 
0160 def turn_off_HB_aging(process):
0161     process = ageHB(process,False,"")
0162     return process
0163 
0164 def turn_on_HE_aging(process):
0165     process = ageHE(process,True,"")
0166     return process
0167 
0168 def turn_off_HE_aging(process):
0169     process = ageHE(process,False,"")
0170     return process
0171 
0172 def turn_on_HF_aging(process):
0173     process = ageHF(process,True)
0174     return process
0175 
0176 def turn_off_HF_aging(process):
0177     process = ageHF(process,False)
0178     return process
0179 
0180 def turn_off_SiPM_aging(process):
0181     process = ageSiPM(process,False,0.0)
0182     return process
0183 
0184 def hf_complete_aging(process):
0185     if hasattr(process,'g4SimHits'):
0186         process.g4SimHits.HCalSD.HFDarkening = cms.untracked.bool(True)
0187     hcaldigi = getHcalDigitizer(process)
0188     if hcaldigi is not None: hcaldigi.HFDarkening = cms.untracked.bool(False)
0189     return process
0190 
0191 def ageEcal(process,lumi,instLumi):
0192     if hasattr(process,'g4SimHits'):
0193         #these lines need to be further activiated by tuning on 'complete' aging for ecal
0194         process.g4SimHits.ECalSD.InstLuminosity = cms.double(instLumi)
0195         process.g4SimHits.ECalSD.DelivLuminosity = cms.double(float(lumi))
0196 
0197    # available conditions
0198     ecal_lumis = [300,1000,3000,4500]
0199     ecal_conditions = [
0200         ['EcalIntercalibConstantsRcd','EcalIntercalibConstants_TL{:d}_upgrade_8deg_v2_mc'],
0201         ['EcalIntercalibConstantsMCRcd','EcalIntercalibConstantsMC_TL{:d}_upgrade_8deg_v2_mc'],
0202         ['EcalLaserAPDPNRatiosRcd','EcalLaserAPDPNRatios_TL{:d}_upgrade_8deg_mc'],
0203         ['EcalPedestalsRcd','EcalPedestals_TL{:d}_upgradeTIA_8deg_mc'],
0204         ['EcalTPGLinearizationConstRcd','EcalTPGLinearizationConst_TL{:d}_upgrade_8deg_mc'],
0205     ]
0206 
0207     # update PF thresholds, based on https://indico.cern.ch/event/653123/contributions/2659235/attachments/1491385/2318364/170711_upsg_ledovskoy.pdf
0208     ecal_thresholds = {
0209         300 : 0.103,
0210         1000 : 0.175,
0211         3000 : 0.435,
0212         4500 : 0.707,
0213     }
0214     ecal_seed_multiplier = 2.5
0215 
0216     # try to get conditions
0217     if int(lumi) in ecal_lumis:
0218         if not hasattr(process.GlobalTag,'toGet'):
0219             process.GlobalTag.toGet=cms.VPSet()
0220         for ecal_condition in ecal_conditions:
0221             process.GlobalTag.toGet.append(cms.PSet(
0222                 record = cms.string(ecal_condition[0]),
0223                 tag = cms.string(ecal_condition[1].format(int(lumi))),
0224                 connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS")
0225                 )
0226             )
0227         pfclusecaluncorrmodules = ['particleFlowClusterECALUncorrected','hltParticleFlowClusterECALUncorrected','hltParticleFlowClusterECALUncorrectedL1Seeded',' hltParticleFlowClusterECALUncorrectedUnseeded']
0228         for pfclusecaluncorrmod in pfclusecaluncorrmodules:
0229             if hasattr(process,pfclusecaluncorrmod):
0230                 _seeds = getattr(process,pfclusecaluncorrmod).seedFinder.thresholdsByDetector
0231                 for iseed in range(0,len(_seeds)):
0232                     if _seeds[iseed].detector.value()=="ECAL_BARREL":
0233                         _seeds[iseed].seedingThreshold = cms.double(ecal_thresholds[int(lumi)]*ecal_seed_multiplier)
0234                 _clusters = getattr(process,pfclusecaluncorrmod).initialClusteringStep.thresholdsByDetector
0235                 for icluster in range(0,len(_clusters)):
0236                     if _clusters[icluster].detector.value()=="ECAL_BARREL":
0237                         _clusters[icluster].gatheringThreshold = cms.double(ecal_thresholds[int(lumi)])
0238 
0239     return process
0240 
0241 def ecal_complete_aging(process):
0242     if hasattr(process,'g4SimHits'):
0243         process.g4SimHits.ECalSD.AgeingWithSlopeLY = cms.untracked.bool(True)
0244     if hasattr(process,'ecal_digi_parameters'):
0245         process.ecal_digi_parameters.UseLCcorrection = cms.untracked.bool(False)
0246     return process
0247 
0248 def customise_aging_300(process):
0249     process=ageHcal(process,300,5.0e34,"nominal")
0250     process=ageEcal(process,300,5.0e34)
0251     return process
0252 
0253 def customise_aging_1000(process):
0254     process=ageHcal(process,1000,5.0e34,"nominal")
0255     process=turn_off_HE_aging(process) #avoid conflict between HGCal and Hcal in phase2 geom configuration
0256     process=ageEcal(process,1000,5.0e34)
0257     return process
0258 
0259 def customise_aging_3000(process):
0260     process=ageHcal(process,3000,5.0e34,"nominal")
0261     process=turn_off_HE_aging(process) #avoid conflict between HGCal and Hcal in phase2 geom configuration
0262     process=ageEcal(process,3000,5.0e34)
0263     process=agedHGCal(process)
0264     process=agedHFNose(process)
0265     return process
0266 
0267 def customise_aging_3000_ultimate(process):
0268     process=ageHcal(process,3000,7.5e34,"ultimate")
0269     process=turn_off_HE_aging(process) #avoid conflict between HGCal and Hcal in phase2 geom configuration
0270     process=ageEcal(process,3000,7.5e34)
0271     process=agedHGCal(process)
0272     process=agedHFNose(process)
0273     return process
0274 
0275 def customise_aging_4500_ultimate(process):
0276     process=ageHcal(process,4500,7.5e34,"ultimate")
0277     process=turn_off_HE_aging(process) #avoid conflict between HGCal and Hcal in phase2 geom configuration
0278     process=ageEcal(process,4500,7.5e34)
0279     process=agedHGCal(process)
0280     process=agedHFNose(process)
0281     return process