Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-09 00:51:32

0001 from __future__ import print_function
0002 import FWCore.ParameterSet.Config as cms
0003 import Validation.RecoTau.ValidationUtils as Utils
0004 import copy
0005 import re
0006 import os
0007 
0008 import RecoTauTag.Configuration.HPSPFTaus_cff as RecoModules #Working point indices are extracted from here
0009 
0010 #from Validation.RecoTau.ValidationOptions_cff import *
0011 
0012 
0013 """
0014 
0015    RecoTauValidation_cfi.py
0016 
0017    Contains the standard tau validation parameters.  It is organized into
0018    the following sections.
0019 
0020    DENOMINATOR 
0021      
0022      Set common kinematic cuts (pt > 5 and eta < 2.5) on the denominator source.
0023      Note that the denominator depends on the type of test (signal/background/e etc)
0024 
0025      The denominator kinematic cutter requires that 
0026 
0027    HISTOGRAMS
0028 
0029      Produce numerator and denominator histgorams used to produce
0030      tau efficiency plots
0031 
0032         Provides sequence: 
0033           TauValNumeratorAndDenominator 
0034         Requires:
0035           tauValSelectedDenominator (filtered GenJet collection)
0036         
0037    EFFICIENCY
0038    
0039      Using numerator and denominators, calculate and store
0040      the efficiency curves
0041 
0042         Provides sequence:
0043           TauEfficiencies
0044         Requires:
0045           TauValNumeratorAndDenominator
0046 
0047    PLOTTING
0048 
0049      Plot curves calculated in efficiency, in both an overlay mode
0050      showing overall performance for a release, and the indvidual 
0051      discriminator efficiency compared to a given release
0052 
0053         Provides sequence:
0054           loadTau
0055           plotTauValidation
0056           loadAndPlotTauValidation
0057 
0058         Requires:
0059           TauEfficiencies, external root file to compare to
0060 
0061      Plotting must be executed in a separate cmsRun job!
0062 
0063    UTILITIES
0064      
0065      Various scripts to automate things...
0066 
0067 
0068 """
0069 
0070 """
0071 
0072 DENOMINATOR
0073 
0074 """
0075 
0076 kinematicSelectedTauValDenominatorCut = cms.string('pt > 5. && abs(eta) < 2.5')
0077 denominator = cms.InputTag("kinematicSelectedTauValDenominator")
0078 
0079 """
0080 
0081 HISTOGRAMS
0082 
0083         Plot the pt/eta/energy/phi spectrum of PFTaus that pass 
0084         a series of PFTauDiscriminator cuts.
0085 
0086         These will be used as the numerator/denominators of the
0087         efficiency calculations
0088 """
0089 
0090 #Helper process to make future cloning easier
0091 proc = cms.Process('helper')
0092 
0093 StandardMatchingParameters = cms.PSet(
0094    DataType                     = cms.string('Leptons'),               
0095    MatchDeltaR_Leptons          = cms.double(0.15),
0096    MatchDeltaR_Jets             = cms.double(0.3),
0097    SaveOutputHistograms         = cms.bool(False), #TRUE FOR TEST ONLY
0098    #RefCollection                = cms.InputTag("TauGenJetProducer","selectedGenTauDecaysToHadronsPt5Cumulative"),
0099    RefCollection                = denominator,
0100    TauPtCut                     = cms.double(0.), #almost deprecated, since recoCuts provides more flexibility
0101    recoCuts                     = cms.string(''), #filter reconstructed candidates. leave this empty to select all. or use sth like: pt > 20 & abs(eta) < 2.3
0102    genCuts                      = cms.string(''), #filter generated candidates. leave this empty to select all. or use sth like: pt > 20 & abs(eta) < 2.3
0103    chainCuts                    = cms.bool(False) #Decide whether to chain discriminators or not
0104 )
0105 
0106 GenericTriggerSelectionParameters = cms.PSet(
0107    andOr          = cms.bool( False ),#specifies the logical combination of the single filters' (L1, HLT and DCS) decisions at top level (True=OR)
0108    dbLabel        = cms.string("PFTauDQMTrigger"),#specifies the label under which the DB payload is available from the ESSource or Global Tag
0109    andOrHlt       = cms.bool(True),#specifies the logical combination of the single HLT paths' decisions (True=OR)
0110    hltInputTag    = cms.InputTag("TriggerResults::HLT"),
0111    #hltDBKey       = cms.string('jetmet_highptjet'),#Tag of the record in the database, where IOV-based HLT paths are found. This record overwrites the configuration parameter hltPaths
0112    hltPaths       = cms.vstring('HLT_IsoMu*_eta*_LooseIsoPFTau*_v*','HLT_DoubleIsoPFTau*_Trk*_eta*_v*'),#Lists logical expressions of HLT paths, which should have accepted the event (fallback in case DB unaccessible)
0113    errorReplyHlt  = cms.bool(False),#specifies the desired return value of the HLT filter and the single HLT path filter in case of certain errors
0114    verbosityLevel = cms.uint32(0) #0: complete silence (default), needed for T0 processing;
0115 )
0116 
0117 from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer
0118 proc.templateAnalyzer = DQMEDAnalyzer(
0119    "TauTagValidation",
0120    StandardMatchingParameters,
0121    GenericTriggerSelection = GenericTriggerSelectionParameters,
0122    ExtensionName           = cms.string(""),
0123    TauProducer             = cms.InputTag(''),
0124    discriminators          = cms.VPSet(
0125    )
0126 )
0127 
0128 
0129 proc.RunHPSValidation = proc.templateAnalyzer.clone()
0130 
0131 #for fast sim we need to ignore the HLT TriggerResults
0132 from Configuration.Eras.Modifier_fastSim_cff import fastSim
0133 fastSim.toModify(
0134    proc.RunHPSValidation, 
0135    hltInputTag = cms.InputTag(""), 
0136    GenericTriggerSelection=dict(hltInputTag = cms.InputTag("")) 
0137 )
0138 
0139 proc.RunHPSValidation.ExtensionName = ""
0140 #RunHPSValidation.TauPtCut = cms.double(15.)
0141 proc.RunHPSValidation.TauProducer   = cms.InputTag('hpsPFTauProducer')
0142 
0143 def tauIDMVAinputs(module, wp):
0144     return {"container" : cms.string(module), "workingPointIndex" : cms.int32(-1 if wp=="raw" else getattr(RecoModules, module).workingPoints.index(wp))}
0145 def tauIDbasicinputs(module, wp):
0146     index = RecoModules.getBasicTauDiscriminatorRawIndex(getattr(RecoModules, module), wp, True)
0147     if index==None:
0148         index = RecoModules.getBasicTauDiscriminatorWPIndex(getattr(RecoModules, module), wp, True)
0149     else:
0150         index = -index - 1 #use negative indices for raw values
0151     if index!=None:
0152         return {"container" : cms.string(module), "workingPointIndex" : cms.int32(index)}
0153     print ("Basic Tau Discriminator <{}> <{}> for Validation configuration not found!".format(module, wp))
0154     raise Exception
0155 
0156 proc.RunHPSValidation.discriminators = cms.VPSet(
0157    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByDecayModeFinding"),plotStep = cms.bool(True),selectionCut = cms.double(0.5),container = cms.string("")),
0158    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByDecayModeFindingNewDMs"),plotStep = cms.bool(True),selectionCut = cms.double(0.5),container = cms.string("")),
0159    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByDecayModeFindingOldDMs"),plotStep = cms.bool(True),selectionCut = cms.double(0.5),container = cms.string("")),
0160    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr3Hits"),plotStep = cms.bool(True),container = cms.string("hpsPFTauBasicDiscriminators"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByLooseCombinedIsolationDBSumPtCorr3Hits")),
0161    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumCombinedIsolationDBSumPtCorr3Hits"),plotStep = cms.bool(True),container = cms.string("hpsPFTauBasicDiscriminators"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByMediumCombinedIsolationDBSumPtCorr3Hits")),
0162    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr3Hits"),plotStep = cms.bool(True),container = cms.string("hpsPFTauBasicDiscriminators"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByTightCombinedIsolationDBSumPtCorr3Hits")),
0163    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseElectronRejection"),plotStep = cms.bool(False),selectionCut = cms.double(0.5),container = cms.string("")),
0164    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumElectronRejection"),plotStep = cms.bool(True),selectionCut = cms.double(0.5),container = cms.string("")),
0165    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightElectronRejection"),plotStep = cms.bool(False),selectionCut = cms.double(0.5),container = cms.string("")),
0166    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5VLooseElectronRejection"),plotStep = cms.bool(False),selectionCut = cms.double(0.5),container = cms.string("")),
0167    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5LooseElectronRejection"),plotStep = cms.bool(False),selectionCut = cms.double(0.5),container = cms.string("")),
0168    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5MediumElectronRejection"),plotStep = cms.bool(False),selectionCut = cms.double(0.5),container = cms.string("")),
0169    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5TightElectronRejection"),plotStep = cms.bool(False),selectionCut = cms.double(0.5),container = cms.string("")),
0170    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA5VTightElectronRejection"),plotStep = cms.bool(False),selectionCut = cms.double(0.5),container = cms.string("")),
0171    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseMuonRejection3"),plotStep = cms.bool(True),container = cms.string("hpsPFTauDiscriminationByMuonRejection3"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByLooseMuonRejection3")),
0172    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightMuonRejection3"),plotStep = cms.bool(True),container = cms.string("hpsPFTauDiscriminationByMuonRejection3"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByTightMuonRejection3")),
0173    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA6VLooseElectronRejection"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByMVA6ElectronRejection"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VLoose")),
0174    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA6LooseElectronRejection"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByMVA6ElectronRejection"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Loose")),
0175    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA6MediumElectronRejection"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByMVA6ElectronRejection"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Medium")),
0176    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA6TightElectronRejection"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByMVA6ElectronRejection"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Tight")),
0177    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMVA6VTightElectronRejection"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByMVA6ElectronRejection"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VTight")),
0178    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBoldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VLoose")),
0179    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseIsolationMVArun2v1DBoldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Loose")),
0180    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumIsolationMVArun2v1DBoldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Medium")),
0181    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightIsolationMVArun2v1DBoldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Tight")),
0182    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVTightIsolationMVArun2v1DBoldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VTight")),
0183    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVVTightIsolationMVArun2v1DBoldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VVTight")),
0184    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBnewDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VLoose")),
0185    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseIsolationMVArun2v1DBnewDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Loose")),
0186    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumIsolationMVArun2v1DBnewDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Medium")),
0187    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightIsolationMVArun2v1DBnewDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Tight")),
0188    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVTightIsolationMVArun2v1DBnewDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VTight")),
0189    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVVTightIsolationMVArun2v1DBnewDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBnewDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VVTight")),
0190    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr3HitsdR03"),plotStep = cms.bool(True),container = cms.string("hpsPFTauBasicDiscriminatorsdR03"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByLooseCombinedIsolationDBSumPtCorr3HitsdR03")),
0191    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumCombinedIsolationDBSumPtCorr3HitsdR03"),plotStep = cms.bool(True),container = cms.string("hpsPFTauBasicDiscriminatorsdR03"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByMediumCombinedIsolationDBSumPtCorr3HitsdR03")),
0192    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr3HitsdR03"),plotStep = cms.bool(True),container = cms.string("hpsPFTauBasicDiscriminatorsdR03"),provenanceConfigLabel=cms.string("IDWPdefinitions"),idLabel=cms.string("ByTightCombinedIsolationDBSumPtCorr3HitsdR03")),
0193    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBdR03oldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VLoose")),
0194    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseIsolationMVArun2v1DBdR03oldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Loose")),
0195    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumIsolationMVArun2v1DBdR03oldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Medium")),
0196    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightIsolationMVArun2v1DBdR03oldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_Tight")),
0197    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVTightIsolationMVArun2v1DBdR03oldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VTight")),
0198    #cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVVTightIsolationMVArun2v1DBdR03oldDMwLT"),plotStep = cms.bool(False),container = cms.string("hpsPFTauDiscriminationByIsolationMVArun2v1DBdR03oldDMwLT"),provenanceConfigLabel=cms.string("workingPoints"),idLabel=cms.string("_VVTight")),
0199 )
0200 
0201 proc.TauValNumeratorAndDenominator = cms.Sequence(
0202       proc.RunHPSValidation
0203    )
0204 
0205 """
0206 
0207 EFFICIENCY
0208 
0209         Tau efficiency calculations
0210 
0211         Define the Efficiency curves to produce.  Each
0212         efficiency producer takes the numberator and denominator
0213         histograms and the dependent variables.
0214 """
0215 
0216 plotPset = Utils.SetPlotSequence(proc.TauValNumeratorAndDenominator)
0217 from DQMServices.Core.DQMEDHarvester import DQMEDHarvester
0218 proc.efficiencies = DQMEDHarvester(
0219    "TauDQMHistEffProducer",
0220    plots = plotPset    
0221    )
0222 
0223 
0224 ################################################
0225 #
0226 #         Normalizes All the histograms
0227 #
0228 ################################################
0229 
0230 proc.normalizePlots = cms.EDAnalyzer(
0231    "DQMHistNormalizer",
0232    plotNamesToNormalize = cms.vstring('*_pTRatio_*','*_Size_*','*_SumPt_*','*_dRTauRefJet*'),
0233    reference = cms.string('*_pTRatio_allHadronic')
0234    )
0235 
0236 proc.TauEfficiencies = cms.Sequence(
0237    proc.efficiencies*
0238    proc.normalizePlots
0239    )
0240 
0241 """
0242 
0243 PLOTTING
0244 
0245         loadTau:  load two separate TauVal root files into the DQM
0246                   so the plotter can access them
0247 
0248 """
0249 
0250 loadTau = DQMEDAnalyzer("TauDQMFileLoader",
0251   test = cms.PSet(
0252     #inputFileNames = cms.vstring('/afs/cern.ch/user/f/friis/scratch0/MyValidationArea/310pre6NewTags/src/Validation/RecoTau/test/CMSSW_3_1_0_pre6_ZTT_0505Fixes.root'),
0253     inputFileNames = cms.vstring('/opt/sbg/cms/ui4_data1/dbodin/CMSSW_3_5_1/src/TauID/QCD_recoFiles/TauVal_CMSSW_3_6_0_QCD.root'),
0254     scaleFactor = cms.double(1.),
0255     dqmDirectory_store = cms.string('test')
0256   ),
0257   reference = cms.PSet(
0258     inputFileNames = cms.vstring('/opt/sbg/cms/ui4_data1/dbodin/CMSSW_3_5_1/src/TauID/QCD_recoFiles/TauVal_CMSSW_3_6_0_QCD.root'),
0259     scaleFactor = cms.double(1.),
0260     dqmDirectory_store = cms.string('reference')
0261   )
0262 )
0263 
0264 # Lots of junk to define the plot style
0265 
0266 # standard drawing stuff
0267 xAxisStuff = cms.PSet(
0268    xAxisTitle = cms.string('P_{T} / GeV'),
0269    xAxisTitleOffset = cms.double(0.9),
0270    xAxisTitleSize = cms.double(0.05)
0271 )
0272 xModifiers = [['pt',['xAxisTitle'],['P_{T} / GeV']],['eta',['xAxisTitle'],['#eta']],['phi',['xAxisTitle'],['#phi']],['pileup',['xAxisTitle'],['# of Reco Vertices']]]
0273 
0274 yAxisStuff =cms.PSet(
0275    yScale = cms.string('linear'), # linear/log
0276    minY_linear = cms.double(0.),
0277    maxY_linear = cms.double(1.6),
0278    minY_log = cms.double(0.001),
0279    maxY_log = cms.double(1.8),
0280    yAxisTitle = cms.string('#varepsilon'), 
0281    yAxisTitleOffset = cms.double(1.1),
0282    yAxisTitleSize = cms.double(0.05)
0283 )
0284 yModifiers = [['efficiency',['yScale','yAxisTitle'],['linear','#varepsilon']],['fakeRate',['yScale','yAxisTitle'],['log','Fake rate']]]
0285 
0286 legStuff = cms.PSet(
0287    posX = cms.double(0.50),
0288    posY = cms.double(0.72),
0289    sizeX = cms.double(0.39),
0290    sizeY = cms.double(0.17),
0291    header = cms.string(''),
0292    option = cms.string('brNDC'),
0293    borderSize = cms.int32(0),
0294    fillColor = cms.int32(0)
0295 )
0296 legModifiers = [['efficiency',['posY','sizeY'],[0.72,0.17]],['efficiency_overlay',['posY','sizeY'],[0.66,0.23]]]
0297 
0298 drawOptStuff = cms.PSet(
0299    markerColor = cms.int32(1),
0300    markerSize = cms.double(1.),
0301    markerStyle = cms.int32(20),
0302    lineColor = cms.int32(1),
0303    lineStyle = cms.int32(1),
0304    lineWidth = cms.int32(2),
0305    drawOption = cms.string('ex0'),
0306    drawOptionLegend = cms.string('p')
0307 )
0308 drawOptModifiers = [['eff_overlay01',['markerColor','lineColor'],[1,1]],['eff_overlay02',['markerColor','lineColor'],[2,2]],['eff_overlay03',['markerColor','lineColor'],[3,3]],['eff_overlay04',['markerColor','lineColor'],[4,4]],['eff_overlay05',['markerColor','lineColor'],[6,6]],['eff_overlay06',['markerColor','lineColor'],[5,5]],['eff_overlay07',['markerColor','lineColor'],[7,7]],['eff_overlay08',['markerColor','lineColor'],[28,28]],['eff_overlay09',['markerColor','lineColor','markerStyle'],[2,2,29]],['eff_overlay010',['markerColor','lineColor','markerStyle'],[4,4,29]],['eff_overlay011',['markerColor','lineColor','markerStyle'],[6,6,29]]]
0309 
0310 standardDrawingStuff = cms.PSet(
0311   canvasSizeX = cms.int32(640),
0312   canvasSizeY = cms.int32(640),                         
0313   indOutputFileName = cms.string('#PLOT#.png'),
0314   xAxes = Utils.SpawnPSet(xModifiers,xAxisStuff),
0315   yAxes = Utils.SpawnPSet(yModifiers,yAxisStuff),
0316   legends =  Utils.SpawnPSet(legModifiers,legStuff),
0317   labels = cms.PSet(
0318     pt = cms.PSet(
0319       posX = cms.double(0.19),
0320       posY = cms.double(0.77),
0321       sizeX = cms.double(0.12),
0322       sizeY = cms.double(0.04),
0323       option = cms.string('brNDC'),
0324       borderSize = cms.int32(0),
0325       fillColor = cms.int32(0),
0326       textColor = cms.int32(1),
0327       textSize = cms.double(0.04),
0328       textAlign = cms.int32(22),
0329       text = cms.vstring('P_{T} > 5 GeV') #vstring not supported by SpawnPSet
0330     ),
0331     eta = cms.PSet(
0332       posX = cms.double(0.19),
0333       posY = cms.double(0.83),
0334       sizeX = cms.double(0.12),
0335       sizeY = cms.double(0.04),
0336       option = cms.string('brNDC'),
0337       borderSize = cms.int32(0),
0338       fillColor = cms.int32(0),
0339       textColor = cms.int32(1),
0340       textSize = cms.double(0.04),
0341       textAlign = cms.int32(22),
0342       text = cms.vstring('-2.5 < #eta < +2.5')
0343     )
0344   ),
0345   drawOptionSets = cms.PSet(
0346     efficiency = cms.PSet(
0347         test = cms.PSet(
0348         markerColor = cms.int32(4),
0349         markerSize = cms.double(1.),
0350         markerStyle = cms.int32(20),
0351         lineColor = cms.int32(1),
0352         lineStyle = cms.int32(1),
0353         lineWidth = cms.int32(1),
0354         drawOption = cms.string('ep'),
0355         drawOptionLegend = cms.string('p')
0356       ),
0357       reference = cms.PSet(
0358         lineColor = cms.int32(1),
0359         lineStyle = cms.int32(1),
0360         lineWidth = cms.int32(1),
0361         fillColor = cms.int32(41),
0362         drawOption = cms.string('eBand'),
0363         drawOptionLegend = cms.string('l')
0364       )
0365     )
0366   ),
0367   drawOptionEntries =  Utils.SpawnPSet(drawOptModifiers,drawOptStuff)
0368 )
0369 
0370 standardCompareTestAndReference = cms.PSet(
0371   processes = cms.PSet(
0372     test = cms.PSet(
0373       dqmDirectory = cms.string('test'),
0374       legendEntry = cms.string('no test label'),
0375       type = cms.string('smMC') # Data/smMC/bsmMC/smSumMC
0376     ),
0377     reference = cms.PSet(
0378       dqmDirectory = cms.string('reference'),
0379       legendEntry = cms.string('no ref label'),
0380       type = cms.string('smMC') # Data/smMC/bsmMC/smSumMC
0381     )
0382   ),
0383 )
0384         
0385 
0386 ##################################################
0387 #
0388 #   The plotting of HPS Efficiencies
0389 #
0390 ##################################################
0391 ## plotHPSEfficiencies = DQMEDAnalyzer("TauDQMHistPlotter",
0392 ##                                      standardDrawingStuff,
0393 ##                                      standardCompareTestAndReference,
0394 ##                                      drawJobs = Utils.SpawnDrawJobs(RunHPSValidation, plotPset),
0395 ##                                      outputFilePath = cms.string('./hpsPFTauProducer/'),
0396 ##                                      PrintToFile = cms.bool(True)
0397 ##                                      )
0398 ## #clone for DQM
0399 ## plotHPSEfficiencies2 = plotHPSEfficiencies.clone()
0400 
0401 
0402 ##################################################
0403 #
0404 #   The plotting of all the Shrinking cone leading pion efficiencies
0405 #
0406 ##################################################
0407 ## plotPFTauHighEfficiencyEfficienciesLeadingPion = DQMEDAnalyzer("TauDQMHistPlotter",
0408 ##                                                                 standardDrawingStuff,
0409 ##                                                                 standardCompareTestAndReference,
0410 ##                                                                 drawJobs = Utils.SpawnDrawJobs(PFTausHighEfficiencyLeadingPionBothProngs, plotPset),
0411 ##                                                                 outputFilePath = cms.string('./shrinkingConePFTauProducerLeadingPion/'),
0412 ##                                                                 PrintToFile = cms.bool(True)
0413 ##                                                                 )
0414 ## #clone for DQM
0415 ## plotPFTauHighEfficiencyEfficienciesLeadingPion2 = plotPFTauHighEfficiencyEfficienciesLeadingPion.clone()
0416 
0417 
0418 ## plotTauValidation = cms.Sequence(
0419 ##       plotPFTauHighEfficiencyEfficienciesLeadingPion
0420 ##       +plotHPSEfficiencies
0421 ##       )
0422 
0423 ## plotTauValidation2 = cms.Sequence(
0424 ##       plotPFTauHighEfficiencyEfficienciesLeadingPion2
0425 ##       +plotHPSEfficiencies2
0426 ##       )
0427 
0428 
0429 ## loadAndPlotTauValidation = cms.Sequence(
0430 ##       loadTau
0431 ##       +plotTauValidation
0432 ##       )
0433 
0434 """
0435 
0436 UTILITIES
0437 
0438 """
0439 
0440 class ApplyFunctionToSequence:
0441    """ Helper class that applies a given function to all modules
0442        in a sequence """
0443    def __init__(self,function):
0444       self.functor = function
0445    def enter(self, module):
0446       self.functor(module)
0447    def leave(self, module):
0448       pass
0449 
0450 def TranslateToLegacyProdNames(input):
0451    input = re.sub('fixedConePFTauProducer', 'pfRecoTauProducer', input)
0452    #fixedDiscriminationRegex = re.compile('fixedConePFTauDiscrimination( \w* )')
0453    fixedDiscriminationRegex = re.compile('fixedConePFTauDiscrimination(\w*)')
0454    input = fixedDiscriminationRegex.sub(r'pfRecoTauDiscrimination\1', input)
0455    input = re.sub('shrinkingConePFTauProducer', 'pfRecoTauProducerHighEfficiency', input)
0456    shrinkingDiscriminationRegex = re.compile('shrinkingConePFTauDiscrimination(\w*)')
0457    input = shrinkingDiscriminationRegex.sub(r'pfRecoTauDiscrimination\1HighEfficiency', input)
0458    return input
0459 
0460 
0461 def ConvertDrawJobToLegacyCompare(input):
0462    """ Converts a draw job defined to compare 31X named PFTau validtion efficiencies
0463        to comapre a 31X to a 22X named validation """
0464    # get the list of drawjobs { name : copyOfPSet }
0465    if not hasattr(input, "drawJobs"):
0466       return
0467    myDrawJobs = input.drawJobs.parameters_()
0468    for drawJobName, drawJobData in myDrawJobs.items():
0469       print(drawJobData)
0470       if not drawJobData.plots.pythonTypeName() == "cms.PSet":
0471          continue
0472       pSetToInsert = cms.PSet(
0473             standardEfficiencyParameters,
0474             plots = cms.VPSet(
0475                # test plot w/ modern names
0476                cms.PSet(
0477                   dqmMonitorElements = drawJobData.plots.dqmMonitorElements,
0478                   process = cms.string('test'),
0479                   drawOptionEntry = cms.string('eff_overlay01'),
0480                   legendEntry = cms.string(input.processes.test.legendEntry.value())
0481                   ),
0482                # ref plot w/ vintage name
0483                cms.PSet(
0484                   # translate the name
0485                   dqmMonitorElements = cms.vstring(TranslateToLegacyProdNames(drawJobData.plots.dqmMonitorElements.value()[0])),
0486                   process = cms.string('reference'),
0487                   drawOptionEntry = cms.string('eff_overlay02'),
0488                   legendEntry = cms.string(input.processes.reference.legendEntry.value())
0489                   )
0490                )
0491             )
0492       input.drawJobs.__setattr__(drawJobName, pSetToInsert)
0493 
0494 def MakeLabeler(TestLabel, ReferenceLabel):
0495    def labeler(module):
0496       if hasattr(module, 'processes'):
0497          if module.processes.hasParameter(['test', 'legendEntry']) and module.processes.hasParameter([ 'reference', 'legendEntry']):
0498             module.processes.test.legendEntry = TestLabel
0499             module.processes.reference.legendEntry = ReferenceLabel
0500             print("Set test label to %s and reference label to %s for plot producer %s" % (TestLabel, ReferenceLabel, module.label()))
0501          else:
0502             print("ERROR in RecoTauValidation_cfi::MakeLabeler - trying to set test/reference label but %s does not have processes.(test/reference).legendEntry parameters!" % module.label())
0503    return labeler
0504 
0505 def SetYmodulesToLog(matchingNames = []):
0506    ''' set all modules whose name contains one of the matching names to log y scale'''
0507    def yLogger(module):
0508       ''' set a module to use log scaling in the yAxis'''
0509       if hasattr(module, 'drawJobs'):
0510          print("EK DEBUG")
0511          drawJobParamGetter = lambda subName : getattr(module.drawJobs, subName)
0512          #for subModule in [getattr(module.drawJobs, subModuleName) for subModuleName in dir(module.drawJobs)]:
0513          attrNames = dir(module.drawJobs)
0514          for subModuleName, subModule in zip(attrNames, map(drawJobParamGetter, attrNames)):
0515             matchedNames = [name for name in matchingNames if subModuleName.find( name) > -1] # matching sub strings
0516             if len(matchingNames) == 0:
0517                matchedNames = ['take','everything','and','dont','bother']
0518             if hasattr(subModule, "yAxis") and len(matchedNames):
0519                print("Setting drawJob: ", subModuleName, " to log scale.")
0520                subModule.yAxis = cms.string('fakeRate') #'fakeRate' configuration specifies the log scaling
0521          if len(matchingNames) == 0: 
0522             module.yAxes.efficiency.maxY_log = 40
0523             module.yAxes.fakeRate.maxY_log = 40
0524    return yLogger
0525 
0526 
0527 def SetBaseDirectory(Directory):
0528    def BaseDirectorizer(module):
0529       newPath = Directory
0530       #if module.hasParameter("outputFilePath"):
0531       if hasattr(module, "outputFilePath"):
0532          oldPath = module.outputFilePath.value()
0533          newPath = os.path.join(newPath, oldPath)
0534          if not os.path.exists(newPath):
0535             os.makedirs(newPath)
0536          print(newPath)
0537          module.outputFilePath = cms.string("%s" % newPath)
0538    return BaseDirectorizer
0539 
0540 def RemoveComparisonPlotCommands(module):
0541    if hasattr(module, 'drawJobs'):
0542       #get draw job parameter names
0543       drawJobs = module.drawJobs.parameterNames_()
0544       for drawJob in drawJobs:
0545          if drawJob != "TauIdEffStepByStep":
0546             module.drawJobs.__delattr__(drawJob)
0547             print("Removing comparison plot", drawJob)
0548 
0549 def SetPlotDirectory(myPlottingSequence, directory):
0550    myFunctor = ApplyFunctionToSequence(SetBaseDirectory(directory))
0551    myPlottingSequence.visit(myFunctor)
0552 
0553 def SetTestAndReferenceLabels(myPlottingSequence, TestLabel, ReferenceLabel):
0554    myFunctor = ApplyFunctionToSequence(MakeLabeler(TestLabel, ReferenceLabel))
0555    myPlottingSequence.visit(myFunctor)
0556 
0557 def SetCompareToLegacyProductNames(myPlottingSequence):
0558    myFunctor = ApplyFunctionToSequence(ConvertDrawJobToLegacyCompare)
0559    myPlottingSequence.visit(myFunctor)
0560 
0561 def SetTestFileToPlot(myProcess, FileLoc):
0562    myProcess.loadTau.test.inputFileNames = cms.vstring(FileLoc)
0563 
0564 def SetReferenceFileToPlot(myProcess, FileLoc):
0565    if FileLoc == None:
0566       del myProcess.loadTau.reference
0567    else:
0568       myProcess.loadTau.reference.inputFileNames = cms.vstring(FileLoc)
0569 
0570 def SetLogScale(myPlottingSequence):
0571    myFunctor = ApplyFunctionToSequence(SetYmodulesToLog())
0572    myPlottingSequence.visit(myFunctor)
0573 
0574 def SetSmartLogScale(myPlottingSequence):
0575    myFunctor = ApplyFunctionToSequence(SetYmodulesToLog(['Electron', 'Muon', 'Isolation', 'TaNC']))
0576    myPlottingSequence.visit(myFunctor)
0577 
0578 def SetPlotOnlyStepByStep(myPlottingSequence):
0579    myFunctor = ApplyFunctionToSequence(RemoveComparisonPlotCommands)
0580    myPlottingSequence.visit(myFunctor)
0581 
0582 def SetValidationExtention(module, extension):
0583     module.ExtensionName = module.ExtensionName.value()+extension
0584 
0585 def setBinning(module,pset):
0586     if module._TypedParameterizable__type == 'TauTagValidation':
0587         module.histoSettings = pset
0588 
0589 def setTrigger(module,pset):
0590    if hasattr(module,'_TypedParameterizable__type') and module._TypedParameterizable__type == 'TauTagValidation':
0591       setattr(module,'turnOnTrigger',cms.bool(True)) #Turns on trigger (in case is off)
0592       for item in pset.parameters_().items():
0593          setattr(module.GenericTriggerSelection,item[0],item[1])