Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

NCContourFinder Namespace Reference


Classes

class  NCContourFinder::Coord
class  NCContourFinder::FindMinSimple< Callable >
class  NCContourFinder::FixVars< Callable >
class  NCContourFinder::MarginalizeSimple< Callable >
class  NCContourFinder::MinuitForCallable< Callable >
class  NCContourFinder::MarginalizeHybrid< Callable >

Typedefs

typedef std::vector< double > CoordNDim

Functions

template<class Callable>
double FindMinMinuit (const Callable &chiSqrFunc, const std::vector< NCParameter > params, CoordNDim &ret, TMinuit **ppMinu)
template<class Callable>
std::vector< CoordFindContour (const Callable &func, const Coord &minCoord, const double &height, const Coord &precision)
template<class Callable>
TH2D * GetLowResGrid (const Callable &func, const Coord min, const Coord max, const Coord prec)
template<class Callable>
TGraph * CreateOneDimProjection (const Callable &func, const NCParameter param, const double minVal, double &leftErr, double &rightErr)
template<class Callable>
void PrintGridSearch (const Callable &func, const std::vector< NCParameter > &params, std::ostream &out)


Typedef Documentation

typedef std::vector<double> NCContourFinder::CoordNDim
 

Definition at line 23 of file NCContourFinder.h.

Referenced by NCContourFinder::MarginalizeHybrid< Callable >::AlreadyAtMinimum(), NCContourFinder::FindMinSimple< Callable >::BeginSearchPos(), NCContourFinder::MinuitForCallable< Callable >::Eval(), NCExtrapolation::FillResultHistograms(), NCExtrapolation::GetBestFitPoint(), NCExtrapolation::GetChiSqrFromDerived::operator()(), NCContourFinder::MarginalizeSimple< Callable >::operator()(), NCContourFinder::FindMinSimple< Callable >::operator()(), NCExtrapolationJK_fit::PredictSpectrum(), and PrintGridSearch().


Function Documentation

template<class Callable>
TGraph * NCContourFinder::CreateOneDimProjection const Callable &  func,
const NCParameter  param,
const double  minVal,
double &  leftErr,
double &  rightErr
 

Definition at line 312 of file NCContourFinder.cxx.

References NCParameter::max, NCParameter::min, MSG, and NCParameter::prec.

Referenced by NCExtrapolation::Get1DProjection().

00317   {
00318     // +.5 makes us round to nearest int instead of toward zero.
00319     const int steps = int(.5+(param.max-param.min)/param.prec);
00320 
00321     vector<double> x, y;
00322 
00323     bool needLeftErr = true;
00324     bool needRightErr = true;
00325 
00326     // Initialize right error for downward sloping projections.
00327     // .5 is to be consistent with binning elsewhere.
00328     rightErr = param.max+.5*param.prec;
00329 
00330     for(int nx = 0; nx <= steps; ++nx){
00331       x.push_back(param.min+nx*param.prec);
00332       MSG("NCContourFinder", Msg::kVerbose) << "Projection: " << nx+1
00333                                             << "/" << steps << " "
00334                                             << x[nx] << endl;
00335       double upVal = func(Coord(x[nx], -999))-minVal;
00336       y.push_back(upVal);
00337 
00338       if(needRightErr && !needLeftErr && upVal > 1){
00339         needRightErr = false;
00340         rightErr = x[nx];
00341       }
00342       if(needLeftErr && upVal < 1){
00343         needLeftErr = false;
00344         leftErr = x[nx]-param.prec;
00345       }
00346     }
00347 
00348     TGraph *ret = new TGraph(steps+1, &x[0], &y[0]);
00349 
00350     return ret;
00351   }

template<class Callable>
std::vector< Coord > NCContourFinder::FindContour const Callable &  func,
const Coord &  minCoord,
const double &  height,
const Coord &  precision
 

Definition at line 162 of file NCContourFinder.cxx.

References MSG, NCContourFinder::Coord::x, and NCContourFinder::Coord::y.

Referenced by NCExtrapolation::GetContour().

