Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:38

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