Problems with SetWeight in TFractionFitter

Hi,
I’m using the TFractionFitter Tool.
I applied a weight to a MC component in this way:
fit->SetWeight(2,corr);
where 2 is the second MC component and corr is a TH1F histogram which contains the weights I want to apply.
Even if each bin content of this histogram is >0, I get this message:
Error in TFractionFitter::ComputeFCN: Invalid weight encountered
for MC source 2
Am I missing something?

Thanks,
Marianna Testa.

Hi,

You get this error if one or more bins in your weight histogram (corr) has the bin content <= 0. You should verify the weight histogram,
Sorry for my late reply.

Lorenzo

Hi,

I’ve got a similar problem. I try to fit my data to two templates as follows:

Double_t heavyweight = 100.;
Int_t nbins = hbackground->GetNbinsX();
TH1 *hweights = hbackground; // Create a histogram with the same binning.
for(int bin = 0; bin < nbins; bin++){ hweights->SetBinContent(bin, heavyweight); }

TObjArray *mc = new TObjArray(2);
mc->Add(hbackground);
mc->Add(hsignal);

TFractionFitter *fit = new TFractionFitter(hdata, mc, "Q");
TVirtualFitter *vfit = fit->GetFitter();

fit->Constrain(0, 0., 1.);
fit->Constrain(1, 0., 1.); // Parameters have to be between 0. and 1

fit->SetWeight(0, hweights);
fit->SetWeight(1, hweights);

Int_t status = fit->Fit();

Double_t value0, error0, value1, error1;
fit->GetResult(0, value0, error0);
fit->GetResult(1, value1, error1);

When I try to run this, I get the following message 28 times:

I already looked for a solution, and found that this message means that my weight is zero or less… Which can’t be the case! Could you please help me with this problem?

Alex

HI,

I would need a file with the histograms to understand this problem

Lorenzo

Hi!

I’ve got a similar problem. I get the following message:

I see that this message means that my weight is zero or less… Which can’t be the case! Could you please help me with this problem?

Thanks

Laura

Hi,

Are you sure all the bins of the weighted histograms have non-zero content ?
In the previous case, the code posted by AlexVS has a mistake: the weight histogram has the last bin with zero content.
It should be

TH1 *hweights = new TH1D(....
for(int bin = 1; bin <= nbins; bin++){ hweights->SetBinContent(bin, heavyweight); }

Since the bin number of the histogram starts from 1

Lorenzo