All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ana::Surface Class Reference

Log-likelihood scan across two parameters. More...

#include <Surface.h>

Inheritance diagram for ana::Surface:
ana::MedianSurface

Public Member Functions

 Surface (const IExperiment *expt, osc::IOscCalcAdjustable *calc, const IFitVar *xvar, int nbinsx, double xmin, double xmax, const IFitVar *yvar, int nbinsy, double ymin, double ymax, const std::vector< const IFitVar * > &profVars={}, const std::vector< const ISyst * > &profSysts={}, const std::map< const IFitVar *, std::vector< double >> &seedPts={}, const std::vector< SystShifts > &systSeedPts={}, bool parallel=false, Fitter::Precision prec=Fitter::kNormal)
 
 Surface (const IExperiment *expt, osc::IOscCalcAdjustable *calc, const FitAxis &xax, const FitAxis &yax, const std::vector< const IFitVar * > &profVars={}, const std::vector< const ISyst * > &profSysts={}, const std::map< const IFitVar *, std::vector< double >> &seedPts={}, const std::vector< SystShifts > &systSeedPts={}, bool parallel=false, Fitter::Precision prec=Fitter::kNormal)
 
void Draw () const
 Draw the surface itself. More...
 
void DrawBestFit (Color_t color, Int_t marker=kFullCircle) const
 Draw the best fit point. More...
 
double MinChi () const
 
double GetMinX () const
 
double GetMinY () const
 
void DrawContour (TH2 *fc, Style_t style, Color_t color, double minchi=-1)
 
TH2F * ToTH2 (double minchi=-1) const
 
void SetTitle (const char *str)
 
std::vector< TH2 * > GetProfiledHists ()
 Maps of the values taken on by the profiled parameters. More...
 
std::vector< TH2 * > GetMarginalizedHists ()
 Deprecated. Retained for backwards compatibility. More...
 
std::vector< TGraph * > GetGraphs (TH2 *fc, double minchi=-1)
 For expert use, custom painting of contours. More...
 
void SaveTo (TDirectory *dir) const
 

Static Public Member Functions

static std::unique_ptr< SurfaceLoadFrom (TDirectory *dir)
 
static std::unique_ptr< SurfaceLoadFromMulti (const std::vector< TFile * > &files, const std::string &label)
 
static std::unique_ptr< SurfaceLoadFromMulti (const std::string &wildcard, const std::string &label)
 

Protected Member Functions

 Surface ()
 
void EnsureAxes () const
 
void CheckMask (const std::string &func) const
 
void FillSurface (const std::string &progTitle, const IExperiment *expt, osc::IOscCalcAdjustable *calc, const FitAxis &xax, const FitAxis &yax, const std::vector< const IFitVar * > &profVars, const std::vector< const ISyst * > &profSysts, const std::map< const IFitVar *, std::vector< double >> &seedPts, const std::vector< SystShifts > &systSeedPts)
 
void FillSurfacePoint (const IExperiment *expt, osc::IOscCalcAdjustable *calc, const FitAxis &xax, double x, const FitAxis &yax, double y, const std::vector< const IFitVar * > &profVars, const std::vector< const ISyst * > &profSysts, const std::map< const IFitVar *, std::vector< double >> &seedPts, const std::vector< SystShifts > &systSeedPts)
 

Protected Attributes

bool fParallel
 
Fitter::Precision fPrec
 
double fMinChi
 
double fMinX
 
double fMinY
 
TH2F * fHist
 
bool fLogX
 
bool fLogY
 
std::vector< TH2 * > fProfHists
 
std::vector< double > fSeedValues
 
std::vector< int > fBinMask
 

Friends

class MedianSurface
 

Detailed Description

Log-likelihood scan across two parameters.

Definition at line 26 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

Constructor & Destructor Documentation

