Roy
1
I am trying to create a percentage in Y-axis instead of count.
planning to use for loop but how can I accomplish that;
TH1F *hist = new TH1F("hist","Histogram",100,0,100);
ifstream file;
file.open("C07.txt", ios::in);
double value;
while(1)
{
file>>value;
hist -> Fill(value);
if (file.eof())break;
}
hist ->GetXaxis() ->SetTitle("data");
hist ->GetYaxis()->SetTitle("Percentage");
TCanvas*c1 = new TCanvas();
hist ->Draw();
}
Maybe you want (before drawing): hist->Scale(100. / hist->Integral());
Roy
4
shows an error (no debug info)
cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const (no debug info)
void CurrentAnalysis()
{
Float_t Threshold;
TFile* file_input = new TFile("January_data.root", "read");
TTree* currentAna = (TTree*)file_input->Get("voltage_current_ntuple");
Float_t Curr;
Int_t NumBins = 100;
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, NumBins);
curr_vals -> GetXaxis()-> SetTitle("Current [#muA] ");
curr_vals -> GetYaxis()-> SetTitle("Frequency");
curr_vals -> SetTitle("Current Distribution");
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, NumBins);
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, 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.");
// beyondThreshold->GetYaxis()->SetRangeUser(0, 0.5);
// beyondThreshold->GetXaxis()->SetRangeUser(0, 5);
c2->Update();
}
At least: Double_t(count) * 100. / Double_t(nEntries)