I have a quick question… can I write the following code in c++? If there is any way, can you point me out which tutorial shoul I look at and which root libraries should I use?
I appreciate your comments.
The following code is very simple. It reads a file that contain two column of numbers and then plots those values and do a linear fit.
and example of the dat value that I have is something like this: (filename: “plotDt21rn5.dat”)
//begin of file:do not consider this line
3173 -19.105
3175 -18.868
3176 -18.510
3177 -18.003
3179 -17.480
//end of file: do not consider this line
this is my code in ROOT
{
gROOT->Reset();
const Int_t n = 5;
char fname[100], message[50];
ifstream in;
Int_t ring=2;
Int_t run=3173;
Int_t chann=21;
Double_t p, q;
Double_t x[n], y[n];
TF1 *myfit;
sprintf(fname,"/home/mosquera/analysis/ddvDAT/plotDt%drn5.dat",chann);
in.open(fname);
c1 = new TCanvas(“c1”,“Transmission”,20,50,1200,800);
c1->SetFillColor(kWhite);
c1->SetGrid();
myfit = new TF1(“myfit”,“pol2”, 3170, 3181);
for (Int_t i=0;i<n;i++){
in >> p >> q;
x[i] = p;
y[i] = q;
printf(" i %i %f %f \n",i,x[i],y[i]);
}
gr = new TGraph(n,x,y);
gr->SetLineColor(1);
gr->SetLineWidth(1);
gr->SetMarkerColor(4);
gr->SetMarkerStyle(25);
sprintf(message,“detector %d”,chann);
gr->Fit(“myfit”,“R”);//change
myfit->Draw(); //change
gr->SetTitle(message);
gr->GetXaxis()->SetTitle(“runs”);
gr->GetYaxis()->SetTitle(“Signal Output”);
gr->Draw(“CP”); //change
// TCanvas::Update() draws the frame, after
// which one can change it
c1->Update();
c1->GetFrame()->SetFillColor(kWhite);
c1->GetFrame()->SetBorderSize(2);
c1->Modified();
in.close();
}
I apreciate your comments and guidance,