File indexing completed on 2024-11-25 02:29:06
0001 from fnmatch import fnmatch
0002 import FWCore.ParameterSet.Config as cms
0003 import FWCore.PythonUtilities.LumiList as LumiList
0004 import FWCore.Utilities.FileUtils as FileUtils
0005 from FWCore.ParameterSet.VarParsing import VarParsing
0006 from Alignment.OfflineValidation.TkAlAllInOneTool.defaultInputFiles_cff import filesDefaultMC_DoubleMuon_string
0007
0008 import sys
0009 import json
0010 import os
0011
0012
0013
0014
0015 process = cms.Process("DiMuonVertexValidation")
0016
0017
0018
0019
0020 options = VarParsing()
0021 options.register("config", "", VarParsing.multiplicity.singleton, VarParsing.varType.string , "AllInOne config")
0022
0023 options.parseArguments()
0024
0025
0026
0027
0028 if options.config == "":
0029 config = {"validation": {},
0030 "alignment": {}}
0031 else:
0032 with open(options.config, "r") as configFile:
0033 config = json.load(configFile)
0034
0035 isMC = config["validation"].get("ismc", True)
0036
0037
0038
0039
0040 readFiles = []
0041
0042 if "dataset" in config["validation"]:
0043 with open(config["validation"]["dataset"], "r") as datafiles:
0044 for fileName in datafiles.readlines():
0045 readFiles.append(fileName.replace("\n", ""))
0046
0047 process.source = cms.Source("PoolSource",
0048 fileNames = cms.untracked.vstring(readFiles),
0049 skipEvents = cms.untracked.uint32(0))
0050 else:
0051 process.source = cms.Source("PoolSource",
0052 fileNames = cms.untracked.vstring(filesDefaultMC_DoubleMuon_string),
0053 skipEvents = cms.untracked.uint32(0))
0054
0055
0056
0057
0058 if "goodlumi" in config["validation"]:
0059 if os.path.isfile(config["validation"]["goodlumi"]):
0060 goodLumiSecs = cms.untracked.VLuminosityBlockRange(LumiList.LumiList(filename = config["validation"]["goodlumi"]).getCMSSWString().split(','))
0061
0062 else:
0063 print("Does not exist: {}. Continue without good lumi section file.")
0064 goodLumiSecs = cms.untracked.VLuminosityBlockRange()
0065
0066 else:
0067 goodLumiSecs = cms.untracked.VLuminosityBlockRange()
0068
0069 if isMC:
0070 pass
0071 else:
0072 process.source.lumisToProcess = goodLumiSecs
0073
0074
0075
0076
0077 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(config["validation"].get("maxevents", 100)))
0078
0079
0080
0081
0082 process.options = cms.untracked.PSet(
0083 wantSummary = cms.untracked.bool(False),
0084 Rethrow = cms.untracked.vstring("ProductNotFound"),
0085 fileMode = cms.untracked.string('NOMERGE'),
0086 )
0087
0088
0089
0090
0091 process.load('FWCore.MessageService.MessageLogger_cfi')
0092 process.MessageLogger.cerr.enable = False
0093 process.MessageLogger.TrackRefitter=dict()
0094 process.MessageLogger.PrimaryVertexProducer=dict()
0095 process.MessageLogger.DiMuonVertexValidation=dict()
0096 process.MessageLogger.DiLeptonHelpCounts=dict()
0097 process.MessageLogger.PlotsVsKinematics=dict()
0098 process.MessageLogger.cout = cms.untracked.PSet(
0099 enable = cms.untracked.bool(True),
0100 threshold = cms.untracked.string("INFO"),
0101 default = cms.untracked.PSet(limit = cms.untracked.int32(0)),
0102 FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1),
0103 reportEvery = cms.untracked.int32(100)
0104 ),
0105 DiMuonVertexValidation = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0106 DiLeptonHelpCounts = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0107 enableStatistics = cms.untracked.bool(True)
0108 )
0109
0110
0111
0112
0113 process.load('Configuration.StandardSequences.Services_cff')
0114 process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
0115 process.load('Configuration.StandardSequences.MagneticField_AutoFromDBCurrent_cff')
0116 process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
0117
0118
0119
0120
0121 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0122 process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi')
0123 process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi')
0124 process.load('TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff')
0125
0126
0127
0128
0129 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
0130
0131
0132
0133
0134 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0135 from Configuration.AlCa.GlobalTag import GlobalTag
0136
0137 process.GlobalTag = GlobalTag(process.GlobalTag, config["alignment"].get("globaltag", "auto:phase1_2022_realistic"))
0138
0139
0140
0141
0142 if "conditions" in config["alignment"]:
0143 from CalibTracker.Configuration.Common.PoolDBESSource_cfi import poolDBESSource
0144
0145 for condition in config["alignment"]["conditions"]:
0146 setattr(process, "conditionsIn{}".format(condition), poolDBESSource.clone(
0147 connect = cms.string(str(config["alignment"]["conditions"][condition]["connect"])),
0148 toGet = cms.VPSet(
0149 cms.PSet(
0150 record = cms.string(str(condition)),
0151 tag = cms.string(str(config["alignment"]["conditions"][condition]["tag"]))
0152 )
0153 )
0154 )
0155 )
0156
0157 setattr(process, "prefer_conditionsIn{}".format(condition), cms.ESPrefer("PoolDBESSource", "conditionsIn{}".format(condition)))
0158
0159
0160
0161
0162 process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
0163 import RecoTracker.TrackProducer.TrackRefitters_cff
0164 process.refittedMuons = RecoTracker.TrackProducer.TrackRefitter_cfi.TrackRefitter.clone(
0165 src = config["validation"].get("muonTrackcollection", "ALCARECOTkAlDiMuon"),
0166 TrajectoryInEvent = True,
0167 NavigationSchool = '',
0168 TTRHBuilder = config["validation"].get("tthrbuilder", "WithAngleAndTemplate"))
0169
0170
0171
0172
0173 process.refittedVtxTracks = RecoTracker.TrackProducer.TrackRefitter_cfi.TrackRefitter.clone(
0174 src = config["validation"].get("trackcollection", "generalTracks"),
0175 TrajectoryInEvent = True,
0176 NavigationSchool = '',
0177 TTRHBuilder = config["validation"].get("tthrbuilder", "WithAngleAndTemplate"))
0178
0179
0180
0181
0182 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices
0183 process.offlinePrimaryVerticesFromRefittedTrks = offlinePrimaryVertices.clone()
0184 process.offlinePrimaryVerticesFromRefittedTrks.TrackLabel = cms.InputTag("refittedVtxTracks")
0185
0186
0187
0188
0189 process.seqRefitting = cms.Sequence(process.offlineBeamSpot +
0190 process.refittedMuons +
0191 process.refittedVtxTracks +
0192 process.offlinePrimaryVerticesFromRefittedTrks)
0193
0194
0195
0196
0197 process.TFileService = cms.Service("TFileService",
0198 fileName = cms.string("{}/DiMuonVertexValidation.root".format(config.get("output", os.getcwd()))),
0199 closeFileFast = cms.untracked.bool(True))
0200
0201
0202
0203
0204 from Alignment.OfflineValidation.diMuonVertexValidation_cfi import diMuonVertexValidation
0205 process.DiMuonVertexValidation = diMuonVertexValidation.clone(useReco = config["validation"].get("useReco",True),
0206 vertices = 'offlinePrimaryVerticesFromRefittedTrks')
0207
0208
0209
0210
0211 if (config["validation"].get("useReco",True)):
0212 print("I AM USING RECO DATA-TIER")
0213 process.DiMuonVertexValidation.muons = 'muons'
0214 process.DiMuonVertexValidation.tracks = 'refittedVtxTracks'
0215 else:
0216 print("I AM USING ALCARECO DATA-TIER")
0217 if(hasattr(process.DiMuonVertexValidation,'muons')):
0218 delattr(process.DiMuonVertexValidation,'muons')
0219 process.DiMuonVertexValidation.muonTracks = cms.InputTag('refittedMuons')
0220
0221
0222
0223
0224 process.p = cms.Path(process.seqRefitting +
0225 process.offlinePrimaryVerticesFromRefittedTrks +
0226 process.DiMuonVertexValidation)
0227
0228 print("# Done")