Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-17 02:41:46

0001 import FWCore.ParameterSet.Config as cms
0002 import sys
0003 from enum import Enum
0004 from Alignment.OfflineValidation.TkAlAllInOneTool.defaultInputFiles_cff import filesDefaultMC_MinBiasPUPhase2RECO
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" unfortunately not yet
0017 
0018 from Configuration.Eras.Era_Phase2C17I13M9_cff import Phase2C17I13M9
0019 process = cms.Process("Demo",Phase2C17I13M9) 
0020 
0021 ###################################################################
0022 # Set the process to run multi-threaded
0023 ###################################################################
0024 process.options.numberOfThreads = 8
0025 
0026 ###################################################################
0027 # Event source and run selection
0028 ###################################################################
0029 process.source = cms.Source("PoolSource",
0030                             fileNames = filesDefaultMC_MinBiasPUPhase2RECO,
0031                             duplicateCheckMode = cms.untracked.string('checkAllFilesOpened')
0032                             )
0033 
0034 runboundary = 1
0035 process.source.firstRun = cms.untracked.uint32(int(runboundary))
0036 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(100) )
0037 
0038 ###################################################################
0039 # JSON Filtering
0040 ###################################################################
0041 if isMC:
0042      print("############ testPVValidation_cfg.py: msg%-i: This is Simulation!")
0043      runboundary = 1
0044 else:
0045      print("############ testPVValidation_cfg.py: msg%-i: This is DATA!")
0046      import FWCore.PythonUtilities.LumiList as LumiList
0047      process.source.lumisToProcess = LumiList.LumiList(filename ='None').getVLuminosityBlockRange()
0048 
0049 ###################################################################
0050 # Messages
0051 ###################################################################
0052 process.load('FWCore.MessageService.MessageLogger_cfi')   
0053 process.MessageLogger.cerr.enable = False
0054 process.MessageLogger.PrimaryVertexValidation=dict()  
0055 process.MessageLogger.SplitVertexResolution=dict()
0056 process.MessageLogger.FilterOutLowPt=dict()  
0057 process.MessageLogger.cout = cms.untracked.PSet(
0058     enable = cms.untracked.bool(True),
0059     threshold = cms.untracked.string("INFO"),
0060     default   = cms.untracked.PSet(limit = cms.untracked.int32(0)),                       
0061     FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1),
0062                                    reportEvery = cms.untracked.int32(1)
0063                                    ),                                                      
0064     PrimaryVertexValidation = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0065     SplitVertexResolution   = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0066     FilterOutLowPt          = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0067     enableStatistics = cms.untracked.bool(True)
0068     )
0069 
0070 ####################################################################
0071 # Produce the Transient Track Record in the event
0072 ####################################################################
0073 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0074 
0075 ####################################################################
0076 # Get the Magnetic Field
0077 ####################################################################
0078 process.load('Configuration.StandardSequences.MagneticField_cff')
0079 
0080 ###################################################################
0081 # Standard loads
0082 ###################################################################
0083 #process.load("Configuration.Geometry.GeometryRecoDB_cff")
0084 process.load('Configuration.Geometry.GeometryExtendedRun4D110Reco_cff')
0085 
0086 ####################################################################
0087 # Get the BeamSpot
0088 ####################################################################
0089 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
0090 
0091 ####################################################################
0092 # Get the GlogalTag
0093 ####################################################################
0094 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0095 from Configuration.AlCa.GlobalTag import GlobalTag
0096 process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic', '')
0097 
0098 if allFromGT:
0099      print("############ testPVValidation_cfg.py: msg%-i: All is taken from GT")
0100 else:
0101      ####################################################################
0102      # Get Alignment constants
0103      ####################################################################
0104      from CondCore.DBCommon.CondDBSetup_cfi import *
0105      process.trackerAlignment = cms.ESSource("PoolDBESSource",CondDBSetup,
0106                                              connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'),
0107                                              toGet = cms.VPSet(cms.PSet(record = cms.string('TrackerAlignmentRcd'),
0108                                                                         tag = cms.string('TrackerAlignment_Upgrade2017_design_v4')
0109                                                                         )
0110                                                                )
0111                                              )
0112      process.es_prefer_trackerAlignment = cms.ESPrefer("PoolDBESSource", "trackerAlignment")
0113 
0114      ####################################################################
0115      # Get APE
0116      ####################################################################
0117      process.setAPE = cms.ESSource("PoolDBESSource",CondDBSetup,
0118                                    connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'),
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 ####################################################################
0182 # BeamSpot check
0183 ####################################################################
0184 from RecoVertex.BeamSpotProducer.beamSpotCompatibilityChecker_cfi import beamSpotCompatibilityChecker
0185 process.BeamSpotChecker = beamSpotCompatibilityChecker.clone(
0186     bsFromEvent = "offlineBeamSpot::RECO",  # source of the event beamspot (in the ALCARECO files)
0187     bsFromDB = "offlineBeamSpot",           # source of the DB beamspot (from Global Tag) NOTE: only if dbFromEvent is True!
0188     warningThr = 3, # significance threshold to emit a warning message
0189     errorThr = 5,    # significance threshold to abort the job
0190 )
0191 
0192 if isMC:
0193      process.goodvertexSkim = cms.Sequence(process.BeamSpotChecker + process.noscraping)
0194 else:
0195      process.goodvertexSkim = cms.Sequence(process.BeamSpotChecker + process.primaryVertexFilter + process.noscraping + process.noslowpt)
0196 
0197 
0198 if(theRefitter == RefitType.COMMON):
0199 
0200      print("############ testPVValidation_cfg.py: msg%-i: using the common track selection and refit sequence!")
0201      ####################################################################
0202      # Load and Configure Common Track Selection and refitting sequence
0203      ####################################################################
0204      import Alignment.CommonAlignment.tools.trackselectionRefitting as trackselRefit
0205      process.seqTrackselRefit = trackselRefit.getSequence(process, _theTrackCollection ,
0206                                                           isPVValidation=True, 
0207                                                           TTRHBuilder='WithAngleAndTemplate',
0208                                                           usePixelQualityFlag=True,
0209                                                           openMassWindow=False,
0210                                                           cosmicsDecoMode=True,
0211                                                           cosmicsZeroTesla=False,
0212                                                           momentumConstraint=None,
0213                                                           cosmicTrackSplitting=False,
0214                                                           use_d0cut=False,
0215                                                           )
0216      
0217 elif (theRefitter == RefitType.STANDARD):
0218 
0219      print("############ testPVValidation_cfg.py: msg%-i: using the standard single refit sequence!")
0220      ####################################################################
0221      # Load and Configure Measurement Tracker Event
0222      # (needed in case NavigationSchool is set != '')
0223      ####################################################################
0224      # process.load("RecoTracker.MeasurementDet.MeasurementTrackerEventProducer_cfi") 
0225      # process.MeasurementTrackerEvent.pixelClusterProducer = 'ALCARECOTkAlMinBias'
0226      # process.MeasurementTrackerEvent.stripClusterProducer = 'ALCARECOTkAlMinBias'
0227      # process.MeasurementTrackerEvent.inactivePixelDetectorLabels = cms.VInputTag()
0228      # process.MeasurementTrackerEvent.inactiveStripDetectorLabels = cms.VInputTag()
0229 
0230      ####################################################################
0231      # Load and Configure TrackRefitter
0232      ####################################################################
0233      process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
0234      import RecoTracker.TrackProducer.TrackRefitters_cff
0235      process.FinalTrackRefitter = RecoTracker.TrackProducer.TrackRefitter_cfi.TrackRefitter.clone()
0236      process.FinalTrackRefitter.src = _theTrackCollection
0237      process.FinalTrackRefitter.TrajectoryInEvent = True
0238      process.FinalTrackRefitter.NavigationSchool = ''
0239      process.FinalTrackRefitter.TTRHBuilder = "WithAngleAndTemplate"
0240 
0241      ####################################################################
0242      # Sequence
0243      ####################################################################
0244      process.load("RecoLocalTracker.SiPixelRecHits.SiPixelTemplateStoreESProducer_cfi")
0245      process.seqTrackselRefit = cms.Sequence(process.offlineBeamSpot*
0246                                              # in case NavigatioSchool is set !='' 
0247                                              #process.MeasurementTrackerEvent*
0248                                              process.FinalTrackRefitter,
0249                                              cms.Task(process.SiPixelTemplateStoreESProducer))
0250 
0251 ####################################################################
0252 # Output file
0253 ####################################################################
0254 process.TFileService = cms.Service("TFileService",
0255                                    fileName=cms.string("PVValidation_test_0.root")
0256                                   )
0257 
0258 ####################################################################
0259 # Imports of parameters
0260 ####################################################################
0261 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices
0262 ## modify the parameters which differ
0263 FilteringParams = offlinePrimaryVertices.TkFilterParameters.clone(
0264      maxNormalizedChi2 = 5.0,  # chi2ndof < 5
0265      maxD0Significance = 5.0,  # fake cut (requiring 1 PXB hit)
0266      maxEta = 5.0,             # as per recommendation in PR #18330
0267 )
0268 
0269 ## MM 04.05.2017 (use settings as in: https://github.com/cms-sw/cmssw/pull/18330)
0270 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import DA_vectParameters
0271 DAClusterizationParams = DA_vectParameters.clone()
0272 
0273 GapClusterizationParams = cms.PSet(algorithm   = cms.string('gap'),
0274                                    TkGapClusParameters = cms.PSet(zSeparation = cms.double(0.2))  # 0.2 cm max separation betw. clusters
0275                                    )
0276 
0277 ####################################################################
0278 # Deterministic annealing clustering or Gap clustering
0279 ####################################################################
0280 def switchClusterizerParameters(da):
0281      if da:
0282           print("############ testPVValidation_cfg.py: msg%-i: Running DA Algorithm!")
0283           return DAClusterizationParams
0284      else:
0285           print("############ testPVValidation_cfg.py: msg%-i: Running GAP Algorithm!")
0286           return GapClusterizationParams
0287 
0288 ####################################################################
0289 # Configure the PVValidation Analyzer module
0290 ####################################################################
0291 process.PVValidation = cms.EDAnalyzer("PrimaryVertexValidation",
0292                                       TrackCollectionTag = cms.InputTag("FinalTrackRefitter"),
0293                                       VertexCollectionTag = cms.InputTag("offlinePrimaryVertices"),
0294                                       Debug = cms.bool(False),
0295                                       storeNtuple = cms.bool(False),
0296                                       useTracksFromRecoVtx = cms.bool(False),
0297                                       isLightNtuple = cms.bool(True),
0298                                       askFirstLayerHit = cms.bool(False),
0299                                       forceBeamSpot = cms.untracked.bool(False),
0300                                       probePt = cms.untracked.double(3.),
0301                                       minPt   = cms.untracked.double(1.),
0302                                       maxPt   = cms.untracked.double(30.),
0303                                       runControl = cms.untracked.bool(True),
0304                                       runControlNumber = cms.untracked.vuint32(int(runboundary)),
0305                                       TkFilterParameters = FilteringParams,
0306                                       TkClusParameters = switchClusterizerParameters(isDA)
0307                                       )
0308 
0309 ####################################################################
0310 # Needed to avoid dependency from Phase-0 strip conditions
0311 ####################################################################
0312 #process.TrackerTrackHitFilter.isPhase2 = cms.bool(True)
0313 
0314 ####################################################################
0315 # Path
0316 ####################################################################
0317 process.p = cms.Path(process.goodvertexSkim*
0318                      process.seqTrackselRefit*
0319                      process.PVValidation)
0320 
0321 ## PV refit part
0322 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0323 process.offlinePrimaryVerticesFromRefittedTrks  = offlinePrimaryVertices.clone()
0324 process.offlinePrimaryVerticesFromRefittedTrks.TrackLabel                                       = cms.InputTag("FinalTrackRefitter")
0325 process.offlinePrimaryVerticesFromRefittedTrks.vertexCollections.maxDistanceToBeam              = 1
0326 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxNormalizedChi2             = 20
0327 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minSiliconLayersWithHits      = 5
0328 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Significance             = 5.0
0329 # as it was prior to https://github.com/cms-sw/cmssw/commit/c8462ae4313b6be3bbce36e45373aa6e87253c59
0330 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Error                    = 1.0
0331 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxDzError                    = 1.0
0332 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minPixelLayersWithHits        = 2
0333 
0334 ###################################################################
0335 # The trigger filter module
0336 ###################################################################
0337 from HLTrigger.HLTfilters.triggerResultsFilter_cfi import *
0338 process.HLTFilter = triggerResultsFilter.clone(
0339      triggerConditions = cms.vstring("HLT_ZeroBias_*"),
0340      #triggerConditions = cms.vstring("HLT_HT*"),
0341      hltResults = cms.InputTag( "TriggerResults", "", "HLT" ),
0342      l1tResults = cms.InputTag( "" ),
0343      throw = cms.bool(False)
0344 )
0345 
0346 ###################################################################
0347 # The analysis module
0348 ###################################################################
0349 process.myanalysis = cms.EDAnalyzer("GeneralPurposeTrackAnalyzer",
0350                                     TkTag  = cms.InputTag('FinalTrackRefitter'),
0351                                     doLatencyAnalysis =  cms.bool(False),
0352                                     isCosmics = cms.bool(False)
0353                                     )
0354 
0355 ###################################################################
0356 # The PV resolution module
0357 ###################################################################
0358 process.PrimaryVertexResolution = cms.EDAnalyzer('SplitVertexResolution',
0359                                                  storeNtuple         = cms.bool(True),
0360                                                  vtxCollection       = cms.InputTag("offlinePrimaryVerticesFromRefittedTrks"),
0361                                                  trackCollection     = cms.InputTag("FinalTrackRefitter"),
0362                                                  minVertexNdf        = cms.untracked.double(10.),
0363                                                  minVertexMeanWeight = cms.untracked.double(0.5),
0364                                                  runControl = cms.untracked.bool(True),
0365                                                  runControlNumber = cms.untracked.vuint32(int(runboundary))
0366                                                  )
0367 #process.Tracer = cms.Service("Tracer")
0368 
0369 process.p2 = cms.Path(process.HLTFilter                               +
0370                       process.seqTrackselRefit                        +
0371                       process.offlinePrimaryVerticesFromRefittedTrks  +
0372                       process.PrimaryVertexResolution                 +
0373                       process.myanalysis)