8#include "Math/MinimizerOptions.h"
9#include "TVirtualFitter.h"
10#include "TFitResult.h"
31 std::cout <<
"fDecay = " <<
fDecay << std::endl;
44 TFitResultPtr tmpres =
hist->Fit(
this, opt);
63 const Size_t oldmarker_size =
fResiduals.GetMarkerSize();
64 const Color_t oldmarker_color =
fResiduals.GetMarkerColor();
65 const Style_t oldmarker_style =
fResiduals.GetMarkerStyle();
74 GetRange(xlow, xhigh);
75 Int_t nbins =
hist->GetXaxis()->GetNbins();
77 for(
int i = 0; i < nbins; ++i) {
78 if((
hist->GetBinCenter(i) <= xlow) || (
hist->GetBinCenter(i) >= xhigh)) {
82 Double_t res = (
hist->GetBinContent(i) - Eval(
hist->GetBinCenter(i))) /
84 Double_t bin =
hist->GetBinCenter(i);
99 std::cout <<
"Residuals not set yet" << std::endl;
105 std::cout <<
"Draw components has not been set in " << ClassName() << std::endl;
106 Draw(Form(
"same%s", opt));
110 : fDetectionEfficiency(1.0)
112 if(parent !=
nullptr) {
117 UInt_t gencounter = 1;
118 while(curParent !=
nullptr) {
133 fDecayFunc->SetParNames(
"Intensity",
"DecayRate");
150 : fDetectionEfficiency(1.0)
152 if(parent !=
nullptr) {
157 UInt_t gencounter = 2;
158 for(UInt_t i = 0; i < generation; ++i) {
166 if(gencounter != generation) {
167 std::cout <<
"Generation numbers do not make sense" << std::endl;
170 if(generation == 1) {
179 fDecayFunc->SetParNames(
"Intensity",
"DecayRate");
207 TNamed::SetName(name);
215 Double_t low_limit = 0.;
216 Double_t high_limit = 0.;
223 Int_t parCounter = 1;
225 while(curDecay !=
nullptr) {
227 fTotalDecayFunc->SetParName(parCounter, Form(
"DecayRate%d", parCounter));
228 curDecay->
GetDecayFunc()->GetParLimits(1, low_limit, high_limit);
229 if(low_limit != 0 && high_limit != 0) {
241 Double_t low_limit = 0.;
242 Double_t high_limit = 0.;
248 while(curDecay !=
nullptr) {
255 curDecay->
fDecayFunc->SetParLimits(0, low_limit, high_limit);
256 fDecayFunc->GetParLimits(0, low_limit, high_limit);
262 fDecayFunc->GetParLimits(1, low_limit, high_limit);
271 fDecayFunc->SetParLimits(1, std::log(2) / high, 1e30);
274 fDecayFunc->SetParLimits(1, std::log(2) / high, std::log(2) / low);
295 low = 0.000000000001;
298 high = 0.000000000001;
300 low = std::log(2) / low;
301 high = std::log(2) / high;
349 Double_t result = 1.0;
350 UInt_t gencounter = 0;
354 Double_t t = dim[0] - tlow;
357 while(curDecay !=
nullptr) {
366 std::cout <<
"We have Problems!" << std::endl;
370 result *= par[0] / par[1];
374 while(curDecay !=
nullptr) {
375 Double_t denom = 1.0;
377 while(denomDecay !=
nullptr) {
378 if(denomDecay != curDecay) {
388 sum += TMath::Exp(-par[curDecay->
GetGeneration()] * t) / denom;
399 ROOT::Math::MinimizerOptions::SetDefaultMinimizer(
"Minuit2",
"Combination");
400 TVirtualFitter::SetPrecision(1.0e-10);
401 TVirtualFitter::SetMaxIterations(10000);
402 Int_t parCounter = 1;
407 Double_t chi2 = fitres->Chi2();
408 Double_t ndf = fitres->Ndf();
410 std::cout <<
"Chi2/ndf = " << chi2 / ndf << std::endl;
416 while(curDecay !=
nullptr) {
446 std::cout <<
" Decay Id: " <<
GetDecayId() << std::endl;
450 std::cout <<
"My Address: " <<
this << std::endl;
452 std::cout <<
"Parent Address: %p\n"
456 std::cout <<
"Daughter Address: " <<
fDaughter << std::endl;
458 std::cout <<
"First Parent: " <<
fFirstParent << std::endl;
463 if(generations == 0u) {
470 for(UInt_t i = 1; i < generations; i++) {
496 decay->SetTotalDecayParameters();
498 Double_t low_limit = 0.;
499 Double_t high_limit = 0.;
501 for(
int i = 0; i <
fChainFunc->GetNpar(); ++i) {
505 fDecayChain.back()->GetTotalDecayFunc()->GetParLimits(i, low_limit, high_limit);
506 fChainFunc->SetParLimits(i, low_limit, high_limit);
513 Double_t result = 0.0;
548 if(decay !=
nullptr) {
565 std::cout <<
"Number of Decays in Chain: " <<
fDecayChain.size() << std::endl;
566 std::cout <<
"Chain Id " <<
fDecayChain.at(0)->GetChainId() << std::endl;
568 std::cout <<
"decay ptr: " << decay << std::endl;
570 std::cout << std::endl;
576 ROOT::Math::MinimizerOptions::SetDefaultMinimizer(
"Minuit2",
"Combination");
577 TVirtualFitter::SetPrecision(1.0e-10);
578 TVirtualFitter::SetMaxIterations(10000);
579 Int_t parCounter = 1;
583 TFitResultPtr fitres =
fChainFunc->
Fit(fithist, Form(
"%sWLRS", opt));
584 Double_t chi2 = fitres->Chi2();
585 Double_t ndf = fitres->Ndf();
587 std::cout <<
"Chi2/ndf = " << chi2 / ndf << std::endl;
593 while(curDecay !=
nullptr) {
616 decay->SetRange(xlow, xhigh);
621 : fChainList(std::move(chainList))
643 Double_t result = 0.0;
649 Int_t par_counter = 0;
650 auto* tmppar =
new Double_t[chain->Size() + 1];
651 tmppar[par_counter++] = par[
fFitFunc->GetParNumber(Form(
"Intensity_ChainId%d", chain->GetChainId()))];
652 for(
int j = 0; j < chain->Size(); ++j) {
653 tmppar[par_counter++] = par[
fFitFunc->GetParNumber(Form(
"DecayRate_DecayId%d", chain->GetDecay(j)->GetDecayId()))];
655 result += chain->EvalPar(dim, tmppar);
668 ROOT::Math::MinimizerOptions::SetDefaultMinimizer(
"Minuit2",
"Combination");
669 TVirtualFitter::SetPrecision(1.0e-10);
670 TVirtualFitter::SetMaxIterations(10000);
671 if(fithist->GetSumw2N() == 0) {
678 TFitResultPtr fitres;
679 if(opt1.Contains(
"G")) {
684 fitres =
fFitFunc->
Fit(fithist, Form(
"%sRIS", opt));
685 Double_t chi2 = fitres->Chi2();
686 Double_t ndf = fitres->Ndf();
687 std::cout <<
"Chi2/ndf = " << chi2 / ndf << std::endl;
692 Int_t par_num =
fFitFunc->GetParNumber(Form(
"Intensity_ChainId%d", chain->GetChainId()));
694 chain->GetDecay(0)->SetIntensityError(
fFitFunc->GetParError(par_num));
695 for(
int j = 0; j < chain->Size(); ++j) {
696 par_num =
fFitFunc->GetParNumber(Form(
"DecayRate_DecayId%d", chain->GetDecay(j)->GetDecayId()));
698 chain->GetDecay(j)->SetDecayRateError(
fFitFunc->GetParError(par_num));
700 chain->GetDecay(0)->UpdateDecays();
701 chain->SetChainParameters();
724 Double_t tmpbg =
fFitFunc->GetParameter(0);
725 Double_t tmpbglow = 0.;
726 Double_t tmpbghigh = 0.;
727 fFitFunc->GetParLimits(0, tmpbglow, tmpbghigh);
728 Double_t tmpbgerr =
fFitFunc->GetParError(0);
732 fFitFunc->SetParName(0,
"Background");
735 fFitFunc->SetParLimits(0, tmpbglow, tmpbghigh);
737 Int_t par_counter = 1;
741 fFitFunc->SetParName(par_counter, Form(
"Intensity_ChainId%d", chain->GetDecay(0)->GetChainId()));
742 chain->SetChainParameters();
743 chain->
GetDecay(0)->GetIntensityLimits(low, high);
744 fFitFunc->SetParLimits(par_counter, low, high);
745 fFitFunc->SetParameter(par_counter++, chain->GetDecay(0)->GetIntensity());
748 fFitFunc->SetParName(par_counter, Form(
"DecayRate_DecayId%d", iter.first));
749 iter.second.at(0)->GetDecayRateLimits(low, high);
750 fFitFunc->SetParLimits(par_counter, low, high);
751 fFitFunc->SetParameter(par_counter++, iter.second.at(0)->GetDecayRate());
760 auto id =
static_cast<Int_t
>(par[0]);
763 for(
auto* decay : iter->second) {
764 result += decay->Eval(dim[0]);
778 tmp_comp->SetName(Form(
"Component_%d", iter.first));
779 tmp_comp->SetParameter(0, iter.first);
780 if(iter.first == kWhite) {
781 tmp_comp->SetLineColor(kOrange);
783 tmp_comp->SetLineColor(
static_cast<Color_t
>(iter.first));
785 tmp_comp->DrawClone(
"same");
796 auto* bg =
new TF1(
"bg",
"pol0", low, high);
798 bg->SetLineColor(kMagenta);
799 bg->DrawClone(
"same");
807 std::cout <<
"Could not find Id = : " << Id << std::endl;
810 for(
auto& i : it->second) {
811 i->SetHalfLife(halflife);
812 i->SetTotalDecayParameters();
820 std::cout <<
"Could not find Id = : " << Id << std::endl;
823 for(
auto& i : it->second) {
824 i->SetHalfLifeLimits(low, high);
825 i->SetTotalDecayParameters();
833 std::cout <<
"Could not find Id = : " << Id << std::endl;
836 for(
auto* decay : iter->second) {
837 decay->SetDecayRateLimits(low, high);
838 decay->SetTotalDecayParameters();
847 std::cout <<
"ID: " << it.first <<
" Name: " << it.second.at(0)->GetName() << std::endl;
848 it.second.at(0)->Print();
849 std::cout << std::endl;
856 std::cout <<
"ID: " << iter.first << std::endl;
857 for(
auto* decay : iter.second) {
860 std::cout << std::endl;
868 chain->SetRange(xlow, xhigh);
876 for(
int j = 0; j < chain->Size(); ++j) {
877 UInt_t
id = chain->GetDecay(j)->GetDecayId();
879 fDecayMap.insert(std::make_pair(
id, std::vector<TSingleDecay*>()));
881 fDecayMap.find(
id)->second.push_back(chain->GetDecay(j));
std::vector< TSingleDecay * > fDecayChain
void Print(Option_t *option="") const override
Double_t EvalPar(const Double_t *x, const Double_t *par=nullptr)
Double_t Eval(Double_t t) const
TSingleDecay * GetDecay(UInt_t generation)
static UInt_t fChainCounter
void AddToChain(TSingleDecay *decay)
void SetChainParameters()
Double_t ChainActivityFunc(Double_t *dim, Double_t *par)
TFitResultPtr Fit(TH1 *fithist, Option_t *opt="")
void DrawComponents(Option_t *opt="", Bool_t color_flag=true) override
void SetRange(Double_t xlow, Double_t xhigh)
void Draw(Option_t *opt="") override
void Print(Option_t *opt="") const override
TFitResultPtr Fit(TH1 *hist, Option_t *opt="")
void SetDecay(TVirtualDecay *decay)
void DrawComponents() const
void UpdateResiduals(TH1 *hist)
TVirtualDecay * GetDecay() const
void DrawComponents(Option_t *opt="", Bool_t color_flag=true) override
void SetDecayRateLimits(Int_t Id, Double_t low, Double_t high)
Double_t DecayFit(Double_t *dim, Double_t *par)
Double_t GetBackgroundError() const
std::map< Int_t, std::vector< TSingleDecay * > > fDecayMap
TFitResultPtr Fit(TH1 *fithist, Option_t *opt="")
std::vector< TDecayChain * > fChainList
void Print(Option_t *opt="") const override
void DrawBackground(Option_t *opt="")
Double_t GetBackground() const
void SetRange(Double_t xlow, Double_t xhigh)
void SetHalfLifeLimits(Int_t Id, Double_t low, Double_t high)
void SetHalfLife(Int_t Id, Double_t halflife)
Double_t ComponentFunc(Double_t *dim, Double_t *par)
void Draw(Option_t *opt="") override
TDecayChain * GetChain(UInt_t idx)
void Fit(TH1 *hist, TF1 *func)
void SetDecayRate(const Double_t &decayrate)
void Print(Option_t *option="") const override
void SetIntensityLimits(const Double_t &low, const Double_t &high)
TDecayFit * fTotalDecayFunc
TSingleDecay * GetDaughterDecay()
void SetDaughterDecay(TSingleDecay *daughter)
Double_t GetHalfLife() const
Double_t GetIntensityError() const
Double_t Eval(Double_t t)
void SetTotalDecayParameters()
void GetDecayRateLimits(Double_t &low, Double_t &high) const
void Draw(Option_t *option="") override
TSingleDecay * GetParentDecay()
void SetDecayRateLimits(const Double_t &low, const Double_t &high)
void SetRange(Double_t tlow, Double_t thigh)
Double_t ActivityFunc(Double_t *dim, Double_t *par)
void GetIntensityLimits(Double_t &low, Double_t &high) const
Double_t GetEfficiency() const
const TDecayFit * GetDecayFunc() const
TSingleDecay * fFirstParent
void SetName(const char *name) override
void SetDecayRateError(Double_t err)
void SetIntensity(const Double_t &intens)
Double_t GetDecayRate() const
TFitResultPtr Fit(TH1 *fithist, Option_t *opt="")
void GetHalfLifeLimits(Double_t &low, Double_t &high) const
Double_t GetHalfLifeError() const
Double_t GetIntensity() const
void SetIntensityError(Double_t err)
UInt_t GetGeneration() const
Double_t EvalPar(const Double_t *x, const Double_t *par=nullptr)
void SetHalfLifeLimits(const Double_t &low, const Double_t &high)
virtual void DrawComponents(Option_t *opt="", Bool_t color_flag=true)