ana::Surface::Surface ( const IExperiment expt,
osc::IOscCalcAdjustable calc,
const IFitVar xvar,
int  nbinsx,
double  xmin,
double  xmax,
const IFitVar yvar,
int  nbinsy,
double  ymin,
double  ymax,
const std::vector< const IFitVar * > &  profVars = {},
const std::vector< const ISyst * > &  profSysts = {},
const std::map< const IFitVar *, std::vector< double >> &  seedPts = {},
const std::vector< SystShifts > &  systSeedPts = {},
bool  parallel = false,
Fitter::Precision  prec = Fitter::kNormal 
)
Parameters
exptThe experiment object to draw $ \chi^2 $ values from
calcValues for oscillation parameters to be held fixed
xvarOscillation parameter to place on the x axis
nbinsxNumber of bins along x axis
xminMinimum value of x axis
xmaxMaximum value of x axis
nbinsyNumber of bins along y axis
yminMinimum value of y axis
ymaxMaximum value of y axis
profVarsOscillation parameters to profile over
profSystsSystematic parameters to profile over
seedPtsTry all combinations of these params as seeds
systSeedPtsTry all of these systematic combinations as seeds
parallelUse all the cores on this machine? Be careful...

Definition at line 127 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

137  : Surface(expt, calc,
138  FitAxis(xvar, nbinsx, xmin, xmax),
139  FitAxis(yvar, nbinsy, ymin, ymax),
140  profVars, profSysts, seedPts, systSeedPts, parallel, prec)
141  {
142  }
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
int prec
ana::Surface::Surface ( const IExperiment expt,
osc::IOscCalcAdjustable calc,
const FitAxis xax,
const FitAxis yax,
const std::vector< const IFitVar * > &  profVars = {},
const std::vector< const ISyst * > &  profSysts = {},
const std::map< const IFitVar *, std::vector< double >> &  seedPts = {},
const std::vector< SystShifts > &  systSeedPts = {},
bool  parallel = false,
Fitter::Precision  prec = Fitter::kNormal 
)
Parameters
exptThe experiment object to draw $ \chi^2 $ values from
calcValues for oscillation parameters to be held fixed
xaxA FitAxis for the first variable
yaxA FitAxis for the second variable
profVarsOscillation parameters to profile over
profSystsSystematic parameters to profile over
seedPtsTry all combinations of these params as seeds
systSeedPtsTry all of these systematic combinations as seeds
parallelUse all the cores on this machine? Be careful...

Definition at line 38 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

48  : fParallel(parallel), fPrec(prec), fLogX(xax.islog), fLogY(yax.islog)
49  {
50  fHist = ExpandedHistogram(";"+xax.var->LatexName()+";"+yax.var->LatexName(),
51  xax.nbins, xax.min, xax.max, xax.islog,
52  yax.nbins, yax.min, yax.max, yax.islog);
53 
54  for(unsigned int i = 0; i < profVars.size()+profSysts.size(); ++i){
55  std::string title;
56  if(i < profVars.size())
57  title = profVars[i]->LatexName();
58  else
59  title = profSysts[i-profVars.size()]->LatexName();
60 
62  (title+";"+xax.var->LatexName()+";"+yax.var->LatexName(),
63  xax.nbins, xax.min, xax.max, xax.islog,
64  yax.nbins, yax.min, yax.max, yax.islog));
65  }
66 
67  std::string progTitle = "Filling surface for "+yax.var->ShortName()+" vs "+xax.var->ShortName();
68 
69  if(!profVars.empty() || !profSysts.empty()){
70  progTitle += " (profiling ";
71 
72  for(const IFitVar* v: profVars) {
73  progTitle += v->ShortName() + ", ";
74  fSeedValues.push_back( v->GetValue( calc ) );
75  }
76  for(const ISyst* s: profSysts)
77  progTitle += s->ShortName() + ", ";
78 
79  // Always have one superfluous ", " at the end
80  progTitle.resize(progTitle.size()-2);
81  progTitle += ")";
82  }
83 
84  FillSurface(progTitle, expt, calc, xax, yax, profVars, profSysts, seedPts, systSeedPts);
85 
86  // Location of the best minimum found from filled surface
87  double minchi = 1e10;
88  int minx = xax.nbins/2;
89  int miny = yax.nbins/2;
90  for(int x = 1; x < xax.nbins+1; ++x){
91  for(int y = 1; y < yax.nbins+1; ++y){
92  const int bin = (y-1)*fHist->GetNbinsX() + (x-1);
93  if(RunningOnGrid() && NumJobs() > 1
94  && !std::count(fBinMask.begin(), fBinMask.end(), bin)) continue;
95  const double chi = fHist->GetBinContent(x, y);
96  if(chi < minchi && !isnan(chi) && !isinf(chi)){
97  minchi = chi;
98  minx = x;
99  miny = y;
100  }
101  }
102  }
103 
104  std::vector<const IFitVar*> allVars = {xax.var, yax.var};
105  allVars.insert(allVars.end(), profVars.begin(), profVars.end());
106  Fitter fit(expt, allVars, profSysts);
107  fit.SetPrecision(fPrec);
108  // Seed from best grid point
109  xax.var->SetValue(calc, BinCenter(fHist->GetXaxis(), minx, xax.islog));
110  yax.var->SetValue(calc, BinCenter(fHist->GetYaxis(), miny, yax.islog));
111  for(int i = 0; i < (int)fSeedValues.size(); ++i) profVars[i]->SetValue( calc, fSeedValues[i] );
112  SystShifts systSeed = SystShifts::Nominal();
113  fMinChi = fit.Fit(calc, systSeed, seedPts);
114  fMinX = xax.var->GetValue(calc);
115  fMinY = yax.var->GetValue(calc);
116 
117  for(int x = 0; x < xax.nbins+2; ++x){
118  for(int y = 0; y < yax.nbins+2; ++y){
119  fHist->SetBinContent(x, y, fHist->GetBinContent(x, y)-fMinChi);
120  }
121  }
122 
123  fHist->SetMinimum(0);
124  }
double BinCenter(const TAxis *ax, int bin, bool islog)
process_name opflash particleana ie x
static SystShifts Nominal()
Definition: SystShifts.h:23
void FillSurface(const std::string &progTitle, const IExperiment *expt, osc::IOscCalcAdjustable *calc, const FitAxis &xax, const FitAxis &yax, const std::vector< const IFitVar * > &profVars, const std::vector< const ISyst * > &profSysts, const std::map< const IFitVar *, std::vector< double >> &seedPts, const std::vector< SystShifts > &systSeedPts)
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
TH2F * ExpandedHistogram(const std::string &title, int nbinsx, double xmin, double xmax, bool xlog, int nbinsy, double ymin, double ymax, bool ylog)
process_name opflash particleana ie ie y
int prec
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
then echo ***************************************echo Variable FHICL_FILE_PATH not found echo You porbably haven t set up larsoft echo Try setup uboonecode vXX_XX_XX q e10
Definition: find_fhicl.sh:6
std::size_t count(Cont const &cont)
std::string LatexName(int pdgcode)
Convert PDG code to a latex string (root-style)
Definition: TruthText.cxx:12
ana::Surface::Surface ( )
inlineprotected

