New Reply

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

 
Share Thread Thread Tools
Nov25-10, 10:06 AM   #1
 

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


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 doesnt seem to work. can anyone tell me where i have gone wrong? thanks
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Bird's playlist could signal mental strengths and weaknesses
>> Minus environment, patterns still emerge: Computational study tracks E. coli cells' regulatory mechanisms
>> Bacterium uses natural 'thermometer' to trigger diarrheal disease, scientists find
Aug22-12, 04:55 PM   #2
 
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
New Reply
Thread Tools


Similar Threads for: how do you superimpose graphs from different root files in C++/root
Thread Forum Replies
Show that sq. root of 2 to power sq. root of 2 to .... N converges Calculus & Beyond Homework 3
square root and cube root question Precalculus Mathematics Homework 4
Need help with finding Root of an Equation, given another root. Analysis Question. Precalculus Mathematics Homework 10
prove sq root of 2 + sq root of 3 is irrational Calculus & Beyond Homework 1
Proove that the cubic root of 2 + the square root of 2 is irrational Calculus & Beyond Homework 4