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 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 plotRotations(t_file): names = hps_utils.getSensorNames() print ' got ', len(names), ' sensor names' hname = 'h_res_gbl_vs_u_' #hname = 'h_res_gbl_vs_vpred_' c = TCanvas('c','c',10,10,700,500) grSlopes = TGraphErrors() grSlopes.SetName('slopes_' + hname) grSlopesBinLabels = [] for sensorname in names: name = hname + sensorname 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') #ans = raw_input('continue?') grMean = TGraphErrors() grMean.SetName( h.GetName() + '_prjYmean' ) for b in range(1, h.GetNbinsX()+1): h_p = h.ProjectionY(h.GetName() + '_prjy' + str(b), b, b, 'E') f = None if h_p.GetEntries() > 77.: peakbin = findPeakBin(h_p) x = h_p.GetBinCenter(peakbin) minv = x - 1.5*h_p.GetRMS() maxv = x + 1.5*h_p.GetRMS() print 'vpred ', h.GetXaxis().GetBinCenter(b) , ' peakbin ', peakbin, ' c ' , h_p.GetBinCenter(peakbin), ' minv ', minv, ' maxv ', maxv f = TF1('f'+'_'+name,'gaus',minv,maxv) h_p.Fit(f,'RQ') ipoint = grMean.GetN() grMean.SetPoint(ipoint, h.GetXaxis().GetBinCenter(b), f.GetParameter(1)) grMean.SetPointError(ipoint, 0., f.GetParError(1)) c.Clear() if f != None: plotutils.myText(0.5,0.85,'<m>=%.2f #sigma=%.2f'%(f.GetParameter(1),f.GetParameter(2)), 0.05, 2) h_p.Draw() c.SaveAs(h_p.GetName() + '-' + args.tag + '.png') #ans = raw_input('continue?') grMean.SetTitle(name + ';;mean') grMean.SetMarkerStyle(20) c.Clear() fpol1 = TF1('f' + grMean.GetName(),'pol1') grMean.Fit(fpol1) grMean.Draw('ALP') plotutils.myText(0.35,0.8,'slope=%.2e m=%.2e'%(fpol1.GetParameter(1),fpol1.GetParameter(0)), 0.05, 2) ipoint = grSlopes.GetN() if args.uflip and hps_utils.getAxialStereo(sensorname) == 'stereo': print 'flip ', sensorname, ' ', fpol1.GetParameter(1) , ' -> ', -1.*fpol1.GetParameter(1) grSlopes.SetPoint( ipoint, ipoint, -1.*fpol1.GetParameter(1) ) else: print 'NO flip ', sensorname, ' ', fpol1.GetParameter(1) grSlopes.SetPoint( ipoint, ipoint, fpol1.GetParameter(1) ) grSlopes.SetPointError( ipoint, 0., fpol1.GetParError(1) ) grSlopesBinLabels.append( hps_utils.getshortsensorname( sensorname ) ) c.SaveAs(name + '-mean-' + args.tag + '.png') #ans = raw_input('continue?') c.Clear() grSlopes.Draw('ALP') plotutils.setBinLabels( grSlopes, grSlopesBinLabels ) c.SetBottomMargin(0.2) if args.uflip: plotutils.myText(0.35,0.8,'u-flipped', 0.05, 2) else: plotutils.myText(0.35,0.8,'NOT u-flipped', 0.05, 2) if args.uflip: c.SaveAs(grSlopes.GetName() + '-uflipped-' + args.tag + '.png') else: c.SaveAs(grSlopes.GetName() + '-' + args.tag + '.png') ans = raw_input('continue?')