コード例 #1
0
def createPlots(plotopts, rootopts):
    from ROOT import TH1D, TProfile, TH2D, TProfile2D
    plots = {}
    #creating histos
    for plotopt in plotopts:
        plots[plotopt] = {}
        for rootopt in rootopts:
            if (plotopt.profile):
                if (plotopt.i2d):
                    plot = TProfile2D(
                        str(hash(plotopt)) + str(hash(rootopt)),
                        plotopt.display_name, plotopt.nbins[0], 0, 0,
                        plotopt.nbins[1], 0, 0)
                else:
                    plot = TProfile(
                        str(hash(plotopt)) + str(hash(rootopt)),
                        plotopt.display_name, plotopt.nbins, 0, 0)
            else:
                if (plotopt.i2d):
                    plot = TH2D(
                        str(hash(plotopt)) + str(hash(rootopt)),
                        plotopt.display_name, plotopt.nbins[0], 0, 0,
                        plotopt.nbins[1], 0, 0)
                else:
                    plot = TH1D(
                        str(hash(plotopt)) + str(hash(rootopt)),
                        plotopt.display_name, plotopt.nbins, 0, 0)
            plot.SetBuffer(1000000)
            plots[plotopt][rootopt] = plot
    return plots
コード例 #2
0
 def create_residual(data,
                     model,
                     nbins=None,
                     maxr=None,
                     calcr=None,
                     skipzero=False):
     """Create radial residual histogram."""
     if nbins is None:
         nbins = data.GetXaxis().GetNbins()
     if maxr is None:
         maxr = data.GetXaxis().GetXmax()
     if calcr is None:
         calcr = lambda x, y: (x**2 + y**2)**0.5
     data.SetBinErrorOption(kPoisson)
     res = TProfile('radialRes', '', nbins, 0.0, maxr)
     for xbin in range(data.GetXaxis().GetNbins()):
         for ybin in range(data.GetYaxis().GetNbins()):
             d = data.GetBinContent(xbin + 1, ybin + 1)
             if skipzero and d == 0.0:
                 continue
             m = model.GetBinContent(xbin + 1, ybin + 1)
             if m < d:
                 e = data.GetBinErrorLow(xbin + 1, ybin + 1)
             else:
                 e = data.GetBinErrorUp(xbin + 1, ybin + 1)
             x = data.GetXaxis().GetBinCenter(xbin + 1)
             y = data.GetYaxis().GetBinCenter(ybin + 1)
             res.Fill(calcr(x, y), (d - m) / e)
     return res
コード例 #3
0
ファイル: hdf5_reader.py プロジェクト: diamondIPP/pxar
 def draw_vcal_time(self, bin_width=1000):
     vcals = self.get_vcal_values()
     h = TProfile('hvt', 'VCAL vs. Time', *self.get_event_bins(bin_width))
     h.FillN(vcals.size, arange(vcals.size, dtype='d'), vcals.astype('d'),
             full(vcals.size, 1, 'd'))
     format_histo(h, x_tit='Cluster Number', y_tit='VCAL', y_off=1.5)
     self.Plotter.format_statbox(entries=1, x=.9)
     self.Plotter.draw_histo(h, lm=.12, rm=.08)
コード例 #4
0
def staff():

    FitParam = ROOT.FitParameters_t()
    f = TFile("FitParam.root", "RECREATE")
    tree = TTree('T', "Fitparameters from main program")
    tree.Branch("FitParam", FitParam, 'Drift_Velocity:Fit_Gradient')

    fname = "test.txt"

    hdv = TH1F("hdv", "Drift Velocity Distribution", 100, 0.002615, 0.002645)
    hfg = TH1F("hfg", "Track Angle Distribution", 100, 0, 0.3)
    hprof = TProfile("hprof", "Profile of Drift Velocity vs Track Angle", 100,
                     0.002615, 0.002645, 0, 0.3)

    histos = ['hdv', 'hfg', 'hprof']
    for name in histos:
        exec('%sFill = %s.Fill' % (name, name))

    for line in open(fname).readlines():
        t = list(filter(lambda x: x, re.split(',', line)))
        FitParam.Drift_Velocity = float(t[0])
        FitParam.Fit_Gradient = float(t[1])
        hdv.Fill(float(t[0]))
        hfg.Fill(float(t[1]))
        hprof.Fill(float(t[0]), float(t[1]))

        tree.Fill()

    c1 = TCanvas("c1", "Drift Velocity Histogram", 200, 10, 700, 500)
    c1.SetGridx()
    c1.SetGridy()
    hdv.Print()
    hdv.Draw()

    c1.Modified()
    c1.Update()

    c2 = TCanvas("c2", "Angular Distribution Histogram", 200, 10, 700, 500)
    c2.SetGrid()
    hfg.Print()
    hfg.Draw()
    c2.Modified()
    c2.Update()

    c3 = TCanvas("c3", "Profile", 200, 10, 700, 500)
    hprof.Print()
    hprof.Draw()
    c3.Modified()
    c3.Update()

    tree.Print()
    tree.Write()

    for name in histos:
        exec('del %sFill' % name)
    del histos

    x = input("Enter any key to continue")
コード例 #5
0
    def initialize(self):

        from TrigEgammaDevelopments.helper import zee_etbins, default_etabins, nvtx_bins
        from ROOT import TH1F, TProfile
        import numpy as np

        et_bins = zee_etbins
        eta_bins = default_etabins

        for name in self._monList:
            self.storeSvc().mkdir(self._basepath + '/' + name + '/Efficiency')
            self.storeSvc().addHistogram(
                TH1F('et', 'E_{T} distribution;E_{T};Count',
                     len(et_bins) - 1, np.array(et_bins)))
            self.storeSvc().addHistogram(
                TH1F('eta', '#eta distribution;#eta;Count',
                     len(eta_bins) - 1, np.array(eta_bins)))
            self.storeSvc().addHistogram(
                TH1F("phi", "#phi distribution; #phi ; Count", 20, -3.2, 3.2))
            self.storeSvc().addHistogram(
                TH1F('mu', '<#mu> distribution;<#mu>;Count', 16, 0, 80))
            self.storeSvc().addHistogram(
                TH1F('nvtx', 'N_{vtx} distribution;N_{vtx};Count',
                     len(nvtx_bins) - 1, np.array(nvtx_bins)))
            self.storeSvc().addHistogram(
                TH1F('match_et', 'E_{T} matched distribution;E_{T};Count',
                     len(et_bins) - 1, np.array(et_bins)))
            self.storeSvc().addHistogram(
                TH1F('match_eta', '#eta matched distribution;#eta;Count',
                     len(eta_bins) - 1, np.array(eta_bins)))
            self.storeSvc().addHistogram(
                TH1F("match_phi", "#phi matched distribution; #phi ; Count",
                     20, -3.2, 3.2))
            self.storeSvc().addHistogram(
                TH1F('match_mu', '<#mu> matched distribution;<#mu>;Count', 16,
                     0, 80))
            self.storeSvc().addHistogram(
                TH1F('match_nvtx',
                     'N_{vtx} matched distribution;N_{vtx};Count',
                     len(nvtx_bins) - 1, np.array(nvtx_bins)))
            self.storeSvc().addHistogram(
                TProfile("eff_et", "#epsilon(E_{T}); E_{T} ; Efficiency",
                         len(et_bins) - 1, np.array(et_bins)))
            self.storeSvc().addHistogram(
                TProfile("eff_eta", "#epsilon(#eta); #eta ; Efficiency",
                         len(eta_bins) - 1, np.array(eta_bins)))
            self.storeSvc().addHistogram(
                TProfile("eff_phi", "#epsilon(#phi); #phi ; Efficiency", 20,
                         -3.2, 3.2))
            self.storeSvc().addHistogram(
                TProfile("eff_mu", "#epsilon(<#mu>); <#mu> ; Efficiency", 16,
                         0, 80))
            self.storeSvc().addHistogram(
                TProfile("eff_nvtx", "#epsilon(N_{vtx}); N_{vtx} ; Efficiency",
                         len(nvtx_bins) - 1, np.array(nvtx_bins)))

        self.init_lock()
        return StatusCode.SUCCESS
