CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/Validation/RecoTau/Tools/makeLayoutFileForGui.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 ######################################################################################################################################################
00003 #                                SHIFT LAYOUTS
00004 ######################################################################################################################################################
00005 #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...
00006 from string import Template
00007 
00008 stripDiscName = lambda x: (x.split('/')[-1]).split('Eff')[0]
00009 
00010 defaultPlots = [
00011     ['RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByDecayModeFinding/DecayModeFindingEff%s',
00012     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseChargedIsolation/LooseChargedIsolationEff%s',
00013     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr/LooseCombinedIsolationDBSumPtCorrEff%s'],
00014     ['RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByMediumCombinedIsolationDBSumPtCorr/MediumCombinedIsolationDBSumPtCorrEff%s',
00015     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr/TightCombinedIsolationDBSumPtCorrEff%s',
00016     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByVLooseCombinedIsolationDBSumPtCorr/VLooseCombinedIsolationDBSumPtCorrEff%s'],
00017     ]
00018 
00019 muonrejplots = ['RecoTauV/hpsPFTauProducerRealMuonsData_hpsPFTauDiscriminationByLooseMuonRejection/LooseMuonRejectionEff%s', 'RecoTauV/hpsPFTauProducerRealMuonsData_hpsPFTauDiscriminationByMediumMuonRejection/MediumMuonRejectionEff%s', 'RecoTauV/hpsPFTauProducerRealMuonsData_hpsPFTauDiscriminationByTightMuonRejection/TightMuonRejectionEff%s']
00020 
00021 elerejplots = [
00022     ['RecoTauV/hpsPFTauProducerRealElectronsData_hpsPFTauDiscriminationByLooseElectronRejection/LooseElectronRejectionEff%s',
00023      'RecoTauV/hpsPFTauProducerRealElectronsData_hpsPFTauDiscriminationByMVAElectronRejection/MVAElectronRejectionEff%s',],
00024     ['RecoTauV/hpsPFTauProducerRealElectronsData_hpsPFTauDiscriminationByMediumElectronRejection/MediumElectronRejectionEff%s',
00025      'RecoTauV/hpsPFTauProducerRealElectronsData_hpsPFTauDiscriminationByTightElectronRejection/TightElectronRejectionEff%s']
00026      ]
00027 
00028 variables = {'a':'pt','b':'pileup','c':'eta','d':'phi'}
00029 
00030 datasetNames = {'RealData' : 'QCD Jets', 'RealMuonsData' : 'muons from Z', 'RealElectronsData' : 'electrons from Z'}
00031 
00032 outputFileString = 'def shiftpftaulayout(i, p, *rows): i["00 Shift/Tau/" + p] = DQMItem(layout=rows)\n\n%s'
00033 stdFill=Template('shiftpftaulayout(\n\tdqmitems,\n\t"$locpath",\n\t$rows\n\t)')
00034 
00035 def defaults(locpath,dataType,var):
00036     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]
00037     strow = ',\n\t'.join([row.__repr__() for row in rows])
00038     return stdFill.substitute(locpath=locpath,rows=strow)
00039 
00040 def muRej(locpath,var):
00041     rows = [{ 'path': plot % var, 'description': '%s fake rate' % (stripDiscName(plot)),'draw': {'drawopts': "e"}} for plot in muonrejplots]
00042     return stdFill.substitute(locpath=locpath,rows=rows.__repr__())
00043 
00044 def eleRej(locpath,var):
00045     rows = [[{ 'path': plot % var, 'description': '%s fake rate' % (stripDiscName(plot)),'draw': {'drawopts': "e"}} for plot in row] for row in elerejplots]
00046     strow = ',\n\t'.join([row.__repr__() for row in rows])
00047     return stdFill.substitute(locpath=locpath,rows=strow)
00048 
00049 #
00050 #SingleMu
00051 #
00052 toAdd = [ defaults('SingleMu/00%s - Fake rate from muons vs %s' % item,'RealMuonsData',item[1]) for item in variables.items() ]
00053 toAdd.extend( [ muRej('SingleMu/01%s - Muon rejection fake rate vs %s' % item,item[1]) for item in variables.items() ] )
00054 toAdd.extend( [ defaults('SingleMu/02%s - Fake rate from jets vs %s' % item,'RealData',item[1]) for item in variables.items() ] )
00055 
00056 #
00057 #Jet
00058 #
00059 toAdd.extend([ defaults('Jet/00%s - Fake rate from jets vs %s' % item,'RealData',item[1]) for item in variables.items() ] )
00060 
00061 #
00062 #DoubleE / TauPlusX
00063 #
00064 toAdd.extend([ defaults('DoubleElectron_OR_TauPlusX/00%s - Fake rate from electrons vs %s' % item,'RealElectronsData',item[1]) for item in variables.items() ] )
00065 toAdd.extend( [ eleRej('DoubleElectron_OR_TauPlusX/01%s - Electron rejection fake rate vs %s' % item,item[1]) for item in variables.items() ] )
00066 
00067 layout = open('shift_pftau_T0_layout.py','w')
00068 layout.write(outputFileString % '\n'.join(toAdd) )
00069 layout.close()
00070 
00071 ######################################################################################################################################################
00072 #                                 LAYOUTS
00073 ######################################################################################################################################################
00074 layoutString = 'def pftaulayout(i, p, *rows): i["RecoTauV/Layouts/" + p] = DQMItem(layout=rows)\n\n%s'
00075 stdFill=Template('pftaulayout(\n\tdqmitems,\n\t"$locpath",\n\t$rows\n\t)')
00076 
00077 layoutDefaultPlots = [
00078     [
00079         ['RecoTauV/hpsPFTauProducer%s_Matched/PFJetMatchingEff%s',
00080         'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByDecayModeFinding/DecayModeFindingEff%s'],
00081         ['RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseChargedIsolation/LooseChargedIsolationEff%s',
00082          'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr/LooseCombinedIsolationDBSumPtCorrEff%s'],
00083          ],
00084     [
00085          ['RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseIsolation/LooseIsolationEff%s',
00086          'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByMediumCombinedIsolationDBSumPtCorr/MediumCombinedIsolationDBSumPtCorrEff%s'],
00087          ['RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr/TightCombinedIsolationDBSumPtCorrEff%s',
00088          'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByVLooseCombinedIsolationDBSumPtCorr/VLooseCombinedIsolationDBSumPtCorrEff%s'],
00089          ]
00090     ]
00091 
00092 layoutscone = [
00093     ['RecoTauV/shrinkingConePFTauProducerLeadingPion%s_shrinkingConePFTauDiscriminationByECALIsolationUsingLeadingPion/ECALIsolationUsingLeadingPionEff%s',
00094      'RecoTauV/shrinkingConePFTauProducerLeadingPion%s_shrinkingConePFTauDiscriminationByLeadingPionPtCut/LeadingPionPtCutEff%s'],
00095     ['RecoTauV/shrinkingConePFTauProducerLeadingPion%s_shrinkingConePFTauDiscriminationByLeadingTrackFinding/LeadingTrackFindingEff%s',
00096      'RecoTauV/shrinkingConePFTauProducerLeadingPion%s_shrinkingConePFTauDiscriminationByTrackIsolationUsingLeadingPion/TrackIsolationUsingLeadingPionEff%s']
00097     ]
00098 
00099 layoutSizeSumpt = [
00100     ['RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByDecayModeFinding/hpsPFTauDiscriminationByDecayModeFinding_Size_%s',
00101     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseChargedIsolation/hpsPFTauDiscriminationByLooseChargedIsolation_Size_%s',
00102     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr/hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr_Size_%s'],
00103     ['RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByDecayModeFinding/hpsPFTauDiscriminationByDecayModeFinding_SumPt_%s',
00104     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseChargedIsolation/hpsPFTauDiscriminationByLooseChargedIsolation_SumPt_%s',
00105     'RecoTauV/hpsPFTauProducer%s_hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr/hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr_SumPt_%s'],
00106     ]
00107 
00108 import string
00109 
00110 def layDefaults(locpath,dataType,var):
00111     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]
00112     strows = [',\n\t'.join([row.__repr__() for row in rows]) for rows in framerows]
00113     ret = [stdFill.substitute(locpath=locpath % postfix, rows=strow) for postfix,strow in zip(string.letters,strows)]
00114     return '\n'.join(ret)
00115 
00116 def sCone(locpath,dataType,var):
00117     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]
00118     strow = ',\n\t'.join([row.__repr__() for row in rows])
00119     return stdFill.substitute(locpath=locpath,rows=strow)
00120 
00121 def sizeSumpt(locpath,dataType,var):
00122     typ = lambda x: x.split('_')[-2]
00123     if typ == 'SumPt':
00124         typ += ' distribution'
00125     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]
00126     strow = ',\n\t'.join([row.__repr__() for row in rows])
00127     return stdFill.substitute(locpath=locpath,rows=strow)
00128 
00129 variables = {'a%s':'pt','b%s':'pileup','c%s':'eta','d%s':'phi'}
00130 sumVar = dict( zip(string.letters,[elem for elem in ['signalPFCands','isolationPFChargedHadrCands','isolationPFGammaCands','isolationPFNeutrHadrCands'] ]) )
00131 
00132 
00133 #
00134 #SingleMu
00135 #
00136 toAdd = [ layDefaults('SingleMu/00%s - Fake rate from muons vs %s' % item,'RealMuonsData',item[1]) for item in variables.items() ]
00137 toAdd.extend( [ muRej('SingleMu/01%s - Muon rejection fake rate vs %s' % (item[0]%'',item[1]),item[1]) for item in variables.items() ] )
00138 toAdd.extend( [ layDefaults('SingleMu/02%s - Fake rate from jets vs %s' % item,'RealData',item[1]) for item in variables.items() ] )
00139 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() ] )
00140 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() ] )
00141 
00142 #
00143 #Jet
00144 #
00145 toAdd.extend([ layDefaults('Jet/00%s - Fake rate from jets vs %s' % item,'RealData',item[1]) for item in variables.items() ] )
00146 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() ] )
00147 
00148 #
00149 #DoubleE / TauPlusX
00150 #
00151 toAdd.extend([ layDefaults('DoubleElectron_OR_TauPlusX/00%s - Fake rate from electrons vs %s' % item,'RealElectronsData',item[1]) for item in variables.items() ] )
00152 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() ] )
00153 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() ] )
00154 
00155 layout = open('pftatau_T0_layouts.py','w')
00156 layout.write(layoutString % '\n'.join(toAdd) )
00157 layout.close()