430 auto weightChoice = std::make_shared<DynamicWeightChoice>();
435 iRun.getByLabel(lheLabel, lheInfo);
441 std::vector<ScaleVarWeight> scaleVariationIDs;
442 std::vector<PDFSetWeights> pdfSetWeightIDs;
443 std::vector<std::string> lheReweighingIDs;
445 std::regex weightgroupmg26x(
"<weightgroup\\s+(?:name|type)=\"(.*)\"\\s+combine=\"(.*)\"\\s*>");
446 std::regex weightgroup(
"<weightgroup\\s+combine=\"(.*)\"\\s+(?:name|type)=\"(.*)\"\\s*>");
447 std::regex weightgroupRwgt(
"<weightgroup\\s+(?:name|type)=\"(.*)\"\\s*>");
448 std::regex endweightgroup(
"</weightgroup>");
449 std::regex scalewmg26x(
450 "<weight\\s+(?:.*\\s+)?id=\"(\\d+)\"\\s*(?:lhapdf=\\d+|dyn=\\s*-?\\d+)?\\s*((?:[mM][uU][rR]|renscfact)=\"(" 451 "\\S+)\"\\s+(?:[mM][uU][Ff]|facscfact)=\"(\\S+)\")(\\s+.*)?</weight>");
453 "<weight\\s+(?:.*\\s+)?id=\"(\\d+)\">\\s*(?:lhapdf=\\d+|dyn=\\s*-?\\d+)?\\s*((?:mu[rR]|renscfact)=(\\S+)\\s+(" 454 "?:mu[Ff]|facscfact)=(\\S+)(\\s+.*)?)</weight>");
456 "<weight\\s+id=\"(\\d+)\">\\s*(?:PDF set|lhapdf|PDF|pdfset)\\s*=\\s*(\\d+)\\s*(?:\\s.*)?</weight>");
457 std::regex pdfwOld(
"<weight\\s+(?:.*\\s+)?id=\"(\\d+)\">\\s*Member \\s*(\\d+)\\s*(?:.*)</weight>");
458 std::regex pdfwmg26x(
459 "<weight\\s+id=\"(\\d+)\"\\s*MUR=\"(?:\\S+)\"\\s*MUF=\"(?:\\S+)\"\\s*(?:PDF " 460 "set|lhapdf|PDF|pdfset)\\s*=\\s*\"(\\d+)\"\\s*>\\s*(?:PDF=(\\d+)\\s*MemberID=(\\d+))?\\s*(?:\\s.*)?</" 462 std::regex rwgt(
"<weight\\s+id=\"(.+)\">(.+)?(</weight>)?");
465 if (iter->tag() !=
"initrwgt") {
467 std::cout <<
"Skipping LHE header with tag" << iter->tag() << std::endl;
471 std::cout <<
"Found LHE header with tag" << iter->tag() << std::endl;
472 std::vector<std::string>
lines = iter->lines();
473 bool missed_weightgroup =
475 bool ismg26x =
false;
476 for (
unsigned int iLine = 0,
nLines = lines.size(); iLine <
nLines;
478 boost::replace_all(lines[iLine],
"<",
"<");
479 boost::replace_all(lines[iLine],
">",
">");
480 if (std::regex_search(lines[iLine], groups, weightgroupmg26x)) {
484 for (
unsigned int iLine = 0, nLines = lines.size(); iLine <
nLines; ++iLine) {
487 if (std::regex_search(lines[iLine], groups, ismg26x ? weightgroupmg26x : weightgroup)) {
490 groupname = groups.str(1);
492 std::cout <<
">>> Looks like the beginning of a weight group for '" << groupname <<
"'" << std::endl;
493 if (groupname.find(
"scale_variation") == 0 || groupname ==
"Central scale variation") {
495 std::cout <<
">>> Looks like scale variation for theory uncertainties" << std::endl;
496 for (++iLine; iLine <
nLines; ++iLine) {
499 if (std::regex_search(lines[iLine], groups, ismg26x ? scalewmg26x : scalew)) {
501 std::cout <<
" >>> Scale weight " << groups[1].str() <<
" for " << groups[3].str() <<
" , " 502 << groups[4].str() <<
" , " << groups[5].str() << std::endl;
503 scaleVariationIDs.emplace_back(groups.str(1), groups.str(2), groups.str(3), groups.str(4));
504 }
else if (std::regex_search(lines[iLine], endweightgroup)) {
506 std::cout <<
">>> Looks like the end of a weight group" << std::endl;
507 if (!missed_weightgroup) {
510 missed_weightgroup =
false;
511 }
else if (std::regex_search(lines[iLine], ismg26x ? weightgroupmg26x : weightgroup)) {
513 std::cout <<
">>> Looks like the beginning of a new weight group, I will assume I missed the end " 517 missed_weightgroup =
true;
522 }
else if (groupname ==
"PDF_variation" || groupname.find(
"PDF_variation ") == 0) {
524 std::cout <<
">>> Looks like a new-style block of PDF weights for one or more pdfs" << std::endl;
525 for (++iLine; iLine <
nLines; ++iLine) {
528 if (std::regex_search(lines[iLine], groups, pdfw)) {
529 unsigned int lhaID = std::stoi(groups.str(2));
531 std::cout <<
" >>> PDF weight " << groups.str(1) <<
" for " << groups.str(2) <<
" = " << lhaID
533 if (pdfSetWeightIDs.empty() || !pdfSetWeightIDs.back().maybe_add(groups.str(1), lhaID)) {
534 pdfSetWeightIDs.emplace_back(groups.str(1), lhaID);
536 }
else if (std::regex_search(lines[iLine], endweightgroup)) {
538 std::cout <<
">>> Looks like the end of a weight group" << std::endl;
539 if (!missed_weightgroup) {
542 missed_weightgroup =
false;
543 }
else if (std::regex_search(lines[iLine], ismg26x ? weightgroupmg26x : weightgroup)) {
545 std::cout <<
">>> Looks like the beginning of a new weight group, I will assume I missed the end " 549 missed_weightgroup =
true;
554 }
else if (groupname ==
"PDF_variation1" || groupname ==
"PDF_variation2") {
556 std::cout <<
">>> Looks like a new-style block of PDF weights for multiple pdfs" << std::endl;
557 unsigned int lastid = 0;
558 for (++iLine; iLine <
nLines; ++iLine) {
561 if (std::regex_search(lines[iLine], groups, pdfw)) {
562 unsigned int id = std::stoi(groups.str(1));
563 unsigned int lhaID = std::stoi(groups.str(2));
565 std::cout <<
" >>> PDF weight " << groups.str(1) <<
" for " << groups.str(2) <<
" = " << lhaID
567 if (
id != (lastid + 1) || pdfSetWeightIDs.empty()) {
568 pdfSetWeightIDs.emplace_back(groups.str(1), lhaID);
570 pdfSetWeightIDs.back().add(groups.str(1), lhaID);
573 }
else if (std::regex_search(lines[iLine], endweightgroup)) {
575 std::cout <<
">>> Looks like the end of a weight group" << std::endl;
576 if (!missed_weightgroup) {
579 missed_weightgroup =
false;
580 }
else if (std::regex_search(lines[iLine], ismg26x ? weightgroupmg26x : weightgroup)) {
582 std::cout <<
">>> Looks like the beginning of a new weight group, I will assume I missed the end " 586 missed_weightgroup =
true;
593 std::cout <<
">>> Looks like an old-style PDF weight for an individual pdf" << std::endl;
594 unsigned int firstLhaID =
lhaNameToID_.find(groupname)->second;
596 for (++iLine; iLine <
nLines; ++iLine) {
599 if (std::regex_search(lines[iLine], groups, ismg26x ? pdfwmg26x : pdfwOld)) {
600 unsigned int member = 0;
602 member = std::stoi(groups.str(2));
604 if (!groups.str(4).empty()) {
605 member = std::stoi(groups.str(4));
608 unsigned int lhaID = member + firstLhaID;
610 std::cout <<
" >>> PDF weight " << groups.str(1) <<
" for " << member <<
" = " << lhaID
614 pdfSetWeightIDs.emplace_back(groups.str(1), lhaID);
617 pdfSetWeightIDs.back().add(groups.str(1), lhaID);
619 }
else if (std::regex_search(lines[iLine], endweightgroup)) {
621 std::cout <<
">>> Looks like the end of a weight group" << std::endl;
622 if (!missed_weightgroup) {
625 missed_weightgroup =
false;
626 }
else if (std::regex_search(lines[iLine], ismg26x ? weightgroupmg26x : weightgroup)) {
628 std::cout <<
">>> Looks like the beginning of a new weight group, I will assume I missed the end " 632 missed_weightgroup =
true;
638 for (++iLine; iLine <
nLines; ++iLine) {
641 if (std::regex_search(lines[iLine], groups, endweightgroup)) {
643 std::cout <<
">>> Looks like the end of a weight group" << std::endl;
644 if (!missed_weightgroup) {
647 missed_weightgroup =
false;
648 }
else if (std::regex_search(lines[iLine], ismg26x ? weightgroupmg26x : weightgroup)) {
650 std::cout <<
">>> Looks like the beginning of a new weight group, I will assume I missed the end " 654 missed_weightgroup =
true;
660 }
else if (std::regex_search(lines[iLine], groups, weightgroupRwgt)) {
662 if (groupname ==
"mg_reweighting") {
664 std::cout <<
">>> Looks like a LHE weights for reweighting" << std::endl;
665 for (++iLine; iLine <
nLines; ++iLine) {
668 if (std::regex_search(lines[iLine], groups, rwgt)) {
671 std::cout <<
" >>> LHE reweighting weight: " << rwgtID << std::endl;
672 if (
std::find(lheReweighingIDs.begin(), lheReweighingIDs.end(), rwgtID) == lheReweighingIDs.end()) {
674 lheReweighingIDs.emplace_back(rwgtID);
676 }
else if (std::regex_search(lines[iLine], endweightgroup)) {
678 std::cout <<
">>> Looks like the end of a weight group" << std::endl;
679 if (!missed_weightgroup) {
682 missed_weightgroup =
false;
683 }
else if (std::regex_search(lines[iLine], ismg26x ? weightgroupmg26x : weightgroup)) {
685 std::cout <<
">>> Looks like the beginning of a new weight group, I will assume I missed the end " 689 missed_weightgroup =
true;
700 std::sort(scaleVariationIDs.begin(), scaleVariationIDs.end());
702 std::cout <<
"Found " << scaleVariationIDs.size() <<
" scale variations: " << std::endl;
703 std::stringstream scaleDoc;
704 scaleDoc <<
"LHE scale variation weights (w_var / w_nominal); ";
705 for (
unsigned int isw = 0, nsw = scaleVariationIDs.size(); isw < nsw; ++isw) {
706 const auto& sw = scaleVariationIDs[isw];
709 scaleDoc <<
"[" << isw <<
"] is " << sw.label;
710 weightChoice->scaleWeightIDs.push_back(sw.wid);
712 printf(
" id %s: scales ren = % .2f fact = % .2f text = %s\n",
718 if (!scaleVariationIDs.empty())
719 weightChoice->scaleWeightsDoc = scaleDoc.str();
723 std::cout <<
"Found " << pdfSetWeightIDs.size() <<
" PDF set errors: " << std::endl;
724 for (
const auto& pw : pdfSetWeightIDs)
725 printf(
"lhaIDs %6d - %6d (%3lu weights: %s, ... )\n",
729 pw.wids.front().c_str());
734 std::cout <<
"Found " << lheReweighingIDs.size() <<
" reweighting weights" << std::endl;
736 std::copy(lheReweighingIDs.begin(), lheReweighingIDs.end(), std::back_inserter(weightChoice->rwgtIDs));
738 std::stringstream pdfDoc;
739 pdfDoc <<
"LHE pdf variation weights (w_var / w_nominal) for LHA IDs ";
742 for (
const auto& pw : pdfSetWeightIDs) {
743 if (pw.lhaIDs.first !=
lhaid && pw.lhaIDs.first != (
lhaid + 1))
745 if (pw.wids.size() == 1)
747 pdfDoc << pw.lhaIDs.first <<
" - " << pw.lhaIDs.second;
748 weightChoice->pdfWeightIDs = pw.wids;
751 pdfDoc <<
", truncated to the first " <<
maxPdfWeights_ <<
" replicas";
753 weightChoice->pdfWeightsDoc = pdfDoc.str();
headers_const_iterator headers_end() const
std::unordered_map< std::string, uint32_t > lhaNameToID_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const std::vector< edm::InputTag > lheLabel_
headers_const_iterator headers_begin() const
std::atomic< bool > debugRun_
unsigned int maxPdfWeights_
std::vector< uint32_t > preferredPDFLHAIDs_