コード例 #6
0
def plot_root(sample, base_name):
    met_pred, met_truth, met_reco, mt_pred, mt_reco = [
        TH1F(n, '', 100, 0, 500)
        for n
        in ['pt_{}'.format(arguments.regressor), 'pt_truth', 'met_reco',
            'mt_{}'.format(arguments.regressor), 'mt_reco']]
    res_pred, res_reco = [
        TH1F(n, '', 100, -100, 100)
        for n
        in ['res_{}'.format(arguments.regressor), 'res_reco']]
    profile = TProfile('profile_pred_{}'.format(arguments.regressor),
                       '', 100, 0, 500)

    map(met_pred.Fill, sample[met_pred_parameter])
    map(met_truth.Fill, sample[met_truth_parameter])
    map(met_reco.Fill, sample[met_reco_parameter])
    map(mt_pred.Fill, sample[mt_pred_parameter])
    map(mt_reco.Fill, sample[mt_reco_parameter])
    map(res_pred.Fill, sample[met_pred_resolution])
    map(res_reco.Fill, sample[met_reco_resolution])
    map(profile.Fill, sample['pt(mc nuH)'], sample[met_pred_ratio])

    root_file = TFile.Open('{}.root'.format(base_name), 'RECREATE')
    root_file.cd()
    met_pred.Write()
    mt_pred.Write()
    res_pred.Write()
    profile.Write()
    root_file.ls()
    root_file.Close()

    init_atlas_style()

    met_pred.SetName('Pred')
    met_reco.SetName('Reco')
    met_truth.SetName('Target')
    o1 = show_hists((met_pred, met_truth, met_reco),
                    'Missing ET',
                    '{}_met.pdf'.format(base_name))

    res_pred.SetName('Pred')
    res_reco.SetName('Reco')
    o2 = show_hists((res_pred, res_reco),
                    'Missing ET resolution',
                    '{}_res.pdf'.format(base_name))

    mt_pred.SetName('Pred')
    mt_reco.SetName('Reco')
    o3 = show_hists((mt_pred, mt_reco),
                    'Transverse mass',
                    '{}_mt.pdf'.format(base_name))

    profile.SetName('Profile')
    o3 = show_hists((profile,),
                    'Profile',
                    '{}_profile.pdf'.format(base_name))
    raw_input('Press any key...')
コード例 #7
0
ファイル: rootUtils.py プロジェクト: marteff/FairShip
def bookProf(h,key=None,title='',nbinsx=100,xmin=0,xmax=1,ymin=None,ymax=None,option=""):
  if key==None : 
    print 'missing key'
    return
  rkey = str(key) # in case somebody wants to use integers, or floats as keys 
  if h.has_key(key):    h[key].Reset()  
  if ymin==None or ymax==None:  h[key] = TProfile(key,title,nbinsx,xmin,xmax,option)
  else:  h[key] = TProfile(key,title,nbinsx,xmin,xmax,ymin,ymax,option)
  h[key].SetDirectory(gROOT)
コード例 #8
0
  def initialize(self):
   
    from ROOT import TH2F, TH1F, TProfile
    keyWanted = ['probes','fakes']

    for dirname in keyWanted:
      for pidname, pair in self._algDictNames.iteritems():
        for etBinIdx in range( len(self._thresholdEtBins)-1 ):
          for etaBinIdx in range( len(self._thresholdEtaBins)-1 ):
            
            binningname = ('et%d_eta%d') % (etBinIdx,etaBinIdx)
            algname = pair[0]
            tgtname = pair[1]
            mumax   = 100
            mumin   = 0
            nmubins = (mumax-mumin)-1
            etbins  = zee_etbins
            etabins = default_etabins
          
 
            # create neural network histograms
            self.storeSvc().mkdir( self._basepath+'/'+dirname+'/'+pidname+'/'+algname+'/'+binningname )
            self.storeSvc().addHistogram(TH2F('discriminantVsEt'  , 'Et Vs discriminant' , 1000, -12, 7, len(etbins)-1 , np.array(etbins) ) )
            self.storeSvc().addHistogram(TH2F('discriminantVsEta' , 'Eta Vs discriminant', 1000, -12, 7, len(etabins)-1, np.array(etabins) ) )
            self.storeSvc().addHistogram(TH2F('discriminantVsNvtx', 'Offline Pileup as function of the discriminant;discriminant;nvtx;Count', \
                                         1000, -12,7,len(nvtx_bins)-1,np.array(nvtx_bins)) ) 
            self.storeSvc().addHistogram(TH2F('discriminantVsMu'  , 'Online Pileup as function of the discriminant;discriminant;nvtx;Count' , \
                                         1000, -12,7,nmubins,mumin,mumax) ) 
          
            # create efficienci target histograms
            self.storeSvc().mkdir( self._basepath+'/'+dirname+'/'+pidname+'/'+tgtname+'/'+binningname )
            self.storeSvc().addHistogram(TH1F('et','E_{T} distribution;E_{T};Count', len(etbins)-1, np.array(etbins)))
            self.storeSvc().addHistogram(TH1F('eta','#eta distribution;#eta;Count', len(etabins)-1, np.array(etabins)))
            self.storeSvc().addHistogram(TH1F("phi", "#phi distribution; #phi ; Count", 20, -3.2, 3.2));
            self.storeSvc().addHistogram(TH1F('nvtx' ,'N_{vtx} distribution;N_{vtx};Count', len(nvtx_bins)-1, np.array(nvtx_bins)))
            self.storeSvc().addHistogram(TH1F('mu' ,'<#mu> distribution;<#mu>;Count', 16, 0, 80))
            self.storeSvc().addHistogram(TH1F('match_et','E_{T} matched distribution;E_{T};Count', len(etbins)-1, np.array(etbins)))
            self.storeSvc().addHistogram(TH1F('match_eta','#eta matched distribution;#eta;Count', len(etabins)-1, np.array(etabins)))
            self.storeSvc().addHistogram(TH1F("match_phi", "#phi matched distribution; #phi ; Count", 20, -3.2, 3.2));
            self.storeSvc().addHistogram(TH1F('match_nvtx' ,'N_{vtx} matched distribution;N_{vtx};Count', len(nvtx_bins)-1, np.array(nvtx_bins)))
            self.storeSvc().addHistogram(TH1F('match_mu' ,'<#mu> matched distribution;<#mu>;Count', 16, 0, 80))
            self.storeSvc().addHistogram(TProfile("eff_et", "#epsilon(E_{T}); E_{T} ; Efficiency" , len(etbins)-1, np.array(etbins)))
            self.storeSvc().addHistogram(TProfile("eff_eta", "#epsilon(#eta); #eta ; Efficiency"  , len(etabins)-1,np.array(etabins)))
            self.storeSvc().addHistogram(TProfile("eff_phi", "#epsilon(#phi); #phi ; Efficiency", 20, -3.2, 3.2));
            self.storeSvc().addHistogram(TProfile("eff_nvtx", "#epsilon(N_{vtx}); N_{vtx} ; Efficiency", len(nvtx_bins)-1, np.array(nvtx_bins)));	
            self.storeSvc().addHistogram(TProfile("eff_mu", "#epsilon(<#mu>); <#mu> ; Efficiency", 16, 0, 80));	


    self.init_lock()
    return StatusCode.SUCCESS 
コード例 #9
0
 def createHistogram( self, title=None, profile=False ):
     ## Create an empty histogram for this variable with the given title
     #  @param title      the title of the new histogram
     #  @param profile    set if the histogram should be a TProfile instead
     #  @return the new histogram 
     title = title if title is not None else self.title
     name = 'h%s_%s' % ( self.name.replace(' ', '').replace('(', '').replace(')',''), uuid.uuid1() )
     from ROOT import TH1D, TProfile
     if profile:
         h = TProfile( name, title, self.binning.nBins, 0., 1. )
     else:
         h = TH1D( name, title, self.binning.nBins, 0., 1. )
     self.binning.setupAxis( h.GetXaxis() )
     self.applyToAxis( h.GetXaxis() )
     return h
