diff --git a/Sim/SimChecks/options/RadLength/RadLengthAna_FullGeo.py b/Sim/SimChecks/options/RadLength/RadLengthAna_FullGeo.py index a2b6f4480ec268b4f31e54fcdd8ff2ffa6c5964f..a0362d37c04185ca07952043ecd96bfac2e99e43 100644 --- a/Sim/SimChecks/options/RadLength/RadLengthAna_FullGeo.py +++ b/Sim/SimChecks/options/RadLength/RadLengthAna_FullGeo.py @@ -4,7 +4,7 @@ ## and the radiation lenght tool is activated. ## ## In order for this to work you also need Gauss-Job.py and MaterialEvalGun.py ## ## ## -## @author : K.Zarebski ## +## @author : K.Zarebski, L. Pescatore ## ## @date : last modified on 2017-10-06 ## ################################################################################# diff --git a/Sim/SimChecks/options/RadLength/RadLengthAna_NoVELO.py b/Sim/SimChecks/options/RadLength/RadLengthAna_NoVELO.py index f40d9b8353bcabc908fd5b1e44a56ad870abde98..f4c694cd6bab62d0841fcf59cc7e5dd8dece77d7 100644 --- a/Sim/SimChecks/options/RadLength/RadLengthAna_NoVELO.py +++ b/Sim/SimChecks/options/RadLength/RadLengthAna_NoVELO.py @@ -4,7 +4,7 @@ ## and the radiation lenght tool is activated. ## ## In order for this to work you also need Gauss-Job.py and MaterialEvalGun.py ## ## ## -## @author : K.Zarebski ## +## @author : L. Pescatore, K.Zarebski ## ## @date : last modified on 2017-10-06 ## ################################################################################# diff --git a/Sim/SimChecks/options/RadLength/RadLengthAna_VELO.py b/Sim/SimChecks/options/RadLength/RadLengthAna_VELO.py index 1c0db9fb578dd1aaf5d5623a885c69729865f43d..bce07e8fb575d93bee510da3d6f9efdfb32fc8e7 100644 --- a/Sim/SimChecks/options/RadLength/RadLengthAna_VELO.py +++ b/Sim/SimChecks/options/RadLength/RadLengthAna_VELO.py @@ -4,7 +4,7 @@ ## and the radiation lenght tool is activated. ## ## In order for this to work you also need Gauss-Job.py and MaterialEvalGun.py ## ## ## -## @author : K.Zarebski ## +## @author : L. Pescatore K.Zarebski ## ## @date : last modified on 2017-06-09 ## ################################################################################# diff --git a/Sim/SimChecks/options/Target/MakeEvents.py b/Sim/SimChecks/options/Target/MakeEvents.py index 18f94e09d4b7cf36d6077798a127e45114656293..2331c0f68623ebe01f352f41259489a36e55747c 100644 --- a/Sim/SimChecks/options/Target/MakeEvents.py +++ b/Sim/SimChecks/options/Target/MakeEvents.py @@ -3,7 +3,7 @@ ## which can be passed options for target materials, particle guns, ## ## thickness of the target and energy. ## ## ## -## @author : Kristian Zarebski ## +## @author : Luca Pescatore, Kristian Zarebski ## ## @date : last modified 2018-02-16 ## ################################################################################# @@ -12,7 +12,6 @@ import os import re import subprocess -from Target.TargetCreateEvents import RunTargetJobs from argparse import ArgumentParser @@ -40,6 +39,9 @@ parser.add_argument("--thicknessList", default="[1]", dest="thickness", help="Sp parser.add_argument("--pgunList", default="['p', 'pbar', 'Kplus', 'Kminus','Piplus, 'Piminus']", dest="pguns", help="Specify the particle gun") parser.add_argument("--use-gauss-geo", dest="gauss_geo", default=False, action='store_true', help='Use GaussGeo instead of GigaGeo for geometry initialisation if option available in Gauss version') parser.add_argument("--use-giga-geo", dest="giga_geo", default=False, action='store_true', help='Use GiGaGeo instead of GaussGeo for geometry initialisation if option available in Gauss version') +parser.add_argument("--plot-only", dest="plot", default=False, action='store_true', help='Perform plotting only') + + opts = parser.parse_args() energies = getArgsNum(opts.energies) models = getArgsChar(opts.physList) @@ -47,20 +49,24 @@ materials = getArgsChar(opts.materials) # 'Al' 'Be' 'Si' thicks = getArgsNum(opts.thickness) # in mm 1, 5, 10 (only) pguns = getArgsChar(opts.pguns) # Available: 'Piminus' 'Piplus' 'Kminus' 'Kplus' 'p' 'pbar' -gauss_geo_opts = '' -if opts.gauss_geo: - gauss_geo_opts = 'from Configurables import Gauss; Gauss().UseGaussGeo = True' -elif opts.giga_geo: - gauss_geo_opts = 'from Configurables import Gauss; Gauss().UseGaussGeo = False' -RunTargetJobs(output_directory, models, pguns, energies, materials, thicks, use_gauss_geo=gauss_geo_opts) +if not opts.plot: + print("Running Test") + gauss_geo_opts = '' + if opts.gauss_geo: + gauss_geo_opts = 'from Configurables import Gauss; Gauss().UseGaussGeo = True' + elif opts.giga_geo: + gauss_geo_opts = 'from Configurables import Gauss; Gauss().UseGaussGeo = False' + from Target.TargetCreateEvents import RunTargetJobs + RunTargetJobs(output_directory, models, pguns, energies, materials, thicks, use_gauss_geo=gauss_geo_opts) from ROOT import * + from Target.TargetPlots import Plot plots = ["RATIO_TOTAL", "RATIO_INEL", "TOTAL", "INEL", "EL", "MULTI", "MULTI_NCH", "MULTI_GAMMA", "ASYM_INEL"] -file_ = TFile(os.path.join(output_directory, "ROOTFiles/TargetsPlots.root")) +file_ = TFile.Open(os.path.join(output_directory, "ROOTFiles/TargetsPlots.root")) dataTree = file_.Get("summaryTree") subprocess.check_call("mkdir -p {}/Kaons".format(output_directory), shell=True) @@ -79,7 +85,7 @@ for e in energies: for t in thicks: for p in plots: - Plot(dataTree, "energy", p, output_directory, models, pguns, materials, 2, t, True) + Plot(dataTree, "energy", p, output_directory, models, pguns, materials, 2, t) if "p" in pguns and "pbar" in pguns: Plot(dataTree, "energy", p, os.path.join(output_directory, "Protons"), models, ["p", "pbar"], materials, 2, t, True) if "Kplus" in pguns and "Kminus" in pguns: diff --git a/Sim/SimChecks/python/RadLengthMakePlots.py b/Sim/SimChecks/python/RadLengthMakePlots.py index 6e5b6285ffa3c4ac43396b171e281c962ee1e16e..645c151fb31a6184c5bfd7def325265e692c6767 100644 --- a/Sim/SimChecks/python/RadLengthMakePlots.py +++ b/Sim/SimChecks/python/RadLengthMakePlots.py @@ -1,7 +1,7 @@ ################################################################################# ## Python script for creation of plots as part of Radiation Length tests ## ## ## -## @author : K. Zarebski ## +## @author : L. Pescatore, K. Zarebski ## ## @date : last modified on 2018-05-29 ## ################################################################################# diff --git a/Sim/SimChecks/python/Target/TargetCreateEvents.py b/Sim/SimChecks/python/Target/TargetCreateEvents.py index 103983f55d8073d738f258cfc0decfa270ef3aea..a2bbdf3f23d8eb245cf195370341218f81bfd512 100644 --- a/Sim/SimChecks/python/Target/TargetCreateEvents.py +++ b/Sim/SimChecks/python/Target/TargetCreateEvents.py @@ -1,9 +1,10 @@ -############################################################################## -# Option file to run hadronic cross section checks with multiple targets. -# For moreusage informations: https://twiki.cern.ch/twiki/bin/view/LHCb/TargetStudy -# -# Last modified: Kristian Zarebski, 02/02/2017 -############################################################################## +##################################################################################### +# Option file to run hadronic cross section checks with multiple targets. # +# For moreusage informations: https://twiki.cern.ch/twiki/bin/view/LHCb/TargetStudy # +# # +# @author : L. Pescatore, K. Zarebski # +# @date : Last modified 2018-07-25 # +##################################################################################### import sys import os diff --git a/Sim/SimChecks/python/Target/TargetPlots.py b/Sim/SimChecks/python/Target/TargetPlots.py index b3976fa6534bd873546aff5b75c97525e64b1810..46b6d9b8ab95351fd5c5602672146c1f2375a41b 100644 --- a/Sim/SimChecks/python/Target/TargetPlots.py +++ b/Sim/SimChecks/python/Target/TargetPlots.py @@ -1,17 +1,19 @@ -############################################################################## -# Option file to run hadronic cross section checks with multiple targets. -# For moreusage informations: https://twiki.cern.ch/twiki/bin/view/LHCb/TargetStudy -# -# Last modified: Kristian Zarebski, 02/02/2017 -############################################################################## - -from string import find -from ROOT import * -gROOT.SetBatch(True) +##################################################################################### +# Option file to run hadronic cross section checks with multiple targets. # +# For moreusage informations: https://twiki.cern.ch/twiki/bin/view/LHCb/TargetStudy # +# # +# @author : L. Pescatore, K. Zarebski # +# @date : Last modified 2018-07-25 # +##################################################################################### + +import ROOT +ROOT.gROOT.SetBatch(True) from Target.TargetSummary import Plotter, doMultiHistos from array import array from copy import * import os +import logging +logging.basicConfig() vardef = {"TOTAL": "xsec", "INEL": "inel_xsec", "EL": "el_xsec", "MULTI_NCH": "multiNCh", "MULTI_NCH_NOGAMMA": "multiNCh_nogamma", @@ -43,19 +45,31 @@ mat_names = {'Al' : 'Aluminium', 'Be' : 'Beryllium', 'Si' : 'Silicon'} part_latex = {'Piminus' : '#pi^{-}', 'Piplus' : '#pi^{+}', 'p' : 'p^{+}', 'pbar' : 'p^{-}', 'Kplus' : 'K^{+}', 'Kminus' : 'K^{-}'} -def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[], E0=-1, Dx=-1, plotData=False, makePDFs=False): - gROOT.SetBatch(True) + +class ROOTException(Exception): + def __init__(self, *args, **kwargs): + message = '{} Failed.\nINFO: {}'.format(*args) + Exception.__init__(self, message) + +def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[], E0=-1, Dx=-1, plotData=False, makePDFs=False, debug=False): + + ROOT.gROOT.SetBatch(True) + + _logger = logging.getLogger('TARGETPLOTS') + + if debug: + _logger.setLevel('DEBUG') plotterDict = Plotter() - leg = TLegend(0.10, 0.1, 0.9, 0.9) + leg = ROOT.TLegend(0.10, 0.1, 0.9, 0.9) leg.SetTextSize(0.05) fPlot = finalPlot.replace("RATIO_", "").replace("ASYM_", "") var = vardef[fPlot] - if(find(finalPlot, "RATIO") > -1 or find(finalPlot, "ASYM") > -1): + if any(i in finalPlot for i in ['RATIO', 'ASYM']): mystr = " in " + str(Dx) + " mm" if(xvar == "thickness"): @@ -89,6 +103,7 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ ratiotxt.write("\\multicolumn{2}{c}{ratio " + str(plotterDict._all_pguns[pguns[pg + 1]].GetLatex("$")) + "/" + str(plotterDict._all_pguns[pguns[pg]].GetLatex("$")) + "} \\\\ \\hline \n") nm = 0 for m in models: + _logger.debug("Creating {}: {} vs {} Graphs for:\n\tPgun: {}\n\tModel: {}\n\tMaterial: {}\n\tEnergy={}GeV\tThickness={}mm".format(finalPlot, xvar, var, pguns[pg], m, materials, E0, Dx)) ratiotxt.write("\\multicolumn{2}{c}{ " + m + "} \\\\ \\hline \n") @@ -103,40 +118,44 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ dataTree.SetEntryList(0) dataTree.Draw(">>" + varexp, select, "entrylist") - list = gDirectory.Get(varexp) - entries = list.GetN() - dataTree.SetEntryList(list) - errx = array('d', [0.] * entries) + entry_list = ROOT.gDirectory.Get(varexp) + entries = entry_list.GetN() + dataTree.SetEntryList(entry_list) - has_error = (find(finalPlot, "MULTI") > -1 or find(finalPlot, "TOTAL") > -1 or find(finalPlot, "INEL") > -1 or find(finalPlot, "EL") > -1) + _logger.debug("Retrieving Entry List of Size "+str(entries)) + + values = {'xerr' : array('d', [0.] * entries), 'R' : array('d', []), 'Rerr' : array('d', [])} - if entries == 0: - print "No entries selected!" - print "Selection used: " + select - continue + has_error = any(i in finalPlot for i in ['MULTI', 'TOTAL', 'INEL', 'EL']) + + try: + assert entries != 0 + except AssertionError: + _logger.error("No entries selected! Selection used: {}\nGot value: entries={}\nAborting...".format(entries, select)) + raise AssertionError if(has_error): try: - dataTree.Draw(xvar + ":" + var + ":" + var + "_err", "", "colz") - gr = TGraphErrors(entries, dataTree.GetV1(), dataTree.GetV2(), errx, dataTree.GetV3()) + values['y1'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, var) for i in xrange(entries)]) + values['x'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, xvar) for i in xrange(entries)]) + values['y1err'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, var+'_err') for i in xrange(entries)]) + + gr = ROOT.TGraphErrors(entries, values['x'], + values['y1'], + values['xerr'], + values['y1err']) except: - print("ERROR: Could not generate Graph: '{}+/-{} vs {}+/-{}'".format(xvar, var, errx, var+'_err' )) - continue + _logger.error("Could not generate Graph: '{}+/-{} vs {}+/-{}'".format(xvar, '0', var, var+'_err' )) + raise ROOTException('ROOT.TGraphErrors', 'x={}\nxerr={}\ny1={}\ny1err={}'.format(values['x'], values['xerr'], values['y1'], values['y1err'])) else: try: - dataTree.Draw(xvar + ":" + var) - gr = TGraphErrors(entries, dataTree.GetV1(), dataTree.GetV2()) + values['y1'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, var) for i in xrange(entries)]) + values['x'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, xvar) for i in xrange(entries)]) + gr = ROOT.TGraphErrors(entries, values['x'], values['y1']) except: - print("ERROR: Could not generate Graph: '{} vs {}'".format(xvar, var)) - continue - ty1 = dataTree.GetV2() - terry1 = dataTree.GetV3() - y1 = [] - erry1 = [] - for i in range(0, entries): - y1.append(ty1[i]) - if has_error: - erry1.append(terry1[i]) + _logger.error("Could not generate Graph: '{} vs {}'".format(xvar, var)) + raise ROOTException('ROOT.TGraphErrors', 'x={}\ny1={}'.format(values['x'], values['y1'])) + varexp = "h_" + str(pg + 1) + m select = select_template.format(mod=ord(m[0]), mat=ord(materials[0][0]), part=plotterDict._all_pguns[pguns[pg + 1]]._pdgID) @@ -146,61 +165,77 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ elif(xvar == "thickness"): select += " && energy == " + str(E0) + dataTree.SetEntryList(0) dataTree.Draw(">>" + varexp, select, "entrylist") - list2 = gDirectory.Get(varexp) - dataTree.SetEntryList(list2) + entry_list = ROOT.gDirectory.Get(varexp) + entries = entry_list.GetN() + + _logger.debug("Retrieving Entry List of Size "+str(entries)) + + dataTree.SetEntryList(entry_list) + if(has_error): try: - dataTree.Draw(xvar + ":" + var + ":" + var + "_err") - gr = TGraphErrors(entries, dataTree.GetV1(), dataTree.GetV2(), errx, dataTree.GetV3()) + values['y2'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, var) for i in xrange(entries)]) + values['x'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, xvar) for i in xrange(entries)]) + values['y2err'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, var+'_err') for i in xrange(entries)]) + gr = ROOT.TGraphErrors(entries, values['x'], values['y2'], values['xerr'], values['y2err']) except: - print("ERROR: Could not generate Graph: '{}+/-{} vs {}+/-{}'".format(xvar, var, errx, var+'_err' )) - continue + _logger.error("Could not generate Graph: '{}+/-{} vs {}+/-{}'".format(xvar, '0', var, var+'_err' )) + raise ROOTException('ROOT.TGraphErrors', 'x={}\nxerr={}\ny2={}\ny2err={}'.format(values['x'], values['xerr'], values['y1'], values['y1err'])) else: try: - dataTree.Draw(xvar + ":" + var) - gr = TGraphErrors(entries, dataTree.GetV1(), dataTree.GetV2()) + values['y2'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, var) for i in xrange(entries)]) + values['x'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, xvar) for i in xrange(entries)]) + gr = ROOT.TGraphErrors(entries, values['x'], values['y2']) except: - print("ERROR: Could not generate Graph: '{} vs {}'".format(xvar, var)) - continue - - tx = dataTree.GetV1() - ty2 = dataTree.GetV2() - terry2 = dataTree.GetV3() - x = [] - y2 = [] - erry2 = [] - for i in range(0, entries): - y2.append(ty2[i]) - if has_error: - erry2.append(terry2[i]) - x.append(tx[i]) + _logger.error("Could not generate Graph: 'x={} vs y2={}'".format(xvar, var)) + raise ROOTException('ROOT.TGraphErrors', '{}\n{}'.format(values['x'], values['y1'])) + + + try: + assert len(values['x']) == len(values['y1']) and len(values['x']) == len(values['y2']) and len(values['x']) == entries + except AssertionError: + _logger.error("Array sizes for x, y1, y2 are incompatible") + raise AssertionError + - y = [] - erry = [] for ee in range(0, entries): - ratiotxt.write(str(x[ee])) - if(find(finalPlot, "RATIO") > -1): - y.append(y2[ee] / y1[ee]) + ratiotxt.write(str(values['x'][ee])) + if 'RATIO' in finalPlot: + try: + values['R'].append(values['y2'][ee] / values['y1'][ee]) + except ZeroDivisionError: + _logger.error("Attempted to Divide by a Zero\nCalculation y2/y1:"+ + "\n\ty2={}\n\ty1={}\nSelection: {}".format(values['y2'],values['y1'], select)+ + "\nThese values are obtained using GetV1(), GetV2() etc.") + raise ZeroDivisionError else: - #y.append(100*TMath.Abs(y1[ee] - y2[ee])/(2. - y1[ee] - y2[ee])) - y.append(100 * TMath.Abs(y1[ee] - y2[ee]) / 2.) + values['R'].append(100 * ROOT.TMath.Abs(values['y1'][ee] - values['y2'][ee]) / 2.) - if(len(erry1) > 0): - totErr2 = TMath.Power(erry1[ee] / y1[ee], 2) + TMath.Power(erry2[ee] / y2[ee], 2) - erry.append(y[ee] * TMath.Sqrt(totErr2)) - ratiotxt.write(' & $ {0:4.2} \\pm {1:4.2} $ \\\\ \n'.format(y[ee], erry[ee])) + if has_error: + try: + totErr2 = ROOT.TMath.Power(values['y1err'][ee] / values['y1'][ee], 2) + ROOT.TMath.Power(values['y2err'][ee] / values['y2'][ee], 2) + except ZeroDivisionError: + _logger.error("Attempted to Divide by a Zero\nCalculation y1err/y1+y2err/y2:"+ + "\n\ty1err={}\n\ty1={}\n\ty2err={}\n\ty2={}.\n\tSelection: {}".format(values['y1err'], + values['y1'], values['y2err'], values['y2'], select)+ + "\nThese values are obtained using GetV1(), GetV2() etc.") + raise ZeroDivisionError + + values['Rerr'].append(values['R'][ee] * ROOT.TMath.Sqrt(totErr2)) + ratiotxt.write(' & $ {0:4.2} \\pm {1:4.2} $ \\\\ \n'.format(values['R'][ee], values['Rerr'][ee])) else: - ratiotxt.write(' & $ {0:4.2} $ \\\\ \n'.format(y[ee])) + ratiotxt.write(' & $ {0:4.2} $ \\\\ \n'.format(values['R'][ee])) - if(len(erry) > 1): - gr = TGraphErrors(entries, array('d', x), array('d', y), array('d', errx), array('d', erry)) + if has_error: + gr = ROOT.TGraphErrors(entries, values['x'], values['R'], values['xerr'], values['Rerr']) else: - gr = TGraphErrors(entries, array('d', x), array('d', y)) + gr = ROOT.TGraphErrors(entries, values['x'], values['R']) gr.SetMarkerColor(colors[pg / 2]) gr.SetMarkerStyle(20 + nm) @@ -210,15 +245,15 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ label += " (" + m + ")" leg.AddEntry(gr, label, "P") - if(plotData and (find(finalPlot, "TOTAL") > -1 or find(finalPlot, "INEL") > -1) and find(finalPlot, "RATIO") > -1): + if plotData and any(i in finalPlot for i in ['TOTAL', 'INEL', 'RATIO']): grPDG = 0 if(plotterDict._all_pguns[pguns[pg]].GetName() == "p" and plotterDict._all_pguns[pguns[pg + 1]].GetName() == "pbar"): - grPDG = TGraphErrors(5, array('d', pdgenergies), array('d', pdgRatios_p)) + grPDG = ROOT.TGraphErrors(5, array('d', pdgenergies), array('d', pdgRatios_p)) elif(plotterDict._all_pguns[pguns[pg]].GetName() == "Piplus" and plotterDict._all_pguns[pguns[pg + 1]].GetName() == "Piminus"): - grPDG = TGraphErrors(5, array('d', pdgenergies), array('d', pdgRatios_pi)) + grPDG = ROOT.TGraphErrors(5, array('d', pdgenergies), array('d', pdgRatios_pi)) elif(plotterDict._all_pguns[pguns[pg]].GetName() == "Kplus" and plotterDict._all_pguns[pguns[pg + 1]].GetName() == "Kminus"): - grPDG = TGraphErrors(5, array('d', pdgenergies), array('d', pdgRatios_K)) + grPDG = ROOT.TGraphErrors(5, array('d', pdgenergies), array('d', pdgRatios_K)) if grPDG: if(len(pguns) > 2): @@ -241,9 +276,9 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ ratiotxt.write("\\hline\n\\end{tabular}") - c = TCanvas() - leg_pad = TPad("leg_pad", "", 0.73, 0, 1., 1.) - gr_pad = TPad("gr_pad", "", 0.03, 0, 0.8, 1.) + c = ROOT.TCanvas() + leg_pad = ROOT.TPad("leg_pad", "", 0.73, 0, 1., 1.) + gr_pad = ROOT.TPad("gr_pad", "", 0.03, 0, 0.8, 1.) gr_pad.cd() gr_pad.SetLogx() @@ -251,7 +286,7 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ os.system("mkdir -p {}/ROOTGraphs".format(outputPath)) output_rootFile = os.path.join(outputPath, "ROOTGraphs/{}".format(finalPlot + mystr.replace(" ", "_") + ".root")) - out_file = TFile.Open(output_rootFile, "recreate") + out_file = ROOT.TFile.Open(output_rootFile, "recreate") ratio_title_y = '#sigma^{{{group}}}_{{antipart}}/#sigma^{{{group}}}_{{part}}' @@ -259,7 +294,7 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ for gg in grs: gg.GetYaxis().SetTitleOffset(1.5) - if(finalPlot.find("RATIO") > -1): + if 'RATIO' in finalPlot: if 'INEL' in finalPlot: gg.GetYaxis().SetTitle(ratio_title_y.format(group='inel')) elif 'TOTAL' in finalPlot: @@ -296,9 +331,9 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ else: - c = TCanvas() - leg_pad = TPad("leg_pad", "", 0.73, 0, 1., 1.) - gr_pad = TPad("gr_pad", "", 0.03, 0, 0.8, 1.) + c = ROOT.TCanvas() + leg_pad = ROOT.TPad("leg_pad", "", 0.73, 0, 1., 1.) + gr_pad = ROOT.TPad("gr_pad", "", 0.03, 0, 0.8, 1.) gr_pad.cd() mystr = " in " + str(Dx) + " mm" @@ -368,22 +403,22 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ COMPASTot_pbar_y = [x * PintOverSigmaFactor for x in COMPASTot_pbar_sigma] COMPASTot_pbar_yErr = [x * PintOverSigmaFactor for x in COMPASTot_pbar_sigmaErr] - COMPAS_p_gr = TGraphErrors(6, array('d', COMPAS_p_x), array('d', COMPAS_p_y), array('d', [0.] * 6), array('d', COMPAS_p_yErr)) - COMPAS_pbar_gr = TGraphErrors(6, array('d', COMPAS_pbar_x), array('d', COMPAS_pbar_y), array('d', [0.] * 6), array('d', COMPAS_pbar_yErr)) + COMPAS_p_gr = ROOT.TGraphErrors(6, array('d', COMPAS_p_x), array('d', COMPAS_p_y), array('d', [0.] * 6), array('d', COMPAS_p_yErr)) + COMPAS_pbar_gr = ROOT.TGraphErrors(6, array('d', COMPAS_pbar_x), array('d', COMPAS_pbar_y), array('d', [0.] * 6), array('d', COMPAS_pbar_yErr)) COMPAS_p_gr.SetMarkerStyle(29) COMPAS_p_gr.SetMarkerSize(1.1) COMPAS_pbar_gr.SetMarkerStyle(30) COMPAS_pbar_gr.SetMarkerSize(1.2) - COMPASTot_p_gr = TGraphErrors(4, array('d', COMPASTot_p_x), array('d', COMPASTot_p_y), array('d', [0.] * 4), array('d', COMPASTot_p_yErr)) - COMPASTot_pbar_gr = TGraphErrors(2, array('d', COMPASTot_pbar_x), array('d', COMPASTot_pbar_y), array('d', [0.] * 2), array('d', COMPASTot_pbar_yErr)) + COMPASTot_p_gr = ROOT.TGraphErrors(4, array('d', COMPASTot_p_x), array('d', COMPASTot_p_y), array('d', [0.] * 4), array('d', COMPASTot_p_yErr)) + COMPASTot_pbar_gr = ROOT.TGraphErrors(2, array('d', COMPASTot_pbar_x), array('d', COMPASTot_pbar_y), array('d', [0.] * 2), array('d', COMPASTot_pbar_yErr)) COMPASTot_p_gr.SetMarkerStyle(29) COMPASTot_p_gr.SetMarkerSize(1.1) COMPASTot_pbar_gr.SetMarkerStyle(30) COMPASTot_pbar_gr.SetMarkerSize(1.2) - COMPAS_inBe_p_gr = TGraphErrors(6, array('d', COMPAS_inBe_p_x), array('d', COMPAS_inBe_p_y), array('d', [0.] * 6), array('d', COMPAS_inBe_p_yErr)) - COMPAS_inBe_pbar_gr = TGraphErrors(5, array('d', COMPAS_inBe_pbar_x), array('d', COMPAS_inBe_pbar_y), array('d', [0.] * 5), array('d', COMPAS_inBe_pbar_yErr)) + COMPAS_inBe_p_gr = ROOT.TGraphErrors(6, array('d', COMPAS_inBe_p_x), array('d', COMPAS_inBe_p_y), array('d', [0.] * 6), array('d', COMPAS_inBe_p_yErr)) + COMPAS_inBe_pbar_gr = ROOT.TGraphErrors(5, array('d', COMPAS_inBe_pbar_x), array('d', COMPAS_inBe_pbar_y), array('d', [0.] * 5), array('d', COMPAS_inBe_pbar_yErr)) COMPAS_inBe_p_gr.SetMarkerStyle(29) COMPAS_inBe_p_gr.SetMarkerSize(1.1) COMPAS_inBe_pbar_gr.SetMarkerStyle(30) @@ -392,13 +427,15 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ #Plotting Gauss values n0 = 0 nh = 0 - for model in models: + for n0, model in enumerate(models): for material in materials: n2 = 0 for pg in pguns: + _logger.debug("Creating {}: {} vs {} Graphs for:\n\tModel: {}\n\tMaterial: {}".format(finalPlot, xvar, var, model, material)) + gr = None varexp = "h_" + str(nh) nh += 1 @@ -408,30 +445,41 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ elif(xvar == "thickness"): select += " && energy == " + str(E0) + dataTree.SetEntryList(0) dataTree.Draw(">>" + varexp, select, "entrylist") - list = gDirectory.Get(varexp) - entries = list.GetN() - dataTree.SetEntryList(list) + entry_list = ROOT.gDirectory.Get(varexp) + entries = entry_list.GetN() + dataTree.SetEntryList(entry_list) + + _logger.debug("Retrieving Entry List of Size "+str(entries)) dataTree.SetEstimate(entries) - errx = array('d', [0.] * entries) - gr = 0 + + values = {'xerr' : array('d', [0.] * entries)} if(finalPlot == "MULTI" or finalPlot == "TOTAL" or finalPlot == "INEL" or finalPlot == "EL"): try: dataTree.Draw(xvar + ":" + var + ":" + var + "_err", "", "colz") - gr = TGraphErrors(entries, dataTree.GetV1(), dataTree.GetV2(), errx, dataTree.GetV3()) + + values['y'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, var) for i in xrange(entries)]) + values['x'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, xvar) for i in xrange(entries)]) + values['yerr'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, var+'_err') for i in xrange(entries)]) + + gr = ROOT.TGraphErrors(entries, values['x'], values['y'], values['xerr'], values['yerr']) + except: - print("ERROR: Could not generate Graph: '{}+/-{} vs {}+/-{}'".format(xvar, var, errx, var+'_err' )) - continue + _logger.error("Could not generate Graph: '{}+/-{} vs {}+/-{}'".format(xvar, '0', var, var+'_err' )) + raise ROOTException('TGraphErrors','') else: try: - dataTree.Draw(xvar + ":" + var) - gr = TGraphErrors(entries, dataTree.GetV1(), dataTree.GetV2()) + values['y'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, var) for i in xrange(entries)]) + values['x'] = array('d', [dataTree.GetEntry(entry_list.GetEntry(i)) and getattr(dataTree, xvar) for i in xrange(entries)]) + gr = ROOT.TGraphErrors(entries, values['x'], values['y']) except: - print("ERROR: Could not generate Graph: '{} vs {}'".format(xvar, var)) - continue + _logger.error("Could not generate Graph: '{} vs {}'".format(xvar, var)) + raise ROOTException('TGraphErrors','') + if(nh % 2 == 0): gr.SetMarkerColor(colors[int(nh / 2. - 1)]) @@ -456,7 +504,7 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ grs.append(gr) if plotData and n0 == len(models) - 1 and materials[0] == "Al": - if find(finalPlot, "TOTAL") > -1: + if 'TOTAL' in finalPlot: if plotterDict._all_pguns[pg].GetName() == "p": COMPASTot_p_gr.SetMarkerColor(4) # colors[int(nh/2.-1)]) grs.append(COMPASTot_p_gr) @@ -465,7 +513,7 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ COMPASTot_pbar_gr.SetMarkerColor(4) # colors[int(nh/2.-1)]) grs.append(COMPASTot_pbar_gr) leg.AddEntry(COMPASTot_pbar_gr, "COMPAS #bar{p} total in Al", "P") - elif find(finalPlot, "INEL") > -1: + elif 'INEL' in finalPlot: if plotterDict._all_pguns[pg].GetName() == "p": COMPAS_p_gr.SetMarkerColor(4) # colors[int(nh/2.-1)]) grs.append(COMPAS_p_gr) @@ -474,7 +522,7 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ COMPAS_pbar_gr.SetMarkerColor(4) # colors[int(nh/2.-1)]) grs.append(COMPAS_pbar_gr) leg.AddEntry(COMPAS_pbar_gr, "COMPAS #bar{p} inel in Al", "P") - elif plotData and n0 == len(models) - 1 and materials[0] == "Be" and find(finalPlot, "INEL") > -1: + elif plotData and n0 == len(models) - 1 and materials[0] == "Be" and 'INEL' in finalPlot: if plotterDict._all_pguns[pg].GetName() == "p": COMPAS_inBe_p_gr.SetMarkerColor(4) # colors[int(nh/2.-1)]) grs.append(COMPAS_inBe_p_gr) @@ -486,14 +534,14 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ n0 += 1 - gStyle.SetOptStat(0) + ROOT.gStyle.SetOptStat(0) gr_pad.SetGrid() if(xvar == "energy"): gr_pad.SetLogx() gr_pad.cd() os.system("mkdir -p {}/ROOTGraphs".format(outputPath)) output_rootFile = os.path.join(outputPath, "ROOTGraphs/{}".format(finalPlot + mystr.replace(" ", "_") + ".root")) - out_file = TFile.Open(output_rootFile, "recreate") + out_file = ROOT.TFile.Open(output_rootFile, "recreate") ngg = 0 for gg in grs: @@ -530,10 +578,10 @@ def Plot(dataTree, xvar, finalPlot, outputPath, models=[], pguns=[], materials=[ gg.GetYaxis().SetRangeUser(0.00001, 0.0025) else: gg.GetYaxis().SetRangeUser(0.00001, 0.025) - elif(find(finalPlot, "MULTI") > -1): + elif 'MULTI' in finalPlot: gg.GetYaxis().SetTitle("< Multi >") gg.GetYaxis().SetRangeUser(0., 40.) - elif(find(finalPlot, "PERC") > -1): + elif 'PERC' in finalPlot: gg.GetYaxis().SetTitle("%") gg.GetYaxis().SetRangeUser(0., 100.) @@ -577,8 +625,8 @@ if __name__ == "__main__": #pguns = ["pbar","p"] path = "/afs/cern.ch/work/p/pluca/TargetOutput" - file = TFile(path + "/TargetsPlots.root") - dataTree = file.Get("summaryTree") + file_in = ROOT.TFile.Open(path + "/TargetsPlots.root") + dataTree = file_in.Get("summaryTree") os.system("mkdir -p " + path + "/Kaons") os.system("mkdir -p " + path + "/Protons") diff --git a/Sim/SimChecks/python/Target/TargetSetup.py b/Sim/SimChecks/python/Target/TargetSetup.py index c3ae8888b39b049b72a28e29d36b03ebb4944afd..9b29cb394881f123946f976992f28ad4bb981a1d 100755 --- a/Sim/SimChecks/python/Target/TargetSetup.py +++ b/Sim/SimChecks/python/Target/TargetSetup.py @@ -1,3 +1,9 @@ +####################################################################################### +## Option file to define geometry reader and geometry conditions ## +## ## +## @authors : L. Pescatore, K. Zarebski ## +## @date : last modified 2018-07-16 ## +####################################################################################### from Gaudi.Configuration import * from Gauss.Configuration import * diff --git a/Sim/SimChecks/python/Target/TargetSummary.py b/Sim/SimChecks/python/Target/TargetSummary.py index d6eab6946dd9b0e7a98c1e9d822725d376d00ede..0b5c94cdad03b9587b8c923fe2dba6bb132c623d 100644 --- a/Sim/SimChecks/python/Target/TargetSummary.py +++ b/Sim/SimChecks/python/Target/TargetSummary.py @@ -1,9 +1,10 @@ -############################################################################## -# Option file to run hadronic cross section checks with multiple targets. -# For moreusage informations: https://twiki.cern.ch/twiki/bin/view/LHCb/TargetStudy -# -# Last modified: Kristian Zarebski, 01/02/2017 -############################################################################## +##################################################################################### +# Option file to run hadronic cross section checks with multiple targets. # +# For moreusage informations: https://twiki.cern.ch/twiki/bin/view/LHCb/TargetStudy # +# # +# @author : L. Pescatore, K. Zarebski # +# @date : Last modified 2018-07-25 # +##################################################################################### from string import * from ROOT import * diff --git a/Sim/SimChecks/scripts/rad_length_scan.py b/Sim/SimChecks/scripts/rad_length_scan.py index 78e9ac842c85a89b9d1aaa44483292849d0f4178..5576e3513d019fb727c36dd6fc0460c5d38557f0 100644 --- a/Sim/SimChecks/scripts/rad_length_scan.py +++ b/Sim/SimChecks/scripts/rad_length_scan.py @@ -21,7 +21,7 @@ ## ## ## Twiki at: https://twiki.cern.ch/twiki/bin/view/LHCb/RadLengthStudies ## ## ## -## @author : K.Zarebski ## +## @author : L. Pescatore, K.Zarebski ## ## @date : last modified on 2018-05-29 ## ################################################################################# diff --git a/Sim/SimChecks/scripts/rad_length_scan_velo_z.py b/Sim/SimChecks/scripts/rad_length_scan_velo_z.py index d85fccb43a8f7820032adec7f505302de84d78bd..0399fb298c28dcbd96fd9c213b5cd9743683b556 100644 --- a/Sim/SimChecks/scripts/rad_length_scan_velo_z.py +++ b/Sim/SimChecks/scripts/rad_length_scan_velo_z.py @@ -21,7 +21,7 @@ ## ## ## Twiki at: https://twiki.cern.ch/twiki/bin/view/LHCb/RadLengthStudies ## ## ## -## @author : K.Zarebski ## +## @author : L. Pescatore, K.Zarebski ## ## @date : last modified on 2018-05-29 ## #################################################################################