Can someone pleas explain me why the value of my content per bins dosn’t fit with my histogram ?
TFile f{"RAW148OS_treeFF01.root"};
std::unique_ptr<TTree> tv__tree{static_cast<TTree*>(f.Get("Analysis_All"))};
tv__tree->Draw("Psd_All_Shift>>h1(7500,500,8000)","","colz");
TH1 *h1 = dynamic_cast<TH1*>(gPad->GetPrimitive("h1")); // Obtention de l'histogramme h1
// Vérifiez si l’histogramme existe
if (h1) { // Utilisation de h1 pour vérifier si l'histogramme existe
// Accédez aux données de l’histogramme
int nbins = h1->GetNbinsX();
for (int i = 1; i <= nbins; ++i) {
double binContent = h1->GetBinContent(i);
// Faites quelque chose avec le contenu du bin, par exemple, l’afficher
std::cout << "Contenu du bin " << i << " : " << binContent << std::endl;
}
} else {
std::cout << "L’histogramme n’a pas été trouvé." << std::endl;
}
Hi @KillianUB,
could you provide the root file you are using, it is difficult to say something without data.
From waht I can see the code seems correct overall, the only thing I will modify is the decalration of the histogram from a generic TH1 to TH1D or TH1F
The DATA is unfortunatly to heavy to be provided even with dropbox or wetransfer. But i can show you that ;
As you can see, it dosnt makes sense at all. Even worst , if I change from all detector to only one detector the resultat stay the same what ever i change.
I just noticed that you used colz
option that is meant for TH2 histograms, I do not know if this can cause prblems.
In any case I suggest you to change dynamic_cast<TH1*>(gPad->GetPrimitive("h1"))
to
(TH1F*)gPad->GetPrimitive("h1")
that is the method described in the Tree::Draw() method on the ROOT page.
Problem has been solved. There has a shift of 500 bins wish is why the content per bins dosnt fitted with histogram. I just changed
tv__tree->Draw("Psd_All_Shift>>h1(8000,0,8000)","","colz");
and then it worked.
Thx for your help !
You can crop the TTree with RDataFrame
and share a small reproducible.
ROOT::RDataFrame df("Analysis_All", "RAW148OS_treeFF01.root").Range(100).Snapshot(""Analysis_All", "RAW148OS_treeFF01_cropped.root"")
1 Like