Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-10 22:50:05

0001 #!/usr/bin/env python3
0002 ######################################################################################################################################################
0003 #                                SHIFT LAYOUTS
0004 ######################################################################################################################################################
0005 #Is there a better way? Can we make it in the DQM, probably, but the documentation is not complete and when you try to make a loop or more then a function the GUI gets crazy. So...
0006 from string import Template
0007 
0008 stripDiscName = lambda x: (x.split('/')[-1]).split('Eff')[0]
0009 
0010 defaultPlots = [
0011     ['RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByDecayModeFinding/DecayModeFindingEff%s',
0012     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseChargedIsolation/LooseChargedIsolationEff%s',
0013     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr/LooseCombinedIsolationDBSumPtCorrEff%s'],
0014     ['RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByMediumCombinedIsolationDBSumPtCorr/MediumCombinedIsolationDBSumPtCorrEff%s',
0015     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr/TightCombinedIsolationDBSumPtCorrEff%s',
0016     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByVLooseCombinedIsolationDBSumPtCorr/VLooseCombinedIsolationDBSumPtCorrEff%s'],
0017     ]
0018 
0019 muonrejplots = ['RecoTauV/hpsPFTauProducerRealMuonsData_hpsPFTauDiscriminationByLooseMuonRejection/LooseMuonRejectionEff%s', 'RecoTauV/hpsPFTauProducerRealMuonsData_hpsPFTauDiscriminationByMediumMuonRejection/MediumMuonRejectionEff%s', 'RecoTauV/hpsPFTauProducerRealMuonsData_hpsPFTauDiscriminationByTightMuonRejection/TightMuonRejectionEff%s']
0020 
0021 elerejplots = [
0022     ['RecoTauV/hpsPFTauProducerRealElectronsData_hpsPFTauDiscriminationByLooseElectronRejection/LooseElectronRejectionEff%s',
0023      'RecoTauV/hpsPFTauProducerRealElectronsData_hpsPFTauDiscriminationByMVAElectronRejection/MVAElectronRejectionEff%s',],
0024     ['RecoTauV/hpsPFTauProducerRealElectronsData_hpsPFTauDiscriminationByMediumElectronRejection/MediumElectronRejectionEff%s',
0025      'RecoTauV/hpsPFTauProducerRealElectronsData_hpsPFTauDiscriminationByTightElectronRejection/TightElectronRejectionEff%s']
0026      ]
0027 
0028 variables = {'a':'pt','b':'pileup','c':'eta','d':'phi'}
0029 
0030 datasetNames = {'RealData' : 'QCD Jets', 'RealMuonsData' : 'muons from Z', 'RealElectronsData' : 'electrons from Z'}
0031 
0032 outputFileString = 'def shiftpftaulayout(i, p, *rows): i["00 Shift/Tau/" + p] = DQMItem(layout=rows)\n\n%s'
0033 stdFill=Template('shiftpftaulayout(\n\tdqmitems,\n\t"$locpath",\n\t$rows\n\t)')
0034 
0035 def defaults(locpath,dataType,var):
0036     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]
0037     strow = ',\n\t'.join([row.__repr__() for row in rows])
0038     return stdFill.substitute(locpath=locpath,rows=strow)
0039 
0040 def muRej(locpath,var):
0041     rows = [{ 'path': plot % var, 'description': '%s fake rate' % (stripDiscName(plot)),'draw': {'drawopts': "e"}} for plot in muonrejplots]
0042     return stdFill.substitute(locpath=locpath,rows=rows.__repr__())
0043 
0044 def eleRej(locpath,var):
0045     rows = [[{ 'path': plot % var, 'description': '%s fake rate' % (stripDiscName(plot)),'draw': {'drawopts': "e"}} for plot in row] for row in elerejplots]
0046     strow = ',\n\t'.join([row.__repr__() for row in rows])
0047     return stdFill.substitute(locpath=locpath,rows=strow)
0048 
0049 #
0050 #SingleMu
0051 #
0052 toAdd = [ defaults('SingleMu/00%s - Fake rate from muons vs %s' % item,'RealMuonsData',item[1]) for item in variables.items() ]
0053 toAdd.extend( [ muRej('SingleMu/01%s - Muon rejection fake rate vs %s' % item,item[1]) for item in variables.items() ] )
0054 toAdd.extend( [ defaults('SingleMu/02%s - Fake rate from jets vs %s' % item,'RealData',item[1]) for item in variables.items() ] )
0055 
0056 #
0057 #Jet
0058 #
0059 toAdd.extend([ defaults('Jet/00%s - Fake rate from jets vs %s' % item,'RealData',item[1]) for item in variables.items() ] )
0060 
0061 #
0062 #DoubleE / TauPlusX
0063 #
0064 toAdd.extend([ defaults('DoubleElectron_OR_TauPlusX/00%s - Fake rate from electrons vs %s' % item,'RealElectronsData',item[1]) for item in variables.items() ] )
0065 toAdd.extend( [ eleRej('DoubleElectron_OR_TauPlusX/01%s - Electron rejection fake rate vs %s' % item,item[1]) for item in variables.items() ] )
0066 
0067 layout = open('shift_pftau_T0_layout.py','w')
0068 layout.write(outputFileString % '\n'.join(toAdd) )
0069 layout.close()
0070 
0071 ######################################################################################################################################################
0072 #                                 LAYOUTS
0073 ######################################################################################################################################################
0074 layoutString = 'def pftaulayout(i, p, *rows): i["RecoTauV/Layouts/" + p] = DQMItem(layout=rows)\n\n%s'
0075 stdFill=Template('pftaulayout(\n\tdqmitems,\n\t"$locpath",\n\t$rows\n\t)')
0076 
0077 layoutDefaultPlots = [
0078     [
0079         ['RecoTauV/hpsPFTauProducer%s_Matched/PFJetMatchingEff%s',
0080         'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByDecayModeFinding/DecayModeFindingEff%s'],
0081         ['RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseChargedIsolation/LooseChargedIsolationEff%s',
0082          'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr/LooseCombinedIsolationDBSumPtCorrEff%s'],
0083          ],
0084     [
0085          ['RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseIsolation/LooseIsolationEff%s',
0086          'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByMediumCombinedIsolationDBSumPtCorr/MediumCombinedIsolationDBSumPtCorrEff%s'],
0087          ['RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr/TightCombinedIsolationDBSumPtCorrEff%s',
0088          'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByVLooseCombinedIsolationDBSumPtCorr/VLooseCombinedIsolationDBSumPtCorrEff%s'],
0089          ]
0090     ]
0091 
0092 layoutscone = [
0093     ['RecoTauV/shrinkingConePFTauProducerLeadingPion%s_shrinkingConePFTauDiscriminationByECALIsolationUsingLeadingPion/ECALIsolationUsingLeadingPionEff%s',
0094      'RecoTauV/shrinkingConePFTauProducerLeadingPion%s_shrinkingConePFTauDiscriminationByLeadingPionPtCut/LeadingPionPtCutEff%s'],
0095     ['RecoTauV/shrinkingConePFTauProducerLeadingPion%s_shrinkingConePFTauDiscriminationByLeadingTrackFinding/LeadingTrackFindingEff%s',
0096      'RecoTauV/shrinkingConePFTauProducerLeadingPion%s_shrinkingConePFTauDiscriminationByTrackIsolationUsingLeadingPion/TrackIsolationUsingLeadingPionEff%s']
0097     ]
0098 
0099 layoutSizeSumpt = [
0100     ['RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByDecayModeFinding/hpsPFTauDiscriminationByDecayModeFinding_Size_%s',
0101     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseChargedIsolation/hpsPFTauDiscriminationByLooseChargedIsolation_Size_%s',
0102     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr/hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr_Size_%s'],
0103     ['RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByDecayModeFinding/hpsPFTauDiscriminationByDecayModeFinding_SumPt_%s',
0104     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseChargedIsolation/hpsPFTauDiscriminationByLooseChargedIsolation_SumPt_%s',
0105     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr/hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr_SumPt_%s'],
0106     ]
0107 
0108 import string
0109 
0110 def layDefaults(locpath,dataType,var):
0111     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]
0112     strows = [',\n\t'.join([row.__repr__() for row in rows]) for rows in framerows]
0113     ret = [stdFill.substitute(locpath=locpath % postfix, rows=strow) for postfix,strow in zip(string.letters,strows)]
0114     return '\n'.join(ret)
0115 
0116 def sCone(locpath,dataType,var):
0117     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]
0118     strow = ',\n\t'.join([row.__repr__() for row in rows])
0119     return stdFill.substitute(locpath=locpath,rows=strow)
0120 
0121 def sizeSumpt(locpath,dataType,var):
0122     typ = lambda x: x.split('_')[-2]
0123     if typ == 'SumPt':
0124         typ += ' distribution'
0125     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]
0126     strow = ',\n\t'.join([row.__repr__() for row in rows])
0127     return stdFill.substitute(locpath=locpath,rows=strow)
0128 
0129 variables = {'a%s':'pt','b%s':'pileup','c%s':'eta','d%s':'phi'}
0130 sumVar = dict( list(zip(string.letters,[elem for elem in ['signalCands','isolationChargedHadrCands','isolationGammaCands','isolationNeutrHadrCands'] ])) )
0131 
0132 
0133 #
0134 #SingleMu
0135 #
0136 toAdd = [ layDefaults('SingleMu/00%s - Fake rate from muons vs %s' % item,'RealMuonsData',item[1]) for item in variables.items() ]
0137 toAdd.extend( [ muRej('SingleMu/01%s - Muon rejection fake rate vs %s' % (item[0]%'',item[1]),item[1]) for item in variables.items() ] )
0138 toAdd.extend( [ layDefaults('SingleMu/02%s - Fake rate from jets vs %s' % item,'RealData',item[1]) for item in variables.items() ] )
0139 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() ] )
0140 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() ] )
0141 
0142 #
0143 #Jet
0144 #
0145 toAdd.extend([ layDefaults('Jet/00%s - Fake rate from jets vs %s' % item,'RealData',item[1]) for item in variables.items() ] )
0146 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() ] )
0147 
0148 #
0149 #DoubleE / TauPlusX
0150 #
0151 toAdd.extend([ layDefaults('DoubleElectron_OR_TauPlusX/00%s - Fake rate from electrons vs %s' % item,'RealElectronsData',item[1]) for item in variables.items() ] )
0152 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() ] )
0153 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() ] )
0154 
0155 layout = open('pftatau_T0_layouts.py','w')
0156 layout.write(layoutString % '\n'.join(toAdd) )
0157 layout.close()