5#include "Math/Minimizer.h"
6#include "Math/Factory.h"
7#include "Math/Functor.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) {
131 "TSingleDecay",
"ActivityFunc");
134 fDecayFunc->SetParNames(
"Intensity",
"DecayRate");
152 : fDetectionEfficiency(1.0)
154 if(parent !=
nullptr) {
159 UInt_t gencounter = 2;
160 for(UInt_t i = 0; i < generation; ++i) {
168 if(gencounter != generation) {
169 std::cout <<
"Generation numbers do not make sense" << std::endl;
172 if(generation == 1) {
181 fDecayFunc->SetParNames(
"Intensity",
"DecayRate");
210 TNamed::SetName(name);
218 Double_t low_limit = 0.;
219 Double_t high_limit = 0.;
226 Int_t parCounter = 1;
228 while(curDecay !=
nullptr) {
230 fTotalDecayFunc->SetParName(parCounter, Form(
"DecayRate%d", parCounter));
231 curDecay->
GetDecayFunc()->GetParLimits(1, low_limit, high_limit);
232 if(low_limit != 0 && high_limit != 0) {
244 Double_t low_limit = 0.;
245 Double_t high_limit = 0.;
251 while(curDecay !=
nullptr) {
258 curDecay->
fDecayFunc->SetParLimits(0, low_limit, high_limit);
259 fDecayFunc->GetParLimits(0, low_limit, high_limit);
265 fDecayFunc->GetParLimits(1, low_limit, high_limit);
274 fDecayFunc->SetParLimits(1, std::log(2) / high, 1e30);
277 fDecayFunc->SetParLimits(1, std::log(2) / high, std::log(2) / low);
298 low = 0.000000000001;
301 high = 0.000000000001;
303 low = std::log(2) / low;
304 high = std::log(2) / high;
352 Double_t result = 1.0;
353 UInt_t gencounter = 0;
357 Double_t t = dim[0] - tlow;
360 while(curDecay !=
nullptr) {
369 std::cout <<
"We have Problems!" << std::endl;
373 result *= par[0] / par[1];
377 while(curDecay !=
nullptr) {
378 Double_t denom = 1.0;
380 while(denomDecay !=
nullptr) {
381 if(denomDecay != curDecay) {
391 sum += TMath::Exp(-par[curDecay->
GetGeneration()] * t) / denom;
402 ROOT::Math::MinimizerOptions::SetDefaultMinimizer(
"Minuit2",
"Combination");
403 TVirtualFitter::SetPrecision(1.0e-10);
404 TVirtualFitter::SetMaxIterations(10000);
405 Int_t parCounter = 1;
410 Double_t chi2 = fitres->Chi2();
411 Double_t ndf = fitres->Ndf();
413 std::cout <<
"Chi2/ndf = " << chi2 / ndf << std::endl;
419 while(curDecay !=
nullptr) {
449 std::cout <<
" Decay Id: " <<
GetDecayId() << std::endl;
453 std::cout <<
"My Address: " <<
this << std::endl;
455 std::cout <<
"Parent Address: %p\n"
459 std::cout <<
"Daughter Address: " <<
fDaughter << std::endl;
461 std::cout <<
"First Parent: " <<
fFirstParent << std::endl;
466 if(generations == 0u) {
473 for(UInt_t i = 1; i < generations; i++) {
481 "TDecayChain",
"ChainActivityFunc");
500 decay->SetTotalDecayParameters();
502 Double_t low_limit = 0.;
503 Double_t high_limit = 0.;
505 for(
int i = 0; i <
fChainFunc->GetNpar(); ++i) {
509 fDecayChain.back()->GetTotalDecayFunc()->GetParLimits(i, low_limit, high_limit);
510 fChainFunc->SetParLimits(i, low_limit, high_limit);
517 Double_t result = 0.0;
552 if(decay !=
nullptr) {
569 std::cout <<
"Number of Decays in Chain: " <<
fDecayChain.size() << std::endl;
570 std::cout <<
"Chain Id " <<
fDecayChain.at(0)->GetChainId() << std::endl;
572 std::cout <<
"decay ptr: " << decay << std::endl;
574 std::cout << std::endl;
580 ROOT::Math::MinimizerOptions::SetDefaultMinimizer(
"Minuit2",
"Combination");
581 TVirtualFitter::SetPrecision(1.0e-10);
582 TVirtualFitter::SetMaxIterations(10000);
583 Int_t parCounter = 1;
587 TFitResultPtr fitres =
fChainFunc->
Fit(fithist, Form(
"%sWLRS", opt));
588 Double_t chi2 = fitres->Chi2();
589 Double_t ndf = fitres->Ndf();
591 std::cout <<
"Chi2/ndf = " << chi2 / ndf << std::endl;
597 while(curDecay !=
nullptr) {
620 decay->SetRange(xlow, xhigh);
625 : fChainList(std::move(chainList))
647 Double_t result = 0.0;
653 Int_t par_counter = 0;
654 auto* tmppar =
new Double_t[chain->Size() + 1];
655 tmppar[par_counter++] = par[
fFitFunc->GetParNumber(Form(
"Intensity_ChainId%d", chain->GetChainId()))];
656 for(
int j = 0; j < chain->Size(); ++j) {
657 tmppar[par_counter++] = par[
fFitFunc->GetParNumber(Form(
"DecayRate_DecayId%d", chain->GetDecay(j)->GetDecayId()))];
659 result += chain->EvalPar(dim, tmppar);
672 ROOT::Math::MinimizerOptions::SetDefaultMinimizer(
"Minuit2",
"Combination");
673 TVirtualFitter::SetPrecision(1.0e-10);
674 TVirtualFitter::SetMaxIterations(10000);
675 if(fithist->GetSumw2N() == 0) {
682 TFitResultPtr fitres;
683 if(opt1.Contains(
"G")) {
688 fitres =
fFitFunc->
Fit(fithist, Form(
"%sRIS", opt));
689 Double_t chi2 = fitres->Chi2();
690 Double_t ndf = fitres->Ndf();
691 std::cout <<
"Chi2/ndf = " << chi2 / ndf << std::endl;
696 Int_t par_num =
fFitFunc->GetParNumber(Form(
"Intensity_ChainId%d", chain->GetChainId()));
698 chain->GetDecay(0)->SetIntensityError(
fFitFunc->GetParError(par_num));
699 for(
int j = 0; j < chain->Size(); ++j) {
700 par_num =
fFitFunc->GetParNumber(Form(
"DecayRate_DecayId%d", chain->GetDecay(j)->GetDecayId()));
702 chain->GetDecay(j)->SetDecayRateError(
fFitFunc->GetParError(par_num));
704 chain->GetDecay(0)->UpdateDecays();
705 chain->SetChainParameters();
728 Double_t tmpbg =
fFitFunc->GetParameter(0);
729 Double_t tmpbglow = 0.;
730 Double_t tmpbghigh = 0.;
731 fFitFunc->GetParLimits(0, tmpbglow, tmpbghigh);
732 Double_t tmpbgerr =
fFitFunc->GetParError(0);
736 fFitFunc->SetParName(0,
"Background");
739 fFitFunc->SetParLimits(0, tmpbglow, tmpbghigh);
741 Int_t par_counter = 1;
745 fFitFunc->SetParName(par_counter, Form(
"Intensity_ChainId%d", chain->GetDecay(0)->GetChainId()));
746 chain->SetChainParameters();
747 chain->
GetDecay(0)->GetIntensityLimits(low, high);
748 fFitFunc->SetParLimits(par_counter, low, high);
749 fFitFunc->SetParameter(par_counter++, chain->GetDecay(0)->GetIntensity());
752 fFitFunc->SetParName(par_counter, Form(
"DecayRate_DecayId%d", iter.first));
753 iter.second.at(0)->GetDecayRateLimits(low, high);
754 fFitFunc->SetParLimits(par_counter, low, high);
755 fFitFunc->SetParameter(par_counter++, iter.second.at(0)->GetDecayRate());
764 auto id =
static_cast<Int_t
>(par[0]);
767 for(
auto* decay : iter->second) {
768 result += decay->Eval(dim[0]);
780 TF1* tmp_comp =
new TF1(
"tmpname",
this, &
TDecay::ComponentFunc, low, high, 1,
"TDecay",
"ComponentFunc");
782 tmp_comp->SetName(Form(
"Component_%d", iter.first));
783 tmp_comp->SetParameter(0, iter.first);
784 if(iter.first == kWhite) {
785 tmp_comp->SetLineColor(kOrange);
787 tmp_comp->SetLineColor(
static_cast<Color_t
>(iter.first));
789 tmp_comp->DrawClone(
"same");
800 auto* bg =
new TF1(
"bg",
"pol0", low, high);
802 bg->SetLineColor(kMagenta);
803 bg->DrawClone(
"same");
811 std::cout <<
"Could not find Id = : " << Id << std::endl;
814 for(
auto& i : it->second) {
815 i->SetHalfLife(halflife);
816 i->SetTotalDecayParameters();
824 std::cout <<
"Could not find Id = : " << Id << std::endl;
827 for(
auto& i : it->second) {
828 i->SetHalfLifeLimits(low, high);
829 i->SetTotalDecayParameters();
837 std::cout <<
"Could not find Id = : " << Id << std::endl;
840 for(
auto* decay : iter->second) {
841 decay->SetDecayRateLimits(low, high);
842 decay->SetTotalDecayParameters();
851 std::cout <<
"ID: " << it.first <<
" Name: " << it.second.at(0)->GetName() << std::endl;
852 it.second.at(0)->Print();
853 std::cout << std::endl;
860 std::cout <<
"ID: " << iter.first << std::endl;
861 for(
auto* decay : iter.second) {
864 std::cout << std::endl;
872 chain->SetRange(xlow, xhigh);
880 for(
int j = 0; j < chain->Size(); ++j) {
881 UInt_t
id = chain->GetDecay(j)->GetDecayId();
883 fDecayMap.insert(std::make_pair(
id, std::vector<TSingleDecay*>()));
885 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)