CMS 3D CMS Logo

makeLayoutFileForGui.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
6 from string import Template
7 
8 stripDiscName = lambda x: (x.split('/')[-1]).split('Eff')[0]
9 
10 defaultPlots = [
11  ['RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByDecayModeFinding/DecayModeFindingEff%s',
12  'RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseChargedIsolation/LooseChargedIsolationEff%s',
13  'RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr/LooseCombinedIsolationDBSumPtCorrEff%s'],
14  ['RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByMediumCombinedIsolationDBSumPtCorr/MediumCombinedIsolationDBSumPtCorrEff%s',
15  'RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr/TightCombinedIsolationDBSumPtCorrEff%s',
16  'RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByVLooseCombinedIsolationDBSumPtCorr/VLooseCombinedIsolationDBSumPtCorrEff%s'],
17  ]
18 
19 muonrejplots = ['RecoTauV/standardValidation/hpsPFTauProducerRealMuonsData_hpsPFTauDiscriminationByLooseMuonRejection/LooseMuonRejectionEff%s',
20  'RecoTauV/standardValidation/hpsPFTauProducerRealMuonsData_hpsPFTauDiscriminationByMediumMuonRejection/MediumMuonRejectionEff%s',
21  'RecoTauV/standardValidation/hpsPFTauProducerRealMuonsData_hpsPFTauDiscriminationByTightMuonRejection/TightMuonRejectionEff%s']
22 
23 elerejplots = [
24  ['RecoTauV/standardValidation/hpsPFTauProducerRealElectronsData_hpsPFTauDiscriminationByLooseElectronRejection/LooseElectronRejectionEff%s',
25  'RecoTauV/standardValidation/hpsPFTauProducerRealElectronsData_hpsPFTauDiscriminationByMVAElectronRejection/MVAElectronRejectionEff%s',],
26  ['RecoTauV/standardValidation/hpsPFTauProducerRealElectronsData_hpsPFTauDiscriminationByMediumElectronRejection/MediumElectronRejectionEff%s',
27  'RecoTauV/standardValidation/hpsPFTauProducerRealElectronsData_hpsPFTauDiscriminationByTightElectronRejection/TightElectronRejectionEff%s']
28  ]
29 
30 variables = {'a':'pt','b':'pileup','c':'eta','d':'phi'}
31 
32 datasetNames = {'RealData' : 'QCD Jets', 'RealMuonsData' : 'muons from Z', 'RealElectronsData' : 'electrons from Z'}
33 
34 outputFileString = 'def shiftpftaulayout(i, p, *rows): i["00 Shift/Tau/" + p] = DQMItem(layout=rows)\n\n%s'
35 stdFill=Template('shiftpftaulayout(\n\tdqmitems,\n\t"$locpath",\n\t$rows\n\t)')
36 
37 def defaults(locpath,dataType,var):
38  rows = [[{ 'path': plot % (dataType,var), 'description': '%s fake rate from %s' % (stripDiscName(plot), datasetNames[dataType]),'draw': {'drawopts': "e"}} for plot in row] for row in defaultPlots]
39  strow = ',\n\t'.join([row.__repr__() for row in rows])
40  return stdFill.substitute(locpath=locpath,rows=strow)
41 
42 def muRej(locpath,var):
43  rows = [{ 'path': plot % var, 'description': '%s fake rate' % (stripDiscName(plot)),'draw': {'drawopts': "e"}} for plot in muonrejplots]
44  return stdFill.substitute(locpath=locpath,rows=rows.__repr__())
45 
46 def eleRej(locpath,var):
47  rows = [[{ 'path': plot % var, 'description': '%s fake rate' % (stripDiscName(plot)),'draw': {'drawopts': "e"}} for plot in row] for row in elerejplots]
48  strow = ',\n\t'.join([row.__repr__() for row in rows])
49  return stdFill.substitute(locpath=locpath,rows=strow)
50 
51 #
52 #SingleMu
53 #
54 toAdd = [ defaults('SingleMu/00%s - Fake rate from muons vs %s' % item,'RealMuonsData',item[1]) for item in variables.items() ]
55 toAdd.extend( [ muRej('SingleMu/01%s - Muon rejection fake rate vs %s' % item,item[1]) for item in variables.items() ] )
56 toAdd.extend( [ defaults('SingleMu/02%s - Fake rate from jets vs %s' % item,'RealData',item[1]) for item in variables.items() ] )
57 
58 #
59 #Jet
60 #
61 toAdd.extend([ defaults('Jet/00%s - Fake rate from jets vs %s' % item,'RealData',item[1]) for item in variables.items() ] )
62 
63 #
64 #DoubleE / TauPlusX
65 #
66 toAdd.extend([ defaults('DoubleElectron_OR_TauPlusX/00%s - Fake rate from electrons vs %s' % item,'RealElectronsData',item[1]) for item in variables.items() ] )
67 toAdd.extend( [ eleRej('DoubleElectron_OR_TauPlusX/01%s - Electron rejection fake rate vs %s' % item,item[1]) for item in variables.items() ] )
68 
69 layout = open('shift_pftau_T0_layout.py','w')
70 layout.write(outputFileString % '\n'.join(toAdd) )
71 layout.close()
72 
73 
76 layoutString = 'def pftaulayout(i, p, *rows): i["RecoTauV/standardValidation/Layouts/" + p] = DQMItem(layout=rows)\n\n%s'
77 stdFill=Template('pftaulayout(\n\tdqmitems,\n\t"$locpath",\n\t$rows\n\t)')
78 
79 layoutDefaultPlots = [
80  [
81  ['RecoTauV/standardValidation/hpsPFTauProducer%s_Matched/PFJetMatchingEff%s',
82  'RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByDecayModeFinding/DecayModeFindingEff%s'],
83  ['RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseChargedIsolation/LooseChargedIsolationEff%s',
84  'RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr/LooseCombinedIsolationDBSumPtCorrEff%s'],
85  ],
86  [
87  ['RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseIsolation/LooseIsolationEff%s',
88  'RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByMediumCombinedIsolationDBSumPtCorr/MediumCombinedIsolationDBSumPtCorrEff%s'],
89  ['RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr/TightCombinedIsolationDBSumPtCorrEff%s',
90  'RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByVLooseCombinedIsolationDBSumPtCorr/VLooseCombinedIsolationDBSumPtCorrEff%s'],
91  ]
92  ]
93 
94 layoutscone = [
95  ['RecoTauV/standardValidation/shrinkingConePFTauProducerLeadingPion%s_shrinkingConePFTauDiscriminationByECALIsolationUsingLeadingPion/ECALIsolationUsingLeadingPionEff%s',
96  'RecoTauV/standardValidation/shrinkingConePFTauProducerLeadingPion%s_shrinkingConePFTauDiscriminationByLeadingPionPtCut/LeadingPionPtCutEff%s'],
97  ['RecoTauV/standardValidation/shrinkingConePFTauProducerLeadingPion%s_shrinkingConePFTauDiscriminationByLeadingTrackFinding/LeadingTrackFindingEff%s',
98  'RecoTauV/standardValidation/shrinkingConePFTauProducerLeadingPion%s_shrinkingConePFTauDiscriminationByTrackIsolationUsingLeadingPion/TrackIsolationUsingLeadingPionEff%s']
99  ]
100 
101 layoutSizeSumpt = [
102  ['RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByDecayModeFinding/hpsPFTauDiscriminationByDecayModeFinding_Size_%s',
103  'RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseChargedIsolation/hpsPFTauDiscriminationByLooseChargedIsolation_Size_%s',
104  'RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr/hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr_Size_%s'],
105  ['RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByDecayModeFinding/hpsPFTauDiscriminationByDecayModeFinding_SumPt_%s',
106  'RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseChargedIsolation/hpsPFTauDiscriminationByLooseChargedIsolation_SumPt_%s',
107  'RecoTauV/standardValidation/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr/hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr_SumPt_%s'],
108  ]
109 
110 import string
111 
112 def layDefaults(locpath,dataType,var):
113  framerows = [[[{ 'path': plot % (dataType,var), 'description': '%s fake rate from %s' % (stripDiscName(plot), datasetNames[dataType]),'draw': {'drawopts': "e"}} for plot in row] for row in frame] for frame in layoutDefaultPlots]
114  strows = [',\n\t'.join([row.__repr__() for row in rows]) for rows in framerows]
115  ret = [stdFill.substitute(locpath=locpath % postfix, rows=strow) for postfix,strow in zip(string.letters,strows)]
116  return '\n'.join(ret)
117 
118 def sCone(locpath,dataType,var):
119  rows = [[{ 'path': plot % (dataType,var), 'description': '%s fake rate from %s' % (stripDiscName(plot), datasetNames[dataType]),'draw': {'drawopts': "e"}} for plot in row] for row in layoutscone]
120  strow = ',\n\t'.join([row.__repr__() for row in rows])
121  return stdFill.substitute(locpath=locpath,rows=strow)
122 
123 def sizeSumpt(locpath,dataType,var):
124  typ = lambda x: x.split('_')[-2]
125  if typ == 'SumPt':
126  typ += ' distribution'
127  rows = [[{ 'path': plot % (dataType,var), 'description': '%s faking taus %s of %s' % (datasetNames[dataType],typ(plot), var),'draw': {'drawopts': "e"}} for plot in row] for row in layoutSizeSumpt]
128  strow = ',\n\t'.join([row.__repr__() for row in rows])
129  return stdFill.substitute(locpath=locpath,rows=strow)
130 
131 variables = {'a%s':'pt','b%s':'pileup','c%s':'eta','d%s':'phi'}
132 sumVar = dict( list(zip(string.letters,[elem for elem in ['signalCands','isolationChargedHadrCands','isolationGammaCands','isolationNeutrHadrCands'] ])) )
133 
134 
135 #
136 #SingleMu
137 #
138 toAdd = [ layDefaults('SingleMu/00%s - Fake rate from muons vs %s' % item,'RealMuonsData',item[1]) for item in variables.items() ]
139 toAdd.extend( [ muRej('SingleMu/01%s - Muon rejection fake rate vs %s' % (item[0]%'',item[1]),item[1]) for item in variables.items() ] )
140 toAdd.extend( [ layDefaults('SingleMu/02%s - Fake rate from jets vs %s' % item,'RealData',item[1]) for item in variables.items() ] )
141 toAdd.extend( [ sizeSumpt('SingleMu/03%s - Distributions of size and sumPt for %s, %s faking taus' % (item[0], item[1],datasetNames['RealMuonsData']),'RealMuonsData',item[1]) for item in sumVar.items() ] )
142 toAdd.extend( [ sizeSumpt('SingleMu/04%s - Distributions of size and sumPt for %s, %s faking taus' % (item[0], item[1],datasetNames['RealData']),'RealData',item[1]) for item in sumVar.items() ] )
143 
144 #
145 #Jet
146 #
147 toAdd.extend([ layDefaults('Jet/00%s - Fake rate from jets vs %s' % item,'RealData',item[1]) for item in variables.items() ] )
148 toAdd.extend( [ sizeSumpt('Jet/01%s - Distributions of size and sumPt for %s, %s faking taus' % (item[0], item[1],datasetNames['RealData']),'RealData',item[1]) for item in sumVar.items() ] )
149 
150 #
151 #DoubleE / TauPlusX
152 #
153 toAdd.extend([ layDefaults('DoubleElectron_OR_TauPlusX/00%s - Fake rate from electrons vs %s' % item,'RealElectronsData',item[1]) for item in variables.items() ] )
154 toAdd.extend( [ eleRej('DoubleElectron_OR_TauPlusX/01%s - Electron rejection fake rate vs %s' % (item[0].replace('%s',''),item[1]),item[1]) for item in variables.items() ] )
155 toAdd.extend( [ sizeSumpt('DoubleElectron_OR_TauPlusX/04%s - Distributions of size and sumPt for %s, %s faking taus' % (item[0], item[1],datasetNames['RealElectronsData']),'RealElectronsData',item[1]) for item in sumVar.items() ] )
156 
157 layout = open('pftatau_T0_layouts.py','w')
158 layout.write(layoutString % '\n'.join(toAdd) )
159 layout.close()
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float zip(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:90
def replace(string, replacements)
def sCone(locpath, dataType, var)
def defaults(locpath, dataType, var)
def layDefaults(locpath, dataType, var)
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def sizeSumpt(locpath, dataType, var)
def eleRej(locpath, var)
def muRej(locpath, var)