Esempio n. 1
0
    def run(self):
        for igen, gj in enumerate(self.outer.genjets_):
            match=False
            if abs(gj.Eta()) > 3.0 or abs(gj.Eta()) < 1.5 : continue
            pt_gen=gj.Pt()
            if pt_gen < 40 : continue

            isReco=False
            for itr, jet in enumerate(self.outer.jets_):
                if jet.Pt()<20 : continue
                #if jet.Pt()<200 : continue ##FIXME
                if abs(jet.Eta()) > 3.0 or abs(jet.Eta()) < 1.5 : continue
                if gj.DeltaR(jet) < 0.4: isReco=True
            if not isReco: continue

            for icl, di in enumerate(self.outer.cl_raw_):
                ieta =  self.outer.cl_eta_[icl]
                iphi = self.outer.cl_phi_[icl] 
                ilayer = self.outer.cl_layer_[icl]
                if f.deltaR(gj.Eta(),ieta, gj.Phi(),iphi ) >= self.dR: continue
                for jcl, dj in enumerate(self.outer.cl_raw_):
                    jeta =  self.outer.cl_eta_[jcl]
                    jphi = self.outer.cl_phi_[jcl] 
                    jlayer = self.outer.cl_layer_[jcl]
                    if f.deltaR(gj.Eta(),jeta, gj.Phi(),jphi ) >= self.dR: continue
                    match = True
                    self.histos["M"].Fill(ilayer,jlayer,di*dj)
                self.histos["v"].Fill(ilayer,di*pt_gen)

            if match:
                self.histos["N"].Fill(1)

        return self
Esempio n. 2
0
    def run(self):

        for igen, gj in enumerate(self.outer.genjets_):
            match=False
            if abs(gj.Eta()) > 3.0 or abs(gj.Eta()) < 1.5 : continue
            pt_gen=gj.Pt()

            pt0 =-1
            pt1 =-1
            for ipt in range( 0,len(self.ptcuts) -1 ):
                if pt_gen >= self.ptcuts[ipt] and pt_gen<self.ptcuts[ipt+1]:
                    pt0 = self.ptcuts[ipt]
                    pt1 = self.ptcuts[ipt+1]
            if pt0 < 0: continue ## not in the pt list

            isReco=False
            for itr, jet in enumerate(self.outer.jets_):
                if jet.Pt()<20 : continue
                if abs(jet.Eta()) > 3.0 or abs(jet.Eta()) < 1.5 : continue
                if gj.DeltaR(jet) < 0.4: isReco=True
            if not isReco: continue

            for icl, di in enumerate(self.outer.cl_raw_):
                ieta =  self.outer.cl_eta_[icl]
                iphi = self.outer.cl_phi_[icl] 
                if f.deltaR(gj.Eta(),ieta, gj.Phi(),iphi ) >= self.dR: continue
                ilayer = self.outer.cl_layer_[icl]
                ipt =  self.outer.cl_pt_[icl]
                iraw = self.outer.cl_raw_[icl]
                self.histos["raw_layer%d_pt%.0f_%.0f"%(ilayer,pt0,pt1)] . Fill (iraw) 
                self.histos["cl_layer%d_pt%.0f_%.0f"%(ilayer,pt0,pt1)] . Fill (ipt) 

        return self
Esempio n. 3
0
    def loop(self):

        nentries = self.chain.GetEntries()
        for ientry, entry in enumerate(self.chain):
            self.print_progress(ientry, nentries)

            #self.clear()
            #c3d_pt_ = np.array(entry.cl3d_pt)
            #c3d_eta_ = np.array(entry.cl3d_eta)
            #c3d_phi_ = np.array(entry.cl3d_phi)
            #c3d_energy_ = np.array(entry.cl3d_energy)

            gen_pt_ = np.array(entry.gen_pt)
            gen_eta_ = np.array(entry.gen_eta)
            gen_phi_ = np.array(entry.gen_phi)
            gen_energy_ = np.array(entry.gen_energy)
            gen_status_ = np.array(entry.gen_status)
            gen_id_ = np.array(entry.gen_id)

            cl_pt_ = np.array(entry.cl_pt)
            cl_eta_ = np.array(entry.cl_eta)
            cl_phi_ = np.array(entry.cl_phi)
            cl_energy_ = np.array(entry.cl_energy)
            cl_layer_ = np.array(entry.cl_layer)
            cl_ncells_ = np.array(entry.cl_ncells)
            ##FIXME ??? check
            cl_cells_ = np.array(entry.cl_cells)  ### ?

            tc_data_ = np.array(entry.tc_data)

            for igen in range(0, len(gen_pt_)):
                if gen_status_[igen] != 1: continue
                if abs(gen_id_[igen]) != 11: continue  ## electron

                for icl in range(0, len(cl_pt_)):
                    if f.deltaR(cl_eta_[icl], gen_eta_[igen], cl_phi_[icl],
                                gen_phi_[igen]) > self.dR:
                        continue
                    ## MATCHED
                    # 1. compute raw energy in the c2d
                    raw = 0.0
                    for icell in range(0, cl_ncells_[icl]):
                        raw += tc_data_[cl_cells_[icl][icell]]
                    # 2. save a histogram with the calibrated energy and the raw energy
                    # nominal and pt
                    name = "raw_layer_%d_truept_%.0f" % (cl_layer_[icl],
                                                         gen_pt_[igen])
                    if name not in self.histos:
                        self.histos[name] = ROOT.TH1D(name, name, self.nbins,
                                                      self.xmin, self.xmax)
                    self.histos[name].Fill(raw)

                    name = "rawt_layer_%d_truept_%.0f" % (cl_layer_[icl],
                                                          gen_pt_[igen])
                    t = math.exp(-cl_eta_[icl])  ## tan theta/2
                    sint = 2 * t / (1 + t * t)  ## sin theta
                    if name not in self.histos:
                        self.histos[name] = ROOT.TH1D(name, name, self.nbins,
                                                      self.xmin, self.xmax)
                    self.histos[name].Fill(raw * sint)

                    name = "pt_layer_%d_truept_%.0f" % (cl_layer_[icl],
                                                        gen_pt_[igen])
                    if name not in self.histos:
                        self.histos[name] = ROOT.TH1D(name, name, self.nbins,
                                                      self.xmin, self.xmax)
                    self.histos[name].Fill(cl_pt_[icl])

            ## produce trigger jets and gen jets

        self.output.cd()
        for hStr in self.histos:
            self.histos[hStr].Write()
        return self
