- #1
lavster
- 217
- 0
Homework Statement
Im having difficulty drawing a specific graph. I am not entirely sure how to explain my question/ the graph i need to draw so i think the best way is to provide a bit of my code and explain using it the graph using it...
the code below gives a read out of the energy deposited (Phantom_Ed) for a particular x interval (Phantom_xpre). These read-outs are given a label - E1 for between -100 and -90mm, E2 for -90 and -80mm etc. What id like to do is produce a graph of the position (Phantom_xpre) with the corresponding value of Energy deposited (E1 for first interval etc) plotted on the y axis. However I am not sure how I am to go about doing this...
Homework Equations
my code at the moment (with the bit before defining the tree etc missing) is:
Long64_t nentries = T->GetEntries();// so can determine how many entries for loop
float E1=0; // defining variables for loop and setting to zero
float E2=0;
float E3=0;
float E4=0;
float E11=0;
float E12=0;
float E13=0;
float E14=0;
for(Long64_t k=0;k<nentries;k++)//original loop - gets the entry
{
T->GetEntry(k);
for( Long64_t l=0; l < Phantom_Nhits; l++ ) //steps loop
{
if((Phantom_xpre[l]>=-100) && (Phantom_xpre[l]<-90)) //if statement defining the region of x-axis of interest
{
E1=Phantom_Ed[l]+E1; //adding up the total energy depsoited in this region
}
if((Phantom_xpre[l]>=-90) && (Phantom_xpre[l]<=-80))
{
E11=Phantom_Ed[l]+E11;
}
if((Phantom_xpre[l]>=-80) && (Phantom_xpre[l]<=-70))
{
E12=Phantom_Ed[l]+E12;
}
if((Phantom_xpre[l]>=-70) && (Phantom_xpre[l]<=-60))
{
E13=Phantom_Ed[l]+E13;
}
if((Phantom_xpre[l]>=-60) && (Phantom_xpre[l]<=-50))
{
E14=Phantom_Ed[l]+E14;
}
if((Phantom_xpre[l]>=-50) && (Phantom_xpre[l]<0))
{
E2=Phantom_Ed[l]+E2;
}
if((Phantom_xpre[l]>=0) && (Phantom_xpre[l]<50))
{
E3=Phantom_Ed[l]+E3;
}
if((Phantom_xpre[l]>=50) && (Phantom_xpre[l]<=100))
{
E4=Phantom_Ed[l]+E4;
}
}//end of steps loop
//printing out to screen the energy in each section
cout << "Energy deposited in first section = " << E1 << " MeV" << endl;
cout << "Energy deposited in second section = " << E11 << "MeV" << endl;
cout << "Energy deposited in third section = " << E12 << "MeV" << endl;
cout << "Energy deposited in fourth section = " << E13 << "MeV" << endl;
cout << "Energy deposited in fifth section = " << E14 << "MeV" << endl;
cout << "Energy deposited in second quarter = " << E2 << "MeV" << endl;
cout << "Energy deposited in third quarter = " << E3 << "MeV" << endl;
cout << "Energy deposited in fourth quarter = " << E4 << "MeV" << endl;
}//end of primary loop
NB i will be changing so that the x intervals are the same length
The Attempt at a Solution
i would assume that the best way to deal with the x-axis is, first of all define a graph (TGraph or TGraph2D which, i don't know the documentation confused me)
in my head i would write some code that first of all sets the x position to be in the middle of the interval. make an array of the E's and somehow put it into graph form.
I realize that my "attempt at a solution" isn't fantastic but I've only been coding for a couple of months and writing the above code was rather testing and now i really don't know how to proceed further. Hence any help will be greatly appreciated
Thanks
NB: I am using CERN root package