Skip to content

Commit

Permalink
Add test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
kdlong committed May 31, 2019
1 parent bb431b7 commit df84164
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 13 deletions.
13 changes: 0 additions & 13 deletions GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -543,15 +532,13 @@ 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<int>(weightGroups_.size())); index++) {
auto& weightGroup = weightGroups_.at(previousGroupIndex);
// Fast search assuming order is not perturbed outside of weight group
if (weightGroup.indexInRange(weightIndex) && weightGroup.containsWeight(wgtId, weightIndex))
return static_cast<int>(index);
}
std::cout << "Done";

// Fall back to unordered search
int counter = 0;
Expand Down
31 changes: 31 additions & 0 deletions GeneratorInterface/LHEInterface/test/testWeights.py
Original file line number Diff line number Diff line change
@@ -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



86 changes: 86 additions & 0 deletions GeneratorInterface/LHEInterface/test/test_Weights_cfg.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit df84164

Please sign in to comment.