Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-10 01:53:59

0001 #include "L1Trigger/Phase2L1ParticleFlow/interface/regionizer/tdr_regionizer_ref.h"
0002 #include "L1Trigger/Phase2L1ParticleFlow/interface/regionizer/tdr_regionizer_elements_ref.icc"
0003 
0004 #include <iostream>
0005 
0006 #ifdef CMSSW_GIT_HASH
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 
0009 l1ct::TDRRegionizerEmulator::TDRRegionizerEmulator(const edm::ParameterSet& iConfig)
0010     : TDRRegionizerEmulator(
0011           /*netaslices=*/3,
0012           iConfig.getParameter<uint32_t>("nTrack"),
0013           iConfig.getParameter<uint32_t>("nCalo"),
0014           iConfig.getParameter<uint32_t>("nEmCalo"),
0015           iConfig.getParameter<uint32_t>("nMu"),
0016           iConfig.getParameter<int32_t>("nClocks"),
0017           iConfig.getParameter<bool>("doSort")) {
0018   debug_ = iConfig.getUntrackedParameter<bool>("debug", false);
0019 }
0020 #endif
0021 
0022 l1ct::TDRRegionizerEmulator::TDRRegionizerEmulator(unsigned int netaslices,
0023                                                    unsigned int ntk,
0024                                                    unsigned int ncalo,
0025                                                    unsigned int nem,
0026                                                    unsigned int nmu,
0027                                                    int nclocks,
0028                                                    bool dosort)
0029     : RegionizerEmulator(),
0030       netaslices_(netaslices),
0031       ntk_(ntk),
0032       ncalo_(ncalo),
0033       nem_(nem),
0034       nmu_(nmu),
0035       nclocks_(nclocks),
0036       dosort_(dosort),
0037       init_(false) {
0038   assert(netaslices == 3);             //the setup here only works for 3 barrel boards
0039   int etaoffsets[3] = {-228, 0, 228};  //this could be made generic perhaps, hardcoding for now
0040   for (unsigned int i = 0; i < netaslices_; i++) {
0041     tkRegionizers_.emplace_back(
0042         (unsigned int)NETA_SMALL, (unsigned int)NUMBER_OF_SMALL_REGIONS, ntk, etaoffsets[i], 115, nclocks);
0043     hadCaloRegionizers_.emplace_back(
0044         (unsigned int)NETA_SMALL, (unsigned int)NUMBER_OF_SMALL_REGIONS, ncalo, etaoffsets[i], 115, nclocks);
0045     emCaloRegionizers_.emplace_back(
0046         (unsigned int)NETA_SMALL, (unsigned int)NUMBER_OF_SMALL_REGIONS, nem, etaoffsets[i], 115, nclocks);
0047     muRegionizers_.emplace_back(
0048         (unsigned int)NETA_SMALL, (unsigned int)NUMBER_OF_SMALL_REGIONS, nmu, etaoffsets[i], 115, nclocks);
0049   }
0050 }
0051 
0052 l1ct::TDRRegionizerEmulator::~TDRRegionizerEmulator() {}
0053 
0054 void l1ct::TDRRegionizerEmulator::initSectorsAndRegions(const RegionizerDecodedInputs& in,
0055                                                         const std::vector<PFInputRegion>& out) {
0056   assert(!init_);
0057   init_ = true;
0058   nregions_ = out.size();
0059   if (ntk_) {
0060     for (unsigned int i = 0; i < netaslices_; i++) {
0061       tkRegionizers_[i].initSectors(in.track);
0062       tkRegionizers_[i].initRegions(out);
0063     }
0064   }
0065   if (ncalo_) {
0066     for (unsigned int i = 0; i < netaslices_; i++) {
0067       hadCaloRegionizers_[i].initSectors(in.hadcalo);
0068       hadCaloRegionizers_[i].initRegions(out);
0069     }
0070   }
0071   if (nem_) {
0072     for (unsigned int i = 0; i < netaslices_; i++) {
0073       emCaloRegionizers_[i].initSectors(in.emcalo);
0074       emCaloRegionizers_[i].initRegions(out);
0075     }
0076   }
0077   if (nmu_) {
0078     for (unsigned int i = 0; i < netaslices_; i++) {
0079       muRegionizers_[i].initSectors(in.muon);
0080       muRegionizers_[i].initRegions(out);
0081     }
0082   }
0083 }
0084 
0085 void l1ct::TDRRegionizerEmulator::fillLinks(const l1ct::RegionizerDecodedInputs& in,
0086                                             std::vector<std::vector<l1ct::TkObjEmu>>& links) {
0087   if (ntk_ == 0)
0088     return;
0089 
0090   links.clear();
0091   links.resize(in.track.size());
0092 
0093   //one link per sector
0094   for (unsigned int il = 0; il < in.track.size(); il++) {
0095     const l1ct::DetectorSector<l1ct::TkObjEmu>& sec = in.track[il];
0096     for (unsigned int io = 0; io < sec.size(); io++) {
0097       links[il].push_back(sec[io]);
0098       if (links[il].size() == MAX_TK_EVT) {
0099         break;
0100       }
0101     }
0102   }
0103 }
0104 
0105 void l1ct::TDRRegionizerEmulator::fillLinks(const l1ct::RegionizerDecodedInputs& in,
0106                                             std::vector<std::vector<l1ct::HadCaloObjEmu>>& links) {
0107   if (ncalo_ == 0)
0108     return;
0109 
0110   links.clear();
0111   links.resize(in.hadcalo.size());
0112 
0113   //one link per sector
0114   for (unsigned int il = 0; il < in.hadcalo.size(); il++) {
0115     const l1ct::DetectorSector<l1ct::HadCaloObjEmu>& sec = in.hadcalo[il];
0116     for (unsigned int io = 0; io < sec.size(); io++) {
0117       links[il].push_back(sec[io]);
0118       if (links[il].size() == MAX_CALO_EVT) {
0119         break;
0120       }
0121     }
0122   }
0123 }
0124 
0125 void l1ct::TDRRegionizerEmulator::fillLinks(const l1ct::RegionizerDecodedInputs& in,
0126                                             std::vector<std::vector<l1ct::EmCaloObjEmu>>& links) {
0127   if (nem_ == 0)
0128     return;
0129 
0130   links.clear();
0131   links.resize(in.emcalo.size());
0132 
0133   //one link per sector
0134   for (unsigned int il = 0; il < in.emcalo.size(); il++) {
0135     const l1ct::DetectorSector<l1ct::EmCaloObjEmu>& sec = in.emcalo[il];
0136     for (unsigned int io = 0; io < sec.size(); io++) {
0137       links[il].push_back(sec[io]);
0138       if (links[il].size() == MAX_EMCALO_EVT) {
0139         break;
0140       }
0141     }
0142   }
0143 }
0144 
0145 void l1ct::TDRRegionizerEmulator::fillLinks(const l1ct::RegionizerDecodedInputs& in,
0146                                             std::vector<std::vector<l1ct::MuObjEmu>>& links) {
0147   if (nmu_ == 0)
0148     return;
0149 
0150   links.clear();
0151   links.resize(1);  //muons are global
0152 
0153   const l1ct::DetectorSector<l1ct::MuObjEmu>& sec = in.muon;
0154   for (unsigned int io = 0; io < sec.size(); io++) {
0155     links[0].push_back(sec[io]);
0156     if (links[0].size() == MAX_MU_EVT) {
0157       break;
0158     }
0159   }
0160 }
0161 
0162 void l1ct::TDRRegionizerEmulator::toFirmware(const std::vector<l1ct::TkObjEmu>& emu, TkObj fw[NTK_SECTORS][NTK_LINKS]) {
0163   if (ntk_ == 0)
0164     return;
0165   assert(emu.size() == NTK_SECTORS * NTK_LINKS * netaslices_);
0166   for (unsigned int is = 0, idx = 0; is < NTK_SECTORS * netaslices_; ++is) {  // tf sectors
0167     for (unsigned int il = 0; il < NTK_LINKS; ++il, ++idx) {
0168       fw[is][il] = emu[idx];
0169     }
0170   }
0171 }
0172 void l1ct::TDRRegionizerEmulator::toFirmware(const std::vector<l1ct::HadCaloObjEmu>& emu,
0173                                              HadCaloObj fw[NCALO_SECTORS][NCALO_LINKS]) {
0174   if (ncalo_ == 0)
0175     return;
0176   assert(emu.size() == NCALO_SECTORS * NCALO_LINKS * netaslices_);
0177   for (unsigned int is = 0, idx = 0; is < NCALO_SECTORS * netaslices_; ++is) {  // tf sectors
0178     for (unsigned int il = 0; il < NCALO_LINKS; ++il, ++idx) {
0179       fw[is][il] = emu[idx];
0180     }
0181   }
0182 }
0183 
0184 void l1ct::TDRRegionizerEmulator::toFirmware(const std::vector<l1ct::EmCaloObjEmu>& emu,
0185                                              EmCaloObj fw[NCALO_SECTORS][NCALO_LINKS]) {
0186   if (nem_ == 0)
0187     return;
0188   assert(emu.size() == NCALO_SECTORS * NCALO_LINKS * netaslices_);
0189   for (unsigned int is = 0, idx = 0; is < NCALO_SECTORS * netaslices_; ++is) {  // tf sectors
0190     for (unsigned int il = 0; il < NCALO_LINKS; ++il, ++idx) {
0191       fw[is][il] = emu[idx];
0192     }
0193   }
0194 }
0195 
0196 void l1ct::TDRRegionizerEmulator::toFirmware(const std::vector<l1ct::MuObjEmu>& emu, MuObj fw[NMU_LINKS]) {
0197   if (nmu_ == 0)
0198     return;
0199   assert(emu.size() == NMU_LINKS);
0200   for (unsigned int il = 0, idx = 0; il < NMU_LINKS; ++il, ++idx) {
0201     fw[il] = emu[idx];
0202   }
0203 }
0204 
0205 void l1ct::TDRRegionizerEmulator::run(const RegionizerDecodedInputs& in, std::vector<PFInputRegion>& out) {
0206   if (!init_)
0207     initSectorsAndRegions(in, out);
0208 
0209   std::vector<std::vector<l1ct::TkObjEmu>> tk_links_in;
0210   std::vector<std::vector<l1ct::EmCaloObjEmu>> em_links_in;
0211   std::vector<std::vector<l1ct::HadCaloObjEmu>> calo_links_in;
0212   std::vector<std::vector<l1ct::MuObjEmu>> mu_links_in;
0213 
0214   // read the inputs
0215   fillLinks(in, tk_links_in);
0216   fillLinks(in, em_links_in);
0217   fillLinks(in, calo_links_in);
0218   fillLinks(in, mu_links_in);
0219   //this is overkill and could be improved, for now its ok (the sectors outside each board just wont do anything)
0220 
0221   for (unsigned int ie = 0; ie < netaslices_; ie++) {
0222     //add objects from link
0223     tkRegionizers_[ie].reset();
0224     tkRegionizers_[ie].setPipes(tk_links_in);
0225     tkRegionizers_[ie].initTimes();
0226     if (debug_) {
0227       dbgCout() << ie << "SECTORS/LINKS " << ie << std::endl;
0228       for (unsigned int i = 0; i < tk_links_in.size(); i++) {
0229         for (unsigned int j = 0; j < tk_links_in[i].size(); j++) {
0230           dbgCout() << "\t" << i << " " << j << "\t" << tk_links_in[i][j].hwPt.to_int() << "\t"
0231                     << tk_links_in[i][j].hwEta.to_int() << "\t" << tk_links_in[i][j].hwPhi.to_int() << std::endl;
0232         }
0233         dbgCout() << "-------------------------------" << std::endl;
0234       }
0235     }
0236     tkRegionizers_[ie].run(debug_);
0237 
0238     emCaloRegionizers_[ie].reset();
0239     emCaloRegionizers_[ie].setPipes(em_links_in);
0240     emCaloRegionizers_[ie].initTimes();
0241     emCaloRegionizers_[ie].run();
0242 
0243     hadCaloRegionizers_[ie].reset();
0244     hadCaloRegionizers_[ie].setPipes(calo_links_in);
0245     hadCaloRegionizers_[ie].initTimes();
0246     hadCaloRegionizers_[ie].run();
0247 
0248     muRegionizers_[ie].reset();
0249     muRegionizers_[ie].setPipes(mu_links_in);
0250     muRegionizers_[ie].initTimes();
0251     muRegionizers_[ie].run();
0252   }
0253 
0254   for (unsigned int ie = 0; ie < netaslices_; ie++) {
0255     for (unsigned int ireg = 0; ireg < nregions_; ireg++) {
0256       std::vector<l1ct::TkObjEmu> out_tks = tkRegionizers_[ie].getSmallRegion(ireg);
0257       if (!out_tks.empty()) {
0258         if (dosort_) {
0259           std::sort(
0260               out_tks.begin(), out_tks.end(), [](const l1ct::TkObjEmu a, const l1ct::TkObjEmu b) { return a > b; });
0261         }
0262         out[ireg].track = out_tks;
0263       }
0264       std::vector<l1ct::EmCaloObjEmu> out_emcalos = emCaloRegionizers_[ie].getSmallRegion(ireg);
0265       if (!out_emcalos.empty()) {
0266         if (dosort_) {
0267           std::sort(out_emcalos.begin(), out_emcalos.end(), [](const l1ct::EmCaloObjEmu a, const l1ct::EmCaloObjEmu b) {
0268             return a > b;
0269           });
0270         }
0271         out[ireg].emcalo = out_emcalos;
0272       }
0273       std::vector<l1ct::HadCaloObjEmu> out_hadcalos = hadCaloRegionizers_[ie].getSmallRegion(ireg);
0274       if (!out_hadcalos.empty()) {
0275         if (dosort_) {
0276           std::sort(out_hadcalos.begin(),
0277                     out_hadcalos.end(),
0278                     [](const l1ct::HadCaloObjEmu a, const l1ct::HadCaloObjEmu b) { return a > b; });
0279         }
0280         out[ireg].hadcalo = out_hadcalos;
0281       }
0282       std::vector<l1ct::MuObjEmu> out_mus = muRegionizers_[ie].getSmallRegion(ireg);
0283       if (!out_mus.empty()) {
0284         if (dosort_) {
0285           std::sort(
0286               out_mus.begin(), out_mus.end(), [](const l1ct::MuObjEmu a, const l1ct::MuObjEmu b) { return a > b; });
0287         }
0288         out[ireg].muon = out_mus;
0289       }
0290     }
0291   }
0292 }