Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-23 02:55:00

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 # RefitType.STANDARD (other option not involving filtering)
0034 _theTrackCollection = 'generalTracks' # FIXME: 'ALCARECOTkAlMinBias' once a sample is available
0035 
0036 ###################################################################
0037 # Set the era
0038 ###################################################################
0039 if(options.isPhase2):
0040      from Configuration.Eras.Era_Phase2C17I13M9_cff import Phase2C17I13M9
0041      process = cms.Process("Demo",Phase2C17I13M9) 
0042 else:
0043      from Configuration.Eras.Era_Run3_cff import Run3
0044      process = cms.Process("Demo", Run3)
0045      
0046 ###################################################################
0047 # Set the process to run multi-threaded
0048 ###################################################################
0049 process.options.numberOfThreads = 8
0050 
0051 ###################################################################
0052 # Event source and run selection
0053 ###################################################################
0054 process.source = cms.Source("PoolSource",
0055                             fileNames = (filesDefaultMC_TTbarPhase2RECO if (options.isPhase2) else filesDefaultMC_TTBarPU),
0056                             duplicateCheckMode = cms.untracked.string('checkAllFilesOpened'))
0057 
0058 runboundary = 1
0059 process.source.firstRun = cms.untracked.uint32(int(runboundary))
0060 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(options.maxEvents))  #(10 if (options.isPhase2) else 100)
0061 
0062 ###################################################################
0063 # JSON Filtering
0064 ###################################################################
0065 if _isMC:
0066      print("############ testPVValidation_cfg.py: msg%-i: This is Simulation!")
0067      runboundary = 1
0068 else:
0069      print("############ testPVValidation_cfg.py: msg%-i: This is DATA!")
0070      import FWCore.PythonUtilities.LumiList as LumiList
0071      process.source.lumisToProcess = LumiList.LumiList(filename ='None').getVLuminosityBlockRange()
0072 
0073 ###################################################################
0074 # Messages
0075 ###################################################################
0076 process.load('FWCore.MessageService.MessageLogger_cfi')   
0077 process.MessageLogger.cerr.enable = False
0078 process.MessageLogger.PrimaryVertexValidation=dict()  
0079 process.MessageLogger.SplitVertexResolution=dict()
0080 process.MessageLogger.FilterOutLowPt=dict()  
0081 process.MessageLogger.cout = cms.untracked.PSet(
0082     enable = cms.untracked.bool(True),
0083     threshold = cms.untracked.string("INFO"),
0084     default   = cms.untracked.PSet(limit = cms.untracked.int32(0)),                       
0085     FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1),
0086                                    reportEvery = cms.untracked.int32(1 if (options.isPhase2) else 10)),                                                      
0087     PrimaryVertexValidation = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0088     SplitVertexResolution   = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0089     FilterOutLowPt          = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0090     enableStatistics = cms.untracked.bool(True)
0091     )
0092 
0093 ####################################################################
0094 # Produce the Transient Track Record in the event
0095 ####################################################################
0096 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0097 
0098 ####################################################################
0099 # Get the Magnetic Field
0100 ####################################################################
0101 process.load('Configuration.StandardSequences.MagneticField_cff')
0102 
0103 ###################################################################
0104 # Standard loads
0105 ###################################################################
0106 if(options.isPhase2):
0107      process.load('Configuration.Geometry.GeometryExtended2026D88Reco_cff')
0108 else:
0109      process.load("Configuration.Geometry.GeometryRecoDB_cff")
0110 
0111 ####################################################################
0112 # Get the BeamSpot
0113 ####################################################################
0114 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
0115 
0116 ####################################################################
0117 # Get the GlogalTag
0118 ####################################################################
0119 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0120 from Configuration.AlCa.GlobalTag import GlobalTag
0121 process.GlobalTag = GlobalTag(process.GlobalTag, ('auto:phase2_realistic_T21' if options.isPhase2 else 'auto:phase1_2022_realistic'), '')
0122 
0123 if _allFromGT:
0124      print("############ testPVValidation_cfg.py: msg%-i: All is taken from GT")
0125 else:
0126      if(options.isPhase2):
0127           print("########## overriding of phase-2 alignment conditions is not yet supported")
0128           pass
0129      else:
0130           ####################################################################
0131           # Get Alignment constants
0132           ####################################################################
0133           from CondCore.DBCommon.CondDBSetup_cfi import *
0134           process.trackerAlignment = cms.ESSource("PoolDBESSource",CondDBSetup,
0135                                                   connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'),
0136                                                   timetype = cms.string("runnumber"),
0137                                                   toGet = cms.VPSet(cms.PSet(record = cms.string('TrackerAlignmentRcd'),
0138                                                                              tag = cms.string('TrackerAlignment_Upgrade2017_design_v4')
0139                                                                         )
0140                                                                )
0141                                              )
0142           process.es_prefer_trackerAlignment = cms.ESPrefer("PoolDBESSource", "trackerAlignment")
0143 
0144           ####################################################################
0145           # Get APE
0146           ####################################################################
0147           process.setAPE = cms.ESSource("PoolDBESSource",CondDBSetup,
0148                                         connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'),
0149                                         timetype = cms.string("runnumber"),
0150                                         toGet = cms.VPSet(cms.PSet(record = cms.string('TrackerAlignmentErrorExtendedRcd'),
0151                                                                    tag = cms.string('TrackerAlignmentErrorsExtended_Upgrade2017_design_v0')
0152                                                               )
0153                                                      )
0154                                    )
0155           process.es_prefer_setAPE = cms.ESPrefer("PoolDBESSource", "setAPE")
0156 
0157           ####################################################################
0158           # Kinks and Bows (optional)
0159           ####################################################################
0160           if _applyBows:
0161                print("############ testPVValidation_cfg.py: msg%-i: Applying TrackerSurfaceDeformations!")
0162                process.trackerBows = cms.ESSource("PoolDBESSource",CondDBSetup,
0163                                                   connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'),
0164                                                   toGet = cms.VPSet(cms.PSet(record = cms.string('TrackerSurfaceDeformationRcd'),
0165                                                                              tag = cms.string('TrackerSurfaceDeformations_zero')
0166                                                                         )
0167                                                                )
0168                                              )
0169                process.es_prefer_Bows = cms.ESPrefer("PoolDBESSource", "trackerBows")
0170           else:
0171                print("############ testPVValidation_cfg.py: msg%-i: MultiPVValidation: Not applying TrackerSurfaceDeformations!")
0172 
0173      ####################################################################
0174      # Extra corrections not included in the GT
0175      ####################################################################
0176      if _applyExtraConditions:
0177 
0178           import CalibTracker.Configuration.Common.PoolDBESSource_cfi
0179           ##### END OF EXTRA CONDITIONS
0180  
0181      else:
0182           print("############ testPVValidation_cfg.py: msg%-i: Not applying extra calibration constants!")
0183      
0184 ####################################################################
0185 # Load and Configure event selection
0186 ####################################################################
0187 process.primaryVertexFilter = cms.EDFilter("VertexSelector",
0188                                              src = cms.InputTag("offlinePrimaryVertices"),
0189                                              cut = cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"),
0190                                              filter = cms.bool(True)
0191                                              )
0192 
0193 process.noscraping = cms.EDFilter("FilterOutScraping",
0194                                   applyfilter = cms.untracked.bool(True),
0195                                   src =  cms.untracked.InputTag(_theTrackCollection),
0196                                   debugOn = cms.untracked.bool(False),
0197                                   numtrack = cms.untracked.uint32(10),
0198                                   thresh = cms.untracked.double(0.25)
0199                                   )
0200 
0201 process.noslowpt = cms.EDFilter("FilterOutLowPt",
0202                                 applyfilter = cms.untracked.bool(True),
0203                                 src =  cms.untracked.InputTag(_theTrackCollection),
0204                                 debugOn = cms.untracked.bool(False),
0205                                 numtrack = cms.untracked.uint32(0),
0206                                 thresh = cms.untracked.int32(1),
0207                                 ptmin  = cms.untracked.double(3.),
0208                                 runControl = cms.untracked.bool(True),
0209                                 runControlNumber = cms.untracked.vuint32(int(runboundary))
0210                                 )
0211 
0212 if _isMC:
0213      process.goodvertexSkim = cms.Sequence(process.noscraping)
0214 else:
0215      process.goodvertexSkim = cms.Sequence(process.primaryVertexFilter + process.noscraping + process.noslowpt)
0216 
0217 
0218 if(_theRefitter == RefitType.COMMON):
0219 
0220      print("############ testPVValidation_cfg.py: msg%-i: using the common track selection and refit sequence!")
0221      ####################################################################
0222      # Load and Configure Common Track Selection and refitting sequence
0223      ####################################################################
0224      import Alignment.CommonAlignment.tools.trackselectionRefitting as trackselRefit
0225      process.seqTrackselRefit = trackselRefit.getSequence(process, _theTrackCollection,
0226                                                           isPVValidation=True, 
0227                                                           TTRHBuilder='WithAngleAndTemplate',
0228                                                           usePixelQualityFlag=True,
0229                                                           openMassWindow=False,
0230                                                           cosmicsDecoMode=True,
0231                                                           cosmicsZeroTesla=False,
0232                                                           momentumConstraint=None,
0233                                                           cosmicTrackSplitting=False,
0234                                                           use_d0cut=False,
0235                                                           )
0236      
0237 elif (_theRefitter == RefitType.STANDARD):
0238 
0239      print("############ testPVValidation_cfg.py: msg%-i: using the standard single refit sequence!")
0240      ####################################################################
0241      # Load and Configure Measurement Tracker Event
0242      # (needed in case NavigationSchool is set != '')
0243      ####################################################################
0244      # process.load("RecoTracker.MeasurementDet.MeasurementTrackerEventProducer_cfi") 
0245      # process.MeasurementTrackerEvent.pixelClusterProducer = '_theTrackCollection'
0246      # process.MeasurementTrackerEvent.stripClusterProducer = '_theTrackCollection'
0247      # process.MeasurementTrackerEvent.inactivePixelDetectorLabels = cms.VInputTag()
0248      # process.MeasurementTrackerEvent.inactiveStripDetectorLabels = cms.VInputTag()
0249 
0250      ####################################################################
0251      # Load and Configure TrackRefitter
0252      ####################################################################
0253      process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
0254      import RecoTracker.TrackProducer.TrackRefitters_cff
0255      process.FinalTrackRefitter = RecoTracker.TrackProducer.TrackRefitter_cfi.TrackRefitter.clone()
0256      process.FinalTrackRefitter.src = _theTrackCollection
0257      process.FinalTrackRefitter.TrajectoryInEvent = True
0258      process.FinalTrackRefitter.NavigationSchool = ''
0259      process.FinalTrackRefitter.TTRHBuilder = "WithAngleAndTemplate"
0260 
0261      ####################################################################
0262      # Sequence
0263      ####################################################################
0264      process.seqTrackselRefit = cms.Sequence(process.offlineBeamSpot*
0265                                              # in case NavigatioSchool is set !='' 
0266                                              #process.MeasurementTrackerEvent*
0267                                              process.FinalTrackRefitter)     
0268 
0269 ####################################################################
0270 # Output file
0271 ####################################################################
0272 process.TFileService = cms.Service("TFileService",
0273                                    fileName=cms.string("PVValidation_test_0.root")
0274                                   )
0275 
0276 ####################################################################
0277 # Imports of parameters
0278 ####################################################################
0279 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices
0280 ## modify the parameters which differ
0281 FilteringParams = offlinePrimaryVertices.TkFilterParameters.clone(
0282      maxNormalizedChi2 = 5.0,  # chi2ndof < 5
0283      maxD0Significance = 5.0,  # fake cut (requiring 1 PXB hit)
0284      maxEta = 5.0,             # as per recommendation in PR #18330
0285 )
0286 
0287 ## MM 04.05.2017 (use settings as in: https://github.com/cms-sw/cmssw/pull/18330)
0288 from RecoVertex.PrimaryVertexProducer.TkClusParameters_cff import DA_vectParameters
0289 DAClusterizationParams = DA_vectParameters.clone()
0290 
0291 GapClusterizationParams = cms.PSet(algorithm   = cms.string('gap'),
0292                                    TkGapClusParameters = cms.PSet(zSeparation = cms.double(0.2))  # 0.2 cm max separation betw. clusters
0293                                    )
0294 
0295 ####################################################################
0296 # Deterministic annealing clustering or Gap clustering
0297 ####################################################################
0298 def switchClusterizerParameters(da):
0299      if da:
0300           print("############ testPVValidation_cfg.py: msg%-i: Running DA Algorithm!")
0301           return DAClusterizationParams
0302      else:
0303           print("############ testPVValidation_cfg.py: msg%-i: Running GAP Algorithm!")
0304           return GapClusterizationParams
0305 
0306 ####################################################################
0307 # Print table of execution parameters
0308 ####################################################################
0309 from prettytable import PrettyTable
0310 x = PrettyTable()
0311 x.field_names = ["Parameter","Value"]
0312 x.add_row(["is DA",_isDA])
0313 x.add_row(["is MC",_isMC])
0314 x.add_row(["applyBows",_applyBows])
0315 x.add_row(["all from GT",_allFromGT])
0316 x.add_row(["extra conditions",_applyExtraConditions])
0317 x.add_row(["refitter type",_theRefitter])
0318 x.add_row(["track collection",_theTrackCollection])
0319 x.add_row(["GlobalTag",process.GlobalTag.globaltag.value()])
0320 x.add_row(["# events",options.maxEvents])
0321 print(x)
0322 
0323 ####################################################################
0324 # Configure the PVValidation Analyzer module
0325 ####################################################################
0326 process.PVValidation = cms.EDAnalyzer("PrimaryVertexValidation",
0327                                       TrackCollectionTag = cms.InputTag("FinalTrackRefitter"),
0328                                       VertexCollectionTag = cms.InputTag("offlinePrimaryVertices"),
0329                                       Debug = cms.bool(False),
0330                                       storeNtuple = cms.bool(False),
0331                                       useTracksFromRecoVtx = cms.bool(False),
0332                                       isLightNtuple = cms.bool(True),
0333                                       askFirstLayerHit = cms.bool(False),
0334                                       forceBeamSpot = cms.untracked.bool(False),
0335                                       probePt = cms.untracked.double(3.),
0336                                       minPt   = cms.untracked.double(1.),
0337                                       maxPt   = cms.untracked.double(30.),
0338                                       runControl = cms.untracked.bool(True),
0339                                       runControlNumber = cms.untracked.vuint32(int(runboundary)),
0340                                       TkFilterParameters = FilteringParams,
0341                                       TkClusParameters = switchClusterizerParameters(_isDA)
0342                                       )
0343 
0344 ####################################################################
0345 # Path
0346 ####################################################################
0347 process.p = cms.Path(process.goodvertexSkim*
0348                      process.seqTrackselRefit*
0349                      process.PVValidation)
0350 
0351 ## PV refit part
0352 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0353 process.offlinePrimaryVerticesFromRefittedTrks  = offlinePrimaryVertices.clone()
0354 process.offlinePrimaryVerticesFromRefittedTrks.TrackLabel                                       = cms.InputTag("FinalTrackRefitter")
0355 process.offlinePrimaryVerticesFromRefittedTrks.vertexCollections.maxDistanceToBeam              = 1
0356 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxNormalizedChi2             = 20
0357 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minSiliconLayersWithHits      = 5
0358 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Significance             = 5.0
0359 # as it was prior to https://github.com/cms-sw/cmssw/commit/c8462ae4313b6be3bbce36e45373aa6e87253c59
0360 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Error                    = 1.0
0361 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxDzError                    = 1.0
0362 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minPixelLayersWithHits        = 2
0363 
0364 ###################################################################
0365 # The trigger filter module
0366 ###################################################################
0367 from HLTrigger.HLTfilters.triggerResultsFilter_cfi import *
0368 process.HLTFilter = triggerResultsFilter.clone(
0369      triggerConditions = cms.vstring("HLT_ZeroBias_*"),
0370      #triggerConditions = cms.vstring("HLT_HT*"),
0371      hltResults = cms.InputTag( "TriggerResults", "", "HLT" ),
0372      l1tResults = cms.InputTag( "" ),
0373      throw = cms.bool(False)
0374 )
0375 
0376 ###################################################################
0377 # The analysis module
0378 ###################################################################
0379 process.myanalysis = cms.EDAnalyzer("GeneralPurposeTrackAnalyzer",
0380                                     TkTag  = cms.InputTag('FinalTrackRefitter'),
0381                                     isCosmics = cms.bool(False)
0382                                     )
0383 
0384 ###################################################################
0385 # The PV resolution module
0386 ###################################################################
0387 process.PrimaryVertexResolution = cms.EDAnalyzer('SplitVertexResolution',
0388                                                  storeNtuple         = cms.bool(True),
0389                                                  vtxCollection       = cms.InputTag("offlinePrimaryVerticesFromRefittedTrks"),
0390                                                  trackCollection     = cms.InputTag("FinalTrackRefitter"),
0391                                                  minVertexNdf        = cms.untracked.double(10.),
0392                                                  minVertexMeanWeight = cms.untracked.double(0.5),
0393                                                  runControl = cms.untracked.bool(True),
0394                                                  runControlNumber = cms.untracked.vuint32(int(runboundary))
0395                                                  )
0396 
0397 process.p2 = cms.Path(process.HLTFilter                               +
0398                       process.seqTrackselRefit                        +
0399                       process.offlinePrimaryVerticesFromRefittedTrks  +
0400                       process.PrimaryVertexResolution                 +
0401                       process.myanalysis
0402                       )