Example #1
0
def getjmecalib(era, period="", redoJEC=False, doSys=False, dtype='data'):
    """Get JME calibrator for dataset of a given year and era."""
    # https://twiki.cern.ch/twiki/bin/view/CMS/JECDataMC
    # https://twiki.cern.ch/twiki/bin/view/CMS/JetResolution
    # https://github.com/cms-jet/JECDatabase/raw/master/tarballs/
    # https://github.com/cms-jet/JRDatabase/tree/master/textFiles/
    # https://github.com/cms-nanoAOD/nanoAOD-tools/tree/master/data/jme
    # https://github.com/cms-nanoAOD/nanoAOD-tools/blob/master/python/postprocessing/modules/jme/jetRecalib.py
    # https://github.com/cms-nanoAOD/nanoAOD-tools/blob/master/python/postprocessing/modules/jme/jetmetUncertainties.py
    #from PhysicsTools.NanoAODTools.postprocessing.modules.jme import jetmetUncertainties
    #from PhysicsTools.NanoAODTools.postprocessing.modules.jme.jetmetUncertainties import jetmetUncertaintiesProducer
    #from PhysicsTools.NanoAODTools.postprocessing.modules.jme import jetRecalib
    from PhysicsTools.NanoAODTools.postprocessing.modules.jme.jetmetHelperRun2 import createJMECorrector
    year = getyear(era)  # get year as integer
    if dtype == 'data':
        #calibrators = { }
        #if year==2016:
        #  calibrators = {
        #    'BCD': jetRecalib.jetRecalib2016BCD,
        #    'EF':  jetRecalib.jetRecalib2016EF,
        #    'GH':  jetRecalib.jetRecalib2016GH,
        #  }
        #elif year==2017:
        #  calibrators = {
        #    'B':  jetRecalib.jetRecalib2017B,
        #    'C':  jetRecalib.jetRecalib2017C,
        #    'DE': jetRecalib.jetRecalib2017DE,
        #    'F':  jetRecalib.jetRecalib2017F,
        #  }
        #else:
        #  calibrators = {
        #    'A': jetRecalib.jetRecalib2018A,
        #    'B': jetRecalib.jetRecalib2018B,
        #    'C': jetRecalib.jetRecalib2018C,
        #    'D': jetRecalib.jetRecalib2018D,
        #  }
        #for eraset in calibrators:
        #  if period in eraset:
        #    return calibrators[eraset]()
        #raise "Could not find an appropiate calibrator for year %s and era %s..."%(year,period)
        return createJMECorrector(False,
                                  era,
                                  runPeriod=period,
                                  jesUncert=jmeUncs,
                                  redojec=redoJEC,
                                  jetType='AK4PFchs',
                                  noGroom=True,
                                  metBranchName=MET,
                                  applySmearing=False)()
    else:
        jmeUncs = 'Total' if doSys else ''
        MET = 'METFixEE2017' if (year == 2017 and 'UL' not in era) else 'MET'
        return createJMECorrector(True,
                                  era,
                                  jesUncert=jmeUncs,
                                  redojec=redoJEC,
                                  jetType='AK4PFchs',
                                  noGroom=True,
                                  metBranchName=MET,
                                  applySmearing=True)()
Example #2
0
    def __call__(self, cut):
        newFileList = []
        logger.info("Starting nanoAOD postprocessing")
        for f in self.files:
            # need a hash to avoid data loss
            file_hash = str(hash(f))

            self.modules = []

            JMECorrector = createJMECorrector(isMC=(not self.isData),
                                              dataYear=self.year,
                                              runPeriod=self.era,
                                              jesUncert=",".join(self.jesTags),
                                              jetType="AK4PFchs",
                                              metBranchName=self.METCollection,
                                              applySmearing=False)
            #            JMECorrector = createJMECorrector( isMC=(not self.isData), dataYear=self.year, runPeriod=self.era, jesUncert="Total", jetType = "AK4PFchs", metBranchName=self.METCollection, applySmearing=False )
            self.modules.append(JMECorrector())
            #            if not self.isData:
            #                if self.year == 2016:
            #                    self.modules.append(ElectronScaleSmear.elecUnc2016MC())
            #                    self.modules.append(PhotonScaleSmear.phoUnc2016MC())
            #                elif self.year == 2017:
            #                    self.modules.append(ElectronScaleSmear.elecUnc2017MC())
            #                    self.modules.append(PhotonScaleSmear.phoUnc2017MC())
            #                elif self.year == 2018:
            #                    self.modules.append(ElectronScaleSmear.elecUnc2018MC())
            #                    self.modules.append(PhotonScaleSmear.phoUnc2018MC())

            p = PostProcessor(self.output_directory, [f],
                              cut=cut,
                              modules=self.modules,
                              postfix="%s_%s" % (self.postfix, file_hash))
            p.run()
            newFileList += [
                self.output_directory + '/' + f.split('/')[-1].replace(
                    '.root', '%s_%s.root' % (self.postfix, file_hash))
            ]
        logger.info("Done. Replacing input files for further processing.")
        self.outfiles = newFileList
