15int first_digit(
double value);
16TH1* benford_level(std::function<
double(shared_ptr<tklevel>)>
const& eval,
tkstring name=
"");
20 gROOT->SetStyle(
"tkn-histo");
22 TF1 benford_law(
"Benford law",
"100*TMath::Log10(1+1/x)",0.5,9.5);
23 benford_law.SetTitle(
"P(n) = log_{10}(1+1/n) ");
24 benford_law.SetMarkerStyle(0);
25 benford_law.SetMarkerColor(benford_law.GetLineColor());
26 benford_law.SetLineStyle(9);
28 auto *cc =
new TCanvas(
"benford",
"Benford's law on lifetimes",1800,500);
31 auto histo = benford_level([](
auto lvl) {
return lvl->get_lifetime(tkunit_manager::units_keys::s);},
36 benford_law.DrawClone(
"same");
37 cc->cd(1)->BuildLegend(0.332776,0.779412,0.934783,0.936975);
39 histo = benford_level([](
auto lvl) {
return lvl->get_lifetime(tkunit_manager::units_keys::keV);},
44 benford_law.DrawClone(
"same");
45 cc->cd(2)->BuildLegend(0.332776,0.779412,0.934783,0.936975);
47 histo = benford_level([](
auto lvl) {
if(!lvl->get_lifetime_measure())
return 0.;
return lvl->get_lifetime_measure()->get_error(tkunit_manager::units_keys::keV);},
48 "lifetime error (in keV)");
52 benford_law.DrawClone(
"same");
53 cc->cd(3)->BuildLegend(0.332776,0.779412,0.934783,0.936975);
54 cc->SaveAs(
"benford.png");
57TH1* benford_level(std::function<
double(shared_ptr<tklevel>)>
const& eval,
tkstring name)
59 glog.set_warnings(
false);
61 auto histo =
new TH1F(
"digit",name.data(),9,.5,9.5);
63 histo->GetXaxis()->SetTitle(
"first digit (n)");
64 histo->GetXaxis()->SetNdivisions(10);
65 histo->GetYaxis()->SetTitle(
"P(n) (in %)");
67 for(
const auto &nuc : gmanager->get_nuclei()) {
68 auto levelscheme = nuc->get_level_scheme();
69 for(
const auto &lvl : nuc->get_level_scheme()->get_levels()) {
70 int fd = first_digit(eval(lvl));
71 if(fd>0) histo->Fill(fd);
75 histo->Scale(100./histo->Integral());
80int first_digit(
double value)
82 if(value<=0.)
return 0;
83 tkstring tmp = tkstring::form(
"%e",value);
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
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.