Fill won't work with float data

Hello,

I’m going through the exercises in nevis.columbia.edu/~seligman/root-class/, and I’m using 6.06/04 on MacOSX 10.11.2

One of the exercises (Analyze.C, if you’re familiar with the exercises) read in a n tuple with float data in there.

[] TFile myFile(“experiment.root”)
[] tree1->Scan()


  • Row * event * ebeam * px * py * pz * zv * chi2 *

  •    0 *         0 * 150.14041 * 14.333598 * -4.021043 * 143.54425 * 22.264110 * 0.9405828 *
    


Then it puts the data in a new TH1F (or TH1D).

[] TH1* chi2Hist = NULL;
[] chi2Hist = new TH1D(“chi2”,“Histogram of Chi2”,100,0,20);
[] tree1->GetEntry(entry);
[] chi2Hist->Fill(chi2);

However, the Fill function won’t accept float arguments it seems.

Analyze.C:80:14: error: no matching member function for call to 'Fill’
chi2Hist->Fill(chi2);
~~~~~~~~^~
/Applications/root/include/TH1.h:220:21: note: candidate function not viable: no known conversion from ‘TTreeReaderValue<Float_t>’ to ‘Double_t’ (aka ‘double’) for 1st argument
virtual Int_t Fill(Double_t x);

I’ve tried many different things, but I can’t get past this. Can anybody help.

Thanks,
Faisal

Hello Faisal.

the problem here is that you are dealing with TTreeReaderValues templated with float not simple floats. You can take a look at this example to see this in action root.cern.ch/doc/master/classTTreeReader.html .
In short, for your particular case, you’ll need to write

chi2Hist->Fill(*chi2);

and not simply

chi2Hist->Fill(chi2);

Cheers,
Danilo

Thank you. That works. Faisal

UNDATE, solved. Replace chi2 into *chi2.

How did you solve this at last. I stuck in the exact same problem.
Simply change chi2 into *chi2 would not work.
Did you change the header file? How did you do to solve this?
Thanks a lot.