Error: invalid conversion from ‘TH1*’ to ‘TH1D*’ [-fpermissive]

Hi,

I am very new to root and C++.
Compiling my script, I get the error above. I basically have the problem, that the Rebin-function does not work as I want it to. I want to write new histograms with rebinned versions of the old histograms.
Here is the code, shortened:

#include <vector>
#include <map>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
#include <fstream>

#include "TH1.h"


double getMeanMinimum(TH1D *histo, int binning){ 
 
  double meanMin=0;

  TH1D *historebin = histo->Rebin(binning,"historebin"); /* This line and the next are where the error occurs! */
  meanMin = historebin->GetMinimum(); 
  return meanMin;
   
}

void root_test(){
  int totalHistoNumber=10;
  int meanBinning=5;
  
  TH1D* histo1[totalHistoNumber]; 
  double meanMin[totalHistoNumber];
  
  /* All meanMin[totalHistoNumber] entries are filled by another function here, and this works fine, so I don't write the function or the filling down.
*/
  
  for(int i=1; i <= totalHistoNumber; i++){
      meanMin[i] = getMeanMinimum(histo1[i], meanBinning); /* I am not sure wether I give histo1[i] to the function getMeanMinimum in the correct way 
*/
       cout << "gemitteltes Minimum: " << meanMin[i]<<  endl;
    }
}

Any ideas what I did wrong here? #-o Thank you in advance!

Cheers, Aiedala

Can you try:

#include “TH1D.h”

instead of:

#include “TH1.h”

[quote=“couet”]Can you try:

#include “TH1D.h”

instead of:

#include “TH1.h”[/quote]

This does not change anything, unfortunately :confused:

Rebin returns a TH1*
root.cern/doc/master/classTH1.h … 1800946790

try:

TH1D historebin = (TH1D)histo->Rebin

Hi,

Rather than TH1D *historebin = histo->Rebin(binning,"historebin");I think you meantTH1D *historebin = dynamic_cast<TH1D*>(histo->Rebin(binning,"historebin"));

Cheers,
Philippe.

This solved it, thank you so much! :smiley: