2#include "tkn_root_macros.h"
13int first_digit(
double value);
14TH1* benford_level(std::function<
double(shared_ptr<tklevel>)>
const& eval,
tkstring name=
"");
18 gROOT->SetStyle(
"tkn-histo");
20 TF1 benford_law(
"Benford law",
"100*TMath::Log10(1+1/x)",0.5,9.5);
21 benford_law.SetTitle(
"P(n) = log_{10}(1+1/n) ");
22 benford_law.SetMarkerStyle(0);
23 benford_law.SetMarkerColor(benford_law.GetLineColor());
24 benford_law.SetLineStyle(9);
26 auto *cc =
new TCanvas(
"benford",
"Benford's law on lifetimes",1800,500);
34 benford_law.DrawCopy(
"same");
35 cc->cd(1)->BuildLegend(0.332776,0.779412,0.934783,0.936975);
42 benford_law.DrawCopy(
"same");
43 cc->cd(2)->BuildLegend(0.332776,0.779412,0.934783,0.936975);
45 histo = benford_level([](
auto lvl) {
if(!lvl->get_lifetime_measure())
return 0.;
return lvl->get_lifetime_measure()->get_error(
tkunit_manager::units_keys::keV);},
46 "lifetime error (in keV)");
50 benford_law.DrawCopy(
"same");
51 cc->cd(3)->BuildLegend(0.332776,0.779412,0.934783,0.936975);
56 cc->SaveAs(
"benford.png");
59TH1* benford_level(std::function<
double(shared_ptr<tklevel>)>
const& eval,
tkstring name)
61 glog.set_warnings(
false);
63 auto histo =
new TH1F(
"digit",name.data(),9,.5,9.5);
65 histo->GetXaxis()->SetTitle(
"first digit (n)");
66 histo->GetXaxis()->SetNdivisions(10);
67 histo->GetYaxis()->SetTitle(
"P(n) (in %)");
69 for(
const auto &nuc : gmanager->get_nuclei()) {
70 auto levelscheme = nuc->get_level_scheme();
71 for(
const auto &lvl : nuc->get_level_scheme()->get_levels()) {
72 int fd = first_digit(eval(lvl));
73 if(fd>0) histo->Fill(fd);
77 histo->Scale(100./histo->Integral());
82int first_digit(
double value)
84 if(value<=0.)
return 0;
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
static const char * form(const char *_format,...)
tkstring & remove_all(const tkstring &_s1)
tkstring substr(size_type __pos=0, size_type __n=npos) const
Inlines.
int atoi() const
Converts a string to integer value.
void DrawLogoAndCredit(double x1, double y1, double width, double text_size, const char *creditTxt, const char *opt)