#include "Riostream.h" #include "TString.h" #include "TNtuple.h" #include "TSystem.h" void plot2graphs() { ifstream in; in.open("Run_13-19.txt"); Float_t Time,Vi_Brick1,Io_Brick1,Vo_Brick1,Vi_Brick2,Io_Brick2; Float_t Vo_Brick2,Vi_Brick3,Io_Brick3,Vo_Brick3,Vi_Brick4,Io_Brick4; Float_t Vo_Brick4,Vi_Brick1err,Vi_Brick2err,Vi_Brick3err; Float_t Vi_Brick4err,Io_Brick1err,Io_Brick2err,Io_Brick3err; Float_t Io_Brick4err,Vo_Brick1err,Vo_Brick2err,Vo_Brick3err,Vo_Brick4err; Int_t n1 = 0; auto f = TFile::Open("Run_13-19.root","RECREATE"); TNtuple ntuple("ntuple","data from ascii file","Time:Vi_Brick1:Vi_Brick1err:Io_Brick1:Io_Brick1err:Vo_Brick1:Vo_Brick1err:Vi_Brick2:Vi_Brick2err:Io_Brick2:Io_Brick2err:Vo_Brick2:Vo_Brick2err:Vi_Brick3:Vi_Brick3err:Io_Brick3: Io_Brick3err:Vo_Brick3:Vo_Brick3err:Vi_Brick4:Vi_Brick4err:Io_Brick4:Io_Brick4err:Vo_Brick4:Vo_Brick4err"); TGraphErrors *g1 = new TGraphErrors(); TGraphErrors *g2 = new TGraphErrors(); TGraphErrors *g3 = new TGraphErrors(); TGraphErrors *g4 = new TGraphErrors(); TGraphErrors *g5 = new TGraphErrors(); TGraphErrors *g6 = new TGraphErrors(); TGraphErrors *g7 = new TGraphErrors(); TGraphErrors *g8 = new TGraphErrors(); TGraphErrors *g9 = new TGraphErrors(); TGraphErrors *g10 = new TGraphErrors(); TGraphErrors *g11 = new TGraphErrors(); TGraphErrors *g12 = new TGraphErrors(); while (1) { in >> Time >> Vi_Brick1 >> Vi_Brick1err >> Io_Brick1 >> Io_Brick1err >> Vo_Brick1 >> Vo_Brick1err >> Vi_Brick2 >> Vi_Brick2err >> Io_Brick2 >>Io_Brick2err >> Vo_Brick2 >>Vo_Brick2err >> Vi_Brick3 >>Vi_Brick3err >> Io_Brick3 >> Io_Brick3err >> Vo_Brick3 >> Vo_Brick3err >> Vi_Brick4 >> Vi_Brick4err >> Io_Brick4 >> Io_Brick4err >> Vo_Brick4 >> Vo_Brick4err; // cout <<"Time:"<SetPoint(n1,Time,Vi_Brick1); g1->SetPointError(n1,0.0,Vi_Brick1err); g2->SetPoint(n1,Time,Io_Brick1); g2->SetPointError(n1,0.0,Io_Brick1err); g3->SetPoint(n1,Time,Vo_Brick1); g3->SetPointError(n1,0.0,Vo_Brick1err); g4->SetPoint(n1,Time,Vi_Brick2); g4->SetPointError(n1,0.0,Vi_Brick2err); g5->SetPoint(n1,Time,Io_Brick2); g5->SetPointError(n1,0.0,Io_Brick2err); g6->SetPoint(n1,Time,Vo_Brick2); g6->SetPointError(n1,0.0,Vo_Brick2err); g7->SetPoint(n1,Time,Vi_Brick3); g7->SetPointError(n1,0.0,Vi_Brick3err); g8->SetPoint(n1,Time,Io_Brick3); g8->SetPointError(n1,0.0,Io_Brick3err); g9->SetPoint(n1,Time,Vo_Brick3); g9->SetPointError(n1,0.0,Vo_Brick3err); g10->SetPoint(n1,Time,Vi_Brick4); g10->SetPointError(n1,0.0,Vi_Brick4err); g11->SetPoint(n1,Time,Io_Brick4); g11->SetPointError(n1,0.0,Io_Brick4err); g12->SetPoint(n1,Time,Vo_Brick4); g12->SetPointError(n1,0.0,Vo_Brick4err); n1++; if(!in.good()) break; } { gROOT->Reset(); c1 = new TCanvas("c1","plot2graphs",200,10,700,500); TPad *pad = new TPad("pad","",0,0,1,1); pad->SetFillColor(42); pad->SetGrid(); pad->Draw(); pad->cd(); // draw a frame to define the range TH1F *hr = c1->DrawFrame(0,-8.16E-07,168, 1.19E-06); hr->SetXTitle("Time"); hr->SetYTitle("V_out"); pad->GetFrame()->SetFillColor(21); pad->GetFrame()->SetBorderSize(12); //create first graph //g1->SetMarkerStyle(21); //g1->SetMarkerColor(2); g1->SetLineColor(kBlue); g1->SetLineWidth(1); g1->SetMarkerColor(kBlue); g1->SetMarkerStyle(21); g1->Draw("LP"); //create a transparent pad drawn on top of the main pad c1->cd(); TPad *overlay = new TPad("overlay","",0,0,1,1); overlay->SetFillStyle(4000); overlay->SetFillColor(0); overlay->SetFrameFillStyle(4000); overlay->Draw(); overlay->cd(); // create second graph //g2->SetMarkerStyle(21); //g2->SetMarkerColor(2); g2->SetLineColor(kBlue); g2->SetLineWidth(1); g2->SetMarkerColor(kBlue); g2->SetMarkerStyle(20); g2->SetName("g2"); Double_t xmin = pad->GetUxmin(); Double_t ymin = pad->GetUymin(); Double_t xmax = pad->GetUxmax(); Double_t ymax = pad->GetUymax(); TH1F *hframe = overlay->DrawFrame(xmin,ymin,xmax,ymax); hframe->GetXaxis()->SetLabelOffset(99); hframe->GetYaxis()->SetLabelOffset(99); g2->Draw("LP"); //Draw an axis on the right side TGaxis *axis = new TGaxis(xmax,ymin,xmax, ymax,ymin,ymax,510,"+L"); axis->SetLineColor(kRed); axis->SetLabelColor(kRed); axis->Draw(); } in.close(); }