Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
234 commits
Select commit Hold shift + click to select a range
208a4a3
Adding first outlines of weight products
kdlong May 28, 2019
0a8810e
Close to an outline, not working for LHESource
kdlong May 29, 2019
7cfc2fe
Working skeleton of LHEWeightInfoProduct
kdlong May 29, 2019
444dbc3
About a working outline with weights in the event
kdlong May 30, 2019
49c25ba
Working rough implementation of Weight/WeightInfo prods
kdlong May 30, 2019
bb431b7
Fix bug in insert to containedIds for WeightGroup
kdlong May 31, 2019
df84164
Add test scripts
kdlong May 31, 2019
23bee66
Store pointers to WeightGroupInfo
kdlong Aug 5, 2019
0ba28e0
Compiles with OwnVector, but need a proper copy constructor
kdlong Aug 6, 2019
9ba9510
Working with edm::OwnVector
kdlong Aug 6, 2019
338a979
Separate WeightGroupInfo into .h and .cc files
kdlong Aug 7, 2019
8397fca
Separate out PDF weights
kdlong Aug 7, 2019
9e06271
Add scale-specific weightgroupinfo class
kdlong Aug 15, 2019
071c069
First tests with parsing of lhe file. Need to incorp EDM lhe reader
dteague Aug 15, 2019
f44363c
Merge pull request #2 from dteague/Gen_parsing
kdlong Aug 15, 2019
6bfea57
fixing readerhelper problems
dteague Aug 15, 2019
9696885
Merge pull request #3 from dteague/Gen_parsing
kdlong Aug 15, 2019
f62468c
Working on parsing integration with scale/pdf weights
kdlong Aug 15, 2019
28f0ba2
Fixing little bit of readerhelper to change things to non-ptrs
dteague Aug 16, 2019
db06b18
Random commit before merge: only spacing diffs -_-
dteague Aug 16, 2019
71629cd
Read header info from headers in externalLHEProducer
kdlong Aug 28, 2019
cf10a6b
Merge branch 'GenWeightRefactor' of https://github.com/kdlong/cmssw i…
dteague Aug 28, 2019
fbf495c
Merge branch 'GenWeightRefactor' of https://github.com/kdlong/cmssw i…
dteague Aug 28, 2019
c98a078
added Regex helper class and put under (kinda silly) namespace
dteague Sep 2, 2019
de0ad7a
Fix problem with instantiating Scale/PdfWeightInfo to file
kdlong Sep 2, 2019
59691bc
Add an alternative sample for testing
kdlong Sep 3, 2019
1c1da76
Slight cleanup to naming and weightgroup type
kdlong Sep 3, 2019
057cb83
Merge remote-tracking branch 'dylan/Gen_parsing' into dteague-Gen_par…
kdlong Sep 3, 2019
80cde77
Fixed small error in names of RegexCreater, should run on new gridp
dteague Sep 4, 2019
41f2e17
Merge remote-tracking branch 'dylan/Gen_parsing' into dteague-Gen_par…
kdlong Sep 4, 2019
33e2466
Remove bloated comments
kdlong Sep 4, 2019
f1bcab0
Merge branch 'dteague-Gen_parsing' into GenWeightRefactor
kdlong Sep 4, 2019
9baeee2
overhaul of code: now works with tinyxml2 instead of regex
dteague Sep 6, 2019
1038e0d
testing helper stuff as comments
dteague Sep 6, 2019
b4b08c9
Merge branch 'GenWeightRefactor' of https://github.com/kdlong/cmssw i…
dteague Sep 6, 2019
f1a3ae4
A bit of cleanup
kdlong Sep 11, 2019
1bb40ac
Merge pull request #5 from dteague/Gen_parsing
kdlong Sep 18, 2019
1e81c15
Merge branch 'GenWeightRefactor' of https://github.com/kdlong/cmssw i…
kdlong Sep 18, 2019
79efbe6
Adding a dummy analyzer for weights, need to clean up organization
kdlong Sep 18, 2019
07eb97a
Use dynamic cast, but then it segfaults
kdlong Sep 18, 2019
5668f0d
Incorporate changes to make OwnVector work
kdlong Sep 20, 2019
8c0c98e
Fix setting of ScaleWeight indices
kdlong Sep 20, 2019
8744839
Add unknown weightgroup
kdlong Sep 20, 2019
682ac14
Start to move parsing tools to GeneratorInterface/Core
kdlong Sep 20, 2019
037f6f9
Move LHE reader to .h and .cc files, rename
kdlong Sep 21, 2019
a78163b
Separate WeightHelper into base and daughter classes
kdlong Sep 21, 2019
b6e3285
Producer or MiniAOD is finally working
kdlong Sep 23, 2019
c82792f
Add outline of Zplotter (from Andreas) with weights implemented
kdlong Sep 24, 2019
ffd0503
Working example of plotting code reading weight products
kdlong Sep 24, 2019
c535b55
Rename LHEWeight-->GenWeight to have same product for LHE and GEN
kdlong Oct 3, 2019
3e48617
Add parton shower weights class
kdlong Oct 3, 2019
176adbf
Simple version of GEN producer working
kdlong Oct 3, 2019
acc3817
Fix nasty bug searching for weights by index
kdlong Oct 3, 2019
27a9239
Clean up test script for LHE weights a bit
kdlong Oct 4, 2019
7402487
Start to implement useful functions for PdfGroupInfo
kdlong Oct 4, 2019
b744a77
Put product in lumi instead of run
kdlong Oct 4, 2019
a30dacf
Some cleanup + nasty bug fix in lhapdfIds
kdlong Oct 6, 2019
2b1b520
Remove dummy analyzer
kdlong Oct 7, 2019
d307670
Move example weight test producer
kdlong Oct 7, 2019
bbdd462
Add PDF and PS weights in example
kdlong Oct 7, 2019
916af26
Make the test script more general
kdlong Oct 8, 2019
70cdb97
New LHEWeightsTableProducer
guitargeek Dec 19, 2019
205de35
Variable number of produced flat tables
guitargeek Dec 19, 2019
d663d2f
select specific weight groups
guitargeek Dec 19, 2019
45be54a
give a bit more structure to weight counter class
guitargeek Dec 20, 2019
c4cd203
Merged NanoGen_11_0_0_pre11 from repository guitargeek with cms-merge…
kdlong Dec 24, 2019
dd34a14
Merged GenWeightRefactor from repository kdlong with cms-merge-topic
kdlong Dec 24, 2019
c545dec
Remove some customization to make it compile
kdlong Dec 25, 2019
d6c2452
Remove duplicate text from merge
kdlong Dec 26, 2019
a4e2b7a
Fix mistake in getting weightMetaInfo by index
kdlong Dec 28, 2019
9f6b791
Add outline of ME reweight weightinfo class
kdlong Dec 29, 2019
afe662a
Add MEParams class, nanogen example config
kdlong Dec 29, 2019
6c5900c
Roughly working with Run, need to move to lumi
kdlong Jan 4, 2020
fb19c05
Produce in beginLumi, working with scale and NanoGen
kdlong Jan 5, 2020
ae40865
Example with both scale and ME weights
kdlong Jan 5, 2020
e542eaa
Improve organization of adding different weight types
kdlong Jan 6, 2020
ca22fc5
Close to working, but segfaulting
kdlong Jan 10, 2020
8fcc230
Update weighttype, read storage info from config
kdlong Jan 11, 2020
3dbdd4c
Correct name of shower weights so they're stored
kdlong Jan 11, 2020
265e6a0
Store normalized weights from the start, cleanup
kdlong Jan 16, 2020
6aaef39
Make pdfIds untracked
kdlong Jan 17, 2020
6ccee5d
Working implementation producing new prod if needed
kdlong Jan 17, 2020
884dc84
Remove test analyzers
kdlong Jan 17, 2020
9bd87c7
Remove dummy weights function
kdlong Jan 18, 2020
7daba24
Significant restructure of parsing
kdlong Jan 19, 2020
419a1cd
Update lheWeights config
kdlong Jan 20, 2020
a2912ec
First stab at cmsDriver NanoGEN
kdlong Jan 23, 2020
9dbe118
Save lheWeightsTable in Nano
kdlong Jan 25, 2020
3c6dd94
Towards separating PDFs into new groups
kdlong Jan 26, 2020
1e31de3
cmsDriver from Mini input
kdlong Feb 1, 2020
f4164f8
Don't save HLT stuff for NanoGen
kdlong Feb 1, 2020
902adbd
Merged ImprovedParsing from repository kdlong with cms-merge-topic
kdlong Feb 6, 2020
13e2347
Merged PhotosHistory from repository intrepid42 with cms-merge-topic
kdlong Feb 6, 2020
ba650b1
Store LHE particles in NanoGen, false by default for some reason
kdlong Feb 7, 2020
8c2927e
Clang format on all weight refactor files
kdlong May 20, 2020
0e63151
changed LHEsource so it compiles, running tests now
dteague Feb 10, 2020
a9b0814
Merge branch 'dylanUpdatesReformat' into ImprovedParsingMerge
kdlong May 20, 2020
7ea1ea4
Revert LHE source
kdlong May 20, 2020
6d6b77f
Dylan's improvements of weight parsing
dteague Feb 10, 2020
1433652
Merge pull request #12 from kdlong/dylanUpdatesMergeTry2
kdlong May 20, 2020
10d5cec
Add script to test which weights are in Nano
kdlong May 20, 2020
07b777d
Fix PS weight name in test script
kdlong May 20, 2020
e663e72
Fix parsing issue with pdfweights in certain files
May 21, 2020
b3a0c6c
Remove PdfSetInfo in favor of LHAPDF library
May 21, 2020
f8a67ef
Refactor pdfweight so pdfweights are always split
May 21, 2020
41ede97
Print out desciption in test script
kdlong May 21, 2020
d81c38c
Simplify ScaleWeight structure in anticipation of dyn weight changes
May 26, 2020
5ddf52d
Add dynWeights to scaleWeightInfo. Can improve code (basic refactor)
May 26, 2020
4e333a2
Add Pdf info to pdfWeights (size, type) & check of size consistency
May 26, 2020
f9b8222
Add orphaned pdf weight into scale weight missing central index
May 26, 2020
6cd57c6
Merge pull request #13 from dteague/ImprovedParsing_moreImproved
kdlong May 28, 2020
d896def
Merge remote-tracking branch 'kdlong/ImprovedParsingMerge' into Impro…
kdlong May 28, 2020
9e07f4d
Merge branch 'ImprovedParsing' of github.com:kdlong/cmssw into Improv…
kdlong May 28, 2020
c1060be
Merged ImprovedParsing from repository kdlong with cms-merge-topic
kdlong Jul 6, 2020
2171761
Remove Test folder
kdlong Jul 6, 2020
c025448
Temporarily force foundProduct = false for lheWeights
kdlong Jul 7, 2020
2c0719e
Avoid failure when there are no PS weights
kdlong Jul 9, 2020
8eeaff3
Add back check for weightproduct in file
kdlong Jul 9, 2020
341cef7
Remove cuts on dressed leptons
kdlong Jul 20, 2020
fbccb5f
Update ouptut modules
kdlong Jul 22, 2020
80ad1d0
Fix bug breaking parton shower weights
kdlong Jul 22, 2020
808d586
Restore check on weightNames for gen weights
kdlong Jul 22, 2020
d69abeb
Fix orphaned central scale problem. was resizing to 1 (not great)
Jul 29, 2020
31043ca
Simplify logic of adding to make less opaque
Jul 29, 2020
baeb16f
Merge pull request #15 from dteague/from-CMSSW_11_1_0_pre2
kdlong Jul 29, 2020
8db5166
Move weight building logic to WeightHelper so GEN can use it
Jul 30, 2020
3bbd4de
Add basic GenLevel parsing. Works on ZGTo2NuG test file
Jul 30, 2020
f295287
Modified nanoAOD modules to produce the whole LHE info (optionally, c…
Jul 30, 2020
74c66a6
Undo several changes introduced when porting the cfg
Jul 30, 2020
4b2d18c
And add a missing import
Jul 30, 2020
ba5be6c
Add PartonShower parsing for GenWeights
Jul 31, 2020
21e251a
Change PartonShower filename to match h file
Jul 31, 2020
34306be
Merge pull request #17 from cericeci/ImprovedParsing
kdlong Aug 1, 2020
35b32c4
Merge branch 'ImprovedParsing' into ImprovedParsingMerge
kdlong Aug 1, 2020
3180b59
Don't fail if there are no LHE weights
kdlong Aug 1, 2020
2622c40
Fix mistake in making LHE weights optional
kdlong Aug 3, 2020
4d24963
Fix mistake in TableOutputBranches port
kdlong Aug 3, 2020
c5fa5ed
Allow weights out of order to be added to same group
kdlong Aug 3, 2020
d057424
LHEWeightsProducer doesn't fail if no LHE weights
kdlong Aug 3, 2020
260d8d4
Merge pull request #16 from dteague/from-CMSSW_11_1_0_pre2
kdlong Aug 3, 2020
801700a
Use boost trim
kdlong Aug 3, 2020
0f1a1ac
Don't fail if there are no LHE weights
kdlong Aug 1, 2020
8733008
Fix mistake in making LHE weights optional
kdlong Aug 3, 2020
1e647bc
Fix mistake in TableOutputBranches port
kdlong Aug 3, 2020
d3c6755
Allow weights out of order to be added to same group
kdlong Aug 3, 2020
20f2634
LHEWeightsProducer doesn't fail if no LHE weights
kdlong Aug 3, 2020
70ef7d8
Use boost trim
kdlong Aug 3, 2020
e159802
Merge remote-tracking branch 'my-cmssw/ImprovedParsingMerge' into Imp…
kdlong Aug 3, 2020
d9a125f
Merge pull request #19 from kdlong/ImprovedParsingMerge
kdlong Aug 4, 2020
4ff6aa0
Add option for raising expection if XML is not valid
Aug 4, 2020
4570e6f
Merge pull request #18 from dteague/validXML
kdlong Aug 6, 2020
5fffa1d
Remove test files
kdlong Aug 6, 2020
c5de61f
Fix parsing of PartonShower name in GenWeights
Aug 11, 2020
8357fff
Add basic MEParam weight functionality
Aug 11, 2020
7a76898
Allow for general adding of params to vector
Aug 14, 2020
dae4595
Merged ImprovedParsing from repository kdlong with cms-merge-topic
sroychow Aug 18, 2020
70ed249
Fix parsing of PartonShower name in GenWeights
Aug 11, 2020
a671e7d
Fix failure in mass weights
kdlong Aug 19, 2020
19230f9
Simplify some features of PS and ME groups
kdlong Aug 20, 2020
d7971cd
Merge branch 'me_weight' into ImprovedParsingMEWeights
kdlong Aug 20, 2020
a91bdf2
updates to allow saving weight sums from all weight categories
sroychow Aug 21, 2020
63eba91
Merge pull request #1 from kdlong/ImprovedParsingMEWeights
dteague Aug 24, 2020
57b20d3
Merge pull request #24 from dteague/me_weight
kdlong Aug 24, 2020
19e832c
Merge pull request #2 from kdlong/ImprovedParsing
sroychow Aug 24, 2020
3f41984
adding option to save preferred PS weights
sroychow Aug 24, 2020
08d13ff
Merged ImprovedParsing from repository kdlong with cms-merge-topic
sroychow Aug 30, 2020
d9d1d51
Merged ImprovedParsing from repository sroychow with cms-merge-topic
sroychow Aug 30, 2020
a073bf0
changing weight table producer to write individual tables for weight …
sroychow Sep 28, 2020
8ca625f
Parton shower weights handle new naming scheme
kdlong Oct 4, 2020
f46cc33
Add isWellFormed check for scale weights to helper class
kdlong Oct 4, 2020
c23d680
Merge pull request #3 from kdlong/ImprovedParsingNano
sroychow Oct 5, 2020
41c79e2
Create entry for unassociated weights if empty
kdlong Oct 5, 2020
5d2297c
Use unique_ptr rather than raw ptrs
kdlong Oct 6, 2020
b504240
Add unassociated group for LHE
kdlong Oct 6, 2020
fb256af
Refactor ScaleWeightGroup to simplify codebase
Oct 13, 2020
cf688ff
Remove/change lines in WeightHelper to clean
Oct 13, 2020
701df45
Fix naming problems in ScaleWeight
Oct 13, 2020
160c925
Refactor LHWeightHelper (moved to helper functions)
Oct 13, 2020
fe416e3
Fix errors in ScaleWeight and add print statements for debug
Oct 14, 2020
a238612
Add more error handling
Oct 14, 2020
05fb6d7
Fix off-by-one error in pdf weight splitting
Oct 14, 2020
2c3d767
Templatize product adder in WeightHelper
Oct 15, 2020
c6e91dc
Expand emission functionality to PSWeight
Oct 15, 2020
ef90c03
adding altset index table
sroychow Nov 3, 2020
96ecb93
resolve conflicts
sroychow Nov 3, 2020
34b9c3a
Create entry for unassociated weights if empty
kdlong Oct 5, 2020
5613cf6
Use unique_ptr rather than raw ptrs
kdlong Oct 6, 2020
7deaad9
Add unassociated group for LHE
kdlong Oct 6, 2020
58340d5
Merge branch 'dylanImprovedParsing' into ImprovedParsingNano
kdlong Nov 3, 2020
f381ae8
Use cms::Exception, more detailed error reporting
kdlong Nov 3, 2020
93ecbf8
Make debugging configurable, fix bug with adding weights in nano
kdlong Nov 3, 2020
601b090
Fix gcc7 error
kdlong Nov 3, 2020
4f453a6
resolving conflicts in 11_2
sroychow Nov 3, 2020
099b683
Weights table is not pretty but at least it's not broken
kdlong Nov 4, 2020
ae87760
Don't pass pointers, clearer naming in LHE tables
kdlong Nov 4, 2020
1069aa6
resolve conflict in nanogen config
sroychow Nov 4, 2020
cb6ef7d
Merged ImprovedParsingNano from repository sroychow with cms-merge-topic
sroychow Nov 4, 2020
71f1387
changes to resolve conflicts part1
sroychow Nov 5, 2020
882f046
resolve compile errors
sroychow Nov 5, 2020
4719048
resolve dependency
sroychow Nov 5, 2020
76b867c
resolve code check and format issues
sroychow Nov 5, 2020
a83a25d
Merged ImprovedParsingNano from repository sroychow with cms-merge-topic
kdlong Nov 5, 2020
e1539ba
Avoid make_unique and be careful copying
kdlong Nov 4, 2020
bd9d3dd
Convert make_unique(...) into unique_ptr(...clone())
Nov 5, 2020
49b5d2b
USe cms::Exception, little bit of cleanup
kdlong Nov 6, 2020
2a4145e
change way PS weights handled
Oct 27, 2020
5882832
Allow for finding missing weights
Oct 27, 2020
8d190ac
Fix error with gap fixing code
Oct 27, 2020
89877ad
Change around logic to have bool to decide if use guess for PS
Nov 3, 2020
c5d57f8
Amend wellformed logic for scaleweight
Nov 3, 2020
db98fc4
Cleanup code
Nov 9, 2020
8f74a2c
Revert accidental changes
kdlong Nov 12, 2020
48fcabd
Move GenWeightsTableProducer, reorganize
kdlong Nov 12, 2020
71259a4
Merge branch 'psWeightMaster' into GenWeightRefactor_merge
kdlong Nov 12, 2020
f4ae659
Merge branch 'GenWeightRefactor_merge' into GenWeightRefactor_master
kdlong Nov 12, 2020
d3be328
Fix formatting
kdlong Nov 12, 2020
20ef60f
Merged GenWeightRefactor_master from repository kdlong with cms-merge…
kdlong Nov 17, 2020
70855a9
code format
kdlong Nov 17, 2020
30ae52f
Code format
kdlong Nov 17, 2020
45323bb
Fix merge mistakes
kdlong Nov 18, 2020
b009ea6
Merged refs/pull/32167/head from repository cms-sw with cms-merge-topic
sroychow Nov 18, 2020
7553ecb
fixing issues in build
sroychow Nov 18, 2020
f672f46
moving throw to exception
sroychow Nov 18, 2020
752f300
Merge pull request #41 from sroychow/genrefactor_clonekdlong
kdlong Nov 18, 2020
999faba
Merged GenWeightRefactor_master from repository kdlong with cms-merge…
SanghyunKo Nov 20, 2020
7fd9c2c
attempt to delete extra kets after the last </weightgroup>
SanghyunKo Nov 20, 2020
0ef65ec
fix runtime error
SanghyunKo Nov 20, 2020
3db8cfc
failIfInvalidXML_ cleanup
SanghyunKo Nov 20, 2020
5db30d3
failIfInvalidXML_ cleanup (2)
SanghyunKo Nov 21, 2020
26e4edd
scram b code-format
SanghyunKo Nov 24, 2020
d09e64d
Merge pull request #43 from SanghyunKo/GenWeightRefactor_master
kdlong Nov 24, 2020
239fa5d
fix Sherpa crashes
SanghyunKo Nov 26, 2020
6036cab
code-formats
SanghyunKo Nov 26, 2020
a28751a
prevent underflow
SanghyunKo Nov 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DataFormats/NanoAOD/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<class name="nanoaod::FlatTable::RowView" transient="true" />
<class name="edm::Wrapper<nanoaod::FlatTable>" />

<class name="edm::Wrapper<std::vector<nanoaod::FlatTable>>" />
<class name="std::vector<nanoaod::FlatTable>" />

<class name="nanoaod::MergeableCounterTable::FloatColumn" ClassVersion="3">
<version ClassVersion="3" checksum="828208870"/>
</class>
Expand Down
1 change: 1 addition & 0 deletions GeneratorInterface/Core/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<use name="lhapdf"/>
<use name="f77compiler"/>
<use name="root"/>
<use name="tinyxml2"/>
<export>
<lib name="1"/>
</export>
26 changes: 26 additions & 0 deletions GeneratorInterface/Core/interface/GenWeightHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef GeneratorInterface_Core_GenWeightHelper_h
#define GeneratorInterface_Core_GenWeightHelper_h

#include <string>
#include <vector>
#include <map>
#include <regex>
#include <fstream>

#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/GenLumiInfoProduct.h"
#include "GeneratorInterface/Core/interface/WeightHelper.h"

#include <tinyxml2.h>

namespace gen {
class GenWeightHelper : public WeightHelper {
public:
GenWeightHelper();
void parseWeightGroupsFromNames(std::vector<std::string> weightNames);
};
} // namespace gen

#endif
45 changes: 45 additions & 0 deletions GeneratorInterface/Core/interface/LHEWeightHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef GeneratorInterface_Core_LHEWeightHelper_h
#define GeneratorInterface_Core_LHEWeightHelper_h

#include <string>
#include <vector>
#include <map>
#include <regex>
#include <fstream>

#include "SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
#include "GeneratorInterface/Core/interface/WeightHelper.h"

#include <tinyxml2.h>

namespace gen {
class LHEWeightHelper : public WeightHelper {
public:
LHEWeightHelper() : WeightHelper(){};

enum ErrorType { SWAPHEADER, HTMLSTYLE, TRAILINGSTR, UNKNOWN };

void setHeaderLines(std::vector<std::string> headerLines);
void parseWeights();
bool isConsistent();
void swapHeaders();
void setFailIfInvalidXML(bool value) { failIfInvalidXML_ = value; }

private:
std::vector<std::string> headerLines_;
std::string weightgroupKet_ = "</weightgroup>";
bool failIfInvalidXML_ = false;
std::string parseGroupName(tinyxml2::XMLElement* el);
void addGroup(tinyxml2::XMLElement* inner, std::string groupName, int groupIndex, int& weightIndex);
bool parseLHE(tinyxml2::XMLDocument& xmlDoc);
tinyxml2::XMLError tryReplaceHtmlStyle(tinyxml2::XMLDocument& xmlDoc, std::string& fullHeader);
tinyxml2::XMLError tryRemoveTrailings(tinyxml2::XMLDocument& xmlDoc, std::string& fullHeader);
ErrorType findErrorType(std::string& fullHeader);
};
} // namespace gen

#endif
117 changes: 117 additions & 0 deletions GeneratorInterface/Core/interface/WeightHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#ifndef GeneratorInterface_LHEInterface_WeightHelper_h
#define GeneratorInterface_LHEInterface_WeightHelper_h

#include "DataFormats/Common/interface/OwnVector.h"
#include "SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/WeightsInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h"
#include "LHAPDF/LHAPDF.h"
#include <boost/algorithm/string.hpp>
#include <bits/stdc++.h>
#include <fstream>

namespace gen {
struct ParsedWeight {
std::string id;
int index;
std::string groupname;
std::string content;
std::unordered_map<std::string, std::string> attributes;
int wgtGroup_idx;
};

class WeightHelper {
public:
WeightHelper();
edm::OwnVector<gen::WeightGroupInfo> weightGroups() { return weightGroups_; }

template <typename T>
std::unique_ptr<GenWeightProduct> weightProduct(std::vector<T> weights, float w0);

void setModel(std::string model) { model_ = model; }
void setGuessPSWeightIdx(bool guessPSWeightIdx) {
PartonShowerWeightGroupInfo::setGuessPSWeightIdx(guessPSWeightIdx);
}
void addUnassociatedGroup() {
weightGroups_.push_back(std::make_unique<UnknownWeightGroupInfo>("unassociated"));
weightGroups_.back().setDescription("Weights with missing or invalid header meta data");
}
int addWeightToProduct(
std::unique_ptr<GenWeightProduct>& product, double weight, std::string name, int weightNum, int groupIndex);
int findContainingWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex);
void setDebug(bool value) { debug_ = value; }

protected:
// TODO: Make this only print from one thread a la
// https://github.com/kdlong/cmssw/blob/master/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc#L1069
bool debug_ = false;
const unsigned int FIRST_PSWEIGHT_ENTRY = 2;
const unsigned int DEFAULT_PSWEIGHT_LENGTH = 46;
std::string model_;
std::vector<ParsedWeight> parsedWeights_;
std::map<std::string, std::string> currWeightAttributeMap_;
std::map<std::string, std::string> currGroupAttributeMap_;
edm::OwnVector<gen::WeightGroupInfo> weightGroups_;
bool isScaleWeightGroup(const ParsedWeight& weight);
bool isMEParamWeightGroup(const ParsedWeight& weight);
bool isPdfWeightGroup(const ParsedWeight& weight);
bool isPartonShowerWeightGroup(const ParsedWeight& weight);
bool isOrphanPdfWeightGroup(ParsedWeight& weight);
void updateScaleInfo(gen::ScaleWeightGroupInfo& scaleGroup, const ParsedWeight& weight);
void updateMEParamInfo(const ParsedWeight& weight, int index);
void updatePdfInfo(gen::PdfWeightGroupInfo& pdfGroup, const ParsedWeight& weight);
void updatePartonShowerInfo(gen::PartonShowerWeightGroupInfo& psGroup, const ParsedWeight& weight);
void cleanupOrphanCentralWeight();
bool splitPdfWeight(ParsedWeight& weight);

int lhapdfId(const ParsedWeight& weight, gen::PdfWeightGroupInfo& pdfGroup);
std::string searchAttributes(const std::string& label, const ParsedWeight& weight) const;
std::string searchAttributesByTag(const std::string& label, const ParsedWeight& weight) const;
std::string searchAttributesByRegex(const std::string& label, const ParsedWeight& weight) const;

// Possible names for the same thing
const std::unordered_map<std::string, std::vector<std::string>> attributeNames_ = {
{"muf", {"muF", "MUF", "muf", "facscfact"}},
{"mur", {"muR", "MUR", "mur", "renscfact"}},
{"pdf", {"PDF", "PDF set", "lhapdf", "pdf", "pdf set", "pdfset"}},
{"dyn", {"DYN_SCALE"}},
{"dyn_name", {"dyn_scale_choice"}},
{"up", {"_up", "Hi"}},
{"down", {"_dn", "Lo"}},
{"me_variation", {"mass", "sthw2", "width"}},
};
void printWeights();
std::unique_ptr<WeightGroupInfo> buildGroup(ParsedWeight& weight);
void buildGroups();
std::string searchString(const std::string& label, const std::string& name);
};

// Templated function (needed here because of plugins)
template <typename T>
std::unique_ptr<GenWeightProduct> WeightHelper::weightProduct(std::vector<T> weights, float w0) {
auto weightProduct = std::make_unique<GenWeightProduct>(w0);
weightProduct->setNumWeightSets(weightGroups_.size());
int weightGroupIndex = 0;
int i = 0;
// This happens if there are no PS weights, so the weights vector contains only the central GEN weight.
// Just add an empty product (need for all cases or...?)
if (weights.size() > 1) {
for (const auto& weight : weights) {
if constexpr (std::is_same<T, gen::WeightsInfo>::value)
weightGroupIndex = addWeightToProduct(weightProduct, weight.wgt, weight.id, i, weightGroupIndex);
else if (std::is_same<T, double>::value)
weightGroupIndex = addWeightToProduct(weightProduct, weight, std::to_string(i), i, weightGroupIndex);
i++;
}
}
return weightProduct;
}
} // namespace gen

