NC::GetChiSqrFromDerived Class Reference

Wrap NCExtrapolation::GetChiSqrForMap so that it can be called by the contour finder. More...

Inheritance diagram for NC::GetChiSqrFromDerived:
NC::Fitter::ICallableND

List of all members.

Public Member Functions

 GetChiSqrFromDerived ()
 GetChiSqrFromDerived (NCExtrapolation *P, std::vector< NCParameter > pars, bool penalty, bool analyticNorm)
virtual ~GetChiSqrFromDerived ()
double EvalAtEx (const CoordNDim &r, CoordNDim *ret) const
 Find the value of the function and return additional information.
void UsePenalty (bool p)
void DrawAndWriteGraph () const

Private Attributes

NCExtrapolationp
std::vector< NCParameterparams
bool usePenalty
bool fAnalyticNormalization

Static Private Attributes

static std::map< CoordNDim,
double > 
cache
static std::vector< CoordNDimevaledAt
static std::vector< double > chisqRets

Detailed Description

Wrap NCExtrapolation::GetChiSqrForMap so that it can be called by the contour finder.

Additionally keep a cache to speed up repeated queries. Evaluates points outside the physical region using a penalty term.

Definition at line 33 of file NCFitMaster.cxx.


Constructor & Destructor Documentation

NC::GetChiSqrFromDerived::GetChiSqrFromDerived (  )  [inline]

Definition at line 36 of file NCFitMaster.cxx.

00036 {}

NC::GetChiSqrFromDerived::GetChiSqrFromDerived ( NCExtrapolation P,
std::vector< NCParameter pars,
bool  penalty,
bool  analyticNorm 
) [inline]

Definition at line 37 of file NCFitMaster.cxx.

00041       :p(P), params(pars), usePenalty(penalty),
00042        fAnalyticNormalization(analyticNorm){}

virtual NC::GetChiSqrFromDerived::~GetChiSqrFromDerived (  )  [inline, virtual]

Definition at line 43 of file NCFitMaster.cxx.

00043 {} // shut gcc up


Member Function Documentation

void NC::GetChiSqrFromDerived::DrawAndWriteGraph (  )  const

Definition at line 136 of file NCFitMaster.cxx.

References evaledAt, Munits::g, Munits::m, and n.

00137 {
00138   TCanvas c("minimizer_eval_positions");
00139   TH2D axes("", "Evaluation Positions;time;", 100, 0, evaledAt.size(), 100, -1, 5);
00140   axes.Draw();
00141   for(unsigned int m = 0; m < evaledAt[0].size(); ++m){
00142     TGraph* g = new TGraph;
00143     g->Set(evaledAt.size());
00144     g->SetMarkerColor(m+1);
00145     for(unsigned int n = 0; n < evaledAt.size(); ++n){
00146       g->SetPoint(n, n, evaledAt[n][m]);
00147       g->Draw("p same");
00148     }
00149   }
00150 
00151   c.Write();
00152 }

double NC::GetChiSqrFromDerived::EvalAtEx ( const CoordNDim r,
CoordNDim ret 
) const [virtual]

Find the value of the function and return additional information.

Parameters:
r Coordinate at which to evaluate the function
[out] ret Return additional information. By convention, the true underlying coordinates evaluated.
Returns:
Value of the function at the point r

Implementations must be prepared for ret to be null

Todo:
Rename to just EvalAt

Implements NC::Fitter::ICallableND.

Definition at line 65 of file NCFitMaster.cxx.

References cache, chisqRets, evaledAt, fAnalyticNormalization, NCExtrapolation::FindChiSqrForPars(), NCExtrapolation::GetCoordConv(), it, n, NC::CoordinateConverter::OscParsFromCoordNDim(), p, params, NC::CoordinateConverter::SystParsFromCoordNDim(), and usePenalty.

