Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:40

0001 import FWCore.ParameterSet.Config as cms
0002 from PhysicsTools.NanoAOD.common_cff import *
0003 
0004 def ecal_phisym_workflow(process, 
0005                          produce_by_run : bool=False, 
0006                          save_edm : bool=False,
0007                          save_edmnano : bool=False,
0008                          save_flatnano : bool=True):
0009     """
0010     Customize the process to include the entire EcalPhiSym workflow:
0011     - ECAL local reco
0012     - PhiSymRecHit producer
0013     - EDM output (standard, EDMNANO, FlatNANO)
0014     """
0015 
0016     reco = ecal_phisym_reco_sequence(process, produce_by_run=produce_by_run)
0017     tables = ecal_phisym_flattables(process, produce_by_run=produce_by_run)
0018     outputs = ecal_phisym_output(process, 
0019                                  save_edm=save_edm, 
0020                                  save_edmnano=save_edmnano, 
0021                                  save_flatnano=save_flatnano)
0022 
0023     process.path = cms.Path(reco*tables)
0024     process.output_step = cms.EndPath()
0025     for out in outputs:
0026         process.output_step += out
0027     process.schedule = cms.Schedule(process.path, process.output_step)
0028 
0029 def ecal_phisym_reco_sequence(process, produce_by_run : bool=False):
0030     """
0031     Customize process to include the EcalPhiSym standard reco sequence
0032     """
0033 
0034     process.load('RecoLuminosity.LumiProducer.bunchSpacingProducer_cfi')
0035     process.load('RecoLocalCalo.EcalRecProducers.ecalMultiFitUncalibRecHit_cfi')
0036     process.load('RecoLocalCalo.EcalRecProducers.ecalUncalibRecHit_cfi')
0037     process.load('RecoLocalCalo.EcalRecProducers.ecalRecHit_cfi')
0038 
0039     #ecalMultiFitUncalibRecHit
0040     process.ecalMultiFitUncalibRecHit.EBdigiCollection = cms.InputTag("hltEcalPhiSymFilter","phiSymEcalDigisEB")
0041     process.ecalMultiFitUncalibRecHit.EEdigiCollection = cms.InputTag("hltEcalPhiSymFilter","phiSymEcalDigisEE")
0042 
0043     #ecalRecHit (no ricovery)
0044     process.ecalRecHit.killDeadChannels = cms.bool( False )
0045     process.ecalRecHit.recoverEBVFE = cms.bool( False )
0046     process.ecalRecHit.recoverEEVFE = cms.bool( False )
0047     process.ecalRecHit.recoverEBFE = cms.bool( False )
0048     process.ecalRecHit.recoverEEFE = cms.bool( False )
0049     process.ecalRecHit.recoverEEIsolatedChannels = cms.bool( False )
0050     process.ecalRecHit.recoverEBIsolatedChannels = cms.bool( False )
0051 
0052     # PHISYM producer
0053     process.load('Calibration.EcalCalibAlgos.EcalPhiSymRecHitProducers_cfi')
0054 
0055     # SCHEDULE
0056     reconstruction_step = cms.Sequence( process.bunchSpacingProducer * (process.ecalMultiFitUncalibRecHit + process.ecalRecHit) )
0057     reconstruction_step *= process.EcalPhiSymRecHitProducerRun if produce_by_run else process.EcalPhiSymRecHitProducerLumi
0058 
0059     return reconstruction_step
0060 
0061 def ecal_phisym_flattables(process, produce_by_run : bool=False):
0062     """
0063     Add the NanoAOD flat table producers.
0064     This functions adjust also the output columns.
0065     Should be called once nMisCalib has been set in the EcalPhiSymRecHitProducer
0066     """
0067 
0068     process.load('Calibration.EcalCalibAlgos.EcalPhiSymFlatTableProducers_cfi')
0069 
0070     nmis = process.EcalPhiSymRecHitProducerRun.nMisCalib.value()
0071     for imis in range(1, nmis+1):
0072         # get the naming and indexing right.
0073         if imis<nmis/2+1:
0074             var_name = 'sumEt_m'+str(abs(int(imis-(nmis/2)-1)))
0075             var = Var(f'sumEt({imis})', float, doc='ECAL PhiSym rechits: '+str(imis-(nmis/2)-1)+'*miscalib et', precision=23)
0076         else:
0077             var_name = 'sumEt_p'+str(int(imis-(nmis/2)))
0078             var = Var(f'sumEt({imis})', float, doc='ECAL PhiSym rechits: '+str(imis-(nmis/2))+'*miscalib et', precision=23)
0079         
0080         if produce_by_run:
0081             setattr(process.ecalPhiSymRecHitRunTableEB.variables, var_name, var)
0082             setattr(process.ecalPhiSymRecHitRunTableEE.variables, var_name, var)
0083             flattable_sequence = cms.Sequence( process.ecalPhiSymRecHitRunTableEB + 
0084                                                process.ecalPhiSymRecHitRunTableEE +
0085                                                process.ecalPhiSymInfoRunTable )
0086         else:
0087             setattr(process.ecalPhiSymRecHitLumiTableEB.variables, var_name, var)
0088             setattr(process.ecalPhiSymRecHitLumiTableEE.variables, var_name, var)
0089             flattable_sequence = cms.Sequence( process.ecalPhiSymRecHitLumiTableEB + 
0090                                                process.ecalPhiSymRecHitLumiTableEE + 
0091                                                process.ecalPhiSymInfoLumiTable
0092             )
0093 
0094     return flattable_sequence
0095 
0096 def ecal_phisym_output(process, 
0097                        save_edm : bool=False,
0098                        save_edmnano : bool=False,
0099                        save_flatnano : bool=True):
0100     """
0101     Customize EcalPhiSym output
0102     """
0103 
0104     outputs = []
0105 
0106     if save_flatnano or save_edmnano:
0107         NanoAODEcalPhiSymEventContent = cms.PSet(
0108             outputCommands = cms.untracked.vstring(
0109                 'drop *',
0110                 "keep nanoaod*_*_*_*",     # event data
0111                 "keep nanoaodMergeableCounterTable_*Table_*_*", # accumulated per/run or per/lumi data
0112                 "keep nanoaodUniqueString_nanoMetadata_*_*",   # basic metadata
0113             )
0114         )        
0115                        
0116     if save_flatnano:
0117         process.nanoout = cms.OutputModule("NanoAODOutputModule",
0118                                            fileName = cms.untracked.string('ecal_phisym_nano.root'),
0119                                            outputCommands = NanoAODEcalPhiSymEventContent.outputCommands,
0120                                            compressionLevel = cms.untracked.int32(9),
0121                                            compressionAlgorithm = cms.untracked.string("LZMA"),
0122                                        )
0123         outputs.append(process.nanoout)
0124 
0125     if save_edmnano:
0126         process.nanooutedm = cms.OutputModule("PoolOutputModule",
0127                                               fileName = cms.untracked.string('ecal_phisym_edmnano.root'),
0128                                               outputCommands = NanoAODEcalPhiSymEventContent.outputCommands,
0129                                           )
0130         outputs.append(process.nanooutedm)
0131 
0132     if save_edm:
0133         ECALPHISYM_output_commands = cms.untracked.vstring(
0134             "drop *",
0135             "keep *_PhiSymProducerRun_*_*")
0136 
0137         process.EcalPhiSymOutput = cms.OutputModule("PoolOutputModule",
0138                                                     splitLevel = cms.untracked.int32(2),
0139                                                     compressionLevel = cms.untracked.int32(5),
0140                                                     compressionAlgorithm = cms.untracked.string('LZMA'),
0141                                                     outputCommands = ECALPHISYM_output_commands,
0142                                                     fileName = cms.untracked.string('ecal_phisym_reco.root')
0143                                                 )
0144         outputs.append(process.EcalPhiSymOutput)
0145 
0146     return outputs
0147 
0148 def customise(process):
0149     """
0150     Function to customize the process produced by cmsDriver.
0151     The customisation works for a process that satisfies the following conditions:
0152     - Run on /AlCaPhiSym/*/RAW data
0153     - Run the following sequence (-s option of cmsDriver): 
0154     RECO:bunchSpacingProducer+ecalMultiFitUncalibRecHitTask+ecalCalibratedRecHitTask,ALCA:EcalPhiSymByRun (or EcalPhiSymByLumi)
0155     """
0156     
0157     # Change input collection for the /AlCaPhiSym/*/RAW stream dataformat
0158     process.ecalMultiFitUncalibRecHitCPU.EBdigiCollection = "hltEcalPhiSymFilter:phiSymEcalDigisEB"
0159     process.ecalMultiFitUncalibRecHitCPU.EEdigiCollection = "hltEcalPhiSymFilter:phiSymEcalDigisEE"
0160     process.ecalRecHit.cpu.killDeadChannels = cms.bool( False )
0161     process.ecalRecHit.cpu.recoverEBVFE = cms.bool( False )
0162     process.ecalRecHit.cpu.recoverEEVFE = cms.bool( False )
0163     process.ecalRecHit.cpu.recoverEBFE = cms.bool( False )
0164     process.ecalRecHit.cpu.recoverEEFE = cms.bool( False )
0165     process.ecalRecHit.cpu.recoverEEIsolatedChannels = cms.bool( False )
0166     process.ecalRecHit.cpu.recoverEBIsolatedChannels = cms.bool( False )
0167 
0168     if "ALCARECOStreamEcalPhiSymByRunOutPath" in process.pathNames():
0169         process.schedule.remove(process.ALCARECOStreamEcalPhiSymByRunOutPath)
0170     if "ALCARECOStreamEcalPhiSymByLumiOutPath" in process.pathNames():
0171         process.schedule.remove(process.ALCARECOStreamEcalPhiSymByLumiOutPath)
0172     process.ALCARECOStreamEcalPhiSymOutNanoPath = cms.EndPath(ecal_phisym_output(process, save_edm=False, save_edmnano=True, save_flatnano=False)[0])
0173     process.schedule.append(process.ALCARECOStreamEcalPhiSymOutNanoPath)
0174 
0175     return process