Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-10-01 01:02:14

0001 #include "L1Trigger/Phase2L1ParticleFlow/interface/pf/pfalgo_common_ref.h"
0002 #include "L1Trigger/Phase2L1ParticleFlow/interface/dbgPrintf.h"
0003 
0004 #include <cmath>
0005 #include <cstdio>
0006 
0007 #ifdef CMSSW_GIT_HASH
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #endif
0010 
0011 l1ct::PFAlgoEmulatorBase::~PFAlgoEmulatorBase() {}
0012 
0013 void l1ct::PFAlgoEmulatorBase::loadPtErrBins(
0014     unsigned int nbins, const float absetas[], const float scales[], const float offs[], bool verbose) {
0015   ptErrBins_.resize(nbins);
0016   for (unsigned int i = 0; i < nbins; ++i) {
0017     ptErrBins_[i].abseta = Scales::makeGlbEta(absetas[i]);
0018     ptErrBins_[i].scale = scales[i];
0019     ptErrBins_[i].offs = offs[i];
0020 
0021     if (verbose || debug_)
0022       dbgPrintf("loadPtErrBins: #%d: abseta %5.3f -> %8d, scale %7.4f -> %7.4f, offs %7.3f -> %7.4f\n",
0023                 i,
0024                 absetas[i],
0025                 ptErrBins_[i].abseta.to_int(),
0026                 scales[i],
0027                 ptErrBins_[i].scale.to_float(),
0028                 offs[i],
0029                 ptErrBins_[i].offs.to_float());
0030   }
0031 }
0032 
0033 #ifdef CMSSW_GIT_HASH
0034 void l1ct::PFAlgoEmulatorBase::loadPtErrBins(const edm::ParameterSet &iConfig) {
0035   const edm::ParameterSet &resol = iConfig.getParameter<edm::ParameterSet>("caloResolution");
0036   std::vector<float> absetas, scales, offs;
0037   for (auto &v : resol.getParameter<std::vector<double>>("etaBins"))
0038     absetas.push_back(v);
0039   for (auto &v : resol.getParameter<std::vector<double>>("scale"))
0040     scales.push_back(v);
0041   for (auto &v : resol.getParameter<std::vector<double>>("offset"))
0042     offs.push_back(v);
0043   loadPtErrBins(absetas.size(), &absetas[0], &scales[0], &offs[0]);
0044 }
0045 
0046 #endif
0047 
0048 l1ct::pt_t l1ct::PFAlgoEmulatorBase::ptErr_ref(const l1ct::PFRegionEmu &region, const l1ct::TkObjEmu &track) const {
0049   glbeta_t abseta = region.hwGlbEta(track.hwEta);
0050   if (abseta < 0)
0051     abseta = -abseta;
0052 
0053   ptErrScale_t scale = 0.3125;
0054   ptErrOffs_t offs = 7.0;
0055   for (const auto &bin : ptErrBins_) {
0056     if (abseta < bin.abseta) {
0057       scale = bin.scale;
0058       offs = bin.offs;
0059       break;
0060     }
0061   }
0062 
0063   pt_t ptErr = track.hwPt * scale + offs;
0064   if (ptErr > track.hwPt)
0065     ptErr = track.hwPt;
0066   return ptErr;
0067 }
0068 
0069 void l1ct::PFAlgoEmulatorBase::pfalgo_mu_ref(const PFInputRegion &in, OutputRegion &out, std::vector<int> &iMu) const {
0070   // init
0071   unsigned int nTRACK = std::min<unsigned>(nTRACK_, in.track.size());
0072   unsigned int nMU = std::min<unsigned>(nMU_, in.muon.size());
0073   out.pfmuon.resize(nMU);
0074   iMu.resize(nTRACK);
0075   for (unsigned int ipf = 0; ipf < nMU; ++ipf)
0076     out.pfmuon[ipf].clear();
0077   for (unsigned int it = 0; it < nTRACK; ++it)
0078     iMu[it] = -1;
0079 
0080   // for each muon, find the closest track
0081   for (unsigned int im = 0; im < nMU; ++im) {
0082     if (in.muon[im].hwPt > 0) {
0083       int ibest = -1;
0084       pt_t dptmin = (in.muon[im].hwPt << 1) + in.muon[im].hwPt;
0085       for (unsigned int it = 0; it < nTRACK; ++it) {
0086         if (!in.track[it].isPFLoose())
0087           continue;
0088         unsigned int dr = dr2_int(in.muon[im].hwEta, in.muon[im].hwPhi, in.track[it].hwEta, in.track[it].hwPhi);
0089         //dbgPrintf("deltaR2(mu %d float pt %5.1f, tk %2d float pt %5.1f) = int %d  (float deltaR = %.3f); int cut at %d\n", im, 0.25*int(in.muon[im].hwPt), it, 0.25*int(in.track[it].hwPt), dr, std::sqrt(float(dr))/229.2, dR2MAX_TK_MU_);
0090         if (dr < dR2MAX_TK_MU_) {
0091           dpt_t dpt = (dpt_t(in.track[it].hwPt) - dpt_t(in.muon[im].hwPt));
0092           pt_t absdpt = dpt >= 0 ? pt_t(dpt) : pt_t(-dpt);
0093           if (absdpt < dptmin) {
0094             dptmin = absdpt;
0095             ibest = it;
0096           }
0097         }
0098       }
0099       if (ibest != -1) {
0100         iMu[ibest] = im;
0101         fillPFCand(in.track[ibest], out.pfmuon[im], /*isMu=*/true, /*isEle=*/false);
0102         // extra emulator info
0103         out.pfmuon[im].srcMu = in.muon[im].src;
0104         if (debug_)
0105           dbgPrintf("FW  \t muon %3d linked to track %3d \n", im, ibest);
0106       } else {
0107         if (debug_)
0108           dbgPrintf("FW  \t muon %3d not linked to any track\n", im);
0109       }
0110     }
0111   }
0112 }
0113 
0114 void l1ct::PFAlgoEmulatorBase::fillPFCand(const TkObjEmu &track, PFChargedObjEmu &pf, bool isMu, bool isEle) const {
0115   assert(!(isEle && isMu));
0116   pf.hwPt = track.hwPt;
0117   pf.hwEta = track.hwEta;
0118   pf.hwPhi = track.hwPhi;
0119   pf.hwDEta = track.hwDEta;
0120   pf.hwDPhi = track.hwDPhi;
0121   pf.hwZ0 = track.hwZ0;
0122   pf.hwDxy = track.hwDxy;
0123   pf.hwTkQuality = track.hwQuality;
0124   if (isMu) {
0125     pf.hwId = ParticleID::mkMuon(track.hwCharge);
0126   } else if (isEle) {
0127     pf.hwId = ParticleID::mkElectron(track.hwCharge);
0128   } else {
0129     pf.hwId = ParticleID::mkChHad(track.hwCharge);
0130   }
0131   // extra emulator information
0132   pf.srcTrack = track.src;
0133 }
0134 
0135 void l1ct::PFAlgoEmulatorBase::fillPFCand(const HadCaloObjEmu &calo, PFNeutralObjEmu &pf, bool isPhoton) const {
0136   pf.hwPt = calo.hwPt;
0137   pf.hwEta = calo.hwEta;
0138   pf.hwPhi = calo.hwPhi;
0139   pf.hwId = isPhoton ? ParticleID::PHOTON : ParticleID::HADZERO;
0140   pf.hwEmPt = calo.hwEmPt;  // FIXME
0141   pf.hwEmID = calo.hwEmID;
0142   pf.hwPUID = 0;
0143   // extra emulator information
0144   pf.srcCluster = calo.src;
0145 }
0146 
0147 void l1ct::PFAlgoEmulatorBase::fillPFCand(const EmCaloObjEmu &calo, PFNeutralObjEmu &pf, bool isPhoton) const {
0148   pf.hwPt = calo.hwPt;
0149   pf.hwEta = calo.hwEta;
0150   pf.hwPhi = calo.hwPhi;
0151   pf.hwId = isPhoton ? ParticleID::PHOTON : ParticleID::HADZERO;
0152   pf.hwEmPt = calo.hwPt;
0153   pf.hwEmID = calo.hwEmID;
0154   pf.hwPUID = 0;
0155   // more emulator info
0156   pf.srcCluster = calo.src;
0157 }