Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:25

0001 #include "CondFormats/PhysicsToolsObjects/interface/PerformancePayloadFromTFormula.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "FWCore/Utilities/interface/GlobalIdentifier.h"
0004 
0005 const int PerformancePayloadFromTFormula::InvalidPos = -1;
0006 
0007 #include <iostream>
0008 using namespace std;
0009 
0010 void PerformancePayloadFromTFormula::initialize() {
0011   for (std::vector<std::string>::const_iterator formula = pl.formulas().begin(); formula != pl.formulas().end();
0012        ++formula) {
0013     const auto formulaUniqueName = edm::createGlobalIdentifier();
0014     //be sure not to add TFormula to ROOT's global list
0015     auto temp = std::make_shared<TFormula>(formulaUniqueName.c_str(), formula->c_str(), false);
0016     temp->Compile();
0017     compiledFormulas_.emplace_back(std::move(temp));
0018   }
0019 }
0020 
0021 float PerformancePayloadFromTFormula::getResult(PerformanceResult::ResultType r, const BinningPointByMap& _p) const {
0022   BinningPointByMap p = _p;
0023   //
0024   // which formula to use?
0025   //
0026   if (!isInPayload(r, p)) {
0027     edm::LogError("PerformancePayloadFromTFormula")
0028         << "Missing formula in conditions. Maybe code/conditions are inconsistent" << std::endl;
0029     assert(false);
0030   }
0031 
0032   const TFormula* formula = compiledFormulas_[resultPos(r)].get();
0033   //
0034   // prepare the vector to pass, order counts!!!
0035   //
0036   std::vector<BinningVariables::BinningVariablesType> t = myBinning();
0037 
0038   // sorry, TFormulas just work up to dimension==4
0039   Double_t values[4];
0040   int i = 0;
0041   for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end(); ++it, ++i) {
0042     values[i] = p.value(*it);
0043   }
0044   //
0045   return formula->EvalPar(values);
0046 }
0047 
0048 bool PerformancePayloadFromTFormula::isOk(const BinningPointByMap& _p) const {
0049   BinningPointByMap p = _p;
0050   std::vector<BinningVariables::BinningVariablesType> t = myBinning();
0051 
0052   for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end(); ++it) {
0053     if (!p.isKeyAvailable(*it))
0054       return false;
0055     float v = p.value(*it);
0056     int pos = limitPos(*it);
0057     std::pair<float, float> limits = (pl.limits())[pos];
0058     if (v < limits.first || v > limits.second)
0059       return false;
0060   }
0061   return true;
0062 }
0063 
0064 bool PerformancePayloadFromTFormula::isInPayload(PerformanceResult::ResultType res,
0065                                                  const BinningPointByMap& point) const {
0066   // first, let's see if it is available at all
0067   if (resultPos(res) == PerformancePayloadFromTFormula::InvalidPos)
0068     return false;
0069 
0070   if (!isOk(point))
0071     return false;
0072   return true;
0073 }
0074 
0075 void PerformancePayloadFromTFormula::printFormula(PerformanceResult::ResultType res) const {
0076   //
0077   // which formula to use?
0078   //
0079   if (resultPos(res) == PerformancePayloadFromTFormula::InvalidPos) {
0080     cout << "Warning: result not available!" << endl;
0081     return;
0082   }
0083 
0084   const TFormula* formula = compiledFormulas_[resultPos(res)].get();
0085   cout << "-- Formula: " << formula->GetExpFormula("p") << endl;
0086   // prepare the vector to pass, order counts!!!
0087   //
0088   std::vector<BinningVariables::BinningVariablesType> t = myBinning();
0089 
0090   for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end(); ++it) {
0091     int pos = limitPos(*it);
0092     std::pair<float, float> limits = (pl.limits())[pos];
0093     cout << "      Variable: " << *it << " with limits: "
0094          << "from: " << limits.first << " to: " << limits.second << endl;
0095   }
0096 }
0097 
0098 #include "FWCore/Utilities/interface/typelookup.h"
0099 TYPELOOKUP_DATA_REG(PerformancePayloadFromTFormula);