Example #3
0
    },
    '2018': {
        'metBranchName': 'MET',
        'heepBranchName': 'cutBased_HEEPV7p0_2018Prompt',
        'applyHEMfix': True
    }
}

#set up process for mc and data
if isMC:
    jmeCorrections = createJMECorrector(
        isMC=isMC,
        dataYear=dataYear,
        runPeriod=runPeriod,
        jesUncert="Total",
        metBranchName=conditions_dict[dataYear]['metBranchName'],
        applySmearing=True,
        jetType="AK4PFchs",
        noGroom=False,
        applyHEMfix=conditions_dict[dataYear]['applyHEMfix'],
    )
    #don't use all modules for bff efficency calculation
    if 'eff' not in selector:
        modules = [
            countHistogramsProducer(),
            triggerFilter(triggers),
            btagSF(dataYear, algo=btag_type),
            jmeCorrections(),
            puWeight(),
            muonScaleRes(),
            lepSF(),
Example #4
0
parser.add_argument('-m', dest='mode', default='local', help='runmode local/condor')
parser.add_argument('-d', dest='isdata',action='store_true',default=False)
parser.add_argument('-e', dest='era',default='B')
args = parser.parse_args()

print "mode: ", args.mode
print "year: ", args.year
print "dataset_name: ", args.infile
print "data_era", args.era

from PhysicsTools.NanoAODTools.postprocessing.modules.btv.btagSFProducer import *
from PhysicsTools.NanoAODTools.postprocessing.modules.common.PrefireCorr import *

if args.year=='2016':
   PrefCorr_2016 = lambda: PrefCorr("L1prefiring_jetpt_2016BtoH.root","L1prefiring_jetpt_2016BtoH","L1prefiring_photonpt_2016BtoH.root","L1prefiring_photonpt_2016BtoH")
   jmeCorrections_ak4_MC = createJMECorrector(True,2016,"B","Total","AK4PFchs",False,"PuppiMET",True,False,True,True)
   jmeCorrections_ak4_Data = createJMECorrector(False,2016,args.era,"Total","AK4PFchs",False,"PuppiMET",True,False,True,True)
   btagSF = lambda: btagSFProducer("2016",'deepcsv')

if args.year=='2017':
   PrefCorr_2017 = lambda: PrefCorr("L1prefiring_jetpt_2017BtoF.root","L1prefiring_jetpt_2017BtoF","L1prefiring_photonpt_2017BtoF.root","L1prefiring_photonpt_2017BtoF")
   jmeCorrections_ak4_MC = createJMECorrector(True,2017,"B","Total","AK4PFchs",False,"PuppiMET",True,False,True,True)
   jmeCorrections_ak4_Data = createJMECorrector(False,2017,args.era,"Total","AK4PFchs",False,"PuppiMET",True,False,True,True)
   btagSF = lambda: btagSFProducer("2017",'deepcsv')

if args.year=='2018':
   jmeCorrections_ak4_MC = createJMECorrector(True,2018,"A","Total","AK4PFchs",False,"PuppiMET",True,False,True,True)
   jmeCorrections_ak4_Data = createJMECorrector(False,2018,args.era,"Total","AK4PFchs",False,"PuppiMET",True,False,True,True)
   btagSF = lambda: btagSFProducer("2018",'deepcsv')

# classify input files
Example #5
0
from tthAnalysis.NanoAODTools.postprocessing.modules.diHiggsVarProducer import diHiggsVar_2016, diHiggsVar_2017, diHiggsVar_2018
from tthAnalysis.NanoAODTools.postprocessing.modules.mllVarProducer import mllWZTo3LNu, mllWZTo3LNu_mllmin01
from tthAnalysis.NanoAODTools.postprocessing.modules.btagSFProducer_explicitBranchNames import *
from tthAnalysis.NanoAODTools.postprocessing.modules.eventCountHistogramProducer import eventCountHistogram
from tthAnalysis.NanoAODTools.postprocessing.modules.countHistogramProducer import *
from tthAnalysis.NanoAODTools.postprocessing.modules.subjetBtagCounter import *
from tthAnalysis.NanoAODTools.postprocessing.modules.binnedEventCountProducer import binnedEventCounter
from tthAnalysis.NanoAODTools.postprocessing.modules.trigObjMatcherProducer import trigObjMatcher
from tthAnalysis.NanoAODTools.postprocessing.modules.puHistogramProducer import puHist2016, puHist2017, puHist2018
from tthAnalysis.NanoAODTools.postprocessing.modules.egammaIdProducer import egammaId
from tthAnalysis.NanoAODTools.postprocessing.modules.btagSFRatioFinder import *
from tthAnalysis.NanoAODTools.postprocessing.modules.rleProducer import rle
from PhysicsTools.NanoAODTools.postprocessing.modules.common.puWeightProducer import puWeight2016, puWeight2017, puWeight2018
from PhysicsTools.NanoAODTools.postprocessing.modules.jme.jetmetHelperRun2 import createJMECorrector

jetmetUncertainties2016Merged = createJMECorrector(dataYear=2016,
                                                   jesUncert="Merged")
jetmetUncertainties2017Merged = createJMECorrector(dataYear=2017,
                                                   jesUncert="Merged",
                                                   metBranchName="MET")
jetmetUncertainties2018Merged = createJMECorrector(dataYear=2018,
                                                   jesUncert="Merged",
                                                   applyHEMfix=True)

fatjetUncertainties2016Total = createJMECorrector(dataYear=2016,
                                                  jesUncert="Total",
                                                  jetType="AK8PFPuppi",
                                                  splitJER=False)
fatjetUncertainties2017Total = createJMECorrector(dataYear=2017,
                                                  jesUncert="Total",
                                                  jetType="AK8PFPuppi",
                                                  splitJER=False)
Example #6
0
                                       linkColl='GenPart',
                                       linkVar='genPartIdx')
