Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "L1Trigger/Phase2L1ParticleFlow/interface/deregionizer/deregionizer_ref.h"
0002 
0003 #include <cstdio>
0004 #include <vector>
0005 
0006 #include "L1Trigger/Phase2L1ParticleFlow/interface/dbgPrintf.h"
0007 
0008 #ifdef CMSSW_GIT_HASH
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 
0011 l1ct::DeregionizerEmulator::DeregionizerEmulator(const edm::ParameterSet &iConfig)
0012     : DeregionizerEmulator(iConfig.getParameter<uint32_t>("nPuppiFinalBuffer"),
0013                            iConfig.getParameter<uint32_t>("nPuppiPerClk"),
0014                            iConfig.getParameter<uint32_t>("nPuppiFirstBuffers"),
0015                            iConfig.getParameter<uint32_t>("nPuppiSecondBuffers"),
0016                            iConfig.getParameter<uint32_t>("nPuppiThirdBuffers")) {
0017   debug_ = iConfig.getUntrackedParameter<bool>("debug", false);
0018 }
0019 #endif
0020 
0021 l1ct::DeregionizerEmulator::DeregionizerEmulator(const unsigned int nPuppiFinalBuffer /*=128*/,
0022                                                  const unsigned int nPuppiPerClk /*=6*/,
0023                                                  const unsigned int nPuppiFirstBuffers /*=12*/,
0024                                                  const unsigned int nPuppiSecondBuffers /*=32*/,
0025                                                  const unsigned int nPuppiThirdBuffers /*=64*/)
0026     : nPuppiFinalBuffer_(nPuppiFinalBuffer),
0027       nPuppiPerClk_(nPuppiPerClk),
0028       nPuppiFirstBuffers_(nPuppiFirstBuffers),
0029       nPuppiSecondBuffers_(nPuppiSecondBuffers),
0030       nPuppiThirdBuffers_(nPuppiThirdBuffers),
0031       debug_(false) {
0032   assert(nPuppiPerClk < nPuppiFirstBuffers && nPuppiFirstBuffers < nPuppiSecondBuffers &&
0033          nPuppiSecondBuffers < nPuppiThirdBuffers && nPuppiThirdBuffers <= nPuppiFinalBuffer);
0034 }
0035 
0036 std::vector<l1ct::PuppiObjEmu> l1ct::DeregionizerEmulator::mergeXtoY(const unsigned int X,
0037                                                                      const unsigned int Y,
0038                                                                      const std::vector<l1ct::PuppiObjEmu> &inLeft,
0039                                                                      const std::vector<l1ct::PuppiObjEmu> &inRight) {
0040   // merge X to Y with truncation
0041   std::vector<l1ct::PuppiObjEmu> out;
0042 
0043   out.insert(out.end(), inLeft.begin(), std::min(inLeft.end(), inLeft.begin() + X));
0044   out.insert(out.end(), inRight.begin(), std::min(inRight.end(), inRight.begin() + Y - X));
0045 
0046   return out;
0047 }
0048 
0049 std::vector<l1ct::PuppiObjEmu> l1ct::DeregionizerEmulator::mergeXtoY(const std::vector<l1ct::PuppiObjEmu> &inLeft,
0050                                                                      const std::vector<l1ct::PuppiObjEmu> &inRight) {
0051   // merge X to Y with no truncation
0052   std::vector<l1ct::PuppiObjEmu> out;
0053 
0054   out.insert(out.end(), inLeft.begin(), inLeft.end());
0055   out.insert(out.end(), inRight.begin(), inRight.end());
0056 
0057   return out;
0058 }
0059 
0060 void l1ct::DeregionizerEmulator::accumulateToY(const unsigned int Y,
0061                                                const std::vector<l1ct::PuppiObjEmu> &in,
0062                                                std::vector<l1ct::PuppiObjEmu> &out,
0063                                                std::vector<l1ct::PuppiObjEmu> &truncated) {
0064   unsigned int initialOutSize = out.size();
0065   assert(initialOutSize <= Y);
0066   if (initialOutSize == Y) {
0067     truncated.insert(truncated.end(), in.begin(), in.end());
0068     return;
0069   }
0070   out.insert(out.end(), in.begin(), std::min(in.end(), in.begin() + Y - initialOutSize));
0071   if (out.size() == Y)
0072     truncated.insert(truncated.end(), in.begin() + Y - initialOutSize, in.end());
0073   return;
0074 }
0075 
0076 static void debugPrint(const std::string &header, const std::vector<l1ct::PuppiObjEmu> &pup) {
0077   dbgCout() << " --> " << header << "\n";
0078   for (unsigned int iPup = 0, nPup = pup.size(); iPup < nPup; ++iPup)
0079     dbgCout() << "      > puppi[" << iPup << "] pT = " << pup[iPup].hwPt << "\n";
0080 }
0081 
0082 void l1ct::DeregionizerEmulator::run(std::vector<std::vector<std::vector<l1ct::PuppiObjEmu>>> in,
0083                                      std::vector<l1ct::PuppiObjEmu> &out,
0084                                      std::vector<l1ct::PuppiObjEmu> &truncated) {
0085   for (int i = 0, n = in.size(); i < n; i++) {
0086     std::vector<std::vector<l1ct::PuppiObjEmu>> pupsOnClock = in[i];
0087     std::vector<l1ct::PuppiObjEmu> intermediateTruncated;
0088     // Merge PF regions from this cycle. No truncation happens here
0089     std::vector<l1ct::PuppiObjEmu> buffer;
0090     for (const auto &pupsOnClockOnBoard : pupsOnClock) {
0091       buffer = mergeXtoY(buffer, pupsOnClockOnBoard);
0092     }
0093 
0094     // accumulate PF regions over cycles, truncation may happen here
0095     accumulateToY(nPuppiFinalBuffer_, buffer, out, truncated);
0096   }
0097 
0098   if (debug_) {
0099     dbgCout() << "\n";
0100     debugPrint("FINAL ARRAY", out);
0101     dbgCout() << "\n";
0102     dbgCout() << "Ran successfully!"
0103               << "\n";
0104   }
0105 }