Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:07

0001 from fnmatch import fnmatch
0002 import FWCore.ParameterSet.Config as cms
0003 import FWCore.Utilities.FileUtils as FileUtils
0004 import FWCore.ParameterSet.VarParsing as VarParsing
0005 import sys
0006 
0007 from Configuration.StandardSequences.Eras import eras
0008 from Alignment.OfflineValidation.TkAlAllInOneTool.defaultInputFiles_cff import filesDefaultMC_DoubleMuon_string
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                   '2022', # 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                   'auto:phase1_2022_realistic', # 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                   filesDefaultMC_DoubleMuon_string, # 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 elif options.era=='2022':
0099     print("===> running era 2022")
0100     process = cms.Process('Analysis',eras.Run3)
0101 elif options.era=='2023':
0102     print("===> running era 2023")
0103     process = cms.Process('Analysis',eras.Run3_2023)
0104 
0105 ###################################################################
0106 # Set the process to run multi-threaded
0107 ###################################################################
0108 process.options.numberOfThreads = 8
0109 
0110 # import of standard configurations
0111 process.load('Configuration.StandardSequences.Services_cff')
0112 process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
0113 process.load('Configuration.StandardSequences.MagneticField_AutoFromDBCurrent_cff')
0114 process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
0115 
0116 ###################################################################
0117 # Tell the program where to find the conditons
0118 connection_map = [
0119     ('Tracker*', 'frontier://PromptProd/CMS_CONDITIONS'),
0120     ('SiPixel*', 'frontier://PromptProd/CMS_CONDITIONS'),
0121     ('SiStrip*', 'frontier://PromptProd/CMS_CONDITIONS'),
0122     ('Beam*', 'frontier://PromptProd/CMS_CONDITIONS'),
0123     ]
0124 
0125 if options.external:
0126     connection_map.extend(
0127         (i.split(':')[0], 'sqlite_file:%s' % i.split(':')[1]) for i in options.external
0128         )
0129 
0130 connection_map.sort(key=lambda x: -1*len(x[0]))
0131 
0132 ###################################################################
0133 # creat the map for the GT toGet
0134 records = []
0135 if options.records:
0136     for record in options.records:
0137         rcd, tag = tuple(record.split(':'))
0138         print("control point:",rcd,tag)
0139         if len(rcd)==0:
0140             print("no overriding will occur")
0141             continue
0142         records.append(
0143             cms.PSet(
0144                 record = cms.string(rcd),
0145                 tag    = cms.string(tag),
0146                 connect = cms.string(best_match(rcd))
0147                 )
0148             )
0149 
0150 ###################################################################
0151 # configure the Global Tag
0152 from Configuration.AlCa.GlobalTag import GlobalTag
0153 process.GlobalTag = GlobalTag(process.GlobalTag, options.GlobalTag, '')
0154 process.GlobalTag.toGet = cms.VPSet(*records)
0155 
0156 '''
0157 process.GlobalTag.toGet = cms.VPSet(
0158     cms.PSet(record = cms.string("TrackerAlignmentRcd"),
0159              tag = cms.string("TrackerAlignment_Upgrade2017_design_v4"),
0160              #tag = cms.string("TrackerAlignment_2017_ultralegacymc_v1"),
0161              connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS")
0162          ),
0163     cms.PSet(record = cms.string("TrackerAlignmentErrorExtendedRcd"),
0164              tag = cms.string("TrackerAlignmentErrorsExtended_Upgrade2017_design_v0"),
0165              #tag = cms.string("TrackerAlignmentExtendedErrors_2017_ultralegacymc_v1"),
0166              connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS")
0167          )
0168 )
0169 '''
0170 
0171 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.maxEvents) )
0172 
0173 #process.load('FWCore.MessageService.MessageLogger_cfi')
0174 #process.MessageLogger.cerr.FwkReport.reportEvery = 1
0175 
0176 ###################################################################
0177 # Messages
0178 ###################################################################
0179 process.load('FWCore.MessageService.MessageLogger_cfi')   
0180 process.MessageLogger.cerr.enable = False
0181 process.MessageLogger.TrackRefitter=dict()
0182 process.MessageLogger.PrimaryVertexProducer=dict()
0183 process.MessageLogger.DiMuonVertexValidation=dict()
0184 process.MessageLogger.DiLeptonHelpCounts=dict()
0185 process.MessageLogger.PlotsVsKinematics=dict()
0186 process.MessageLogger.cout = cms.untracked.PSet(
0187     enable = cms.untracked.bool(True),
0188     threshold = cms.untracked.string("INFO"),
0189     default   = cms.untracked.PSet(limit = cms.untracked.int32(0)),                       
0190     FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1),
0191                                    reportEvery = cms.untracked.int32(100)
0192                                    ),                                                      
0193     DiMuonVertexValidation = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0194     DiLeptonHelpCounts = cms.untracked.PSet( limit = cms.untracked.int32(-1)),
0195     enableStatistics = cms.untracked.bool(True)
0196     )
0197 
0198 ###################################################################
0199 # Source
0200 ###################################################################
0201 if(options.FileList):
0202     print('Loading file list from ASCII file')
0203     filelist = FileUtils.loadListFromFile (options.FileList)
0204     readFiles = cms.untracked.vstring( *filelist)
0205 else:
0206     readFiles = cms.untracked.vstring([options.myfile])
0207 
0208 process.source = cms.Source("PoolSource",
0209                             fileNames = readFiles,
0210                             #skipEvents = cms.untracked.uint32(45000)
0211 )
0212 
0213 ###################################################################
0214 # TransientTrack from https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideTransientTracks
0215 ###################################################################
0216 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0217 process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi')
0218 process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi')
0219 process.load('TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff')
0220 
0221 ####################################################################
0222 # Get the BeamSpot
0223 ####################################################################
0224 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
0225 
0226 ####################################################################
0227 # Track Refitter
0228 ####################################################################
0229 process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
0230 import RecoTracker.TrackProducer.TrackRefitters_cff
0231 process.TrackRefitter = RecoTracker.TrackProducer.TrackRefitter_cfi.TrackRefitter.clone()
0232 process.TrackRefitter.src = "generalTracks"
0233 #process.TrackRefitter.src = "ALCARECOTkAlDiMuonVertexTracks"
0234 process.TrackRefitter.TrajectoryInEvent = True
0235 process.TrackRefitter.NavigationSchool = ''
0236 process.TrackRefitter.TTRHBuilder = "WithAngleAndTemplate"
0237 
0238 ####################################################################
0239 # Sequence
0240 ####################################################################
0241 process.seqTrackselRefit = cms.Sequence(process.offlineBeamSpot*
0242                                         # in case NavigatioSchool is set !=''
0243                                         #process.MeasurementTrackerEvent*
0244                                         process.TrackRefitter)
0245 
0246 ####################################################################
0247 # Re-do vertices
0248 ####################################################################
0249 from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices
0250 process.offlinePrimaryVerticesFromRefittedTrks = offlinePrimaryVertices.clone()
0251 process.offlinePrimaryVerticesFromRefittedTrks.TrackLabel = cms.InputTag("TrackRefitter")
0252 
0253 ####################################################################
0254 # Output file
0255 ####################################################################
0256 process.TFileService = cms.Service("TFileService",fileName=cms.string("DiMuonVertexValidation_"+options.outputName+"_"+options.myseed+".root"))
0257 
0258 # Additional output definition
0259 process.analysis = cms.EDAnalyzer("DiMuonVertexValidation",
0260                                   useReco = cms.bool(True),
0261                                   ## the two parameters below are mutually exclusive,
0262                                   ## depending if RECO or ALCARECO is used
0263                                   muons  = cms.InputTag('muons'),
0264                                   #muonTracks = cms.InputTag('ALCARECOTkAlDiMuon'),
0265                                   tracks = cms.InputTag('TrackRefitter'),
0266                                   vertices = cms.InputTag('offlinePrimaryVerticesFromRefittedTrks'))
0267 
0268 ####################################################################
0269 # Path
0270 ####################################################################
0271 process.p = cms.Path(process.seqTrackselRefit                        +
0272                      process.offlinePrimaryVerticesFromRefittedTrks  +
0273                      process.analysis
0274                      )