A generic correction library
Project description
correctionlib
Introduction
The purpose of this library is to provide a well-structured JSON data format for a wide variety of ad-hoc correction factors encountered in a typical HEP analysis and a companion evaluation tool suitable for use in C++ and python programs. Here we restrict our definition of correction factors to a class of functions with scalar inputs that produce a scalar output.
In python, the function signature is:
from typing import Union
def f(*args: Union[str,int,float]) -> float:
return ...
In C++, the evaluator implements this currently as:
double Correction::evaluate(const std::vector<std::variant<int, double, std::string>>& values) const;
The supported function classes may include:
- multi-dimensional binned lookups;
- binned lookups pointing to multi-argument formulas with a restricted
math function set (
exp
,sqrt
, etc.); - categorical (string or integer enumeration) maps; and
- compositions of the above.
Each function type is represented by a "node" in a call graph and holds all of its parameters in a JSON structure, described by the JSON schema. Possible future extension nodes might include weigted sums (which, when composed with the others, could represent a BDT) and perhaps simple MLPs.
The tool should provide:
- standardized, versioned JSON schemas;
- forward-porting tools (to migrate data written in older schema versions); and
- a well-optimized C++ evaluator and python bindings (with numpy vectorization support).
This tool will definitely not provide:
- support for
TLorentzVector
or other object-type inputs (such tools should be written as a higher-level tool depending on this library as a low-level tool)
Formula support is currently planned via linking to ROOT libraries and using TFormula
,
however if possible we would like to avoid this external dependency. One alternative could
be using the boost.spirit parser with some reasonable grammar--
this is the approach used for CMSSW's expression parser.
There are also various C++ formula parsers such as ExprTk,
and the python bindings may be able to call into numexpr,
though, due to the tree-like structure of the corrections, it may prove difficult to exploit vectorization
at levels other than the entrypoint.
Installation
The build process is Makefile-based for the C++ evaluator and via setuptools for the python bindings. Builds have been tested in Windows, OS X, and Linux, and python bindings can be compiled against both python2 and python3, as well as from within a CMSSW environment. The python bindings are distributed as a pip-installable package.
If you use python 3, you can simply pip install correctionlib
(possibly with --user
, or in a virtualenv, etc.)
To build the C++ evaluator in most environments:
git clone --recursive git@github.com:nsmith-/correctionlib.git
cd correctionlib
make
# demo C++ binding, main function at src/demo.cc
./demo data/examples.json
To compile with python2 support, consider using python 3 :) If you considered that and still
want to us python2, follow the C++ build instructions and then call make PYTHON=python2 correctionlib
to compile.
Inside CMSSW you should use make PYTHON=python correctionlib
assuming python
is the name of the scram tool you intend to link against.
This will output a correctionlib
directory that acts as a python package, and can be moved where needed.
This package will only provide the correctionlib._core
evaluator module, as the schema tools and high-level bindings are python3-only.
Creating new corrections
The correctionlib
python package provides a helpful
framework for defining correction objects. Nodes can be type-checked as they are constructed using the
parse_obj class method.
Some examples can be found in convert.ipynb
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for correctionlib-1.1.0-pp37-pypy37_pp73-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54ec3265968539970c8850b71489c90c83587f9c6c72dfe8605e43c804571cdf |
|
MD5 | d4542edf70b6bb5cc25eb23316768319 |
|
BLAKE2b-256 | cd2abf577f3eb46aaf2ac2aded1be7356ad2bc2a01b88355fd7761203ef46779 |
Hashes for correctionlib-1.1.0-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49532df23eaa0cbd92d6a646b031302bc136dc4ad444470f3cfc969399738e36 |
|
MD5 | e58371478e8136267d15b53602025bb2 |
|
BLAKE2b-256 | 21d4cdd737f1e9189fe4cd98555a08e3f20858bba69d97e65b46f6272ff63b2c |
Hashes for correctionlib-1.1.0-pp37-pypy37_pp73-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 080d5e05f215a1fa4ee6252c57ea2d201523989440e38443a6071b475220b51b |
|
MD5 | 7de844bd41c86e5582455561376d1d1a |
|
BLAKE2b-256 | 4b2db89236021677f3612f5ba6f1c159ed368f8d33f649eaa2d23ca1ce4eb61d |
Hashes for correctionlib-1.1.0-pp36-pypy36_pp73-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f8f73b0eae0dd83ead858e3a78c60dd23699a8f8cf23b69bb93301675c2b176 |
|
MD5 | e5a493411a3c89eeceb9cf3236a26c63 |
|
BLAKE2b-256 | a5c8655e148a648c9457e350e14c0874239a2b6a8eaafe645c5053b640664e7d |
Hashes for correctionlib-1.1.0-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bd0fbd4f8c026c89cf116096cf916045acbbf1d5ffaba306c5bd7ea61fdf76b |
|
MD5 | 86f7ac562fe3d344f1ac8f235678b4dc |
|
BLAKE2b-256 | 8a76f1787e76d6a41e342c17b4c0e4fdc8a4f0df27064256c9fb55542543d14a |
Hashes for correctionlib-1.1.0-pp36-pypy36_pp73-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20b57a63c78c564c2e2df50841283072717ae46ba8bb69681f23d6a1979522b9 |
|
MD5 | f74c7ce7dddf92229f7ce353956d3efc |
|
BLAKE2b-256 | ecc8d8998c9e19ef272de7bc767d4d4e2d3d29ed09945f007a9b78e7f16d3391 |
Hashes for correctionlib-1.1.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07ed6b1b9b4e7ea1747842482093d278d490bf952fbd613654e60123fcdd31df |
|
MD5 | 66314fea105876605cd56c6ab3861d67 |
|
BLAKE2b-256 | 84f567249cd89535a3387ac9d3758061273b8fbc039ef425bc69d1ec55859b31 |
Hashes for correctionlib-1.1.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c62548afd56fe76a622cb2225b687d6934e3710492a7c33e708f9f1dcc72ad8 |
|
MD5 | 316a8b4c51fe6de57617cdfdcc7761aa |
|
BLAKE2b-256 | c98d6fb49707dbb3306afbebc1afb1283d8a5cb1d2af54764faac31d79affb65 |
Hashes for correctionlib-1.1.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 983f69a49454960f54a949b30a927fcdb8664ced65fedc4073e3d148580756c0 |
|
MD5 | fa843b77699f3a9040414078f5addd06 |
|
BLAKE2b-256 | fa020be1f8bf58f2ea43eed4b8c5ee4b193b4a7afcb22149e548e3071cafcf8b |
Hashes for correctionlib-1.1.0-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39486a138c13d266ff61238f1bb6500af81357e6f9ec59bce5821216ba0eaf89 |
|
MD5 | d9fdf02f5e25b38c57afbaa68cfa4ee4 |
|
BLAKE2b-256 | b5ecb5aa1d788b7a9f8143f9cd6551039290b11e458c8c5b078e0ba33bf410d8 |
Hashes for correctionlib-1.1.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dbb10664eef8cfaf44a918cea5e6427ce31dffb3d439cc7e081d9d7f3e824a6 |
|
MD5 | 2db2c517777ec1730c28fd1ec39c301e |
|
BLAKE2b-256 | 58911dae49c15c5ea043e65034226ec53374651587cdfe07bc7bc8f8ee630a6f |
Hashes for correctionlib-1.1.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07ebc7cd579c6b33262e1215eb5bca0686f27e2392735b23e22d183866ddb3d2 |
|
MD5 | d72fbb4b784e110b3fce05e3571b072b |
|
BLAKE2b-256 | a535d27c24a2d55334bc26f0593a402cbc669df68bb07a37d0b7f781e9da8775 |
Hashes for correctionlib-1.1.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ebd075b17b2bf49cbd21703b3b82da79d00428e1ed26524c1103c8dc4bf7e8a |
|
MD5 | a12e3fb50559543831e01f7cdf9e9518 |
|
BLAKE2b-256 | 7affcf439af81bb6169c331d00f12fa55a05e9065564d0a275aee15ae31309a1 |
Hashes for correctionlib-1.1.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 643a42fc8ca73b9a477296e2ccb57284106d6d9710e33fb59192811e34fa695f |
|
MD5 | 2c5b36371b5c920ca219d095e315f52e |
|
BLAKE2b-256 | 3526a63fce6697d4c73f1164f46b5c7e3053f02cacc818d579ccf152f12e6262 |
Hashes for correctionlib-1.1.0-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9761003a039dde5d29a2ac66161394d9d6437a7669680a710d1a4ce92ef69c4b |
|
MD5 | 1aa04b2880673f3d01a38a4aa1e3b80d |
|
BLAKE2b-256 | 1698f6ac6d2f5314b17250a86e7040eb24888b47f91cd0dbdfcc4e163b4864c9 |
Hashes for correctionlib-1.1.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23209149a73f901b483162ab6b39e170883fe8c34befd2e7c9bdb97dc1cd359d |
|
MD5 | 8c1281938e265733c501e0422dbc3299 |
|
BLAKE2b-256 | 1ca4404ee795beea862f93b8d89c7d0d272959419a3bddb17f83d1dd3b27593b |
Hashes for correctionlib-1.1.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c83b6b4d234fa01a2d6037bdf6a7e9f9eac8cd3423a3d3be1b4eafbd203499e |
|
MD5 | b096a9dc3bebea4fbd05752605c8422b |
|
BLAKE2b-256 | bba601d60e1e369b326109638d601b12ddf0681042d784d601cef4115da5d02c |
Hashes for correctionlib-1.1.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce7f0c13124987dfca652b9b8e484e9f99fb5a59ea50f7d341509a28c93370d3 |
|
MD5 | 74249e63317342d6c882204ff61d16b6 |
|
BLAKE2b-256 | 03fe63f7f3d8d8becc1e2c48edd01d8fae3b4b8719983c250d7cbf1af354220e |
Hashes for correctionlib-1.1.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4dd7969066ea3e0f2277acfcaddbc1845deb21da4bb7b8b6b4bf565951a5c69 |
|
MD5 | 59c1d67eef4876ec90a4e978a023cf48 |
|
BLAKE2b-256 | 7ad9791d3fe6969a76bf529ce82201723eba218fb1cbca2a2ba2fd37958fc6fe |
Hashes for correctionlib-1.1.0-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b9bbdb170e553d0cb3bf0999bf0e7efaafc9fc53aed1008f0389db2207fad54 |
|
MD5 | d24c4bedfc911f7401c1a78196f720fe |
|
BLAKE2b-256 | e71a38c9c7a4465946b0ec29eab68efdc4df36828c3e9ec876a7c1bb3260ac3b |
Hashes for correctionlib-1.1.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6dd20f26e3381741e6a82fd6d1c07c3c03705455d181b58b9f9b90fb88bd33d |
|
MD5 | a10b3fd503bf48d370ebb37819afe11d |
|
BLAKE2b-256 | c656eff021c6aee940c2c72eb40cc725477417925874b435531b812b27134a2a |
Hashes for correctionlib-1.1.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0ba2c1dc083e2c7f1ed320624144bbedcbcea6910461605fd31a25cc38aad2d |
|
MD5 | 493efc0da201d1778d96262c7d08f630 |
|
BLAKE2b-256 | d9a16bcb675b5736f2ca902a642e84de20ba1b7240e6ca429b2b15937e7a26c5 |
Hashes for correctionlib-1.1.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 551b71eaea8040d036a53df6a9019d67679783b0b1cf6c52f4db1db9526e820c |
|
MD5 | a0ef74a738969ed2eef1febc46e8fbb0 |
|
BLAKE2b-256 | 1b86691442318c60b128f2f642ea3ab8467612e7f74c13a060cd5bbadfffefe6 |
Hashes for correctionlib-1.1.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdfbcbba614f41ea65f77f5bdae7804257094abe12a696c4efe22b3f023b7324 |
|
MD5 | 19972f8a0bcb8cb0b88fe7b6238a20d4 |
|
BLAKE2b-256 | ea0a7ad5eb940dba87d7e96f9f117ace11d85baf3dd73254f6924df00be691fe |
Hashes for correctionlib-1.1.0-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 079f99bc6af117a8ccd60006312f6112d26e8a7a6e9e84930c3f7c08848ade0d |
|
MD5 | 5c79724084de35e92378c4ab28a7b494 |
|
BLAKE2b-256 | 9389c07cabcec6c944adb5cd7fc92a97730c6dcb20bd02de4fdeeb210184d7af |
Hashes for correctionlib-1.1.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 644ca5733a8b19f9cedd11c479eeffd7655b9f3568508c67a41ae82e215a2e00 |
|
MD5 | d5093b58e142f8789ba8daf45da338b4 |
|
BLAKE2b-256 | 831e2d5358f867ac621b6ddc19eafe55c17a310c82779ec96379c47cd91fc2f3 |