Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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