Skip to content

Commit

Permalink
Merge branch 'CMSSW_9_4_MAOD_X' into fixLegacy2016
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocos committed May 24, 2018
2 parents 8e68392 + fffc9b2 commit 19915d6
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 21 deletions.
33 changes: 33 additions & 0 deletions CommonTools/Utils/src/FormulaEvaluator.cc
Expand Up @@ -297,6 +297,11 @@ namespace {
fullExpression.evaluator.reset();
}

if(fullExpression.evaluator == nullptr) {
//we had a parsing problem
return fullExpression;
}

//Now to handle precedence
auto topNode = fullExpression.top;
auto binaryEval = dynamic_cast<reco::formula::BinaryOperatorEvaluatorBase*>(fullExpression.evaluator.get());
Expand Down Expand Up @@ -573,6 +578,10 @@ namespace {
const std::string k_TMath__Erf("TMath::Erf");
const std::string k_erf("erf");
const std::string k_TMath__Landau("TMath::Landau");
const std::string k_sqrt("sqrt");
const std::string k_TMath__Sqrt("TMath::Sqrt");
const std::string k_abs("abs");
const std::string k_TMath__Abs("TMath::Abs");


EvaluatorInfo
Expand Down Expand Up @@ -621,6 +630,30 @@ namespace {
return info;
}

info = checkForSingleArgFunction(iBegin, iEnd, m_expressionFinder,
k_sqrt, [](double iArg)->double { return std::sqrt(iArg); } );
if(info.evaluator.get() != nullptr) {
return info;
}

info = checkForSingleArgFunction(iBegin, iEnd, m_expressionFinder,
k_TMath__Sqrt, [](double iArg)->double { return std::sqrt(iArg); } );
if(info.evaluator.get() != nullptr) {
return info;
}

info = checkForSingleArgFunction(iBegin, iEnd, m_expressionFinder,
k_abs, [](double iArg)->double { return std::abs(iArg); } );
if(info.evaluator.get() != nullptr) {
return info;
}

info = checkForSingleArgFunction(iBegin, iEnd, m_expressionFinder,
k_TMath__Abs, [](double iArg)->double { return std::abs(iArg); } );
if(info.evaluator.get() != nullptr) {
return info;
}

info = checkForTwoArgsFunction(iBegin, iEnd, m_expressionFinder,
k_pow, [](double iArg1, double iArg2)->double { return std::pow(iArg1,iArg2); } );
if(info.evaluator.get() != nullptr) {
Expand Down
34 changes: 34 additions & 0 deletions CommonTools/Utils/test/testFormulaEvaluator.cc
Expand Up @@ -895,4 +895,38 @@ testFormulaEvaluator::checkFormulaEvaluator() {
}
}

//tests for JER
{
reco::FormulaEvaluator f("[0]+[1]*exp(-x/[2])");

std::vector<double> v = {0.006467,0.02519,77.08};
std::vector<double> x = {100.};

auto func = [&v](double x) { return v[0]+v[1]*std::exp(-x/v[2]); };

CPPUNIT_ASSERT( compare( f.evaluate(x,v), func(x[0]) ) );
}

{
reco::FormulaEvaluator f("sqrt([0]*abs([0])/(x*x)+[1]*[1]*pow(x,[3])+[2]*[2])");

std::vector<double> v = {1.326,0.4209,0.02223,-0.6704};
std::vector<double> x = {100.};

auto func = [&v](double x) { return std::sqrt(v[0]*std::abs(v[0])/(x*x)+v[1]*v[1]*std::pow(x,v[3])+v[2]*v[2]); };

CPPUNIT_ASSERT( compare( f.evaluate(x,v), func(x[0]) ) );
}

{
reco::FormulaEvaluator f("sqrt([0]*[0]/(x*x)+[1]*[1]/x+[2]*[2])");

std::vector<double> v = {2.3,0.20,0.009};
std::vector<double> x = {100.};

auto func = [&v](double x) { return std::sqrt(v[0]*v[0]/(x*x)+v[1]*v[1]/x+v[2]*v[2]); };

CPPUNIT_ASSERT( compare( f.evaluate(x,v), func(x[0]) ) );
}

}
16 changes: 14 additions & 2 deletions CondFormats/JetMETObjects/interface/JetResolutionObject.h
Expand Up @@ -20,7 +20,11 @@
#include <memory>
#include <initializer_list>

