-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36547 from nsmith-/correctionlib_backport_10_6
Add a unit test for correctionlib external
- Loading branch information
Showing
3 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"schema_version": 2, | ||
"description": "A few test corrections", | ||
"corrections": [ | ||
{ "name": "test corr", | ||
"description": null, | ||
"version": 2, | ||
"inputs": [ | ||
{ "name": "pt", | ||
"type": "real", | ||
"description": null | ||
}, | ||
{ "name": "syst", | ||
"type": "string", | ||
"description": null | ||
} | ||
], | ||
"output": { | ||
"name": "a scale", | ||
"type": "real", | ||
"description": null | ||
}, | ||
"generic_formulas": null, | ||
"data": { | ||
"nodetype": "binning", | ||
"input": "pt", | ||
"edges": [ 0.0, 20.0, 40.0, Infinity ], | ||
"content": [ | ||
{ "nodetype": "category", | ||
"input": "syst", | ||
"content": [ | ||
{ "key": "blah", "value": 1.1 }, | ||
{ "key": "blah2", "value": 2.2 } | ||
], | ||
"default": null | ||
}, | ||
{ "nodetype": "category", | ||
"input": "syst", | ||
"content": [ | ||
{ "key": "blah2", "value": 1.3 }, | ||
{ "key": "blah3", | ||
"value": { | ||
"nodetype": "formula", | ||
"expression": "0.25*x + exp([0])", | ||
"parser": "TFormula", | ||
"variables": [ "pt" ], | ||
"parameters": [ 3.1 ] | ||
} | ||
} | ||
], | ||
"default": null | ||
}, | ||
1.0 | ||
], | ||
"flow": "error" | ||
} | ||
} | ||
], | ||
"compound_corrections": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <cmath> | ||
#include <cppunit/extensions/HelperMacros.h> | ||
#include "FWCore/ParameterSet/interface/FileInPath.h" | ||
#include "correction.h" | ||
|
||
class test_correctionlib : public CppUnit::TestFixture { | ||
CPPUNIT_TEST_SUITE(test_correctionlib); | ||
CPPUNIT_TEST(checkAll); | ||
CPPUNIT_TEST_SUITE_END(); | ||
|
||
public: | ||
void setUp() {} | ||
void tearDown() {} | ||
void checkAll(); | ||
}; | ||
|
||
CPPUNIT_TEST_SUITE_REGISTRATION(test_correctionlib); | ||
|
||
void test_correctionlib::checkAll() { | ||
edm::FileInPath testfile("PhysicsTools/Utilities/test/corrections.json"); | ||
auto cset = correction::CorrectionSet::from_file(testfile.fullPath()); | ||
CPPUNIT_ASSERT(cset->at("test corr")); | ||
CPPUNIT_ASSERT_THROW(cset->at("nonexistent"), std::out_of_range); | ||
auto corr = cset->at("test corr"); | ||
CPPUNIT_ASSERT(corr->evaluate({12.0, "blah"}) == 1.1); | ||
CPPUNIT_ASSERT(corr->evaluate({31.0, "blah3"}) == 0.25 * 31.0 + std::exp(3.1)); | ||
} |