Classes | |
| class | Plot::Style |
| class | Plot::Band |
| class | Plot::Hist |
| class | Plot::Range |
Functions | |
| double | GetChi2 (TH1 *h1, TH1 *h2, const std::string &option="", const std::string &tag="") |
| double | GetChi2 (const Hist &lhs, const Hist &rhs, const std::string &option="", std::ostream &o=std::cout) |
| const std::string | Format (double v, int w, int p) |
| bool | operator== (const Band &lhs, const Band &rhs) |
| void | TestHist (TH1 *hO, TH1 *hC, std::string option="") |
| void | TestError (TH1 *hI, std::string option="") |
|
||||||||||||||||
|
Definition at line 325 of file Plot.cxx. Referenced by NCExtrapolation::DrawContours(), NCExtraction::DrawDataMCComparisonPlots(), NCExtraction::MakeBackgroundPlots(), and NCExtrapolationNS::PredictSpectrum(). 00326 {
00327 stringstream ss;
00328 ss << std::fixed << std::setw(w) << std::setprecision(p) << v;
00329 return ss.str();
00330 }
|
|
||||||||||||||||||||
|
Definition at line 32 of file Plot.cxx. References Plot::Band::Bin(), Plot::Hist::GetErrorBand(), Plot::Hist::GetHist(), Plot::Band::High(), Plot::Band::Low(), and option. 00033 {
00034 TH1 *hL = lhs.GetHist();
00035 TH1 *hR = rhs.GetHist();
00036
00037 if(!hL || !hR)
00038 {
00039 cerr << "GetChi2() - null histogram pointers" << endl;
00040 return 0.0;
00041 }
00042 if(hL -> GetNbinsX() != hR -> GetNbinsX())
00043 {
00044 cerr << "GetChi2() - histograms have unequal number of bins" << endl;
00045 return 0.0;
00046 }
00047
00048 unsigned int ndof = 0;
00049 double chi2 = 0.0;
00050
00051 int lbin = 1, hbin = hL -> GetNbinsX();
00052
00053 if(option.find("U") != string::npos || option.find("u") != string::npos)
00054 {
00055 --lbin;
00056 }
00057 if(option.find("O") != string::npos || option.find("o") != string::npos)
00058 {
00059 ++hbin;
00060 }
00061 if(!(lbin < hbin))
00062 {
00063 cerr << "GetChi2() - invalid range of histogram bins" << endl;
00064 return 0.0;
00065 }
00066
00067 const map<int, pair<Band, Band> >& bandL = lhs.GetErrorBand();
00068 const map<int, pair<Band, Band> >& bandR = rhs.GetErrorBand();
00069
00070 for(int ibin = lbin; ibin <= hbin; ++ibin)
00071 {
00072 const double valueL = hL -> GetBinContent(ibin);
00073 const double valueR = hR -> GetBinContent(ibin);
00074
00075 if(!(valueL > 0.0) && !(valueR > 0.0))
00076 {
00077 continue;
00078 }
00079
00080 const double nom = (valueL - valueR)*(valueL - valueR);
00081 double den = 0.0;
00082
00083 const map<int, pair<Band, Band> >::const_iterator lit = bandL.find(ibin);
00084 if(lit != bandL.end())
00085 {
00086 const Band &band = (lit -> second).second;
00087 assert(band.Bin() == ibin && "Mismatched bin number");
00088
00089 if(band.Low() > band.High())
00090 {
00091 den += band.Low();
00092 }
00093 else
00094 {
00095 den += band.High();
00096 }
00097 }
00098 else
00099 {
00100 den += valueL;
00101 }
00102
00103 const map<int, pair<Band, Band> >::const_iterator rit = bandR.find(ibin);
00104 if(rit != bandR.end())
00105 {
00106 const Band &band = (rit -> second).second;
00107 assert(band.Bin() == ibin && "Mismatched bin number");
00108
00109 if(band.Low() > band.High())
00110 {
00111 den += band.Low();
00112 }
00113 else
00114 {
00115 den += band.High();
00116 }
00117 }
00118 else
00119 {
00120 den += valueR;
00121 }
00122
00123 if(!(den > 0.0))
00124 {
00125 cerr << "Plot::GetChi2 - bin error is zero" << endl;
00126 continue;
00127 }
00128
00129 chi2 += nom/den;
00130 ++ndof;
00131 }
00132
00133 if(!(ndof > 0))
00134 {
00135 return 0.0;
00136 }
00137
00138 if(option.find("P") != string::npos || option.find("V") != string::npos)
00139 {
00140 o << "chi2/ndof = " << chi2 << "/" << ndof << " = " << chi2/ndof << endl;
00141 }
00142
00143 if(option.find("chi2") != string::npos)
00144 {
00145 return chi2;
00146 }
00147 else if(option.find("ndof") != string::npos)
00148 {
00149 return ndof;
00150 }
00151
00152 return chi2/ndof;
00153 }
|
|
||||||||||||||||||||
|
Definition at line 260 of file Plot.cxx. References option. 00261 {
00262 if(!h1 || !h2)
00263 {
00264 cerr << "GetChi2() - invalid histogram pointers" << endl;
00265 return 0.0;
00266 }
00267 if(h1 -> GetNbinsX() != h2 -> GetNbinsX())
00268 {
00269 cerr << "GetChi2() - histograms have unequal number of bins" << endl;
00270 return 0.0;
00271 }
00272
00273 double ndof = 0.0;
00274 double chi2 = 0.0;
00275
00276 int lbin = 1, hbin = h1 -> GetNbinsX();
00277
00278 if(option.find("U") != string::npos || option.find("u") != string::npos)
00279 {
00280 --lbin;
00281 }
00282 if(option.find("O") != string::npos || option.find("o") != string::npos)
00283 {
00284 ++hbin;
00285 }
00286 if(!(lbin < hbin))
00287 {
00288 cerr << "GetChi2() - invalid range of histogram bins" << endl;
00289 return 0.0;
00290 }
00291
00292 for(int ibin = lbin; ibin <= hbin; ++ibin)
00293 {
00294 const double value1 = h1 -> GetBinContent(ibin);
00295 const double value2 = h2 -> GetBinContent(ibin);
00296
00297 if(value1 > 0.0 && value2 > 0.0)
00298 {
00299 chi2 += (value1 - value2) * (value1 - value2)/value1;
00300 ndof += 1.0;
00301 }
00302 }
00303
00304 if(!(ndof > 0.0))
00305 {
00306 return 0.0;
00307 }
00308
00309 if(option.find("P") != string::npos || option.find("V") != string::npos || !tag.empty())
00310 {
00311 if(tag.empty())
00312 {
00313 cout << "chi2/ndof = " << chi2 << "/" << ndof << " = " << chi2/ndof << endl;
00314 }
00315 else
00316 {
00317 cout << tag << ": chi2/ndof = " << chi2 << "/" << ndof << " = " << chi2/ndof << endl;
00318 }
00319 }
00320
00321 return chi2/ndof;
00322 }
|
|
||||||||||||
|
Definition at line 1361 of file Plot.cxx. References Plot::Band::Bin(). 01362 {
01363 return (lhs.Bin() == rhs.Bin());
01364 }
|
|
||||||||||||
|
Definition at line 1516 of file Plot.cxx. References Draw(), and option. 01517 {
01518 cout << "Plot::TestError - option = " << option << endl;
01519
01520 TH1 *hO = dynamic_cast<TH1 *>(hI -> Clone("hO"));
01521 TH1 *hN = dynamic_cast<TH1 *>(hI -> Clone("hN"));
01522
01523 hO -> SetDirectory(0);
01524 hN -> SetDirectory(0);
01525
01526 const int nbin = hN -> GetNbinsX();
01527
01528 for(int ibin = 1; ibin <= nbin; ++ibin)
01529 {
01530 const double value = hN -> GetBinContent(ibin);
01531
01532 if(option.find("half") != std::string::npos)
01533 {
01534 hN -> SetBinError(ibin, 0.5*std::sqrt(value));
01535 }
01536 else
01537 {
01538 hN -> SetBinError(ibin, std::sqrt(value));
01539 }
01540 }
01541
01542 hO -> SetLineColor(2);
01543 hN -> SetLineColor(4);
01544
01545 TCanvas *canvas = new TCanvas("ctest", "ctest", 0, 0, 720, 450);
01546 canvas -> SetGrid();
01547 canvas -> Draw();
01548
01549 hO -> Draw("E1");
01550 hN -> Draw("E1 sames");
01551 }
|
|
||||||||||||||||
|
Definition at line 1367 of file Plot.cxx. References Anp::Bin< T >::add(), Draw(), Anp::Bin< T >::edge(), Anp::Hist1d< T >::Fill(), Anp::Hist1d< T >::Merge(), option, Anp::Hist1d< T >::Print(), Anp::Hist1d< T >::Reset(), NR::sort(), and Anp::Bin< T >::sum(). 01368 {
01369 const double nmin = 1000;
01370
01371 vector<Anp::Bin<double> > bvec;
01372
01373 map<int, double> bmap;
01374
01375 Anp::Hist1d<double> histO(*hO);
01376 Anp::Hist1d<double> histC(*hC);
01377
01378 cout << "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO" << endl;
01379 histO.Print();
01380 const unsigned int nmergeO = histO.Merge(1000.0);
01381 histO.Print();
01382
01383 cout << "Merged " << nmergeO << " bins" << endl;
01384
01385 cout << "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC" << endl;
01386 histC.Print();
01387 const unsigned int nmergeC = histC.Merge(1000.0);
01388 histC.Print();
01389
01390 cout << "Merged " << nmergeC << " bins" << endl;
01391
01392 cout << "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN" << endl;
01393 histO.Reset();
01394 histO.Fill(*hC);
01395 histO.Print();
01396
01397 cout << "Attempting draw test..." << endl;
01398
01399 TH1 *h1 = Anp::CreateTH1<double>(histO, "h1");
01400 TH1 *h2 = Anp::CreateTH1<double>(histC, "h2");
01401
01402 hC -> SetLineColor(1);
01403 hC -> SetLineWidth(2);
01404 hC -> SetFillColor(0);
01405 h1 -> SetLineColor(2);
01406 h2 -> SetLineColor(4);
01407
01408 if(!h1)
01409 {
01410 cerr << "Failed to create h1" << endl;
01411 return;
01412 }
01413 if(!h2)
01414 {
01415 cerr << "Failed to create h2" << endl;
01416 return;
01417 }
01418
01419 TCanvas *canvas = new TCanvas("ctest", "ctest", 0, 0, 650, 400);
01420 canvas -> SetGrid();
01421 canvas -> Draw();
01422
01423 hC -> Draw("HIST");
01424 h1 -> Draw("sames");
01425 h2 -> Draw("sames");
01426
01427 cout << "Finished draw test" << endl;
01428
01429 return;
01430
01431 const int nbin = hC -> GetNbinsX();
01432
01433 for(int ibin = 1; ibin <= nbin; ++ibin)
01434 {
01435 const double value = hO -> GetBinContent(ibin);
01436 const double edge = hO -> GetBinLowEdge(ibin);
01437
01438 Anp::Bin<double> bin(ibin, edge);
01439 bin.add(value);
01440
01441 bvec.push_back(bin);
01442 }
01443
01444 unsigned int osize = bvec.size();
01445 double osum = 0.0;
01446
01447 if(option.find("V") != string::npos)
01448 {
01449 for(unsigned int ibin = 0; ibin < bvec.size(); ++ibin)
01450 {
01451 const Anp::Bin<double> &bin = bvec[ibin];
01452 cout << "ibin = " << ibin << ", edge = " << bin.edge() << ", sum = " << bin.sum() << endl;
01453 osum += bin.sum();
01454 }
01455 }
01456
01457 std::sort(bvec.begin(), bvec.end());
01458
01459 vector<Anp::Bin<double> >::iterator bit = bvec.begin();
01460 while(bit != bvec.end())
01461 {
01462 if(bit -> sum() > nmin || bit == bvec.begin() || bit + 1 == bvec.end())
01463 {
01464 ++bit;
01465 continue;
01466 }
01467
01468 vector<Anp::Bin<double> >::iterator lit = bit - 1;
01469 vector<Anp::Bin<double> >::iterator hit = bit + 1;
01470
01471 if(lit -> sum() < hit -> sum())
01472 {
01473 Anp::Bin<double> bin(0, lit -> edge());
01474
01475 bin.add(bit -> sum());
01476 bin.add(lit -> sum());
01477
01478 bvec.erase(lit, hit + 1);
01479
01480 bvec.push_back(bin);
01481 }
01482 else
01483 {
01484 Anp::Bin<double> bin(0, bit -> edge());
01485
01486 bin.add(bit -> sum());
01487 bin.add(hit -> sum());
01488
01489 bvec.erase(bit, hit + 1);
01490
01491 bvec.push_back(bin);
01492 }
01493
01494 std::sort(bvec.begin(), bvec.end());
01495
01496 bit = bvec.begin();
01497 }
01498
01499 if(option.find("V") != string::npos)
01500 {
01501 double nsum = 0.0;
01502 for(unsigned int ibin = 0; ibin < bvec.size(); ++ibin)
01503 {
01504 const Anp::Bin<double> &bin = bvec[ibin];
01505 cout << "ibin = " << ibin << ", edge = " << bin.edge() << ", sum = " << bin.sum() << endl;
01506 nsum += bin.sum();
01507 }
01508
01509 cout << "old bvec size = " << osize << endl;
01510 cout << "new bvec size = " << bvec.size() << endl;
01511 cout << "osum - nsum = " << osum << " - " << nsum << " = " << osum - nsum << endl;
01512 }
01513 }
|
1.3.9.1