Problem with declare and define more histograms

Dear everybody,

I am working with pyROOT and I find an particular problem when I tried to define and declare multi-histogram.

Firslty I defined a list as following:

nuanus       = ['nu', 'anu']
nutypes      = ['mu', 'e', 'tau']
currents_weak     = ['_CC', '_NC']

I made a cycle for to have all combinations:

flavours    = []
for nuanu in nuanus:
    for nutype in nutypes:
        for current in currents_weak:
            flavours.append( nuanu + nutype + current ) 

Defined a general histogram:

h_Ntot_cos_ = {}

Finally I defined all histogram:

for flavour in flavours:

     h_Ntot_cos_[flavour]                              = ROOT.TH2D( "h_Ntot_cos_"           +flavour,    "TOTAL rate of cosmic neutrinos (NOCUTS AT ALL), 1 building block, 1 yr, "+flavour, nbinsx, bin_minX, bin_maxX, nbinsr, rmin, rmax )

Where in my opinion I considered all combination (printing I found that was correct).
But If I do a simple operation like (outside the cycle):

h_Ntot_cos_numu_CC. Add(h_Ntot_cos_numu_CC,h_Ntot_cos_anumu_CC,1.0,1.0)

I mean, why I cannot considering one specific histogram, if was declared???

Maybe @etejedor can take a look

h_Ntot_cos_numu_CC is not the name of a variable. As per your code, to access that histo, you need to do h_Ntot_cos_['numu_CC']. In other words, you need to access the histo that you stored in a dictionary.

1 Like


Thank you a lot, I didn’t thought about that.

Have a nice day.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.