コード例 #10
0
def create2dHist(varname, params, title):
    if "to_pt" in varname and "tagRate" in varname:
        h = TProfile(varname, title, 50, params["plotPtRange"][0],
                     params["plotPtRange"][1])
        h.GetXaxis().SetTitle("#tau_{vis} p_{T} [GeV]")
        h.GetYaxis().SetTitle("tagging efficiency")
    if "to_eta" in varname and "tagRate" in varname:
        h = TProfile(varname, title, 50, params["plotEtaRange"][0],
                     params["plotEtaRange"][1])
        h.GetXaxis().SetTitle("#tau_{vis} #eta")
        h.GetYaxis().SetTitle("tagging efficiency")
    h.Sumw2()
    return h
コード例 #11
0
ファイル: util.py プロジェクト: kaducovas/ringer
def retrieveProfile(rfile, location):
    from ROOT import TProfile
    obj = TProfile('', '', 1, 0, 1)
    try:
        rfile.GetObject(location, obj)
        return obj
    except:
        raise RuntimeError(
            "Can not retrieve the TProfile object %s from root file", location)
コード例 #12
0
ファイル: myroc.py プロジェクト: suvayu/Bs2DsKTools
def get_hists(classifiers, rfile, name, marks):
    from ROOT import TProfile, TPolyMarker
    from numpy import linspace
    from array import array
    rfile = ROOT.TFile.Open(rfile)
    tree = rfile.Get(name)
    sig, bkg = 'classID=={}'.format(0), 'classID=={}'.format(1)
    hists = {}
    marks = {} if marks else None
    for cl in classifiers:
        name = '{}_{}'.format(cl, rfile.GetName().split('/', 1)[0])
        nsig = float(tree.GetEntries(sig))
        nbkg = float(tree.GetEntries(bkg))
        # variable bin width
        bins = array('f',
                     [1.0 / (-i * 0.5 - 1) + 1 for i in xrange(100)] + [1])
        hist = TProfile('h_{}'.format(name), 'ROC curve ({})'.format(cl), 100,
                        bins)
        hist.SetDirectory(0)  # otherwise current file owns histogram
        if isinstance(marks, dict):
            xmark, ymark = array('f'), array('f')
        for i, cut in enumerate(linspace(-1, 1, 1001)):
            cutstr = '{}>{}'.format(cl, cut)
            eff_s = tree.GetEntries('{}&&{}'.format(sig, cutstr)) / nsig
            eff_b = 1 - tree.GetEntries('{}&&{}'.format(bkg, cutstr)) / nbkg
            hist.Fill(eff_s, eff_b)
            if isinstance(marks, dict):
                if cl == 'BDTB':
                    window = -0.3 <= cut and cut <= 0.3
                    step = not i % 10
                else:
                    window = -0.9 <= cut and cut <= 0.9
                    step = not i % 50
                if window and step:
                    xmark.append(eff_s)
                    ymark.append(eff_b)
        hists[cl] = hist
        if isinstance(marks, dict):
            marks[cl] = TPolyMarker(len(xmark), xmark, ymark)
            print '{}: {} marks'.format(cl, len(xmark))
            for pt in zip(xmark, ymark):
                print pt,
            print
    return hists, marks
コード例 #13
0
def pccPerLumiSection(options):
    """Extract PCC data from ROOT files and sort by lumisection"""
    c = chain(options['fileset'], options['scan'])
    rc = reducedChain(options['fileset'], options['scan'])
    name = options['name'] + '_perLS'
    f = openRootFileU(name)
    print '<<< Analyze', options['title']
    histname = plotName(options['title'] + '_perLS', timestamp=False)
    histtitl = plotTitle()
    print '<<< Get Minimum'
    mini = int(rc.GetMinimum('LS'))
    print '<<< Get Maximum'
    maxi = int(rc.GetMaximum('LS'))
    print '<<< Fill Profile Histogram', histname
    hist = TProfile(histname, histtitl, maxi - mini + 1, mini - 0.5,
                    maxi + 0.5)
    c.Draw(options['field'] + ':LS>>' + histname, '', 'goff')
    hist.Write('', TObject.kOverwrite)
    closeRootFile(f, name)
コード例 #14
0
def pccPerTimeStamp(options):
    """Extract PCC data from ROOT files and sort by timestamps"""
    c = chain(options['fileset'], options['scan'])
    rc = chain(options['fileset'], options['scan'])
    name = options['name'] + '_' + options['scan'] + '_perTime'
    f = openRootFileU(options['name'] + '_perTime')
    print '<<< Analyze', options['scan'], options['name']
    histname = plotName(name, timestamp=False)
    histtitl = plotTitle(options['scan'])
    print '<<< Get Minimum'
    mini = int(rc.GetMinimum(O['timename'][options['fileset']]))
    print '<<< Get Maximum'
    maxi = int(rc.GetMaximum(O['timename'][options['fileset']]))
    print '<<< Fill Profile Histogram', histname
    hist = TProfile(histname, histtitl, maxi - mini + 1, mini - 0.5,
                    maxi + 0.5)
    c.Draw(options['field']+':'+O['timename'][options['fileset']]+'>>'+ \
           histname, '', 'goff')
    hist.Write('', TObject.kOverwrite)
    closeRootFile(f, options['name'] + '_perTime')
コード例 #15
0
ファイル: electron_dataset.py プロジェクト: Enucatl/lab-unipd
 def __init__(self, root_file_name):
     self.name = root_file_name
     self.root_file = TFile(root_file_name)
     tree = self.root_file.Get(tree_name)
     self.histograms = []
     for key, value in d.iteritems():
         if value[0] is "TH1D":
             self.histograms.append(TH1D(*value[1]))
         elif value[0] is "TProfile":
             self.histograms.append(TProfile(*value[1]))
     [tree.Project(key, formula[key], cuts[key]) for key in d.iterkeys()]
コード例 #16
0
ファイル: ITScanCore.py プロジェクト: hxc0/test
    def FindAndIntegrateHVIs(self):
        T_Points = self.__members__['__T_POINTS__']
        not_valid = ['PU01_AB']
        for sensor_label in T_Points:
            time_data = T_Points[sensor_label]
            if sensor_label not in not_valid:
                # -> create dynamically TProfile object to keep i_hv vs. T curve            
                const_temps = self.__const_temp_list__(time_data)
                if len(const_temps) == 0:
                    continue
                first = min( map(float, const_temps) )
                last = max( map(float, const_temps) )
                bins = int( ((last-first) + TEMP_BIN_OFFSET) )
                #name = 'IT_' + sensor_label
                name = sensor_label
		title = sensor_label
		#title = 'i_hv vs. T for sensor ' + sensor_label
                prof = TProfile(name, title, bins, first - 1.5, last + 1.5, I_HV_MIN, I_HV_MAX)
                if sensor_label not in self.__members__['__IT_HISTOS__']:
                    self.__members__['__IT_HISTOS__'][sensor_label] = None
                self.__members__['__IT_HISTOS__'][sensor_label] = prof

                # -> for each const temp find and integrate hv current
                hvi_bank = self.__find_hvi_histo__(sensor_label)
                if hvi_bank == None:
                    print ' --> Problem, hvi data not found for sensor: ', sensor_label
                    continue

                #######################################################################
                print ' --> Creating IT plot for sensor: ', sensor_label
                #######################################################################

                # -> first get the pair (const_Temp, delta_t)
                bin_pointer = 1
                time_jump = 0
                for time in sorted(time_data):
                    for temp_pair in time_data[time]:
                        const_T = temp_pair[CONST_TEMP]
                        delta_t = temp_pair[TIME_INTERVAL]
                        time_in_bin = hvi_bank.GetBinCenter(bin_pointer)
                        time_jump = time - time_in_bin
                        bin_pointer += int(time_jump)
                        for time_bin in range(bin_pointer, bin_pointer + delta_t):
                            hvi = hvi_bank.GetBinContent(time_bin)
                            if hvi:
                                self.__members__['__IT_HISTOS__'][sensor_label].Fill(const_T, hvi)
                self.__members__['__IT_HISTOS__'][sensor_label].SetStats(kFALSE)
                self.__members__['__IT_HISTOS__'][sensor_label].SetOption("P")
                self.__members__['__IT_HISTOS__'][sensor_label].SetMarkerSize(0.8)
                self.__members__['__IT_HISTOS__'][sensor_label].GetXaxis().SetTitle('Temperature deg')
                self.__members__['__IT_HISTOS__'][sensor_label].GetXaxis().SetLabelSize(0.03)
                self.__members__['__IT_HISTOS__'][sensor_label].GetYaxis().SetTitle('HV current mA')
                self.__members__['__IT_HISTOS__'][sensor_label].GetYaxis().SetLabelSize(0.03)
