def printPpassMetCut(self): if hasattr(self, "TagPt35"): total = self.TagPt35["yield"] passes = 0.0 sample = self.TagPt35["sample"] condorDir = self.TagPt35["condorDir"] name = self.TagPt35["name"] #met = self.getHistFromProjectionZ (sample, condorDir, name + "Plotter", self._metMinusOneHist, alternate1DHist = self._Flavor + " Plots/" + self._flavor + "MetNoMuMinusOnePt") met = getHist( sample, condorDir, name + "Plotter" + "/" + self._Flavor + "-eventvariable Plots", "deltaPhiMetJetLeadingVs" + self._Flavor + "MetNoMuMinusOnePt") passesError = Double(0.0) passes = met.IntegralAndError(met.GetXaxis().FindBin(self._metCut), met.GetNbinsX() + 1, met.GetYaxis().FindBin(self._phiCut), met.GetNbinsY() + 1, passesError) passes = Measurement(passes, passesError) passes.isPositive() eff = passes / total print "P (pass met cut): " + str(eff) return eff else: print "TagPt35 not defined. Not printing P (pass met cut)..." return float("nan")
def printPpassMetCut (self): if hasattr (self, "TagPt35"): total = self.TagPt35["yield"] passes = 0.0 if hasattr (self, "TagPt35MetCut"): passes = self.TagPt35MetCut["yield"] else: sample = self.TagPt35["sample"] condorDir = self.TagPt35["condorDir"] name = self.TagPt35["name"] #met = self.getHistFromProjectionZ (sample, condorDir, name + "Plotter", self._metMinusOneHist, alternate1DHist = self._Flavor + " Plots/" + self._flavor + "MetNoMuMinusOnePt") met = getHist (sample, condorDir, name + "Plotter" + "/" + self._Flavor + "-eventvariable Plots", "deltaPhiMetJetLeadingVs" + self._Flavor + "MetNoMuMinusOnePt") passesError = Double (0.0) passes = met.IntegralAndError (met.GetXaxis ().FindBin (self._metCut), met.GetNbinsX () + 1, met.GetYaxis ().FindBin (self._phiCut), met.GetNbinsY () + 1, passesError) passes = Measurement (passes, passesError) passes.isPositive () eff = passes / total print "P (pass met cut): " + str (eff) return eff else: print "TagPt35 not defined. Not printing P (pass met cut)..." return float ("nan")
def addChannel(self, role, name, sample, condorDir, useIdMatch=False): channel = {"name": name, "sample": sample, "condorDir": condorDir} n = None nError = None n, nError = getYieldInBin(sample, condorDir, name + "CutFlowPlotter", 1) w = (nError * nError) / n n /= w nError /= w channel["weight"] = w channel["total"] = Measurement(n * w, (nError if n != 0.0 else up68) * w) channel["total"].isPositive() if useIdMatch: pdgLo, pdgHi = self.getPdgRange() # NOTE: below is wrong since the fiducial map cuts haven't been applied. # need to add 3d plot of bestMatchPdgId vs these maxSigmas n, nError = getHistIntegral(sample, condorDir, name + "Plotter", "Track Plots/bestMatchPdgId", pdgLo, pdgHi) else: n, nError = self.getHistIntegralFromProjectionZ( sample, condorDir, name + "Plotter") n /= w nError /= w channel["yield"] = Measurement(n * w, (nError if n != 0.0 else up68) * w) channel["yield"].isPositive() setattr(self, role, channel) print "yield for " + name + ": " + str(channel["yield"])
def printPpassVetoTagProbe (self): self.plotPpassVeto () if not hasattr (self._pPassVeto, "centralValue"): if hasattr (self, "TagProbe") and hasattr (self, "TagProbePass"): total = None passes = None if not self._useHistogramsForPpassVeto: total = self.TagProbe["yield"] passes = self.TagProbePass["yield"] else: hist = "Eventvariable Plots/nGoodTPPairs" sample = self.TagProbe["sample"] condorDir = self.TagProbe["condorDir"] name = self.TagProbe["name"] totalHist = getHist (sample, condorDir, name + "Plotter", hist) hist = "Eventvariable Plots/nProbesPassingVeto" sample = self.TagProbePass["sample"] condorDir = self.TagProbePass["condorDir"] name = self.TagProbePass["name"] passesHist = getHist (sample, condorDir, name + "Plotter", hist) totalError1 = Double (0.0) passesError1 = Double (0.0) totalError2 = Double (0.0) passesError2 = Double (0.0) total = totalHist.IntegralAndError (2, 2, totalError1) + 2.0 * totalHist.IntegralAndError (3, 3, totalError2) passes = passesHist.IntegralAndError (2, 2, passesError1) + 2.0 * passesHist.IntegralAndError (3, 3, passesError2) total = Measurement (total, math.hypot (totalError1, 2.0 * totalError2)) passes = Measurement (passes, math.hypot (passesError1, 2.0 * passesError2)) passes1 = 0.0 if hasattr (self, "TagProbe1") and hasattr (self, "TagProbePass1"): total += self.TagProbe1["yield"] passes1 = self.TagProbePass1["yield"] scaledPasses = passes * self._tagProbePassScaleFactor + passes1 * self._tagProbePass1ScaleFactor p = passes sf = Measurement (self._tagProbePassScaleFactor, 0.0) if scaledPasses > 0.0: p = (scaledPasses * scaledPasses) / (passes * self._tagProbePassScaleFactor * self._tagProbePassScaleFactor + passes1 * self._tagProbePass1ScaleFactor * self._tagProbePass1ScaleFactor) sf = (passes * self._tagProbePassScaleFactor * self._tagProbePassScaleFactor + passes1 * self._tagProbePass1ScaleFactor * self._tagProbePass1ScaleFactor) / scaledPasses p.setUncertainty (math.sqrt (p.centralValue ())) sf.setUncertainty (0.0) if (self._flavor == "electron" or self._flavor == "muon") and not self._useHistogramsForPpassVeto: eff = scaledPasses / (2.0 * total - scaledPasses) else: eff = scaledPasses / total print "P (pass lepton veto) in tag-probe sample: " + str (eff) return (eff, p, sf, total) else: print "TagProbe and TagProbePass not both defined. Not printing lepton veto efficiency..." return (float ("nan"), float ("nan"), float ("nan"), float ("nan")) else: print "P (pass lepton veto) from user input: " + str (self._pPassVeto) return (self._pPassVeto, float ("nan"), float ("nan"), float ("nan"))
def printTransferFactor(self): if hasattr(self, "Basic3hits"): passes, passesError = getHistIntegral( self.Basic3hits["sample"], self.Basic3hits["condorDir"], self.Basic3hits["name"] + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", 0.0, 0.02 - 0.001) fails, failsError = getHistIntegral( self.Basic3hits["sample"], self.Basic3hits["condorDir"], self.Basic3hits["name"] + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", self._minD0, self._maxD0 - 0.001) passes = Measurement(passes, passesError) fails = Measurement(fails, failsError) passes.isPositive() fails.isPositive() if fails > 0.0: transferFactor = passes / fails print "Transfer factor: (" + str(passes) + ") / (" + str( fails) + ") = " + str(transferFactor) return (transferFactor, passes, fails) else: print "N(fail d0 cut, 3 hits) = 0, not printing scale factor..." return (float("nan"), float("nan"), float("nan")) else: print "Basic3hits is not defined. Not printing transfer factor..." return (float("nan"), float("nan"), float("nan"))
def getNMissOutEfficiency(self, dataOrMC, nLow, nHigh=-1, hits=None, sample=None): if hasattr(self, dataOrMC): if not hits: channel = getattr(self, dataOrMC) if dataOrMC != "Signal": sample = channel["sample"] condorDir = channel["condorDir"] name = channel["name"] hits = getHist(sample, condorDir, name + "Plotter", self._integrateHistogram) if nHigh < 0: nHigh = nLow passesError = Double(0.0) totalError = Double(0.0) passes = hits.IntegralAndError(hits.FindBin(nLow), hits.FindBin(nHigh), totalError) total = hits.IntegralAndError(0, hits.GetNbinsX() + 1, totalError) eff, effErrorLow, effErrorHigh = getEfficiency( passes, passesError, total, totalError) eff = Measurement(eff, effErrorLow, effErrorHigh) return (eff, hits) else: print dataOrMC + " not defined. Not printing missing outer hits systematic..." return (float("nan"), float("nan"))
def addChannel(self, role, name, sample, condorDir): channel = {"name": name, "sample": sample, "condorDir": condorDir} n, nError = getHistIntegral( sample, condorDir, name + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", 0.0, self._maxD0 - 0.001) channel["yield"] = Measurement(n, nError) channel["yield"].isPositive() setattr(self, role, channel) print "yield for " + name + ": " + str(channel["yield"])
def printPpassMetTriggers (self): if hasattr (self, "TagPt35") and (hasattr (self, "TagPt35MetTrig") or (hasattr (self, "TrigEffDenom") and hasattr (self, "TrigEffNumer"))): sample = self.TrigEffDenom["sample"] if hasattr (self, "TrigEffDenom") else self.TagPt35["sample"] condorDir = self.TrigEffDenom["condorDir"] if hasattr (self, "TrigEffDenom") else self.TagPt35["condorDir"] name = self.TrigEffDenom["name"] if hasattr (self, "TrigEffDenom") else self.TagPt35["name"] hist = "Track-met Plots/metNoMuMinusOnePtVsMaxSigmaForFiducialTracksX" totalHist = self.getHistFromProjectionZ (sample, condorDir, name + "Plotter", hist, alternate1DHist = "Met Plots/metNoMu") sample = self.TrigEffNumer["sample"] if hasattr (self, "TrigEffNumer") else self.TagPt35MetTrig["sample"] condorDir = self.TrigEffNumer["condorDir"] if hasattr (self, "TrigEffNumer") else self.TagPt35MetTrig["condorDir"] name = self.TrigEffNumer["name"] if hasattr (self, "TrigEffNumer") else self.TagPt35MetTrig["name"] hist = "Track-met Plots/metNoMuMinusOnePtVsMaxSigmaForFiducialTracksX" passesHist = self.getHistFromProjectionZ (sample, condorDir, name + "Plotter", hist, alternate1DHist = "Met Plots/metNoMu") self.plotTriggerEfficiency (passesHist, totalHist) sample = self.TagPt35["sample"] condorDir = self.TagPt35["condorDir"] name = self.TagPt35["name"] #metHist = self.getHistFromProjectionZ (sample, condorDir, name + "Plotter", self._metMinusOneHist, alternate1DHist = self._Flavor + " Plots/" + self._flavor + "MetNoMuMinusOnePt") metHist2D = getHist (sample, condorDir, name + "Plotter" + "/" + self._Flavor + "-eventvariable Plots", "deltaPhiMetJetLeadingVs" + self._Flavor + "MetNoMuMinusOnePt") metHist2D.GetYaxis ().SetRangeUser (self._phiCut, 4.0) metHist = metHist2D.ProjectionX ("metHist") passesHist.Divide (totalHist) metHist.Multiply (passesHist) total = 0.0 totalError = Double (0.0) passesError = Double (0.0) passes = metHist.IntegralAndError (metHist.FindBin (self._metCut), metHist.GetNbinsX () + 1, passesError) passes = Measurement (passes, passesError) passes.isPositive () if hasattr (self, "TagPt35MetCut"): total = self.TagPt35MetCut["yield"] else: sample = self.TagPt35["sample"] condorDir = self.TagPt35["condorDir"] name = self.TagPt35["name"] #met = self.getHistFromProjectionZ (sample, condorDir, name + "Plotter", self._metMinusOneHist, alternate1DHist = self._Flavor + " Plots/" + self._flavor + "MetNoMuMinusOnePt") met = getHist (sample, condorDir, name + "Plotter" + "/" + self._Flavor + "-eventvariable Plots", "deltaPhiMetJetLeadingVs" + self._Flavor + "MetNoMuMinusOnePt") totalError = Double (0.0) total = met.IntegralAndError (met.GetXaxis ().FindBin (self._metCut), met.GetNbinsX () + 1, met.GetYaxis ().FindBin (self._phiCut), met.GetNbinsY () + 1, totalError) total = Measurement (total, totalError) total.isPositive () eff = passes / total print "P (pass met triggers): " + str (eff) return (eff, passesHist) else: print "TagPt35 and TagPt35MetTrig not both defined. Not printing P (pass met triggers)..." return (float ("nan"), float ("nan"))
def getSignalYield(self, mass, lifetime, nLow, nHigh=-1, hits=None): if hasattr(self, "Signal"): if not hits: channel = getattr(self, "Signal") sample = "AMSB_chargino_" + str(mass) + "GeV_" + str( lifetime) + "cm" + self._signalSuffix condorDir = channel["condorDir"] name = channel["name"] hits = getHist(sample, condorDir, name + "Plotter", self._integrateHistogram) if nHigh < 0: nHigh = nLow nError = Double(0.0) n = hits.IntegralAndError(hits.FindBin(nLow), hits.FindBin(nHigh), nError) n = Measurement(n, nError) return (n, hits) else: print "\"Signal\" not defined. Not printing missing outer hits systematic..." return (float("nan"), float("nan"))
def printNback(self): self.plotMetForNback() if hasattr(self, "CandTrkIdPt35"): sample = self.CandTrkIdPt35["sample"] condorDir = self.CandTrkIdPt35["condorDir"] name = self.CandTrkIdPt35["name"] hist = "Track Plots/trackCaloTot_RhoCorr" eCalo = getHist(sample, condorDir, name + "Plotter", hist) nError = Double(0.0) n = eCalo.IntegralAndError(0, eCalo.FindBin(self._eCaloCut), nError) w = self.CandTrkIdPt35["weight"] n /= w nError /= w n = Measurement(n * w, (nError if n != 0.0 else up68) * w) print "N_back: " + str(n) + " (" + str( n / self._luminosityInInvFb) + " fb)" return n else: print "CandTrkIdPt35 not defined. Not printing N_back..." return float("nan")
def printTransferFactor (self): if hasattr (self, "Basic3hits"): passes, passesError = getHistIntegral (self.Basic3hits["sample"], self.Basic3hits["condorDir"], self.Basic3hits["name"] + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", 0.0, 0.02 - 0.001) fails, failsError = getHistIntegral (self.Basic3hits["sample"], self.Basic3hits["condorDir"], self.Basic3hits["name"] + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", self._minD0, self._maxD0 - 0.001) passes = Measurement (passes, passesError) fails = Measurement (fails, failsError) passes.isPositive () fails.isPositive () if fails > 0.0: transferFactor = passes / fails print "Transfer factor: (" + str (passes) + ") / (" + str (fails) + ") = " + str (transferFactor) return (transferFactor, passes, fails) else: print "N(fail d0 cut, 3 hits) = 0, not printing scale factor..." return (float ("nan"), float ("nan"), float ("nan")) else: print "Basic3hits is not defined. Not printing transfer factor..." return (float ("nan"), float ("nan"), float ("nan"))
def printNctrl (self): if hasattr (self, "DisTrkInvertD0"): n, nError = getHistIntegral (self.DisTrkInvertD0["sample"], self.DisTrkInvertD0["condorDir"], self.DisTrkInvertD0["name"] + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", self._minD0, self._maxD0 - 0.001) n = Measurement (n, (nError if n != 0.0 else 0.5 * TMath.ChisquareQuantile (0.68, 2 * (n + 1)))) n.isPositive () if self._minHits < 7: n6, n6Error = getHistIntegral (self.DisTrkInvertD0NHits6["sample"], self.DisTrkInvertD0NHits6["condorDir"], self.DisTrkInvertD0NHits6["name"] + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", self._minD0, self._maxD0 - 0.001) n6 = Measurement (n6, (n6Error if n6 != 0.0 else 0.5 * TMath.ChisquareQuantile (0.68, 2 * (n6 + 1)))) n6.isPositive () n += n6 if self._minHits < 6: n5, n5Error = getHistIntegral (self.DisTrkInvertD0NHits5["sample"], self.DisTrkInvertD0NHits5["condorDir"], self.DisTrkInvertD0NHits5["name"] + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", self._minD0, self._maxD0 - 0.001) n5 = Measurement (n5, (n5Error if n5 != 0.0 else 0.5 * TMath.ChisquareQuantile (0.68, 2 * (n5 + 1)))) n5.isPositive () n += n5 if self._minHits < 5: n4, n4Error = getHistIntegral (self.DisTrkInvertD0NHits4["sample"], self.DisTrkInvertD0NHits4["condorDir"], self.DisTrkInvertD0NHits4["name"] + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", self._minD0, self._maxD0 - 0.001) n4 = Measurement (n4, (n4Error if n4 != 0.0 else 0.5 * TMath.ChisquareQuantile (0.68, 2 * (n4 + 1)))) n4.isPositive () n += n4 if self._minHits < 4: n3, n3Error = getHistIntegral (self.DisTrkInvertD0NHits3["sample"], self.DisTrkInvertD0NHits3["condorDir"], self.DisTrkInvertD0NHits3["name"] + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", self._minD0, self._maxD0 - 0.001) n3 = Measurement (n3, (n3Error if n3 != 0.0 else 0.5 * TMath.ChisquareQuantile (0.68, 2 * (n3 + 1)))) n3.isPositive () n += n3 pFake = float ("nan") norm = 1.0 # For ZtoMuMu control regions, need to normalize to BasicSelection if hasattr (self, "ZtoLL") and hasattr (self, "Basic"): norm = self.Basic["yield"] / self.ZtoLL["yield"] pFake = n / self.ZtoLL["yield"] elif hasattr (self, "Basic"): pFake = n / self.Basic["yield"] nRaw = n n *= norm n *= self._prescale print "N_ctrl: " + str (n) + " (" + str (n / self._luminosityInInvFb) + " fb)" print "P_fake^raw: " + str (pFake) return (n, nRaw, norm, pFake) else: print "DisTrkInvertD0 is not defined. Not printing N_ctrl..." return (float ("nan"), float ("nan"))
'error' : str ( 0.457123 * 1.0e-3 ), }, '800' : { 'value' : str ( 2.21197 * 1.0e-3 ), 'error' : str ( 0.245196 * 1.0e-3 ), }, '900' : { 'value' : str ( 1.15301 * 1.0e-3 ), 'error' : str ( 0.135822 * 1.0e-3 ), }, } signal_cross_sections = {} for mass in chargino_neutralino_cross_sections: cnX = chargino_neutralino_cross_sections[mass] ccX = chargino_chargino_cross_sections[mass] cn = Measurement (cnX['value'], cnX['error']) cc = Measurement (ccX['value'], ccX['error']) total = cn + cc # convert errors from absolute to relative chargino_neutralino_cross_sections[mass]['error'] = str (1.0 + (cn.uncertainty () / cn.centralValue ())) chargino_chargino_cross_sections[mass]['error'] = str (1.0 + (cc.uncertainty () / cc.centralValue ())) signal_cross_sections[mass] = { 'value' : str (total.centralValue ()), 'error' : str (1.0 + (total.uncertainty () / total.centralValue ())), }
'value': str(0.621866 * 1.0e-3), 'error': str(0.0771005 * 1.0e-3), }, '1100': { 'value': str(0.342626 * 1.0e-3), 'error': str(0.0427672 * 1.0e-3), }, } signal_cross_sections = {} for mass in chargino_neutralino_cross_sections: cnX = chargino_neutralino_cross_sections[mass] ccX = chargino_chargino_cross_sections[mass] cn = Measurement(cnX['value'], cnX['error']) cc = Measurement(ccX['value'], ccX['error']) total = cn + cc # convert errors from absolute to relative chargino_neutralino_cross_sections[mass]['error'] = str( 1.0 + (cn.uncertainty() / cn.centralValue())) chargino_chargino_cross_sections[mass]['error'] = str(1.0 + (cc.uncertainty() / cc.centralValue())) signal_cross_sections[mass] = { 'value': str(total.centralValue()), 'error': str(1.0 + (total.uncertainty() / total.centralValue())), }
'error' : str ( 0.135822 * 1.0e-3 ), }, '1000' : { 'value' : str ( 0.621866 * 1.0e-3 ), 'error' : str ( 0.0771005 * 1.0e-3 ), }, '1100' : { 'value' : str ( 0.342626 * 1.0e-3 ), 'error' : str ( 0.0427672 * 1.0e-3 ), }, } signal_cross_sections = {} for mass in chargino_neutralino_cross_sections: cnX = chargino_neutralino_cross_sections[mass] ccX = chargino_chargino_cross_sections[mass] cn = Measurement (cnX['value'], cnX['error']) cc = Measurement (ccX['value'], ccX['error']) total = cn + cc # convert errors from absolute to relative chargino_neutralino_cross_sections[mass]['error'] = str (1.0 + (cn.uncertainty () / cn.centralValue ())) chargino_chargino_cross_sections[mass]['error'] = str (1.0 + (cc.uncertainty () / cc.centralValue ())) signal_cross_sections[mass] = { 'value' : str (total.centralValue ()), 'error' : str (1.0 + (total.uncertainty () / total.centralValue ())), }
"SingleMu_2017" + runPeriod, dirs['Andrew'] + "2017/zToMuMu") print "********************************************************************************" print "Baseline sideband result ({:.2f}, {:.2f}) cm: ".format( fakeSidebands[0][0], fakeSidebands[0][1]) fakeTrackBkgdEstimate.addMinD0(fakeSidebands[0][0]) fakeTrackBkgdEstimate.addMaxD0(fakeSidebands[0][1]) nEstFake[(nLayersWord, runPeriod)] = fakeTrackBkgdEstimate.printNest()[0] fout.Close() if len(fakeSidebands) > 1: print "********************************************************************************" print "Mean result over sidebands: " nEstAllSidebands = Measurement(0, 0) pFakeAllSidebands = Measurement(0, 0) for sb in fakeSidebands: fakeTrackBkgdEstimate.addMinD0(sb[0]) fakeTrackBkgdEstimate.addMaxD0(sb[1]) sbResults = fakeTrackBkgdEstimate.printNest(verbose=False) nEstAllSidebands += sbResults[0] pFakeAllSidebands += sbResults[1] print '\t({:.2f}, {:.2f}: N_est = '.format( sb[0], sb[1]) + str( sbResults[0]) + ' ; P_fake = ' + str(sbResults[1]) nEstAllSidebands /= len(fakeSidebands) pFakeAllSidebands /= len(fakeSidebands) print "N_est (mean): ", nEstAllSidebands print "P_fake (mean): ", pFakeAllSidebands
def printNctrl(self): if hasattr(self, "DisTrkInvertD0"): n, nError = getHistIntegral( self.DisTrkInvertD0["sample"], self.DisTrkInvertD0["condorDir"], self.DisTrkInvertD0["name"] + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", self._minD0, self._maxD0 - 0.001) n = Measurement(n, (nError if n != 0.0 else 0.5 * TMath.ChisquareQuantile(0.68, 2 * (n + 1)))) n.isPositive() if self._minHits < 7: n6, n6Error = getHistIntegral( self.DisTrkInvertD0NHits6["sample"], self.DisTrkInvertD0NHits6["condorDir"], self.DisTrkInvertD0NHits6["name"] + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", self._minD0, self._maxD0 - 0.001) n6 = Measurement(n6, (n6Error if n6 != 0.0 else 0.5 * TMath.ChisquareQuantile(0.68, 2 * (n6 + 1)))) n6.isPositive() n += n6 if self._minHits < 6: n5, n5Error = getHistIntegral( self.DisTrkInvertD0NHits5["sample"], self.DisTrkInvertD0NHits5["condorDir"], self.DisTrkInvertD0NHits5["name"] + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", self._minD0, self._maxD0 - 0.001) n5 = Measurement(n5, (n5Error if n5 != 0.0 else 0.5 * TMath.ChisquareQuantile(0.68, 2 * (n5 + 1)))) n5.isPositive() n += n5 if self._minHits < 5: n4, n4Error = getHistIntegral( self.DisTrkInvertD0NHits4["sample"], self.DisTrkInvertD0NHits4["condorDir"], self.DisTrkInvertD0NHits4["name"] + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", self._minD0, self._maxD0 - 0.001) n4 = Measurement(n4, (n4Error if n4 != 0.0 else 0.5 * TMath.ChisquareQuantile(0.68, 2 * (n4 + 1)))) n4.isPositive() n += n4 if self._minHits < 4: n3, n3Error = getHistIntegral( self.DisTrkInvertD0NHits3["sample"], self.DisTrkInvertD0NHits3["condorDir"], self.DisTrkInvertD0NHits3["name"] + "Plotter", "Track-eventvariable Plots/trackd0WRTPVMag", self._minD0, self._maxD0 - 0.001) n3 = Measurement(n3, (n3Error if n3 != 0.0 else 0.5 * TMath.ChisquareQuantile(0.68, 2 * (n3 + 1)))) n3.isPositive() n += n3 pFake = float("nan") norm = 1.0 # For ZtoMuMu control regions, need to normalize to BasicSelection if hasattr(self, "ZtoLL") and hasattr(self, "Basic"): norm = self.Basic["yield"] / self.ZtoLL["yield"] pFake = n / self.ZtoLL["yield"] elif hasattr(self, "Basic"): pFake = n / self.Basic["yield"] nRaw = n n *= norm n *= self._prescale print "N_ctrl: " + str(n) + " (" + str( n / self._luminosityInInvFb) + " fb)" print "P_fake^raw: " + str(pFake) return (n, nRaw, norm, pFake) else: print "DisTrkInvertD0 is not defined. Not printing N_ctrl..." return (float("nan"), float("nan"))
def printPpassMetTriggers(self): if hasattr(self, "TagPt35") and (hasattr(self, "TagPt35MetTrig") or (hasattr(self, "TrigEffDenom") and hasattr(self, "TrigEffNumer"))): totalHist = passesHist = l1TotalHist = l1PassesHist = None total = 0.0 passes = 0.0 if not self._useHistogramsForPpassMetTriggers: sample = self.TrigEffDenom["sample"] if hasattr( self, "TrigEffDenom") else self.TagPt35["sample"] condorDir = self.TrigEffDenom["condorDir"] if hasattr( self, "TrigEffDenom") else self.TagPt35["condorDir"] name = self.TrigEffDenom["name"] if hasattr( self, "TrigEffDenom") else self.TagPt35["name"] hist = "Track-met Plots/metNoMuMinusOnePtVsMaxSigmaForFiducialTracksX" totalHist = self.getHistFromProjectionZ( sample, condorDir, name + "Plotter", hist, alternate1DHist="Met Plots/metNoMu") sample = self.TrigEffNumer["sample"] if hasattr( self, "TrigEffNumer") else self.TagPt35MetTrig["sample"] condorDir = self.TrigEffNumer["condorDir"] if hasattr( self, "TrigEffNumer") else self.TagPt35MetTrig["condorDir"] name = self.TrigEffNumer["name"] if hasattr( self, "TrigEffNumer") else self.TagPt35MetTrig["name"] hist = "Track-met Plots/metNoMuMinusOnePtVsMaxSigmaForFiducialTracksX" passesHist = self.getHistFromProjectionZ( sample, condorDir, name + "Plotter", hist, alternate1DHist="Met Plots/metNoMu") else: sample = self.TagPt35MetTrig["sample"] condorDir = self.TagPt35MetTrig["condorDir"] name = self.TagPt35MetTrig["name"] trigEffHist = getHist( sample, condorDir, name + "Plotter" + "/" + self._Flavor + "-eventvariable Plots", "passesMETTriggersWithout" + self._Flavor + "Vs" + self._Flavor + "MetNoMuMinusOnePt") totalHist = trigEffHist.ProjectionX() totalHist.SetDirectory(0) totalHist.SetName("total") trigEffHist.GetYaxis().SetRangeUser(1.0, 2.0) passesHist = trigEffHist.ProjectionX() passesHist.SetDirectory(0) passesHist.SetName("passes") if hasattr(self, "TagPt35MetL1Trig"): sample = self.TagPt35MetL1Trig["sample"] condorDir = self.TagPt35MetL1Trig["condorDir"] name = self.TagPt35MetL1Trig["name"] l1TrigEffHist = getHist( sample, condorDir, name + "Plotter" + "/" + self._Flavor + "-eventvariable Plots", "passesL1ETMWithout" + self._Flavor + "Vs" + self._Flavor + "MetNoMuMinusOnePt") l1TotalHist = l1TrigEffHist.ProjectionX() l1TotalHist.SetDirectory(0) l1TotalHist.SetName("l1Total") l1PassesHist = l1TotalHist.Clone("l1PassesHist") l1PassesHist.SetDirectory(0) l1PassesHist.SetName("l1PassesHist") progressIndicator = ProgressIndicator( "calculating L1 trigger efficiency") progressIndicator.printProgress() for x in range(1, l1TrigEffHist.GetXaxis().GetNbins() + 1): progressIndicator.setPercentDone( (x / float(l1TrigEffHist.GetXaxis().GetNbins())) * 100.0) progressIndicator.printProgress() nFail = Measurement(l1TrigEffHist.GetBinContent(x, 1), l1TrigEffHist.GetBinError(x, 1)) nPass = Measurement(0.0, 0.0) for y in range(2, l1TrigEffHist.GetYaxis().GetNbins() + 1): prescale = l1TrigEffHist.GetYaxis().GetBinLowEdge( y) n = Measurement(l1TrigEffHist.GetBinContent(x, y), l1TrigEffHist.GetBinError(x, y)) nPass += n nFail += n * (prescale - 1.0) nTotal = nFail + nPass l1TotalHist.SetBinContent(x, nTotal.centralValue()) l1TotalHist.SetBinError(x, nTotal.maxUncertainty()) l1PassesHist.SetBinContent(x, nPass.centralValue()) l1PassesHist.SetBinError(x, nPass.maxUncertainty()) progressIndicator.printProgress(True) sample = self.TagPt35["sample"] condorDir = self.TagPt35["condorDir"] name = self.TagPt35["name"] #metHist = self.getHistFromProjectionZ (sample, condorDir, name + "Plotter", self._metMinusOneHist, alternate1DHist = self._Flavor + " Plots/" + self._flavor + "MetNoMuMinusOnePt") metHist2D = getHist( sample, condorDir, name + "Plotter" + "/" + self._Flavor + "-eventvariable Plots", "deltaPhiMetJetLeadingVs" + self._Flavor + "MetNoMuMinusOnePt") metHist2D.GetYaxis().SetRangeUser(self._phiCut, 4.0) metHist = metHist2D.ProjectionX("metHist") self.plotTriggerEfficiency(passesHist, totalHist, "HLT") if l1PassesHist and l1TotalHist: self.plotTriggerEfficiency(l1PassesHist, l1TotalHist, "L1") passesHist.Multiply(l1PassesHist) totalHist.Multiply(l1TotalHist) self.plotTriggerEfficiency(passesHist, totalHist, "Full") passesHist.Divide(totalHist) metHist.Multiply(passesHist) total = 0.0 totalError = Double(0.0) passesError = Double(0.0) passes = metHist.IntegralAndError(metHist.FindBin(self._metCut), metHist.GetNbinsX() + 1, passesError) passes = Measurement(passes, passesError) passes.isPositive() sample = self.TagPt35["sample"] condorDir = self.TagPt35["condorDir"] name = self.TagPt35["name"] #met = self.getHistFromProjectionZ (sample, condorDir, name + "Plotter", self._metMinusOneHist, alternate1DHist = self._Flavor + " Plots/" + self._flavor + "MetNoMuMinusOnePt") met = getHist( sample, condorDir, name + "Plotter" + "/" + self._Flavor + "-eventvariable Plots", "deltaPhiMetJetLeadingVs" + self._Flavor + "MetNoMuMinusOnePt") totalError = Double(0.0) total = met.IntegralAndError(met.GetXaxis().FindBin(self._metCut), met.GetNbinsX() + 1, met.GetYaxis().FindBin(self._phiCut), met.GetNbinsY() + 1, totalError) total = Measurement(total, totalError) total.isPositive() eff = passes / total print "P (pass met triggers): " + str(eff) return (eff, passesHist) else: print "TagPt35 and TagPt35MetTrig not both defined. Not printing P (pass met triggers)..." return (float("nan"), float("nan"))
def printSystematic(self): dataHits = None mcHits = None signalHits = None systematic = [] masses = map(float, self._masses) lifetimes = map(float, self._lifetimes) massBins = array("d", masses + [masses[-1] + 100]) lifetimeBins = array("d", lifetimes + [lifetimes[-1] * 10.0]) h = TH2D("nMissOutSystematic", ";chargino mass [GeV];chargino lifetime [cm/c]", len(massBins) - 1, massBins, len(lifetimeBins) - 1, lifetimeBins) for mass in self._masses: for lifetime in self._lifetimes: sample = "AMSB_chargino_" + str(mass) + "GeV_" + str( lifetime) + "cm" + self._signalSuffix eTrue3ToInf, signalHits = self.getNMissOutEfficiency( "Signal", 3, 12, hits=None, sample=sample) eTrue2, signalHits = self.getNMissOutEfficiency( "Signal", 2, 2, hits=signalHits, sample=sample) eTrue1, signalHits = self.getNMissOutEfficiency( "Signal", 1, 1, hits=signalHits, sample=sample) eTrue0, signalHits = self.getNMissOutEfficiency( "Signal", 0, 0, hits=signalHits, sample=sample) eMC1ToInf, mcHits = self.getNMissOutEfficiency("MC", 1, 12, hits=mcHits) eMC2ToInf, mcHits = self.getNMissOutEfficiency("MC", 2, 12, hits=mcHits) eMC3ToInf, mcHits = self.getNMissOutEfficiency("MC", 3, 12, hits=mcHits) eData1ToInf, dataHits = self.getNMissOutEfficiency( "Data", 1, 12, hits=dataHits) eData2ToInf, dataHits = self.getNMissOutEfficiency( "Data", 2, 12, hits=dataHits) eData3ToInf, dataHits = self.getNMissOutEfficiency( "Data", 3, 12, hits=dataHits) mcEff = eTrue3ToInf + eTrue2 * eMC1ToInf + eTrue1 * eMC2ToInf + eTrue0 * eMC3ToInf dataEff = eTrue3ToInf + eTrue2 * eData1ToInf + eTrue1 * eData2ToInf + eTrue0 * eData3ToInf #mcEff = eTrue2 * eMC1ToInf + eTrue1 * eMC2ToInf + eTrue0 * eMC3ToInf #dataEff = eTrue2 * eData1ToInf + eTrue1 * eData2ToInf + eTrue0 * eData3ToInf sys = abs(mcEff - dataEff) / mcEff if mcEff > 0.0 else Measurement( 0.0, 0.0) systematic.append([ sample, str(max(1.0 - sys.centralValue(), 1.0e-12)), str(max(1.0 + sys.centralValue(), 1.0e-12)) ]) sys *= 100.0 sys.printUncertainty(False) sys.printLongFormat(True) h.Fill(mass, lifetime, abs(sys.centralValue() / 100.0)) print "[" + str(mass) + " GeV, " + str( lifetime ) + " cm] data eff.: " + str(dataEff) + ", MC eff.: " + str( mcEff) + ", systematic uncertainty: " + str(sys) + "%" if self._foutForPlot: self._foutForPlot.cd() h.Write() self._foutForPlot.Close() if self._fout: width = max(len(word) for row in systematic for word in row) + 2 for row in systematic: self._fout.write("".join(word.ljust(width) for word in row) + "\n")
def printPpassVetoTagProbe(self): self.plotPpassVeto() if not hasattr(self._pPassVeto, "centralValue"): if hasattr(self, "TagProbe") and hasattr(self, "TagProbePass"): total = None passes = None if not self._useHistogramsForPpassVeto: total = self.TagProbe["yield"] passes = self.TagProbePass["yield"] else: hist = "Eventvariable Plots/nGoodTPPairs" sample = self.TagProbe["sample"] condorDir = self.TagProbe["condorDir"] name = self.TagProbe["name"] totalHist = getHist(sample, condorDir, name + "Plotter", hist) hist = "Eventvariable Plots/nProbesPassingVeto" sample = self.TagProbePass["sample"] condorDir = self.TagProbePass["condorDir"] name = self.TagProbePass["name"] passesHist = getHist(sample, condorDir, name + "Plotter", hist) totalError1 = Double(0.0) passesError1 = Double(0.0) totalError2 = Double(0.0) passesError2 = Double(0.0) if self._flavor != "tau": total = totalHist.IntegralAndError( 2, 2, totalError1) + 2.0 * totalHist.IntegralAndError( 3, 3, totalError2) passes = passesHist.IntegralAndError( 2, 2, passesError1) + 2.0 * passesHist.IntegralAndError( 3, 3, passesError2) else: total = totalHist.IntegralAndError(2, 2, totalError1) passes = passesHist.IntegralAndError( 2, 2, passesError1) total = Measurement( total, math.hypot(totalError1, 2.0 * totalError2)) passes = Measurement( passes, math.hypot(passesError1, 2.0 * passesError2) if passes != 0.0 else up68) passes1 = Measurement(0.0, 0.0) if hasattr(self, "TagProbe1") and hasattr( self, "TagProbePass1"): if not self._useHistogramsForPpassVeto: total += self.TagProbe1["yield"] passes1 = self.TagProbePass1["yield"] else: hist = "Eventvariable Plots/nGoodTPPairs" sample = self.TagProbe1["sample"] condorDir = self.TagProbe1["condorDir"] name = self.TagProbe1["name"] totalHist = getHist(sample, condorDir, name + "Plotter", hist) hist = "Eventvariable Plots/nProbesPassingVeto" sample = self.TagProbePass1["sample"] condorDir = self.TagProbePass1["condorDir"] name = self.TagProbePass1["name"] passesHist = getHist(sample, condorDir, name + "Plotter", hist) total1 = 0.0 passes1 = 0.0 totalError1 = Double(0.0) passesError1 = Double(0.0) totalError2 = Double(0.0) passesError2 = Double(0.0) if self._flavor != "tau": total1 = totalHist.IntegralAndError( 2, 2, totalError1 ) + 2.0 * totalHist.IntegralAndError( 3, 3, totalError2) passes1 = passesHist.IntegralAndError( 2, 2, passesError1 ) + 2.0 * passesHist.IntegralAndError( 3, 3, passesError2) else: total1 = totalHist.IntegralAndError( 2, 2, totalError1) passes1 = passesHist.IntegralAndError( 2, 2, passesError1) total += Measurement( total1, math.hypot(totalError1, 2.0 * totalError2)) passes1 = Measurement( passes1, math.hypot(passesError1, 2.0 * passesError2) if passes1 != 0.0 else up68) background = Measurement(0.0, 0.0) if hasattr(self, "TagProbePassSS"): hist = "Met Plots/metNoMu" sample = self.TagProbePassSS["sample"] condorDir = self.TagProbePassSS["condorDir"] name = self.TagProbePassSS["name"] backgroundHist = getHist(sample, condorDir, name + "Plotter", hist) backgroundError = Double(0.0) background = backgroundHist.IntegralAndError( 0, backgroundHist.GetNbinsX() + 1, backgroundError) background = Measurement(background, backgroundError) background1 = Measurement(0.0, 0.0) if hasattr(self, "TagProbePassSS1"): hist = "Met Plots/metNoMu" sample = self.TagProbePassSS1["sample"] condorDir = self.TagProbePassSS1["condorDir"] name = self.TagProbePassSS1["name"] backgroundHist = getHist(sample, condorDir, name + "Plotter", hist) backgroundError = Double(0.0) background1 = backgroundHist.IntegralAndError( 0, backgroundHist.GetNbinsX() + 1, backgroundError) background1 = Measurement(background1, backgroundError) if (passes - background - background1) > 0.0: passes -= background passes1 -= background1 passes.isPositive() passes1.isPositive() total.isPositive() scaledPasses = passes * self._tagProbePassScaleFactor + passes1 * self._tagProbePass1ScaleFactor p = passes sf = Measurement(self._tagProbePassScaleFactor, 0.0) if scaledPasses > 0.0: p = (scaledPasses * scaledPasses) / ( passes * self._tagProbePassScaleFactor * self._tagProbePassScaleFactor + passes1 * self._tagProbePass1ScaleFactor * self._tagProbePass1ScaleFactor) sf = (passes * self._tagProbePassScaleFactor * self._tagProbePassScaleFactor + passes1 * self._tagProbePass1ScaleFactor * self._tagProbePass1ScaleFactor) / scaledPasses p.setUncertainty(math.sqrt(p.centralValue())) sf.setUncertainty(0.0) if (self._flavor == "electron" or self._flavor == "muon") and not self._useHistogramsForPpassVeto: eff = scaledPasses / (2.0 * total - scaledPasses) else: eff = scaledPasses / total print "P (pass lepton veto) in tag-probe sample: " + str(eff) return (eff, p, sf, total) else: print "TagProbe and TagProbePass not both defined. Not printing lepton veto efficiency..." return (float("nan"), float("nan"), float("nan"), float("nan")) else: print "P (pass lepton veto) from user input: " + str( self._pPassVeto) return (self._pPassVeto, float("nan"), float("nan"), float("nan"))
#!/usr/bin/env python from OSUT3Analysis.Configuration.Measurement import Measurement from DisappTrks.SignalMC.signalCrossSecs import * print "\\begin{tabular}{llll}" print " \\hline" print " $m (\\Pchipm)$ [$\\GeV$] & $\\sigma (\\Pp\\Pp {\\rightarrow} \\Pchipm \\Pchimp)$ [$\\mathrm{pb}$] & $\\sigma (\\Pp\\Pp {\\rightarrow} \\Pchiz \\Pchipm)$ [$\\mathrm{pb}$] & total $\\sigma$ [$\\mathrm{pb}$] \\\\" print " \\hline" for mass in sorted (signal_cross_sections.keys ()): cnX = chargino_neutralino_cross_sections[mass] ccX = chargino_chargino_cross_sections[mass] totalX = signal_cross_sections[mass] cn = Measurement (cnX['value'], cnX['error']) cc = Measurement (ccX['value'], ccX['error']) total = Measurement (totalX['value'], totalX['error']) cn.setUncertainty ((cn.uncertainty () - 1.0) * cn.centralValue ()) cc.setUncertainty ((cc.uncertainty () - 1.0) * cc.centralValue ()) total.setUncertainty ((total.uncertainty () - 1.0) * total.centralValue ()) #cn *= 1.0e3 #cc *= 1.0e3 #total *= 1.0e3 cn.printTeX () cc.printTeX () total.printTeX ()