CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PerformancePayloadFromBinnedTFormula.cc
Go to the documentation of this file.
2 
4 #include <boost/uuid/uuid.hpp>
5 #include <boost/uuid/uuid_generators.hpp>
6 #include <boost/uuid/uuid_io.hpp>
7 #include <boost/lexical_cast.hpp>
8 
9 
10 
12 
13 #include <iostream>
14 using namespace std;
15 
17  boost::uuids::random_generator gen;
18  for (unsigned int t=0; t< pls.size(); ++t){
19  std::vector <boost::shared_ptr<TFormula> > temp;
20  for (unsigned int i=0; i< (pls[t].formulas()).size(); ++i){
21  boost::uuids::uuid uniqueFormulaId = gen();
22  const auto formulaUniqueName = boost::lexical_cast<std::string>(uniqueFormulaId);
24  boost::shared_ptr<TFormula> tt(new TFormula(formulaUniqueName.c_str(),tmp.formulas()[i].c_str()));
25  tt->Compile();
26  temp.push_back(tt);
27  }
28  compiledFormulas_.push_back(temp);
29  }
30 }
31 
32 
33 
35  //
36  // chooses the correct rectangular region
37  //
38  if (! isInPayload(r,p)) { throw cms::Exception("MalformedPerfPayload") << "Requested performance data not available!"; }
39  unsigned int region;
40  bool ok = isOk(p,region);
41  if (ok == false) { throw cms::Exception("MalformedPerfPayload") << "Requested variable does not match internal structure!"; }
42 
43  return compiledFormulas_[region][resultPos(r)];
44 
45 }
46 
48  BinningPointByMap p = _p;
49  //
50  // which formula to use?
51  //
52  if (! isInPayload(r,p)) return PerformancePayload::InvalidResult;
53 
54  // nice, what to do here???
55  // TFormula * formula = compiledFormulas_[resultPos(r)];
56  //
57 
58  const boost::shared_ptr<TFormula>& formula = getFormula(r,p);
59 
60  // prepare the vector to pass, order counts!!!
61  //
62  std::vector<BinningVariables::BinningVariablesType> t = myBinning();
63 
64  // sorry, TFormulas just work up to dimension==4
65  Double_t values[4];
66  int i=0;
67  for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end();++it, ++i){
68  values[i] = p.value(*it);
69  }
70  //
71  // i need a non const version
72  // Note, in current implementation of TFormula EvalPar should be
73  // thread safe as it does nothing more than call a function
74  // through a function pointer which is stateless. In spite of the
75  // fact that it is not const.
76  return formula->EvalPar(values);
77 }
78 
79 bool PerformancePayloadFromBinnedTFormula::isOk(const BinningPointByMap& _p,unsigned int& whichone) const {
80 
81  BinningPointByMap p = _p;
82  //
83  // change: look on whether a single rectangularr region matches
84  //
85  for (unsigned int ti=0; ti< pls.size(); ++ti){
86  bool result = true;
87  std::vector<BinningVariables::BinningVariablesType> t = myBinning();
88  for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end();++it){
89  //
90  // now looking into a single payload
91  //
92  if (! p.isKeyAvailable(*it)) return false;
93  float v = p.value(*it);
94  int pos = limitPos(*it);
95  std::pair<float, float> limits = (pls[ti].limits())[pos];
96  if (v<limits.first || v>limits.second) result= false;
97  }
98  if (result == true) {
99  whichone = ti;
100  return true;
101  }
102  }
103  whichone = 9999;
104  return false;
105 }
106 
108  // first, let's see if it is available at all
109  if (resultPos(res) == PerformancePayloadFromBinnedTFormula::InvalidPos) return false;
110  unsigned int whocares;
111  if ( ! isOk(point,whocares)) return false;
112  return true;
113 }
114 
116  //
117  // which formula to use?
118  //
119  if (resultPos(res) == PerformancePayloadFromBinnedTFormula::InvalidPos) {
120  cout << "Warning: result not available!" << endl;
121  }
122 
123  // nice, what to do here???
124  const boost::shared_ptr<TFormula>& formula = getFormula(res, point);
125  unsigned int whichone;
126  isOk(point,whichone);
127  cout << "-- Formula: " << formula->GetExpFormula("p") << endl;
128  // prepare the vector to pass, order counts!!!
129  //
130  std::vector<BinningVariables::BinningVariablesType> t = myBinning();
131 
132  for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end();++it){
133  int pos = limitPos(*it);
134  std::pair<float, float> limits = (pls[whichone].limits())[pos];
135  cout << " Variable: " << *it << " with limits: " << "from: " << limits.first << " to: " << limits.second << endl;
136  }
137 
138 }
139 
int i
Definition: DBlmapReader.cc:9
bool isOk(const BinningPointByMap &p, unsigned int &) const
bool isKeyAvailable(BinningVariables::BinningVariablesType)
const boost::shared_ptr< TFormula > & getFormula(PerformanceResult::ResultType, const BinningPointByMap &) const
static const float InvalidResult
float value(BinningVariables::BinningVariablesType)
tuple result
Definition: query.py:137
void printFormula(PerformanceResult::ResultType res, const BinningPointByMap &) const
float getResult(PerformanceResult::ResultType, const BinningPointByMap &) const
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:96
virtual bool isInPayload(PerformanceResult::ResultType, const BinningPointByMap &) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
tuple cout
Definition: gather_cfg.py:121
tuple size
Write out results.
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5