Definition at line 109 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

109 {};

Member Function Documentation

void ana::Surface::CheckMask ( const std::string &  func) const
protected

Definition at line 718 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

719  {
720  if(!fBinMask.empty()) {
721  std::cout << "Cannot call " << func << "() on a partial surface!" << std::endl;
722  abort();
723  }
724  }
BEGIN_PROLOG could also be cout
void ana::Surface::Draw ( ) const

Draw the surface itself.

Definition at line 397 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

398  {
399  EnsureAxes();
400 
401  fHist->Draw("colz same");
402 
403  // colz obliterated them
404  gPad->RedrawAxis();
405 
406  gPad->Update();
407  }
void ana::Surface::DrawBestFit ( Color_t  color,
Int_t  marker = kFullCircle 
) const

Draw the best fit point.

Definition at line 410 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

411  {
412  CheckMask("DrawBestFit");
413  EnsureAxes();
414 
415  TMarker* mark = new TMarker(fMinX, fMinY, marker);
416  mark->SetMarkerSize(1.5);
417  mark->SetMarkerColor(color);
418  mark->Draw();
419  gPad->Update();
420  }
void CheckMask(const std::string &func) const
void ana::Surface::DrawContour ( TH2 *  fc,
Style_t  style,
Color_t  color,
double  minchi = -1 
)
Parameters
fcSurface to compare against for this significance level
styleLine style for TAttLine, solid, dotted, dashed etc
colorLine color for TAttLine
minchi$\chi^2$ of best fit to compare against. Default: best fit from this surface.

Definition at line 480 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

482  {
483  CheckMask("DrawContour");
484  EnsureAxes();
485 
486  std::vector<TGraph*> gs = GetGraphs(fc, minchi);
487 
488  for(TGraph* g: gs){
489  g->SetLineWidth(3);//2);
490  g->SetLineStyle(style);
491  g->SetLineColor(color);
492  g->Draw("l");
493  }
494 
495  gPad->Update();
496  }
def style
Definition: util.py:237
BEGIN_PROLOG g
void CheckMask(const std::string &func) const
std::vector< TGraph * > GetGraphs(TH2 *fc, double minchi=-1)
For expert use, custom painting of contours.
void ana::Surface::EnsureAxes ( ) const
protected