#endif
1 change: 1 addition & 0 deletions GeneratorInterface/Core/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<use name="FWCore/MessageLogger"/>
<use name="FWCore/Utilities"/>
<use name="SimDataFormats/GeneratorProducts"/>
<use name="GeneratorInterface/Core"/>
<use name="FWCore/SharedMemory"/>
<use name="clhep"/>
<library name="GeneratorInterfaceCore_plugins" file="*.cc">
Expand Down
95 changes: 95 additions & 0 deletions GeneratorInterface/Core/plugins/GenWeightProductProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include <cstdio>
#include <memory>
#include <vector>
#include <string>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDProducer.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"

#include "FWCore/Framework/interface/Run.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/FileInPath.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/GenLumiInfoHeader.h"

#include "GeneratorInterface/Core/interface/GenWeightHelper.h"

#include "FWCore/ServiceRegistry/interface/Service.h"
#include <boost/algorithm/string.hpp>

class GenWeightProductProducer : public edm::one::EDProducer<edm::BeginLuminosityBlockProducer> {
public:
explicit GenWeightProductProducer(const edm::ParameterSet& iConfig);
~GenWeightProductProducer() override;

private:
std::vector<std::string> weightNames_;
gen::GenWeightHelper weightHelper_;
edm::EDGetTokenT<GenLumiInfoHeader> genLumiInfoToken_;
edm::EDGetTokenT<GenEventInfoProduct> genEventToken_;
const edm::EDGetTokenT<GenLumiInfoHeader> genLumiInfoHeadTag_;

void produce(edm::Event&, const edm::EventSetup&) override;
void beginLuminosityBlockProduce(edm::LuminosityBlock& lb, edm::EventSetup const& c) override;
};