00166   {
00167     const double dx = precision.x;
00168     const double dy = precision.y;
00169 
00170     typedef pair<int, int> Box;    // first == left, second == top
00171 
00172     std::map<Box, bool> results;   // Is this box already in the result set?
00173     std::vector<Box> todo;         // Boxes to investigate
00174     std::map<Box, double> heights; // Boxes whose topleft corner has already been evaluated, used as cache.
00175 
00176     // Top left corner of the box containing the best fit.
00177     const int bfxi = int(minCoord.x/dx);
00178     const int bfyi = int(minCoord.y/dy);
00179 
00180     MSG("NCContourFinder", Msg::kVerbose) << "Contour: walking left" << endl;
00181     // Walk to the left
00182     for(int x = bfxi; ; --x){
00183       // As soon as we exceed the contour
00184       MSG("NCExtrapolation", Msg::kVerbose) << "Contour: at " << x << endl;
00185       if(func(Coord(x*dx, bfyi*dy)) > height){
00186         // make it the first element in the todo list
00187         todo.push_back(Box(x, bfyi));
00188         // and stop going left.
00189         break;
00190       }
00191     }
00192 
00193     // NB - for some reason while writing this I decided that increasing y is downward.
00194 
00195     std::vector<Coord> contour;
00196 
00197     while(!todo.empty()){
00198       Box now = todo.back();
00199       todo.pop_back();
00200 
00201       // We end up evaluating the function multiple times at each point, so are
00202       // relying heavily on the cacheing done in GetChiSqrFromDerived()
00203 
00204       MSG("NCContourFinder", Msg::kVerbose) << "Contour: at " << now.first << "," << now.second << endl;
00205 
00206       // Set by the loop below.
00207       double topleft, topright, bottomleft, bottomright;
00208 
00209       // Evaluate the function at all the corners.
00210       for(int cx = 0; cx <= 1; ++cx){
00211         for(int cy = 0; cy <=1; ++cy){
00212           Box corner(now.first+cx, now.second+cy);
00213           const std::map<Box, double>::const_iterator it = heights.find(corner);
00214           double heightHere;
00215           if(it == heights.end()){
00216             heightHere = func(Coord((now.first+cx)*dx, (now.second+cy)*dy));
00217             heights[corner] = heightHere;
00218           }
00219           else{
00220             heightHere = heights[corner];
00221           }
00222           if(cx == 0 && cy == 0) topleft = heightHere;
00223           if(cx == 1 && cy == 0) topright = heightHere;
00224           if(cx == 0 && cy == 1) bottomleft = heightHere;
00225           if(cx == 1 && cy == 1) bottomright = heightHere;
00226         }
00227       }
00228 
00229       MSG("NCContourFinder", Msg::kVerbose) << "Contour: tl,tr,bl,br=" << topleft << " "
00230                                             << topright << " " << bottomleft << " "
00231                                             << bottomright << endl;
00232 
00233       // For each side of the box: see if one corner is high and the other low.
00234       // If so, and if the box adjacent on this side isn't already part of the
00235       // results, then append the adjacent box to the todo list and linearly
00236       // interpolate to find where to put the contour point on that edge.
00237 
00238       if( (topright-height)*(bottomright-height) <= 0){
00239         Box right(now.first+1, now.second);
00240         if(!results[right]){
00241           MSG("NCContourFinder", Msg::kVerbose) << "Contour: went right" << endl;
00242           todo.push_back(right);
00243           results[right] = true;
00244           contour.push_back(Coord((now.first+1)*dx, (now.second+(height-topright)/(bottomright-topright))*dy));
00245         }
00246       }
00247       if( (topleft-height)*(bottomleft-height) <= 0){
00248         Box left(now.first-1, now.second);
00249         if(!results[left]){
00250           MSG("NCContourFinder", Msg::kVerbose) << "Contour: went left" << endl;
00251           todo.push_back(left);
00252           results[left] = true;
00253           contour.push_back(Coord(now.first*dx, (now.second+(height-topleft)/(bottomleft-topleft))*dy));
00254         }
00255       }
00256       if( (bottomleft-height)*(bottomright-height) <= 0){
00257         Box down(now.first, now.second+1);
00258         if(!results[down]){
00259           MSG("NCContourFinder", Msg::kVerbose) << "Contour: went down" << endl;
00260           todo.push_back(down);
00261           results[down] = true;
00262           contour.push_back(Coord((now.first+(height-bottomleft)/(bottomright-bottomleft))*dx, (now.second+1)*dy));
00263         }
00264       }
00265       if( (topleft-height)*(topright-height) <= 0 ){
00266         Box up(now.first, now.second-1);
00267         if(!results[up]){
00268           MSG("NCContourFinder", Msg::kVerbose) << "Contour: went up" << endl;
00269           todo.push_back(up);
00270           results[up] = true;
00271           contour.push_back(Coord((now.first+(height-topleft)/(topright-topleft))*dx, now.second*dy));
00272         }
00273       }
00274     }
00275 
00276     if(contour.size()) contour.push_back(contour[0]); // Close the loop.
00277     return contour;
00278   }

template<class Callable>
double NCContourFinder::FindMinMinuit const Callable &  chiSqrFunc,
const std::vector< NCParameter params,
CoordNDim ret,
TMinuit **  minu = 0
 

Definition at line 113 of file NCContourFinder.cxx.

References MSG.

Referenced by NCExtrapolation::MakeDeltaChiSqrMaps().

