From df8416421345ba3a7e3d920edc30c914ad7d7cf2 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 31 May 2019 02:46:15 -0500 Subject: [PATCH] Add test scripts --- .../plugins/ExternalLHEProducer.cc | 13 --- .../LHEInterface/test/testWeights.py | 31 +++++++ .../LHEInterface/test/test_Weights_cfg.py | 86 +++++++++++++++++++ 3 files changed, 117 insertions(+), 13 deletions(-) create mode 100644 GeneratorInterface/LHEInterface/test/testWeights.py create mode 100644 GeneratorInterface/LHEInterface/test/test_Weights_cfg.py diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 345fec6bd5917..354a34e75e9f9 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -213,17 +213,7 @@ ExternalLHEProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) int weightNum = 0; for (const auto& weight : partonLevel->weights()) { weightGroupIndex = findWeightGroup(weight.id, weightNum, weightGroupIndex); - std::cout << "Weight group index" << weightGroupIndex << std::endl; - std::cout << weightGroups_.at(1).name() << std::endl; - if (weightGroupIndex < 0) { - std::cout << "Yep that's the case."; - std::cout << " num Contained IDs " << weightGroups_.at(1).containedIds().size() << std::endl; - for (auto& id : weightGroups_.at(1).containedIds()) - std::cout << id.id; - } int entry = weightGroups_.at(weightGroupIndex).weightVectorEntry(weight.id, weightNum); - std::cout << "Matching entry is " << entry; - std::cout << "Still going. Entry is " << entry << std::endl; weightProduct->addWeight(weight.wgt, weightGroupIndex, entry); weightNum++; } @@ -365,7 +355,6 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) for (auto& pdfSet : pdfSets) weightInfoProduct->addWeightGroupInfo(pdfSet); weightGroups_ = weightInfoProduct->allWeightGroupsInfo(); - std::cout << "Number of groups is " << weightGroups_.size() << std::endl; run.put(std::move(weightInfoProduct)); nextEvent(); @@ -543,7 +532,6 @@ ExternalLHEProducer::executeScript() int ExternalLHEProducer::findWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex) { // Start search at previous index, under expectation of ordered weights - std::cout << "Here we are"; for (int index = previousGroupIndex; index < std::min(index+1, static_cast(weightGroups_.size())); index++) { auto& weightGroup = weightGroups_.at(previousGroupIndex); @@ -551,7 +539,6 @@ int ExternalLHEProducer::findWeightGroup(std::string wgtId, int weightIndex, int if (weightGroup.indexInRange(weightIndex) && weightGroup.containsWeight(wgtId, weightIndex)) return static_cast(index); } - std::cout << "Done"; // Fall back to unordered search int counter = 0; diff --git a/GeneratorInterface/LHEInterface/test/testWeights.py b/GeneratorInterface/LHEInterface/test/testWeights.py new file mode 100644 index 0000000000000..12e2961868af9 --- /dev/null +++ b/GeneratorInterface/LHEInterface/test/testWeights.py @@ -0,0 +1,31 @@ +from DataFormats.FWLite import Events,Handle,Runs +source = "externalLHEProducer" + +#for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"," HIG-RunIIFall18wmLHEGS-00509_ordered.root","HIG-RunIIFall18wmLHEGS-00509_unordered.root"]: +for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"]: + runs = Runs(filename) + run = runs.__iter__().next() + weightInfoHandle = Handle("LHEWeightInfoProduct") + run.getByLabel(source, weightInfoHandle) + weightInfoProd = weightInfoHandle.product() + + events = Events(filename) + event = events.__iter__().next() + weightHandle = Handle("LHEWeightProduct") + event.getByLabel("externalLHEProducer", weightHandle) + event.getByLabel(source, weightHandle) + weightInfo = weightHandle.product() + print "Content of the weights" + for j, weights in enumerate(weightInfo.weights()): + print "-"*10, "Looking at entry", j, "length is", len(weights),"-"*10 + matching = weightInfoProd.orderedWeightGroupInfo(j) + print "Weights length?", len(weights), "Contained ids lenths?", len(matching.containedIds()) + print "-"*80 + for i,weight in enumerate(weights): + print i, weight + info = matching.weightMetaInfo(i) + print " ID, localIndex, globalIndex, label, set:", info.id, info.localIndex, info.globalIndex, info.label, matching.name() + print "-"*80 + + + diff --git a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py new file mode 100644 index 0000000000000..aeb7882932c6e --- /dev/null +++ b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py @@ -0,0 +1,86 @@ +# Auto generated configuration file +# using: +# Revision: 1.19 +# Source: /local/reps/CMSSW/CMSSW/Configuration/Applications/python/ConfigBuilder.py,v +# with command line options: Configuration/GenProduction/python/HIG-RunIIFall18wmLHEGS-00509-fragment.py --fileout file:HIG-RunIIFall18wmLHEGS-00509.root --mc --eventcontent LHE --datatier LHE --conditions 102X_upgrade2018_realistic_v11 --step LHE --python_filename HIG-RunIIFall18wmLHEGS-00509_1_cfg.py --no_exec +import FWCore.ParameterSet.Config as cms + + + +process = cms.Process('LHE') + +# import of standard configurations +process.load('Configuration.StandardSequences.Services_cff') +process.load('SimGeneral.HepPDTESSource.pythiapdt_cfi') +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.EventContent.EventContent_cff') +process.load('SimGeneral.MixingModule.mixNoPU_cfi') +process.load('Configuration.StandardSequences.GeometryRecoDB_cff') +process.load('Configuration.StandardSequences.MagneticField_cff') +process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(10) +) + +# Input source +process.source = cms.Source("EmptySource") + +process.options = cms.untracked.PSet( + +) + +# Production Info +process.configurationMetadata = cms.untracked.PSet( + annotation = cms.untracked.string('Configuration/GenProduction/python/HIG-RunIIFall18wmLHEGS-00509-fragment.py nevts:10'), + name = cms.untracked.string('Applications'), + version = cms.untracked.string('$Revision: 1.19 $') +) + +# Output definition + +process.LHEoutput = cms.OutputModule("PoolOutputModule", + dataset = cms.untracked.PSet( + dataTier = cms.untracked.string('LHE'), + filterName = cms.untracked.string('') + ), + fileName = cms.untracked.string('file:HIG-RunIIFall18wmLHEGS-00509.root'), + #outputCommands = process.LHEEventContent.outputCommands, + outputCommands = cms.untracked.vstring('keep *', + 'drop ME*_MEtoEDM*_*_*'), + splitLevel = cms.untracked.int32(0) +) + +# Additional output definition + +# Other statements +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, '102X_upgrade2018_realistic_v11', '') + +process.externalLHEProducer = cms.EDProducer("ExternalLHEProducer", + args = cms.vstring('/afs/hep.wisc.edu/home/kdlong/public/DarkMatter_MonoZPrime_V_Mx50_Mv500_gDMgQ1_LO_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), + nEvents = cms.untracked.uint32(10), + numberOfParameters = cms.uint32(1), + outputFile = cms.string('cmsgrid_final.lhe'), + scriptName = cms.FileInPath('GeneratorInterface/LHEInterface/data/run_generic_tarball_cvmfs.sh') +) + + +# Path and EndPath definitions +process.lhe_step = cms.Path(process.externalLHEProducer) +process.endjob_step = cms.EndPath(process.endOfProcess) +process.LHEoutput_step = cms.EndPath(process.LHEoutput) + +# Schedule definition +process.schedule = cms.Schedule(process.lhe_step,process.endjob_step,process.LHEoutput_step) +from PhysicsTools.PatAlgos.tools.helpers import associatePatAlgosToolsTask +associatePatAlgosToolsTask(process) + + +# Customisation from command line + +# Add early deletion of temporary data products to reduce peak memory need +from Configuration.StandardSequences.earlyDeleteSettings_cff import customiseEarlyDelete +process = customiseEarlyDelete(process) +# End adding early deletion