Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-01-20 05:48:19

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