Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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                   'root://cms-xrd-global.cern.ch//store/relval/CMSSW_10_6_1/RelValZEE_13/GEN-SIM-RECO/PU25ns_106X_mc2017_realistic_v6_HS-v1/10000/B3F7544E-F34D-9D42-B897-21820FDE0331.root',
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:         ", "DiElectronVertexValidation_{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 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.maxEvents) )
0146 
0147 #process.load('FWCore.MessageService.MessageLogger_cfi')
0148 #process.MessageLogger.cerr.FwkReport.reportEvery = 1000
0149 
0150 ###################################################################
0151 # Messages
0152 ###################################################################
0153 process.load('FWCore.MessageService.MessageLogger_cfi')   
0154 process.MessageLogger.cerr.enable = False
0155 process.MessageLogger.TrackRefitter=dict()
0156 process.MessageLogger.GsfTrackRefitter=dict()
0157 process.MessageLogger.PrimaryVertexProducer=dict()
0158 process.MessageLogger.DiElectronVertexValidation=dict()
0159 process.MessageLogger.DiLeptonHelpCounts=dict()
0160 process.MessageLogger.PlotsVsKinematics=dict()
0161 process.MessageLogger.cout = cms.untracked.PSet(
0162     enable = cms.untracked.bool(True),
0163     threshold = cms.untracked.string("INFO"),
0164     default   = cms.untracked.PSet(limit = cms.untracked.int32(0)),                       
0165     FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1),
0166                                    reportEvery = cms.untracked.int32(1000)
0167                                    ),                                                      
0168     DiElectronVertexValidation = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0169     DiLeptonHelpCounts = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0170     enableStatistics = cms.untracked.bool(True)
0171     )
0172 
0173 ###################################################################
0174 # Source
0175 ###################################################################
0176 if(options.FileList):
0177     print('Loading file list from ASCII file')
0178     filelist = FileUtils.loadListFromFile (options.FileList)
0179     readFiles = cms.untracked.vstring( *filelist)
0180 else:
0181     readFiles = cms.untracked.vstring([options.myfile])
0182 
0183 process.source = cms.Source("PoolSource",
0184                             fileNames = readFiles)
0185 
0186 ###################################################################
0187 # TransientTrack from https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideTransientTracks
0188 ###################################################################
0189 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0190 process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi')
0191 process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi')
0192 process.load('TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff')
0193 
0194 ####################################################################
0195 # Get the BeamSpot
0196 ####################################################################
0197 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
0198 
0199 ####################################################################
0200 # Track Refitter
0201 ####################################################################
0202 process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
0203 import RecoTracker.TrackProducer.TrackRefitters_cff
0204 process.TrackRefitter = RecoTracker.TrackProducer.TrackRefitter_cfi.TrackRefitter.clone()
0205 process.TrackRefitter.src = "generalTracks"
0206 process.TrackRefitter.TrajectoryInEvent = True
0207 process.TrackRefitter.NavigationSchool = ''
0208 process.TrackRefitter.TTRHBuilder = "WithAngleAndTemplate"
0209 
0210 ####################################################################
0211 # Load  electron configuration files
0212 ####################################################################
0213 process.load("TrackingTools.GsfTracking.GsfElectronFit_cff")
0214 
0215 ####################################################################
0216 # GSF Track Refitter
0217 ####################################################################
0218 process.load("TrackingTools.GsfTracking.fwdGsfElectronPropagator_cff")
0219 process.load("RecoTracker.TrackProducer.GsfTrackRefitter_cff")
0220 process.GsfTrackRefitter = RecoTracker.TrackProducer.GsfTrackRefitter_cff.GsfTrackRefitter.clone()
0221 process.GsfTrackRefitter.src = cms.InputTag('electronGsfTracks')  
0222 process.GsfTrackRefitter.TrajectoryInEvent = True
0223 process.GsfTrackRefitter.AlgorithmName = cms.string('gsf')
0224 #process.GsfTrackRefitter.NavigationSchool = ''
0225 #process.GsfTrackRefitter.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                                         process.GsfTrackRefitter)
0235 
0236 ####################################################################
0237 # Re-do vertices
0238 ####################################################################
0239 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices
0240 process.offlinePrimaryVerticesFromRefittedTrks = offlinePrimaryVertices.clone()
0241 process.offlinePrimaryVerticesFromRefittedTrks.TrackLabel = cms.InputTag("TrackRefitter")
0242 
0243 ####################################################################
0244 # Output file
0245 ####################################################################
0246 process.TFileService = cms.Service("TFileService",fileName=cms.string("DiElectronVertexValidation_"+options.outputName+"_"+options.myseed+".root"))
0247 
0248 # Additional output definition
0249 process.analysis = cms.EDAnalyzer("DiElectronVertexValidation",
0250                                   gsfTracks = cms.InputTag('GsfTrackRefitter'),
0251                                   vertices = cms.InputTag('offlinePrimaryVerticesFromRefittedTrks'))
0252 
0253 ####################################################################
0254 # Path
0255 ####################################################################
0256 process.p = cms.Path(process.seqTrackselRefit                        +
0257                      process.offlinePrimaryVerticesFromRefittedTrks  +
0258                      process.analysis)