From f1a3ae406e49d6c904e27d83efa3050452aeb96b Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Wed, 11 Sep 2019 08:53:53 -0400 Subject: [PATCH] A bit of cleanup --- .../interface/LHEWeightGroupReaderHelper.h | 122 ++++++------------ .../LHEInterface/test/test_Weights_cfg.py | 3 +- 2 files changed, 38 insertions(+), 87 deletions(-) diff --git a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h index 38315664782aa..893c528e20379 100644 --- a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h +++ b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h @@ -155,63 +155,13 @@ LHEWeightGroupReaderHelper::isAWeight(std::string line) { XMLDocument xmlParser; int error = xmlParser.Parse(line.c_str()); if (error) { - return false; - //do something.... + return false; + //do something.... } XMLElement* element = xmlParser.FirstChildElement(); return element; } -// void -// LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { -// std::ifstream file; -// file.open(filename); - -// std::string line; -// std::smatch matches; -// // TODO: Not sure the weight indexing is right here, this seems to more or less -// // count the lines which isn't quite the goal. TOCHECK! -// int index = 0; -// while(getline(file, line)) { -// if(std::regex_match(line, weightGroupStart_)) { -// std::string name = getMap_testAll(line, {weightGroupInfo})["name"]; - -// //TODO: Fine for now, but in general there should also be a check on the PDF weights, -// // e.g., it could be an unknown weight - -// if(std::regex_match(name, scaleWeightMatch_)) { -// weightGroups_.push_back(new gen::ScaleWeightGroupInfo(line)); -// std::cout << "scale weight" << "\n"; -// } - - -// else -// weightGroups_.push_back(new gen::PdfWeightGroupInfo(line)); - -// /// file weights -// while(getline(file, line) && !std::regex_match(line, weightGroupEnd_)) { -// auto tagsMap = getMap_testAll(line, regexOptions); - -// std::regex_search(line, matches, weightContent_); -// // TODO: Add proper check that it worked -// std::string content = matches[1].str(); - -// auto& group = weightGroups_.back(); -// if (group.weightType() == gen::kScaleWeights) { -// float muR = std::stof(tagsMap["mur"]); -// float muF = std::stof(tagsMap["muf"]); -// auto& scaleGroup = static_cast(group); -// scaleGroup.addContainedId(index, tagsMap["id"], line, muR, muF); -// } -// else -// group.addContainedId(index, tagsMap["id"], line); - -// index++; -// } -// } -// } -// } - void LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector lheHeader) { // TODO: Not sure the weight indexing is right here, this seems to more or less @@ -220,11 +170,11 @@ LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector bool foundGroup = false; for (std::string headerLine : lheHeader) { - std::cout << "Header line is:" << headerLine; - headerLine = sanitizeText(headerLine); - std::cout << "Header line is:" << weightGroups_.size() << " "<< headerLine; - //TODO: Fine for now, but in general there should also be a check on the PDF weights, - // e.g., it could be an unknown weight + std::cout << "Header line is:" << headerLine; + headerLine = sanitizeText(headerLine); + std::cout << "Header line is:" << weightGroups_.size() << " "<< headerLine; + //TODO: Fine for now, but in general there should also be a check on the PDF weights, + // e.g., it could be an unknown weight if (std::regex_match(headerLine, weightGroupStart_)) { //std::cout << "Adding new group for headerLine" << std::endl; @@ -235,62 +185,62 @@ LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector if(name.find("Central scale variation") != std::string::npos || name.find("scale_variation") != std::string::npos) { - weightGroups_.push_back(new gen::ScaleWeightGroupInfo(headerLine)); - std::cout << "scale weight" << "\n"; + weightGroups_.push_back(new gen::ScaleWeightGroupInfo(name)); } - else - weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); + else + weightGroups_.push_back(new gen::PdfWeightGroupInfo(name)); } /// file weights else if (foundGroup && isAWeight(headerLine)) { //std::cout << "Adding new weight for headerLine" << std::endl; auto tagsMap = getAttributeMap(headerLine); - for(auto pair: tagsMap) { - std::cout << pair.first << ": " << pair.second << " | "; - } + for(auto pair: tagsMap) { + std::cout << pair.first << ": " << pair.second << " | "; + } std::cout << "\n"; std::string content = tagsMap["content"]; - if (tagsMap["id"] == std::string()) { + if (tagsMap["id"].empty()) { std::cout << "error" << "\n"; // should do something } auto& group = weightGroups_.back(); if (group.weightType() == gen::kScaleWeights) { - if (tagsMap["mur"] == std::string() || tagsMap["muf"] == std::string()) { + if (tagsMap["mur"].empty() || tagsMap["muf"].empty()) { std::cout << "error" << "\n"; // something should happen here - continue; + continue; } float muR = std::stof(tagsMap["mur"]); float muF = std::stof(tagsMap["muf"]); std::cout << tagsMap["id"] << " " << muR << " " << muF << " " << content << "\n"; auto& scaleGroup = static_cast(group); - scaleGroup.addContainedId(index, tagsMap["id"], headerLine, muR, muF); + scaleGroup.addContainedId(index, tagsMap["id"], headerLine, muR, muF); } else group.addContainedId(index, tagsMap["id"], headerLine); + index++; - } - // commented out since code doesn't work with this in.... - // else if(isAWeight(headerLine)) { - // // found header. Don't know what to do with it so just shove it into a new weightgroup for now - // // do minimum work for it - // weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); - // auto& group = weightGroups_.back(); - // auto tagsMap = getAttributeMap(headerLine); - // group.addContainedId(index, tagsMap["id"], headerLine); - // foundGroup = true; - // index++; - // } + } + // commented out since code doesn't work with this in.... + // else if(isAWeight(headerLine)) { + // // found header. Don't know what to do with it so just shove it into a new weightgroup for now + // // do minimum work for it + // weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); + // auto& group = weightGroups_.back(); + // auto tagsMap = getAttributeMap(headerLine); + // group.addContainedId(index, tagsMap["id"], headerLine); + // foundGroup = true; + // index++; + // } - else if(std::regex_match(headerLine, weightGroupEnd_)) { - foundGroup = false; - } - else { - std::cout << "problem!!!" << "\n"; - } + else if(std::regex_match(headerLine, weightGroupEnd_)) { + foundGroup = false; + } + else { + std::cout << "problem!!!" << "\n"; + } } } diff --git a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py index bef001d3972f3..fb6a1f58c66b4 100644 --- a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py +++ b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py @@ -59,7 +59,8 @@ process.GlobalTag = GlobalTag(process.GlobalTag, '102X_upgrade2018_realistic_v11', '') process.externalLHEProducer = cms.EDProducer("ExternalLHEProducer", - args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/WLLJJ_WToLNu_EWK_4F_MLL-60_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), + #args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/WLLJJ_WToLNu_EWK_4F_MLL-60_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), + args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/ZZ_4L_NNPDF30_13TeV_tarballDummy.tar.gz'), nEvents = cms.untracked.uint32(10), numberOfParameters = cms.uint32(1), outputFile = cms.string('cmsgrid_final.lhe'),