File indexing completed on 2024-10-03 05:27:12
0001 import FWCore.ParameterSet.Config as cms
0002 import FWCore.Utilities.FileUtils as FileUtils
0003 import FWCore.ParameterSet.VarParsing as VarParsing
0004 import pkgutil
0005 import sys
0006
0007
0008
0009
0010 options = VarParsing.VarParsing ('analysis')
0011 options.register('redir', 'root://cms-xrd-global.cern.ch/', VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string, "The XRootD redirector to use")
0012 options.register('nstart', 0,VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int, "File index to start on")
0013 options.register('nfiles', -1,VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int, "Number of files to process per job")
0014 options.register('storeTracks', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.bool, "Store tracks in NTuple")
0015 options.register('l1Tracks','l1tTTTracksFromTrackletEmulation:Level1TTTracks', VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string, 'L1 track collection to use')
0016 options.register('runVariations', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.bool, "Run some pre-defined algorithmic variations")
0017 options.register('threads', 1,VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int, "Number of threads to run")
0018 options.register('streams', 0,VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int, "Number of streams to run")
0019 options.register('memoryProfiler', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.bool, "Run the memory profile")
0020 options.register('tmi', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.bool, "Run a simple profiler")
0021 options.register('trace', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.bool, "Dump the paths and consumes")
0022 options.register('dump', False, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.bool, "Dump the configuration and exit")
0023 options.parseArguments()
0024
0025
0026 if options.redir[0]=="T":
0027 options.redir = "root://cms-xrd-global.cern.ch//store/test/xrootd/"+options.redir
0028
0029
0030 inputFiles = cms.untracked.vstring()
0031
0032 for filePath in options.inputFiles:
0033 if filePath.endswith(".root") :
0034 inputFiles.append( filePath )
0035 elif filePath.endswith(".txt"):
0036 inputFiles += FileUtils.loadListFromFile( filePath )
0037 elif filePath.endswith("_cff.py"):
0038 inputFilesImport = getattr(__import__(filePath.strip(".py").strip("python/").replace('/','.'),fromlist=["readFiles"]),"readFiles")
0039 if options.nfiles==-1:
0040 inputFiles.extend( inputFilesImport )
0041 else:
0042 inputFiles.extend( inputFilesImport[options.nstart:(options.nstart+options.nfiles)] )
0043 elif pkgutil.find_loader("L1Trigger.VertexFinder."+filePath+"_cff") is not None:
0044 inputFilesImport = getattr(__import__("L1Trigger.VertexFinder."+filePath+"_cff",fromlist=["readFiles"]),"readFiles")
0045 if options.nfiles==-1:
0046 inputFiles.extend( inputFilesImport )
0047 else:
0048 inputFiles.extend( inputFilesImport[options.nstart:(options.nstart+options.nfiles)] )
0049 else:
0050 raise RuntimeError("Must specify a list of ROOT files, a list of txt files containing a list of ROOT files, or a list of python input files.")
0051
0052 if options.redir != "":
0053 inputFiles = [(options.redir if val.startswith("/") else "")+val for val in inputFiles]
0054
0055 if options.l1Tracks.count(':') != 1:
0056 raise RuntimeError("Value for 'l1Tracks' command-line argument (= '{}') should contain one colon".format(options.l1Tracks))
0057
0058 l1TracksTag = cms.InputTag(options.l1Tracks.split(':')[0], options.l1Tracks.split(':')[1])
0059 print("Input Track Collection = {0} {1}".format(*options.l1Tracks.split(':')))
0060
0061
0062
0063
0064 process = cms.Process("L1TVertexFinder")
0065
0066 process.load('Configuration.Geometry.GeometryExtended2026D49Reco_cff')
0067 process.load('Configuration.Geometry.GeometryExtended2026D49_cff')
0068 process.load('Configuration.StandardSequences.MagneticField_cff')
0069 process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
0070 from Configuration.AlCa.GlobalTag import GlobalTag
0071 process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:upgradePLS3', '')
0072 process.load("FWCore.MessageService.MessageLogger_cfi")
0073
0074 process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring(inputFiles) )
0075 process.TFileService = cms.Service("TFileService", fileName = cms.string(options.outputFile))
0076 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.maxEvents) )
0077 process.options = cms.untracked.PSet(
0078 numberOfThreads = cms.untracked.uint32(options.threads),
0079 numberOfStreams = cms.untracked.uint32(options.streams if options.streams>0 else 0)
0080 )
0081
0082 process.load('L1Trigger.VertexFinder.l1tVertexProducer_cfi')
0083 process.l1tVertexProducer.l1TracksInputTag = l1TracksTag
0084
0085 process.load('L1Trigger.VertexFinder.l1tTPStubValueMapProducer_cfi')
0086 process.load('L1Trigger.VertexFinder.l1tInputDataProducer_cfi')
0087
0088 process.load('L1Trigger.VertexFinder.l1tVertexNTupler_cfi')
0089 process.l1tVertexNTupler.l1TracksInputTag = l1TracksTag
0090
0091 if process.l1tVertexNTupler.debug == 0:
0092 process.MessageLogger.cerr.FwkReport.reportEvery = 50
0093 process.Timing = cms.Service("Timing", summaryOnly = cms.untracked.bool(True))
0094
0095 producerSum = process.l1tVertexProducer
0096 additionalProducerAlgorithms = ["fastHistoEmulation", "fastHistoLooseAssociation", "DBSCAN"]
0097 for algo in additionalProducerAlgorithms:
0098 producerName = 'VertexProducer{0}'.format(algo)
0099 producerName = producerName.replace(".","p")
0100
0101 producer = process.l1tVertexProducer.clone()
0102 producer.VertexReconstruction.Algorithm = cms.string(algo)
0103
0104 if "Emulation" in algo:
0105 if "L1GTTInputProducer" not in process.producerNames():
0106 process.load('L1Trigger.L1TTrackMatch.l1tGTTInputProducer_cfi')
0107 producer.l1TracksInputTag = cms.InputTag("l1tGTTInputProducer","Level1TTTracksConverted")
0108 producerSum = process.L1GTTInputProducer + producerSum
0109
0110 process.l1tVertexNTupler.emulationVertexInputTags.append( cms.InputTag(producerName, 'L1VerticesEmulation') )
0111 process.l1tVertexNTupler.emulationVertexBranchNames.append(algo)
0112 else:
0113 process.l1tVertexNTupler.l1VertexInputTags.append( cms.InputTag(producerName, 'L1Vertices') )
0114 process.l1tVertexNTupler.l1VertexBranchNames.append(algo)
0115 process.l1tVertexNTupler.l1VertexTrackInputs.append('hybrid')
0116
0117 setattr(process, producerName, producer)
0118 producerSum += producer
0119
0120
0121 if options.runVariations:
0122 for i in range(1, 9):
0123 dist = float(i) * 0.05
0124 for j in range(6):
0125 minPt = 2.0 + float(j) * 0.2
0126 for k in range(1, 6):
0127 minDensity = k
0128 for l in range(7):
0129 seedTrackPt = 2.0 + float(l) * 0.5
0130
0131 print()
0132 print("dist =", dist)
0133 print("minPt =", minPt)
0134 print("minDensity =", minDensity)
0135 print("seedTrkPt =", seedTrackPt)
0136
0137 producer = process.l1tVertexProducer.clone()
0138 producer.VertexReconstruction.VertexDistance = cms.double(dist)
0139 producer.VertexReconstruction.VxMinTrackPt = cms.double(minPt)
0140 producer.VertexReconstruction.DBSCANMinDensityTracks = cms.uint32(minDensity)
0141 producer.VertexReconstruction.DBSCANPtThreshold = cms.double(seedTrackPt)
0142
0143 producerName = 'VertexProducerDBSCANDist{0}minPt{1}minDensity{2}seedTrackPt{3}'.format(dist, minPt, minDensity, seedTrackPt)
0144 producerName = producerName.replace(".","p")
0145 print("producer name =", producerName)
0146 setattr(process, producerName, producer)
0147 producerNames += [producerName]
0148 process.l1tVertexNTupler.extraVertexDescriptions += ['DBSCAN(dist={0},minPt={1},minDensity={2},seedTrackPt{3})'.format(dist, minPt, minDensity, seedTrackPt)]
0149 process.l1tVertexNTupler.extraVertexInputTags.append( cms.InputTag(producerName, 'L1Vertices'))
0150 producerSum += producer
0151
0152 print("Total number of producers =", len(additionalProducerAlgorithms)+1)
0153 print(" Producers = [{0}]".format(producerSum.dumpSequenceConfig().replace('&',', ')))
0154 print(" Algorithms = [fastHisto, {0}]".format(', '.join(additionalProducerAlgorithms)))
0155
0156
0157
0158
0159 if options.memoryProfiler:
0160 process.IgProfService = cms.Service("IgProfService",
0161 reportEventInterval = cms.untracked.int32(1),
0162 reportFirstEvent = cms.untracked.int32(1),
0163 reportToFileAtPostEndJob = cms.untracked.string('| gzip -c > '+options.outputFile+'___memory___%I_EndOfJob.gz'),
0164 reportToFileAtPostEvent = cms.untracked.string('| gzip -c > '+options.outputFile+'___memory___%I.gz')
0165 )
0166
0167
0168 if options.tmi:
0169 from Validation.Performance.TimeMemoryInfo import customise
0170 process = customise(process)
0171
0172 if options.trace:
0173 process.add_(cms.Service("Tracer", dumpPathsAndConsumes = cms.untracked.bool(True)))
0174
0175
0176 process.p = cms.Path(producerSum + process.l1tTPStubValueMapProducer + process.l1tInputDataProducer + process.l1tVertexNTupler)
0177
0178
0179 if options.dump:
0180 print(process.dumpPython())
0181 sys.exit(0)