mcMatchId = lambda: ObjTagger('mcMatchId', 'LepGood', [
    lambda l: (l.genPartFlav == 1 or l.genPartFlav == 15)
])
mcPromptGamma = lambda: ObjTagger('mcPromptGamma', 'LepGood',
                                  [lambda l: (l.genPartFlav == 22)])
mcMatch_seq = [isMatchRightCharge, mcMatchId, mcPromptGamma]

countTaus = lambda: ObjTagger('Tight', 'TauSel_Recl',
                              [lambda t: t.idDeepTau2017v2p1VSjet & 4])

from CMGTools.TTHAnalysis.tools.nanoAOD.jetmetGrouper import jetMetCorrelate2016, jetMetCorrelate2017, jetMetCorrelate2018
from PhysicsTools.NanoAODTools.postprocessing.modules.jme.jetmetHelperRun2 import createJMECorrector

jetmetUncertainties2016All = createJMECorrector(dataYear=2016, jesUncert="All")
jetmetUncertainties2017All = createJMECorrector(dataYear=2017,
                                                jesUncert="All",
                                                metBranchName="METFixEE2017")
jetmetUncertainties2018All = createJMECorrector(dataYear=2016, jesUncert="All")

jme2016_allvariations = [jetmetUncertainties2016All, jetMetCorrelate2016]
jme2017_allvariations = [jetmetUncertainties2017All, jetMetCorrelate2017]
jme2018_allvariations = [jetmetUncertainties2018All, jetMetCorrelate2018]


