Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-27 22:36:55

0001 from __future__ import print_function
0002 from fnmatch import fnmatch
0003 import FWCore.ParameterSet.Config as cms
0004 import FWCore.Utilities.FileUtils as FileUtils
0005 import FWCore.ParameterSet.VarParsing as VarParsing
0006 import sys
0007 
0008 from Configuration.StandardSequences.Eras import eras
0009 
0010 ###################################################################
0011 def best_match(rcd):
0012 ###################################################################
0013     '''
0014     find out where to best match the input conditions
0015     '''
0016     print(rcd)
0017     for pattern, string in connection_map:
0018         print(pattern, fnmatch(rcd, pattern))
0019         if fnmatch(rcd, pattern):
0020             return string
0021 
0022 options = VarParsing.VarParsing ()
0023 options.register('maxEvents',
0024                  -1,
0025                  VarParsing.VarParsing.multiplicity.singleton,
0026                  VarParsing.VarParsing.varType.int,
0027                  "number of events to process (\"-1\" for all)")
0028 options.register ('era',
0029                   '2017', # default value
0030                   VarParsing.VarParsing.multiplicity.singleton, # singleton or list
0031                   VarParsing.VarParsing.varType.string,         # string, int, or float
0032                   "CMS running era")
0033 
0034 options.register ('GlobalTag',
0035                   '113X_mc2017_realistic_v4', # default value
0036                   VarParsing.VarParsing.multiplicity.singleton,
0037                   VarParsing.VarParsing.varType.string,
0038                   "seed number")
0039 
0040 options.register ('records',
0041                   [],
0042                   VarParsing.VarParsing.multiplicity.list, # singleton or list
0043                   VarParsing.VarParsing.varType.string,          # string, int, or float
0044                   "record:tag names to be used/changed from GT")
0045 
0046 options.register ('external',
0047                   [],
0048                   VarParsing.VarParsing.multiplicity.list, # singleton or list
0049                   VarParsing.VarParsing.varType.string,          # string, int, or float
0050                   "record:fle.db picks the following record from this external file")
0051 
0052 options.register ('myseed',
0053                   '1', # default value
0054                   VarParsing.VarParsing.multiplicity.singleton,
0055                   VarParsing.VarParsing.varType.string,
0056                   "seed number")
0057 
0058 options.register ('myfile',
0059                   '/store/relval/CMSSW_10_6_1/RelValZMM_13/GEN-SIM-RECO/PU25ns_106X_mc2017_realistic_v6_HS-v1/10000/44690279-DDF3-0D43-B92D-F5CB57EF7E6A.root', # default value
0060                   VarParsing.VarParsing.multiplicity.singleton,
0061                   VarParsing.VarParsing.varType.string,
0062                   "file name")
0063 
0064 options.register ('FileList',
0065                   '', # default value
0066                   VarParsing.VarParsing.multiplicity.singleton, 
0067                   VarParsing.VarParsing.varType.string,
0068                   "FileList in DAS format")
0069 
0070 options.register ('outputName',
0071                   'default', # default value
0072                   VarParsing.VarParsing.multiplicity.singleton, # singleton or list
0073                   VarParsing.VarParsing.varType.string,         # string, int, or float
0074                   "output file")
0075 
0076 options.parseArguments()
0077 
0078 if(options.FileList):
0079     print("FileList:           ", options.FileList)
0080 else:
0081     print("inputFile:          ", options.myfile)
0082 print("outputFile:         ", "DiMuonVertexValidation_{fname}_{fseed}.root".format(fname = options.outputName,fseed=options.myseed))
0083 print("era:                ", options.era)
0084 print("conditionGT:        ", options.GlobalTag)
0085 print("conditionOverwrite: ", options.records)
0086 print("external conditions:", options.external)
0087 print("max events:         ", options.maxEvents)
0088 
0089 if options.era=='2016':
0090     print("===> running era 2016")
0091     process = cms.Process('Analysis',eras.Run2_2016)
0092 elif options.era=='2017':
0093     print("===> running era 2017")
0094     process = cms.Process('Analysis',eras.Run2_2017)
0095 elif options.era=='2018':
0096     print("===> running era 2018")
0097     process = cms.Process('Analysis',eras.Run2_2018)
0098 
0099 # import of standard configurations
0100 process.load('Configuration.StandardSequences.Services_cff')
0101 process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
0102 process.load('Configuration.StandardSequences.MagneticField_AutoFromDBCurrent_cff')
0103 process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
0104 
0105 ###################################################################
0106 # Tell the program where to find the conditons
0107 connection_map = [
0108     ('Tracker*', 'frontier://PromptProd/CMS_CONDITIONS'),
0109     ('SiPixel*', 'frontier://PromptProd/CMS_CONDITIONS'),
0110     ('SiStrip*', 'frontier://PromptProd/CMS_CONDITIONS'),
0111     ('Beam*', 'frontier://PromptProd/CMS_CONDITIONS'),
0112     ]
0113 
0114 if options.external:
0115     connection_map.extend(
0116         (i.split(':')[0], 'sqlite_file:%s' % i.split(':')[1]) for i in options.external
0117         )
0118 
0119 connection_map.sort(key=lambda x: -1*len(x[0]))
0120 
0121 ###################################################################
0122 # creat the map for the GT toGet
0123 records = []
0124 if options.records:
0125     for record in options.records:
0126         rcd, tag = tuple(record.split(':'))
0127         print("control point:",rcd,tag)
0128         if len(rcd)==0:
0129             print("no overriding will occur")
0130             continue
0131         records.append(
0132             cms.PSet(
0133                 record = cms.string(rcd),
0134                 tag    = cms.string(tag),
0135                 connect = cms.string(best_match(rcd))
0136                 )
0137             )
0138 
0139 ###################################################################
0140 # configure the Global Tag
0141 from Configuration.AlCa.GlobalTag import GlobalTag
0142 process.GlobalTag = GlobalTag(process.GlobalTag, options.GlobalTag, '')
0143 process.GlobalTag.toGet = cms.VPSet(*records)
0144 
0145 '''
0146 process.GlobalTag.toGet = cms.VPSet(
0147     cms.PSet(record = cms.string("TrackerAlignmentRcd"),
0148              tag = cms.string("TrackerAlignment_Upgrade2017_design_v4"),
0149              #tag = cms.string("TrackerAlignment_2017_ultralegacymc_v1"),
0150              connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS")
0151          ),
0152     cms.PSet(record = cms.string("TrackerAlignmentErrorExtendedRcd"),
0153              tag = cms.string("TrackerAlignmentErrorsExtended_Upgrade2017_design_v0"),
0154              #tag = cms.string("TrackerAlignmentExtendedErrors_2017_ultralegacymc_v1"),
0155              connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS")
0156          )
0157 )
0158 '''
0159 
0160 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.maxEvents) )
0161 
0162 #process.load('FWCore.MessageService.MessageLogger_cfi')
0163 #process.MessageLogger.cerr.FwkReport.reportEvery = 1
0164 
0165 ###################################################################
0166 # Messages
0167 ###################################################################
0168 process.load('FWCore.MessageService.MessageLogger_cfi')   
0169 process.MessageLogger.cerr.enable = False
0170 process.MessageLogger.TrackRefitter=dict()
0171 process.MessageLogger.PrimaryVertexProducer=dict()
0172 process.MessageLogger.DiMuonVertexValidation=dict()
0173 process.MessageLogger.DiLeptonHelpCounts=dict()
0174 process.MessageLogger.PlotsVsKinematics=dict()
0175 process.MessageLogger.cout = cms.untracked.PSet(
0176     enable = cms.untracked.bool(True),
0177     threshold = cms.untracked.string("INFO"),
0178     default   = cms.untracked.PSet(limit = cms.untracked.int32(0)),                       
0179     FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1),
0180                                    reportEvery = cms.untracked.int32(100)
0181                                    ),                                                      
0182     DiMuonVertexValidation = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0183     DiLeptonHelpCounts = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0184     enableStatistics = cms.untracked.bool(True)
0185     )
0186 
0187 ###################################################################
0188 # Source
0189 ###################################################################
0190 if(options.FileList):
0191     print('Loading file list from ASCII file')
0192     filelist = FileUtils.loadListFromFile (options.FileList)
0193     readFiles = cms.untracked.vstring( *filelist)
0194 else:
0195     readFiles = cms.untracked.vstring([options.myfile])
0196 
0197 process.source = cms.Source("PoolSource",
0198                             fileNames = readFiles,
0199                             #skipEvents = cms.untracked.uint32(45000)
0200 )
0201 
0202 ###################################################################
0203 # TransientTrack from https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideTransientTracks
0204 ###################################################################
0205 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0206 process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi')
0207 process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi')
0208 process.load('TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff')
0209 
0210 ####################################################################
0211 # Get the BeamSpot
0212 ####################################################################
0213 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
0214 
0215 ####################################################################
0216 # Track Refitter
0217 ####################################################################
0218 process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
0219 import RecoTracker.TrackProducer.TrackRefitters_cff
0220 process.TrackRefitter = RecoTracker.TrackProducer.TrackRefitter_cfi.TrackRefitter.clone()
0221 process.TrackRefitter.src = "generalTracks"
0222 #process.TrackRefitter.src = "ALCARECOTkAlDiMuonVertexTracks"
0223 process.TrackRefitter.TrajectoryInEvent = True
0224 process.TrackRefitter.NavigationSchool = ''
0225 process.TrackRefitter.TTRHBuilder = "WithAngleAndTemplate"
0226 
0227 ####################################################################
0228 # Sequence
0229 ####################################################################
0230 process.seqTrackselRefit = cms.Sequence(process.offlineBeamSpot*
0231                                         # in case NavigatioSchool is set !=''
0232                                         #process.MeasurementTrackerEvent*
0233                                         process.TrackRefitter)
0234 
0235 ####################################################################
0236 # Re-do vertices
0237 ####################################################################
0238 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices
0239 process.offlinePrimaryVerticesFromRefittedTrks = offlinePrimaryVertices.clone()
0240 process.offlinePrimaryVerticesFromRefittedTrks.TrackLabel = cms.InputTag("TrackRefitter")
0241 
0242 ####################################################################
0243 # Output file
0244 ####################################################################
0245 process.TFileService = cms.Service("TFileService",fileName=cms.string("DiMuonVertexValidation_"+options.outputName+"_"+options.myseed+".root"))
0246 
0247 # Additional output definition
0248 process.analysis = cms.EDAnalyzer("DiMuonVertexValidation",
0249                                   useReco = cms.bool(True),
0250                                   ## the two parameters below are mutually exclusive,
0251                                   ## depending if RECO or ALCARECO is used
0252                                   muons  = cms.InputTag('muons'),
0253                                   #muonTracks = cms.InputTag('ALCARECOTkAlDiMuon'),
0254                                   tracks = cms.InputTag('TrackRefitter'),
0255                                   vertices = cms.InputTag('offlinePrimaryVerticesFromRefittedTrks'))
0256 
0257 ####################################################################
0258 # Path
0259 ####################################################################
0260 process.p = cms.Path(process.seqTrackselRefit                        +
0261                      process.offlinePrimaryVerticesFromRefittedTrks  +
0262                      process.analysis
0263                      )