Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-19 23:58:18

0001 #! /bin/env cmsRun
0002 
0003 '''
0004 cfg to produce pv resolution plots
0005 here doing refit of tracks and vertices using latest alignment 
0006 '''
0007 
0008 from __future__ import print_function
0009 import FWCore.ParameterSet.Config as cms
0010 from fnmatch import fnmatch
0011 import FWCore.ParameterSet.VarParsing as VarParsing
0012 from pdb import set_trace
0013 
0014 process = cms.Process("PrimaryVertexResolution")
0015 
0016 ###################################################################
0017 def best_match(rcd):
0018 ###################################################################
0019     '''
0020     find out where to best match the input conditions
0021     '''
0022     print(rcd)
0023     for pattern, string in connection_map:
0024         print(pattern, fnmatch(rcd, pattern))
0025         if fnmatch(rcd, pattern):
0026             return string
0027 
0028 options = VarParsing.VarParsing("analysis")
0029 
0030 options.register('lumi',
0031                  1.,
0032                  VarParsing.VarParsing.multiplicity.singleton, # singleton or list
0033                  VarParsing.VarParsing.varType.float,          # string, int, or float
0034                  "luminosity used")
0035 
0036 options.register ('outputRootFile',
0037                   "pvresolution_YYY_KEY_YYY_XXX_RUN_XXX.root",
0038                   VarParsing.VarParsing.multiplicity.singleton, # singleton or list
0039                   VarParsing.VarParsing.varType.string,          # string, int, or float
0040                   "output root file")
0041 
0042 options.register ('records',
0043                   [],
0044                   VarParsing.VarParsing.multiplicity.list, # singleton or list
0045                   VarParsing.VarParsing.varType.string,          # string, int, or float
0046                   "record:tag names to be used/changed from GT")
0047 
0048 options.register ('external',
0049                   [],
0050                   VarParsing.VarParsing.multiplicity.list, # singleton or list
0051                   VarParsing.VarParsing.varType.string,          # string, int, or float
0052                   "record:fle.db picks the following record from this external file")
0053 
0054 options.register ('GlobalTag',
0055                   '110X_dataRun3_Prompt_v3',
0056                   VarParsing.VarParsing.multiplicity.singleton, # singleton or list
0057                   VarParsing.VarParsing.varType.string,          # string, int, or float
0058                   "Global Tag to be used")
0059 
0060 options.parseArguments()
0061 
0062 print("conditionGT       : ", options.GlobalTag)
0063 print("conditionOverwrite: ", options.records)
0064 print("external conditions:", options.external)
0065 print("outputFile        : ", options.outputRootFile)
0066 
0067 process.load("FWCore.MessageService.MessageLogger_cfi")
0068 process.MessageLogger.cerr = cms.untracked.PSet(enable = cms.untracked.bool(False))
0069 process.MessageLogger.cout = cms.untracked.PSet(INFO = cms.untracked.PSet(
0070         reportEvery = cms.untracked.int32(1000) # every 100th only
0071         #    limit = cms.untracked.int32(10)       # or limit to 10 printouts...
0072     ))
0073 
0074 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(150000) )
0075 
0076 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0077 
0078 process.load("Configuration.StandardSequences.MagneticField_cff")
0079 process.load('Configuration.Geometry.GeometryRecoDB_cff')
0080 
0081 process.load('Configuration/StandardSequences/Services_cff')
0082 process.load('TrackingTools.TransientTrack.TransientTrackBuilder_cfi')
0083 
0084 process.source = cms.Source("PoolSource",
0085                             fileNames = cms.untracked.vstring(XXX_FILES_XXX)
0086                             )
0087 
0088 ###################################################################
0089 # Tell the program where to find the conditons
0090 connection_map = [
0091     ('Tracker*', 'frontier://PromptProd/CMS_CONDITIONS'),
0092     ('SiPixel*', 'frontier://PromptProd/CMS_CONDITIONS'),
0093     ('SiStrip*', 'frontier://PromptProd/CMS_CONDITIONS'),
0094     ('Beam*', 'frontier://PromptProd/CMS_CONDITIONS'),
0095     ]
0096 
0097 if options.external:
0098     connection_map.extend(
0099         (i.split(':')[0], 'sqlite_file:%s' % i.split(':')[1]) for i in options.external
0100         )
0101 
0102 connection_map.sort(key=lambda x: -1*len(x[0]))
0103 
0104 ###################################################################
0105 # creat the map for the GT toGet
0106 records = []
0107 if options.records:
0108     for record in options.records:
0109         rcd, tag = tuple(record.split(':'))
0110         records.append(
0111             cms.PSet(
0112                 record = cms.string(rcd),
0113                 tag    = cms.string(tag),
0114                 connect = cms.string(best_match(rcd))
0115                 )
0116             )
0117 
0118 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi")
0119 process.GlobalTag.globaltag  = options.GlobalTag
0120 #process.GlobalTag.DumpStat = cms.untracked.bool(True)
0121 process.GlobalTag.toGet = cms.VPSet(*records)
0122 
0123 process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
0124 # remove the following lines if you run on RECO files
0125 process.TrackRefitter.src = 'ALCARECOTkAlMinBias'
0126 process.TrackRefitter.NavigationSchool = ''
0127 
0128 ## PV refit
0129 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0130 
0131 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices 
0132 process.offlinePrimaryVerticesFromRefittedTrks  = offlinePrimaryVertices.clone()
0133 process.offlinePrimaryVerticesFromRefittedTrks.TrackLabel                                       = cms.InputTag("TrackRefitter") 
0134 process.offlinePrimaryVerticesFromRefittedTrks.vertexCollections.maxDistanceToBeam              = 1
0135 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxNormalizedChi2             = 20
0136 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minSiliconLayersWithHits      = 5
0137 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Significance             = 5.0
0138 # as it was prior to https://github.com/cms-sw/cmssw/commit/c8462ae4313b6be3bbce36e45373aa6e87253c59
0139 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Error                    = 1.0
0140 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxDzError                    = 1.0
0141 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minPixelLayersWithHits        = 2   
0142 
0143 process.PrimaryVertexResolution = cms.EDAnalyzer('SplitVertexResolution',
0144                                                  storeNtuple         = cms.bool(False),
0145                                                  intLumi             = cms.untracked.double(options.lumi),
0146                                                  vtxCollection       = cms.InputTag("offlinePrimaryVerticesFromRefittedTrks"),
0147                                                  trackCollection     = cms.InputTag("TrackRefitter"),       
0148                                                  minVertexNdf        = cms.untracked.double(10.),
0149                                                  minVertexMeanWeight = cms.untracked.double(0.5),
0150                                                  runControl = cms.untracked.bool(True),
0151                                                  runControlNumber = cms.untracked.vuint32(int(XXX_RUN_XXX)),
0152                                                  sumpTStartScale = cms.untracked.double(1.),
0153                                                  sumpTEndScale = cms.untracked.double(1000.),
0154                                                  nTrackBins = cms.untracked.double(60.),
0155                                                  nVtxBins = cms.untracked.double(40.)
0156                                                  )
0157 
0158 process.TFileService = cms.Service("TFileService",
0159                                    fileName = cms.string(options.outputRootFile),   
0160                                    closeFileFast = cms.untracked.bool(False)
0161                                    )
0162 
0163 process.p = cms.Path(process.offlineBeamSpot                        + 
0164                      process.TrackRefitter                          + 
0165                      process.offlinePrimaryVerticesFromRefittedTrks +
0166                      process.PrimaryVertexResolution)
0167 
0168