CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Validation/RecoTau/python/RecoTauValidation_cfi.py

Go to the documentation of this file.
00001 import FWCore.ParameterSet.Config as cms
00002 import Validation.RecoTau.ValidationUtils as Utils
00003 import copy
00004 import re
00005 import os
00006 
00007 from Validation.RecoTau.ValidationOptions_cfi import *
00008 
00009 
00010 """
00011 
00012    RecoTauValidation_cfi.py
00013 
00014    Contains the standard tau Validation parameters.  It is organized into
00015    the following sections.
00016 
00017    DENOMINATOR 
00018      
00019      Set common kinematic cuts (pt > 5 and eta < 2.5) on the denominator source.
00020      Note that the denominator depends on the type of test (signal/background/e etc)
00021 
00022      The denominator kinematic cutter requires that 
00023 
00024    HISTOGRAMS
00025 
00026      Produce numerator and denominator histgorams used to produce
00027      tau efficiency plots
00028 
00029         Provides sequence: 
00030           TauValNumeratorAndDenominator 
00031         Requires:
00032           tauValSelectedDenominator (filtered GenJet collection)
00033         
00034    EFFICIENCY
00035    
00036      Using numerator and denominators, calculate and store
00037      the efficiency curves
00038 
00039         Provides sequence:
00040           TauEfficiencies
00041         Requires:
00042           TauValNumeratorAndDenominator
00043 
00044    PLOTTING
00045 
00046      Plot curves calculated in efficiency, in both an overlay mode
00047      showing overall performance for a release, and the indvidual 
00048      discriminator efficiency compared to a given release
00049 
00050         Provides sequence:
00051           loadTau
00052           plotTauValidation
00053           loadAndPlotTauValidation
00054 
00055         Requires:
00056           TauEfficiencies, external root file to compare to
00057 
00058      Plotting must be executed in a separate cmsRun job!
00059 
00060    UTILITIES
00061      
00062      Various scripts to automate things...
00063 
00064 
00065 """
00066 
00067 """
00068 
00069 DENOMINATOR
00070 
00071 """
00072 
00073 # require generator level hadrons produced in tau-decay to have transverse momentum above threshold
00074 kinematicSelectedTauValDenominator = cms.EDFilter("GenJetSelector",
00075      src = cms.InputTag("objectTypeSelectedTauValDenominator"),
00076      cut = cms.string('pt > 5. && abs(eta) < 2.5'),
00077      filter = cms.bool(False)
00078 )
00079 
00080 denominator = cms.InputTag("kinematicSelectedTauValDenominator")
00081 
00082 """
00083 
00084 HISTOGRAMS
00085 
00086         Plot the pt/eta/energy/phi spectrum of PFTaus that pass 
00087         a series of PFTauDiscriminator cuts.
00088 
00089         These will be used as the numerator/denominators of the
00090         efficiency calculations
00091 """
00092 
00093 StandardMatchingParameters = cms.PSet(
00094    DataType                     = cms.string('Leptons'),               
00095    MatchDeltaR_Leptons          = cms.double(0.15),
00096    MatchDeltaR_Jets             = cms.double(0.3),
00097    SaveOutputHistograms         = cms.bool(False), #TRUE FOR TEST ONLY
00098    #RefCollection                = cms.InputTag("TauGenJetProducer","selectedGenTauDecaysToHadronsPt5Cumulative"),
00099    RefCollection                = cms.InputTag("kinematicSelectedTauValDenominator"),
00100 )
00101 
00102 PFTausHighEfficiencyLeadingPionBothProngs = cms.EDAnalyzer("TauTagValidation",
00103    StandardMatchingParameters,
00104    ExtensionName                = cms.string("LeadingPion"),
00105    TauProducer                  = cms.InputTag('shrinkingConePFTauProducer'),
00106    discriminators               = cms.VPSet(
00107     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationByLeadingTrackFinding"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00108     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationByLeadingPionPtCut"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)), #not plotted
00109     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationByTrackIsolationUsingLeadingPion"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00110     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationByECALIsolationUsingLeadingPion"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00111     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationAgainstElectron"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00112     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationAgainstMuon"),selectionCut = cms.double(0.5),plotStep = cms.bool(True))
00113  )
00114 )
00115 
00116 PFTausHighEfficiencyBothProngs = cms.EDAnalyzer("TauTagValidation",
00117    StandardMatchingParameters,
00118    ExtensionName                = cms.string(""),
00119    TauProducer                  = cms.InputTag('shrinkingConePFTauProducer'),
00120    discriminators               = cms.VPSet(
00121     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationByLeadingTrackFinding"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00122     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationByLeadingTrackPtCut"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)), #not plotted
00123     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationByTrackIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00124     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationByECALIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00125     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationAgainstElectron"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00126     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationAgainstMuon"),selectionCut = cms.double(0.5),plotStep = cms.bool(True))
00127  )
00128 )
00129 
00130 RunTancValidation = copy.deepcopy(PFTausHighEfficiencyBothProngs)
00131 RunTancValidation.ExtensionName = "Tanc"
00132 RunTancValidation.discriminators = cms.VPSet(
00133     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationByLeadingTrackFinding"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00134     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationByLeadingPionPtCut"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)), #not plotted
00135     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationByTaNCfrOnePercent"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00136     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationByTaNCfrHalfPercent"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00137     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationByTaNCfrQuarterPercent"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00138     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationByTaNCfrTenthPercent"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00139     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationAgainstElectron"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00140     cms.PSet( discriminator = cms.string("shrinkingConePFTauDiscriminationAgainstMuon"),selectionCut = cms.double(0.5),plotStep = cms.bool(True))
00141 )
00142 
00143 RunHPSValidation = copy.deepcopy(PFTausHighEfficiencyBothProngs)
00144 RunHPSValidation.ExtensionName = ""
00145 RunHPSValidation.TauProducer   = cms.InputTag('hpsPFTauProducer')
00146 RunHPSValidation.discriminators = cms.VPSet(
00147    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByDecayModeFinding"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00148    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByVLooseIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00149    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00150    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00151    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00152    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
00153    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByMediumElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00154    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
00155    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByLooseMuonRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00156    cms.PSet( discriminator = cms.string("hpsPFTauDiscriminationByTightMuonRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False))
00157 )
00158 
00159 RunHPSTanc_HPSValidation = copy.deepcopy(PFTausHighEfficiencyBothProngs)
00160 RunHPSTanc_HPSValidation.ExtensionName = "_HPS"
00161 RunHPSTanc_HPSValidation.TauProducer   = cms.InputTag('hpsTancTaus')
00162 RunHPSTanc_HPSValidation.discriminators = cms.VPSet(
00163    cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByDecayModeSelection"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00164    cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByVLooseIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00165    cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByLooseIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00166    cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByMediumIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00167    cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByTightIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00168    cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByLooseElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
00169    cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByMediumElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00170    cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByTightElectronRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
00171    cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByLooseMuonRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00172    cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByTightMuonRejection"),selectionCut = cms.double(0.5),plotStep = cms.bool(False))
00173 )
00174 
00175 RunHPSTanc_TANCValidation = copy.deepcopy(PFTausHighEfficiencyBothProngs)
00176 RunHPSTanc_TANCValidation.ExtensionName = "_TANC"
00177 RunHPSTanc_TANCValidation.TauProducer   = cms.InputTag('hpsTancTaus')
00178 RunHPSTanc_TANCValidation.discriminators = cms.VPSet(
00179     cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByDecayModeSelection"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00180     cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByLeadingPionPtCut"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)), #not plotted
00181     cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByLeadingTrackFinding"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
00182     cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByLeadingTrackPtCut"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)), #not plotted
00183     cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByTanc"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
00184     cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByTancVLoose"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
00185     cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByTancLoose"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00186     cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByTancMedium"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
00187     cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByTancRaw"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)),
00188     cms.PSet( discriminator = cms.string("hpsTancTausDiscriminationByTancTight"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00189 )
00190 
00191 CaloTausBothProngs = cms.EDAnalyzer("TauTagValidation",
00192    StandardMatchingParameters,
00193    ExtensionName                = cms.string(""),
00194    TauProducer                  = cms.InputTag('caloRecoTauProducer'),
00195    discriminators = cms.VPSet(
00196     cms.PSet( discriminator = cms.string("caloRecoTauDiscriminationByLeadingTrackFinding"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00197     cms.PSet( discriminator = cms.string("caloRecoTauDiscriminationByLeadingTrackPtCut"),selectionCut = cms.double(0.5),plotStep = cms.bool(False)), #not plotted
00198     cms.PSet( discriminator = cms.string("caloRecoTauDiscriminationByIsolation"),selectionCut = cms.double(0.5),plotStep = cms.bool(True)),
00199     cms.PSet( discriminator = cms.string("caloRecoTauDiscriminationAgainstElectron"),selectionCut = cms.double(0.5),plotStep = cms.bool(True))
00200  )
00201 )
00202 
00203 TauValNumeratorAndDenominator = cms.Sequence(
00204 #      PFTausBothProngs+ OLD
00205       RunHPSTanc_HPSValidation*
00206       RunHPSTanc_TANCValidation*
00207       CaloTausBothProngs *
00208       PFTausHighEfficiencyBothProngs*
00209       PFTausHighEfficiencyLeadingPionBothProngs*
00210       RunTancValidation*
00211       RunHPSValidation
00212    )
00213 
00214 """
00215 
00216 EFFICIENCY
00217 
00218         Tau efficiency calculations
00219 
00220         Define the Efficiency curves to produce.  Each
00221         efficiency producer takes the numberator and denominator
00222         histograms and the dependent variables.
00223 """
00224 
00225 plotPset = Utils.SetPlotSequence(TauValNumeratorAndDenominator)
00226 TauEfficiencies = cms.EDAnalyzer("DQMHistEffProducer",
00227     plots = plotPset    
00228 )
00229 
00230  
00231 """
00232 
00233 PLOTTING
00234 
00235         loadTau:  load two separate TauVal root files into the DQM
00236                   so the plotter can access them
00237 
00238 """
00239 
00240 loadTau = cms.EDAnalyzer("DQMFileLoader",
00241   test = cms.PSet(
00242     #inputFileNames = cms.vstring('/afs/cern.ch/user/f/friis/scratch0/MyValidationArea/310pre6NewTags/src/Validation/RecoTau/test/CMSSW_3_1_0_pre6_ZTT_0505Fixes.root'),
00243     inputFileNames = cms.vstring('/opt/sbg/cms/ui4_data1/dbodin/CMSSW_3_5_1/src/TauID/QCD_recoFiles/TauVal_CMSSW_3_6_0_QCD.root'),
00244     scaleFactor = cms.double(1.),
00245     dqmDirectory_store = cms.string('test')
00246   ),
00247   reference = cms.PSet(
00248     inputFileNames = cms.vstring('/opt/sbg/cms/ui4_data1/dbodin/CMSSW_3_5_1/src/TauID/QCD_recoFiles/TauVal_CMSSW_3_6_0_QCD.root'),
00249     scaleFactor = cms.double(1.),
00250     dqmDirectory_store = cms.string('reference')
00251   )
00252 )
00253 
00254 # Lots of junk to define the plot style
00255 
00256 # standard drawing stuff
00257 xAxisStuff = cms.PSet(
00258    xAxisTitle = cms.string('P_{T} / GeV'),
00259    xAxisTitleOffset = cms.double(0.9),
00260    xAxisTitleSize = cms.double(0.05)
00261 )
00262 xModifiers = [['pt',['xAxisTitle'],['P_{T} / GeV']],['eta',['xAxisTitle'],['#eta']],['phi',['xAxisTitle'],['#phi']],['energy',['xAxisTitle'],['E / GeV']]]
00263 
00264 yAxisStuff =cms.PSet(
00265    yScale = cms.string('linear'), # linear/log
00266    minY_linear = cms.double(0.),
00267    maxY_linear = cms.double(1.6),
00268    minY_log = cms.double(0.001),
00269    maxY_log = cms.double(1.8),
00270    yAxisTitle = cms.string('#varepsilon'), 
00271    yAxisTitleOffset = cms.double(1.1),
00272    yAxisTitleSize = cms.double(0.05)
00273 )
00274 yModifiers = [['efficiency',['yScale'],['linear']],['fakeRate',['yScale'],['log']]]
00275 
00276 legStuff = cms.PSet(
00277    posX = cms.double(0.50),
00278    posY = cms.double(0.72),
00279    sizeX = cms.double(0.39),
00280    sizeY = cms.double(0.17),
00281    header = cms.string(''),
00282    option = cms.string('brNDC'),
00283    borderSize = cms.int32(0),
00284    fillColor = cms.int32(0)
00285 )
00286 legModifiers = [['efficiency',['posY','sizeY'],[0.72,0.17]],['efficiency_overlay',['posY','sizeY'],[0.66,0.23]]]
00287 
00288 drawOptStuff = cms.PSet(
00289    markerColor = cms.int32(1),
00290    markerSize = cms.double(1.),
00291    markerStyle = cms.int32(20),
00292    lineColor = cms.int32(1),
00293    lineStyle = cms.int32(1),
00294    lineWidth = cms.int32(2),
00295    drawOption = cms.string('ex0'),
00296    drawOptionLegend = cms.string('p')
00297 )
00298 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]]]
00299 
00300 standardDrawingStuff = cms.PSet(
00301   canvasSizeX = cms.int32(640),
00302   canvasSizeY = cms.int32(640),                         
00303   indOutputFileName = cms.string('#PLOT#.png'),
00304   xAxes = Utils.SpawnPSet(xModifiers,xAxisStuff),
00305   yAxes = Utils.SpawnPSet(yModifiers,yAxisStuff),
00306   legends =  Utils.SpawnPSet(legModifiers,legStuff),
00307   labels = cms.PSet(
00308     pt = cms.PSet(
00309       posX = cms.double(0.19),
00310       posY = cms.double(0.77),
00311       sizeX = cms.double(0.12),
00312       sizeY = cms.double(0.04),
00313       option = cms.string('brNDC'),
00314       borderSize = cms.int32(0),
00315       fillColor = cms.int32(0),
00316       textColor = cms.int32(1),
00317       textSize = cms.double(0.04),
00318       textAlign = cms.int32(22),
00319       text = cms.vstring('P_{T} > 5 GeV') #vstring not supported by SpawnPSet
00320     ),
00321     eta = cms.PSet(
00322       posX = cms.double(0.19),
00323       posY = cms.double(0.83),
00324       sizeX = cms.double(0.12),
00325       sizeY = cms.double(0.04),
00326       option = cms.string('brNDC'),
00327       borderSize = cms.int32(0),
00328       fillColor = cms.int32(0),
00329       textColor = cms.int32(1),
00330       textSize = cms.double(0.04),
00331       textAlign = cms.int32(22),
00332       text = cms.vstring('-2.5 < #eta < +2.5')
00333     )
00334   ),
00335   drawOptionSets = cms.PSet(
00336     efficiency = cms.PSet(
00337         test = cms.PSet(
00338         markerColor = cms.int32(4),
00339         markerSize = cms.double(1.),
00340         markerStyle = cms.int32(20),
00341         lineColor = cms.int32(1),
00342         lineStyle = cms.int32(1),
00343         lineWidth = cms.int32(1),
00344         drawOption = cms.string('ep'),
00345         drawOptionLegend = cms.string('p')
00346       ),
00347       reference = cms.PSet(
00348         lineColor = cms.int32(1),
00349         lineStyle = cms.int32(1),
00350         lineWidth = cms.int32(1),
00351         fillColor = cms.int32(41),
00352         drawOption = cms.string('eBand'),
00353         drawOptionLegend = cms.string('l')
00354       )
00355     )
00356   ),
00357   drawOptionEntries =  Utils.SpawnPSet(drawOptModifiers,drawOptStuff)
00358 )
00359 
00360 standardCompareTestAndReference = cms.PSet(
00361   processes = cms.PSet(
00362     test = cms.PSet(
00363       dqmDirectory = cms.string('test'),
00364       legendEntry = cms.string('no test label'),
00365       type = cms.string('smMC') # Data/smMC/bsmMC/smSumMC
00366     ),
00367     reference = cms.PSet(
00368       dqmDirectory = cms.string('reference'),
00369       legendEntry = cms.string('no ref label'),
00370       type = cms.string('smMC') # Data/smMC/bsmMC/smSumMC
00371     )
00372   ),
00373 )
00374         
00375 ##################################################
00376 #
00377 #   The plotting of all the HPS TaNC efficiencies
00378 #
00379 ##################################################
00380 plotPFTauEfficiencies_hps = cms.EDAnalyzer("DQMHistPlotter",
00381   standardDrawingStuff,
00382   standardCompareTestAndReference,
00383   drawJobs = Utils.SpawnDrawJobs(RunHPSTanc_HPSValidation, plotPset),
00384   outputFilePath = cms.string('./HPSTancTaus_HPS/'),
00385 )
00386 
00387 plotPFTauEfficiencies_tanc = cms.EDAnalyzer("DQMHistPlotter",
00388   standardDrawingStuff,
00389   standardCompareTestAndReference,
00390   drawJobs = Utils.SpawnDrawJobs(RunHPSTanc_TANCValidation, plotPset),
00391   outputFilePath = cms.string('./HPSTancTaus_TANC/'),
00392 )
00393 
00394 ##################################################
00395 #
00396 #   The plotting of HPS Efficiencies
00397 #
00398 ##################################################
00399 
00400 
00401 plotHPSEfficiencies = cms.EDAnalyzer("DQMHistPlotter",
00402   standardDrawingStuff,
00403   standardCompareTestAndReference,
00404   drawJobs = Utils.SpawnDrawJobs(RunHPSValidation, plotPset),
00405   outputFilePath = cms.string('./hpsPFTauProducer/')
00406 )      
00407 
00408 ##################################################
00409 #
00410 #   The plotting of all the PFTauHighEfficiencies ID efficiencies
00411 #
00412 ##################################################
00413 plotPFTauHighEfficiencyEfficiencies = cms.EDAnalyzer("DQMHistPlotter",
00414   standardDrawingStuff,
00415   standardCompareTestAndReference,
00416   drawJobs = Utils.SpawnDrawJobs(PFTausHighEfficiencyBothProngs, plotPset),
00417   outputFilePath = cms.string('./shrinkingConePFTauProducer/'),
00418 )      
00419 
00420 ##################################################
00421 #
00422 #   The plotting of all the CaloTau ID efficiencies
00423 #
00424 ##################################################
00425 
00426 plotCaloTauEfficiencies = cms.EDAnalyzer("DQMHistPlotter",
00427   standardDrawingStuff,
00428   standardCompareTestAndReference,
00429   drawJobs = Utils.SpawnDrawJobs(CaloTausBothProngs, plotPset),
00430   outputFilePath = cms.string('./caloRecoTauProducer/'),
00431 )
00432 
00433 ##################################################
00434 #
00435 #   The plotting of all the TaNC efficiencies
00436 #
00437 ##################################################
00438 
00439 plotTancValidation = cms.EDAnalyzer("DQMHistPlotter",
00440   standardDrawingStuff,
00441   standardCompareTestAndReference,
00442   drawJobs = Utils.SpawnDrawJobs(RunTancValidation, plotPset),
00443   outputFilePath = cms.string('./shrinkingConePFTauProducerTanc/'),
00444 )
00445 
00446 ##################################################
00447 #
00448 #   The plotting of all the Shrinking cone leading pion efficiencies
00449 #
00450 ##################################################
00451 
00452 plotPFTauHighEfficiencyEfficienciesLeadingPion = cms.EDAnalyzer("DQMHistPlotter",
00453   standardDrawingStuff,
00454   standardCompareTestAndReference,
00455   drawJobs = Utils.SpawnDrawJobs(PFTausHighEfficiencyLeadingPionBothProngs, plotPset),
00456   outputFilePath = cms.string('./shrinkingConePFTauProducerLeadingPion/'),
00457 )
00458 
00459 plotTauValidation = cms.Sequence(
00460       plotPFTauEfficiencies_hps
00461       +plotPFTauEfficiencies_tanc
00462       +plotPFTauHighEfficiencyEfficiencies
00463       +plotCaloTauEfficiencies
00464       +plotTancValidation
00465       +plotPFTauHighEfficiencyEfficienciesLeadingPion
00466       +plotHPSEfficiencies
00467       )
00468 
00469 loadAndPlotTauValidation = cms.Sequence(
00470       loadTau
00471       +plotTauValidation
00472       )
00473 
00474 """
00475 
00476 UTILITIES
00477 
00478 """
00479 
00480 class ApplyFunctionToSequence:
00481    """ Helper class that applies a given function to all modules
00482        in a sequence """
00483    def __init__(self,function):
00484       self.functor = function
00485    def enter(self, module):
00486       self.functor(module)
00487    def leave(self, module):
00488       pass
00489 
00490 def TranslateToLegacyProdNames(input):
00491    input = re.sub('fixedConePFTauProducer', 'pfRecoTauProducer', input)
00492    #fixedDiscriminationRegex = re.compile('fixedConePFTauDiscrimination( \w* )')
00493    fixedDiscriminationRegex = re.compile('fixedConePFTauDiscrimination(\w*)')
00494    input = fixedDiscriminationRegex.sub(r'pfRecoTauDiscrimination\1', input)
00495    input = re.sub('shrinkingConePFTauProducer', 'pfRecoTauProducerHighEfficiency', input)
00496    shrinkingDiscriminationRegex = re.compile('shrinkingConePFTauDiscrimination(\w*)')
00497    input = shrinkingDiscriminationRegex.sub(r'pfRecoTauDiscrimination\1HighEfficiency', input)
00498    return input
00499 
00500 
00501 def ConvertDrawJobToLegacyCompare(input):
00502    """ Converts a draw job defined to compare 31X named PFTau validtion efficiencies
00503        to comapre a 31X to a 22X named Validation """
00504    # get the list of drawjobs { name : copyOfPSet }
00505    if not hasattr(input, "drawJobs"):
00506       return
00507    myDrawJobs = input.drawJobs.parameters_()
00508    for drawJobName, drawJobData in myDrawJobs.iteritems():
00509       print drawJobData
00510       if not drawJobData.plots.pythonTypeName() == "cms.PSet":
00511          continue
00512       pSetToInsert = cms.PSet(
00513             standardEfficiencyParameters,
00514             plots = cms.VPSet(
00515                # test plot w/ modern names
00516                cms.PSet(
00517                   dqmMonitorElements = drawJobData.plots.dqmMonitorElements,
00518                   process = cms.string('test'),
00519                   drawOptionEntry = cms.string('eff_overlay01'),
00520                   legendEntry = cms.string(input.processes.test.legendEntry.value())
00521                   ),
00522                # ref plot w/ vintage name
00523                cms.PSet(
00524                   # translate the name
00525                   dqmMonitorElements = cms.vstring(TranslateToLegacyProdNames(drawJobData.plots.dqmMonitorElements.value()[0])),
00526                   process = cms.string('reference'),
00527                   drawOptionEntry = cms.string('eff_overlay02'),
00528                   legendEntry = cms.string(input.processes.reference.legendEntry.value())
00529                   )
00530                )
00531             )
00532       input.drawJobs.__setattr__(drawJobName, pSetToInsert)
00533 
00534 def MakeLabeler(TestLabel, ReferenceLabel):
00535    def labeler(module):
00536       if hasattr(module, 'processes'):
00537          if module.processes.hasParameter(['test', 'legendEntry']) and module.processes.hasParameter([ 'reference', 'legendEntry']):
00538             module.processes.test.legendEntry = TestLabel
00539             module.processes.reference.legendEntry = ReferenceLabel
00540             print "Set test label to %s and reference label to %s for plot producer %s" % (TestLabel, ReferenceLabel, module.label())
00541          else:
00542             print "ERROR in RecoTauValidation_cfi::MakeLabeler - trying to set test/reference label but %s does not have processes.(test/reference).legendEntry parameters!" % module.label()
00543    return labeler
00544 
00545 def SetYmodulesToLog(matchingNames = []):
00546    ''' set all modules whose name contains one of the matching names to log y scale'''
00547    def yLogger(module):
00548       ''' set a module to use log scaling in the yAxis'''
00549       if hasattr(module, 'drawJobs'):
00550          print "EK DEBUG"
00551          drawJobParamGetter = lambda subName : getattr(module.drawJobs, subName)
00552          #for subModule in [getattr(module.drawJobs, subModuleName) for subModuleName in dir(module.drawJobs)]:
00553          attrNames = dir(module.drawJobs)
00554          for subModuleName, subModule in zip(attrNames, map(drawJobParamGetter, attrNames)):
00555             matchedNames = [name for name in matchingNames if subModuleName.find( name) > -1] # matching sub strings
00556             if len(matchingNames) == 0:
00557                matchedNames = ['take','everything','and','dont','bother']
00558             if hasattr(subModule, "yAxis") and len(matchedNames):
00559                print "Setting drawJob: ", subModuleName, " to log scale."
00560                subModule.yAxis = cms.string('fakeRate') #'fakeRate' configuration specifies the log scaling
00561          if len(matchingNames) == 0: 
00562             module.yAxes.efficiency.maxY_log = 40
00563             module.yAxes.fakeRate.maxY_log = 40
00564    return yLogger
00565 
00566 
00567 def SetBaseDirectory(Directory):
00568    def BaseDirectorizer(module):
00569       newPath = Directory
00570       #if module.hasParameter("outputFilePath"):
00571       if hasattr(module, "outputFilePath"):
00572          oldPath = module.outputFilePath.value()
00573          newPath = os.path.join(newPath, oldPath)
00574          if not os.path.exists(newPath):
00575             os.makedirs(newPath)
00576          print newPath
00577          module.outputFilePath = cms.string("%s" % newPath)
00578    return BaseDirectorizer
00579 
00580 def RemoveComparisonPlotCommands(module):
00581    if hasattr(module, 'drawJobs'):
00582       #get draw job parameter names
00583       drawJobs = module.drawJobs.parameterNames_()
00584       for drawJob in drawJobs:
00585          if drawJob != "TauIdEffStepByStep":
00586             module.drawJobs.__delattr__(drawJob)
00587             print "Removing comparison plot", drawJob
00588 
00589 def SetPlotDirectory(myPlottingSequence, directory):
00590    myFunctor = ApplyFunctionToSequence(SetBaseDirectory(directory))
00591    myPlottingSequence.visit(myFunctor)
00592 
00593 def SetTestAndReferenceLabels(myPlottingSequence, TestLabel, ReferenceLabel):
00594    myFunctor = ApplyFunctionToSequence(MakeLabeler(TestLabel, ReferenceLabel))
00595    myPlottingSequence.visit(myFunctor)
00596 
00597 def SetCompareToLegacyProductNames(myPlottingSequence):
00598    myFunctor = ApplyFunctionToSequence(ConvertDrawJobToLegacyCompare)
00599    myPlottingSequence.visit(myFunctor)
00600 
00601 def SetTestFileToPlot(myProcess, FileLoc):
00602    myProcess.loadTau.test.inputFileNames = cms.vstring(FileLoc)
00603 
00604 def SetReferenceFileToPlot(myProcess, FileLoc):
00605    if FileLoc == None:
00606       del myProcess.loadTau.reference
00607    else:
00608       myProcess.loadTau.reference.inputFileNames = cms.vstring(FileLoc)
00609 
00610 def SetLogScale(myPlottingSequence):
00611    myFunctor = ApplyFunctionToSequence(SetYmodulesToLog())
00612    myPlottingSequence.visit(myFunctor)
00613 
00614 def SetSmartLogScale(myPlottingSequence):
00615    myFunctor = ApplyFunctionToSequence(SetYmodulesToLog(['Electron', 'Muon', 'Isolation', 'TaNC']))
00616    myPlottingSequence.visit(myFunctor)
00617 
00618 def SetPlotOnlyStepByStep(myPlottingSequence):
00619    myFunctor = ApplyFunctionToSequence(RemoveComparisonPlotCommands)
00620    myPlottingSequence.visit(myFunctor)