00117   {
00118     ret.resize(params.size());
00119 
00120     TMinuit* minu = new MinuitForCallable<Callable>(chiSqrFunc, params.size());
00121     minu->SetPrintLevel(-1); // Shut Minuit up.
00122     minu->Command("set strategy 2"); // Be careful, instead of fast.
00123 
00124     for(int n = 0; n < int(params.size()); ++n)
00125       // NB - no parameter limits imposed.
00126       minu->DefineParameter(n, params[n].shortName.c_str(),
00127                             (params[n].min+params[n].max)/2, (params[n].max-params[n].min)/4,
00128                             0, 0);
00129 
00130     // Minuit tries to return a lot of parameters we don't want to keep.
00131     double junkd; int junki; TString junks;
00132 
00133     if(minu->Migrad()){
00134       MSG("NCContourFinder", Msg::kWarning) << "Migrad failed, falling back to Simplex.\n";
00135       minu->SetPrintLevel(0); // Things are going wrong, we should let the user see.
00136       minu->mnsimp();
00137       minu->Migrad();
00138     }
00139 
00140     double minChiSqr;
00141     minu->mnstat(minChiSqr, junkd, junkd, junki, junki, junki);
00142 
00143     for(unsigned int n = 0; n < params.size(); ++n)
00144       minu->GetParameter(n, ret[n], junkd);
00145 
00146     if(ppMinu)
00147       *ppMinu = minu;
00148     else
00149       delete minu;
00150 
00151     return minChiSqr;
00152   }

template<class Callable>
TH2D * NCContourFinder::GetLowResGrid const Callable &  func,
const Coord  min,
const Coord  max,
const Coord  prec
 

Definition at line 283 of file NCContourFinder.cxx.

References max, min, MSG, NCContourFinder::Coord::x, and NCContourFinder::Coord::y.

Referenced by NCExtrapolation::Get2DGrid().

00287   {
00288     const int Nx = int((max.x-min.x)/prec.x+.5);
00289     const int Ny = int((max.y-min.y)/prec.y+.5);
00290 
00291     TH2D* ret = new TH2D("foo", "bar", Nx, min.x, max.x, Ny, min.y, max.y);
00292 
00293     for(int nx = 0; nx < Nx ; ++nx){
00294       for(int ny = 0; ny < Ny; ++ny){
00295         const double x = min.x+(max.x-min.x)/double(Nx)*(nx+.5);
00296         const double y = min.y+(max.y-min.y)/double(Ny)*(ny+.5);
00297         const double f = func(Coord(x, y));
00298         MSG("NCContourFinder", Msg::kVerbose) << "GetLowResGrid: "
00299                                               << nx << "," << ny
00300                                               << " (" << x << "," << y << ") "
00301                                               << "-> " << f << endl;
00302         ret->Fill(x, y, f);
00303       }
00304     }
00305 
00306     return ret;
00307   }

template<class Callable>
void NCContourFinder::PrintGridSearch const Callable &  func,
const std::vector< NCParameter > &  params,
std::ostream &  out
 

Definition at line 549 of file NCContourFinder.cxx.

References base, CoordNDim, and min.

Referenced by NCExtrapolation::MakeDeltaChiSqrMaps().

00552   {
00553     std::vector<NCParameter> lowResParams = params;
00554     for(unsigned int n = 0; n < lowResParams.size(); ++n)
00555       lowResParams[n].prec *= 10;
00556 
00557     std::vector<CoordNDim> evalAt;
00558 
00559     CoordNDim first;
00560     for(unsigned int n = 0; n < lowResParams.size(); ++n)
00561       first.push_back(lowResParams[n].min);
00562 
00563     evalAt.push_back(first);
00564 
00565     for(unsigned int d = 0; d < lowResParams.size(); ++d){
00566       unsigned int maxn = evalAt.size();
00567       for(unsigned int n = 0; n < maxn; ++n){
00568         for(unsigned int nx = 1; ; ++nx){
00569           CoordNDim base = evalAt[n];
00570           base[d] += lowResParams[d].prec*nx;
00571           if(base[d] > lowResParams[d].max) break;
00572           evalAt.push_back(base);
00573         }
00574       }
00575     }
00576 
00577     for(unsigned int d = 0; d < lowResParams.size(); ++d)
00578       out << lowResParams[d].shortName << "\t";
00579     out << "chisq" << endl;
00580 
00581     for(unsigned int n = 0; n < evalAt.size(); ++n){
00582       for(unsigned int d = 0; d < evalAt[n].size(); ++d){
00583         out << evalAt[n][d]<<"\t";
00584       }
00585       out << func(evalAt[n])<<endl;
00586     }
00587   }


Generated on Fri Mar 28 16:16:12 2008 for loon by  doxygen 1.3.9.1