コード例 #17
0
  def initialize(self):
    
    basepath = self.getProperty( "Basepath" )
    doJpsiee = self.getProperty( "DoJpisee" )

    sg = self.getStoreGateSvc()
    
    #et_bins  = zee_etbins
    eta_bins = default_etabins
    nvtx_bins.extend(high_nvtx_bins)
    #eta_bins = [0,0.6,0.8,1.15,1.37,1.52,1.81,2.01,2.37,2.47]
    et_bins = jpsiee_etbins if doJpsiee else [4.,7.,10.,15.,20.,25.,30.,35.,40.,45.,50.,60.,80.,150.] 
    
    for group in self.__groups:
      # Get the chain object
      chain = group.chain()
      for dirname in ( self.__triggerLevels if (type(chain) is Chain or type(chain) is TDT) else ['Selector'] ):

        sg.mkdir( basepath+'/'+chain.name()+'/Efficiency/'+dirname )
        sg.addHistogram(TH1F('et','E_{T} distribution;E_{T};Count', len(et_bins)-1, np.array(et_bins)))
        sg.addHistogram(TH1F('eta','#eta distribution;#eta;Count', len(eta_bins)-1, np.array(eta_bins)))
        sg.addHistogram(TH1F("phi", "#phi distribution; #phi ; Count", 20, -3.2, 3.2));
        sg.addHistogram(TH1F('mu' ,'<#mu> distribution;<#mu>;Count', 20, 0, 100))
        sg.addHistogram(TH1F('nvtx' ,'N_{vtx} distribution;N_{vtx};Count', len(nvtx_bins)-1, np.array(nvtx_bins)))
        sg.addHistogram(TH1F('match_et','E_{T} matched distribution;E_{T};Count', len(et_bins)-1, np.array(et_bins)))
        sg.addHistogram(TH1F('match_eta','#eta matched distribution;#eta;Count', len(eta_bins)-1, np.array(eta_bins)))
        sg.addHistogram(TH1F("match_phi", "#phi matched distribution; #phi ; Count", 20, -3.2, 3.2));
        sg.addHistogram(TH1F('match_mu' ,'<#mu> matched distribution;<#mu>;Count', 20, 0, 100))
        sg.addHistogram(TH1F('match_nvtx' ,'N_{vtx} matched distribution;N_{vtx};Count', len(nvtx_bins)-1, np.array(nvtx_bins)))
        sg.addHistogram(TProfile("eff_et", "#epsilon(E_{T}); E_{T} ; Efficiency" , len(et_bins)-1, np.array(et_bins)))
        sg.addHistogram(TProfile("eff_eta", "#epsilon(#eta); #eta ; Efficiency"  , len(eta_bins)-1,np.array(eta_bins)))
        sg.addHistogram(TProfile("eff_phi", "#epsilon(#phi); #phi ; Efficiency", 20, -3.2, 3.2));
        sg.addHistogram(TProfile("eff_mu", "#epsilon(<#mu>); <#mu> ; Efficiency", 20, 0, 100));	
        sg.addHistogram(TProfile("eff_nvtx", "#epsilon(N_{vtx}); N_{vtx} ; Efficiency", len(nvtx_bins)-1, np.array(nvtx_bins)));	
        sg.addHistogram( TH2F('match_etVsEta', "Passed;E_{T};#eta;Count", len(et_bins)-1, np.array(et_bins), len(eta_bins)-1, np.array(eta_bins)) )
        sg.addHistogram( TH2F('etVsEta' , "Total;E_{T};#eta;Count", len(et_bins)-1,  np.array(et_bins), len(eta_bins)-1, np.array(eta_bins)) )
        sg.addHistogram( TProfile2D('eff_etVsEta' , "Total;E_{T};#eta;Count", len(et_bins)-1,  np.array(et_bins), len(eta_bins)-1, np.array(eta_bins)) )

    self.init_lock()
    return StatusCode.SUCCESS 
コード例 #18
0
 def create_residual(data, model, nbins=None, calcphi=None, skipzero=False):
     """Create angular residual histogram."""
     if nbins is None:
         nbins = data.GetXaxis().GetNbins()
     if calcphi is None:
         calcphi = lambda x, y: atan(x / y)
     data.SetBinErrorOption(kPoisson)
     res = TProfile('angularRes', '', nbins, -0.5 * pi, 0.5 * pi)
     for xbin in range(data.GetXaxis().GetNbins()):
         for ybin in range(data.GetYaxis().GetNbins()):
             d = data.GetBinContent(xbin + 1, ybin + 1)
             if skipzero and d == 0.0:
                 continue
             m = model.GetBinContent(xbin + 1, ybin + 1)
             if m < d:
                 e = data.GetBinErrorLow(xbin + 1, ybin + 1)
             else:
                 e = data.GetBinErrorUp(xbin + 1, ybin + 1)
             x = data.GetXaxis().GetBinCenter(xbin + 1)
             y = data.GetYaxis().GetBinCenter(ybin + 1)
             res.Fill(calcphi(x, y), (d - m) / e)
     return res
コード例 #19
0
def plotting_init(data, trainvar, histo_dict, masses, weights='totalWeight'):
    """ Initializes the plotting

    Parameters:
    -----------
    data : pandas DataFrame
        Data to be used for creating the TProfiles
    trainvar : str
        Name of the training variable.
    histo_dict : dict
        Dictionary containing the info for plotting for a given trainvar
    masses : list
        List of masses to be used
    [weights='totalWeight'] : str
        What column to be used for weight in the data.

    Returns:
    --------
    canvas : ROOT.TCanvas instance
        canvas to be plotted on
    profile : ROOT.TProfile instance
        profile for the fitting
    """
    canvas = TCanvas('canvas', 'TProfile plot', 200, 10, 700, 500)
    canvas.GetFrame().SetBorderSize(6)
    canvas.GetFrame().SetBorderMode(-1)
    signal_data = data.loc[data['target'] == 1]
    gen_mHH_values = np.array(signal_data['gen_mHH'].values, dtype=np.float)
    trainvar_values = np.array(signal_data[trainvar].values, dtype=np.float)
    weights = np.array(signal_data[weights].values, dtype=np.float)
    sanity_check = len(gen_mHH_values) == len(trainvar_values) == len(weights)
    assert sanity_check
    title = 'Profile of ' + str(trainvar) + ' vs gen_mHH'
    num_bins = (len(masses) - 1)
    xlow = masses[0]
    xhigh = (masses[(len(masses) - 1)] + 100.0)
    ylow = histo_dict["min"]
    yhigh = histo_dict["max"]
    profile = TProfile('profile', title, num_bins, xlow, xhigh, ylow, yhigh)
    mass_bins = np.array(masses, dtype=float)
    profile.SetBins((len(mass_bins) - 1), mass_bins)
    profile.GetXaxis().SetTitle("gen_mHH (GeV)")
    profile.GetYaxis().SetTitle(str(trainvar))
    for x, y, w in zip(gen_mHH_values, trainvar_values, weights):
        profile.Fill(x, y, w)
    profile.Draw()
    canvas.Modified()
    canvas.Update()
    return canvas, profile
コード例 #20
0
ファイル: ROOTUtils.py プロジェクト: PhysTom88/JetRes
def createProfile(t_corrList, t_select, l_histoList, nBins, dBins):

    d_profileBin = {}
    h_str, tFile, c_x, c_y, xMin, xMax, yMin, yMax, varBins = l_histoList
    PythonUtils.Info('       CREATING PROFILES: ' + h_str + '           ')
    for bin in t_select:
        PythonUtils.Info('Creating Profiles: ' + h_str + ' in bin: ' + bin[0] +
                         ' -> ' + bin[1])
        d_profile = {}
        for i in range(len(t_corrList)):
            dName = h_str + '_' + bin[0] + '_' + bin[1] + '_' + t_corrList[i][0]
            d_profile[dName] = TProfile(dName, dName, int(nBins), dBins,
                                        float(yMin), float(yMax))

        d_profileBin[bin[0] + bin[1]] = d_profile

    return d_profileBin
