File indexing completed on 2024-11-06 06:06:10
0001 import sys
0002 import FWCore.ParameterSet.Config as cms
0003
0004 import FWCore.ParameterSet.VarParsing as VarParsing
0005 options = VarParsing.VarParsing()
0006 options.register("isPhase2",
0007 False,
0008 VarParsing.VarParsing.multiplicity.singleton,
0009 VarParsing.VarParsing.varType.bool,
0010 "is the test running with phase-2 geometry")
0011 options.register("maxEvents",
0012 -1,
0013 VarParsing.VarParsing.multiplicity.singleton,
0014 VarParsing.VarParsing.varType.int,
0015 "number of events to run")
0016 options.parseArguments()
0017
0018 if (options.isPhase2):
0019 from Alignment.OfflineValidation.TkAlAllInOneTool.defaultInputFiles_cff import filesDefaultMC_TTbarPhase2RECO
0020 else:
0021 from Alignment.OfflineValidation.TkAlAllInOneTool.defaultInputFiles_cff import filesDefaultMC_TTBarPU
0022
0023 from enum import Enum
0024 class RefitType(Enum):
0025 STANDARD = 1
0026 COMMON = 2
0027
0028 _isDA = True
0029 _isMC = True
0030 _allFromGT = True
0031 _applyBows = True
0032 _applyExtraConditions = True
0033 _theRefitter = RefitType.COMMON
0034 _theTrackCollection = 'generalTracks'
0035
0036
0037
0038
0039 import Configuration.Geometry.defaultPhase2ConditionsEra_cff as _settings
0040 _PH2_GLOBAL_TAG, _PH2_ERA = _settings.get_era_and_conditions(_settings.DEFAULT_VERSION)
0041
0042
0043
0044
0045 if(options.isPhase2):
0046 process = cms.Process("Demo", _PH2_ERA)
0047 else:
0048 from Configuration.Eras.Era_Run3_cff import Run3
0049 process = cms.Process("Demo", Run3)
0050
0051
0052
0053
0054 process.options.numberOfThreads = 8
0055
0056
0057
0058
0059 process.source = cms.Source("PoolSource",
0060 fileNames = (filesDefaultMC_TTbarPhase2RECO if (options.isPhase2) else filesDefaultMC_TTBarPU),
0061 duplicateCheckMode = cms.untracked.string('checkAllFilesOpened'))
0062
0063 runboundary = 1
0064 process.source.firstRun = cms.untracked.uint32(int(runboundary))
0065 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(options.maxEvents))
0066
0067
0068
0069
0070 if _isMC:
0071 print("############ testPVValidation_cfg.py: msg%-i: This is Simulation!")
0072 runboundary = 1
0073 else:
0074 print("############ testPVValidation_cfg.py: msg%-i: This is DATA!")
0075 import FWCore.PythonUtilities.LumiList as LumiList
0076 process.source.lumisToProcess = LumiList.LumiList(filename ='None').getVLuminosityBlockRange()
0077
0078
0079
0080
0081 process.load('FWCore.MessageService.MessageLogger_cfi')
0082 process.MessageLogger.cerr.enable = False
0083 process.MessageLogger.PrimaryVertexValidation=dict()
0084 process.MessageLogger.SplitVertexResolution=dict()
0085 process.MessageLogger.FilterOutLowPt=dict()
0086 process.MessageLogger.cout = cms.untracked.PSet(
0087 enable = cms.untracked.bool(True),
0088 threshold = cms.untracked.string("INFO"),
0089 default = cms.untracked.PSet(limit = cms.untracked.int32(0)),
0090 FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1),
0091 reportEvery = cms.untracked.int32(1 if (options.isPhase2) else 10)),
0092 PrimaryVertexValidation = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0093 SplitVertexResolution = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0094 FilterOutLowPt = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0095 enableStatistics = cms.untracked.bool(True)
0096 )
0097
0098
0099
0100
0101 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0102
0103
0104
0105
0106 process.load('Configuration.StandardSequences.MagneticField_cff')
0107
0108
0109
0110
0111 if(options.isPhase2):
0112 process.load('Configuration.Geometry.GeometryExtendedRun4DefaultReco_cff')
0113 else:
0114 process.load("Configuration.Geometry.GeometryRecoDB_cff")
0115
0116
0117
0118
0119 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
0120
0121
0122
0123
0124 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0125 from Configuration.AlCa.GlobalTag import GlobalTag
0126 process.GlobalTag = GlobalTag(process.GlobalTag, (_PH2_GLOBAL_TAG if options.isPhase2 else 'auto:phase1_2022_realistic'), '')
0127
0128 if _allFromGT:
0129 print("############ testPVValidation_cfg.py: msg%-i: All is taken from GT")
0130 else:
0131 if(options.isPhase2):
0132 print("########## overriding of phase-2 alignment conditions is not yet supported")
0133 pass
0134 else:
0135
0136
0137
0138 from CondCore.DBCommon.CondDBSetup_cfi import *
0139 process.trackerAlignment = cms.ESSource("PoolDBESSource",CondDBSetup,
0140 connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'),
0141 timetype = cms.string("runnumber"),
0142 toGet = cms.VPSet(cms.PSet(record = cms.string('TrackerAlignmentRcd'),
0143 tag = cms.string('TrackerAlignment_Upgrade2017_design_v4')
0144 )
0145 )
0146 )
0147 process.es_prefer_trackerAlignment = cms.ESPrefer("PoolDBESSource", "trackerAlignment")
0148
0149
0150
0151
0152 process.setAPE = cms.ESSource("PoolDBESSource",CondDBSetup,
0153 connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'),
0154 timetype = cms.string("runnumber"),
0155 toGet = cms.VPSet(cms.PSet(record = cms.string('TrackerAlignmentErrorExtendedRcd'),
0156 tag = cms.string('TrackerAlignmentErrorsExtended_Upgrade2017_design_v0')
0157 )
0158 )
0159 )
0160 process.es_prefer_setAPE = cms.ESPrefer("PoolDBESSource", "setAPE")
0161
0162
0163
0164
0165 if _applyBows:
0166 print("############ testPVValidation_cfg.py: msg%-i: Applying TrackerSurfaceDeformations!")
0167 process.trackerBows = cms.ESSource("PoolDBESSource",CondDBSetup,
0168 connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'),
0169 toGet = cms.VPSet(cms.PSet(record = cms.string('TrackerSurfaceDeformationRcd'),
0170 tag = cms.string('TrackerSurfaceDeformations_zero')
0171 )
0172 )
0173 )
0174 process.es_prefer_Bows = cms.ESPrefer("PoolDBESSource", "trackerBows")
0175 else:
0176 print("############ testPVValidation_cfg.py: msg%-i: MultiPVValidation: Not applying TrackerSurfaceDeformations!")
0177
0178
0179
0180
0181 if _applyExtraConditions:
0182
0183 import CalibTracker.Configuration.Common.PoolDBESSource_cfi
0184
0185
0186 else:
0187 print("############ testPVValidation_cfg.py: msg%-i: Not applying extra calibration constants!")
0188
0189
0190
0191
0192 process.primaryVertexFilter = cms.EDFilter("VertexSelector",
0193 src = cms.InputTag("offlinePrimaryVertices"),
0194 cut = cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"),
0195 filter = cms.bool(True)
0196 )
0197
0198 process.noscraping = cms.EDFilter("FilterOutScraping",
0199 applyfilter = cms.untracked.bool(True),
0200 src = cms.untracked.InputTag(_theTrackCollection),
0201 debugOn = cms.untracked.bool(False),
0202 numtrack = cms.untracked.uint32(10),
0203 thresh = cms.untracked.double(0.25)
0204 )
0205
0206 process.noslowpt = cms.EDFilter("FilterOutLowPt",
0207 applyfilter = cms.untracked.bool(True),
0208 src = cms.untracked.InputTag(_theTrackCollection),
0209 debugOn = cms.untracked.bool(False),
0210 numtrack = cms.untracked.uint32(0),
0211 thresh = cms.untracked.int32(1),
0212 ptmin = cms.untracked.double(3.),
0213 runControl = cms.untracked.bool(True),
0214 runControlNumber = cms.untracked.vuint32(int(runboundary))
0215 )
0216
0217 if _isMC:
0218 process.goodvertexSkim = cms.Sequence(process.noscraping)
0219 else:
0220 process.goodvertexSkim = cms.Sequence(process.primaryVertexFilter + process.noscraping + process.noslowpt)
0221
0222
0223 if(_theRefitter == RefitType.COMMON):
0224
0225 print("############ testPVValidation_cfg.py: msg%-i: using the common track selection and refit sequence!")
0226
0227
0228
0229 import Alignment.CommonAlignment.tools.trackselectionRefitting as trackselRefit
0230 process.seqTrackselRefit = trackselRefit.getSequence(process, _theTrackCollection,
0231 isPVValidation=True,
0232 TTRHBuilder='WithAngleAndTemplate',
0233 usePixelQualityFlag=True,
0234 openMassWindow=False,
0235 cosmicsDecoMode=True,
0236 cosmicsZeroTesla=False,
0237 momentumConstraint=None,
0238 cosmicTrackSplitting=False,
0239 use_d0cut=False,
0240 )
0241
0242 elif (_theRefitter == RefitType.STANDARD):
0243
0244 print("############ testPVValidation_cfg.py: msg%-i: using the standard single refit sequence!")
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258 process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
0259 import RecoTracker.TrackProducer.TrackRefitters_cff
0260 process.FinalTrackRefitter = RecoTracker.TrackProducer.TrackRefitter_cfi.TrackRefitter.clone()
0261 process.FinalTrackRefitter.src = _theTrackCollection
0262 process.FinalTrackRefitter.TrajectoryInEvent = True
0263 process.FinalTrackRefitter.NavigationSchool = ''
0264 process.FinalTrackRefitter.TTRHBuilder = "WithAngleAndTemplate"
0265
0266
0267
0268
0269 process.seqTrackselRefit = cms.Sequence(process.offlineBeamSpot*
0270
0271
0272 process.FinalTrackRefitter)
0273
0274
0275
0276
0277 process.TFileService = cms.Service("TFileService",
0278 fileName=cms.string("PVValidation_test_0.root")
0279 )
0280
0281
0282
0283
0284 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices
0285
0286 FilteringParams = offlinePrimaryVertices.TkFilterParameters.clone(
0287 maxNormalizedChi2 = 5.0,
0288 maxD0Significance = 5.0,
0289 maxEta = 5.0,
0290 )
0291
0292
0293 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import DA_vectParameters
0294 DAClusterizationParams = DA_vectParameters.clone()
0295
0296 GapClusterizationParams = cms.PSet(algorithm = cms.string('gap'),
0297 TkGapClusParameters = cms.PSet(zSeparation = cms.double(0.2))
0298 )
0299
0300
0301
0302
0303 def switchClusterizerParameters(da):
0304 if da:
0305 print("############ testPVValidation_cfg.py: msg%-i: Running DA Algorithm!")
0306 return DAClusterizationParams
0307 else:
0308 print("############ testPVValidation_cfg.py: msg%-i: Running GAP Algorithm!")
0309 return GapClusterizationParams
0310
0311
0312
0313
0314 from prettytable import PrettyTable
0315 x = PrettyTable()
0316 x.field_names = ["Parameter","Value"]
0317 x.add_row(["is DA",_isDA])
0318 x.add_row(["is MC",_isMC])
0319 x.add_row(["applyBows",_applyBows])
0320 x.add_row(["all from GT",_allFromGT])
0321 x.add_row(["extra conditions",_applyExtraConditions])
0322 x.add_row(["refitter type",_theRefitter])
0323 x.add_row(["track collection",_theTrackCollection])
0324 x.add_row(["GlobalTag",process.GlobalTag.globaltag.value()])
0325 x.add_row(["# events",options.maxEvents])
0326 print(x)
0327
0328
0329
0330
0331 process.PVValidation = cms.EDAnalyzer("PrimaryVertexValidation",
0332 TrackCollectionTag = cms.InputTag("FinalTrackRefitter"),
0333 VertexCollectionTag = cms.InputTag("offlinePrimaryVertices"),
0334 Debug = cms.bool(False),
0335 storeNtuple = cms.bool(False),
0336 useTracksFromRecoVtx = cms.bool(False),
0337 isLightNtuple = cms.bool(True),
0338 askFirstLayerHit = cms.bool(False),
0339 forceBeamSpot = cms.untracked.bool(False),
0340 probePt = cms.untracked.double(3.),
0341 minPt = cms.untracked.double(1.),
0342 maxPt = cms.untracked.double(30.),
0343 runControl = cms.untracked.bool(True),
0344 runControlNumber = cms.untracked.vuint32(int(runboundary)),
0345 TkFilterParameters = FilteringParams,
0346 TkClusParameters = switchClusterizerParameters(_isDA)
0347 )
0348
0349
0350
0351
0352 process.p = cms.Path(process.goodvertexSkim*
0353 process.seqTrackselRefit*
0354 process.PVValidation)
0355
0356
0357 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0358 process.offlinePrimaryVerticesFromRefittedTrks = offlinePrimaryVertices.clone()
0359 process.offlinePrimaryVerticesFromRefittedTrks.TrackLabel = cms.InputTag("FinalTrackRefitter")
0360 process.offlinePrimaryVerticesFromRefittedTrks.vertexCollections.maxDistanceToBeam = 1
0361 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxNormalizedChi2 = 20
0362 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minSiliconLayersWithHits = 5
0363 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Significance = 5.0
0364
0365 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Error = 1.0
0366 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxDzError = 1.0
0367 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minPixelLayersWithHits = 2
0368
0369
0370
0371
0372 from HLTrigger.HLTfilters.triggerResultsFilter_cfi import *
0373 process.HLTFilter = triggerResultsFilter.clone(
0374 triggerConditions = cms.vstring("HLT_ZeroBias_*"),
0375
0376 hltResults = cms.InputTag( "TriggerResults", "", "HLT" ),
0377 l1tResults = cms.InputTag( "" ),
0378 throw = cms.bool(False)
0379 )
0380
0381
0382
0383
0384 process.trackanalysis = cms.EDAnalyzer("GeneralPurposeTrackAnalyzer",
0385 TkTag = cms.InputTag('FinalTrackRefitter'),
0386 isCosmics = cms.bool(False))
0387
0388 process.vertexanalysis = cms.EDAnalyzer('GeneralPurposeVertexAnalyzer',
0389 ndof = cms.int32(4),
0390 vertexLabel = cms.InputTag('offlinePrimaryVerticesFromRefittedTrks'),
0391 beamSpotLabel = cms.InputTag('offlineBeamSpot'),
0392 Xpos = cms.double(0.1),
0393 Ypos = cms.double(0),
0394 TkSizeBin = cms.int32(100),
0395 TkSizeMin = cms.double(499.5),
0396 TkSizeMax = cms.double(-0.5),
0397 DxyBin = cms.int32(100),
0398 DxyMin = cms.double(5000),
0399 DxyMax = cms.double(-5000),
0400 DzBin = cms.int32(100),
0401 DzMin = cms.double(-2000),
0402 DzMax = cms.double(2000),
0403 PhiBin = cms.int32(32),
0404 PhiBin2D = cms.int32(12),
0405 PhiMin = cms.double(-3.1415926535897931),
0406 PhiMax = cms.double(3.1415926535897931),
0407 EtaBin = cms.int32(26),
0408 EtaBin2D = cms.int32(8),
0409 EtaMin = cms.double(-2.7),
0410 EtaMax = cms.double(2.7))
0411
0412
0413
0414
0415 process.PrimaryVertexResolution = cms.EDAnalyzer('SplitVertexResolution',
0416 storeNtuple = cms.bool(True),
0417 vtxCollection = cms.InputTag("offlinePrimaryVerticesFromRefittedTrks"),
0418 trackCollection = cms.InputTag("FinalTrackRefitter"),
0419 minVertexNdf = cms.untracked.double(10.),
0420 minVertexMeanWeight = cms.untracked.double(0.5),
0421 runControl = cms.untracked.bool(True),
0422 runControlNumber = cms.untracked.vuint32(int(runboundary))
0423 )
0424
0425 process.p2 = cms.Path(process.HLTFilter +
0426 process.seqTrackselRefit +
0427 process.offlinePrimaryVerticesFromRefittedTrks +
0428 process.PrimaryVertexResolution +
0429 process.trackanalysis +
0430 process.vertexanalysis
0431 )