File indexing completed on 2022-06-10 01:53:50
0001 #ifndef tdr_regionizer_elements_ref_h
0002 #define tdr_regionizer_elements_ref_h
0003
0004 #include "DataFormats/L1TParticleFlow/interface/layer1_emulator.h"
0005
0006 #include <list>
0007 #include <vector>
0008 #include <cassert>
0009 #include <algorithm>
0010
0011 #ifdef CMSSW_GIT_HASH
0012 #include "L1Trigger/Phase2L1ParticleFlow/interface/dbgPrintf.h"
0013 #else
0014 #include "../../utils/dbgPrintf.h"
0015 #endif
0016
0017 namespace l1ct {
0018 namespace tdr_regionizer {
0019
0020 inline int dphi_wrap(int local_phi) {
0021 if (local_phi > l1ct::Scales::INTPHI_PI)
0022 local_phi -= l1ct::Scales::INTPHI_TWOPI;
0023 else if (local_phi <= -l1ct::Scales::INTPHI_PI)
0024 local_phi += l1ct::Scales::INTPHI_TWOPI;
0025 return local_phi;
0026 }
0027
0028 struct RegionInfo {
0029 RegionInfo(unsigned int idx, int regphi, int regeta) : index(idx), phi(regphi), eta(regeta) {}
0030 unsigned int index;
0031 int phi;
0032 int eta;
0033 };
0034
0035 inline bool sortRegionInfo(RegionInfo& a, RegionInfo& b) {
0036 if (a.phi < b.phi)
0037 return true;
0038 if (a.phi > b.phi)
0039 return false;
0040 if (a.eta < b.eta)
0041 return true;
0042 if (a.eta > b.eta)
0043 return false;
0044 return false;
0045 }
0046
0047 template <typename T>
0048 class PipeObject {
0049 public:
0050 PipeObject() {}
0051 PipeObject(const T& obj,
0052 unsigned int phiindex,
0053 unsigned int etaindex,
0054 bool phioverlap,
0055 bool etaoverlap,
0056 int glbphi,
0057 int glbeta,
0058 unsigned int clk);
0059
0060 const unsigned int getClock() { return linkobjclk_; }
0061 void setClock(unsigned int clock) { linkobjclk_ = clock; }
0062 const unsigned int getPhi() { return phiindex_; }
0063 const unsigned int getEta() { return etaindex_; }
0064 const bool getPhiOverlap() { return phioverlap_; }
0065 const bool getEtaOverlap() { return etaoverlap_; }
0066 const unsigned int getCount() { return objcount_; }
0067 unsigned int getCountAndInc() { return objcount_++; }
0068 void incCount() { objcount_++; }
0069 const int getPt() { return obj_.hwPt.to_int(); }
0070 const int getGlbPhi() { return glbphi_; }
0071 const int getGlbEta() { return glbeta_; }
0072
0073 T getObj() { return obj_; }
0074
0075 private:
0076 T obj_;
0077 unsigned int phiindex_, etaindex_;
0078 bool phioverlap_, etaoverlap_;
0079 int glbphi_, glbeta_;
0080 unsigned int linkobjclk_, objcount_;
0081 };
0082
0083 template <typename T>
0084 class Pipe {
0085 public:
0086 Pipe(unsigned int nphi = 9) : clkindex_(0), nphi_(nphi) {}
0087
0088 void addObj(
0089 T obj, unsigned int phiindex, unsigned int etaindex, bool phioverlap, bool etaoverlap, int glbphi, int glbeta);
0090 PipeObject<T>& getObj(unsigned int index) { return data_[index]; }
0091 T getRawObj(unsigned int index) { return data_[index].getObj(); }
0092
0093 unsigned int getClock(unsigned int index = 0) { return getObj(index).getClock(); }
0094 void setClock(unsigned int clock, unsigned int index = 0) { return getObj(index).setClock(clock); }
0095 unsigned int getPhi(unsigned int index = 0) { return getObj(index).getPhi(); }
0096 unsigned int getEta(unsigned int index = 0) { return getObj(index).getEta(); }
0097 bool getPhiOverlap(unsigned int index = 0) { return getObj(index).getPhiOverlap(); }
0098 bool getEtaOverlap(unsigned int index = 0) { return getObj(index).getEtaOverlap(); }
0099 unsigned int getCount(unsigned int index = 0) { return getObj(index).getCount(); }
0100 unsigned int getCountAndInc(unsigned int index = 0) { return getObj(index).getCountAndInc(); }
0101 void incCount(unsigned int index = 0) { getObj(index).incCount(); }
0102 void erase(unsigned int index = 0) { data_.erase(data_.begin() + index); }
0103 int getPt(unsigned int index = 0) { return getObj(index).getPt(); }
0104 int getGlbPhi(unsigned int index = 0) { return getObj(index).getGlbPhi(); }
0105 int getGlbEta(unsigned int index = 0) { return getObj(index).getGlbEta(); }
0106
0107 int getClosedIndexForObject(unsigned int index = 0);
0108 int getPipeIndexForObject(unsigned int index = 0);
0109
0110 unsigned int getSize() { return data_.size(); }
0111
0112 void reset() {
0113 clkindex_ = 0;
0114 data_.clear();
0115 }
0116
0117 private:
0118 unsigned int clkindex_, nphi_;
0119 std::vector<PipeObject<T>> data_;
0120 };
0121
0122 template <typename T>
0123 class Regionizer {
0124 public:
0125 Regionizer() {}
0126 Regionizer(
0127 unsigned int neta, unsigned int nregions, unsigned int maxobjects, int etaoffset, int etawidth, int nclocks);
0128 void initSectors(const std::vector<DetectorSector<T>>& sectors);
0129 void initSectors(const DetectorSector<T>& sector);
0130 void initRegions(const std::vector<PFInputRegion>& regions);
0131
0132 unsigned int getSize() { return pipes_.size(); }
0133 unsigned int getPipeSize(unsigned int index) { return getPipe(index).getSize(); }
0134
0135 bool setIndicesOverlaps(const T& obj,
0136 unsigned int& phiindex,
0137 unsigned int& etaindex,
0138 bool& phioverlap,
0139 bool& etaoverlap,
0140 int& glbphi,
0141 int& glbeta,
0142 unsigned int index);
0143
0144 void addToPipe(const T& obj, unsigned int index);
0145 void setPipe(const std::vector<T>& objvec, unsigned int index);
0146 void setPipes(const std::vector<std::vector<T>>& objvecvec);
0147 Pipe<T>& getPipe(unsigned int index) { return pipes_[index]; }
0148
0149 int getPipeTime(int linkIndex, int linkTimeOfObject, int linkAlgoClockRunningTime);
0150 int popLinkObject(int linkIndex, int currentTimeOfObject);
0151 int timeNextFromIndex(unsigned int index, int time) { return getPipeTime(index, pipes_[index].getClock(), time); }
0152
0153 void initTimes();
0154
0155 int getClosedIndexForObject(unsigned int linknum, unsigned int index = 0) {
0156 return pipes_[linknum].getClosedIndexForObject(index);
0157 }
0158 int getPipeIndexForObject(unsigned int linknum, unsigned int index = 0) {
0159 return pipes_[linknum].getPipeIndexForObject(index);
0160 }
0161 void addToSmallRegion(unsigned int linkNum, unsigned int index = 0);
0162
0163 void run(bool debug = false);
0164
0165 void reset();
0166
0167 std::vector<T> getSmallRegion(unsigned int index);
0168
0169 void printDebug(int count) {
0170 dbgCout() << count << "\tindex\tpt\teta\tphi" << std::endl;
0171 dbgCout() << "PIPES" << std::endl;
0172 for (unsigned int i = 0; i < getSize(); i++) {
0173 for (unsigned int j = 0; j < getPipeSize(i); j++) {
0174 dbgCout() << "\t" << i << " " << j << "\t" << getPipe(i).getPt(j) << "\t" << getPipe(i).getGlbEta(j) << "\t"
0175 << getPipe(i).getGlbPhi(j) << std::endl;
0176 }
0177 dbgCout() << "-------------------------------" << std::endl;
0178 }
0179 dbgCout() << "SMALL REGIONS" << std::endl;
0180 for (unsigned int i = 0; i < nregions_; i++) {
0181 for (unsigned int j = 0; j < smallRegionObjects_[i].size(); j++) {
0182 dbgCout() << "\t" << i << " " << j << "\t" << smallRegionObjects_[i][j].hwPt.to_int() << "\t"
0183 << smallRegionObjects_[i][j].hwEta.to_int() + regionmap_[i].eta << "\t"
0184 << smallRegionObjects_[i][j].hwPhi.to_int() + regionmap_[i].phi << std::endl;
0185 }
0186 dbgCout() << "-------------------------------" << std::endl;
0187 }
0188 dbgCout() << "TIMES" << std::endl;
0189 for (unsigned int i = 0; i < timeOfNextObject_.size(); i++) {
0190 dbgCout() << " " << timeOfNextObject_[i];
0191 }
0192 dbgCout() << "\n-------------------------------" << std::endl;
0193 }
0194
0195 private:
0196 unsigned int neta_, nregions_, maxobjects_, nsectors_;
0197 int etaoffset_, etawidth_, nclocks_;
0198 std::vector<l1ct::PFRegionEmu> sectors_;
0199 std::vector<l1ct::PFRegionEmu> regions_;
0200 std::vector<RegionInfo> regionmap_;
0201
0202 std::vector<Pipe<T>> pipes_;
0203 std::vector<int> timeOfNextObject_;
0204 std::vector<std::vector<T>> smallRegionObjects_;
0205 };
0206
0207 }
0208 }
0209
0210 #endif