コード例 #21
0
ファイル: tests.py プロジェクト: kratsg/root_numpy_dev
def test_fill_profile():
    np.random.seed(0)
    w1D = np.empty(1E6)
    w1D.fill(2.)
    data1D = np.random.randn(1E6, 2)
    data2D = np.random.randn(1E6, 3)
    data3D = np.random.randn(1E4, 4)

    a = TProfile('th1d', 'test', 1000, -5, 5)
    rnp.fill_profile(a, data1D)
    assert_true(a.Integral() !=0)

    a_w = TProfile('th1dw', 'test', 1000, -5, 5)
    rnp.fill_profile(a_w, data1D, w1D)
    assert_true(a_w.Integral() != 0)
    assert_equal(a_w.Integral(), a.Integral())

    b = TProfile2D('th2d', 'test', 100, -5, 5, 100, -5, 5)
    rnp.fill_profile(b, data2D)
    assert_true(b.Integral() != 0)

    c = TProfile3D('th3d', 'test', 10, -5, 5, 10, -5, 5, 10, -5, 5)
    rnp.fill_profile(c, data3D)
    assert_true(c.Integral() != 0)

    # array and weights lengths do not match
    assert_raises(ValueError, rnp.fill_profile, c, data3D, np.ones(10))

    # weights is not 1D
    assert_raises(ValueError, rnp.fill_profile, c, data3D,
                  np.ones((data3D.shape[0], 1)))

    # array is not 2D
    assert_raises(ValueError, rnp.fill_profile, c, np.ones(10))

    # length of second axis is not one more than dimensionality of the profile
    for h in (a, b, c):
        assert_raises(ValueError, rnp.fill_profile, h, np.random.randn(1E4, 5))

    # wrong type
    assert_raises(TypeError, rnp.fill_profile,
                  TH1D("test", "test", 1, 0, 1), data1D)
コード例 #22
0
ファイル: dqmjson.py プロジェクト: jfpatrick/HistoricDQM
def dqm_getSingleHist_json(server, run, dataset, hist, rootContent=False):
    postfix = "?rootcontent=1" if rootContent else ""
    datareq = urllib2.Request(('%s/jsonfairy/archive/%s/%s/%s%s') % (server, run, dataset, hist, postfix))
    datareq.add_header('User-agent', ident)
    # Get data
    data = eval(re.sub(r"\bnan\b", "0", urllib2.build_opener(X509CertOpen()).open(datareq).read()),
               { "__builtins__": None }, {})
    histo = data['hist']
    # Now convert into real ROOT histogram object
    if 'TH1' in histo['type']:
        # The following assumes a TH1F object
        contents = histo['bins']['content']
        nbins = len(contents)
        xmin = histo['xaxis']['first']['value']
        xmax = histo['xaxis']['last']['value']
        roothist = TH1F(histo['stats']['name'],histo['title'],nbins,xmin,xmax)
        for xx in range(1,nbins+1):
            roothist.SetBinContent(xx, contents[xx-1])
            roothist.SetBinError(xx, histo['bins']['error'][xx-1])
        roothist.SetEntries(histo['stats']['entries']) 
        stats=array('d')
        stats.append(histo['stats']['entries'])
        stats.append(histo['stats']['entries'])
        stats.append(histo['stats']['entries']*histo['stats']['mean']['X']['value'])
        stats.append((histo['stats']['rms']['X']['value']*histo['stats']['rms']['X']['value']+histo['stats']['mean']['X']['value']*histo['stats']['mean']['X']['value'])*histo['stats']['entries'])
        roothist.PutStats(stats)
    elif(histo['type']=='TProfile'):
        contents = histo['bins']['content']
        nbins = len(contents)
        xmin = histo['xaxis']['first']['value']
        xmax = histo['xaxis']['last']['value']
        roothist = TProfile(histo['stats']['name'],histo['title'],nbins,xmin,xmax)
        roothist.SetErrorOption("g")
        for xx in range(0,nbins):
            if(histo['bins']['error'][xx]!=0):
                ww=1./(histo['bins']['error'][xx]*histo['bins']['error'][xx])
            else:
                ww=0.
            roothist.Fill(xmin+(2*xx+1)*((xmax-xmin)/(nbins*2.0)), contents[xx],ww)
#            roothist.SetBinContent(xx, contents[xx-1])
#            roothist.SetBinError(xx, histo['bins']['error'][xx-1])
        roothist.SetEntries(histo['stats']['entries']) 
        stats=array('d')
        for i in range(0,6):
            stats.append(i)
        roothist.GetStats(stats)
        stats[0]=(histo['stats']['entries'])
        stats[1]=(histo['stats']['entries'])
        stats[2]=(histo['stats']['entries']*histo['stats']['mean']['X']['value'])
        stats[3]=((histo['stats']['rms']['X']['value']*histo['stats']['rms']['X']['value']+histo['stats']['mean']['X']['value']*histo['stats']['mean']['X']['value'])*histo['stats']['entries'])
        roothist.PutStats(stats)
    elif 'TH2' in histo['type']:
        contents = histo['bins']['content']
        nbinsx = histo['xaxis']['last']['id']
        xmin = histo['xaxis']['first']['value']
        xmax = histo['xaxis']['last']['value']
        nbinsy = histo['yaxis']['last']['id']
        ymin = histo['yaxis']['first']['value']
        ymax = histo['yaxis']['last']['value']
        roothist = TH2F(histo['stats']['name'],histo['title'],nbinsx,xmin,xmax,nbinsy,ymin,ymax)
        for xx in range(1,nbinsx+1):
            for yy in range(1,nbinsy+1):
                roothist.SetBinContent(xx,yy, contents[yy-1][xx-1])
        roothist.SetEntries(histo['stats']['entries']) 
        stats=array('d')
        stats.append(histo['stats']['entries'])
        stats.append(histo['stats']['entries'])
        stats.append(histo['stats']['entries']*histo['stats']['mean']['X']['value'])
        stats.append((histo['stats']['rms']['X']['value']*histo['stats']['rms']['X']['value']+histo['stats']['mean']['X']['value']*histo['stats']['mean']['X']['value'])*histo['stats']['entries'])
        stats.append(histo['stats']['entries']*histo['stats']['mean']['Y']['value'])
        stats.append((histo['stats']['rms']['Y']['value']*histo['stats']['rms']['Y']['value']+histo['stats']['mean']['Y']['value']*histo['stats']['mean']['Y']['value'])*histo['stats']['entries'])
        roothist.PutStats(stats)

    elif(histo['type']=='TProfile2D'):
        contents = histo['bins']['content']
        nbinsx = histo['xaxis']['last']['id']
        xmin = histo['xaxis']['first']['value']
        xmax = histo['xaxis']['last']['value']
        nbinsy = histo['yaxis']['last']['id']
        ymin = histo['yaxis']['first']['value']
        ymax = histo['yaxis']['last']['value']
        roothist = TProfile2D(histo['stats']['name'],histo['title'],nbinsx,xmin,xmax,nbinsy,ymin,ymax)
        for xx in range(0,nbinsx):
            for yy in range(0,nbinsy):
                roothist.Fill(xmin+(2*xx+1)*((xmax-xmin)/(nbinsx*2.0)),ymin+(2*yy+1)*((ymax-ymin)/(nbinsy*2.0)),0,1)
        for xx in range(1,nbinsx+1):
            for yy in range(1,nbinsy+1):
                roothist.SetBinContent(xx,yy, contents[yy-1][xx-1])
                roothist.SetEntries(histo['stats']['entries']) 

    return roothist
