forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cms-sw#94 from thomreis/l1phase2-l2ct-eg-puppi-iso…
…-integration-p2l1pfp-1230pre4 Add PUPPI isolation to CT L2 EG emulator
- Loading branch information
Showing
5 changed files
with
250 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
L1Trigger/Phase2L1ParticleFlow/interface/egamma/L1EGPuppiIsoAlgo.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef L1Trigger_Phase2L1ParticleFlow_L1EGPuppiIsoAlgo_h | ||
#define L1Trigger_Phase2L1ParticleFlow_L1EGPuppiIsoAlgo_h | ||
|
||
#include <list> | ||
#include <string> | ||
#include <vector> | ||
#include <memory> | ||
|
||
#include "DataFormats/Math/interface/deltaR.h" | ||
#include "DataFormats/L1TParticleFlow/interface/datatypes.h" | ||
#include "DataFormats/L1TParticleFlow/interface/layer1_emulator.h" | ||
#include "DataFormats/L1TParticleFlow/interface/egamma.h" | ||
#include "DataFormats/L1TParticleFlow/interface/puppi.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
|
||
namespace l1ct { | ||
|
||
struct L1EGPuppiIsoAlgoConfig { | ||
enum { kPFIso, kPuppiIso }; | ||
|
||
int pfIsoType_; | ||
pt_t ptMin_; | ||
ap_int<z0_t::width + 1> dZMax_; | ||
int dRMin2_; | ||
int dRMax2_; | ||
bool pfCandReuse_; | ||
|
||
L1EGPuppiIsoAlgoConfig(const std::string& pfIsoTypeStr, | ||
const float ptMin, | ||
const float dZMax, | ||
const float dRMin, | ||
const float dRMax, | ||
const bool pfCandReuse) | ||
: pfIsoType_(pfIsoTypeStr == "PF" ? kPFIso : kPuppiIso), | ||
ptMin_(Scales::makePtFromFloat(ptMin)), | ||
dZMax_(Scales::makeZ0(dZMax)), | ||
dRMin2_(Scales::makeDR2FromFloatDR(dRMin)), | ||
dRMax2_(Scales::makeDR2FromFloatDR(dRMax)), | ||
pfCandReuse_(pfCandReuse) {} | ||
}; | ||
|
||
typedef std::vector<EGIsoObjEmu> EGIsoObjsEmu; | ||
typedef std::vector<EGIsoEleObjEmu> EGIsoEleObjsEmu; | ||
typedef std::vector<PuppiObj> PuppiObjs; | ||
|
||
class L1EGPuppiIsoAlgo { | ||
public: | ||
L1EGPuppiIsoAlgo(const L1EGPuppiIsoAlgoConfig& config) : config_(config) {} | ||
L1EGPuppiIsoAlgo(const edm::ParameterSet& pSet); | ||
virtual ~L1EGPuppiIsoAlgo() = default; | ||
|
||
void run(const EGIsoObjsEmu& l1EGs, const PuppiObjs& l1PFCands, EGIsoObjsEmu& outL1EGs, z0_t z0 = 0) const; | ||
void run(EGIsoObjsEmu& l1EGs, const PuppiObjs& l1PFCands, z0_t z0 = 0) const; | ||
void run(EGIsoEleObjsEmu& l1Eles, const PuppiObjs& l1PFCands) const; | ||
|
||
private: | ||
iso_t calcIso(const EGIsoObj& l1EG, std::list<const PuppiObj*>& workPFCands, z0_t z0 = 0) const; | ||
|
||
const L1EGPuppiIsoAlgoConfig config_; | ||
}; | ||
|
||
} // namespace l1ct | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
L1Trigger/Phase2L1ParticleFlow/src/egamma/L1EGPuppiIsoAlgo.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#include "L1Trigger/Phase2L1ParticleFlow/interface/egamma/L1EGPuppiIsoAlgo.h" | ||
|
||
using namespace l1ct; | ||
|
||
L1EGPuppiIsoAlgo::L1EGPuppiIsoAlgo(const edm::ParameterSet& pSet) | ||
: config_(pSet.getParameter<std::string>("pfIsoType"), | ||
pSet.getParameter<double>("pfPtMin"), | ||
pSet.getParameter<double>("dZ"), | ||
pSet.getParameter<double>("dRMin"), | ||
pSet.getParameter<double>("dRMax"), | ||
pSet.getParameter<bool>("pfCandReuse")) {} | ||
|
||
void L1EGPuppiIsoAlgo::run(const EGIsoObjsEmu& l1EGs, | ||
const PuppiObjs& l1PFCands, | ||
EGIsoObjsEmu& outL1EGs, | ||
z0_t z0) const { | ||
outL1EGs.reserve(l1EGs.size()); | ||
|
||
// make a list of pointers to PF candidates | ||
// the pointer will be removed from the list once the candidate has been used and the the module is configured to to so | ||
std::list<const PuppiObj*> workPFCands; | ||
std::list<const PuppiObj*> workPFCandsPV; | ||
for (const auto& l1PFCand : l1PFCands) { | ||
workPFCands.emplace_back(&l1PFCand); | ||
workPFCandsPV.emplace_back(&l1PFCand); | ||
} | ||
|
||
for (const auto& l1EG : l1EGs) { | ||
auto outL1EG(l1EG); | ||
iso_t iso = 0; | ||
iso_t isoPV = 0; | ||
if (!workPFCands.empty()) { | ||
iso = calcIso(l1EG, workPFCands); | ||
isoPV = calcIso(l1EG, workPFCandsPV, z0); | ||
} | ||
|
||
if (config_.pfIsoType_ == L1EGPuppiIsoAlgoConfig::kPFIso) { | ||
outL1EG.setHwIso(EGIsoObjEmu::IsoType::PfIso, iso); | ||
outL1EG.setHwIso(EGIsoObjEmu::IsoType::PfIsoPV, isoPV); | ||
} else { | ||
outL1EG.setHwIso(EGIsoObjEmu::IsoType::PuppiIso, iso); | ||
outL1EG.setHwIso(EGIsoObjEmu::IsoType::PuppiIsoPV, isoPV); | ||
} | ||
outL1EGs.emplace_back(outL1EG); | ||
} | ||
} | ||
|
||
void L1EGPuppiIsoAlgo::run(EGIsoObjsEmu& l1EGs, const PuppiObjs& l1PFCands, z0_t z0) const { | ||
// make a list of pointers to PF candidates | ||
// the pointer will be removed from the list once the candidate has been used and the the module is configured to to so | ||
std::list<const PuppiObj*> workPFCands; | ||
std::list<const PuppiObj*> workPFCandsPV; | ||
for (const auto& l1PFCand : l1PFCands) { | ||
workPFCands.emplace_back(&l1PFCand); | ||
workPFCandsPV.emplace_back(&l1PFCand); | ||
} | ||
|
||
for (auto& l1EG : l1EGs) { | ||
iso_t iso = 0; | ||
iso_t isoPV = 0; | ||
if (!workPFCands.empty()) { | ||
iso = calcIso(l1EG, workPFCands); | ||
isoPV = calcIso(l1EG, workPFCandsPV, z0); | ||
} | ||
|
||
if (config_.pfIsoType_ == L1EGPuppiIsoAlgoConfig::kPFIso) { | ||
l1EG.setHwIso(EGIsoObjEmu::IsoType::PfIso, iso); | ||
l1EG.setHwIso(EGIsoObjEmu::IsoType::PfIsoPV, isoPV); | ||
} else { | ||
l1EG.setHwIso(EGIsoObjEmu::IsoType::PuppiIso, iso); | ||
l1EG.setHwIso(EGIsoObjEmu::IsoType::PuppiIsoPV, isoPV); | ||
} | ||
} | ||
} | ||
|
||
void L1EGPuppiIsoAlgo::run(EGIsoEleObjsEmu& l1Eles, const PuppiObjs& l1PFCands) const { | ||
// make a list of pointers to PF candidates | ||
// the pointer will be removed from the list once the candidate has been used and the the module is configured to to so | ||
std::list<const PuppiObj*> workPFCands; | ||
for (const auto& l1PFCand : l1PFCands) { | ||
workPFCands.emplace_back(&l1PFCand); | ||
} | ||
|
||
for (auto& l1Ele : l1Eles) { | ||
iso_t iso = 0; | ||
if (!workPFCands.empty()) { | ||
iso = calcIso(l1Ele, workPFCands); | ||
} | ||
|
||
if (config_.pfIsoType_ == L1EGPuppiIsoAlgoConfig::kPFIso) { | ||
l1Ele.setHwIso(EGIsoEleObjEmu::IsoType::PfIso, iso); | ||
} else { | ||
l1Ele.setHwIso(EGIsoEleObjEmu::IsoType::PuppiIso, iso); | ||
} | ||
} | ||
} | ||
|
||
iso_t L1EGPuppiIsoAlgo::calcIso(const EGIsoObj& l1EG, std::list<const PuppiObj*>& workPFCands, z0_t z0) const { | ||
iso_t sumPt = 0; | ||
|
||
auto pfIt = workPFCands.cbegin(); | ||
while (pfIt != workPFCands.cend()) { | ||
// use the PF candidate pT if it is within the cone and optional dz cut for charged PF candidates | ||
const auto workPFCand = *pfIt; | ||
z0_t pfCandZ0 = 0; | ||
if (workPFCand->hwId.charged()) { | ||
pfCandZ0 = workPFCand->hwZ0(); | ||
} | ||
|
||
// calculate dz | ||
ap_int<z0_t::width + 1> dz = z0 - pfCandZ0; | ||
if (dz < 0) { | ||
dz = -dz; | ||
} | ||
|
||
if (workPFCand->intCharge() == 0 || (workPFCand->intCharge() != 0 && dz < config_.dZMax_)) { | ||
const auto dR2 = dr2_int(l1EG.hwEta, l1EG.hwPhi, workPFCand->hwEta, workPFCand->hwPhi); | ||
if (dR2 >= config_.dRMin2_ && dR2 < config_.dRMax2_ && workPFCand->hwPt >= config_.ptMin_) { | ||
sumPt += workPFCand->hwPt; | ||
// remove the candidate from the collection if the module is configured to not reuse them | ||
if (!config_.pfCandReuse_) { | ||
// this returns an iterator to the next element already so no need to increase here | ||
pfIt = workPFCands.erase(pfIt); | ||
continue; | ||
} | ||
} | ||
} | ||
++pfIt; | ||
} | ||
|
||
return sumPt; | ||
} |