//
// constructors and destructor
//
GenWeightProductProducer::GenWeightProductProducer(const edm::ParameterSet& iConfig)
: genLumiInfoToken_(consumes<GenLumiInfoHeader, edm::InLumi>(iConfig.getParameter<edm::InputTag>("genInfo"))),
genEventToken_(consumes<GenEventInfoProduct>(iConfig.getParameter<edm::InputTag>("genInfo"))),
genLumiInfoHeadTag_(
mayConsume<GenLumiInfoHeader, edm::InLumi>(iConfig.getParameter<edm::InputTag>("genLumiInfoHeader"))) {
weightHelper_.setDebug(iConfig.getUntrackedParameter<bool>("debug", false));
produces<GenWeightProduct>();
produces<GenWeightInfoProduct, edm::Transition::BeginLuminosityBlock>();
weightHelper_.setGuessPSWeightIdx(iConfig.getUntrackedParameter<bool>("guessPSWeightIdx", false));
}

GenWeightProductProducer::~GenWeightProductProducer() {}

// ------------ method called to produce the data ------------
void GenWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::Handle<GenEventInfoProduct> genEventInfo;
iEvent.getByToken(genEventToken_, genEventInfo);

float centralWeight = !genEventInfo->weights().empty() ? genEventInfo->weights().at(0) : 1.;
auto weightProduct = weightHelper_.weightProduct(genEventInfo->weights(), centralWeight);
iEvent.put(std::move(weightProduct));
}

