Exemple #1
0
    def process(self, event):
        self.tree.reset()
        zprimes_ele = getattr(event, self.cfg_ana.zprime_ele)
        zprimes_muon = getattr(event, self.cfg_ana.zprime_muon)
        if len(zprimes_ele) + len(zprimes_muon) == 0: return

        jets = getattr(event, self.cfg_ana.jets)
        for ijet, jet in enumerate(jets):
            if ijet == 3:
                break
            fillParticle(self.tree, 'jet{ijet}'.format(ijet=ijet + 1), jet)

        self.tree.fill('weight', sign(event.weight))

        met = getattr(event, self.cfg_ana.met)
        fillMet(self.tree, 'met', met)

        zprimes_ele.sort(key=lambda x: x.m(), reverse=True)
        zprimes_muon.sort(key=lambda x: x.m(), reverse=True)

        Zp = TLorentzVector()

        if len(zprimes_ele) > 0 and len(zprimes_muon) == 0:
            fillParticle(self.tree, 'zprime_ele', zprimes_ele[0])
            fillLepton(self.tree, 'lep1', zprimes_ele[0].legs[0])
            fillLepton(self.tree, 'lep2', zprimes_ele[0].legs[1])
            Zp.SetPtEtaPhiM(zprimes_ele[0].pt(), zprimes_ele[0].eta(),
                            zprimes_ele[0].phi(), zprimes_ele[0].m())
            self.tree.fill('zprime_y', Zp.Rapidity())

        elif len(zprimes_muon) > 0 and len(zprimes_ele) == 0:
            fillParticle(self.tree, 'zprime_muon', zprimes_muon[0])
            fillLepton(self.tree, 'lep1', zprimes_muon[0].legs[0])
            fillLepton(self.tree, 'lep2', zprimes_muon[0].legs[1])
            Zp.SetPtEtaPhiM(zprimes_muon[0].pt(), zprimes_muon[0].eta(),
                            zprimes_muon[0].phi(), zprimes_muon[0].m())
            self.tree.fill('zprime_y', Zp.Rapidity())

        else:
            if zprimes_ele[0].m() > zprimes_muon[0].m():
                fillParticle(self.tree, 'zprime_ele', zprimes_ele[0])
                fillLepton(self.tree, 'lep1', zprimes_ele[0].legs[0])
                fillLepton(self.tree, 'lep2', zprimes_ele[0].legs[1])
                Zp.SetPtEtaPhiM(zprimes_ele[0].pt(), zprimes_ele[0].eta(),
                                zprimes_ele[0].phi(), zprimes_ele[0].m())
                self.tree.fill('zprime_y', Zp.Rapidity())

            else:
                fillParticle(self.tree, 'zprime_muon', zprimes_muon[0])
                fillLepton(self.tree, 'lep1', zprimes_muon[0].legs[0])
                fillLepton(self.tree, 'lep2', zprimes_muon[0].legs[1])
                Zp.SetPtEtaPhiM(zprimes_muon[0].pt(), zprimes_muon[0].eta(),
                                zprimes_muon[0].phi(), zprimes_muon[0].m())
                self.tree.fill('zprime_y', Zp.Rapidity())

        self.tree.tree.Fill()
Exemple #2
0
    def read(self, iev):

        #read a given event

        if iev >= self.nev: return False

        self.tree.GetEntry(iev)

        #initialize event variables
        self.epos = 0.
        self.eneg = 0.

        self.npos = 0
        self.nneg = 0

        self.is_XnXn = False
        self.is_Cen = True

        vec = TLorentzVector()

        #particle loop
        for imc in xrange(self.particles.GetEntriesFast()):
            part = self.particles.At(imc)

            #central electron and positron
            if TMath.Abs(part.GetPdgCode()) == 11:
                if TMath.Abs(part.Eta()) > self.aeta_max: self.is_Cen = False
                #if part.P() < self.p_min: self.is_Cen = False
                pv = TLorentzVector()
                part.Momentum(pv)
                vec += pv

            #select the neutrons
            if part.GetPdgCode() != 2112: continue

            #energy at positive and negative rapidity
            if part.Eta() > 0:
                self.epos += part.Energy()
                self.npos += 1
            else:
                self.eneg += part.Energy()
                self.nneg += 1

        #particle loop

        #flag for XnXn event
        if self.npos > 0 and self.nneg > 0: self.is_XnXn = True

        #J/psi kinematics
        self.pT = vec.Pt()
        self.y = vec.Rapidity()
        self.m = vec.M()

        return True
