C/C++ How do you superimpose graphs from different root files in C++/root

AI Thread Summary
The discussion revolves around an attempt to superimpose multiple graphs from different Emacs files using ROOT, a data analysis framework. The user has written code to read several ROOT files and plot graphs on a single canvas. However, they encounter issues with the drawing options for the graphs. It is highlighted that the "sames" option is only applicable to histograms, and for graphs, the first graph should be drawn with the "A" option to include axes. Subsequent graphs should be drawn without the "A" option but should include a marker option. This adjustment is suggested as a solution to the problem faced in the code implementation.
lavster
Messages
213
Reaction score
0
Hi,

ive created several graphs in different emacs files. I now want to superimpose them using code in a different emacs file. This is what i have done:

Code:
  //get the input files

  TFile * inputfile = new TFile("p60.root","READ");
  TFile * inputfile2 = new TFile("p20.root","READ");
  TFile * inputfile3 = new TFile("p80.root","READ");
  TFile * inputfile4 = new TFile("p40.root","READ");
  
  //define canvas and plotting like before
  
  /////////////////////////////////////////////////////////////////
  //superposition of different energies of proton beam (one proton)
  /////////////////////////////////////////////////////////////////
  
   gStyle->SetPalette(1);
  
  TCanvas* comp = new TCanvas("comp","",1100,1100);
  comp->Clear();
  comp->Divide(1,1);
  //TGraph* g40 = (TGraph*) inputfile4 -> Get("g4");//bit in the bracket is the name of the histogram
   TGraph* g20 = (TGraph*) inputfile2 -> Get("g4");
  comp->cd(1);
  g20->SetLineColor(2);//2=red
  g20->GetXaxis()->SetTitle("x (mm)");//title
  g20->GetYaxis()->SetTitle("energy deposited (Mev)");
  g20->Draw();
  g20->GetXaxis()->SetTitleOffset(0.9);//changes vertical postion of the title
  g20->GetXaxis()->SetTitleSize(0.045);//changes size of xaxis title (default)
  g20->GetXaxis()->SetLabelSize(0.04); //changes the size of numbers on xaxis
  g40->Draw("sames");// the s at end means that can have multiple stats box
  g60->Draw("sames");
  g20->SetLineColor(3);//2=red
  g80->Draw("sames");
  g20->SetLineColor(4);//2=red
  //add legends
  
   comp->Modified();
   comp->Update();
   TLegend* legends = new TLegend(0.130,0.828,0.436,0.980,"","brNDC"); // the numbers determine the position of the box
   legends->SetFillColor(0);
   legends->SetHeader("proton dose distributions");
   legends->AddEntry(g20, "20MeV proton beam","l");//(name of hist,what you want it called in legend, l=line, p=polymarker, f=boxy thing )
   legends->AddEntry(g40, "40MeV proton beam","l");
   //legends->AddEntry(g60, "60MeV proton beam","l");
   // legends->AddEntry(g80, "80MeV proton beam","l");
  // legends->Draw();
  
  comp->cd();

however, this doesn't seem to work. can anyone tell me where i have gone wrong? thanks
 
Technology news on Phys.org
I know it is an old post, but I'll answer it to avoid an unanswered post.

The problem is in the options to draw the graphs. The "same" or "sames" option works only for histograms.
For graphs, the first should be, at least, with the "A" option to include the axis. An extra option should appear for the marks or lines. Now, the next graphs should be drawn WITHOUT the A option, but with the mark option.

I think it should work
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top