void GenWeightProductProducer::beginLuminosityBlockProduce(edm::LuminosityBlock& iLumi, edm::EventSetup const& iSetup) {
edm::Handle<GenLumiInfoHeader> genLumiInfoHead;
iLumi.getByToken(genLumiInfoHeadTag_, genLumiInfoHead);
if (genLumiInfoHead.isValid()) {
std::string label = genLumiInfoHead->configDescription();
boost::replace_all(label, "-", "_");
weightHelper_.setModel(label);
}

edm::Handle<GenLumiInfoHeader> genLumiInfoHandle;
iLumi.getByToken(genLumiInfoToken_, genLumiInfoHandle);

weightNames_ = genLumiInfoHandle->weightNames();
weightHelper_.parseWeightGroupsFromNames(weightNames_);

auto weightInfoProduct = std::make_unique<GenWeightInfoProduct>();
if (weightHelper_.weightGroups().empty())
weightHelper_.addUnassociatedGroup();

for (auto& weightGroup : weightHelper_.weightGroups()) {
weightInfoProduct->addWeightGroupInfo(std::unique_ptr<gen::WeightGroupInfo>(weightGroup.clone()));
}
iLumi.put(std::move(weightInfoProduct));
}

DEFINE_FWK_MODULE(GenWeightProductProducer);
Loading