コード例 #23
0
def generator(nuslice_tree, rootfile, pset):
    n_bins = pset.n_bins
    drift_distance = pset.DriftDistance
    bin_width = drift_distance/n_bins
    half_bin_width = bin_width/2.

    xvals = np.arange(half_bin_width, drift_distance, bin_width)
    xerrs = np.array([half_bin_width] * len(xvals))
    dist_to_anode_bins = n_bins
    dist_to_anode_low = 0.
    dist_to_anode_up = drift_distance
    profile_bins = n_bins
    profile_option = 's'  # errors are the standard deviation

    dy_spreads = [None] * n_bins
    dy_means = [None] * n_bins
    dy_hist = TH2D("dy_hist", "#Delta y",
                   dist_to_anode_bins, dist_to_anode_low, dist_to_anode_up,
                   pset.dy_bins, pset.dy_low, pset.dy_up)
    dy_hist.GetXaxis().SetTitle("distance from anode (cm)")
    dy_hist.GetYaxis().SetTitle("y_flash - y_TPC (cm)")
    dy_prof = TProfile("dy_prof", "Profile of dy_spreads in #Delta y",
                       profile_bins, dist_to_anode_low, dist_to_anode_up,
                       pset.dy_low*2, pset.dy_up*2, profile_option)
    dy_prof.GetXaxis().SetTitle("distance from anode (cm)")
    dy_prof.GetYaxis().SetTitle("y_flash - y_TPC (cm)")
    dy_h1 = TH1D("dy_h1", "",
                 profile_bins, dist_to_anode_low, dist_to_anode_up)
    dy_h1.GetXaxis().SetTitle("distance from anode (cm)")
    dy_h1.GetYaxis().SetTitle("y_flash - y_TPC (cm)")

    dz_spreads = [None] * n_bins
    dz_means = [None] * n_bins
    dz_hist = TH2D("dz_hist", "#Delta z",
                   dist_to_anode_bins, dist_to_anode_low, dist_to_anode_up,
                   pset.dz_bins, pset.dz_low, pset.dz_up)
    dz_hist.GetXaxis().SetTitle("distance from anode (cm)")
    dz_hist.GetYaxis().SetTitle("z_flash - z_TPC (cm)")
    dz_prof = TProfile("dz_prof", "Profile of dz_spreads in #Delta z",
                       profile_bins, dist_to_anode_low, dist_to_anode_up,
                       pset.dz_low*2.5, pset.dz_up*2.5, profile_option)
    dz_prof.GetXaxis().SetTitle("distance from anode (cm)")
    dz_prof.GetYaxis().SetTitle("z_flash - z_TPC (cm)")
    dz_h1 = TH1D("dz_h1", "",
                 profile_bins, dist_to_anode_low, dist_to_anode_up)
    dz_h1.GetXaxis().SetTitle("distance from anode (cm)")
    dz_h1.GetYaxis().SetTitle("z_flash - z_TPC (cm)")

    rr_spreads = [None] * n_bins
    rr_means = [None] * n_bins
    rr_hist = TH2D("rr_hist", "PE Spread",
                   dist_to_anode_bins, dist_to_anode_low, dist_to_anode_up,
                   pset.rr_bins, pset.rr_low, pset.rr_up)
    rr_hist.GetXaxis().SetTitle("distance from anode (cm)")
    rr_hist.GetYaxis().SetTitle("RMS flash (cm)")
    rr_prof = TProfile("rr_prof", "Profile of PE Spread",
                       profile_bins, dist_to_anode_low, dist_to_anode_up,
                       pset.rr_low, pset.rr_up, profile_option)
    rr_prof.GetXaxis().SetTitle("distance from anode (cm)")
    rr_prof.GetYaxis().SetTitle("RMS flash (cm)")
    rr_h1 = TH1D("rr_h1", "",
                 profile_bins, dist_to_anode_low, dist_to_anode_up)
    rr_h1.GetXaxis().SetTitle("distance from anode (cm)")
    rr_h1.GetYaxis().SetTitle("RMS flash (cm)")

    if detector == "sbnd":
        pe_spreads = [None] * n_bins
        pe_means = [None] * n_bins
        pe_hist = TH2D("pe_hist", "Uncoated/Coated Ratio",
                       dist_to_anode_bins, dist_to_anode_low, dist_to_anode_up,
                       pset.pe_bins, pset.pe_low, pset.pe_up)
        pe_hist.GetXaxis().SetTitle("distance from anode (cm)")
        pe_hist.GetYaxis().SetTitle("ratio_{uncoated/coated}")
        pe_prof = TProfile("pe_prof", "Profile of Uncoated/Coated Ratio",
                           profile_bins, dist_to_anode_low, dist_to_anode_up,
                           pset.pe_low, pset.pe_up, profile_option)
        pe_prof.GetXaxis().SetTitle("distance from anode (cm)")
        pe_prof.GetYaxis().SetTitle("ratio_{uncoated/coated}")
        pe_h1 = TH1D("pe_h1", "",
                     profile_bins, dist_to_anode_low, dist_to_anode_up)
        pe_h1.GetXaxis().SetTitle("distance from anode (cm)")
        pe_h1.GetYaxis().SetTitle("ratio_{uncoated/coated}")

    match_score_scatter = TH2D("match_score_scatter", "Scatter plot of match scores",
                               dist_to_anode_bins, dist_to_anode_low, dist_to_anode_up,
                               pset.score_hist_bins, pset.score_hist_low, pset.score_hist_up*(3./5.))
    match_score_scatter.GetXaxis().SetTitle("distance from anode (cm)")
    match_score_scatter.GetYaxis().SetTitle("match score (arbitrary)")
    match_score_hist = TH1D("match_score", "Match Score",
                            pset.score_hist_bins, pset.score_hist_low, pset.score_hist_up)
    match_score_hist.GetXaxis().SetTitle("match score (arbitrary)")

    for e in nuslice_tree:
        slice = e.charge_x

        dy_hist.Fill(slice, e.flash_y - e.charge_y)
        dy_prof.Fill(slice, e.flash_y - e.charge_y)
        dz_hist.Fill(slice, e.flash_z - e.charge_z)
        dz_prof.Fill(slice, e.flash_z - e.charge_z)
        rr_hist.Fill(slice, e.flash_r)
        rr_prof.Fill(slice, e.flash_r)
        if detector == "sbnd":
            pe_hist.Fill(slice, e.flash_ratio)
            pe_prof.Fill(slice, e.flash_ratio)

    # fill histograms for match score calculation from profile histograms
    for ib in list(range(0, profile_bins)):
        ibp = ib + 1
        dy_h1.SetBinContent(ibp, dy_prof.GetBinContent(ibp))
        dy_h1.SetBinError(ibp, dy_prof.GetBinError(ibp))
        dy_means[int(ib)] = dy_prof.GetBinContent(ibp)
        dy_spreads[int(ib)] = dy_prof.GetBinError(ibp)
        dz_h1.SetBinContent(ibp, dz_prof.GetBinContent(ibp))
        dz_h1.SetBinError(ibp, dz_prof.GetBinError(ibp))
        dz_means[int(ib)] = dz_prof.GetBinContent(ibp)
        dz_spreads[int(ib)] = dz_prof.GetBinError(ibp)
        rr_h1.SetBinContent(ibp, rr_prof.GetBinContent(ibp))
        rr_h1.SetBinError(ibp, rr_prof.GetBinError(ibp))
        rr_means[int(ib)] = rr_prof.GetBinContent(ibp)
        rr_spreads[int(ib)] = rr_prof.GetBinError(ibp)
        if detector == "sbnd":
            pe_h1.SetBinContent(ibp, pe_prof.GetBinContent(ibp))
            pe_h1.SetBinError(ibp, pe_prof.GetBinError(ibp))
            pe_means[int(ib)] = pe_prof.GetBinContent(ibp)
            pe_spreads[int(ib)] = pe_prof.GetBinError(ibp)

    for e in nuslice_tree:
        slice = e.charge_x
        # calculate match score
        isl = int(slice/bin_width)
        score = 0.
        if dy_spreads[isl] <= 1.e-8:
            print("Warning zero spread.\n",
                  f"slice: {slice}. isl: {isl}. dy_spreads[isl]: {dy_spreads[isl]} ")
            dy_spreads[isl] = dy_spreads[isl+1]
        if dz_spreads[isl] <= 1.e-8:
            print("Warning zero spread.\n",
                  f"slice: {slice}. isl: {isl}. dz_spreads[isl]: {dz_spreads[isl]} ")
            dz_spreads[isl] = dz_spreads[isl+1]
        if rr_spreads[isl] <= 1.e-8:
            print("Warning zero spread.\n",
                  f"slice: {slice}. isl: {isl}. rr_spreads[isl]: {rr_spreads[isl]} ")
            rr_spreads[isl] = rr_spreads[isl+1]
        if detector == "sbnd" and pe_spreads[isl] <= 1.e-8:
            print("Warning zero spread.\n",
                  f"slice: {slice}. isl: {isl}. pe_spreads[isl]: {pe_spreads[isl]} ")
            pe_spreads[isl] = pe_spreads[isl+1]
        score += abs(abs(e.flash_y-e.charge_y) - dy_means[isl])/dy_spreads[isl]
        score += abs(abs(e.flash_z-e.charge_z) - dz_means[isl])/dz_spreads[isl]
        score += abs(e.flash_r-rr_means[isl])/rr_spreads[isl]
        if detector == "sbnd" and pset.UseUncoatedPMT:
            score += abs(e.flash_ratio-pe_means[isl])/pe_spreads[isl]
        match_score_scatter.Fill(slice, score)
        match_score_hist.Fill(score)
    metrics_filename = 'fm_metrics_' + detector + '.root'
    hfile = gROOT.FindObject(metrics_filename)
    if hfile:
        hfile.Close()
    hfile = TFile(metrics_filename, 'RECREATE',
                  'Simple flash matching metrics for ' + detector.upper())
    dy_hist.Write()
    dy_prof.Write()
    dy_h1.Write()
    dz_hist.Write()
    dz_prof.Write()
    dz_h1.Write()
    rr_hist.Write()
    rr_prof.Write()
    rr_h1.Write()
    if detector == "sbnd":
        pe_hist.Write()
        pe_prof.Write()
        pe_h1.Write()
    match_score_scatter.Write()
    match_score_hist.Write()
    hfile.Close()

    canv = TCanvas("canv")

    dy_hist.Draw()
    crosses = TGraphErrors(n_bins,
                           array('f', xvals), array('f', dy_means),
                           array('f', xerrs), array('f', dy_spreads))
    crosses.SetLineColor(9)
    crosses.SetLineWidth(3)
    crosses.Draw("Psame")
    canv.Print("dy.pdf")
    canv.Update()

    dz_hist.Draw()
    crosses = TGraphErrors(n_bins,
                           array('f', xvals), array('f', dz_means),
                           array('f', xerrs), array('f', dz_spreads))
    crosses.SetLineColor(9)
    crosses.SetLineWidth(3)
    crosses.Draw("Psame")
    canv.Print("dz.pdf")
    canv.Update()

    rr_hist.Draw()
    crosses = TGraphErrors(n_bins,
                           array('f', xvals), array('f', rr_means),
                           array('f', xerrs), array('f', rr_spreads))
    crosses.SetLineColor(9)
    crosses.SetLineWidth(3)
    crosses.Draw("Psame")
    canv.Print("rr.pdf")
    canv.Update()

    if detector == "sbnd":
        pe_hist.Draw()
        crosses = TGraphErrors(n_bins,
                               array('f', xvals), array('f', pe_means),
                               array('f', xerrs), array('f', pe_spreads))
        crosses.SetLineColor(9)
        crosses.SetLineWidth(3)
        crosses.Draw("Psame")
        canv.Print("pe.pdf")
        canv.Update()

    match_score_scatter.Draw()
    canv.Print("match_score_scatter.pdf")
    canv.Update()

    match_score_hist.Draw()
    canv.Print("match_score.pdf")
    canv.Update()
    sleep(20)
