Percentage Threshold histogram

I am trying to plot percentage on the Y-axis instead of data count,
the plot does not show as expected,
my data size is from [0,0.25]

‘’’
void cae()
{
Float_t Threshold;
TFile* file_input = new TFile(“Mar07.root”, “read”);
TTree* currentAna = (TTree*)file_input->Get(“current_ntuple”);

Float_t Curr;
Int_t NumBins = 1;
currentAna->SetBranchAddress("Current", &Curr);

ULong64_t nEntries = currentAna->GetEntries();
cout << "This tree contains " << nEntries << " events!" << endl;
cout << "Loop over " << nEntries << " events!" << endl;

TH1D* curr_vals = new TH1D("curr_vals", "",NumBins, 0, 1);
curr_vals -> GetXaxis()-> SetTitle("Current [#muA] ");
curr_vals -> GetYaxis()-> SetTitle("Frequency");
curr_vals -> SetTitle("Current Distribution from January till March 02");
for(Int_t f = 0; f < nEntries; f++)
{
    currentAna->GetEntry(f);
    curr_vals->Fill(abs(Curr));
}

TCanvas* c1 = new TCanvas("c1");
curr_vals->Draw();
c1->SetLogy();
c1->Update();


TH1D* beyondThreshold = new TH1D("beyondThreshold", "",NumBins, 0, 1);
beyondThreshold -> GetXaxis()-> SetTitle("Current [#muA] ");
beyondThreshold -> GetYaxis()-> SetTitle("Percentage [%]");
beyondThreshold->Sumw2(kTRUE);
for(ULong64_t i = 0; i < NumBins; i++)
{
    Threshold = i;
    Int_t count = 0;

    for(ULong64_t e = 0; e < nEntries; e++)
        {
         currentAna->GetEntry(e);
        if( abs(Curr) < Threshold ) continue;
        {
            count++;
        }
    }
    beyondThreshold->SetBinContent(i+1, Double_t(count) * 100. / Double_t(nEntries));
    beyondThreshold->SetBinContent(i+1, count*100/nEntries);
    cout << Threshold << "\t \t" << count << endl;
}
TCanvas* c2 = new TCanvas("c2");
c2->SetLogy();

beyondThreshold->Draw();
beyondThreshold->SetTitle("Percentage of current beyond the threshold value from March 07 to April 10");
c2->Update();

}

‘’’

or you can also use DrawNormalized.

1 Like