Histogram from a Txt file

Hi everyone,

I started to use the root cern a short time , I’m trying to make a histogram from a text file. However in my text file I have my data divided into channel 0 (initial) and channel 1 (final). I need my program to read each pair of channels, give me the difference between them (1-0). And this result is put into my histogram.

Could someone help me solve this? I managed to get all the data and put in the histogram , now select peers and from the result could not.

Thank you all.

Mydata_txt.dat (70.9 KB)

Hi,

this will get you started:

import ROOT

def getCounts(line):
    return int(line.split(" ")[1])
    
h=ROOT.TH1F("diff","Counts Difference;Final-Initial;# Channels",200,4200,4400)
with open("Mydata_txt.dat") as f:
    lines = f.readlines()
    nlines = len(lines)
    for i in xrange(nlines/2):
        j = i*2
        begin = getCounts(lines[j])
        end = getCounts(lines[j+1])
        h.Fill(end-begin)

h.Draw()

raw_input("Press enter to exit.")

Danilo