Hello,
I have some analysis code that outputs both 1 and 2D histograms that require weighting. For the 1D histograms it works fine to add the weight after the fill item:
hist("name")->Fill(fillItem, weight);
However, trying to do this for 2D histograms is failing:
error: no matching function for call to 'TH1::Fill(float&, float&, double&)'
hist(histTitle)->Fill(logLike, mcResponse, mainWeight);
I don’t understand why it is interpreting the fill command as a TH1 and not a TH2. both TH1 and TH2 are included. What do I need to do to weight my 2D histograms?
Interesting, the histogram is filling (without weights) when I feed it two floats, and is defined as a TH2F. Unfortunately, the problem persists having changed to doubles.
error: no matching function for call to 'TH1::Fill(double&, double&, double&)'
hist(histTitle)->Fill(logLike, mcResponse, mainWeight);
^
It’s probably better / more useful if you show the code you are using, or at least a minimal but complete working example that reproduces your problem.
The error in the first post explicitly mentiones “TH1::Fill”. So, it does not know that it is a “TH2”. @abunka Try: ((TH2*)hist("name2D"))->Fill(fillItemA, fillItemB, weight);
root [0] .x TH2Fill.C
In file included from input_line_12:1:
/Users/couet/roottest/TH2Fill.C:9:17: error: no matching member function for call to 'Fill'
((TH1*)h2d)->Fill(xf,yf,wf);
~~~~~~~~~~~~~^~~~
/Users/couet/git/roottrunk-bin/include/TH1.h:219:21: note: candidate function not viable: requires 2 arguments, but 3 were provided
virtual Int_t Fill(Double_t x, Double_t w);
^
/Users/couet/git/roottrunk-bin/include/TH1.h:220:21: note: candidate function not viable: requires 2 arguments, but 3 were provided
virtual Int_t Fill(const char *name, Double_t w);
^
/Users/couet/git/roottrunk-bin/include/TH1.h:218:21: note: candidate function not viable: requires single argument 'x', but 3 arguments were provided
virtual Int_t Fill(Double_t x);
^
#include "TH2D.h"
void TH2Fill()
{
float xf=0., yf=0., wf=1.;
auto h2d = new TH2D("h2d","h2d",10,-1,1.,10,-1,1.);
((TH1*)h2d)->Fill(xf,yf,wf);
}