def _fires(ev, path):
    if "/hasfiredtriggers_cc.so" not in ROOT.gSystem.GetLibraries():
        ROOT.gROOT.ProcessLine(
            ".L %s/src/CMGTools/Production/src/hasfiredtriggers.cc+O" %
            os.environ['CMSSW_BASE'])
Example #7
0
else:
    dataset = Dataset.kNone

if args.year == 2016:
    year = Year.k2016
elif args.year == 2017:
    year = Year.k2017
elif args.year == 2018:
    year = Year.k2018
else:
    print "ERROR : --year is mandatory."
    sys.exit(1)

if data_source == Source.kMC:
     jme_corrector = createJMECorrector(isMC=True,
                                          dataYear=args.year,
                                          applyHEMfix=(args.year==2018))  

if data_source == Source.kDATA:
    modules_list = [DijetSkimmer(year=year, source=data_source, dataset=dataset, hist_file="./hists_{}.root".format(args.jobID))]
else:
    modules_list = [jme_corrector(), DijetSkimmer(year=year, source=data_source, dataset=dataset, hist_file="./hists_{}.root".format(args.jobID))]

print "Printing modules_list:"
print modules_list

if args.jobID == -1:
    # Local test
    skimmer = PostProcessor(outputDir=".",
        #inputFiles=["root://cmsxrootd.fnal.gov//store/data/Run2017C/JetHT/NANOAOD/Nano14Dec2018-v1/80000/25DF8860-C198-2947-8BCB-60A43CCA34EF.root"],
        inputFiles=["root://xrootd-cms.infn.it//store/data/Run2017C/JetHT/NANOAOD/Nano14Dec2018-v1/80000/25DF8860-C198-2947-8BCB-60A43CCA34EF.root"],
Example #8
0
print "mode: ", args.mode
print "year: ", args.year
print "dataset_name: ", args.infile
print "data_era", args.era

from PhysicsTools.NanoAODTools.postprocessing.modules.btv.btagSFProducer import *
from PhysicsTools.NanoAODTools.postprocessing.modules.common.PrefireCorr import *

if args.year == '2016':
    jmeCorrections_ak4_MC = createJMECorrector(isMC=True,
                                               dataYear=2016,
                                               runPeriod="B",
                                               jesUncert="Total",
                                               jetType="AK4PFchs",
                                               noGroom=False,
                                               metBranchName="MET",
                                               applySmearing=True,
                                               isFastSim=False,
                                               applyHEMfix=False,
                                               splitJER=True)
    jmeCorrections_ak4_Data = createJMECorrector(isMC=False,
                                                 dataYear=2016,
                                                 runPeriod=args.era,
                                                 jesUncert="Total",
                                                 jetType="AK4PFchs",
                                                 noGroom=False,
                                                 metBranchName="MET",
                                                 applySmearing=True,
                                                 isFastSim=False,
                                                 applyHEMfix=False,
Example #9
0
parser.add_argument('-n',
                    dest='name',
                    default='test',
                    help='dataset name in short, currently support'
                    '\n tZq_ll'
                    '\n WZ'
                    '\n TTWJetsToLNu'
                    '\n ttZJets')
args = parser.parse_args()

print "mode: ", args.mode
print "year: ", args.year
print "dataset_name: ", args.name

jmeCorrections_ak4_2016 = createJMECorrector(True, 2016, "A", "Total",
                                             "AK4PFchs", False, "MET", True,
                                             False, False, False)
jmeCorrections_ak4_2017 = createJMECorrector(True, 2017, "A", "Total",
                                             "AK4PFchs", False, "METFixEE2017",
                                             True, False, False, False)
jmeCorrections_ak4_2018 = createJMECorrector(True, 2018, "A", "Total",
                                             "AK4PFchs", False, "MET", True,
                                             False, True, False)
jmeCorrections_ak8_2016 = createJMECorrector(True, 2016, "A", "Total",
                                             "AK8PFPuppi", False, "MET", True,
                                             False, False, False)
jmeCorrections_ak8_2017 = createJMECorrector(True, 2017, "A", "Total",
                                             "AK8PFPuppi", False,
                                             "METFixEE2017", True, False,
                                             False, False)
jmeCorrections_ak8_2018 = createJMECorrector(True, 2018, "A", "Total",