Definition at line 342 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

343  {
344  // Could have a file temporarily open
345  DontAddDirectory guard;
346 
347  // If this pad has already been drawn in, already has axes
348  if(gPad && !gPad->GetListOfPrimitives()->IsEmpty()) return;
349 
350  // Old, hackier solution
351  /*
352  std::cout << gPad->GetListOfPrimitives()->GetEntries() << std::endl;
353  // Which pads have we already drawn axes in? Never draw axes in them
354  // again. Unfortunately UniqueID() never seems to be set. If that's the
355  // case, set it to a random value and hope...
356  static std::set<UInt_t> already;
357  if(already.count(gPad->GetUniqueID())) return;
358  if(gPad->GetUniqueID() == 0) gPad->SetUniqueID(rand());
359  already.insert(gPad->GetUniqueID());
360  */
361 
362  const TAxis* ax = fHist->GetXaxis();
363  const TAxis* ay = fHist->GetYaxis();
364  const double Nx = ax->GetNbins();
365  const double Ny = ay->GetNbins();
366 
367  // Axes with limits where the user originally requested them, which we
368  // adjusted to be the centres of the first and last bins.
369  TH2* axes = new TH2C(UniqueName().c_str(),
370  TString::Format(";%s;%s",
371  ax->GetTitle(), ay->GetTitle()),
372  Nx-1, BinCenter(ax, 1, fLogX), BinCenter(ax, Nx, fLogX),
373  Ny-1, BinCenter(ay, 1, fLogY), BinCenter(ay, Ny, fLogY));
374  axes->Draw();
375 
376  if(fHist){
377  // "colz same" will reuse axis's min and max, so set them helpfully here
378  axes->SetMinimum(fHist->GetMinimum());
379  axes->SetMaximum(fHist->GetMaximum());
380  }
381 
382  axes->SetTitle(fHist->GetTitle());
383  axes->GetXaxis()->SetLabelSize(ax->GetLabelSize());
384  axes->GetYaxis()->SetLabelSize(ay->GetLabelSize());
385  axes->GetXaxis()->SetLabelOffset(ax->GetLabelOffset());
386  axes->GetYaxis()->SetLabelOffset(ay->GetLabelOffset());
387  axes->GetXaxis()->CenterTitle();
388  axes->GetYaxis()->CenterTitle();
389 
390  if(fLogX) gPad->SetLogx();
391  if(fLogY) gPad->SetLogy();
392 
393  gPad->Update();
394  }
double BinCenter(const TAxis *ax, int bin, bool islog)
std::string UniqueName()
Return a different string each time, for creating histograms.
void ana::Surface::FillSurface ( const std::string &  progTitle,
const IExperiment expt,
osc::IOscCalcAdjustable calc,
const FitAxis xax,
const FitAxis yax,
const std::vector< const IFitVar * > &  profVars,
const std::vector< const ISyst * > &  profSysts,
const std::map< const IFitVar *, std::vector< double >> &  seedPts,
const std::vector< SystShifts > &  systSeedPts 
)
protected

Definition at line 145 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

