I have selected two .txt files each having three colomns but I need two of them to plot between them and same procedure for the other 2nd .text file. At the end i want to plot both the graphs at one convas and find the difference between them. Kindly have a look the macro below why it does wrote them in one canvas and the procedure i followed is correct?
#include <iostream>
#include <sstream>
#include <fstream>
#include <TGraphErrors.h>
void rt_copy_new()
{
TCanvas *c1 = new TCanvas("c1","graph1",200,10,800,600);
std::ifstream inputFile1("/atlashome/msohail/calibration/athena/MuonCalibration_20.7.5/WorkArea/run/calibration/rts/Rt_BIL_5_-5.dat");
std::string line1;
double xarr1[105], yarr1[105], zarr1[105];
double xarr_err1[105]={105*0};
double yarr_err1[105]={105*0};
double zarr_err1[105]={105*0};
int i =0;
while(getline(inputFile1, line1))
{
if (!line1.length() || line1[0] == '#')
continue;
std::istringstream iss(line1);
double x = 20., y = 20., z= 20.;
iss>>z>>y>>x;
zarr1[i]=x;
yarr1[i]=y;
xarr1[i]=z;
i++;
std::cout<<"point:"<<x<<' '<<y<<std::endl;
}
TGraphErrors* gr_xy1= new TGraphErrors(i,yarr1,xarr1,yarr_err1,xarr_err1);
TGraphErrors* gr_yz1= new TGraphErrors(i,yarr1,zarr1,yarr_err1,zarr_err1);
TFile ouFile("old.root", "RECREATE");
gr_xy1->Draw("apl");
gr_xy1->Write("old");
gr_xy1->GetXaxis()->SetTitle("Time");
//second file
std::ifstream inputFile("/atlashome/msohail/calibration/athena_21/run/calibration/rts/Rt_BIL_5_-5.dat");
std::string line;
double xarr2[105], yarr2[105], zarr2[105];
double xarr_err2[105]={105*0};
double yarr_err2[105]={105*0};
double zarr_err2[105]={105*0};
int j =0;
while(getline(inputFile, line))
{
if (!line.length() || line[0] == '#')
continue;
std::istringstream iss(line);
double x = 20., y = 20., z= 20.;
iss>>z>>y>>x;
zarr2[j]=x;
yarr2[j]=y;
xarr2[j]=z;
j++;
std::cout<<"point:"<<x<<' '<<y<<std::endl;
}
TGraphErrors* gr_xy= new TGraphErrors(j,yarr2,xarr2,yarr_err2,xarr_err2);
TGraphErrors* gr_yz= new TGraphErrors(j,yarr2,zarr2,yarr_err2,zarr_err2);
TFile outFile("output.root", "RECREATE");
gr_xy->Draw("same");
gr_xy->Write("new");
gr_xy->GetXaxis()->SetTitle("Time");
gr_xy->GetYaxis()->SetTitle("Radius");
//difference
int maxCount = 105;
double diff_xarr3[105]= {0};
double diff_yarr3[105]= {0};
for(int i=0 ; i<maxCount ; i++)
{
diff_xarr3[i]=xarr1[i]-yarr1[i];
diff_yarr3[i]=xarr1[i]-yarr2[i];
}
TGraphErrors* diff_arr3= new TGraphErrors(i,diff_xarr3,diff_yarr3);
diff_arr3->Draw("same");
diff_arr3->Write("difference");
}