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 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 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 createPlots_(plot, geometry): """Cumulative material budget from simulation. Internal function that will produce a cumulative profile of the material budget inferred from the simulation starting from the single detectors that compose the tracker. It will iterate over all existing detectors contained in the DETECTORS dictionary. The function will automatically skip non-existent detectors. """ IBs = ["InnerServices", "Phase2PixelBarrel", "TIB", "TIDF", "TIDB"] theDirname = "Figures" if plot not in plots.keys(): print("Error: chosen plot name not known %s" % plot) return hist_X0_detectors = OrderedDict() hist_X0_IB = None hist_X0_elements = OrderedDict() for subDetector,color in six.iteritems(DETECTORS): h = get1DHisto_(subDetector,plots[plot].plotNumber,geometry) if not h: print('Warning: Skipping %s'%subDetector) continue hist_X0_detectors[subDetector] = h # Merge together the "inner barrel detectors". if subDetector in IBs: hist_X0_IB = assignOrAddIfExists_( hist_X0_IB, hist_X0_detectors[subDetector] ) # category profiles for label, [num, color, leg] in six.iteritems(hist_label_to_num): if label is 'SUM': continue hist_label = get1DHisto_(subDetector, num + plots[plot].plotNumber, geometry) hist_X0_elements[label] = assignOrAddIfExists_( hist_X0_elements.setdefault(label,None), hist_label, ) hist_X0_elements[label].SetFillColor(color) cumulative_matbdg = TH1D("CumulativeSimulMatBdg", "CumulativeSimulMatBdg", hist_X0_IB.GetNbinsX(), hist_X0_IB.GetXaxis().GetXmin(), hist_X0_IB.GetXaxis().GetXmax()) cumulative_matbdg.SetDirectory(0) # colors for det, color in six.iteritems(DETECTORS): setColorIfExists_(hist_X0_detectors, det, color) # First Plot: BeamPipe + Pixel + TIB/TID + TOB + TEC + Outside # stack stackTitle_SubDetectors = "Tracker Material Budget;%s;%s" % ( plots[plot].abscissa,plots[plot].ordinate) stack_X0_SubDetectors = THStack("stack_X0",stackTitle_SubDetectors) for det, histo in six.iteritems(hist_X0_detectors): stack_X0_SubDetectors.Add(histo) cumulative_matbdg.Add(histo, 1) # canvas can_SubDetectors = TCanvas("can_SubDetectors","can_SubDetectors",800,800) can_SubDetectors.Range(0,0,25,25) can_SubDetectors.SetFillColor(kWhite) # Draw stack_X0_SubDetectors.SetMinimum(plots[plot].ymin) stack_X0_SubDetectors.SetMaximum(plots[plot].ymax) stack_X0_SubDetectors.Draw("HIST") stack_X0_SubDetectors.GetXaxis().SetLimits(plots[plot].xmin, plots[plot].xmax) # Legenda theLegend_SubDetectors = TLegend(0.180,0.8,0.98,0.92) theLegend_SubDetectors.SetNColumns(3) theLegend_SubDetectors.SetFillColor(0) theLegend_SubDetectors.SetFillStyle(0) theLegend_SubDetectors.SetBorderSize(0) for det, histo in six.iteritems(hist_X0_detectors): theLegend_SubDetectors.AddEntry(histo, det, "f") theLegend_SubDetectors.Draw() # text text_SubDetectors = TPaveText(0.180,0.727,0.402,0.787,"NDC") text_SubDetectors.SetFillColor(0) text_SubDetectors.SetBorderSize(0) text_SubDetectors.AddText("CMS Simulation") text_SubDetectors.SetTextAlign(11) text_SubDetectors.Draw() # Store can_SubDetectors.Update() if not checkFile_(theDirname): os.mkdir(theDirname) can_SubDetectors.SaveAs("%s/Tracker_SubDetectors_%s.pdf" % (theDirname, plot)) can_SubDetectors.SaveAs("%s/Tracker_SubDetectors_%s.root" % (theDirname, plot)) # Second Plot: BeamPipe + SEN + ELE + CAB + COL + SUP + OTH/AIR + # Outside stack stackTitle_Materials = "Tracker Material Budget;%s;%s" % (plots[plot].abscissa, plots[plot].ordinate) stack_X0_Materials = THStack("stack_X0",stackTitle_Materials) stack_X0_Materials.Add(hist_X0_detectors["BeamPipe"]) for label, [num, color, leg] in six.iteritems(hist_label_to_num): if label is 'SUM': continue stack_X0_Materials.Add(hist_X0_elements[label]) # canvas can_Materials = TCanvas("can_Materials","can_Materials",800,800) can_Materials.Range(0,0,25,25) can_Materials.SetFillColor(kWhite) # Draw stack_X0_Materials.SetMinimum(plots[plot].ymin) stack_X0_Materials.SetMaximum(plots[plot].ymax) stack_X0_Materials.Draw("HIST") stack_X0_Materials.GetXaxis().SetLimits(plots[plot].xmin, plots[plot].xmax) # Legenda theLegend_Materials = TLegend(0.180,0.8,0.95,0.92) theLegend_Materials.SetNColumns(3) theLegend_Materials.SetFillColor(0) theLegend_Materials.SetBorderSize(0) theLegend_Materials.AddEntry(hist_X0_detectors["BeamPipe"], "Beam Pipe", "f") for label, [num, color, leg] in six.iteritems(hist_label_to_num): if label is 'SUM': continue theLegend_Materials.AddEntry(hist_X0_elements[label], leg, "f") theLegend_Materials.Draw() # text text_Materials = TPaveText(0.180,0.727,0.402,0.787,"NDC") text_Materials.SetFillColor(0) text_Materials.SetBorderSize(0) text_Materials.AddText("CMS Simulation") text_Materials.SetTextAlign(11) text_Materials.Draw() # Store can_Materials.Update() can_Materials.SaveAs("%s/Tracker_Materials_%s.pdf" % (theDirname, plot)) can_Materials.SaveAs("%s/Tracker_Materials_%s.root" % (theDirname, plot)) return cumulative_matbdg
def createPlots_(plot, geometry): """Cumulative material budget from simulation. Internal function that will produce a cumulative profile of the material budget inferred from the simulation starting from the single detectors that compose the tracker. It will iterate over all existing detectors contained in the DETECTORS dictionary. The function will automatically skip non-existent detectors. """ IBs = ["InnerServices", "Phase2PixelBarrel", "TIB", "TIDF", "TIDB"] theDirname = "Figures" if plot not in plots.keys(): print("Error: chosen plot name not known %s" % plot) return hist_X0_detectors = OrderedDict() hist_X0_IB = None hist_X0_elements = OrderedDict() for subDetector,color in six.iteritems(DETECTORS): h = get1DHisto_(subDetector,plots[plot].plotNumber,geometry) if not h: print('Warning: Skipping %s'%subDetector) continue hist_X0_detectors[subDetector] = h # Merge together the "inner barrel detectors". if subDetector in IBs: hist_X0_IB = assignOrAddIfExists_( hist_X0_IB, hist_X0_detectors[subDetector] ) # category profiles for label, [num, color, leg] in six.iteritems(hist_label_to_num): if label is 'SUM': continue hist_label = get1DHisto_(subDetector, num + plots[plot].plotNumber, geometry) hist_X0_elements[label] = assignOrAddIfExists_( hist_X0_elements.setdefault(label,None), hist_label, ) hist_X0_elements[label].SetFillColor(color) cumulative_matbdg = TH1D("CumulativeSimulMatBdg", "CumulativeSimulMatBdg", hist_X0_IB.GetNbinsX(), hist_X0_IB.GetXaxis().GetXmin(), hist_X0_IB.GetXaxis().GetXmax()) cumulative_matbdg.SetDirectory(0) # colors for det, color in six.iteritems(DETECTORS): setColorIfExists_(hist_X0_detectors, det, color) # First Plot: BeamPipe + Pixel + TIB/TID + TOB + TEC + Outside # stack stackTitle_SubDetectors = "Tracker Material Budget;%s;%s" % ( plots[plot].abscissa,plots[plot].ordinate) stack_X0_SubDetectors = THStack("stack_X0",stackTitle_SubDetectors) for det, histo in six.iteritems(hist_X0_detectors): stack_X0_SubDetectors.Add(histo) cumulative_matbdg.Add(histo, 1) # canvas can_SubDetectors = TCanvas("can_SubDetectors","can_SubDetectors",800,800) can_SubDetectors.Range(0,0,25,25) can_SubDetectors.SetFillColor(kWhite) # Draw stack_X0_SubDetectors.SetMinimum(plots[plot].ymin) stack_X0_SubDetectors.SetMaximum(plots[plot].ymax) stack_X0_SubDetectors.Draw("HIST") stack_X0_SubDetectors.GetXaxis().SetLimits(plots[plot].xmin, plots[plot].xmax) # Legenda theLegend_SubDetectors = TLegend(0.180,0.8,0.98,0.92) theLegend_SubDetectors.SetNColumns(3) theLegend_SubDetectors.SetFillColor(0) theLegend_SubDetectors.SetFillStyle(0) theLegend_SubDetectors.SetBorderSize(0) for det, histo in six.iteritems(hist_X0_detectors): theLegend_SubDetectors.AddEntry(histo, det, "f") theLegend_SubDetectors.Draw() # text text_SubDetectors = TPaveText(0.180,0.727,0.402,0.787,"NDC") text_SubDetectors.SetFillColor(0) text_SubDetectors.SetBorderSize(0) text_SubDetectors.AddText("CMS Simulation") text_SubDetectors.SetTextAlign(11) text_SubDetectors.Draw() # Store can_SubDetectors.Update() if not checkFile_(theDirname): os.mkdir(theDirname) can_SubDetectors.SaveAs("%s/Tracker_SubDetectors_%s.pdf" % (theDirname, plot)) can_SubDetectors.SaveAs("%s/Tracker_SubDetectors_%s.root" % (theDirname, plot)) # Second Plot: BeamPipe + SEN + ELE + CAB + COL + SUP + OTH/AIR + # Outside stack stackTitle_Materials = "Tracker Material Budget;%s;%s" % (plots[plot].abscissa, plots[plot].ordinate) stack_X0_Materials = THStack("stack_X0",stackTitle_Materials) stack_X0_Materials.Add(hist_X0_detectors["BeamPipe"]) for label, [num, color, leg] in six.iteritems(hist_label_to_num): if label is 'SUM': continue stack_X0_Materials.Add(hist_X0_elements[label]) # canvas can_Materials = TCanvas("can_Materials","can_Materials",800,800) can_Materials.Range(0,0,25,25) can_Materials.SetFillColor(kWhite) # Draw stack_X0_Materials.SetMinimum(plots[plot].ymin) stack_X0_Materials.SetMaximum(plots[plot].ymax) stack_X0_Materials.Draw("HIST") stack_X0_Materials.GetXaxis().SetLimits(plots[plot].xmin, plots[plot].xmax) # Legenda theLegend_Materials = TLegend(0.180,0.8,0.95,0.92) theLegend_Materials.SetNColumns(3) theLegend_Materials.SetFillColor(0) theLegend_Materials.SetBorderSize(0) theLegend_Materials.AddEntry(hist_X0_detectors["BeamPipe"], "Beam Pipe", "f") for label, [num, color, leg] in six.iteritems(hist_label_to_num): if label is 'SUM': continue theLegend_Materials.AddEntry(hist_X0_elements[label], leg, "f") theLegend_Materials.Draw() # text text_Materials = TPaveText(0.180,0.727,0.402,0.787,"NDC") text_Materials.SetFillColor(0) text_Materials.SetBorderSize(0) text_Materials.AddText("CMS Simulation") text_Materials.SetTextAlign(11) text_Materials.Draw() # Store can_Materials.Update() can_Materials.SaveAs("%s/Tracker_Materials_%s.pdf" % (theDirname, plot)) can_Materials.SaveAs("%s/Tracker_Materials_%s.root" % (theDirname, plot)) return cumulative_matbdg