dally96 / DisplacedTauAnalysis

1 stars 2 forks source link

Slight discrepancies in cutflow #1

Open dally96 opened 1 year ago

dally96 commented 1 year ago

Finally, Mykyta and I have synched our cutflows where our selections on taus are the same, but our selections on jets are very slightly different. Without the lepton veto, it was a one jet difference. With the lepton veto, it's a two jet difference.

Without lepton veto:

Mykyta n_jets: 1971

Daniel n_jets: 1970

With lepton veto:

Mykyta n_jets: 635

Daniel n_jets: 637

On the subject of lepton veto, I was able to recreate the GenLepton collection by picking out the (charged) leptons from the GenParticle collection and choosing the ones that have the statusFlags isPrompt() and isFirstCopy(). I checked kinematics against each other and they agree. However, I have 3 more particles when I do it. I need to check why they appear in my version of the GenLepton collection.

class GenLepton {
public:
    enum class Kind { PromptElectron = 1, PromptMuon = 2, TauDecayedToElectron = 3, TauDecayedToMuon = 4,TauDecayedToHadrons = 5, Other = 6 };

    static constexpr size_t MaxNumberOfParticles = 1000;
    ...
    template<typename IntVector, typename FloatVector>
    static std::vector<GenLepton> fromNanoAOD( const FloatVector& GenPart_pt ,
                                            const FloatVector& GenPart_eta,
                                            const FloatVector& GenPart_phi,
                                            const FloatVector& GenPart_mass,
                                            const FloatVector& GenPart_vertexX,
                                            const FloatVector& GenPart_vertexY,
                                            const FloatVector& GenPart_vertexZ,
                                            const IntVector& GenPart_genPartIdxMother,
                                            const IntVector& GenPart_pdgId,
                                            const IntVector& GenPart_statusFlags,
                                            int event=0){
        try {
            std::vector<GenLepton> genLeptons;
            std::set<size_t> processed_particles;
            for(size_t genPart_idx=0; genPart_idx<GenPart_pt.size(); ++genPart_idx ){
                if(processed_particles.count(genPart_idx)) continue;
                GenStatusFlags particle_statusFlags(GenPart_statusFlags.at(genPart_idx));
                if(!(particle_statusFlags.isPrompt() && particle_statusFlags.isFirstCopy())) continue;
                const int abs_pdg = std::abs(GenPart_pdgId.at(genPart_idx));
                if(!GenParticle::ChargedLeptons().count(static_cast<GenParticle::PdgId>(abs_pdg)))
                    continue;
                GenLepton lepton;
                FillImplNano<IntVector, FloatVector> fillImplNano(lepton, processed_particles,GenPart_pt,GenPart_eta, GenPart_phi, GenPart_mass,
                GenPart_vertexX, GenPart_vertexY, GenPart_vertexZ,
                GenPart_genPartIdxMother, GenPart_pdgId, GenPart_statusFlags);
                fillImplNano.FillAll(genPart_idx);
                lepton.initialize();
                genLeptons.push_back(lepton);
            }
            return genLeptons;
        } catch(std::runtime_error& e) {
            std::cerr << "Event id = " << event << std::endl;
            throw;
        }
    }
    ...
Branches = { 

            "Jet_pt": nano_file_evt["Jet_pt"].array(),
            "Jet_phi": nano_file_evt["Jet_phi"].array(),
            "Jet_eta": nano_file_evt["Jet_eta"].array(),
            "Jet_genJetIdx": nano_file_evt["Jet_genJetIdx"].array(),

            "GenPart_genPartIdxMother": nano_file_evt["GenPart_genPartIdxMother"].array(),
            "GenPart_pdgId": nano_file_evt["GenPart_pdgId"].array(),
            "GenPart_statusFlags": nano_file_evt["GenPart_statusFlags"].array(),
            "GenPart_pt": nano_file_evt["GenPart_pt"].array(),
            "GenPart_phi": nano_file_evt["GenPart_phi"].array(),
            "GenPart_eta": nano_file_evt["GenPart_eta"].array(),
            ...
            }
lepton_selection = ((abs(Branches["GenPart_pdgId"]) == 11) | (abs(Branches["GenPart_pdgId"]) == 13) | (abs(Branches["GenPart_pdgId"]) == 15))
prompt_selection = (Branches["GenPart_statusFlags"] & 1 == 1)
first_selection  = ((Branches["GenPart_statusFlags"] & 4096) == 4096)

GenPart_genLeptons_eta = Branches["GenPart_eta"][lepton_selection & prompt_selection & first_selection]
GenPart_genLeptons_phi = Branches["GenPart_phi"][lepton_selection & prompt_selection & first_selection]
GenPart_genLeptons_pt = Branches["GenPart_pt"][lepton_selection & prompt_selection & first_selection]
...
for evt in range(nevt):
  if len(Branches["Jet_pt"][evt]) > 0 :
    for jet_idx in range(len(Branches["Jet_pt"][evt])):
        lepVeto = False
        if len(GenPart_genLeptons_eta[evt]) > 0:
          for tau_idx in range(len(GenPart_genLeptons_eta[evt])):
            lep_dphi = abs(Branches["Jet_phi"][evt][jet_idx] - GenPart_genLeptons_phi[evt][tau_idx])
            if (lep_dphi > math.pi) : dphi -= 2 * math.pi
            lep_deta = Branches["Jet_eta"][evt][jet_idx] - GenPart_genLeptons_eta[evt][tau_idx]
            lep_dR2 = lep_dphi ** 2 + lep_deta ** 2
            if lep_dR2 < 0.4**2:
              lepVeto = True
        if lepVeto: continue
...
dally96 commented 1 year ago

The 3 extra particles I'm seeing are electrons. They are somehow removed from the selection with this line of code

if(processed_particles.count(genPart_idx)) continue;

I'm not sure what this means; I was under the assumption that this condition was used to make sure we didn't loop over the same particles twice. Once I understand this condition, then I'll see how to apply it in my code.