153  {
154  if(fParallel && !(profVars.empty() && profSysts.empty())){
155  // Minuit calls this at some point, and it creates a static. Which
156  // doesn't like happening on multiple threads at once. So do it upfront
157  // while we're still single-threaded.
158  ROOT::Minuit2::StackAllocatorHolder::Get();
159  }
160 
161  // Nothing created during surface filling belongs in a
162  // directory. Unfortunately the local guards in Spectrum etc are racey when
163  // run in parallel. But this should cover the whole lot safely.
164  DontAddDirectory guard;
165 
166  Progress* prog = 0;
167  // Difficult to keep a progress bar properly up to date when threaded
168  if(!fParallel) prog = new Progress(progTitle);
169  ThreadPool* pool = 0;
170  if(fParallel){
171  pool = new ThreadPool;
172  pool->ShowProgress(progTitle);
173  }
174 
175  const int Nx = fHist->GetNbinsX();
176  const int Ny = fHist->GetNbinsY();
177 
178  // Fill bins in "random" order so that the progress bar is accurate
179  // straight away instead of possibly being misled by whatever atypical
180  // points we start with. This step is a prime which guarantees we get every
181  // cell.
182  int step = 7919;
183  // Very unlikely (Nx or Ny is a multiple of step), but just to be safe.
184  if((Nx*Ny)%step == 0) step = 1;
185 
186  int bin = 0;
187  int neval = 0;
188 
189  // Allow the surface to be parallelised across multiple jobs by splitting
190  // up the full surface into patches, and only running bins that fall inside
191  // a certain patch
192  int grid_stride = 1;
193  if(RunningOnGrid() && NumJobs() > 1){
194  grid_stride = NumJobs();
195  bin = (step*JobNumber()) % (Nx*Ny);
196  }
197 
198  do{
199  const int x = bin%Nx+1;
200  const int y = bin/Nx+1;
201 
202  const double xv = BinCenter(fHist->GetXaxis(), x, xax.islog);
203  const double yv = BinCenter(fHist->GetYaxis(), y, yax.islog);
204 
205  // For parallel running need to set these at point of use otherwise we
206  // race.
207  if(!fParallel){
208  xax.var->SetValue(calc, xv);
209  yax.var->SetValue(calc, yv);
210  }
211 
212  if(xax.var->Penalty(xv, calc) > 1e-10){
213  std::cerr << "Warning! " << xax.var->ShortName() << " = " << xv
214  << " has penalty of " << xax.var->Penalty(xv, calc)
215  << " that could have been applied in surface. "
216  << "This should never happen." << std::endl;
217  }
218  if(yax.var->Penalty(yv, calc) > 1e-10){
219  std::cerr << "Warning! " << yax.var->ShortName() << " = " << yv
220  << " has penalty of " << yax.var->Penalty(yv, calc)
221  << " that could have been applied in surface. "
222  << "This should never happen." << std::endl;
223  }
224 
225  if(fParallel){
226  pool->AddMemberTask(this, &Surface::FillSurfacePoint,
227  expt, calc,
228  xax, xv, yax, yv,
229  profVars, profSysts, seedPts, systSeedPts);
230  }
231  else{
232  FillSurfacePoint(expt, calc,
233  xax, xv, yax, yv,
234  profVars, profSysts, seedPts, systSeedPts);
235  ++neval;
236  prog->SetProgress(neval*grid_stride/double(Nx*Ny));
237  }
238 
239  if(grid_stride > 1) fBinMask.push_back(bin);
240 
241  for(int i = 0; i < grid_stride; ++i){
242  bin = (bin + step) % (Nx * Ny);
243  if(bin == 0) break;
244  }
245  } while(bin != 0);
246 
247 
248  if(fParallel){
249  pool->Finish();
250  delete pool;
251  }
252  else{
253  prog->Done();
254  delete prog;
255  }
256  }
double BinCenter(const TAxis *ax, int bin, bool islog)
process_name opflash particleana ie x
BEGIN_PROLOG could also be cerr
void FillSurfacePoint(const IExperiment *expt, osc::IOscCalcAdjustable *calc, const FitAxis &xax, double x, const FitAxis &yax, double y, const std::vector< const IFitVar * > &profVars, const std::vector< const ISyst * > &profSysts, const std::map< const IFitVar *, std::vector< double >> &seedPts, const std::vector< SystShifts > &systSeedPts)
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
process_name opflash particleana ie ie y
do i e
prog
Definition: just_cmake.sh:3
void ana::Surface::FillSurfacePoint ( const IExperiment expt,
osc::IOscCalcAdjustable calc,
const FitAxis xax,
double  x,
const FitAxis yax,
double  y,
const std::vector< const IFitVar * > &  profVars,
const std::vector< const ISyst * > &  profSysts,
const std::map< const IFitVar *, std::vector< double >> &  seedPts,
const std::vector< SystShifts > &  systSeedPts 
)
protected

Definition at line 291 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