Exemple #3
0
def plotATOut(inputname, outputname, weighted=True, treename='nominal'):
    infile = TFile.Open(inputname, 'read')
    tree = infile.Get(treename)

    foutput = TFile(outputname, 'recreate')

    # histograms
    histsToPlot = HistogramsTTbar()

    # loop over all events in the tree
    for event in tree:
        if not isSelected(event):
            continue

        weight = event.weight_mc if weighted else 1.

        # jets
        njets = len(event.jet_pt)
        histsToPlot.histNJets.Fill(njets, weight)

        for i in range(njets):
            histsToPlot.histJetPT.Fill(event.jet_pt[i] * 1e-3, weight)
            if i == 0:
                histsToPlot.histJet0PT.Fill(event.jet_pt[i] * 1e-3, weight)
            if i == 1:
                histsToPlot.histJet1PT.Fill(event.jet_pt[i] * 1e-3, weight)

        # MET
        histsToPlot.histMET.Fill(event.met_met * 1e-3, weight)

        # lepton
        if event.el_pt.size() > 0:
            histsToPlot.histElePT.Fill(event.el_pt[0] * 1e-3)
        if event.mu_pt.size() > 0:
            histsToPlot.histMuPT.Fill(event.mu_pt[0] * 1e-3)

        # parton
        # top
        t_p4 = TLorentzVector()
        t_p4.SetPtEtaPhiM(event.MC_t_afterFSR_pt * 1e-3,
                          event.MC_t_afterFSR_eta, event.MC_t_afterFSR_phi,
                          event.MC_t_afterFSR_m * 1e-3)

        histsToPlot.histTopPT.Fill(t_p4.Pt(), weight)
        histsToPlot.histTopY.Fill(t_p4.Rapidity(), weight)

        # anti-top
        tbar_p4 = TLorentzVector()
        tbar_p4.SetPtEtaPhiM(event.MC_tbar_afterFSR_pt * 1e-3,
                             event.MC_tbar_afterFSR_eta,
                             event.MC_tbar_afterFSR_phi,
                             event.MC_tbar_afterFSR_m * 1e-3)

        histsToPlot.histTbarPT.Fill(tbar_p4.Pt(), weight)
        histsToPlot.histTbarY.Fill(tbar_p4.Rapidity(), weight)

        # ttbar
        ttbar_p4 = t_p4 + tbar_p4
        histsToPlot.histTTbarM.Fill(ttbar_p4.M(), weight)
        histsToPlot.histTTbarPT.Fill(ttbar_p4.Pt(), weight)
        histsToPlot.histTTbarDPHI.Fill(abs(t_p4.DeltaPhi(tbar_p4)), weight)

    # Write histograms to the output file
    foutput.cd()
    foutput.Write()
    foutput.Close()
                (1 - math.cos(abs(MET.DeltaPhi(L1 + L2)))))

            CScostheta[0] = costheta_CS(l1pt[0], l1eta[0], l1phi[0], l2pt[0],
                                        l2eta[0], l2phi[0], l1id[0])
            CMsintheta[0] = sintheta_CM(l1pt[0], l1eta[0], l1phi[0], zpt[0],
                                        zeta[0], zphi[0], mass[0])

            Boost = Boosted_Angle(l1pt[0], l1eta[0], l1phi[0], l2pt[0],
                                  l2eta[0], l2phi[0], zpt[0], zeta[0], zphi[0],
                                  mass[0])
            Theta_Boost[0] = Boost[0]  #should always be ~pi
            Theta_lab[0] = Boost[1]
            ZL1_Boost[0] = Boost[2]
            ZL1_lab[0] = Boost[3]
            ZL2_lab[0] = Boost[4]
            ZRapidity[0] = ZB.Rapidity(
            )  #0.5*math.log((ZB.E()+ZB.Pz())/(ZB.E()-ZB.Pz()))

            exec('tout' + suff + '.Fill()')
        exec('fout' + suff + '.Write()')
        exec('fout' + suff + '.Close()')

