Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:20

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.load("RecoLocalTracker.SiPixelRecHits.SiPixelTemplateStoreESProducer_cfi")
0234      process.seqTrackselRefit = cms.Sequence(process.offlineBeamSpot*
0235                                              # in case NavigatioSchool is set !='' 
0236                                              #process.MeasurementTrackerEvent*
0237                                              process.FinalTrackRefitter,
0238                                              cms.Task(process.SiPixelTemplateStoreESProducer))
0239 
0240 ####################################################################
0241 # Output file
0242 ####################################################################
0243 process.TFileService = cms.Service("TFileService",
0244                                    fileName=cms.string("PVValidation_test_0.root")
0245                                   )
0246 
0247 ####################################################################
0248 # Imports of parameters
0249 ####################################################################
0250 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices
0251 ## modify the parameters which differ
0252 FilteringParams = offlinePrimaryVertices.TkFilterParameters.clone(
0253      maxNormalizedChi2 = 5.0,  # chi2ndof < 5
0254      maxD0Significance = 5.0,  # fake cut (requiring 1 PXB hit)
0255      maxEta = 5.0,             # as per recommendation in PR #18330
0256 )
0257 
0258 ## MM 04.05.2017 (use settings as in: https://github.com/cms-sw/cmssw/pull/18330)
0259 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import DA_vectParameters
0260 DAClusterizationParams = DA_vectParameters.clone()
0261 
0262 GapClusterizationParams = cms.PSet(algorithm   = cms.string('gap'),
0263                                    TkGapClusParameters = cms.PSet(zSeparation = cms.double(0.2))  # 0.2 cm max separation betw. clusters
0264                                    )
0265 
0266 ####################################################################
0267 # Deterministic annealing clustering or Gap clustering
0268 ####################################################################
0269 def switchClusterizerParameters(da):
0270      if da:
0271           print("############ testPVValidation_cfg.py: msg%-i: Running DA Algorithm!")
0272           return DAClusterizationParams
0273      else:
0274           print("############ testPVValidation_cfg.py: msg%-i: Running GAP Algorithm!")
0275           return GapClusterizationParams
0276 
0277 ####################################################################
0278 # Configure the PVValidation Analyzer module
0279 ####################################################################
0280 process.PVValidation = cms.EDAnalyzer("PrimaryVertexValidation",
0281                                       TrackCollectionTag = cms.InputTag("FinalTrackRefitter"),
0282                                       VertexCollectionTag = cms.InputTag("offlinePrimaryVertices"),
0283                                       Debug = cms.bool(False),
0284                                       storeNtuple = cms.bool(False),
0285                                       useTracksFromRecoVtx = cms.bool(False),
0286                                       isLightNtuple = cms.bool(True),
0287                                       askFirstLayerHit = cms.bool(False),
0288                                       forceBeamSpot = cms.untracked.bool(False),
0289                                       probePt = cms.untracked.double(3.),
0290                                       minPt   = cms.untracked.double(1.),
0291                                       maxPt   = cms.untracked.double(30.),
0292                                       runControl = cms.untracked.bool(True),
0293                                       runControlNumber = cms.untracked.vuint32(int(runboundary)),
0294                                       TkFilterParameters = FilteringParams,
0295                                       TkClusParameters = switchClusterizerParameters(isDA)
0296                                       )
0297 
0298 ####################################################################
0299 # Path
0300 ####################################################################
0301 process.p = cms.Path(process.goodvertexSkim*
0302                      process.seqTrackselRefit*
0303                      process.PVValidation)
0304 
0305 ## PV refit part
0306 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0307 process.offlinePrimaryVerticesFromRefittedTrks  = offlinePrimaryVertices.clone()
0308 process.offlinePrimaryVerticesFromRefittedTrks.TrackLabel                                       = cms.InputTag("FinalTrackRefitter")
0309 process.offlinePrimaryVerticesFromRefittedTrks.vertexCollections.maxDistanceToBeam              = 1
0310 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxNormalizedChi2             = 20
0311 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minSiliconLayersWithHits      = 5
0312 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Significance             = 5.0
0313 # as it was prior to https://github.com/cms-sw/cmssw/commit/c8462ae4313b6be3bbce36e45373aa6e87253c59
0314 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Error                    = 1.0
0315 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxDzError                    = 1.0
0316 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minPixelLayersWithHits        = 2
0317 
0318 ###################################################################
0319 # The trigger filter module
0320 ###################################################################
0321 from HLTrigger.HLTfilters.triggerResultsFilter_cfi import *
0322 process.HLTFilter = triggerResultsFilter.clone(
0323      triggerConditions = cms.vstring("HLT_ZeroBias_*"),
0324      #triggerConditions = cms.vstring("HLT_HT*"),
0325      hltResults = cms.InputTag( "TriggerResults", "", "HLT" ),
0326      l1tResults = cms.InputTag( "" ),
0327      throw = cms.bool(False)
0328 )
0329 
0330 ###################################################################
0331 # The analysis module
0332 ###################################################################
0333 process.myanalysis = cms.EDAnalyzer("GeneralPurposeTrackAnalyzer",
0334                                     TkTag  = cms.InputTag('FinalTrackRefitter'),
0335                                     isCosmics = cms.bool(False)
0336                                     )
0337 
0338 ###################################################################
0339 # The PV resolution module
0340 ###################################################################
0341 process.PrimaryVertexResolution = cms.EDAnalyzer('SplitVertexResolution',
0342                                                  storeNtuple         = cms.bool(True),
0343                                                  vtxCollection       = cms.InputTag("offlinePrimaryVerticesFromRefittedTrks"),
0344                                                  trackCollection     = cms.InputTag("FinalTrackRefitter"),
0345                                                  minVertexNdf        = cms.untracked.double(10.),
0346                                                  minVertexMeanWeight = cms.untracked.double(0.5),
0347                                                  runControl = cms.untracked.bool(True),
0348                                                  runControlNumber = cms.untracked.vuint32(int(runboundary))
0349                                                  )
0350 
0351 process.p2 = cms.Path(process.HLTFilter                               +
0352                       process.seqTrackselRefit                        +
0353                       process.offlinePrimaryVerticesFromRefittedTrks  +
0354                       process.PrimaryVertexResolution                 +
0355                       process.myanalysis
0356                       )