Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-06 06:06:10

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                                              timetype = cms.string("runnumber"),
0108                                              toGet = cms.VPSet(cms.PSet(record = cms.string('TrackerAlignmentRcd'),
0109                                                                         tag = cms.string('TrackerAlignment_Upgrade2017_design_v4')
0110                                                                         )
0111                                                                )
0112                                              )
0113      process.es_prefer_trackerAlignment = cms.ESPrefer("PoolDBESSource", "trackerAlignment")
0114 
0115      ####################################################################
0116      # Get APE
0117      ####################################################################
0118      process.setAPE = cms.ESSource("PoolDBESSource",CondDBSetup,
0119                                    connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'),
0120                                    timetype = cms.string("runnumber"),
0121                                    toGet = cms.VPSet(cms.PSet(record = cms.string('TrackerAlignmentErrorExtendedRcd'),
0122                                                               tag = cms.string('TrackerAlignmentErrorsExtended_Upgrade2017_design_v0')
0123                                                               )
0124                                                      )
0125                                    )
0126      process.es_prefer_setAPE = cms.ESPrefer("PoolDBESSource", "setAPE")
0127 
0128      ####################################################################
0129      # Kinks and Bows (optional)
0130      ####################################################################
0131      if applyBows:
0132           print("############ testPVValidation_cfg.py: msg%-i: Applying TrackerSurfaceDeformations!")
0133           process.trackerBows = cms.ESSource("PoolDBESSource",CondDBSetup,
0134                                              connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'),
0135                                              toGet = cms.VPSet(cms.PSet(record = cms.string('TrackerSurfaceDeformationRcd'),
0136                                                                         tag = cms.string('TrackerSurfaceDeformations_zero')
0137                                                                         )
0138                                                                )
0139                                              )
0140           process.es_prefer_Bows = cms.ESPrefer("PoolDBESSource", "trackerBows")
0141      else:
0142           print("############ testPVValidation_cfg.py: msg%-i: MultiPVValidation: Not applying TrackerSurfaceDeformations!")
0143 
0144      ####################################################################
0145      # Extra corrections not included in the GT
0146      ####################################################################
0147      if applyExtraConditions:
0148 
0149           import CalibTracker.Configuration.Common.PoolDBESSource_cfi
0150           ##### END OF EXTRA CONDITIONS
0151  
0152      else:
0153           print("############ testPVValidation_cfg.py: msg%-i: Not applying extra calibration constants!")
0154      
0155 ####################################################################
0156 # Load and Configure event selection
0157 ####################################################################
0158 process.primaryVertexFilter = cms.EDFilter("VertexSelector",
0159                                              src = cms.InputTag("offlinePrimaryVertices"),
0160                                              cut = cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"),
0161                                              filter = cms.bool(True)
0162                                              )
0163 
0164 process.noscraping = cms.EDFilter("FilterOutScraping",
0165                                   applyfilter = cms.untracked.bool(True),
0166                                   src =  cms.untracked.InputTag(_theTrackCollection),
0167                                   debugOn = cms.untracked.bool(False),
0168                                   numtrack = cms.untracked.uint32(10),
0169                                   thresh = cms.untracked.double(0.25)
0170                                   )
0171 
0172 process.noslowpt = cms.EDFilter("FilterOutLowPt",
0173                                 applyfilter = cms.untracked.bool(True),
0174                                 src =  cms.untracked.InputTag(_theTrackCollection),
0175                                 debugOn = cms.untracked.bool(False),
0176                                 numtrack = cms.untracked.uint32(0),
0177                                 thresh = cms.untracked.int32(1),
0178                                 ptmin  = cms.untracked.double(3.),
0179                                 runControl = cms.untracked.bool(True),
0180                                 runControlNumber = cms.untracked.vuint32(int(runboundary))
0181                                 )
0182 
0183 if isMC:
0184      process.goodvertexSkim = cms.Sequence(process.noscraping)
0185 else:
0186      process.goodvertexSkim = cms.Sequence(process.primaryVertexFilter + process.noscraping + process.noslowpt)
0187 
0188 
0189 if(theRefitter == RefitType.COMMON):
0190 
0191      print("############ testPVValidation_cfg.py: msg%-i: using the common track selection and refit sequence!")
0192      ####################################################################
0193      # Load and Configure Common Track Selection and refitting sequence
0194      ####################################################################
0195      import Alignment.CommonAlignment.tools.trackselectionRefitting as trackselRefit
0196      process.seqTrackselRefit = trackselRefit.getSequence(process, _theTrackCollection ,
0197                                                           isPVValidation=True, 
0198                                                           TTRHBuilder='WithAngleAndTemplate',
0199                                                           usePixelQualityFlag=True,
0200                                                           openMassWindow=False,
0201                                                           cosmicsDecoMode=True,
0202                                                           cosmicsZeroTesla=False,
0203                                                           momentumConstraint=None,
0204                                                           cosmicTrackSplitting=False,
0205                                                           use_d0cut=False,
0206                                                           )
0207      
0208 elif (theRefitter == RefitType.STANDARD):
0209 
0210      print("############ testPVValidation_cfg.py: msg%-i: using the standard single refit sequence!")
0211      ####################################################################
0212      # Load and Configure Measurement Tracker Event
0213      # (needed in case NavigationSchool is set != '')
0214      ####################################################################
0215      # process.load("RecoTracker.MeasurementDet.MeasurementTrackerEventProducer_cfi") 
0216      # process.MeasurementTrackerEvent.pixelClusterProducer = 'ALCARECOTkAlMinBias'
0217      # process.MeasurementTrackerEvent.stripClusterProducer = 'ALCARECOTkAlMinBias'
0218      # process.MeasurementTrackerEvent.inactivePixelDetectorLabels = cms.VInputTag()
0219      # process.MeasurementTrackerEvent.inactiveStripDetectorLabels = cms.VInputTag()
0220 
0221      ####################################################################
0222      # Load and Configure TrackRefitter
0223      ####################################################################
0224      process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
0225      import RecoTracker.TrackProducer.TrackRefitters_cff
0226      process.FinalTrackRefitter = RecoTracker.TrackProducer.TrackRefitter_cfi.TrackRefitter.clone()
0227      process.FinalTrackRefitter.src = _theTrackCollection
0228      process.FinalTrackRefitter.TrajectoryInEvent = True
0229      process.FinalTrackRefitter.NavigationSchool = ''
0230      process.FinalTrackRefitter.TTRHBuilder = "WithAngleAndTemplate"
0231 
0232      ####################################################################
0233      # Sequence
0234      ####################################################################
0235      process.load("RecoLocalTracker.SiPixelRecHits.SiPixelTemplateStoreESProducer_cfi")
0236      process.seqTrackselRefit = cms.Sequence(process.offlineBeamSpot*
0237                                              # in case NavigatioSchool is set !='' 
0238                                              #process.MeasurementTrackerEvent*
0239                                              process.FinalTrackRefitter,
0240                                              cms.Task(process.SiPixelTemplateStoreESProducer))
0241 
0242 ####################################################################
0243 # Output file
0244 ####################################################################
0245 process.TFileService = cms.Service("TFileService",
0246                                    fileName=cms.string("PVValidation_test_0.root")
0247                                   )
0248 
0249 ####################################################################
0250 # Imports of parameters
0251 ####################################################################
0252 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices
0253 ## modify the parameters which differ
0254 FilteringParams = offlinePrimaryVertices.TkFilterParameters.clone(
0255      maxNormalizedChi2 = 5.0,  # chi2ndof < 5
0256      maxD0Significance = 5.0,  # fake cut (requiring 1 PXB hit)
0257      maxEta = 5.0,             # as per recommendation in PR #18330
0258 )
0259 
0260 ## MM 04.05.2017 (use settings as in: https://github.com/cms-sw/cmssw/pull/18330)
0261 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import DA_vectParameters
0262 DAClusterizationParams = DA_vectParameters.clone()
0263 
0264 GapClusterizationParams = cms.PSet(algorithm   = cms.string('gap'),
0265                                    TkGapClusParameters = cms.PSet(zSeparation = cms.double(0.2))  # 0.2 cm max separation betw. clusters
0266                                    )
0267 
0268 ####################################################################
0269 # Deterministic annealing clustering or Gap clustering
0270 ####################################################################
0271 def switchClusterizerParameters(da):
0272      if da:
0273           print("############ testPVValidation_cfg.py: msg%-i: Running DA Algorithm!")
0274           return DAClusterizationParams
0275      else:
0276           print("############ testPVValidation_cfg.py: msg%-i: Running GAP Algorithm!")
0277           return GapClusterizationParams
0278 
0279 ####################################################################
0280 # Configure the PVValidation Analyzer module
0281 ####################################################################
0282 process.PVValidation = cms.EDAnalyzer("PrimaryVertexValidation",
0283                                       TrackCollectionTag = cms.InputTag("FinalTrackRefitter"),
0284                                       VertexCollectionTag = cms.InputTag("offlinePrimaryVertices"),
0285                                       Debug = cms.bool(False),
0286                                       storeNtuple = cms.bool(False),
0287                                       useTracksFromRecoVtx = cms.bool(False),
0288                                       isLightNtuple = cms.bool(True),
0289                                       askFirstLayerHit = cms.bool(False),
0290                                       forceBeamSpot = cms.untracked.bool(False),
0291                                       probePt = cms.untracked.double(3.),
0292                                       minPt   = cms.untracked.double(1.),
0293                                       maxPt   = cms.untracked.double(30.),
0294                                       runControl = cms.untracked.bool(True),
0295                                       runControlNumber = cms.untracked.vuint32(int(runboundary)),
0296                                       TkFilterParameters = FilteringParams,
0297                                       TkClusParameters = switchClusterizerParameters(isDA)
0298                                       )
0299 
0300 ####################################################################
0301 # Needed to avoid dependency from Phase-0 strip conditions
0302 ####################################################################
0303 #process.TrackerTrackHitFilter.isPhase2 = cms.bool(True)
0304 
0305 ####################################################################
0306 # Path
0307 ####################################################################
0308 process.p = cms.Path(process.goodvertexSkim*
0309                      process.seqTrackselRefit*
0310                      process.PVValidation)
0311 
0312 ## PV refit part
0313 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0314 process.offlinePrimaryVerticesFromRefittedTrks  = offlinePrimaryVertices.clone()
0315 process.offlinePrimaryVerticesFromRefittedTrks.TrackLabel                                       = cms.InputTag("FinalTrackRefitter")
0316 process.offlinePrimaryVerticesFromRefittedTrks.vertexCollections.maxDistanceToBeam              = 1
0317 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxNormalizedChi2             = 20
0318 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minSiliconLayersWithHits      = 5
0319 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Significance             = 5.0
0320 # as it was prior to https://github.com/cms-sw/cmssw/commit/c8462ae4313b6be3bbce36e45373aa6e87253c59
0321 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Error                    = 1.0
0322 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxDzError                    = 1.0
0323 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minPixelLayersWithHits        = 2
0324 
0325 ###################################################################
0326 # The trigger filter module
0327 ###################################################################
0328 from HLTrigger.HLTfilters.triggerResultsFilter_cfi import *
0329 process.HLTFilter = triggerResultsFilter.clone(
0330      triggerConditions = cms.vstring("HLT_ZeroBias_*"),
0331      #triggerConditions = cms.vstring("HLT_HT*"),
0332      hltResults = cms.InputTag( "TriggerResults", "", "HLT" ),
0333      l1tResults = cms.InputTag( "" ),
0334      throw = cms.bool(False)
0335 )
0336 
0337 ###################################################################
0338 # The analysis module
0339 ###################################################################
0340 process.myanalysis = cms.EDAnalyzer("GeneralPurposeTrackAnalyzer",
0341                                     TkTag  = cms.InputTag('FinalTrackRefitter'),
0342                                     doLatencyAnalysis =  cms.bool(False),
0343                                     isCosmics = cms.bool(False)
0344                                     )
0345 
0346 ###################################################################
0347 # The PV resolution module
0348 ###################################################################
0349 process.PrimaryVertexResolution = cms.EDAnalyzer('SplitVertexResolution',
0350                                                  storeNtuple         = cms.bool(True),
0351                                                  vtxCollection       = cms.InputTag("offlinePrimaryVerticesFromRefittedTrks"),
0352                                                  trackCollection     = cms.InputTag("FinalTrackRefitter"),
0353                                                  minVertexNdf        = cms.untracked.double(10.),
0354                                                  minVertexMeanWeight = cms.untracked.double(0.5),
0355                                                  runControl = cms.untracked.bool(True),
0356                                                  runControlNumber = cms.untracked.vuint32(int(runboundary))
0357                                                  )
0358 #process.Tracer = cms.Service("Tracer")
0359 
0360 process.p2 = cms.Path(process.HLTFilter                               +
0361                       process.seqTrackselRefit                        +
0362                       process.offlinePrimaryVerticesFromRefittedTrks  +
0363                       process.PrimaryVertexResolution                 +
0364                       process.myanalysis)