299  {
300  osc::IOscCalcAdjustable* calcNoHash = 0; // specific to parallel mode
301 
302  if(fParallel){
303  // Need to take our own copy so that we don't get overwritten by someone
304  // else's changes.
305  calc = calc->Copy();
306  xax.var->SetValue(calc, x);
307  yax.var->SetValue(calc, y);
308 
309  calcNoHash = new OscCalcNoHash(calc);
310  }
311 
312  //Make sure that the profiled values of fitvars do not persist between steps.
313  for(int i = 0; i < (int)fSeedValues.size(); ++i) profVars[i]->SetValue( calc, fSeedValues[i] );
314 
315  double chi;
316  if(profVars.empty() && profSysts.empty()){
317  chi = expt->ChiSq(fParallel ? calcNoHash : calc);
318  }
319  else{
320  Fitter fitter(expt, profVars, profSysts);
321  fitter.SetPrecision(fPrec);
322  SystShifts bestSysts;
323  chi = fitter.Fit(calc, bestSysts, seedPts, systSeedPts, Fitter::kQuiet);
324 
325  for(unsigned int i = 0; i < profVars.size(); ++i){
326  fProfHists[i]->Fill(x, y, profVars[i]->GetValue(calc));
327  }
328  for(unsigned int j = 0; j < profSysts.size(); ++j){
329  fProfHists[j+profVars.size()]->Fill(x, y, bestSysts.GetShift(profSysts[j]));
330  }
331  }
332 
333  fHist->Fill(x, y, chi);
334 
335  if(fParallel){
336  delete calc;
337  delete calcNoHash;
338  }
339  }
process_name opflash particleana ie x
process_name opflash particleana ie ie y
std::vector< TGraph * > ana::Surface::GetGraphs ( TH2 *  fc,
double  minchi = -1 
)

For expert use, custom painting of contours.

Definition at line 423 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

424  {
425  CheckMask("GetGraphs");
426 
427  std::vector<TGraph*> ret;
428 
429  if(minchi < 0) minchi = fMinChi;
430  std::unique_ptr<TH2> surf((TH2*)fHist->Clone(UniqueName().c_str()));
431  surf->Add(fc, -1);
432 
433  TVirtualPad* bak = gPad;
434 
435  const bool wasbatch = gROOT->IsBatch();
436  gROOT->SetBatch(); // User doesn't want to see our temporary canvas
437  TCanvas tmp;
438 
439  gStyle->SetOptStat(0);
440 
441  const double level = minchi-fMinChi;
442  surf->SetContour(1, &level);
443  surf->Draw("cont list");
444 
445  tmp.Update();
446  tmp.Paint();
447 
448  gROOT->SetBatch(wasbatch);
449  gPad = bak;
450 
451  // The graphs we need (contained inside TLists, contained inside
452  // TObjArrays) are in the list of specials. But we need to be careful about
453  // types, because other stuff can get in here too (TDatabasePDG for
454  // example).
455  TCollection* specs = gROOT->GetListOfSpecials();
456 
457  TIter nextSpec(specs);
458  while(TObject* spec = nextSpec()){
459  if(!spec->InheritsFrom(TObjArray::Class())) continue;
460  TObjArray* conts = (TObjArray*)spec;
461 
462  if(conts->IsEmpty()) continue;
463 
464  if(!conts->At(0)->InheritsFrom(TList::Class())) continue;
465  TList* cont = (TList*)conts->At(0);
466 
467  TIter nextObj(cont);
468  // Contour could be split into multiple pieces
469  while(TObject* obj = nextObj()){
470  if(!obj->InheritsFrom(TGraph::Class())) continue;
471 
472  ret.push_back((TGraph*)obj->Clone(UniqueName().c_str()));
473  } // end for obj
474  } // end for spec
475 
476  return ret;
477  }
void CheckMask(const std::string &func) const
std::string UniqueName()
Return a different string each time, for creating histograms.
std::vector<TH2*> ana::Surface::GetMarginalizedHists ( )
inline

Deprecated. Retained for backwards compatibility.

Definition at line 98 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

98 {return fProfHists;}
double ana::Surface::GetMinX ( ) const
inline
double ana::Surface::GetMinY ( ) const
inline
std::vector<TH2*> ana::Surface::GetProfiledHists ( )
inline

Maps of the values taken on by the profiled parameters.

Definition at line 96 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

96 {return fProfHists;}
std::unique_ptr< Surface > ana::Surface::LoadFrom ( TDirectory *  dir)
static

Definition at line 597 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

