Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:31

0001 #include "L1Trigger/Phase2L1ParticleFlow/interface/egamma/L1EGPuppiIsoAlgo.h"
0002 
0003 using namespace l1ct;
0004 
0005 L1EGPuppiIsoAlgo::L1EGPuppiIsoAlgo(const edm::ParameterSet& pSet)
0006     : config_(pSet.getParameter<std::string>("pfIsoType"),
0007               pSet.getParameter<double>("pfPtMin"),
0008               pSet.getParameter<double>("dZ"),
0009               pSet.getParameter<double>("dRMin"),
0010               pSet.getParameter<double>("dRMax"),
0011               pSet.getParameter<bool>("pfCandReuse")) {}
0012 
0013 void L1EGPuppiIsoAlgo::run(const EGIsoObjsEmu& l1EGs,
0014                            const PuppiObjs& l1PFCands,
0015                            EGIsoObjsEmu& outL1EGs,
0016                            z0_t z0) const {
0017   outL1EGs.reserve(l1EGs.size());
0018 
0019   // make a list of pointers to PF candidates
0020   // the pointer will be removed from the list once the candidate has been used and the the module is configured to to so
0021   std::list<const PuppiObj*> workPFCands;
0022   std::list<const PuppiObj*> workPFCandsPV;
0023   for (const auto& l1PFCand : l1PFCands) {
0024     workPFCands.emplace_back(&l1PFCand);
0025     workPFCandsPV.emplace_back(&l1PFCand);
0026   }
0027 
0028   for (const auto& l1EG : l1EGs) {
0029     auto outL1EG(l1EG);
0030     iso_t iso = 0;
0031     iso_t isoPV = 0;
0032     if (!workPFCands.empty()) {
0033       iso = calcIso(l1EG, workPFCands);
0034       isoPV = calcIso(l1EG, workPFCandsPV, z0);
0035     }
0036 
0037     if (config_.pfIsoType_ == L1EGPuppiIsoAlgoConfig::kPFIso) {
0038       outL1EG.setHwIso(EGIsoObjEmu::IsoType::PfIso, iso);
0039       outL1EG.setHwIso(EGIsoObjEmu::IsoType::PfIsoPV, isoPV);
0040     } else {
0041       outL1EG.setHwIso(EGIsoObjEmu::IsoType::PuppiIso, iso);
0042       outL1EG.setHwIso(EGIsoObjEmu::IsoType::PuppiIsoPV, isoPV);
0043     }
0044     outL1EGs.emplace_back(outL1EG);
0045   }
0046 }
0047 
0048 void L1EGPuppiIsoAlgo::run(EGIsoObjsEmu& l1EGs, const PuppiObjs& l1PFCands, z0_t z0) const {
0049   // make a list of pointers to PF candidates
0050   // the pointer will be removed from the list once the candidate has been used and the the module is configured to to so
0051   std::list<const PuppiObj*> workPFCands;
0052   std::list<const PuppiObj*> workPFCandsPV;
0053   for (const auto& l1PFCand : l1PFCands) {
0054     workPFCands.emplace_back(&l1PFCand);
0055     workPFCandsPV.emplace_back(&l1PFCand);
0056   }
0057 
0058   for (auto& l1EG : l1EGs) {
0059     iso_t iso = 0;
0060     iso_t isoPV = 0;
0061     if (!workPFCands.empty()) {
0062       iso = calcIso(l1EG, workPFCands);
0063       isoPV = calcIso(l1EG, workPFCandsPV, z0);
0064     }
0065 
0066     if (config_.pfIsoType_ == L1EGPuppiIsoAlgoConfig::kPFIso) {
0067       l1EG.setHwIso(EGIsoObjEmu::IsoType::PfIso, iso);
0068       l1EG.setHwIso(EGIsoObjEmu::IsoType::PfIsoPV, isoPV);
0069     } else {
0070       l1EG.setHwIso(EGIsoObjEmu::IsoType::PuppiIso, iso);
0071       l1EG.setHwIso(EGIsoObjEmu::IsoType::PuppiIsoPV, isoPV);
0072     }
0073   }
0074 }
0075 
0076 void L1EGPuppiIsoAlgo::run(EGIsoEleObjsEmu& l1Eles, const PuppiObjs& l1PFCands) const {
0077   // make a list of pointers to PF candidates
0078   // the pointer will be removed from the list once the candidate has been used and the the module is configured to to so
0079   std::list<const PuppiObj*> workPFCands;
0080   for (const auto& l1PFCand : l1PFCands) {
0081     workPFCands.emplace_back(&l1PFCand);
0082   }
0083 
0084   for (auto& l1Ele : l1Eles) {
0085     iso_t iso = 0;
0086     if (!workPFCands.empty()) {
0087       iso = calcIso(l1Ele, workPFCands);
0088     }
0089 
0090     if (config_.pfIsoType_ == L1EGPuppiIsoAlgoConfig::kPFIso) {
0091       l1Ele.setHwIso(EGIsoEleObjEmu::IsoType::PfIso, iso);
0092     } else {
0093       l1Ele.setHwIso(EGIsoEleObjEmu::IsoType::PuppiIso, iso);
0094     }
0095   }
0096 }
0097 
0098 iso_t L1EGPuppiIsoAlgo::calcIso(const EGIsoObj& l1EG, std::list<const PuppiObj*>& workPFCands, z0_t z0) const {
0099   iso_t sumPt = 0;
0100 
0101   auto pfIt = workPFCands.cbegin();
0102   while (pfIt != workPFCands.cend()) {
0103     // use the PF candidate pT if it is within the cone and optional dz cut for charged PF candidates
0104     const auto workPFCand = *pfIt;
0105     z0_t pfCandZ0 = 0;
0106     if (workPFCand->hwId.charged()) {
0107       pfCandZ0 = workPFCand->hwZ0();
0108     }
0109 
0110     // calculate dz
0111     ap_int<z0_t::width + 1> dz = z0 - pfCandZ0;
0112     if (dz < 0) {
0113       dz = -dz;
0114     }
0115 
0116     if (workPFCand->intCharge() == 0 || (workPFCand->intCharge() != 0 && dz < config_.dZMax_)) {
0117       const auto dR2 = dr2_int(l1EG.hwEta, l1EG.hwPhi, workPFCand->hwEta, workPFCand->hwPhi);
0118       if (dR2 >= config_.dRMin2_ && dR2 < config_.dRMax2_ && workPFCand->hwPt >= config_.ptMin_) {
0119         sumPt += workPFCand->hwPt;
0120         // remove the candidate from the collection if the module is configured to not reuse them
0121         if (!config_.pfCandReuse_) {
0122           // this returns an iterator to the next element already so no need to increase here
0123           pfIt = workPFCands.erase(pfIt);
0124           continue;
0125         }
0126       }
0127     }
0128     ++pfIt;
0129   }
0130 
0131   return sumPt;
0132 }