Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:33:00

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 ('GlobalTag',
0059                   '110X_dataRun3_Prompt_v3',
0060                   VarParsing.VarParsing.multiplicity.singleton, # singleton or list
0061                   VarParsing.VarParsing.varType.string,          # string, int, or float
0062                   "Global Tag to be used")
0063 
0064 options.parseArguments()
0065 
0066 print("conditionGT       : ", options.GlobalTag)
0067 print("conditionOverwrite: ", options.records)
0068 print("external conditions:", options.external)
0069 print("outputFile        : ", options.outputRootFile)
0070 
0071 process.load("FWCore.MessageService.MessageLogger_cfi")
0072 process.MessageLogger.cerr = cms.untracked.PSet(enable = cms.untracked.bool(False))
0073 process.MessageLogger.cout = cms.untracked.PSet(INFO = cms.untracked.PSet(
0074         reportEvery = cms.untracked.int32(1000) # every 100th only
0075         #    limit = cms.untracked.int32(10)       # or limit to 10 printouts...
0076     ))
0077 
0078 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(150000) )
0079 
0080 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0081 
0082 process.load("Configuration.StandardSequences.MagneticField_cff")
0083 process.load('Configuration.Geometry.GeometryRecoDB_cff')
0084 
0085 process.load('Configuration/StandardSequences/Services_cff')
0086 process.load('TrackingTools.TransientTrack.TransientTrackBuilder_cfi')
0087 
0088 process.source = cms.Source("PoolSource",
0089                             fileNames = cms.untracked.vstring(XXX_FILES_XXX)
0090                             )
0091 
0092 ###################################################################
0093 # Tell the program where to find the conditons
0094 connection_map = [
0095     ('Tracker*', 'frontier://PromptProd/CMS_CONDITIONS'),
0096     ('SiPixel*', 'frontier://PromptProd/CMS_CONDITIONS'),
0097     ('SiStrip*', 'frontier://PromptProd/CMS_CONDITIONS'),
0098     ('Beam*', 'frontier://PromptProd/CMS_CONDITIONS'),
0099     ]
0100 
0101 if options.external:
0102     connection_map.extend(
0103         (i.split(':')[0], 'sqlite_file:%s' % i.split(':')[1]) for i in options.external
0104         )
0105 
0106 connection_map.sort(key=lambda x: -1*len(x[0]))
0107 
0108 ###################################################################
0109 # creat the map for the GT toGet
0110 records = []
0111 if options.records:
0112     for record in options.records:
0113         rcd, tag = tuple(record.split(':'))
0114         records.append(
0115             cms.PSet(
0116                 record = cms.string(rcd),
0117                 tag    = cms.string(tag),
0118                 connect = cms.string(best_match(rcd))
0119                 )
0120             )
0121 
0122 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi")
0123 process.GlobalTag.globaltag  = options.GlobalTag
0124 #process.GlobalTag.DumpStat = cms.untracked.bool(True)
0125 process.GlobalTag.toGet = cms.VPSet(*records)
0126 
0127 process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
0128 # remove the following lines if you run on RECO files
0129 process.TrackRefitter.src = 'ALCARECOTkAlMinBias'
0130 process.TrackRefitter.NavigationSchool = ''
0131 
0132 ####################################################################
0133 # Refitting Sequence
0134 ####################################################################
0135 process.load("RecoLocalTracker.SiPixelRecHits.SiPixelTemplateStoreESProducer_cfi")
0136 process.seqTrackselRefit = cms.Sequence(process.offlineBeamSpot*
0137                                         process.TrackRefitter,
0138                                         cms.Task(process.SiPixelTemplateStoreESProducer))
0139 
0140 ####################################################################
0141 ## PV refit
0142 ####################################################################
0143 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0144 
0145 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices 
0146 process.offlinePrimaryVerticesFromRefittedTrks  = offlinePrimaryVertices.clone()
0147 process.offlinePrimaryVerticesFromRefittedTrks.TrackLabel                                       = cms.InputTag("TrackRefitter") 
0148 process.offlinePrimaryVerticesFromRefittedTrks.vertexCollections.maxDistanceToBeam              = 1
0149 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxNormalizedChi2             = 20
0150 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minSiliconLayersWithHits      = 5
0151 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Significance             = 5.0
0152 # as it was prior to https://github.com/cms-sw/cmssw/commit/c8462ae4313b6be3bbce36e45373aa6e87253c59
0153 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxD0Error                    = 1.0
0154 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.maxDzError                    = 1.0
0155 process.offlinePrimaryVerticesFromRefittedTrks.TkFilterParameters.minPixelLayersWithHits        = 2   
0156 
0157 process.PrimaryVertexResolution = cms.EDAnalyzer('SplitVertexResolution',
0158                                                  storeNtuple         = cms.bool(False),
0159                                                  intLumi             = cms.untracked.double(options.lumi),
0160                                                  vtxCollection       = cms.InputTag("offlinePrimaryVerticesFromRefittedTrks"),
0161                                                  trackCollection     = cms.InputTag("TrackRefitter"),       
0162                                                  minVertexNdf        = cms.untracked.double(10.),
0163                                                  minVertexMeanWeight = cms.untracked.double(0.5),
0164                                                  runControl = cms.untracked.bool(True),
0165                                                  runControlNumber = cms.untracked.vuint32(int(XXX_RUN_XXX)),
0166                                                  sumpTStartScale = cms.untracked.double(1.),
0167                                                  sumpTEndScale = cms.untracked.double(1000.),
0168                                                  nTrackBins = cms.untracked.double(60.),
0169                                                  nVtxBins = cms.untracked.double(40.)
0170                                                  )
0171 
0172 process.TFileService = cms.Service("TFileService",
0173                                    fileName = cms.string(options.outputRootFile),   
0174                                    closeFileFast = cms.untracked.bool(False)
0175                                    )
0176 
0177 process.p = cms.Path(process.seqTrackselRefit                       +
0178                      #process.offlineBeamSpot                       +
0179                      #process.TrackRefitter                         +
0180                      process.offlinePrimaryVerticesFromRefittedTrks +
0181                      process.PrimaryVertexResolution)
0182 
0183