598  {
599  DontAddDirectory guard;
600 
601  TObjString* tag = (TObjString*)dir->Get("type");
602  assert(tag);
603  assert(tag->GetString() == "Surface");
604 
605  const TVectorD v = *(TVectorD*)dir->Get("minValues");
606  const TVectorD s = *(TVectorD*)dir->Get("seeds");
607  const TVectorD* m = (TVectorD*)dir->Get("mask");
608 
609  std::unique_ptr<Surface> surf(new Surface);
610  surf->fHist = (TH2F*)dir->Get("hist");
611  surf->fMinChi = v[0];
612  surf->fMinX = v[1];
613  surf->fMinY = v[2];
614 
615  for(int idx = 0; idx < s.GetNrows(); ++idx){
616  surf->fSeedValues.push_back(s[idx]);
617  }
618 
619  for(int idx = 0; ; ++idx){
620  TH2* h = (TH2*)dir->Get(TString::Format("profHists/hist%d", idx));
621  if(h) surf->fProfHists.push_back(h); else break;
622  }
623 
624  if(m){
625  for(int idx = 0; idx < m->GetNrows(); ++idx)
626  surf->fBinMask.push_back((*m)[idx]);
627  }
628 
629  const TObjString* logx = (TObjString*)dir->Get("logx");
630  const TObjString* logy = (TObjString*)dir->Get("logy");
631  // Tolerate missing log tags for backwards compatibility
632  surf->fLogX = (logx && logx->GetString() == "yes");
633  surf->fLogY = (logy && logy->GetString() == "yes");
634 
635  return surf;
636  }
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
while getopts h
tuple dir
Definition: dropbox.py:28
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
std::unique_ptr< Surface > ana::Surface::LoadFromMulti ( const std::vector< TFile * > &  files,
const std::string &  label 
)
static

Definition at line 640 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

641  {
642  std::vector<std::unique_ptr<Surface>> surfs;
643  for(TFile* f: files) {
644  surfs.push_back(Surface::LoadFrom(f->GetDirectory(label.c_str())));
645  }
646 
647  int Nx = surfs[0]->fHist->GetNbinsX();
648  int Ny = surfs[0]->fHist->GetNbinsY();
649  size_t nbins = Nx * Ny;
650  std::vector<int> binMask;
651 
652  // Loop over the surfaces to check all bins are present
653  for(size_t i = 0; i < surfs.size(); ++i) {
654  for(int bin : surfs[i]->fBinMask) {
655  if (std::count(binMask.begin(), binMask.end(), bin))
656  assert(false && "Repeated bin found in surfaces being merged.");
657  binMask.push_back(bin);
658  }
659  }
660  if(binMask.size() != nbins) {
661  std::cout << "Missing bins found in surfaces being merged. "
662  << "Are you sure you included all files for this surface?"
663  << std::endl;
664  assert(false);
665  }
666 
667  // Create return surface and initialise with first in list
668  std::unique_ptr<Surface> ret(new Surface);
669  ret->fHist = new TH2F(*(TH2F*)surfs[0]->ToTH2(0));
670  ret->fMinChi = surfs[0]->fMinChi;
671  ret->fMinX = surfs[0]->fMinX;
672  ret->fMinY = surfs[0]->fMinY;
673  ret->fLogX = surfs[0]->fLogX;
674  ret->fLogY = surfs[0]->fLogY;
675  ret->fSeedValues = surfs[0]->fSeedValues;
676  for(TH2* h: surfs[0]->fProfHists)
677  ret->fProfHists.push_back((TH2F*)h->Clone());
678 
679  // Loop over other surfaces and add them in
680  for(size_t i = 1; i < surfs.size(); ++i) {
681  ret->fHist->Add(surfs[i]->ToTH2(0));
682  if(surfs[i]->fMinChi < ret->fMinChi) {
683  ret->fMinChi = surfs[i]->fMinChi;
684  ret->fMinX = surfs[i]->fMinX;
685  ret->fMinY = surfs[i]->fMinY;
686  }
687  for(size_t j = 0; j < ret->fProfHists.size(); ++j)
688  ret->fProfHists[j]->Add(surfs[i]->fProfHists[j]);
689  }
690 
691  // Scale hist by global minimum
692  for(int x = 0; x < ret->fHist->GetNbinsX()+2; ++x){
693  for(int y = 0; y < ret->fHist->GetNbinsY()+2; ++y){
694  ret->fHist->SetBinContent(x, y, ret->fHist->GetBinContent(x, y)-ret->fMinChi);
695  }
696  }
697 
698  ret->fHist->SetMinimum(0);
699 
700  return ret;
701  }
process_name opflash particleana ie x
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
while getopts h
process_name opflash particleana ie ie y
static std::unique_ptr< Surface > LoadFrom(TDirectory *dir)
TH2F * ToTH2(double minchi=-1) const
std::size_t count(Cont const &cont)
BEGIN_PROLOG could also be cout
std::unique_ptr< Surface > ana::Surface::LoadFromMulti ( const std::string &  wildcard,
const std::string &  label 
)
static

