Exemple #1
0
 def __init__(self,m_cfg_parser):
     """Initialize the inherited class and pass the config parser object around"""
     DataMCPlotter.__init__(self,m_cfg_parser)
     
     # initialize some variables that the user can modify
     self.p_cfg_name  = 'configuration'
     self._leading    = False
     self.alpha       = 0.5
     self.hist_type   = 'stepfilled'
     self.leg_labels  = {'ttbar_inclu':r't$\bar{\text{t}}$',\
                         'TTS_M1000':r'T$\bar{\text{T}}$S (1000)'}
     self.colors      = ''           # scatter / errorbar plots (str or [str1,str2])
     self.format      = 'png'
     self.dpi         = 300
     self.y_label     = ''           # efficiency: r'$\epsilon$'
     self.x_label     = ''
     self.y_err       = False
     self.x_err       = False
     self.maxpred     = 0.           # maximum prediction to scale the y-axis
     self.capsize     = 0
     self.plt_cmap    = ''           # colormap for histogram
     self.lumi        = info.LUMI()  # define luminosity (user can set different one)
     self.plt_marker  = 'o'
     self.plt_size    = 20
     self.edgecolor   = 'none'
     self.h_rebin     = 50           # for ROOT histograms, rebin using this parameter
     self.obj2ttree   = info.obj2ttree()
     self.key2attr    = info.key2attr()
     self.add_labels  = {}
Exemple #2
0
    def main(self,parser):
        """
        Main function in the datamc class -- does all the directing for
        reading/writing of data from ROOT to json files, and plotting histograms.
        """
        ## -- Configuration -- ##
        self.p_vars_file    = parser.get('datamc','vars')                   # ex. share/varNames.txt
        self.p_jsonoutput   = str2bool(parser.get('datamc','makejsonfile')) # ex. False
        self.p_plotoutput   = str2bool(parser.get('datamc','makeplot'))     # ex. True
        self.p_mergejson    = str2bool(parser.get('datamc','mergejson'))    # ex. True
        self.p_outfile      = parser.get('datamc','jsonfilename')           # ex. pre
        self.p_lepton       = parser.get('datamc','lepton')                 # ex. muel
        ## ------------------- ##

        ## -- Sanity check -- ##
        if not any([self.p_plotoutput,self.p_jsonoutput,self.p_mergejson]):
            print
            print " You have specified that you don't want to "
            print " make json outputs, don't want to make "
            print " plots, and don't want to merge json files. "
            print " There's nothing left to do. "
            print " Exiting. "
            print
            sys.exit(1)
        ## ------------------ ##


        self.p_varlist = info.read_txt_file(self.p_vars_file) # variables from text file
        # for variables that may have [N], e.g., jet_pt[0], make a list
        # that just contains the name, e.g., jet_pt.
        # Plan to is to make a single json file for jet_pt, but
        # only plot [N], or [N+1] (e.g., the user specifies both jet_pt[0] and jet_pt[1]
        # in the text file)
        self.p_varlist_nolead = list(set([p_var.split('[')[0] for p_var in self.p_varlist]))

        loggingLEVEL     = logging.getLogger().getEffectiveLevel()
        logging.info(" -- In file dataMC.py")
        logging.info(" -- Make json output: {0} ".format(self.p_jsonoutput))

        ## -- Conver ROOT to JSON -- ##
        if self.p_jsonoutput:

            import pyDataMC.root2json as root2json

            logging.info(" > Specified json output ")
            logging.info("   Will produce json files and then plots automatically ")
            logging.info(" -- Making json output")

            print "\n   -- Converting ROOT to json output -- \n"

            ## Making json output, and then making plots (one step is easier...)
            root2json.ROOT2json(parser)

        ## -- Merge json files -- ##
        if self.p_mergejson:
            ## merge before plotting!!
            self.merge_json_files()

        ## -- Plot Histograms -- ##
        if self.p_plotoutput:
            from pyDataMC.json2hist import DataMCPlotter
            logging.info(" -- Making plots from json output")
            print "\n   -- Producing figures -- \n"

            plotter = DataMCPlotter(parser)
            plotter.initialize()
            for var in self.p_varlist:

                print "   ++ Plotting {0} ++\n".format(var)
                logging.info("   ++ Plotting {0} ++".format(var))

                plotter.datamcplotter(var)



        logging.info(" Finished datamc.py class DataMC")

        return