PROBLEM: Basic Histogram Filling Improperly


I’m new to ROOT, (Just got an undergrad job at Fermilab), and to practice with the hardware here, I set up a muon telescope to take simple counts. Now, I had these counts in a text file column, of which I was able to read into a TTree file and log into a leaf of which I called “px”, each count having a different value associated to it.

My first experiment is to try to make a histogram of these counts, and I noticed if I double-click the “px” leaf in TBrowser, I’ll see the histogram of my dreams (htemp). However, to manipulate the histogram to my wishes, I want to create it from scratch. The following code creates the histogram after creating the TTree with my variable “px” and I wish to fill the new histogram with the px variable to make it look similar to the htemp one, only custom.

When I run the program, I have 14731 counts and want to read each one in, but what it does is read only the LAST VALUE (it happens to be 352mV) into the histogram 14731 times. Obviously incorrect. I want it to step through all the data and plot it logically in separate bins. It’d be very much appreciated if I could have some help :confused:


//Create a TFile with a TTree called “f”
TFile f("/home/propp/Desktop/treebutt.root",“recreate”);
TTree t1(“t1”,“a simple Tree with simple variables”);
//Administer to it a single variable “px”
Float_t px;
//Create a Single Branch on that Tree with “px” as its leaf.

//Read in a data file and fill the leaf with all the data
t1.ReadFile("/home/propp/Desktop/Histograms/PureColumns/Run 3.dat");

//Create a 1D histogram using the data from the “px” leaf.
TH1F *hpx = new TH1F(“hpx”,“Lead-Glass Counts”,2000,0,2000);
//“Grab” from the px leaf 14731 times to fill the histogram with data.
for( int i=0; i<14731; i++) {

//Draw it for the user

//Write the whole operation to the TFile and save!


If there’s any other info you need, feel free to ask!


Thanks a million, I’ll attempt to implement the techniques used here and let you know how far I get.