Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
#include "GeneratorInterface/Pythia8Interface/test/analyserhepmc/LeptonAnalyserHepMC.h"
#include "HepMC/GenVertex.h"
#include "HepMC/GenParticle.h"
#include <iterator>
#include <algorithm>

LeptonAnalyserHepMC::LeptonAnalyserHepMC(double aMaxEta, double aThresholdEt)
    : MaxEta(aMaxEta), ThresholdEt(aThresholdEt), RConeIsol(0.3), MaxPtIsol(2.), RIdJet(0.3), EpsIdJet(0.6) {
  ;
}

std::vector<HepMC::GenParticle> LeptonAnalyserHepMC::isolatedLeptons(const HepMC::GenEvent* pEv) {
  HepMC::GenEvent::particle_const_iterator part;
  HepMC::GenEvent::particle_const_iterator part1;

  std::vector<HepMC::GenParticle> isoleptons;
  bool lepton = false;
  for (part = pEv->particles_begin(); part != pEv->particles_end(); ++part) {
    lepton = false;
    if (abs((*part)->pdg_id()) == 11)
      lepton = true;
    if (abs((*part)->pdg_id()) == 13)
      lepton = true;
    if (!(*part)->end_vertex() && (*part)->status() == 1 && lepton && fabs((*part)->momentum().eta()) < MaxEta &&
        (*part)->momentum().perp() > ThresholdEt) {
      double eta0 = (*part)->momentum().eta();
      double phi0 = (*part)->momentum().phi();
      double pti, dist, etai, phii, dphi;
      bool isol = true;
      for (part1 = pEv->particles_begin(); part1 != part && part1 != pEv->particles_end(); part1++) {
        if (!(*part1)->end_vertex() && (*part1)->status() == 1) {
          pti = (*part1)->momentum().perp();
          etai = (*part1)->momentum().eta();
          phii = (*part1)->momentum().phi();
          dphi = phi0 - phii;
          if (fabs(phi0 - phii - 6.2832) < fabs(dphi))
            dphi = phi0 - phii - 6.2832;
          if (fabs(phi0 - phii + 6.2832) < fabs(dphi))
            dphi = phi0 - phii + 6.2832;
          dist = sqrt((eta0 - etai) * (eta0 - etai) + dphi * dphi);
          if (dist < RConeIsol && pti > MaxPtIsol) {
            isol = false;
            break;
          }
        }
      }
      if (isol)
        isoleptons.push_back(HepMC::GenParticle(**part));
    }
  }
  return isoleptons;
}

int LeptonAnalyserHepMC::nIsolatedLeptons(const HepMC::GenEvent* pEv) {
  std::vector<HepMC::GenParticle> isoleptons = isolatedLeptons(pEv);
  return isoleptons.size();
}

double LeptonAnalyserHepMC::MinMass(const HepMC::GenEvent* pEv) {
  std::vector<HepMC::GenParticle> isoleptons = isolatedLeptons(pEv);
  if (isoleptons.size() < 2)
    return 0.;
  double MinM = 100000.;
  std::vector<HepMC::GenParticle>::iterator ipart, ipart1;
  for (ipart = isoleptons.begin(); ipart != isoleptons.end(); ipart++) {
    for (ipart1 = isoleptons.begin(); ipart1 != isoleptons.end(); ipart1++) {
      if (ipart1 == ipart)
        continue;
      double px = ipart->momentum().px() + ipart1->momentum().px();
      double py = ipart->momentum().py() + ipart1->momentum().py();
      double pz = ipart->momentum().pz() + ipart1->momentum().pz();
      double e = ipart->momentum().e() + ipart1->momentum().e();
      double mass = sqrt(e * e - px * px - py * py - pz * pz);
      if (mass < MinM)
        MinM = mass;
    }
  }
  return MinM;
}

std::vector<fastjet::PseudoJet> LeptonAnalyserHepMC::removeLeptonsFromJets(std::vector<fastjet::PseudoJet>& jets,
                                                                           const HepMC::GenEvent* pEv) {
  std::vector<HepMC::GenParticle> isoleptons = isolatedLeptons(pEv);
  if (isoleptons.empty())
    return jets;
  std::vector<fastjet::PseudoJet>::iterator ijet;
  std::vector<HepMC::GenParticle>::iterator ipart;
  std::vector<fastjet::PseudoJet> newjets;
  for (ijet = jets.begin(); ijet != jets.end(); ijet++) {
    if (fabs(ijet->rap()) > 5.0)
      continue;
    bool isLepton = false;
    for (ipart = isoleptons.begin(); ipart != isoleptons.end(); ipart++) {
      fastjet::PseudoJet fjLept(
          ipart->momentum().px(), ipart->momentum().py(), ipart->momentum().pz(), ipart->momentum().e());
      //cout << "lepton eta = " << fjLept.rap() << endl;

      if (fjLept.squared_distance(*ijet) < RIdJet * RIdJet &&
          fabs(ijet->e() - ipart->momentum().e()) / ijet->e() < EpsIdJet)
        isLepton = true;
    }

    if (!isLepton)
      newjets.push_back(*ijet);
  }
  return newjets;
}

#if 0
vector<Jet> LeptonAnalyserHepMC::removeLeptonsFromJets(vector<Jet>& jets,
                                                       HepMC::GenEvent* pEv)
{
  vector<HepMC::GenParticle> isoleptons = isolatedLeptons(pEv);
  if(isoleptons.empty()) return jets;
  vector<Jet>::iterator ijet;
  vector<HepMC::GenParticle>::iterator ipart;
#if 00
  // this code can be used if first argument is vector<Jet>, not vector<Jet>&
  for ( ijet = jets.begin(); ijet < jets.end(); ijet++) {
    bool bad = false;
    for ( ipart=isoleptons.begin(); ipart != isoleptons.end(); ipart++) {
      JetableObject jpart(*ipart);
      if(ijet->dist(jpart) < RIdJet &&
         fabs(ijet->e()-ipart->momentum().e())/ijet->e() < EpsIdJet )
                                                             bad = true;
    }
    if(bad) {ijet = jets.erase(ijet); ijet--;}
  }
  return jets;
#endif
  vector<Jet> newjets;
  for ( ijet = jets.begin(); ijet != jets.end(); ijet++) {
    bool islepton = false;
    for ( ipart=isoleptons.begin(); ipart != isoleptons.end(); ipart++) {
      JetableObject jpart(*ipart);
      if(ijet->dist(jpart) < RIdJet &&
         fabs(ijet->e()-ipart->momentum().e())/ijet->e() < EpsIdJet )
                                                       islepton = true;
    }
    if(!islepton) newjets.push_back(*ijet);
  }
  return newjets;
}
#endif