Hello,
From a ROOT file I hosted here, I try to extract the content of a bin using the following macro
[code]#include <TFile.h>
#include <TH1D.h>
#include <TGraph.h>
#include <TAxis.h>
#include
#include
#include
void calculRendement() {
std::map <int, float> energyRun;
energyRun[0] = 10.00;
energyRun[1] = 14.00;
energyRun[2] = 17.55;
energyRun[3] = 22.10;
energyRun[4] = 25.07;
energyRun[5] = 32.06;
energyRun[6] = 36.45;
energyRun[7] = 37.3;
energyRun[8] = 59.541;
energyRun[9] = 88.034;
energyRun[10] = 122.061;
energyRun[11] = 136.474;
energyRun[12] = 255.134;
energyRun[13] = 391.698;
energyRun[14] = 661.657;
energyRun[15] = 834.838;
energyRun[16] = 1000.0;
float Nsimulation = 1000000.;
std::ofstream ofile(“rendement_Porthos1.txt”);
ofile << “Energy (keV) \t PORTHOS” << std::endl;
TFile *f = new TFile(“fichier2.root”,“READ”);
if(f->IsZombie()) {
std::cout << “Problem while opening fichier2.root” << std::endl;
return;
}
TH1D *hPorthos = NULL;
std::vector < double > x, y;
for(unsigned int i=11 ; i<energyRun.size() ; i++) {
TH1D hPorthos = (TH1D)f->Get(Form(“h%d”,i));
x.push_back(energyRun[i]);
y.push_back(static_cast(hPorthos->GetBinContent(hPorthos->FindBin(energyRun[i]/1000.))));
std::cout << x.back() << " keV, PORTHOS : " << y.back() << ", bin: " << hPorthos->FindBin(energyRun[i]/1000.) << std::endl;
ofile << x.back() << “\t” << y.back() << std::endl;
delete hPorthos;
}
f->Close();
ofile.close();
TGraph *g = new TGraph(x.size(),&(x[0]),&(y[0]));
g->GetXaxis()->SetTitle(“E_{#gamma} (keV)”);
g->GetXaxis()->CenterTitle(true);
g->GetYaxis()->SetTitle(“Efficiency (%)”);
g->GetYaxis()->CenterTitle(true);
g->Draw(“ALP”);
}[/code]
The problem is I get the following output
[quote] 10 keV, PORTHOS : 1007, bin: 41
14 keV, PORTHOS : 20889, bin: 57
17.55 keV, PORTHOS : 73301, bin: 71
22.1 keV, PORTHOS : 145005, bin: 89
25.07 keV, PORTHOS : 183889, bin: 101
32.06 keV, PORTHOS : 241432, bin: 129
36.45 keV, PORTHOS : 262068, bin: 146
37.3 keV, PORTHOS : 264629, bin: 150
59.541 keV, PORTHOS : 297476, bin: 239
88.034 keV, PORTHOS : 297023, bin: 353
122.061 keV, PORTHOS : 278702, bin: 489
136.474 keV, PORTHOS : 118, bin: 546
255.134 keV, PORTHOS : 168187, bin: 1021
391.698 keV, PORTHOS : 108797, bin: 1567
661.657 keV, PORTHOS : 66596, bin: 2647
834.838 keV, PORTHOS : 54315, bin: 3340
1000 keV, PORTHOS : 44053, bin: 4001[/quote]
My problem comes from the fact that the content for the energy 136.474 keV given by the macro is 118 whereas it is not the real content of the bin 546.
You can check with the following commands
TFile *f = new TFile("fichier2.root")
TH1D *h = (TH1D*)f->Get("h11")
h->GetBinContent(h->FindBin(546))
What is going wrong?
Thank you in advance.