Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:46

0001 from __future__ import print_function
0002 import json
0003 import ROOT
0004 from pprint import pprint
0005 from optparse import OptionParser
0006 
0007 
0008 parser = OptionParser()
0009 parser.add_option("-f", "--file", dest="filename",
0010                   help="open FILE and extract info", metavar="FILE")
0011 parser.add_option("-q", "--quiet",
0012                   action="store_false", dest="verbose", default=False,
0013                   help="don't print status messages to stdout")
0014 
0015 (options, args) = parser.parse_args()
0016 
0017 with open(options.filename) as data_file:    
0018     data = json.load(data_file)
0019     values = data["data"]
0020     annotations = data["annotations"]
0021     title   = annotations["title"]
0022     x_label = annotations["x_label"]
0023     y_label = annotations["y_label"]
0024 
0025 if(options.verbose):
0026     pprint(values)
0027 
0028 bins=len(values)
0029 print("n. of bins",bins)
0030 histo=ROOT.TH1F("histo",title+";"+x_label+";"+y_label,bins,values[0]['x'],values[bins-1]['x'])
0031 for i,value in enumerate(values):
0032     histo.SetBinContent(i+1,value['y'])
0033 
0034 histo.SetLineColor(ROOT.kBlue)
0035 canv=ROOT.TCanvas("c1","c1",800,800)
0036 canv.cd()
0037 histo.Draw()
0038 canv.SaveAs(options.filename.replace(".json",".png"))
0039 
0040