I wonder if there is a more elegant way (a template way?) of copying histograms. Will it fail if I use TH1 * h_copy, instead of the proper class (TH1F vs TH1D)?
If you intend is simply to load the histogram and transfer ownership from the TFile to you, the following code should work:
TH1 * h_copy = nullptr;
inputFile->GetObject("myHistogram",h_copy);
if (h_copy) // we do have a TH1
h_copy->SetDirectrory(nullptr);
else
std::cerr << "!-> Error" << std::endl;