コード例 #24
0
def plotPulls(optunf="Bayes",
              ntest=10,
              leff=True,
              loufl=False,
              optfun="exp",
              opttfun="",
              gmean=-1.0,
              nrebin=4):

    if opttfun == "":
        opttfun = optfun

    if optfun == "blobel":
        gmean = 0.0

    funttxt, funtxt = funtxts(opttfun, optfun, leff, loufl)

    global histos, canv, canv2
    histos = []

    canv = TCanvas("canv", "thruth vs reco pulls", 600, 800)
    canv.Divide(1, 3)
    canv2 = TCanvas("canv2", "P(chi^2)", 600, 800)
    canv2.Divide(2, 3)

    if optunf == "BasisSplines":
        bininfo = BinInfo(nrebin)
        unfoldtester = UnfoldTester(optunf, nrebin)
    else:
        bininfo = BinInfo()
        unfoldtester = UnfoldTester(optunf)
    trainer = Trainer(bininfo, opttfun, optfun)
    tester = Tester(bininfo, optfun)
    hbininfo = bininfo.create(optfun)
    dx = hbininfo["mhi"]
    for sigma, ipad in [[0.01 * dx, 1], [0.03 * dx, 2], [0.1 * dx, 3]]:
        txt = optunf + ", smear mu, s.d.= " + str(gmean) + ", " + str(
            sigma) + ", train: " + funttxt + ", test: " + funtxt + ", " + str(
                ntest) + " tests"
        hPulls = TProfile("pulls", txt, hbininfo["tbins"], hbininfo["tlo"],
                          hbininfo["thi"])
        hPulls.SetErrorOption("s")
        hPulls.SetYTitle("Thruth reco pull")
        histos.append(hPulls)
        hChisq = TH1D("chisq", "P(chi^2) rec " + txt, 10, 0.0, 1.0)
        hChisqm = TH1D("chisqm", "P(chi^2) mea " + txt, 10, 0.0, 1.0)
        histos.append(hChisq)
        histos.append(hChisqm)
        measurement = createMeasurement(gmean, sigma, leff, optfun)
        response = trainer.train(measurement, loufl=loufl)
        for itest in range(ntest):
            print "Test", itest
            unfold, hTrue, hMeas = unfoldtester.rununfoldtest(
                tester, measurement, response)
            unfold.PrintTable(cout, hTrue, 2)
            hReco = unfold.Hreco(2)
            nbin = hReco.GetNbinsX()
            if hbininfo["nrebin"] > 1:
                hTrue = hTrue.Rebin(nrebin)
            for ibin in range(nbin + 1):
                truevalue = hTrue.GetBinContent(ibin)
                recvalue = hReco.GetBinContent(ibin)
                error = hReco.GetBinError(ibin)
                if error > 0.0:
                    pull = (recvalue - truevalue) / error
                    hPulls.Fill(hReco.GetBinCenter(ibin), pull)
            chisq = unfold.Chi2(hTrue, 2)
            hChisq.Fill(TMath.Prob(chisq, hTrue.GetNbinsX()))
            chisqm = unfold.Chi2measured()
            pchisqm = TMath.Prob(chisqm, hMeas.GetNbinsX() - hReco.GetNbinsX())
            print "Chisq measured=", chisqm, "P(chi^2)=", pchisqm
            hChisqm.Fill(pchisqm)

        canv.cd(ipad)
        gStyle.SetErrorX(0)
        hPulls.SetMinimum(-3.0)
        hPulls.SetMaximum(3.0)
        hPulls.SetMarkerSize(1.0)
        hPulls.SetMarkerStyle(20)
        hPulls.SetStats(False)
        hPulls.Draw()
        canv2.cd(ipad * 2 - 1)
        hChisq.Draw()
        canv2.cd(ipad * 2)
        hChisqm.Draw()

    fname = "RooUnfoldTestPulls_" + optunf + "_" + opttfun + "_" + optfun
    if loufl:
        fname += "_oufl"
    canv.Print(fname + ".pdf")
    fname = "RooUnfoldTestChisq_" + optunf + "_" + opttfun + "_" + optfun
    if loufl:
        fname += "_oufl"
    canv2.Print(fname + ".pdf")

    return