Definition at line 705 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

706  {
707  std::vector<std::string> fileNames = Wildcard(wildcard);
708  std::vector<TFile*> files;
709  for(std::string fileName : fileNames){
710  files.push_back(TFile::Open(fileName.c_str()));
711  }
712  std::unique_ptr<Surface> ret = LoadFromMulti(files, label);
713  for(TFile* f: files) delete f;
714  return ret;
715  }
std::vector< std::string > Wildcard(const std::string &wildcardString)
static std::unique_ptr< Surface > LoadFromMulti(const std::vector< TFile * > &files, const std::string &label)
double ana::Surface::MinChi ( ) const
inline
void ana::Surface::SaveTo ( TDirectory *  dir) const

Definition at line 559 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

560  {
561  TDirectory* tmp = gDirectory;
562  dir->cd();
563  TObjString("Surface").Write("type");
564 
565  TVectorD v(3);
566  v[0] = fMinChi;
567  v[1] = fMinX;
568  v[2] = fMinY;
569  v.Write("minValues");
570 
571  fHist->Write("hist");
572 
573  TVectorD s(fSeedValues.size(), &fSeedValues[0]);
574  s.Write("seeds");
575 
576  TDirectory* profDir = dir->mkdir("profHists");
577  int idx = 0;
578  for(auto it: fProfHists){
579  profDir->cd();
580  it->Write( TString::Format("hist%d", idx++));
581  }
582 
583  if(!fBinMask.empty()){
584  const std::vector<double> tmp(fBinMask.begin(), fBinMask.end());
585  TVectorD m(tmp.size(), &tmp[0]);
586  m.Write("mask");
587  }
588 
589  dir->cd();
590  TObjString(fLogX ? "yes" : "no").Write("logx");
591  TObjString(fLogY ? "yes" : "no").Write("logy");
592 
593  tmp->cd();
594  }
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
tuple dir
Definition: dropbox.py:28
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
void ana::Surface::SetTitle ( const char *  str)

Definition at line 518 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

519  {
520  fHist->SetTitle(str);
521  }
TH2F * ana::Surface::ToTH2 ( double  minchi = -1) const

Definition at line 499 of file sbnana/sbnana/CAFAna/Analysis/Surface.cxx.

500  {
501  // Could have a file temporarily open
502  DontAddDirectory guard;
503 
504  TH2F* ret = new TH2F(*fHist);
505 
506  if(minchi >= 0){
507  for(int x = 0; x < ret->GetNbinsX()+2; ++x){
508  for(int y = 0; y < ret->GetNbinsY()+2; ++y){
509  ret->SetBinContent(x, y, ret->GetBinContent(x, y)+fMinChi-minchi);
510  }
511  }
512  }
513 
514  return ret;
515  }
process_name opflash particleana ie x
process_name opflash particleana ie ie y

Friends And Related Function Documentation

friend class MedianSurface
friend

Definition at line 29 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

Member Data Documentation

std::vector<int> ana::Surface::fBinMask
protected

Definition at line 141 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

TH2F* ana::Surface::fHist
protected

Definition at line 137 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

bool ana::Surface::fLogX
protected

Definition at line 138 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

bool ana::Surface::fLogY
protected

Definition at line 138 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

double ana::Surface::fMinChi
protected

Definition at line 135 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

double ana::Surface::fMinX
protected

Definition at line 136 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

double ana::Surface::fMinY
protected

Definition at line 136 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

bool ana::Surface::fParallel
protected

Definition at line 132 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

Fitter::Precision ana::Surface::fPrec
protected

Definition at line 133 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

std::vector<TH2*> ana::Surface::fProfHists
protected

Definition at line 139 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.

std::vector<double> ana::Surface::fSeedValues
protected

Definition at line 140 of file sbnana/sbnana/CAFAna/Analysis/Surface.h.


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