Problem Macro crashes

Hello, I’m using an old macro that I used to fit data from file, to just plot data.
Unfortunately, deleting the lines regarding of the fit, the macro crashes and I can’ understand the reason because of

Moreover, I would add tow coordinates line as in this graph
image
to show to students that in a RC circuit the time constant is the time to charge the capacitor at 63%…then, given that in my data the time costant is 10s, I need two coordinates line at time=10s and at the releated voltage value (about 3,15V). Is it possible to do it?
Here the macro and the data file
data2.txt (801 Bytes)
RC.cpp (1.5 KB)


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


void RC() {
   const char *datain = "data2.txt";
   const char *dataout = "RC.pdf";
   TCanvas *c01 = new TCanvas("c01","Graph",1280,1024);
   float offx=1.3;
   float offy=1.3;
   float margr=0.08;
   float w=3;
   float margl=0.12;
   float line=2;
   gPad->SetLeftMargin(margl);
   gPad->SetRightMargin(margr);
   TGraph *graph = new TGraph(datain,"%lg %lg");
   graph->SetMarkerColor(kBlue);
   graph->SetLineColor(kBlue);
   graph->SetMarkerStyle(3);
   graph->SetMarkerSize(1.3);
   graph->SetLineWidth(line);
   TPaveText *t=new TPaveText(0.7,0.15,0.75,0.2,"brNDC");
   graph->Draw("ap");
   graph->SetTitle("RC circuit");
   graph->GetXaxis()->SetTitle("Time (s)");
   graph->GetYaxis()->SetTitle("Voltage (V)");
   graph->GetYaxis()->SetTitleOffset(offy);
   graph->GetXaxis()->SetTitleOffset(offx);
   TLegend* leg = new TLegend(0.15, 0.75, .25, .85);
   leg->SetHeader("Legend");
   leg->SetNColumns(1);
   leg->AddEntry(graph, "Data", "ap");
   leg->Draw();
   c01->Print(dataout);
}

Thank you @couet… it worked, but I can’t notice what you fixed…can you tell me it please?
Moreover, is there a way to do this

can’t you do a diff ?

Oh yes! Now I noticed it! The stat box!

You will need to draw two dotted TLine and two TLatex at the proper positions.

Thank you @couet, I did it!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.