CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CondFormats/PhysicsToolsObjects/src/PerformancePayloadFromTFormula.cc

Go to the documentation of this file.
00001 #include "CondFormats/PhysicsToolsObjects/interface/PerformancePayloadFromTFormula.h"
00002 
00003 int PerformancePayloadFromTFormula::InvalidPos=-1;
00004 
00005 #include <iostream>
00006 using namespace std;
00007 
00008 float PerformancePayloadFromTFormula::getResult(PerformanceResult::ResultType r ,BinningPointByMap p) const {
00009   check();
00010   //
00011   // which formula to use?
00012   //
00013   if (! isInPayload(r,p)) return PerformancePayload::InvalidResult;
00014 
00015   // nice, what to do here???
00016   TFormula * formula = compiledFormulas_[resultPos(r)];
00017   //
00018   // prepare the vector to pass, order counts!!!
00019   //
00020   std::vector<BinningVariables::BinningVariablesType> t = myBinning();
00021   
00022   // sorry, TFormulas just work up to dimension==4
00023   Double_t values[4];
00024   int i=0;
00025   for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end();++it, ++i){
00026     values[i] = p.value(*it);    
00027   }
00028   //
00029   // i need a non const version #$%^
00030   return formula->EvalPar(values);
00031 }
00032 
00033 bool PerformancePayloadFromTFormula::isOk(BinningPointByMap p) const {
00034   
00035   std::vector<BinningVariables::BinningVariablesType> t = myBinning();
00036   
00037   for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end();++it){
00038     if (!   p.isKeyAvailable(*it)) return false;
00039     float v = p.value(*it);
00040     int pos = limitPos(*it);
00041     std::pair<float, float> limits = (pl.limits())[pos];
00042     if (v<limits.first || v>limits.second) return false;
00043   }
00044   return true;
00045 }
00046 
00047 bool PerformancePayloadFromTFormula::isInPayload(PerformanceResult::ResultType res,BinningPointByMap point) const {
00048   check();
00049   // first, let's see if it is available at all
00050   if (resultPos(res) == PerformancePayloadFromTFormula::InvalidPos) return false;
00051   
00052   if ( ! isOk(point)) return false;
00053   return true;
00054 }
00055 
00056 
00057 void PerformancePayloadFromTFormula::check() const {
00058   if (pl.formulas().size() == compiledFormulas_.size()) return;
00059   //
00060   // otherwise, compile!
00061   //
00062   for (unsigned int i=0; i< pl.formulas().size(); ++i){
00063     TFormula* t = new TFormula("rr",(pl.formulas()[i]).c_str()); //FIXME: "rr" should be unique!
00064     t->Compile();
00065     compiledFormulas_.push_back(t);
00066   }
00067 }
00068 
00069 void PerformancePayloadFromTFormula::printFormula(PerformanceResult::ResultType res) const {
00070   check();
00071   //
00072   // which formula to use?
00073   //
00074   if (resultPos(res) == PerformancePayloadFromTFormula::InvalidPos)  {
00075     cout << "Warning: result not available!" << endl;
00076   }
00077   
00078   // nice, what to do here???
00079   TFormula * formula = compiledFormulas_[resultPos(res)];
00080   cout << "-- Formula: " << formula->GetExpFormula("p") << endl;
00081   // prepare the vector to pass, order counts!!!
00082   //
00083   std::vector<BinningVariables::BinningVariablesType> t = myBinning();
00084   
00085   for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end();++it){
00086     int pos = limitPos(*it);
00087     std::pair<float, float> limits = (pl.limits())[pos];
00088     cout << "      Variable: " << *it << " with limits: " << "from: " << limits.first  << " to: " << limits.second << endl;
00089   }
00090 
00091 }
00092 
00093 
00094 
00095 #include "FWCore/Framework/interface/EventSetup.h"
00096 #include "FWCore/Framework/interface/ESHandle.h"
00097 #include "FWCore/Framework/interface/ModuleFactory.h"
00098 
00099 #include "FWCore/Utilities/interface/typelookup.h"
00100 TYPELOOKUP_DATA_REG(PerformancePayloadFromTFormula);