/// \file /// \ingroup tutorial_hist /// \notebook -js /// Illustrate use of the TH1::GetCumulative method. /// /// \macro_image /// \macro_code /// /// \author M. Schiller #include #include #include "TH1.h" #include "TH1D.h" #include "TCanvas.h" #include "TRandom.h" #include "DoubleList.h" #include "DoubleList.c" TCanvas *original() { gStyle->SetOptStat("nemri"); gStyle->SetStatW(0.15); // Set width of stat-box (fraction of pad size) gStyle->SetStatH(0.1); // Set height of stat-box (fraction of pad size) TH1* h5 = new TH1D("8000 Samples","", 260, 4.6., 13.6); ifstream inp5; double x5; inp5.open("Penalty_8000_522000.txt"); while (inp5 >> x5) { h5->Fill(x5); } inp5.close(); h5->SetLineColor(41); h5->SetLineWidth(1); TLine *l5 = new TLine(5.52564,0,5.52564,14200); l5->SetLineColor(41); l5->SetLineWidth(1); TPaveText *pt5 = new TPaveText(5.6,15800,6.4,15500); //pt5->SetBorderSize(1); //pt5->AddText("f#left(x_{0}#right) = 5.36"); //h5->GetYaxis()->SetRangeUser(0,16000); //4000_522422 TH1* h = new TH1D("4000 Samples","", 260, 4.6., 13.6); ifstream inp; double x; inp.open("Penalty_4000_522000.txt"); while (inp >> x) { h->Fill(x); } inp.close(); h->SetLineColor(9); h->SetLineWidth(1); TLine *l = new TLine(5.47581,0,5.47581,14200); l->SetLineColor(9); l->SetLineWidth(1); //TPaveText *pt = new TPaveText(5.4,14800,6.2,15500); //pt->SetBorderSize(1); //pt->AddText("f#left(x_{0}#right) = 5.48"); //2000_522422 TH1* h1 = new TH1D("2000 Samples","", 260, 4.6., 13.6); ifstream inp1; double x1; inp1.open("Penalty_2000_522000.txt"); while (inp1 >> x1) { h1->Fill(x1); } inp1.close(); h1->SetLineColor(8); h1->SetLineWidth(1); TLine *l1 = new TLine(6.29896,0,6.29896,14200); l1->SetLineColor(8); l1->SetLineWidth(1); //TPaveText *pt1 = new TPaveText(6.2,13600,7,14100); //pt1->SetBorderSize(1); //pt1->AddText("f#left(x_{0}#right) = 6.3"); //1000_522422 TH1* h2 = new TH1D("1000 Samples","", 260, 4.6, 13.6); ifstream inp2; double x2; inp2.open("Penalty_1000_522000.txt"); while (inp2 >> x2) { h2->Fill(x2); } inp2.close(); h2->SetLineColor(6); h2->SetLineWidth(1); TLine *l2 = new TLine(7.65041,0,7.65041,14200); l2->SetLineColor(6); l2->SetLineWidth(1); //TPaveText *pt2 = new TPaveText(7.6,12200,8.4,12700); //pt2->SetBorderSize(1); //pt2->AddText("f#left(x_{0}#right) = 7.65"); //100_522422 TH1* h3 = new TH1D("100 Samples","", 260, 4.6, 13.6); ifstream inp3; double x3; inp3.open("Penalty_100_522000.txt"); while (inp3 >> x3) { h3->Fill(x3); } inp3.close(); h3->SetLineColor(46); h3->SetLineWidth(1); TLine *l3 = new TLine(10.98,0,10.98,7200); l3->SetLineColor(46); l3->SetLineWidth(1); //TPaveText *pt3 = new TPaveText(10.3,7200,11.1,7700); //pt3->SetBorderSize(1); //pt3->AddText("f#left(x_{0}#right) = 11"); //Chr_3_522422 TH1* h4 = new TH1D("Reference Coil Set","",260, 4.6, 13.6); DoubleList OnePercent4 = DoubleList(1000); //1% Stack DoubleList TwoPercent4 = DoubleList(2000); //2% Stack DoubleList FivePercent4 = DoubleList(5000); //5% Stack DoubleList TenPercent4 = DoubleList(10000); //10% Stack ifstream inp4; double x4; inp4.open("Penalty_Chr_3.5_522000.txt"); while (inp4 >> x4) { h4->Fill(x4); OnePercent4.additem(x4); TwoPercent4.additem(x4); FivePercent4.additem(x4); TenPercent4.additem(x4); } inp4.close(); h4->SetLineColor(1); h4->SetLineWidth(2); TLine *l4 = new TLine(6.65137,0,6.65137,14200); l4->SetLineColor(1); l4->SetLineWidth(2); value = OnePercent4.getValue(); bin = h4->GetXaxis()->FindBin(value); TLine *lOne4 = new TLine(value,-200,value,h4->GetBinContent(bin)); lOne4->SetLineColor(1); lOne4->SetLineWidth(2); value = TwoPercent4.getValue(); bin = h4->GetXaxis()->FindBin(value); TLine *lTwo4 = new TLine(value,-200,value,h4->GetBinContent(bin)); lTwo4->SetLineColor(1); lTwo4->SetLineWidth(2); value = FivePercent4.getValue(); bin = h4->GetXaxis()->FindBin(value); TLine *lFive4 = new TLine(value,-200,value,h4->GetBinContent(bin)); lFive4->SetLineColor(1); lFive4->SetLineWidth(2); value = TenPercent4.getValue(); bin = h4->GetXaxis()->FindBin(value); TLine *lTen4 = new TLine(value,-200,value,h4->GetBinContent(bin)); lTen4->SetLineColor(1); lTen4->SetLineWidth(2); // draw histogram together with its cumulative distribution TCanvas* c = new TCanvas; // c->Divide(1,2); // c->cd(1); gPad->SetGrid(1,1); TIter next(gDirectory->GetList()); TObject *obj; while ((obj=next())) { if (obj->InheritsFrom("TH1")) { TH1 *m = (TH1*)obj; m->GetXaxis()->SetTitle("Penalty Value"); m->GetXaxis()->CenterTitle(); m->GetYaxis()->SetTitle("Frequency"); m->GetYaxis()->CenterTitle(); m->GetYaxis()->SetTitleOffset(1.2); } } h5->Draw(); l5->Draw(); h->Draw("sames"); l->Draw(); h1->Draw("sames"); l1->Draw(); h2->Draw("sames"); l2->Draw(); h3->Draw("sames"); l3->Draw(); h4->Draw("sames"); l4->Draw(); lOne4->Draw(); lTwo4->Draw(); lFive4->Draw(); lTen4->Draw(); //----------------------------- /* c->cd(2); gPad->SetGrid(1,1); hc->Draw(); hc1->Draw("sames"); hc3->Draw("sames"); hc4->Draw("sames"); hc2->Draw("sames"); */ c->Update(); TPaveStats *s5 = (TPaveStats*)h5->GetListOfFunctions()->FindObject("stats"); s5->SetLineColor(41); s5->SetX1NDC(0.368); s5->SetX2NDC(0.568); s5->SetY1NDC(0.99); s5->SetY2NDC(0.83); s5->Draw(); TPaveStats *s = (TPaveStats*)h->GetListOfFunctions()->FindObject("stats"); s->SetLineColor(9); s->SetX1NDC(0.574); s->SetX2NDC(0.774); s->SetY1NDC(0.99); s->SetY2NDC(0.83); s->Draw(); TPaveStats *s1 = (TPaveStats*)h1->GetListOfFunctions()->FindObject("stats"); s1->SetLineColor(8); s1->SetX1NDC(0.78); s1->SetX2NDC(0.98); s1->SetY1NDC(0.99); s1->SetY2NDC(0.83); s1->Draw(); TPaveStats *s2 = (TPaveStats*)h2->GetListOfFunctions()->FindObject("stats"); s2->SetLineColor(6); s2->SetX1NDC(0.78); s2->SetX2NDC(0.98); s2->SetY1NDC(0.82); s2->SetY2NDC(0.66); s2->Draw(); TPaveStats *s3 = (TPaveStats*)h3->GetListOfFunctions()->FindObject("stats"); s3->SetLineColor(46); s3->SetX1NDC(0.78); s3->SetX2NDC(0.98); s3->SetY1NDC(0.65); s3->SetY2NDC(0.49); s3->Draw(); TPaveStats *s4 = (TPaveStats*)h4->GetListOfFunctions()->FindObject("stats"); s4->SetLineColor(1); s4->SetX1NDC(0.78); s4->SetX2NDC(0.98); s4->SetY1NDC(0.48); s4->SetY2NDC(0.32); s4->Draw(); c->Update(); gPad->Print("2D_35.tex"); gPad->Print("2D_35.pdf"); return c; }