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 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;
- input transforms (updating one input value in place); 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 currently includes a mostly-complete subset of the ROOT library TFormula
class,
and is implemented in a threadsafe standalone manner. The parsing grammar is formally defined
and parsed through the use of a header-only PEG parser library.
The supported features mirror CMSSW's reco::formulaEvaluator
and fully passes the test suite for that utility with the purposeful exception of the TMath::
namespace.
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 based on setuptools, with CMake (through scikit-build) for the C++ evaluator and its python bindings module. 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. Note that CMSSW 11_2_X and above has ROOT accessible from python 3.
To install in an environment that has python 3, you can simply
python3 -m pip install correctionlib
(possibly with --user
, or in a virtualenv, etc.)
If you wish to install the latest development version,
python3 -m pip install git+https://github.com/cms-nanoAOD/correctionlib.git
should work.
The C++ evaluator library is distributed as part of the python package, and it can be
linked to directly without using python. If you are using CMake you can depend on it by including
the output of correction config --cmake
in your cmake invocation. A complete cmake
example that builds a user C++ application against correctionlib and ROOT RDataFrame
can be found here.
For manual compilation, include and linking definitions can similarly be found via correction config --cflags --ldflags
.
For example, the demo application can be compiled with:
wget https://raw.githubusercontent.com/cms-nanoAOD/correctionlib/master/src/demo.cc
g++ $(correction config --cflags --ldflags --rpath) demo.cc -o demo
If the correction
command-line utility is not on your path for some reason, it can also be invoked via python -m correctionlib.cli
.
To compile with python2 support, consider using python 3 :) If you considered that and still want to use python2, the following recipe may work:
git clone --recursive git@github.com:cms-nanoAOD/correctionlib.git
cd correctionlib
make PYTHON=python2 correctionlib
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.schemav2
module provides a helpful framework for defining correction objects
and correctionlib.convert
includes select conversion routines for common types. Nodes can be type-checked as they are
constructed using the parse_obj
class method or by directly constructing them using keyword arguments.
Some examples can be found in data/conversion.py
. The tests/
directory may also be helpful.
Developing
See CONTRIBUTING.md
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-2.0.0-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 841adb296398c3358a99c13225b93f1e4d42eade6df41f516e3530e40ce375f2 |
|
MD5 | 090ecfb734d6e5856a341093ecb95077 |
|
BLAKE2b-256 | 87407f4395b4f0ddb8c15be6deda236cd01e75b1a310c24bb92e920fba3f03d2 |
Hashes for correctionlib-2.0.0-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef1e1578ff525004e985c13638928cbdea2476560ddec2a573de8a0c5c8e9301 |
|
MD5 | 0dea6cdd326dd7b5d6ce44838b6e967a |
|
BLAKE2b-256 | 15a5efb622a042a6d786862d6d0f37cad93064ceb61afc02494b871546a35aca |
Hashes for correctionlib-2.0.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a7af260c3585ebfa001aa25277de2da463e5761f9d100e23b3dcff709f49584 |
|
MD5 | 0d7fe525113aaa9218c1bd11c344b1ab |
|
BLAKE2b-256 | 6d605990c71310d44d445ddd3e8ec61d8b10f8751fcb858d63dee080bb6a64ba |
Hashes for correctionlib-2.0.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fa4f384a8d7da790a81501df130f5ff539b227c0a497756e9e1c2410b67eb51 |
|
MD5 | a8deea33471edac35a9e614ed187ce26 |
|
BLAKE2b-256 | 6856d3fa26221c738b1e4937a45f6bc2c024283f432b7d3a1eded47ad4d0ad0c |
Hashes for correctionlib-2.0.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8dbbc7bdb5ff2b3aa9c799aeffd1b94207faf9c24c01ceaa7042f1d2fc32c8e |
|
MD5 | e36b70e2c628e144dee749ece11b32a0 |
|
BLAKE2b-256 | c5edfed6dc85633c1575e457d26c2fe99ab5aa32c28416e8d20090e3fa748894 |
Hashes for correctionlib-2.0.0-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b207c830d6f6c86fd2f2820076d3d60c3ea1c2def3e8c3f07f28a1213e08a99b |
|
MD5 | be59d36d6b4b43c136919c1fe7d9a1d3 |
|
BLAKE2b-256 | 42b789631e72b2d2b31d95b9a606fde0ddf9af18d84872c9b9a715e3226ced63 |
Hashes for correctionlib-2.0.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b7d75e12556a615f679bba4836b2109b41902fbc437d32be3db80f55b68f69a |
|
MD5 | fff8b220e55e0023bbb32c2960c0f7b3 |
|
BLAKE2b-256 | 2c52ddd579cd05548e46704c1ee262809e8d1c31e6bc38e2c2bcd2ca9d7357a2 |
Hashes for correctionlib-2.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d266623831948e371f6173c84cbd2ad9153b8b5e736f802b1d6eca47c1dd90af |
|
MD5 | e9828fe539462d73412fda77d15780f8 |
|
BLAKE2b-256 | 279b36e246a801567a781ca5ee6792c789eb5332058c716debe02275e3454630 |
Hashes for correctionlib-2.0.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a5be6e6b9dec08b8c71dabc63d249a2716e0675316062eb978cf16d20157c1a |
|
MD5 | 1d5153fcbbfb61817c8b667461648b44 |
|
BLAKE2b-256 | 9506097f5424413afa20c090853e13c01151ef77d191ca430c3e26c57b1d5abd |
Hashes for correctionlib-2.0.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a89cfdfbd2b4ec988d703725cf6128bfde3910cdb0ca2c82fe90548091c712b |
|
MD5 | 6f9d6525955a5208ffd799ba66c1752a |
|
BLAKE2b-256 | 2697734a5b6d4a43acaad2833265a2e23327fb9784e5c9d2587a907c5a3715aa |
Hashes for correctionlib-2.0.0-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65262e9ce578b1c206e3210dc9df5c55dca578b6ac0ce9084e657fcfe796035a |
|
MD5 | 50aaca9f56bfd0b6091694347cef22d9 |
|
BLAKE2b-256 | 4bfea94676e00c6248467d6e3abb04e3cbabbc8bd6d41f4a6af617536d9fae95 |
Hashes for correctionlib-2.0.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1246daa4a6f14f10b58e55f57b94211c279fd32e3f42a3154e260ab70742f330 |
|
MD5 | 2d4fe61e9e1325a0db9bf882a901d042 |
|
BLAKE2b-256 | 7b20e1ff88583a7b16034c5968b15b7834343c1aaa074e44df541729aabd9122 |
Hashes for correctionlib-2.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 763968b4ca7286c6ad0c8c0aa54d6e0ffea5807d04b96fb91b985a6e15ebfc44 |
|
MD5 | f115e7f46cb1b74e628de79f83213036 |
|
BLAKE2b-256 | 30ed5a58ba1e1554c0d9fc5c127e5f3452686ac2c5ff1bd2bee09e7fd9af2218 |
Hashes for correctionlib-2.0.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fad8cdeed32a1d6aa2452c18d1627a25b981c628b823035f6d766ffec5489db6 |
|
MD5 | f941482fa96aab8b4dc0f01d17f9ec6f |
|
BLAKE2b-256 | 70f79a532209fe7b9ebf9625ff842ee59ae1c6a2b432549a13981048f851f2e4 |
Hashes for correctionlib-2.0.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d2063f3e35f6a4acb625cf8cbf69b947074fb7262fdb96fc86560174a7fd175 |
|
MD5 | 2b618b3f92bbe498892e17646178ae40 |
|
BLAKE2b-256 | 2b9c827d066ec40b03761732372367a20dd2040081f3845d17a8af1c8ad2acee |
Hashes for correctionlib-2.0.0-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4657dd401cd4bcb39b1b8d8f58694b1e59ce5ace249634cee2076d964c3778e8 |
|
MD5 | c6bef4f1425beb46de2ae74c6e786018 |
|
BLAKE2b-256 | a5b8469633686cb8cf76a053658b18ceb9f7a6a0d3163ad6531a643c0d0d5eac |
Hashes for correctionlib-2.0.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c62322e9bacc7f58ac478e303eabeff8672c1b273e70cf5fa37e2580bc9eb6c4 |
|
MD5 | f6a4a968fc0ae9d3aea4c0e34206a5ee |
|
BLAKE2b-256 | 688f12f33b73442cede56c2e606836eaf1b4ec237069c4031efead8418afca27 |
Hashes for correctionlib-2.0.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47c4253a7488b103b5d6218c77a354119555bb4df8db5192d4411e8198823e58 |
|
MD5 | f227d2ce893bdeb7ed89f810be6494e8 |
|
BLAKE2b-256 | acfe08bf6218cd96ca1d249beefa19ce8046e050e4aa84b5686a8da1910dd024 |
Hashes for correctionlib-2.0.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed42e59d9a625efac4b34c172543cf9887e62946ad64ebdf99fe99ff30fd0861 |
|
MD5 | c719e141c1881e67ab343396894d0ff9 |
|
BLAKE2b-256 | 830a6154ae7f72989584b3df281d1d42ef3dda5a694a0caf3b15032d5bbdc056 |
Hashes for correctionlib-2.0.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9042a48872882db3e6edf1928dd027e285cfbc3f69529b19aa1da230e5ed9985 |
|
MD5 | feb894b994b4cbfdc87972dcfdb36b9e |
|
BLAKE2b-256 | bfc1aa42f2293c3d978c55ee00d485138bbccbacfb19c18e949313066497a8a9 |
Hashes for correctionlib-2.0.0-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16cf6866b6f6bde177f38a7f9482353806f756a15397353d65ba464ab7609d4b |
|
MD5 | 298823a53d9264a15d7af6c0ae543e2a |
|
BLAKE2b-256 | d46ac8d24c7d8e4056a02dce3f0d361f72de07a10120cce732b1f69a02f0c19c |
Hashes for correctionlib-2.0.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0765cb5f0b4bf0aba41792a7be855493bfb6c04271ed4d9857d3a8f6b2bfb31b |
|
MD5 | 5cb9dba96f7ba03b9a52a00f56b11161 |
|
BLAKE2b-256 | 4184f8d33e9add8135218974740c7df90378f731a7d2d2e3c0eb5ea189788eea |