def paramsGood_(detector, plot): """Check the validity of the arguments. Common function to check the validity of the parameters passed in. It returns a tuple composed by a bool and a string. The bool indicates if all checks are ok, the string the name of the appropriate ROOT file to open (empty string in case the any check failed) """ if plot not in plots.keys(): print("Error, unknown plot %s" % plot) return (False, '') if detector not in DETECTORS and detector not in COMPOUNDS.keys(): print('Error, unknown detector: %s' % detector) return (False, '') theDetectorFilename = '' if detector in DETECTORS: theDetectorFilename = 'matbdg_%s.root' % detector else: theDetectorFilename = 'matbdg_%s.root' % COMPOUNDS[detector][0] if not checkFile_(theDetectorFilename): print("Error, missing file %s" % theDetectorFilename) raise RuntimeError return (True, theDetectorFilename)
def get2DHisto_(detector,plotNumber,geometry): """ This function opens the appropiate ROOT file, extracts the TProfile2D and turns it into a Histogram, if it is a compound detector, this function takes care of the subdetectors' addition. Note that it takes plotNumber as opposed to plot """ histo = None rootFile = TFile() detectorFilename = 'matbdg_%s_%s.root'%(detector,geometry) if detector not in COMPOUNDS.keys() or checkFile_(detectorFilename): if not checkFile_(detectorFilename): print('Warning: %s not found' % detectorFilename) return 0 rootFile = TFile.Open(detectorFilename,'READ') prof = rootFile.Get("%d" % plotNumber) if not prof: return 0 # Prevent memory leaking by specifing a unique name prof.SetName('%u_%s_%s' %(plotNumber,detector,geometry)) prof.__class__ = TProfile2D histo = prof.ProjectionXY() else: histos = OrderedDict() theFiles = [] for subDetector in COMPOUNDS[detector]: subDetectorFilename = 'matbdg_%s_%s.root' % (subDetector,geometry) if not checkFile_(subDetectorFilename): print('Warning: %s not found'%subDetectorFilename) continue subDetectorFile = TFile.Open(subDetectorFilename,'READ') theFiles.append(subDetectorFile) print('*** Open file... %s' % subDetectorFilename) prof = subDetectorFile.Get('%d'%plotNumber) if not prof: return 0 prof.__class__ = TProfile2D if not histo: histo = prof.ProjectionXY('B_%s' % prof.GetName()) else: histo.Add(prof.ProjectionXY('B_%s' % prof.GetName())) return copy.deepcopy(histo)
def paramsGood_(detector, plot, geometryOld = '', geometryNew = ''): """Check the validity of the arguments. Common function to check the validity of the parameters passed in. It returns a tuple composed by a bool and a string. The bool indicates if all checks are ok, the string the appropriate ROOT filename to open (empty string in case any check failed) If geometry comparison is being made, a list of strings is returned instead. """ theFiles = [] if plot not in plots.keys(): print("Error, unknown plot %s" % plot) return (False, '') if detector not in DETECTORS and detector not in COMPOUNDS.keys(): print('Error, unknown detector: %s' % detector) return (False, '') if detector not in DETECTORS: detector = COMPOUNDS[detector][0] if geometryNew: oldgeoFilename = 'matbdg_%s_%s.root' % (detector,geometryOld) theFiles.append(oldgeoFilename) newgeoFilename = 'matbdg_%s_%s.root' % (detector,geometryNew) theFiles.append(newgeoFilename) else: theFiles.append('matbdg_%s_%s.root' % (detector,geometryOld)) for thisFile in theFiles: if not checkFile_(thisFile): print("Error, missing file %s" % thisFile) raise RuntimeError if len(theFiles) > 1: return (True, theFiles) else: return (True, theFiles[0])
def get1DHisto_(detector,plotNumber,geometry): """ This function opens the appropiate ROOT file, extracts the TProfile and turns it into a Histogram, if it is a compound detector, this function takes care of the subdetectors' addition unless the detector's ROOT file is present in which case no addition is performed and the detector ROOT file is used. """ histo = None rootFile = TFile() detectorFilename = 'matbdg_%s_%s.root'%(detector,geometry) if detector not in COMPOUNDS.keys() or checkFile_(detectorFilename): if not checkFile_(detectorFilename): print('Warning: %s not found' % detectorFilename) return 0 print('Reading from: %s File' % detectorFilename) rootFile = TFile.Open(detectorFilename,'READ') prof = rootFile.Get("%d" % plotNumber) if not prof: return 0 # Prevent memory leaking by specifing a unique name prof.SetName('%u_%s_%s' %(plotNumber,detector,geometry)) histo = prof.ProjectionX() else: theFiles = [] histos = OrderedDict() for subDetector in COMPOUNDS[detector]: subDetectorFilename = 'matbdg_%s_%s.root' % (subDetector,geometry) if not checkFile_(subDetectorFilename): print('Warning: %s not found'%subDetectorFilename) continue print('Reading from: %s File' % subDetectorFilename) subDetectorFile = TFile.Open(subDetectorFilename,'READ') theFiles.append(subDetectorFile) prof = subDetectorFile.Get('%d'%(plotNumber)) if not prof: return 0 prof.__class__ = TProfile histo = assignOrAddIfExists_(histo,prof.ProjectionX()) return copy.deepcopy(histo)
def createRatioPlots(detector, plot): """Create ratio plots. Function that will make the ratio between the radiation length and interaction length, for the specified detector. The specified detector could either be a real detector or a compound one. """ goodToGo, theDetectorFilename = paramsGood_(detector, plot) if not goodToGo: return theDirname = 'Images' if not os.path.exists(theDirname): os.mkdir(theDirname) theDetectorFile = TFile(theDetectorFilename) # get TProfiles prof_x0_det_total = theDetectorFile.Get('%d' % plots[plot].plotNumber) prof_l0_det_total = theDetectorFile.Get('%d' % (1000 + plots[plot].plotNumber)) # histos hist_x0_total = prof_x0_det_total.ProjectionX() hist_l0_total = prof_l0_det_total.ProjectionX() if detector in COMPOUNDS.keys(): for subDetector in COMPOUNDS[detector][1:]: # file name subDetectorFilename = "matbdg_%s.root" % subDetector # open file if not checkFile_(subDetectorFilename): print("Error, missing file %s" % subDetectorFilename) continue subDetectorFile = TFile(subDetectorFilename) # subdetector profiles prof_x0_det_total = subDetectorFile.Get('%d' % plots[plot].plotNumber) prof_l0_det_total = subDetectorFile.Get( '%d' % (1000 + plots[plot].plotNumber)) # add to summary histogram hist_x0_total.Add( prof_x0_det_total.ProjectionX( "B_%s" % prof_x0_det_total.GetName()), +1.000) hist_l0_total.Add( prof_l0_det_total.ProjectionX( "B_%s" % prof_l0_det_total.GetName()), +1.000) # hist_x0_over_l0_total = hist_x0_total hist_x0_over_l0_total.Divide(hist_l0_total) histTitle = "Material Budget %s;%s;%s" % (detector, plots[plot].abscissa, plots[plot].ordinate) hist_x0_over_l0_total.SetTitle(histTitle) # properties hist_x0_over_l0_total.SetMarkerStyle(1) hist_x0_over_l0_total.SetMarkerSize(3) hist_x0_over_l0_total.SetMarkerColor(kBlue) # canvas canRname = "MBRatio_%s_%s" % (detector, plot) canR = TCanvas(canRname, canRname, 800, 800) canR.Range(0, 0, 25, 25) canR.SetFillColor(kWhite) gStyle.SetOptStat(0) # Draw hist_x0_over_l0_total.Draw("E1") # Store canR.Update() canR.SaveAs("%s/%s_%s.pdf" % (theDirname, detector, plot)) canR.SaveAs("%s/%s_%s.png" % (theDirname, detector, plot))
def create2DPlots(detector, plot): """Produce the requested plot for the specified detector. Function that will plot the requested 2D-@plot for the specified @detector. The specified detector could either be a real detector or a compound one. The list of available plots are the keys of plots dictionary (imported from plot_utils). """ theDirname = 'Images' if not checkFile_(theDirname): os.mkdir(theDirname) goodToGo, theDetectorFilename = paramsGood_(detector, plot) if not goodToGo: return theDetectorFile = TFile(theDetectorFilename) # get TProfiles prof2d_X0_det_total = theDetectorFile.Get('%s' % plots[plot].plotNumber) # histos prof2d_X0_det_total.__class__ = TProfile2D hist_X0_total = prof2d_X0_det_total.ProjectionXY() # keep files live forever files = [] if detector in COMPOUNDS.keys(): for subDetector in COMPOUNDS[detector][1:]: # filenames of single components subDetectorFilename = "matbdg_%s.root" % subDetector # open file if not checkFile_(subDetectorFilename): print("Error, missing file %s" % subDetectorFilename) continue subDetectorFile = TFile(subDetectorFilename) files.append(subDetectorFile) print("*** Open file... %s" % subDetectorFilename) # subdetector profiles prof2d_X0_det_total = subDetectorFile.Get('%s' % plots[plot].plotNumber) prof2d_X0_det_total.__class__ = TProfile2D # add to summary histogram hist_X0_total.Add( prof2d_X0_det_total.ProjectionXY( "B_%s" % prof2d_X0_det_total.GetName()), +1.000) # # properties gStyle.SetPalette(1) gStyle.SetStripDecimals(False) # # # Create "null" histo minX = 1.03 * hist_X0_total.GetXaxis().GetXmin() maxX = 1.03 * hist_X0_total.GetXaxis().GetXmax() minY = 1.03 * hist_X0_total.GetYaxis().GetXmin() maxY = 1.03 * hist_X0_total.GetYaxis().GetXmax() frame = TH2F("frame", "", 10, minX, maxX, 10, minY, maxY) frame.SetMinimum(0.1) frame.SetMaximum(10.) frame.GetXaxis().SetTickLength(frame.GetXaxis().GetTickLength() * 0.50) frame.GetYaxis().SetTickLength(frame.GetXaxis().GetTickLength() / 4.) # Ratio if plots[plot].iRebin: hist_X0_total.Rebin2D() # stack hist2dTitle = ('%s %s;%s;%s;%s' % (plots[plot].quotaName, detector, plots[plot].abscissa, plots[plot].ordinate, plots[plot].quotaName)) hist2d_X0_total = hist_X0_total frame.SetTitle(hist2dTitle) frame.SetTitleOffset(0.5, "Y") if plots[plot].histoMin != -1.: hist2d_X0_total.SetMinimum(plots[plot].histoMin) if plots[plot].histoMax != -1.: hist2d_X0_total.SetMaximum(plots[plot].histoMax) # can2name = "MBCan_2D_%s_%s" % (detector, plot) can2 = TCanvas(can2name, can2name, 2480 + 248, 580 + 58 + 58) can2.SetTopMargin(0.1) can2.SetBottomMargin(0.1) can2.SetLeftMargin(0.04) can2.SetRightMargin(0.06) can2.SetFillColor(kWhite) gStyle.SetOptStat(0) gStyle.SetTitleFillColor(0) gStyle.SetTitleBorderSize(0) # Color palette gStyle.SetPalette(1) # Log? can2.SetLogz(plots[plot].zLog) # Draw in colors frame.Draw() hist2d_X0_total.Draw("COLZsame") #Dummy draw to create the palette object # Store can2.Update() #Aesthetic palette = hist2d_X0_total.GetListOfFunctions().FindObject("palette") if palette: palette.__class__ = TPaletteAxis palette.SetX1NDC(0.945) palette.SetX2NDC(0.96) palette.SetY1NDC(0.1) palette.SetY2NDC(0.9) palette.GetAxis().SetTickSize(.01) palette.GetAxis().SetTitle("") if plots[plot].zLog: palette.GetAxis().SetLabelOffset(-0.01) paletteTitle = TLatex(1.12 * maxX, maxY, plots[plot].quotaName) paletteTitle.SetTextAngle(90.) paletteTitle.SetTextSize(0.05) paletteTitle.SetTextAlign(31) paletteTitle.Draw() hist2d_X0_total.GetYaxis().SetTickLength( hist2d_X0_total.GetXaxis().GetTickLength() / 4.) hist2d_X0_total.GetYaxis().SetTickLength( hist2d_X0_total.GetXaxis().GetTickLength() / 4.) hist2d_X0_total.SetTitleOffset(0.5, "Y") hist2d_X0_total.GetXaxis().SetNoExponent(True) hist2d_X0_total.GetYaxis().SetNoExponent(True) #Add eta labels keep_alive = [] if plots[plot].iDrawEta: keep_alive.extend(drawEtaValues()) can2.Modified() hist2d_X0_total.SetContour(255) # Store can2.Update() can2.Modified() can2.SaveAs("%s/%s_%s_bw.pdf" % (theDirname, detector, plot)) can2.SaveAs("%s/%s_%s_bw.png" % (theDirname, detector, plot)) gStyle.SetStripDecimals(True)
def createCompoundPlots(detector, plot): """Produce the requested plot for the specified detector. Function that will plot the requested @plot for the specified @detector. The specified detector could either be a real detector or a compound one. The list of available plots are the keys of plots dictionary (imported from plot_utils. """ theDirname = 'Images' if not checkFile_(theDirname): os.mkdir(theDirname) goodToGo, theDetectorFilename = paramsGood_(detector, plot) if not goodToGo: return theDetectorFile = TFile(theDetectorFilename) # # get TProfiles prof_X0_elements = OrderedDict() hist_X0_elements = OrderedDict() for label, [num, color, leg] in six.iteritems(hist_label_to_num): prof_X0_elements[label] = theDetectorFile.Get( "%d" % (num + plots[plot].plotNumber)) hist_X0_elements[label] = prof_X0_elements[label].ProjectionX() hist_X0_elements[label].SetFillColor(color) hist_X0_elements[label].SetLineColor(kBlack) files = [] if detector in COMPOUNDS.keys(): for subDetector in COMPOUNDS[detector][1:]: subDetectorFilename = "matbdg_%s.root" % subDetector # open file if not checkFile_(subDetectorFilename): continue subDetectorFile = TFile(subDetectorFilename) files.append(subDetectorFile) print("*** Open file... %s" % subDetectorFilename) # subdetector profiles for label, [num, color, leg] in six.iteritems(hist_label_to_num): prof_X0_elements[label] = subDetectorFile.Get( "%d" % (num + plots[plot].plotNumber)) hist_X0_elements[label].Add( prof_X0_elements[label].ProjectionX( "B_%s" % prof_X0_elements[label].GetName()), +1.000) # stack stackTitle = "Material Budget %s;%s;%s" % (detector, plots[plot].abscissa, plots[plot].ordinate) stack_X0 = THStack("stack_X0", stackTitle) for label, [num, color, leg] in six.iteritems(hist_label_to_num): stack_X0.Add(hist_X0_elements[label]) # canvas canname = "MBCan_1D_%s_%s" % (detector, plot) can = TCanvas(canname, canname, 800, 800) can.Range(0, 0, 25, 25) can.SetFillColor(kWhite) gStyle.SetOptStat(0) # Draw stack_X0.Draw("HIST") # Legenda theLegend = TLegend(0.70, 0.70, 0.89, 0.89) for label, [num, color, leg] in six.iteritems(hist_label_to_num): theLegend.AddEntry(hist_X0_elements[label], leg, "f") theLegend.Draw() # Store can.Update() can.SaveAs("%s/%s_%s.pdf" % (theDirname, detector, plot)) can.SaveAs("%s/%s_%s.png" % (theDirname, detector, plot))
def createRatioPlots(detector, plot): """Create ratio plots. Function that will make the ratio between the radiation length and interaction length, for the specified detector. The specified detector could either be a real detector or a compound one. """ goodToGo, theDetectorFilename = paramsGood_(detector, plot) if not goodToGo: return theDirname = 'Images' if not os.path.exists(theDirname): os.mkdir(theDirname) theDetectorFile = TFile(theDetectorFilename) # get TProfiles prof_x0_det_total = theDetectorFile.Get('%d' % plots[plot].plotNumber) prof_l0_det_total = theDetectorFile.Get('%d' % (1000+plots[plot].plotNumber)) # histos hist_x0_total = prof_x0_det_total.ProjectionX() hist_l0_total = prof_l0_det_total.ProjectionX() if detector in COMPOUNDS.keys(): for subDetector in COMPOUNDS[detector][1:]: # file name subDetectorFilename = "matbdg_%s.root" % subDetector # open file if not checkFile_(subDetectorFilename): print("Error, missing file %s" % subDetectorFilename) continue subDetectorFile = TFile(subDetectorFilename) # subdetector profiles prof_x0_det_total = subDetectorFile.Get('%d' % plots[plot].plotNumber) prof_l0_det_total = subDetectorFile.Get('%d' % (1000+plots[plot].plotNumber)) # add to summary histogram hist_x0_total.Add(prof_x0_det_total.ProjectionX("B_%s" % prof_x0_det_total.GetName()), +1.000 ) hist_l0_total.Add(prof_l0_det_total.ProjectionX("B_%s" % prof_l0_det_total.GetName()), +1.000 ) # hist_x0_over_l0_total = hist_x0_total hist_x0_over_l0_total.Divide(hist_l0_total) histTitle = "Material Budget %s;%s;%s" % (detector, plots[plot].abscissa, plots[plot].ordinate) hist_x0_over_l0_total.SetTitle(histTitle) # properties hist_x0_over_l0_total.SetMarkerStyle(1) hist_x0_over_l0_total.SetMarkerSize(3) hist_x0_over_l0_total.SetMarkerColor(kBlue) # canvas canRname = "MBRatio_%s_%s" % (detector, plot) canR = TCanvas(canRname,canRname,800,800) canR.Range(0,0,25,25) canR.SetFillColor(kWhite) gStyle.SetOptStat(0) # Draw hist_x0_over_l0_total.Draw("E1") # Store canR.Update() canR.SaveAs("%s/%s_%s.pdf" % (theDirname, detector, plot)) canR.SaveAs("%s/%s_%s.png" % (theDirname, detector, plot))
def create2DPlots(detector, plot): """Produce the requested plot for the specified detector. Function that will plot the requested 2D-@plot for the specified @detector. The specified detector could either be a real detector or a compound one. The list of available plots are the keys of plots dictionary (imported from plot_utils). """ theDirname = 'Images' if not checkFile_(theDirname): os.mkdir(theDirname) goodToGo, theDetectorFilename = paramsGood_(detector, plot) if not goodToGo: return theDetectorFile = TFile(theDetectorFilename) # get TProfiles prof2d_X0_det_total = theDetectorFile.Get('%s' % plots[plot].plotNumber) # histos prof2d_X0_det_total.__class__ = TProfile2D hist_X0_total = prof2d_X0_det_total.ProjectionXY() # keep files live forever files = [] if detector in COMPOUNDS.keys(): for subDetector in COMPOUNDS[detector][1:]: # filenames of single components subDetectorFilename = "matbdg_%s.root" % subDetector # open file if not checkFile_(subDetectorFilename): print("Error, missing file %s" % subDetectorFilename) continue subDetectorFile = TFile(subDetectorFilename) files.append(subDetectorFile) print("*** Open file... %s" % subDetectorFilename) # subdetector profiles prof2d_X0_det_total = subDetectorFile.Get('%s' % plots[plot].plotNumber) prof2d_X0_det_total.__class__ = TProfile2D # add to summary histogram hist_X0_total.Add(prof2d_X0_det_total.ProjectionXY("B_%s" % prof2d_X0_det_total.GetName()), +1.000 ) # # properties gStyle.SetPalette(1) gStyle.SetStripDecimals(False) # # # Create "null" histo minX = 1.03*hist_X0_total.GetXaxis().GetXmin() maxX = 1.03*hist_X0_total.GetXaxis().GetXmax() minY = 1.03*hist_X0_total.GetYaxis().GetXmin() maxY = 1.03*hist_X0_total.GetYaxis().GetXmax() # Ratio if plots[plot].iRebin: hist_X0_total.Rebin2D() # stack hist2dTitle = ('%s %s;%s;%s;%s' % (plots[plot].quotaName, detector, plots[plot].abscissa, plots[plot].ordinate, plots[plot].quotaName)) hist_X0_total.SetTitle(hist2dTitle) hist_X0_total.SetTitleOffset(0.5,"Y") if plots[plot].histoMin != -1.: hist_X0_total.SetMinimum(plots[plot].histoMin) if plots[plot].histoMax != -1.: hist_X0_total.SetMaximum(plots[plot].histoMax) # can2name = "MBCan_2D_%s_%s" % (detector, plot) can2 = TCanvas(can2name, can2name, 2480+248, 580+58+58) can2.SetTopMargin(0.1) can2.SetBottomMargin(0.1) can2.SetLeftMargin(0.04) can2.SetRightMargin(0.06) can2.SetFillColor(kWhite) gStyle.SetOptStat(0) gStyle.SetTitleFillColor(0) gStyle.SetTitleBorderSize(0) # Color palette gStyle.SetPalette(1) # Log? can2.SetLogz(plots[plot].zLog) # Draw in colors hist_X0_total.Draw("COLZ") # Store can2.Update() #Aesthetic palette = hist_X0_total.GetListOfFunctions().FindObject("palette") if palette: palette.__class__ = TPaletteAxis palette.SetX1NDC(0.945) palette.SetX2NDC(0.96) palette.SetY1NDC(0.1) palette.SetY2NDC(0.9) palette.GetAxis().SetTickSize(.01) palette.GetAxis().SetTitle("") if plots[plot].zLog: palette.GetAxis().SetLabelOffset(-0.01) paletteTitle = TLatex(1.12*maxX, maxY, plots[plot].quotaName) paletteTitle.SetTextAngle(90.) paletteTitle.SetTextSize(0.05) paletteTitle.SetTextAlign(31) paletteTitle.Draw() hist_X0_total.GetYaxis().SetTickLength(hist_X0_total.GetXaxis().GetTickLength()/4.) hist_X0_total.GetYaxis().SetTickLength(hist_X0_total.GetXaxis().GetTickLength()/4.) hist_X0_total.SetTitleOffset(0.5,"Y") hist_X0_total.GetXaxis().SetNoExponent(True) hist_X0_total.GetYaxis().SetNoExponent(True) #Add eta labels keep_alive = [] if plots[plot].iDrawEta: keep_alive.extend(drawEtaValues()) can2.Modified() hist_X0_total.SetContour(255) # Store can2.Update() can2.Modified() can2.SaveAs( "%s/%s_%s_bw.pdf" % (theDirname, detector, plot)) can2.SaveAs( "%s/%s_%s_bw.png" % (theDirname, detector, plot)) gStyle.SetStripDecimals(True)
def createCompoundPlots(detector, plot): """Produce the requested plot for the specified detector. Function that will plot the requested @plot for the specified @detector. The specified detector could either be a real detector or a compound one. The list of available plots are the keys of plots dictionary (imported from plot_utils. """ theDirname = 'Images' if not checkFile_(theDirname): os.mkdir(theDirname) goodToGo, theDetectorFilename = paramsGood_(detector, plot) if not goodToGo: return theDetectorFile = TFile(theDetectorFilename) # # get TProfiles prof_X0_elements = OrderedDict() hist_X0_elements = OrderedDict() for label, [num, color, leg] in six.iteritems(hist_label_to_num): prof_X0_elements[label] = theDetectorFile.Get("%d" % (num + plots[plot].plotNumber)) hist_X0_elements[label] = prof_X0_elements[label].ProjectionX() hist_X0_elements[label].SetFillColor(color) hist_X0_elements[label].SetLineColor(kBlack) files = [] if detector in COMPOUNDS.keys(): for subDetector in COMPOUNDS[detector][1:]: subDetectorFilename = "matbdg_%s.root" % subDetector # open file if not checkFile_(subDetectorFilename): continue subDetectorFile = TFile(subDetectorFilename) files.append(subDetectorFile) print("*** Open file... %s" % subDetectorFilename) # subdetector profiles for label, [num, color, leg] in six.iteritems(hist_label_to_num): prof_X0_elements[label] = subDetectorFile.Get("%d" % (num + plots[plot].plotNumber)) hist_X0_elements[label].Add(prof_X0_elements[label].ProjectionX("B_%s" % prof_X0_elements[label].GetName()) , +1.000) # stack stackTitle = "Material Budget %s;%s;%s" % (detector, plots[plot].abscissa, plots[plot].ordinate) stack_X0 = THStack("stack_X0", stackTitle); for label, [num, color, leg] in six.iteritems(hist_label_to_num): stack_X0.Add(hist_X0_elements[label]) # canvas canname = "MBCan_1D_%s_%s" % (detector, plot) can = TCanvas(canname, canname, 800, 800) can.Range(0,0,25,25) can.SetFillColor(kWhite) gStyle.SetOptStat(0) # Draw stack_X0.Draw("HIST"); # Legenda theLegend = TLegend(0.70, 0.70, 0.89, 0.89); for label, [num, color, leg] in six.iteritems(hist_label_to_num): theLegend.AddEntry(hist_X0_elements[label], leg, "f") theLegend.Draw(); # Store can.Update(); can.SaveAs( "%s/%s_%s.pdf" % (theDirname, detector, plot)) can.SaveAs( "%s/%s_%s.png" % (theDirname, detector, plot))