コード例 #25
0
    diffProf = []
    inHists = []
    inProf = []

    for itarg in range(target.shape[1]):
        hist = TH1F('diff{}'.format(itarg),
                    'T_{{{0}}}-O_{{{0}}}'.format(itarg),
                    100,meanDiff[itarg]-3*stdDiff[itarg],meanDiff[itarg]+3*stdDiff[itarg])
        diffHists.append(hist)
        hist = TH2F('vs{}'.format(itarg),
                    'O_{{{0}}} vs T_{{{0}}}'.format(itarg),
                    400,minTarget[itarg],maxTarget[itarg],
                    400,minOutput[itarg],maxOutput[itarg])
        vsHists.append(hist)
        hist = TProfile('prof{}'.format(itarg),
                    'Prof(O_{{{0}}}) vs T_{{{0}}}'.format(itarg),
                    400,minTarget[itarg],maxTarget[itarg])
        diffProf.append(hist)
        hist = TH2F('input{}'.format(itarg),
                    'O_{{{0}}} vs I_{{{0}}}'.format(itarg),
                    400,minInput[itarg],maxInput[itarg],
                    400,minOutput[itarg],maxOutput[itarg])
        inHists.append(hist)
        hist = TProfile('inProf{}'.format(itarg),
                        'Prof(O_{{{0}}}) vs I_{{{0}}}'.format(itarg),
                        400,minInput[itarg],maxInput[itarg])
        inProf.append(hist)
   
    # Filling the old fashioned way...
    for irow in range(diff.shape[0]):
        for ivar in range(diff.shape[1]):
コード例 #26
0
#!/usr/bin/env python
# coding: utf-8
# In[1]:
from ROOT import TCanvas, TFile, TProfile, TNtuple, TH1F, TH2F
from ROOT import gROOT, gBenchmark, gRandom, gSystem
from array import array
# In[2]:
hfile = gROOT.FindObject('py-hsimple.root')
if hfile:
    hfile.Close()
hfile = TFile('py-hsimple.root', 'RECREATE', 'Demo ROOT file with histograms')
# In[3]:
hpx = TH1F('hpx', 'This is the px distribution', 100, -4, 4)
hpxpy = TH2F('hpxpy', 'py vs px', 40, -4, 4, 40, -4, 4)
hprof = TProfile('hprof', 'Profile of pz versus px', 100, -4, 4, 0, 20)
ntuple = TNtuple('ntuple', 'Demo ntuple', 'px:py:pz:random:i')
# In[ ]:
# In[4]:
gRandom.SetSeed()
rannor, rndm = gRandom.Rannor, gRandom.Rndm
# In[5]:
_px = array('d', [0])
_py = array('d', [0])

for i in range(25000):
    # Generate random values.
    rannor(_px, _py)
    px, py = _px[0], _py[0]
    pz = px * px + py * py
    random = rndm(1)
    # Fill histograms.
コード例 #27
0
ファイル: picca_Pk1D.py プロジェクト: philippedavid/picca
        # control histograms
        if (args.forest_type == 'Lya'):
            forest_inf = 1040.
            forest_sup = 1200.
        elif (args.forest_type == 'SiIV'):
            forest_inf = 1270.
            forest_sup = 1380.
        elif (args.forest_type == 'CIV'):
            forest_inf = 1410.
            forest_sup = 1520.
        hdelta = TProfile2D('hdelta',
                            'delta mean as a function of lambda-lambdaRF', 36,
                            3600., 7200., 16, forest_inf, forest_sup, -5.0,
                            5.0)
        hdelta_RF = TProfile('hdelta_RF',
                             'delta mean as a function of lambdaRF', 320,
                             forest_inf, forest_sup, -5.0, 5.0)
        hdelta_OBS = TProfile('hdelta_OBS',
                              'delta mean as a function of lambdaOBS', 1800,
                              3600., 7200., -5.0, 5.0)
        hdelta_RF_we = TProfile(
            'hdelta_RF_we', 'delta mean weighted as a function of lambdaRF',
            320, forest_inf, forest_sup, -5.0, 5.0)
        hdelta_OBS_we = TProfile(
            'hdelta_OBS_we', 'delta mean weighted as a function of lambdaOBS',
            1800, 3600., 7200., -5.0, 5.0)
        hivar = TH1D('hivar', '  ivar ', 10000, 0.0, 10000.)
        hsnr = TH1D('hsnr', '  snr per pixel ', 100, 0.0, 100.)
        hdelta_RF_we.Sumw2()
        hdelta_OBS_we.Sumw2()
コード例 #28
0
ファイル: hsimple.py プロジェクト: govoni/learn
c1.GetFrame().SetBorderMode(-1)

# Create a new ROOT binary machine independent file.
# Note that this file may contain any kind of ROOT objects, histograms,
# pictures, graphics objects, detector geometries, tracks, events, etc..
# This file is now becoming the current directory.

hfile = gROOT.FindObject('hsimple.root')
if hfile:
    hfile.Close()
hfile = TFile('hsimple.root', 'RECREATE', 'Demo ROOT file with histograms')

# Create some histograms, a profile histogram and an ntuple
hpx = TH1F('hpx', 'This is the px distribution', 100, -4, 4)
hpxpy = TH2F('hpxpy', 'py vs px', 40, -4, 4, 40, -4, 4)
hprof = TProfile('hprof', 'Profile of pz versus px', 100, -4, 4, 0, 20)
ntuple = TNtuple('ntuple', 'Demo ntuple', 'px:py:pz:random:i')

# Set canvas/frame attributes.
hpx.SetFillColor(48)

gBenchmark.Start('hsimple')

# Initialize random number generator.
gRandom.SetSeed()
gauss, rndm = gRandom.Gaus, gRandom.Rndm

# For speed, bind and cache the Fill member functions,
histos = ['hpx', 'hpxpy', 'hprof', 'ntuple']
for name in histos:
    exec '%sFill = %s.Fill' % (name, name)
コード例 #29
0
data_chain = TChain('events')
data_list = open(args.inFile, 'r')
data_files = data_list.readlines()
for i in data_files:
    data_chain.Add(i.strip())

outfile = TFile(args.outFile, "recreate")

# Book histos
# we want to make 15 pt bins covering the range 20 - 500 (spacing of 480/15 = 32 GeV)
n_bins = 99
x_low = 5
x_high = 500

pt_prof = TProfile("ptprof", "profile of deltapt versus pt", n_bins, x_low,
                   x_high, 0, 1)
tau32_prof = TProfile("tau32prof", "profile of tau32 vs. jet pt", n_bins,
                      x_low, x_high, 0, 1)
tau31_prof = TProfile("tau31prof", "profile of tau31 vs. jet pt", n_bins,
                      x_low, x_high, 0, 1)
tau21_prof = TProfile("tau21prof", "profile of tau21 vs. jet pt", n_bins,
                      x_low, x_high, 0, 1)

nevts = data_chain.GetEntries()
for i in range(nevts):
    data_chain.GetEntry(i)

    hlt_n_jets = data_chain.jet_num
    fj_n_jets = data_chain.fj_jet_num

    n_jets = min(hlt_n_jets, fj_n_jets)
コード例 #30
0
#create branch addresses for reading data off of root files
pchannel, sample0, sample1, sample2, sample3, sample4, sample5 = (array(
    'd', [0]), ) * 7
nbytes = 0

#create list of TProfiles
prof0 = [None] * len(fn)
prof1 = [None] * len(fn)
prof2 = [None] * len(fn)
prof3 = [None] * len(fn)
prof4 = [None] * len(fn)
prof5 = [None] * len(fn)

for i in range(len(fn)):
    prof0[i] = TProfile("hprof0_" + str(i), "sample0", 640, 0, 640, 3500, 7000,
                        "s")
    prof1[i] = TProfile("hprof1_" + str(i), "sample1", 640, 0, 640, 3500, 7000,
                        "s")
    prof2[i] = TProfile("hprof2_" + str(i), "sample2", 640, 0, 640, 3500, 7000,
                        "s")
    prof3[i] = TProfile("hprof3_" + str(i), "sample3", 640, 0, 640, 3500, 7000,
                        "s")
    prof4[i] = TProfile("hprof4_" + str(i), "sample4", 640, 0, 640, 3500, 7000,
                        "s")
    prof5[i] = TProfile("hprof5_" + str(i), "sample5", 640, 0, 640, 3500, 7000,
                        "s")

#create list of error histograms for normalization
hsig0 = [None] * len(fn)
hsig1 = [None] * len(fn)
hsig2 = [None] * len(fn)