Esempio n. 4
0
    def plotResponse(self):

        # definition of the output file and histogram to store in it
        output = ROOT.TFile(self.outputFile + ".root", "RECREATE")
        h_resoPt = ROOT.TH1D("resoPt", "Pt response", 100, 0, 2)
        h_resoEta = ROOT.TH1D("resoEta", "Eta response", 100, -0.02, 0.02)
        h_resoPhi = ROOT.TH1D("resoPhi", "Phi response", 100, -0.05, 0.05)
        h_L1PtvsTrue2D = ROOT.TH2D("h_L1PtvsTrue2D", "h_L1PtvsTrue2D", 200, 0,
                                   200, 201, -1, 200)

        self.chain.Print()

        # loop over the ttree ntries
        for ientry, entry in enumerate(self.chain):
            gen_pt_ = np.array(entry.gen_pt)  # for vectors
            gen_eta_ = np.array(entry.gen_eta)
            gen_phi_ = np.array(entry.gen_phi)
            gen_energy_ = np.array(entry.gen_energy)
            gen_status_ = np.array(entry.gen_status)
            gen_id_ = np.array(entry.gen_id)
            c3d_pt_ = np.array(entry.cl3d_pt)
            c3d_eta_ = np.array(entry.cl3d_eta)
            c3d_phi_ = np.array(entry.cl3d_phi)
            c3d_energy_ = np.array(entry.cl3d_energy)

            # select the good C3d
            goodC3d_idx = []
            for i_c3d in range(len(c3d_pt_)):
                if (abs(c3d_eta_[i_c3d]) > self.cfg.minEta_C3d
                        and abs(c3d_eta_[i_c3d]) < self.cfg.maxEta_C3d
                        and c3d_pt_[i_c3d] > self.cfg.minPt_C3d):
                    goodC3d_idx.append(i_c3d)

            # loop over the gen particle and apply basic selection at MC-truth level
            for i_gen in range(len(gen_pt_)):
                if (abs(gen_eta_[i_gen]) > self.cfg.minEta_gen
                        and abs(gen_eta_[i_gen]) < self.cfg.maxEta_gen
                        and gen_pt_[i_gen] > self.cfg.minPt_gen
                        and abs(gen_id_[i_gen]) == self.cfg.particle_type
                        and gen_status_[i_gen] == self.cfg.particle_status):

                    hasMatched = False
                    pt_cand = -1.
                    eta_cand = -100.
                    phi_cand = -100.

                    # loop over the good 3D-cluster
                    for i in range(len(goodC3d_idx)):
                        i_c3d = goodC3d_idx[i]
                        dR = f.deltaR(gen_eta_[i_gen], c3d_eta_[i_c3d],
                                      gen_phi_[i_gen], c3d_phi_[i_c3d])
                        if dR < 0.5:
                            hasMatched = True
                            if c3d_pt_[i_c3d] > pt_cand:
                                pt_cand = c3d_pt_[i_c3d]
                                eta_cand = c3d_eta_[i_c3d]
                                phi_cand = c3d_phi_[i_c3d]

                    # fill the response histograms
                    if hasMatched:
                        print gen_pt_[i_gen], pt_cand
                        h_L1PtvsTrue2D.Fill(gen_pt_[i_gen], pt_cand)
                    elif not hasMatched:
                        print gen_pt_[i_gen], -1
                        h_L1PtvsTrue2D.Fill(gen_pt_[i_gen], -1)

                    h_resoPt.Fill(pt_cand / gen_pt_[i_gen])
                    h_resoEta.Fill(eta_cand - gen_eta_[i_gen])
                    h_resoPhi.Fill(phi_cand - gen_phi_[i_gen])

        # write histograms into output file
        output.cd()
        h_resoPt.Write()
        h_resoEta.Write()
        h_resoPhi.Write()
        h_L1PtvsTrue2D.Write()