Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:34:24

0001 from __future__ import print_function
0002 from ROOT import *
0003 import re
0004 
0005 files = ['DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root']
0006 
0007 folders = [
0008     'DQMData/Run 1/Vertexing/Run summary/PrimaryVertexV/selectedOfflinePrimaryVertices',
0009     'DQMData/Run 1/Vertexing/Run summary/PrimaryVertexV/selectedPixelVertices'
0010 ]
0011 
0012 histo_names = [
0013     {'name': 'RecoVtx_vs_GenVtx', 'o': '', 'xAxis': 'Pileup Interactions', 'yAxis': 'Reco Vertices', 'yMax': '90', 'yMin': ''},
0014     {'name': 'MatchedRecoVtx_vs_GenVtx', 'o': '', 'xAxis': 'Pileup Interactions', 'yAxis': 'Matched Reco Vertices', 'yMax': '90', 'yMin': ''},
0015     {'name': 'RecoAllAssoc2GenProperties', 'o': '', 'xAxis': 'Kind of Reco Vertex', 'yAxis': '', 'yMax': '', 'yMin': ''},
0016     {'name': 'RecoAllAssoc2Gen_PairDistanceZ', 'o': '', 'xAxis': 'Reco Vertex, Pair Distance', 'yAxis': '', 'yMax': '', 'yMin': ''},
0017     {'name': 'globalEfficiencies', 'o': '', 'xAxis': '', 'yAxis': '', 'yMax': '', 'yMin': ''},
0018     {'name': 'KindOfSignalPV', 'o': '', 'xAxis': 'Type Of Signal VTX', 'yAxis': '', 'yMax': '', 'yMin': '0'},
0019     {'name': 'MisTagRate', 'o': '', 'xAxis': 'Misidentification', 'yAxis': '', 'yMax': '', 'yMin': '0'},
0020     {'name': 'MisTagRate_vs_PU', 'o': '', 'xAxis': 'Pileup Interactions', 'yAxis': 'Misidentification', 'yMax': '', 'yMin': '0'},
0021     {'name': 'MisTagRate_vs_sum-pt2', 'o': 'logx', 'xAxis': '#sum_{pt^{2}}', 'yAxis': 'Misidentification', 'yMax': '', 'yMin': '0'},
0022     {'name': 'MisTagRate_vs_Z', 'o': '', 'xAxis': 'Z', 'yAxis': 'Misidentification', 'yMax': '', 'yMin': '0'},
0023     {'name': 'MisTagRate_vs_R', 'o': '', 'xAxis': 'R', 'yAxis': 'Misidentification', 'yMax': '', 'yMin': '0'},
0024     {'name': 'MisTagRate_vs_NumTracks', 'o': '', 'xAxis': 'Number of Tracks in Vertex', 'yAxis': 'Misidentification', 'yMax': '', 'yMin': '0'},
0025     {'name': 'TruePVLocationIndex', 'o': '', 'xAxis': 'True PV index in RecoVtx collection', 'yAxis': '', 'yMax': '', 'yMin': ''},
0026     {'name': 'effic_vs_NumVertices', 'o': '', 'xAxis': 'Number of Vertices', 'yAxis': 'Efficiency', 'yMax': '', 'yMin': ''},
0027     {'name': 'effic_vs_NumTracks', 'o': '', 'xAxis': 'Number of Tracks in Vertex', 'yAxis': 'Efficiency', 'yMax': '', 'yMin': ''},
0028     {'name': 'effic_vs_ClosestVertexInZ', 'o': 'logx', 'xAxis': 'Closest Distance in Z', 'yAxis': 'Efficiency', 'yMax': '', 'yMin': ''},
0029     {'name': 'effic_vs_Pt2', 'o': 'logx', 'xAxis': '#sum_{pt^{2}}', 'yAxis': 'Efficiency', 'yMax': '', 'yMin': ''},
0030     {'name': 'effic_vs_Z', 'o': '', 'xAxis': 'Z', 'yAxis': 'Efficiency', 'yMax': '', 'yMin': ''},
0031     {'name': 'gen_duplicate_vs_NumVertices', 'o': '', 'xAxis': 'Number of Vertices', 'yAxis': 'GenLevel Duplicates', 'yMax': '', 'yMin': ''},
0032     {'name': 'gen_duplicate_vs_NumTracks', 'o': '', 'xAxis': 'Number of Tracks in Vertex', 'yAxis': 'GenLevel Duplicates', 'yMax': '', 'yMin': ''},
0033     {'name': 'gen_duplicate_vs_ClosestVertexInZ', 'o': 'logx', 'xAxis': 'Closest Distance in Z', 'yAxis': 'GenLevel Duplicates', 'yMax': '', 'yMin': ''},
0034     {'name': 'gen_duplicate_vs_Pt2', 'o': 'logx', 'xAxis': '#sum_{pt^{2}}', 'yAxis': 'GenLevel Duplicates', 'yMax': '', 'yMin': ''},
0035     {'name': 'gen_duplicate_vs_Z', 'o': '', 'xAxis': 'Z', 'yAxis': 'GenLevel Duplicates', 'yMax': '', 'yMin': ''},
0036     {'name': 'fakerate_vs_NumVertices', 'o': '', 'xAxis': 'Number of Vertices', 'yAxis': 'Fake Rate', 'yMax': '', 'yMin': ''},
0037     {'name': 'fakerate_vs_PU', 'o': '', 'xAxis': 'Pileup Interactions', 'yAxis': 'Fake Rate', 'yMax': '', 'yMin': ''},
0038     {'name': 'fakerate_vs_Ndof', 'o': '', 'xAxis': 'Vertex DOF', 'yAxis': 'Fake Rate', 'yMax': '', 'yMin': ''},
0039     {'name': 'fakerate_vs_NumTracks', 'o': '', 'xAxis': 'Number of Tracks in Vertex', 'yAxis': 'Fake Rate', 'yMax': '', 'yMin': ''},
0040     {'name': 'fakerate_vs_ClosestVertexInZ', 'o': 'logx', 'xAxis': 'Closest Distance in Z', 'yAxis': 'Fake Rate', 'yMax': '', 'yMin': ''},
0041     {'name': 'fakerate_vs_Pt2', 'o': 'logx', 'xAxis': '#sum_{pt^{2}}', 'yAxis': 'Fake Rate', 'yMax': '', 'yMin': ''},
0042     {'name': 'fakerate_vs_Z', 'o': '', 'xAxis': 'Z', 'yAxis': 'Fake Rate', 'yMax': '', 'yMin': ''},
0043     {'name': 'duplicate_vs_NumVertices', 'o': '', 'xAxis': 'Number of Vertices', 'yAxis': 'Duplicate Rate', 'yMax': '', 'yMin': ''},
0044     {'name': 'duplicate_vs_PU', 'o': '', 'xAxis': 'Pileup Interactions', 'yAxis': 'Duplicate Rate', 'yMax': '', 'yMin': ''},
0045     {'name': 'duplicate_vs_NumTracks', 'o': '', 'xAxis': 'Number of Tracks in Vertex', 'yAxis': 'Duplicate Rate', 'yMax': '', 'yMin': ''},
0046     {'name': 'duplicate_vs_ClosestVertexInZ', 'o': 'logx', 'xAxis': 'Closest Distance in Z', 'yAxis': 'Duplicate Rate', 'yMax': '', 'yMin': ''},
0047     {'name': 'duplicate_vs_Pt2', 'o': 'logx', 'xAxis': '#sum_{pt^{2}}', 'yAxis': 'Duplicate Rate', 'yMax': '', 'yMin': ''},
0048     {'name': 'duplicate_vs_Z', 'o': '', 'xAxis': 'Z', 'yAxis': 'Duplicate Rate', 'yMax': '', 'yMin': ''},
0049     {'name': 'merged_vs_NumVertices', 'o': '', 'xAxis': 'Number of Vertices', 'yAxis': 'Merge Rate', 'yMax': '', 'yMin': ''},
0050     {'name': 'merged_vs_PU', 'o': '', 'xAxis': 'Pileup Interactions', 'yAxis': 'Merge Rate', 'yMax': '', 'yMin': ''},
0051     {'name': 'merged_vs_NumTracks', 'o': '', 'xAxis': 'Number of Tracks in Vertex', 'yAxis': 'Merge Rate', 'yMax': '', 'yMin': ''},
0052     {'name': 'merged_vs_ClosestVertexInZ', 'o': 'logx', 'xAxis': 'Closest Distance in Z', 'yAxis': 'Merge Rate', 'yMax': '', 'yMin': ''},
0053     {'name': 'merged_vs_Pt2', 'o': 'logx', 'xAxis': '#sum_{pt^{2}}', 'yAxis': 'Merge Rate', 'yMax': '', 'yMin': ''},
0054     {'name': 'merged_vs_Z', 'o': '', 'xAxis': 'Z', 'yAxis': 'Merge Rate', 'yMax': '', 'yMin': ''}
0055 ]
0056 
0057 histograms = []
0058 # Build full list of histograms
0059 for h in histo_names:
0060     for f in folders:
0061         histograms.append({'name': '%s/%s' % (f, h['name']), 'o': h['o'],
0062                            'xAxis': h['xAxis'], 'yAxis': h['yAxis'],
0063                            'yMax': h['yMax'], 'yMin': h['yMin']})
0064 
0065 file_handles = []
0066 
0067 def prepareFileHandles():
0068     for file in files:
0069         file_handles.append(TFile(file))
0070 
0071 def cleanOptions():
0072     gPad.SetLogx(0)
0073     gPad.SetLogy(0)
0074 
0075 def setTextProperties(obj, label=False, title=False):
0076     textFont = 42
0077     textSize = 0.027
0078     titleOffset = 1.25
0079     labelOffset = 0.002
0080     if not label and not title:
0081         obj.SetTextFont(textFont)
0082         obj.SetTextSize(textSize)
0083     if label:
0084         obj.SetLabelOffset(labelOffset)
0085         obj.SetLabelFont(textFont)
0086         obj.SetLabelSize(textSize)
0087     if title:
0088         gStyle.SetTitleX(0.5)
0089         gStyle.SetTitleAlign(23)
0090         obj.SetTitleFont(textFont)
0091         obj.SetTitleSize(textSize)
0092         obj.SetTitleOffset(titleOffset)
0093     return obj
0094 
0095 def producePlots():
0096     gStyle.SetOptStat(0)
0097     c = TCanvas('c', 'c', 1024, 1024)
0098     histo = {}
0099     for h in histograms:
0100         counter = 0
0101         draw_options = ''
0102         for f in file_handles:
0103             histo = f.Get(h['name'])
0104             if not histo:
0105                 print('Failed to get histograms %s', h)
0106             else:
0107                 if counter == 0:
0108                     counter += 1
0109                 else:
0110                     draw_options += 'SAME'
0111                 cleanOptions()
0112                 if h['o'] != '':
0113                     if h['o'] == 'logx':
0114                         gPad.SetLogx()
0115                 if h['yMax'] != '':
0116                     histo.SetMaximum(float(h['yMax']))
0117                 if h['yMin'] != '':
0118                     histo.SetMinimum(float(h['yMin']))
0119                 histo.GetXaxis().SetTitle(h['xAxis'])
0120                 histo.GetYaxis().SetTitle(h['yAxis'])
0121                 setTextProperties(histo.GetXaxis(), title=True)
0122                 setTextProperties(histo.GetYaxis(), title=True)
0123                 setTextProperties(histo.GetXaxis(), label=True)
0124                 setTextProperties(histo.GetYaxis(), label=True)
0125                 histo.SetMarkerStyle(20)
0126                 histo.SetMarkerColor(kAzure)
0127                 histo.SetMarkerSize(1.2)
0128                 histo.Draw(draw_options)
0129                 c.Update()
0130                 c.SaveAs('%s' % ("_".join(h['name'].split('/')[-2:]) + ".png"))
0131 
0132 if __name__ == '__main__':
0133     prepareFileHandles()
0134     producePlots()