#include "Riostream.h" #include "TString.h" #include "TFile.h" #include "TNtuple.h" #include "TSystem.h" void basichist() { // Read data from an ascii file and create a root file with an histogram and an ntuple. // see a variant of this macro in basic2.C //Author: Rene Brun TString dir = gSystem->UnixPathName(__FILE__); dir.ReplaceAll("basichist.C",""); dir.ReplaceAll("/./","/"); ifstream in; in.open(Form("%s19-03-17.txt",dir.Data()));; Float_t Time, Vi_Brick1,Io_Brick1,Vo_Brick1,Vi_Brick2,Io_Brick2,Vo_Brick2,Vi_Brick3,Io_Brick3,Vo_Brick3,Vi_Brick4,Io_Brick4,Vo_Brick4; Int_t nlines = 0; auto f = TFile::Open("19-03-17.root","RECREATE"); //Creating the 2D histogram TH1D *h1 = new TH1D("h1","x distribution",100,0,43200); TH2D *h2 = new TH2D("h2","2D Histogram for input voltage over time for irradiation test R1-19-03-17;time (s);Vi (V)",200,0,43200,200,180,220); TH2D *h3 = new TH2D("h3","2D Histogram for output current over time for irradiation test R1-19-03-17;time (s);Io (A)",200,0,43200,200,2,3); TH2D *h4 = new TH2D("h4","2D Histogram for output voltage over time for irradiation test R1-19-03-17;time (s);Vo (V)",200,0,43200,200,10,12); TH2D *h5 = new TH2D("h5","2D Histogram for input voltage over time for irradiation test R1-19-03-17,time (s); Vi (V)",200,0,43200,200,180,220); TH2D *h6 = new TH2D("h6","2D Histogram for output current over time for irradiation test R1-19-03-17;time (s);Io (A)",200,0,43200,200,2,3); TH2D *h7 = new TH2D("h7","2D Histogram for output voltage over time for irradiation test R1-19-03-17;time (s);Vo (V)",200,0,43200,200,10,12); TH2D *h8 = new TH2D("h8","2D Histogram for input voltage over time for irradiation test R1-19-03-17;time (s);Vi (V)",200,0,43200,200,180,220); TH2D *h9 = new TH2D("h9","2D Histogram for output current over time for irradiation test R1-19-03-17;time (s);Io (A)",200,0,43200,200,2,3); TH2D *h10 = new TH2D("h10","2D Histogram for for output voltage over time for irradiation test R1-19-03-17;time (s);Vo (V)",200,0,43200,200,10,12); TH2D *h11 = new TH2D("h11","2D Histogram for input voltage over time for irradiation test R1-19-03-17;time (s) Vi (V)",200,0,43200,200,180,220); TH2D *h12 = new TH2D("h12","2D Histogram for output current over time for irradiation test R1-19-03-17;time (s);Io (A)",200,0,43200,200,2,3); TH2D *h13 = new TH2D("h13","2D Histogram for output voltage over time for irradiation test R1-19-03-17;time (s);Vo (V)",200,0,43200,200,10,12); TNtuple ntuple("ntuple","data from ascii file","Time:Vi_Brick1:Io_Brick1:Vo_Brick1:Vi_Brick2:Io_Brick2:Vo_Brick2:Vi_Brick3:Io_Brick3:Vo_Brick3:Vi_Brick4:Io_Brick4:Vo_Brick4"); while (1) { in >> Time >> Vi_Brick1 >> Io_Brick1 >> Vo_Brick1 >> Vi_Brick2 >> Io_Brick2 >> Vo_Brick2 >> Vi_Brick3 >> Io_Brick3 >> Vo_Brick3 >> Vi_Brick4 >> Io_Brick4 >> Vo_Brick4; if (!in.good()) break; if (nlines < 13) printf("Time=%i, Vi_Brick1=%8f, Io_Brick1=%8f, Vo_Brick1=%8f, Vi_Brick2=%8f, Io_Brick2=%8f, Vo_Brick2=%8f, Vi_Brick3=%8f, Io_Brick3=%8f, Vo_Brick3=%8f, Vi_Brick4=%8f, Io_Brick4=%8f, Vo_Brick4=%8f", Time, Vi_Brick1, Io_Brick1, Vo_Brick1, Vi_Brick2, Io_Brick2, Vo_Brick2, Vi_Brick3, Io_Brick3, Vo_Brick3, Vi_Brick4, Io_Brick4, Vo_Brick4); //h2.Fill(Time,Vi_Brick1); <<< Add this line h1->Fill(Time); h2->Fill(Time,Vi_Brick1); h3->Fill(Time,Io_Brick1); h4->Fill(Time,Vo_Brick1); h5->Fill(Time,Vi_Brick2); h6->Fill(Time,Io_Brick2); h7->Fill(Time,Vo_Brick2); h8->Fill(Time,Vi_Brick3); h9->Fill(Time,Io_Brick3); h10->Fill(Time,Vo_Brick3); h11->Fill(Time,Vi_Brick4); h12->Fill(Time,Io_Brick4); h13->Fill(Time,Vo_Brick4); ntuple.Fill(Time, Vi_Brick1,Io_Brick1,Vo_Brick1,Vi_Brick2,Io_Brick2,Vo_Brick2,Vi_Brick3,Io_Brick3,Vo_Brick3,Vi_Brick4,Io_Brick4,Vo_Brick4); nlines++; } printf(" found %d points\n",nlines); TCanvas *c1 = new TCanvas("c1", "c1",400,400); h2->Fit("pol1"); h2->Draw(); TCanvas *c2 = new TCanvas("c2", "c2",400,400); h3->Fit("pol1"); h3->Draw(); // TLatex* ltx1 = new TLatex(); // ltx1->DrawLatex( TCanvas *c3 = new TCanvas("c3", "c3",400,400); h4->Fit("pol1"); h4->Draw(); TCanvas *c4 = new TCanvas("c4", "c4",400,400); h5->Fit("pol1"); h5->Draw(); TCanvas *c5 = new TCanvas("c5", "c5",400,400); h6->Fit("pol1"); h6->Draw(); TCanvas *c6 = new TCanvas("c6", "c6",400,400); h7->Fit("pol1"); h7->Draw(); TCanvas *c7 = new TCanvas("c7", "c7",400,400); h8->Fit("pol1"); h8->Draw(); TCanvas *c8 = new TCanvas("c8", "c8",400,400); h9->Fit("pol1"); h9->Draw(); TCanvas *c9 = new TCanvas("c9", "c9",400,400); h10->Fit("pol1"); h10->Draw(); TCanvas *c10 = new TCanvas("c10", "c10",400,400); h11->Fit("pol1"); h11->Draw(); TCanvas *c11 = new TCanvas("c11", "c11",400,400); h12->Fit("pol1"); h12->Draw(); TCanvas *c12 = new TCanvas("c12", "c12",400,400); h13->Fit("pol1"); h13->Draw(); in.close(); f->Write(); }