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 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 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' % (10000 + 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' % (10000 + 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, plotnum, plotmat, dosingledetector=True): """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. """ #gStyle.Reset() #Better to use an underscore. plotmat = plotmat.replace(" ", "_") if plotmat != "": theDirname = ('Images/%s' % plotmat).replace(" ", "") else: theDirname = 'Images' if not checkFile_(theDirname): os.mkdir(theDirname) if not os.path.isdir(('Images/%s/ZPlusZoom' % plotmat).replace(" ", "")): os.mkdir(('Images/%s/ZPlusZoom' % plotmat).replace(" ", "")) if not os.path.isdir(('Images/%s/ZMinusZoom' % plotmat).replace(" ", "")): os.mkdir(('Images/%s/ZMinusZoom' % plotmat).replace(" ", "")) goodToGo, theDetectorFilename = paramsGood_(detector, plot) if not goodToGo: return theDetectorFile = TFile(theDetectorFilename) prof2d_X0_det_total = TProfile2D() prof2d_X0_det_total.Reset() # get TProfiles #prof2d_X0_det_total = theDetectorFile.Get('%s' % plots[plot].plotNumber) prof2d_X0_det_total = theDetectorFile.Get('%s' % plotnum) print "==================================================================" print plotnum # 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() and not dosingledetector: #When the loop was: #for subDetector in COMPOUNDS[detector][1:]: #and the detector was single it never went in the loop and read the single file #from above. I alter this to COMPOUNDS[detector] to do the multi material budget plot. #This won't effect the single detector due to the alter in the if above for subDetector in COMPOUNDS[detector]: # 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 * prof2d_X0_det_total.GetXaxis().GetXmin() maxX = 1.03 * prof2d_X0_det_total.GetXaxis().GetXmax() minY = 1.03 * prof2d_X0_det_total.GetYaxis().GetXmin() maxY = 1.03 * prof2d_X0_det_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: prof2d_X0_det_total.Rebin2D() # stack hist2dTitle = ('%s %s;%s;%s;%s' % (plots[plot].quotaName, detector, plots[plot].abscissa, plots[plot].ordinate, plots[plot].quotaName)) if dosingledetector: hist2d_X0_total = prof2d_X0_det_total else: hist2d_X0_total = hist_X0_total hist2d_X0_total.SetTitle(hist2dTitle) frame.SetTitle(hist2dTitle) frame.SetTitleOffset(0.5, "Y") #If here you put different histomin,histomaxin plot_utils you won't see anything #for the material plots. 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_%s" % (detector, plot, plotmat) 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) #hist2d_X0_total.SetMaximum(hist2d_X0_total.GetMaximum()) # Color palette # gStyle.SetPalette()#1 acustompalette() ex1 = TExec("ex1", "acustompalette();") ex1.Draw() #for i in range(100): MyPaletteArray.append(i+1) #gStyle.SetPalette(first_color_number); # Log? can2.SetLogz(plots[plot].zLog) # Draw in colors #frame.Draw() #hist2d_X0_total.Draw("COLZsame") #Dummy draw to create the palette object hist2d_X0_total.Draw("COLZ") #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.GetYaxis().SetTitleOffset(0.45) #hist2d_X0_total.GetXaxis().SetTitleOffset(1.15); #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%s.pdf" % (theDirname, detector, plot, plotmat)) can2.SaveAs("%s/%s_%s%s.png" % (theDirname, detector, plot, plotmat)) #can2.SaveAs( "%s/%s_%s%s.root" % (theDirname, detector, plot, plotmat)) #Zoom in a little bit if plot == "x_vs_z_vs_Rsum" or plot == "l_vs_z_vs_Rsum" or plot == "x_vs_z_vs_Rsumcos" or plot == "l_vs_z_vs_Rsumcos" or plot == "x_vs_z_vs_Rloc" or plot == "l_vs_z_vs_Rloc" or plot == "x_vs_z_vs_Rloccos" or plot == "l_vs_z_vs_Rloccos": #Z+ #hist2d_X0_total.GetXaxis().SetLimits( 3100., 5200.) if dosingledetector: hist2d_X0_total.GetXaxis().SetRangeUser(3100., 5400.) else: hist2d_X0_total.GetXaxis().SetRangeUser(0., 7000.) #Do not draw eta values in the zoom case keep_alive = [] #hist2d_X0_total.Draw("COLZ") can2.Update() can2.Modified() can2.SaveAs("%s/%s/%s_%s%s_ZplusZoom.pdf" % (theDirname, "ZPlusZoom", detector, plot, plotmat)) can2.SaveAs("%s/%s/%s_%s%s_ZplusZoom.png" % (theDirname, "ZPlusZoom", detector, plot, plotmat)) #Z- #hist2d_X0_total.GetXaxis().SetLimits( 3100., 5200.) if dosingledetector: hist2d_X0_total.GetXaxis().SetRangeUser(-5400., -3100.) else: hist2d_X0_total.GetXaxis().SetRangeUser(0., -7000.) #Do not draw eta values in the zoom case keep_alive = [] #hist2d_X0_total.Draw("COLZ") can2.Update() can2.Modified() can2.SaveAs("%s/%s/%s_%s%s_ZminusZoom.pdf" % (theDirname, "ZMinusZoom", detector, plot, plotmat)) can2.SaveAs("%s/%s/%s_%s%s_ZminusZoom.png" % (theDirname, "ZMinusZoom", detector, plot, plotmat)) 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 hist_label_to_num.iteritems(): #print label, num, color, leg 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 hist_label_to_num.iteritems(): 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 hist_label_to_num.iteritems(): 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) gStyle.SetOptTitle(1) # Draw stack_X0.Draw("HIST") stack_X0.GetYaxis().SetTitleOffset(1.15) # Legenda theLegend = TLegend(0.40, 0.65, 0.60, 0.89) if plot == "x_vs_phi" or plot == "l_vs_phi": theLegend = TLegend(0.65, 0.30, 0.89, 0.70) if plot == "x_vs_R" or plot == "l_vs_R": theLegend = TLegend(0.75, 0.60, 0.95, 0.90) for label, [num, color, leg] in hist_label_to_num.iteritems(): 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)) #Let's also save the total accumulated budget vs eta since muon id relies #on adequate calorimeter thickness if plot == "x_vs_eta" or plot == "l_vs_eta": canname = "MBCan_1D_%s_%s_total" % (detector, plot) can2 = TCanvas(canname, canname, 800, 800) can2.Range(0, 0, 25, 25) can2.SetFillColor(kWhite) gStyle.SetOptStat(0) gStyle.SetOptTitle(0) #title = TPaveLabel(.11,.95,.35,.99,"Total accumulated material budget","brndc") stack_X0.GetStack().Last().GetXaxis().SetRangeUser(0., 3.) stack_X0.GetStack().Last().Draw() stack_X0.GetYaxis().SetTitleOffset(1.15) can2.Update() can2.Modified() can2.SaveAs("%s/%s_%s_total_Zplus.pdf" % (theDirname, detector, plot)) can2.SaveAs("%s/%s_%s_total_Zplus.png" % (theDirname, detector, plot)) stack_X0.GetStack().Last().GetXaxis().SetRangeUser(-3., 0.) stack_X0.GetStack().Last().Draw() stack_X0.GetYaxis().SetTitleOffset(1.15) can2.Update() can2.Modified() can2.SaveAs("%s/%s_%s_total_Zminus.pdf" % (theDirname, detector, plot)) can2.SaveAs("%s/%s_%s_total_Zminus.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' % (10000+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' % (10000+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, plotnum, plotmat): """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. """ #gStyle.Reset() #Better to use an underscore. plotmat = plotmat.replace(" ", "_") if plotmat != "": theDirname = ('Images/%s' % plotmat).replace(" ", "") else: theDirname = 'Images' if not checkFile_(theDirname): os.mkdir(theDirname) if not os.path.isdir(('Images/%s/ZPlusZoom' % plotmat).replace(" ", "")): os.mkdir( ('Images/%s/ZPlusZoom' % plotmat).replace(" ", "") ) if not os.path.isdir(('Images/%s/ZMinusZoom' % plotmat).replace(" ", "")): os.mkdir( ('Images/%s/ZMinusZoom' % plotmat).replace(" ", "") ) goodToGo, theDetectorFilename = paramsGood_(detector, plot) if not goodToGo: return theDetectorFile = TFile(theDetectorFilename) prof2d_X0_det_total = TProfile2D() prof2d_X0_det_total.Reset() # get TProfiles #prof2d_X0_det_total = theDetectorFile.Get('%s' % plots[plot].plotNumber) prof2d_X0_det_total = theDetectorFile.Get('%s' % plotnum) print "==================================================================" print plotnum # 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*prof2d_X0_det_total.GetXaxis().GetXmin() maxX = 1.03*prof2d_X0_det_total.GetXaxis().GetXmax() minY = 1.03*prof2d_X0_det_total.GetYaxis().GetXmin() maxY = 1.03*prof2d_X0_det_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: prof2d_X0_det_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 = prof2d_X0_det_total hist2d_X0_total.SetTitle(hist2dTitle) frame.SetTitle(hist2dTitle) frame.SetTitleOffset(0.5,"Y") #If here you put different histomin,histomaxin plot_utils you won't see anything #for the material plots. 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_%s" % (detector, plot, plotmat) 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) #hist2d_X0_total.SetMaximum(hist2d_X0_total.GetMaximum()) # Color palette # gStyle.SetPalette()#1 acustompalette() ex1 = TExec("ex1","acustompalette();"); ex1.Draw(); #for i in range(100): MyPaletteArray.append(i+1) #gStyle.SetPalette(first_color_number); # Log? can2.SetLogz(plots[plot].zLog) # Draw in colors #frame.Draw() #hist2d_X0_total.Draw("COLZsame") #Dummy draw to create the palette object hist2d_X0_total.Draw("COLZ") #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.GetYaxis().SetTitleOffset(0.45); #hist2d_X0_total.GetXaxis().SetTitleOffset(1.15); #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%s.pdf" % (theDirname, detector, plot, plotmat)) can2.SaveAs( "%s/%s_%s%s.png" % (theDirname, detector, plot, plotmat)) #can2.SaveAs( "%s/%s_%s%s.root" % (theDirname, detector, plot, plotmat)) #Zoom in a little bit if plot == "x_vs_z_vs_Rsum" or plot == "l_vs_z_vs_Rsum" or plot == "x_vs_z_vs_Rsumcos" or plot == "l_vs_z_vs_Rsumcos" or plot == "x_vs_z_vs_Rloc" or plot == "l_vs_z_vs_Rloc" or plot == "x_vs_z_vs_Rloccos" or plot == "l_vs_z_vs_Rloccos": #Z+ #hist2d_X0_total.GetXaxis().SetLimits( 3100., 5200.) hist2d_X0_total.GetXaxis().SetRangeUser( 3100., 5400.) #Do not draw eta values in the zoom case keep_alive = [] #hist2d_X0_total.Draw("COLZ") can2.Update() can2.Modified() can2.SaveAs( "%s/%s/%s_%s%s_ZplusZoom.pdf" % (theDirname, "ZPlusZoom", detector, plot, plotmat)) can2.SaveAs( "%s/%s/%s_%s%s_ZplusZoom.png" % (theDirname, "ZPlusZoom", detector, plot, plotmat)) #Z- #hist2d_X0_total.GetXaxis().SetLimits( 3100., 5200.) hist2d_X0_total.GetXaxis().SetRangeUser( -5400., -3100.) #Do not draw eta values in the zoom case keep_alive = [] #hist2d_X0_total.Draw("COLZ") can2.Update() can2.Modified() can2.SaveAs( "%s/%s/%s_%s%s_ZminusZoom.pdf" % (theDirname, "ZMinusZoom", detector, plot, plotmat)) can2.SaveAs( "%s/%s/%s_%s%s_ZminusZoom.png" % (theDirname, "ZMinusZoom", detector, plot, plotmat)) 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 hist_label_to_num.iteritems(): #print label, num, color, leg 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 hist_label_to_num.iteritems(): 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 hist_label_to_num.iteritems(): 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) gStyle.SetOptTitle(1); # Draw stack_X0.Draw("HIST"); stack_X0.GetYaxis().SetTitleOffset(1.15); # Legenda theLegend = TLegend(0.40, 0.65, 0.60, 0.89) if plot == "x_vs_phi" or plot == "l_vs_phi": theLegend = TLegend(0.65, 0.30, 0.89, 0.70) if plot == "x_vs_R" or plot == "l_vs_R": theLegend = TLegend(0.75, 0.60, 0.95, 0.90) for label, [num, color, leg] in hist_label_to_num.iteritems(): 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)) #Let's also save the total accumulated budget vs eta since muon id relies #on adequate calorimeter thickness if plot == "x_vs_eta" or plot == "l_vs_eta": canname = "MBCan_1D_%s_%s_total" % (detector, plot) can2 = TCanvas(canname, canname, 800, 800) can2.Range(0,0,25,25) can2.SetFillColor(kWhite) gStyle.SetOptStat(0) gStyle.SetOptTitle(0); #title = TPaveLabel(.11,.95,.35,.99,"Total accumulated material budget","brndc") stack_X0.GetStack().Last().GetXaxis().SetRangeUser( 0., 3.) stack_X0.GetStack().Last().Draw(); stack_X0.GetYaxis().SetTitleOffset(1.15); can2.Update() can2.Modified() can2.SaveAs("%s/%s_%s_total_Zplus.pdf" % (theDirname, detector, plot)) can2.SaveAs("%s/%s_%s_total_Zplus.png" % (theDirname, detector, plot)) stack_X0.GetStack().Last().GetXaxis().SetRangeUser( -3., 0.) stack_X0.GetStack().Last().Draw(); stack_X0.GetYaxis().SetTitleOffset(1.15); can2.Update() can2.Modified() can2.SaveAs("%s/%s_%s_total_Zminus.pdf" % (theDirname, detector, plot)) can2.SaveAs("%s/%s_%s_total_Zminus.png" % (theDirname, detector, plot))