CMS 3D CMS Logo

L1EGPuppiIsoAlgo.cc
Go to the documentation of this file.
2 
3 using namespace l1ct;
4 
6  : config_(pSet.getParameter<std::string>("pfIsoType"),
7  pSet.getParameter<double>("pfPtMin"),
8  pSet.getParameter<double>("dZ"),
9  pSet.getParameter<double>("dRMin"),
10  pSet.getParameter<double>("dRMax"),
11  pSet.getParameter<bool>("pfCandReuse")) {}
12 
14  const PuppiObjs& l1PFCands,
15  EGIsoObjsEmu& outL1EGs,
16  z0_t z0) const {
17  outL1EGs.reserve(l1EGs.size());
18 
19  // make a list of pointers to PF candidates
20  // the pointer will be removed from the list once the candidate has been used and the the module is configured to to so
21  std::list<const PuppiObj*> workPFCands;
22  std::list<const PuppiObj*> workPFCandsPV;
23  for (const auto& l1PFCand : l1PFCands) {
24  workPFCands.emplace_back(&l1PFCand);
25  workPFCandsPV.emplace_back(&l1PFCand);
26  }
27 
28  for (const auto& l1EG : l1EGs) {
29  auto outL1EG(l1EG);
30  iso_t iso = 0;
31  iso_t isoPV = 0;
32  if (!workPFCands.empty()) {
33  iso = calcIso(l1EG, workPFCands);
34  isoPV = calcIso(l1EG, workPFCandsPV, z0);
35  }
36 
38  outL1EG.setHwIso(EGIsoObjEmu::IsoType::PfIso, iso);
39  outL1EG.setHwIso(EGIsoObjEmu::IsoType::PfIsoPV, isoPV);
40  } else {
41  outL1EG.setHwIso(EGIsoObjEmu::IsoType::PuppiIso, iso);
42  outL1EG.setHwIso(EGIsoObjEmu::IsoType::PuppiIsoPV, isoPV);
43  }
44  outL1EGs.emplace_back(outL1EG);
45  }
46 }
47 
48 void L1EGPuppiIsoAlgo::run(EGIsoObjsEmu& l1EGs, const PuppiObjs& l1PFCands, z0_t z0) const {
49  // make a list of pointers to PF candidates
50  // the pointer will be removed from the list once the candidate has been used and the the module is configured to to so
51  std::list<const PuppiObj*> workPFCands;
52  std::list<const PuppiObj*> workPFCandsPV;
53  for (const auto& l1PFCand : l1PFCands) {
54  workPFCands.emplace_back(&l1PFCand);
55  workPFCandsPV.emplace_back(&l1PFCand);
56  }
57 
58  for (auto& l1EG : l1EGs) {
59  iso_t iso = 0;
60  iso_t isoPV = 0;
61  if (!workPFCands.empty()) {
62  iso = calcIso(l1EG, workPFCands);
63  isoPV = calcIso(l1EG, workPFCandsPV, z0);
64  }
65 
67  l1EG.setHwIso(EGIsoObjEmu::IsoType::PfIso, iso);
68  l1EG.setHwIso(EGIsoObjEmu::IsoType::PfIsoPV, isoPV);
69  } else {
70  l1EG.setHwIso(EGIsoObjEmu::IsoType::PuppiIso, iso);
71  l1EG.setHwIso(EGIsoObjEmu::IsoType::PuppiIsoPV, isoPV);
72  }
73  }
74 }
75 
76 void L1EGPuppiIsoAlgo::run(EGIsoEleObjsEmu& l1Eles, const PuppiObjs& l1PFCands) const {
77  // make a list of pointers to PF candidates
78  // the pointer will be removed from the list once the candidate has been used and the the module is configured to to so
79  std::list<const PuppiObj*> workPFCands;
80  for (const auto& l1PFCand : l1PFCands) {
81  workPFCands.emplace_back(&l1PFCand);
82  }
83 
84  for (auto& l1Ele : l1Eles) {
85  iso_t iso = 0;
86  if (!workPFCands.empty()) {
87  iso = calcIso(l1Ele, workPFCands);
88  }
89 
91  l1Ele.setHwIso(EGIsoEleObjEmu::IsoType::PfIso, iso);
92  } else {
93  l1Ele.setHwIso(EGIsoEleObjEmu::IsoType::PuppiIso, iso);
94  }
95  }
96 }
97 
98 iso_t L1EGPuppiIsoAlgo::calcIso(const EGIsoObj& l1EG, std::list<const PuppiObj*>& workPFCands, z0_t z0) const {
99  iso_t sumPt = 0;
100 
101  auto pfIt = workPFCands.cbegin();
102  while (pfIt != workPFCands.cend()) {
103  // use the PF candidate pT if it is within the cone and optional dz cut for charged PF candidates
104  const auto workPFCand = *pfIt;
105  z0_t pfCandZ0 = 0;
106  if (workPFCand->hwId.charged()) {
107  pfCandZ0 = workPFCand->hwZ0();
108  }
109 
110  // calculate dz
111  ap_int<z0_t::width + 1> dz = z0 - pfCandZ0;
112  if (dz < 0) {
113  dz = -dz;
114  }
115 
116  if (workPFCand->intCharge() == 0 || (workPFCand->intCharge() != 0 && dz < config_.dZMax_)) {
117  const auto dR2 = dr2_int(l1EG.hwEta, l1EG.hwPhi, workPFCand->hwEta, workPFCand->hwPhi);
118  if (dR2 >= config_.dRMin2_ && dR2 < config_.dRMax2_ && workPFCand->hwPt >= config_.ptMin_) {
119  sumPt += workPFCand->hwPt;
120  // remove the candidate from the collection if the module is configured to not reuse them
121  if (!config_.pfCandReuse_) {
122  // this returns an iterator to the next element already so no need to increase here
123  pfIt = workPFCands.erase(pfIt);
124  continue;
125  }
126  }
127  }
128  ++pfIt;
129  }
130 
131  return sumPt;
132 }
std::vector< EGIsoEleObjEmu > EGIsoEleObjsEmu
int dr2_int(eta_t eta1, phi_t phi1, eta_t eta2, phi_t phi2)
Definition: datatypes.h:220
const L1EGPuppiIsoAlgoConfig config_
std::vector< PuppiObj > PuppiObjs
ALPAKA_FN_ACC static ALPAKA_FN_INLINE float dR2(Position4 pos1, Position4 pos2)
ap_ufixed< 11, 9, AP_TRN, AP_SAT > iso_t
Definition: datatypes.h:40
ap_int< 10 > z0_t
Definition: datatypes.h:21
L1EGPuppiIsoAlgo(const L1EGPuppiIsoAlgoConfig &config)
std::vector< EGIsoObjEmu > EGIsoObjsEmu
ap_int< z0_t::width+1 > dZMax_
void run(const EGIsoObjsEmu &l1EGs, const PuppiObjs &l1PFCands, EGIsoObjsEmu &outL1EGs, z0_t z0=0) const
iso_t calcIso(const EGIsoObj &l1EG, std::list< const PuppiObj *> &workPFCands, z0_t z0=0) const
Definition: datatypes.h:8