00067 {
00068   if(retCoord) *retCoord = r;
00069 
00070   evaledAt.push_back(r);
00071 
00072   const map<CoordNDim, double>::const_iterator it = cache.find(r);
00073   if(it != cache.end()){
00074 //    cout << "chisq from cache " << r << endl;
00075     chisqRets.push_back(it->second);
00076     return it->second;
00077   }
00078   // Maximum cache size is arbitrary, tune for performance.
00079   const unsigned int maxCacheSize = int(1e7); // on the order of 10meg
00080   if(cache.size() > maxCacheSize) cache.clear();
00081   //cout << "UNCACHED CHISQ REQUESTED " << r << endl;
00082 
00083   CoordNDim evalAt = r;
00084 
00085   if(usePenalty){
00086     // If the point is outside the physical region - move it to the boundary
00087     for(unsigned int n = 0; n < params.size(); ++n){
00088       if(params[n].UseLimits()){
00089         if(r[n] < params[n].Min()) evalAt[n] = params[n].Min();
00090         if(r[n] > params[n].Max()) evalAt[n] = params[n].Max();
00091       }
00092     }
00093   }
00094 
00095   const CoordinateConverter* cc = p->GetCoordConv();
00096   NC::OscProb::OscPars* oscPars = cc->OscParsFromCoordNDim(evalAt);
00097 
00098   double norm = 1;
00099   double ret = p->FindChiSqrForPars(oscPars,
00100                                     cc->SystParsFromCoordNDim(evalAt),
00101                                     fAnalyticNormalization ? &norm : 0);
00102 
00103   // TODO WE NEED TO STORE NORM INTO RETCOORD, BUT DON'T KNOW WHICH ONE!
00104 
00105   delete oscPars;
00106 
00107   if(usePenalty){
00108     // If we had to move the point then apply a quadratic penalty term.
00109     // The factor of 1000 was arrived at through trial and error.
00110     const double amplitude = 1e3;
00111     for(unsigned int n = 0; n < params.size(); ++n){
00112       if(params[n].UseLimits()){
00113         const double wsqr = (params[n].Min()-params[n].Max())*(params[n].Min()-params[n].Max());
00114         assert(wsqr);
00115         if(r[n] < params[n].Min())
00116           ret += amplitude*(params[n].Min()-r[n])*(params[n].Min()-r[n])/wsqr;
00117         if(r[n] > params[n].Max())
00118           ret += amplitude*(r[n]-params[n].Max())*(r[n]-params[n].Max())/wsqr;
00119       }
00120     }
00121   }
00122 
00123   //  for(unsigned int n = 0; n < evalAt.size(); ++n)
00124   //    cout << names[n] << " = " << evalAt[n] << "  ";
00125   //  cout << "-> " << ret << endl;
00126 
00127   // TODO - this cache is broken when using more than one extrapolation
00128   // disable it for now
00129   //  cache[r] = ret;
00130   chisqRets.push_back(ret);
00131 
00132   return ret;
00133 }

void NC::GetChiSqrFromDerived::UsePenalty ( bool  p  )  [inline]

Definition at line 45 of file NCFitMaster.cxx.

References usePenalty.

Referenced by NC::FitMaster::Run().

00045 {usePenalty = p;}


Member Data Documentation

map< CoordNDim, double > NC::GetChiSqrFromDerived::cache [static, private]

Definition at line 50 of file NCFitMaster.cxx.

Referenced by EvalAtEx().

vector< double > NC::GetChiSqrFromDerived::chisqRets [static, private]

Definition at line 55 of file NCFitMaster.cxx.

Referenced by EvalAtEx().

Definition at line 54 of file NCFitMaster.cxx.

Referenced by DrawAndWriteGraph(), and EvalAtEx().

Definition at line 53 of file NCFitMaster.cxx.

Referenced by EvalAtEx().

Definition at line 48 of file NCFitMaster.cxx.

Referenced by EvalAtEx().

Definition at line 51 of file NCFitMaster.cxx.

Referenced by EvalAtEx().

Definition at line 52 of file NCFitMaster.cxx.

Referenced by EvalAtEx(), and UsePenalty().


The documentation for this class was generated from the following file:

Generated on 24 Jul 2018 for loon by  doxygen 1.6.1