print variable_amount_array
VAA = str(variable_amount_array).replace(str(variable_amount_array[0]),
                                         '').replace(',', '')
print VAA

######################################################################################

Sstr = str(SystematicSuffixList).replace("['", "" + outdir + "Trees").replace(
    "']", "").replace("', '", " " + outdir + "Trees").replace(" ",
                                                              "/XXX ") + "/XXX"
Exemple #5
0
def plotDelphesOut(inputFiles, outputFile, weighted=True, applyCuts=False):
    print("plotDelphesOut")
    # inputs
    files = getFileList(inputFiles)

    chain = TChain("Delphes")
    for infile in files:
        chain.Add(infile)
        print("Add {} to TChain".format(infile))
    nevents = chain.GetEntries()
    print("Total number of events:", nevents)

    # output
    foutput = TFile(outputFile, "RECREATE")

    # book histograms
    histsToPlot = HistogramsTTbar()

    # loop over events
    ievent = 0
    for ievt, event in enumerate(chain):
        if not ievt % 10000:
            print("processing event", ievt)

        if applyCuts and not passEventSelection(event):
            continue

        weight = event.Event[0].Weight if weighted else 1.

        # jets
        njets = event.Jet.GetEntries()
        histsToPlot.histNJets.Fill(njets)

        for i, jet in enumerate(event.Jet):
            histsToPlot.histJetPT.Fill(jet.PT, weight)
            if i == 0:
                histsToPlot.histJet0PT.Fill(jet.PT, weight)
            if i == 1:
                histsToPlot.histJet1PT.Fill(jet.PT, weight)

        # MET
        if event.MissingET.GetEntries() > 0:
            histsToPlot.histMET.Fill(event.MissingET[0].MET, weight)

        # lepton if l+jets channel selected
        if event.Electron.GetEntries() > 0:
            histsToPlot.histElePT.Fill(event.Electron[0].PT, weight)
        if event.Muon.GetEntries() > 0:
            histsToPlot.histMuPT.Fill(event.Muon[0].PT, weight)

        # partons
        # top
        t_afterFSR = getTopAfterFSR(event.Particle)
        t_p4 = TLorentzVector()
        t_p4.SetPxPyPzE(t_afterFSR.Px, t_afterFSR.Py, t_afterFSR.Pz,
                        t_afterFSR.E)
        histsToPlot.histTopPT.Fill(t_p4.Pt(), weight)
        histsToPlot.histTopY.Fill(t_p4.Rapidity(), weight)

        # antitop
        tbar_afterFSR = getAntiTopAfterFSR(event.Particle)
        tbar_p4 = TLorentzVector()
        tbar_p4.SetPxPyPzE(tbar_afterFSR.Px, tbar_afterFSR.Py,
                           tbar_afterFSR.Pz, tbar_afterFSR.E)
        histsToPlot.histTbarPT.Fill(tbar_p4.Pt(), weight)
        histsToPlot.histTbarY.Fill(tbar_p4.Rapidity(), weight)

        # ttbar
        ttbar_p4 = t_p4 + tbar_p4
        histsToPlot.histTTbarM.Fill(ttbar_p4.M(), weight)
        histsToPlot.histTTbarPT.Fill(ttbar_p4.Pt(), weight)
        histsToPlot.histTTbarDPHI.Fill(abs(t_p4.DeltaPhi(tbar_p4)), weight)

        # decay mode
        isTHadronic = isHadronicTop(t_afterFSR, event.Particle)
        isTbarHadronic = isHadronicTop(tbar_afterFSR, event.Particle)
        histsToPlot.histTTbarMode.Fill(isTHadronic, isTbarHadronic, weight)

    foutput.cd()
    foutput.Write()
    foutput.Close()