CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/CondFormats/PhysicsToolsObjects/src/PerformancePayloadFromBinnedTFormula.cc

Go to the documentation of this file.
00001 #include "CondFormats/PhysicsToolsObjects/interface/PerformancePayloadFromBinnedTFormula.h"
00002 
00003 int PerformancePayloadFromBinnedTFormula::InvalidPos=-1;
00004 
00005 #include <iostream>
00006 using namespace std;
00007 
00008 
00009 TFormula * PerformancePayloadFromBinnedTFormula::getFormula(PerformanceResult::ResultType r ,BinningPointByMap p ) const {
00010   //
00011   // chooses the correct rectangular region
00012   //
00013   if (! isInPayload(r,p)) return NULL;
00014   unsigned int region;
00015   bool ok =  isOk(p,region);
00016   if (ok == false) return NULL;
00017 
00018   return compiledFormulas_[region][resultPos(r)];
00019 
00020 }
00021 
00022 float PerformancePayloadFromBinnedTFormula::getResult(PerformanceResult::ResultType r ,BinningPointByMap p) const {
00023   check();
00024   //
00025   // which formula to use?
00026   //
00027   if (! isInPayload(r,p)) return PerformancePayload::InvalidResult;
00028 
00029   // nice, what to do here???
00030   //  TFormula * formula = compiledFormulas_[resultPos(r)];
00031   //
00032 
00033   TFormula * formula = getFormula(r,p);
00034 
00035   // prepare the vector to pass, order counts!!!
00036   //
00037   std::vector<BinningVariables::BinningVariablesType> t = myBinning();
00038   
00039   // sorry, TFormulas just work up to dimension==4
00040   Double_t values[4];
00041   int i=0;
00042   for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end();++it, ++i){
00043     values[i] = p.value(*it);    
00044   }
00045   //
00046   // i need a non const version #$%^
00047   return formula->EvalPar(values);
00048 }
00049 
00050 bool PerformancePayloadFromBinnedTFormula::isOk(BinningPointByMap p,unsigned int& whichone) const {
00051   
00052   //
00053   // change: look on whether a single rectangularr region matches
00054   //
00055   for (unsigned int ti=0; ti< pls.size(); ++ti){
00056     bool result = true;
00057     std::vector<BinningVariables::BinningVariablesType>  t = myBinning();
00058     for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end();++it){
00059       //
00060       // now looking into a single payload
00061       //
00062       if (!   p.isKeyAvailable(*it)) return false;
00063       float v = p.value(*it);
00064       int pos = limitPos(*it);
00065       std::pair<float, float> limits = (pls[ti].limits())[pos];
00066       if (v<limits.first || v>limits.second) result= false;
00067     }
00068     if (result == true)  {
00069       whichone = ti;
00070       return true;
00071     }
00072   }
00073   whichone = 9999;
00074   return false;
00075 }
00076 
00077 bool PerformancePayloadFromBinnedTFormula::isInPayload(PerformanceResult::ResultType res,BinningPointByMap point) const {
00078   check();
00079   // first, let's see if it is available at all
00080   if (resultPos(res) == PerformancePayloadFromBinnedTFormula::InvalidPos) return false;
00081   unsigned int whocares;
00082   if ( ! isOk(point,whocares)) return false;
00083   return true;
00084 }
00085 
00086 
00087 void PerformancePayloadFromBinnedTFormula::check() const {
00088   if (pls.size()== compiledFormulas_.size()) return;
00089   //
00090   // otherwise, compile!
00091   //
00092   compiledFormulas_.clear();
00093   for (unsigned int t=0; t< pls.size(); ++t){
00094     std::vector <TFormula *> temp;
00095     for (unsigned int i=0; i< (pls[t].formulas()).size(); ++i){
00096       PhysicsTFormulaPayload  tmp = pls[t];
00097       TFormula* tt = new TFormula("rr",((tmp.formulas())[i]).c_str()); //FIXME: "rr" should be unique!
00098       tt->Compile();
00099       temp.push_back(tt);
00100     }
00101     compiledFormulas_.push_back(temp);
00102   }
00103 }
00104 
00105 
00106 
00107 
00108 void PerformancePayloadFromBinnedTFormula::printFormula(PerformanceResult::ResultType res,BinningPointByMap point) const {
00109   check();
00110   //
00111   // which formula to use?
00112   //
00113   if (resultPos(res) == PerformancePayloadFromBinnedTFormula::InvalidPos)  {
00114     cout << "Warning: result not available!" << endl;
00115   }
00116   
00117   // nice, what to do here???
00118   TFormula * formula = getFormula(res, point);
00119   unsigned int whichone;
00120   isOk(point,whichone);
00121   cout << "-- Formula: " << formula->GetExpFormula("p") << endl;
00122   // prepare the vector to pass, order counts!!!
00123   //
00124   std::vector<BinningVariables::BinningVariablesType> t = myBinning();
00125   
00126   for (std::vector<BinningVariables::BinningVariablesType>::const_iterator it = t.begin(); it != t.end();++it){
00127     int pos = limitPos(*it);
00128     std::pair<float, float> limits = (pls[whichone].limits())[pos];
00129     cout << "      Variable: " << *it << " with limits: " << "from: " << limits.first  << " to: " << limits.second << endl;
00130   }
00131 
00132 }
00133 
00134 #include "FWCore/Utilities/interface/typelookup.h"
00135 TYPELOOKUP_DATA_REG(PerformancePayloadFromBinnedTFormula);