Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "L1Trigger/Phase2L1ParticleFlow/interface/regionizer/folded_multififo_regionizer_ref.h"
0002 
0003 #include <iostream>
0004 #include <memory>
0005 
0006 l1ct::FoldedMultififoRegionizerEmulator::FoldedMultififoRegionizerEmulator(unsigned int nclocks,
0007                                                                            unsigned int ntklinks,
0008                                                                            unsigned int ncalolinks,
0009                                                                            unsigned int ntk,
0010                                                                            unsigned int ncalo,
0011                                                                            unsigned int nem,
0012                                                                            unsigned int nmu,
0013                                                                            bool streaming,
0014                                                                            unsigned int outii,
0015                                                                            unsigned int pauseii,
0016                                                                            bool useAlsoVtxCoords)
0017     : RegionizerEmulator(useAlsoVtxCoords),
0018       NTK_SECTORS(9),
0019       NCALO_SECTORS(3),
0020       NTK_LINKS(ntklinks),
0021       NCALO_LINKS(ncalolinks),
0022       HCAL_LINKS(0),
0023       ECAL_LINKS(0),
0024       NMU_LINKS(1),
0025       nclocks_(nclocks),
0026       ntk_(ntk),
0027       ncalo_(ncalo),
0028       nem_(nem),
0029       nmu_(nmu),
0030       outii_(outii),
0031       pauseii_(pauseii),
0032       streaming_(streaming),
0033       foldMode_(FoldMode::EndcapEta2),
0034       init_(false) {
0035   // now we initialize the routes: track finder
0036   for (unsigned int ie = 0; ie < 2; ++ie) {
0037     fold_.emplace_back(ie,
0038                        std::make_unique<l1ct::MultififoRegionizerEmulator>(
0039                            /*nendcaps=*/1,
0040                            nclocks / 2,
0041                            NTK_LINKS,
0042                            NCALO_LINKS,
0043                            ntk,
0044                            ncalo,
0045                            nem,
0046                            nmu,
0047                            streaming,
0048                            outii,
0049                            pauseii,
0050                            useAlsoVtxCoords));
0051   }
0052   clocksPerFold_ = nclocks / 2;
0053 }
0054 
0055 l1ct::FoldedMultififoRegionizerEmulator::~FoldedMultififoRegionizerEmulator() {}
0056 
0057 void l1ct::FoldedMultififoRegionizerEmulator::setEgInterceptMode(
0058     bool afterFifo, const l1ct::EGInputSelectorEmuConfig& interceptorConfig) {
0059   for (auto& f : fold_)
0060     f.regionizer->setEgInterceptMode(afterFifo, interceptorConfig);
0061 }
0062 
0063 void l1ct::FoldedMultififoRegionizerEmulator::splitSectors(const RegionizerDecodedInputs& in) {
0064   for (auto& f : fold_) {
0065     f.sectors.track.clear();
0066     f.sectors.hadcalo.clear();
0067     f.sectors.emcalo.clear();
0068   }
0069   for (const auto& src : in.track) {
0070     for (auto& f : fold_) {
0071       if (inFold(src.region, f))
0072         f.sectors.track.emplace_back(src);
0073     }
0074   }
0075   for (const auto& src : in.hadcalo) {
0076     for (auto& f : fold_) {
0077       if (inFold(src.region, f))
0078         f.sectors.hadcalo.emplace_back(src);
0079     }
0080   }
0081   for (const auto& src : in.emcalo) {
0082     for (auto& f : fold_) {
0083       if (inFold(src.region, f))
0084         f.sectors.emcalo.emplace_back(src);
0085     }
0086   }
0087   for (auto& f : fold_)
0088     f.sectors.muon = in.muon;
0089 }
0090 
0091 void l1ct::FoldedMultififoRegionizerEmulator::splitRegions(const std::vector<PFInputRegion>& out) {
0092   for (auto& f : fold_) {
0093     f.regions.clear();
0094   }
0095   for (const auto& o : out) {
0096     fold_[whichFold(o.region)].regions.push_back(o);
0097   }
0098 }
0099 
0100 void l1ct::FoldedMultififoRegionizerEmulator::initSectorsAndRegions(const RegionizerDecodedInputs& in,
0101                                                                     const std::vector<PFInputRegion>& out) {
0102   assert(!init_);
0103   init_ = true;
0104   splitSectors(in);
0105   splitRegions(out);
0106   for (auto& f : fold_) {
0107     f.regionizer->initSectorsAndRegions(f.sectors, f.regions);
0108   }
0109   nregions_ = out.size();
0110 }
0111 
0112 bool l1ct::FoldedMultififoRegionizerEmulator::step(bool newEvent,
0113                                                    const std::vector<l1ct::TkObjEmu>& links_tk,
0114                                                    const std::vector<l1ct::HadCaloObjEmu>& links_hadCalo,
0115                                                    const std::vector<l1ct::EmCaloObjEmu>& links_emCalo,
0116                                                    const std::vector<l1ct::MuObjEmu>& links_mu,
0117                                                    std::vector<l1ct::TkObjEmu>& out_tk,
0118                                                    std::vector<l1ct::HadCaloObjEmu>& out_hadCalo,
0119                                                    std::vector<l1ct::EmCaloObjEmu>& out_emCalo,
0120                                                    std::vector<l1ct::MuObjEmu>& out_mu,
0121                                                    bool mux) {
0122   iclock_ = (newEvent ? 0 : iclock_ + 1);
0123   bool newSubEvent = iclock_ % clocksPerFold_ == 0;
0124   bool ret = false;
0125   if (!mux) {
0126     Fold& f = fold_[whichFold(iclock_)];
0127     ret = f.regionizer->step(
0128         newSubEvent, links_tk, links_hadCalo, links_emCalo, links_mu, out_tk, out_hadCalo, out_emCalo, out_mu, false);
0129   } else {
0130     unsigned int inputFold = whichFold(iclock_);
0131     unsigned int outputFold = (inputFold + 1) % fold_.size();  // to be seen if this is general or not
0132     std::vector<l1ct::TkObjEmu> nolinks_tk(links_tk.size());
0133     std::vector<l1ct::HadCaloObjEmu> nolinks_hadCalo(links_hadCalo.size());
0134     std::vector<l1ct::EmCaloObjEmu> nolinks_emCalo(links_emCalo.size());
0135     std::vector<l1ct::MuObjEmu> nolinks_mu(links_mu.size());
0136     std::vector<l1ct::TkObjEmu> noout_tk;
0137     std::vector<l1ct::HadCaloObjEmu> noout_hadCalo;
0138     std::vector<l1ct::EmCaloObjEmu> noout_emCalo;
0139     std::vector<l1ct::MuObjEmu> noout_mu;
0140     for (auto& f : fold_) {
0141       bool fret = f.regionizer->step(newSubEvent,
0142                                      f.index == inputFold ? links_tk : nolinks_tk,
0143                                      f.index == inputFold ? links_hadCalo : nolinks_hadCalo,
0144                                      f.index == inputFold ? links_emCalo : nolinks_emCalo,
0145                                      f.index == inputFold ? links_mu : nolinks_mu,
0146                                      f.index == outputFold ? out_tk : noout_tk,
0147                                      f.index == outputFold ? out_hadCalo : noout_hadCalo,
0148                                      f.index == outputFold ? out_emCalo : noout_emCalo,
0149                                      f.index == outputFold ? out_mu : noout_mu,
0150                                      true);
0151       if (f.index == outputFold)
0152         ret = fret;
0153     }
0154   }
0155   return ret;
0156 }
0157 
0158 void l1ct::FoldedMultififoRegionizerEmulator::fillEvent(const l1ct::RegionizerDecodedInputs& in) {
0159   splitSectors(in);
0160   for (auto& f : fold_) {
0161     for (auto& o : f.regions) {
0162       o.clear();
0163     }
0164   }
0165 }
0166 
0167 unsigned int l1ct::FoldedMultififoRegionizerEmulator::whichFold(const l1ct::PFRegion& reg) {
0168   switch (foldMode_) {
0169     case FoldMode::EndcapEta2:
0170       return (reg.floatEtaCenter() >= 0);
0171   }
0172   assert(false);
0173   return 0;
0174 }
0175 bool l1ct::FoldedMultififoRegionizerEmulator::inFold(const l1ct::PFRegion& reg, const Fold& fold) {
0176   switch (foldMode_) {
0177     case FoldMode::EndcapEta2:
0178       return int(reg.floatEtaCenter() >= 0) == int(fold.index);
0179   }
0180   assert(false);
0181   return false;
0182 }
0183 
0184 void l1ct::FoldedMultififoRegionizerEmulator::run(const RegionizerDecodedInputs& in, std::vector<PFInputRegion>& out) {
0185   if (!init_)
0186     initSectorsAndRegions(in, out);
0187   else {
0188     fillEvent(in);
0189     for (auto& f : fold_)
0190       f.regionizer->reset();
0191   }
0192 
0193   std::vector<l1ct::TkObjEmu> tk_links_in, tk_out;
0194   std::vector<l1ct::EmCaloObjEmu> em_links_in, em_out;
0195   std::vector<l1ct::HadCaloObjEmu> calo_links_in, calo_out;
0196   std::vector<l1ct::MuObjEmu> mu_links_in, mu_out;
0197 
0198   std::vector<bool> unused;
0199   for (unsigned int iclock = 0; iclock < 2 * nclocks_; ++iclock) {
0200     if (iclock < nclocks_) {
0201       fillLinks(iclock, tk_links_in, unused);
0202       fillLinks(iclock, em_links_in, unused);
0203       fillLinks(iclock, calo_links_in, unused);
0204       fillLinks(iclock, mu_links_in, unused);
0205     } else {
0206       // set up an empty event
0207       for (auto& l : tk_links_in)
0208         l.clear();
0209       for (auto& l : em_links_in)
0210         l.clear();
0211       for (auto& l : calo_links_in)
0212         l.clear();
0213       for (auto& l : mu_links_in)
0214         l.clear();
0215     }
0216 
0217     bool newevt = (iclock % nclocks_) == 0, mux = true;
0218     step(newevt, tk_links_in, calo_links_in, em_links_in, mu_links_in, tk_out, calo_out, em_out, mu_out, mux);
0219 
0220     if (iclock >= nclocks_ / 2) {
0221       unsigned int ireg = ((iclock - nclocks_ / 2) / (outii_ + pauseii_));
0222       if (((iclock - nclocks_ / 2) % (outii_ + pauseii_)) >= outii_)
0223         continue;
0224       if (ireg >= nregions_)
0225         break;
0226 
0227       if (streaming_) {
0228         Fold& f = fold_[whichFold(iclock)];
0229         f.regionizer->destream(iclock % clocksPerFold_, tk_out, em_out, calo_out, mu_out, out[ireg]);
0230       } else {
0231         if ((iclock - nclocks_ / 2) % (outii_ + pauseii_) == 0) {
0232           out[ireg].track = tk_out;
0233           out[ireg].emcalo = em_out;
0234           out[ireg].hadcalo = calo_out;
0235           out[ireg].muon = mu_out;
0236         }
0237       }
0238     }
0239   }
0240 
0241   for (auto& f : fold_)
0242     f.regionizer->reset();
0243 }