#ifndef STANDALONE
#include "CommonTools/Utils/interface/FormulaEvaluator.h"
#else
#include <TFormula.h>
#endif

enum class Variation {
NOMINAL = 0,
Expand Down Expand Up @@ -186,19 +190,27 @@ namespace JME {
return m_formula_str;
}

#ifndef STANDALONE
const reco::FormulaEvaluator* getFormula() const {
return m_formula.get();
}
#else
TFormula const * getFormula() const {
return m_formula.get();
}

#endif
void init();

private:
std::vector<std::string> m_bins_name;
std::vector<std::string> m_variables_name;
std::string m_formula_str;

#ifndef STANDALONE
std::shared_ptr<reco::FormulaEvaluator> m_formula COND_TRANSIENT;
#else
std::shared_ptr<TFormula> m_formula COND_TRANSIENT;

#endif
std::vector<Binning> m_bins COND_TRANSIENT;
std::vector<Binning> m_variables COND_TRANSIENT;

Expand Down
30 changes: 23 additions & 7 deletions CondFormats/JetMETObjects/src/JetResolutionObject.cc
Expand Up @@ -177,8 +177,11 @@ namespace JME {

void JetResolutionObject::Definition::init() {
if (!m_formula_str.empty())
#ifndef STANDALONE
m_formula = std::make_shared<reco::FormulaEvaluator>(m_formula_str);
#else
m_formula = std::make_shared<TFormula>("jet_resolution_formula", m_formula_str.c_str());

#endif
for (const auto& bin: m_bins_name) {
const auto& b = JetParameters::binning_to_string.right.find(bin);
if (b == JetParameters::binning_to_string.right.cend()) {
Expand Down Expand Up @@ -384,25 +387,38 @@ namespace JME {
if (! m_valid)
return 1;

#ifndef STANDALONE
const auto* formula = m_definition.getFormula();
#else
// Set parameters
auto const* pFormula = m_definition.getFormula();
if (! pFormula)
return 1;
auto formula = *pFormula;
auto formula = *pFormula;
#endif
// Create vector of variables value. Throw if some values are missing
std::vector<float> variables = variables_parameters.createVector(m_definition.getVariables());

const std::vector<float>& parameters = record.getParametersValues();
for (size_t index = 0; index < parameters.size(); index++) {
formula.SetParameter(index, parameters[index]);
}

double variables_[4] = {0};
for (size_t index = 0; index < m_definition.nVariables(); index++) {
variables_[index] = clip(variables[index], record.getVariablesRange()[index].min, record.getVariablesRange()[index].max);
}
const std::vector<float>& parameters = record.getParametersValues();

#ifndef STANDALONE
//ArrayAdaptor only takes doubles
std::vector<double> parametersD(parameters.begin(),parameters.end());
return formula->evaluate(
reco::formula::ArrayAdaptor(variables_,m_definition.nVariables()),
reco::formula::ArrayAdaptor(parametersD.data(),parametersD.size())
);
#else
for (size_t index = 0; index < parameters.size(); index++) {
formula.SetParameter(index, parameters[index]);
}

return formula.EvalPar(variables_);
#endif
}
}

Expand Down
24 changes: 12 additions & 12 deletions Configuration/AlCa/python/autoCond.py
Expand Up @@ -10,25 +10,25 @@
# GlobalTag for MC production (p-Pb collisions) with realistic alignment and calibrations for Run1
'run1_mc_pa' : '94X_mcRun1_pA_v1',
# GlobalTag for MC production with perfectly aligned and calibrated detector for Run2
'run2_design' : '94X_mcRun2_design_v2',
'run2_design' : '94X_mcRun2_design_v4',
# GlobalTag for MC production with pessimistic alignment and calibrations for Run2
'run2_mc_50ns' : '94X_mcRun2_startup_v2',
'run2_mc_50ns' : '94X_mcRun2_startup_v3',
#GlobalTag for MC production with optimistic alignment and calibrations for Run2
'run2_mc' : '94X_mcRun2_asymptotic_v2',
'run2_mc' : '94X_mcRun2_asymptotic_v3',
# GlobalTag for MC production (L1 Trigger Stage1) with starup-like alignment and calibrations for Run2, L1 trigger in Stage1 mode
'run2_mc_l1stage1' : '93X_mcRun2_asymptotic_v1',
# GlobalTag for MC production (cosmics) with starup-like alignment and calibrations for Run2, Strip tracker in peak mode
'run2_mc_cosmics' : '94X_mcRun2cosmics_startup_deco_v2',
'run2_mc_cosmics' : '94X_mcRun2cosmics_startup_deco_v3',
# GlobalTag for MC production (Heavy Ions collisions) with optimistic alignment and calibrations for Run2
'run2_mc_hi' : '93X_mcRun2_HeavyIon_v0',
# GlobalTag for MC production (p-Pb collisions) with realistic alignment and calibrations for Run2
'run2_mc_pa' : '94X_mcRun2_pA_v2',
'run2_mc_pa' : '94X_mcRun2_pA_v3',
# GlobalTag for Run1 data reprocessing
'run1_data' : '94X_dataRun2_v9',
'run1_data' : '94X_dataRun2_v10',
# GlobalTag for Run2 data reprocessing
'run2_data' : '94X_dataRun2_v9',
'run2_data' : '94X_dataRun2_v10',
# GlobalTag for Run2 data relvals: allows customization to run with fixed L1 menu
'run2_data_relval' : '94X_dataRun2_relval_v13',
'run2_data_relval' : '94X_dataRun2_relval_v14',
# GlobalTag for Run2 data 2016H relvals only: Prompt Conditions + fixed L1 menu (to be removed)
'run2_data_promptlike' : '94X_dataRun2_PromptLike_v9',
# GlobalTag for Run1 HLT: it points to the online GT
Expand All @@ -40,13 +40,13 @@
# GlobalTag for Run2 HLT for HI: it points to the online GT
'run2_hlt_hi' : '94X_dataRun2_HLTHI_frozen_v5',
# GlobalTag for MC production with perfectly aligned and calibrated detector for Phase1 2017 (and 0,0,~0-centred beamspot)
'phase1_2017_design' : '94X_mc2017_design_IdealBS_v10',
'phase1_2017_design' : '94X_mc2017_design_IdealBS_v11',
# GlobalTag for MC production with realistic conditions for Phase1 2017 detector
'phase1_2017_realistic' : '94X_mc2017_realistic_v14',
'phase1_2017_realistic' : '94X_mc2017_realistic_v15',
# GlobalTag for MC production (cosmics) with realistic alignment and calibrations for Phase1 2017 detector, Strip tracker in DECO mode
'phase1_2017_cosmics' : '94X_mc2017cosmics_realistic_deco_v10',
'phase1_2017_cosmics' : '94X_mc2017cosmics_realistic_deco_v11',
# GlobalTag for MC production (cosmics) with realistic alignment and calibrations for Phase1 2017 detector, Strip tracker in PEAK mode
'phase1_2017_cosmics_peak' : '94X_mc2017cosmics_realistic_peak_v10',
'phase1_2017_cosmics_peak' : '94X_mc2017cosmics_realistic_peak_v11',
# GlobalTag for MC production with perfectly aligned and calibrated detector for full Phase1 2018 (and 0,0,0-centred beamspot)
'phase1_2018_design' : '94X_upgrade2018_design_IdealBS_v7',
# GlobalTag for MC production with realistic conditions for full Phase1 2018 detector
Expand Down

0 comments on commit 19915d6

Please sign in to comment.