def plotGBLvsSeedResiduals(t_file, half): names = hps_utils.getSensorNames() print ' got ', len(names), ' sensor names' hname = 'h_res_diff_gbl_seed_' #h_res_diff_gbl_seed_module_L4b_halfmodule_axial_hole_sensor0_bot c = TCanvas('c','c',10,10,700,500) for sensorname in names: name = hname + sensorname if half != '': if half == 'top' and hps_utils.getHalf(sensorname) != 't': continue if half == 'bot' and hps_utils.getHalf(sensorname) != 'b': continue name += '_' + half if args.regexp != None: m = re.match(args.regexp, name) if m == None: print 'skip this histogram \"', name, '\"' continue h = t_file.Get(name) if h == None: print 'no histogram \"', name, '\"' sys.exit(1) print 'process \"', name , '\"' c.Clear() h.Draw('colz') c.SaveAs(name + '-' + args.tag + '.png')
def isTop(self): """Check if this is a track in the top half of the detector.""" if len(self.strips) == 0: raise HpsGblException('There are no strips on this track so this question makes no sense.') # the check method should have been called already so no point doing that. The below should be safe then. # get string representation h = getHalf(self.strips[0].deName) # check that it makes sense if h != 't' and h != 'b': raise HpsGblException('This half \"' + h + '\" is weird?') return h == 't'
def check(self): """Check consistency of this track. """ # check that all hits are in the same half halfcount = {} for strip in self.strips: h = getHalf(strip.deName) if h in halfcount: halfcount[h] += 1 else: halfcount[h] = 0 if len(halfcount) != 1: raise HpsGblException('this track has strips from both sides?\n' + halfcount) # check that the correct nr of parameters exist if len(self.clPar) != 5 or len(self.perPar) != 4: raise HpsGblException('this track has wrong number of parameters?\n' + clPar + '\n' + perPar) # check dimenstion of transformation if self.perToClPrj == None: raise HpsGblException('this track has no CL projection matrix?') elif np.size( self.perToClPrj ) != 9: raise HpsGblException('this projection matrix has wrong dimenstions ' + np.size( self.perToClPrj ) )
def compareSensorHists(files,histName,tag='',half=None,singleCanvas=None,beamspot=False,legends=None): print 'compareSensorHists for ', len(files), ' for histName ', histName, ' tag ', tag, ' beamspot ', beamspot sensorHistNames = [] sensors = hps_utils.getSensorNames(beamspot) for s in sensors: if hps_utils.getLayer > 3 and hps_utils.getHoleSlot(s) == 'slot': continue #if hps_utils.getHalf(s) != 'b' or hps_utils.getLayer(s) !=2 or hps_utils.getAxialStereo(s) != 'axial': # continue #if hps_utils.getHalf(s) != 't' or hps_utils.getLayer(s) !=6 or hps_utils.getHoleSlot(s) != 'slot' and hps_utils.getAxialStereo(s) != 'slot': # continue #if beamspot and hps_utils.getLayer(s)==0: # if hps_utils.getHalf(s) != 'b': # print 'this beamspot sensor is weird! ', s # sys.exit(1) if hps_utils.getHalf(s) == 't' and half != 'top': continue if hps_utils.getHalf(s) == 'b' and half != 'bottom': continue addOn = '' if hps_utils.getHalf(s) == 't': addOn = '_top' else: addOn = '_bot' sensorHistNames.append(histName + s + addOn) print sensorHistNames print 'open TFiles' tFiles = [] for f in files: tFiles.append(TFile(f)) print 'opened ', len(tFiles) c = None print 'singleCanvas ', singleCanvas if singleCanvas != None: cName = 'c_' + histName + '_' + half + '_' + tag c = TCanvas(cName, cName, 10, 10, 690*2, 390*2) c.Divide(2,12) currentPad = None graphBinNames = {} graphMean = [] graphRMS = [] for tf in tFiles: print 'tf ', tf.GetName() grM = TGraphErrors() grM.SetName('grMean_' + tf.GetName()) grR = TGraphErrors() grR.SetName('grRMS_' + tf.GetName()) graphMean.append( grM ) graphRMS.append( grR ) for hName in sensorHistNames: histos = [] print 'get ', hName for tf in tFiles: print 'tf ', tf.GetName() h = tf.Get(hName) histos.append(h) print 'compare ', len(histos),' root histos' if c != None: i = hps_utils.getCanvasIdxTwoCols(hName,beamspot) currentPad = c.cd(i) print currentPad compareRootHists.compareHists(histos,legends=legends,normalize=True,fitName={'name':'gaus','rms':2},t=tag,pad=currentPad,myTextSize=0.1) print 'make graphs of mean and RMS' for ih in range(len(histos)): h = histos[ih] f = h.GetFunction('fg_' + h.GetName()) if f != None: mean = f.GetParameter(1) meanError = f.GetParError(1) rms = f.GetParameter(2) rmsError = f.GetParError(2) ipoint = graphMean[ih].GetN() graphMean[ih].SetPoint(ipoint, ipoint, mean) graphRMS[ih].SetPoint(ipoint, ipoint, rms) graphMean[ih].SetPointError(ipoint, 0., meanError) graphRMS[ih].SetPointError(ipoint, 0., rmsError) graphBinNames[ ipoint ] = hps_utils.getshortsensorname( hName ) print 'mean ', mean, ' RMS ', rms, ' fg ', f.GetName() else: print 'No fg in histo ', ih, ' name ', h.GetName() print 'done comparing ', len(histos),' root histos' if c != None: c.SaveAs(cName + '.png') cGrName = 'c_summary' + histName + '_' + half + '_' + tag cGr = TCanvas(cGrName, cGrName, 10, 10, 690*2, 390*2) cGr.Divide(1,2) grMaxValMean = -1000000. grMaxValRMS = -10000000. grMinValMean = 1000000. grMinValRMS = 10000000. for igr in range(len(graphMean)): grM = graphMean[ igr ] grR = graphRMS [ igr ] limVals = plotutils.getGraphMaxMinVal(grM) print limVals if limVals[1] > grMaxValMean: grMaxValMean = limVals[1] if limVals[0] < grMinValMean: grMinValMean = limVals[0] limVals = plotutils.getGraphMaxMinVal(grR) if limVals[1] > grMaxValRMS: grMaxValRMS = limVals[1] if limVals[0] < grMinValMean: grMinValRMS = limVals[0] print grMaxValMean, grMinValMean for igr in range(len(graphMean)): grM = graphMean[ igr ] grR = graphRMS [ igr ] #print 'igr ', igr, ' name ', grM.GetName() plotutils.setGraphStyle(grM,igr+1) plotutils.setGraphStyle(grR,igr+1) plotutils.setBinLabelsDict(grM,graphBinNames) plotutils.setBinLabelsDict(grR,graphBinNames) if igr == 0: cGr.cd(1) gPad.SetBottomMargin(0.3) grM.GetHistogram().SetMaximum(grMaxValMean*1.2) grM.GetHistogram().SetMinimum(grMinValMean*1.2) grM.Draw('AXPL') cGr.cd(2) gPad.SetBottomMargin(0.3) grR.SetMaximum(grMaxValRMS) grR.SetMinimum(grMinValRMS) grR.Draw('AXPL') else: cGr.cd(1) grM.Draw('PL,same') cGr.cd(2) grR.Draw('PL,same') if legends: styles = [ 'PL' for x in range( len( graphMean ) ) ] l = plotutils.getLegendList(0.13,0.75,0.25,0.85,graphMean,legends,styles) l.Draw() cGr.SaveAs(cGr.GetName() + '.png') #ans = raw_input('press anything') for tf in tFiles: print 'closing ', tf.GetName() tf.Close() return
def plot_residuals(tFile,hist_name,half,side,maxminlist): #module_L6b_halfmodule_axial_hole_sensor0_hitresglobal #module_L1t_halfmodule_axial_sensor0_hitresglobal names = hps_utils.get_module_names() print 'found ', len(names), ' histogram names' graphBinNames = [] graphMean = TGraphErrors() graphMean.SetName('grMean_' + half) graphRMS = TGraphErrors() graphRMS.SetName('grRMS_' + half) for h_name in [hist_name]: for m_name in names: m_half = hps_utils.getHalf(m_name) if half != '' and m_half != half: continue if hps_utils.getAxialStereo(m_name) == 'stereo': continue if hps_utils.getLayer(m_name) > 3: if side != '' and hps_utils.getHoleSlot(m_name) != side: continue name = m_name + '_' + h_name h = t_file.Get(name) if h == None: print 'no histogram name \"', name, '\" found' print 'got hist \"', h.GetName(), '\"' c = TCanvas('c_' + name, 'c_' + name,10,10,1400,900) if h.GetEntries() > 10: fitFuncName = 'fg_' + h.GetName() fitOpt = 'R' fg = TF1(fitFuncName,'gaus') bc = plotutils.getHistMaxBinValue(h) rms = h.GetRMS() fg.SetParameter(1,bc) fg.SetParameter(2,rms) fg.SetRange( bc - rms*2, bc + rms*2 ) h.Fit(fg,fitOpt) #print 'make graphs of mean and RMS' mean = fg.GetParameter(1) meanError = fg.GetParError(1) rms = fg.GetParameter(2) rmsError = fg.GetParError(2) ipoint = graphMean.GetN() graphMean.SetPoint(ipoint, ipoint, mean) graphRMS.SetPoint(ipoint, ipoint, rms) graphMean.SetPointError(ipoint, 0., meanError) graphRMS.SetPointError(ipoint, 0., rmsError) graphBinNames.append(hps_utils.getshortsensorname( m_name ) ) print 'mean ', mean, '+-',meanError,' RMS ', rms, '+-', rmsError, ' fg ', fg.GetName() else: print 'Not enough entries for histogram \"', name, '\"' h.Draw() #ans = raw_input('continue?') saveName = name c.SaveAs(saveName + '.png') c = TCanvas('c_' + hist_name +'_mean_'+half+'_'+side, 'c_' + hist_name +'_mean_'+half+'_'+side,10,10,1400,900) c.Divide(1,2) c.cd(1) gPad.SetBottomMargin(0.3) gPad.SetGridy() plotutils.setBinLabels(graphMean,graphBinNames) plotutils.setGraphStyle(graphMean) graphMean.SetTitle(hist_name+';;Track residual mean (mm)') if len(maxminlist) == 4: graphMean.GetHistogram().SetMaximum(maxminlist[0]) graphMean.GetHistogram().SetMinimum(maxminlist[1]) graphMean.Draw('APL') c.cd(2) gPad.SetBottomMargin(0.3) gPad.SetGridy() plotutils.setBinLabels(graphRMS,graphBinNames) plotutils.setGraphStyle(graphRMS) graphRMS.SetTitle(';;Axial track residual width (mm)') if len(maxminlist) == 4: graphRMS.GetHistogram().SetMaximum(maxminlist[2]) graphRMS.GetHistogram().SetMinimum(maxminlist[3]) graphRMS.Draw('APL') c.SaveAs('summary_' + hist_name+'_mean_'+half+'_'+side +'.png') ans = raw_input('continue?')
def plot_sensor_hist(tFile,hist_name,half,maxminlist): names = hps_utils.get_module_names() print 'found ', len(names), ' sensor names' graphBinNames = [] graphMean = TGraphErrors() graphMean.SetName('grMean_' + half) graphRMS = TGraphErrors() graphRMS.SetName('grRMS_' + half) for h_name in [hist_name]: print 'Process histogram \"', h_name, '\"' for m_name in names: print 'Sensor \"', m_name, '\"' m_half = hps_utils.getHalf(m_name) if half != '' and m_half != half: continue name = m_name + h_name if args.regexp != None: if debug: print 'apply regexp \"', args.regexp, '\" to file \"', name, '\"' m = re.match(args.regexp, name) if m == None: if debug: print 'no match for regexp \"', args.regexp, '\" for \"', name, '\"' continue print 'Try to find histogram \"', name, '\"' h = t_file.Get(name) if h == None: print 'no histogram name \"', name, '\" found' else: print 'got hist \"', h.GetName(), '\"' c = TCanvas('c_' + name, 'c_' + name,10,10,1400,900) if h.GetEntries() > 10: fitFuncName = 'fg_' + h.GetName() fitOpt = 'R' fg = TF1(fitFuncName,'gaus') bc = plotutils.getHistMaxBinValue(h) rms = h.GetRMS() fg.SetParameter(1,bc) fg.SetParameter(2,rms) fg.SetRange( bc - rms*2, bc + rms*2 ) h.Fit(fg,fitOpt) #print 'make graphs of mean and RMS' mean = fg.GetParameter(1) meanError = fg.GetParError(1) rms = fg.GetParameter(2) rmsError = fg.GetParError(2) ipoint = graphMean.GetN() graphMean.SetPoint(ipoint, ipoint, mean) graphRMS.SetPoint(ipoint, ipoint, rms) graphMean.SetPointError(ipoint, 0., meanError) graphRMS.SetPointError(ipoint, 0., rmsError) graphBinNames.append(hps_utils.getshortsensorname( m_name ) ) print 'mean ', mean, '+-',meanError,' RMS ', rms, '+-', rmsError, ' fg ', fg.GetName() else: print 'Not enough entries for histogram \"', name, '\"' h.Draw() #ans = raw_input('continue?') saveName = name c.SaveAs(saveName + '.png') c = TCanvas('c_' + hist_name +'_mean_'+half, 'c_' + hist_name +'_mean_'+half,10,10,1400,900) c.Divide(1,2) c.cd(1) gPad.SetBottomMargin(0.3) gPad.SetGridy() plotutils.setBinLabels(graphMean,graphBinNames) plotutils.setGraphStyle(graphMean) graphMean.SetTitle(hist_name+';;Mean') if len(maxminlist) == 4: graphMean.GetHistogram().SetMaximum(maxminlist[0]) graphMean.GetHistogram().SetMinimum(maxminlist[1]) graphMean.Draw('APL') c.cd(2) gPad.SetBottomMargin(0.3) gPad.SetGridy() plotutils.setBinLabels(graphRMS,graphBinNames) plotutils.setGraphStyle(graphRMS) graphRMS.SetTitle(';;Width') if len(maxminlist) == 4: graphRMS.GetHistogram().SetMaximum(maxminlist[2]) graphRMS.GetHistogram().SetMinimum(maxminlist[3]) graphRMS.Draw('APL') c.SaveAs('summary_' + hist_name+'_mean_'+half+'.png') ans = raw_input('continue?')