Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:32

0001 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTRegion.h"
0002 
0003 #include <vector>
0004 using std::vector;
0005 
0006 #include <iostream>
0007 using std::cerr;
0008 using std::cout;
0009 using std::endl;
0010 
0011 L1RCTRegion::L1RCTRegion() : totalRegionEt(36), totalRegionHE_FG(36), etIn9Bits(16), muonBit(16), activityBit(16) {}
0012 
0013 L1RCTRegion::~L1RCTRegion() {}
0014 
0015 // So the whole point of the following two functions is that they provide
0016 // an interface to the "real" 4x4 region 7 bit energies and h/e||fg bits
0017 // that are used in electron finding.
0018 // Now, you actually *can* give them arguments ranging from -1 to 4
0019 // representing the outer neighbors.
0020 // This is actually quite helpful and allows you to write the electronfinding
0021 // algorithm in the same form no matter what tower you're centered on.
0022 //
0023 // As a reminder i is row and j is column, just like matrices.
0024 // row -1 is the northern neighbors and column -1 is the western neighbors
0025 unsigned short L1RCTRegion::getEtIn7Bits(int i, int j) const {
0026   // i & j run 0-3
0027   return totalRegionEt.at(6 * (i + 1) + j + 1);
0028 }
0029 
0030 void L1RCTRegion::setEtIn7Bits(int i, int j, unsigned short energy) {
0031   // i & j should be 0-3
0032   if (energy <= 127)
0033     totalRegionEt.at(6 * (i + 1) + j + 1) = energy;
0034   else
0035     totalRegionEt.at(6 * (i + 1) + j + 1) = 127;
0036 }
0037 
0038 unsigned short L1RCTRegion::getHE_FGBit(int i, int j) const { return totalRegionHE_FG.at(6 * (i + 1) + j + 1); }
0039 
0040 void L1RCTRegion::setHE_FGBit(int i, int j, unsigned short HE_FG) { totalRegionHE_FG.at(6 * (i + 1) + j + 1) = HE_FG; }
0041 
0042 // The rest of the data stored in a region only works if i and j are
0043 // in the 0-3 range.  The arrays truly are 4x4 and will signal an error
0044 // if misused thanks to the vector function .at
0045 unsigned short L1RCTRegion::getEtIn9Bits(int i, int j) const { return etIn9Bits.at(4 * i + j); }
0046 
0047 void L1RCTRegion::setEtIn9Bits(int i, int j, unsigned short energy) {
0048   if (energy <= 511)
0049     etIn9Bits.at(4 * i + j) = energy;
0050   else
0051     etIn9Bits.at(4 * i + j) = 511;
0052 }
0053 
0054 unsigned short L1RCTRegion::getMuonBit(int i, int j) const { return muonBit.at(4 * i + j); }
0055 
0056 void L1RCTRegion::setMuonBit(int i, int j, unsigned short muon) { muonBit.at(4 * i + j) = muon; }
0057 
0058 void L1RCTRegion::setActivityBit(int i, int j, unsigned short activity) { activityBit.at(4 * i + j) = activity; }
0059 
0060 unsigned short L1RCTRegion::getActivityBit(int i, int j) const { return activityBit.at(4 * i + j); }
0061 
0062 // The following list of give and set functions are the core
0063 // of the work for neighbor sharing swept under the rug.
0064 // Basically, the way it works is that "give" methods return
0065 // what would be the appropriate neighbor information so that you can
0066 // use the set methods on the other region in order to set the neighbor
0067 // information.  For example, r0:crate 0 card 0 region 0 is the northern
0068 // neighbor of r1:crate 0 card 1 region 0.  Then to set the northern
0069 // neighbor information you call r1.setNorthEt(r0.getNorthEt())
0070 // That's why it's give insted of get.  It doesn't return the region's
0071 // northern neighbor information, it returns what would be its southern
0072 // neighbor's northern neighbor information.
0073 vector<unsigned short> L1RCTRegion::giveNorthEt() const {
0074   std::vector<unsigned short> north(4);
0075   for (int i = 0; i < 4; i++)
0076     north.at(i) = getEtIn7Bits(3, i);
0077   return north;
0078 }
0079 void L1RCTRegion::setNorthEt(const std::vector<unsigned short> &north) {
0080   for (int i = 0; i < 4; i++)
0081     totalRegionEt.at(i + 1) = north.at(i);
0082 }
0083 vector<unsigned short> L1RCTRegion::giveNorthHE_FG() const {
0084   std::vector<unsigned short> north(4);
0085   for (int i = 0; i < 4; i++)
0086     north.at(i) = getHE_FGBit(3, i);
0087   return north;
0088 }
0089 void L1RCTRegion::setNorthHE_FG(const std::vector<unsigned short> &north) {
0090   for (int i = 0; i < 4; i++)
0091     totalRegionHE_FG.at(i + 1) = north.at(i);
0092 }
0093 
0094 vector<unsigned short> L1RCTRegion::giveSouthEt() const {
0095   std::vector<unsigned short> south(4);
0096   for (int i = 0; i < 4; i++)
0097     south.at(i) = getEtIn7Bits(0, i);
0098   return south;
0099 }
0100 void L1RCTRegion::setSouthEt(const std::vector<unsigned short> &south) {
0101   for (int i = 0; i < 4; i++)
0102     totalRegionEt.at(31 + i) = south.at(i);
0103 }
0104 
0105 vector<unsigned short> L1RCTRegion::giveSouthHE_FG() const {
0106   std::vector<unsigned short> south(4);
0107   for (int i = 0; i < 4; i++)
0108     south.at(i) = getHE_FGBit(0, i);
0109   return south;
0110 }
0111 void L1RCTRegion::setSouthHE_FG(const std::vector<unsigned short> &south) {
0112   for (int i = 0; i < 4; i++)
0113     totalRegionHE_FG.at(31 + i) = south.at(i);
0114 }
0115 
0116 vector<unsigned short> L1RCTRegion::giveWestEt() const {
0117   std::vector<unsigned short> west(4);
0118   for (int i = 0; i < 4; i++)
0119     west.at(i) = getEtIn7Bits(i, 3);
0120   return west;
0121 }
0122 void L1RCTRegion::setWestEt(const std::vector<unsigned short> &west) {
0123   for (int i = 0; i < 4; i++)
0124     totalRegionEt.at(6 * (i + 1)) = west.at(i);
0125 }
0126 
0127 vector<unsigned short> L1RCTRegion::giveWestHE_FG() const {
0128   std::vector<unsigned short> west(4);
0129   for (int i = 0; i < 4; i++)
0130     west.at(i) = getHE_FGBit(i, 3);
0131   return west;
0132 }
0133 void L1RCTRegion::setWestHE_FG(const std::vector<unsigned short> &west) {
0134   for (int i = 0; i < 4; i++)
0135     totalRegionHE_FG.at(6 * (i + 1)) = west.at(i);
0136 }
0137 
0138 vector<unsigned short> L1RCTRegion::giveEastEt() const {
0139   std::vector<unsigned short> east(4);
0140   for (int i = 0; i < 4; i++)
0141     east.at(i) = getEtIn7Bits(i, 0);
0142   return east;
0143 }
0144 void L1RCTRegion::setEastEt(const std::vector<unsigned short> &east) {
0145   for (int i = 0; i < 4; i++)
0146     totalRegionEt.at(6 * (i + 1) + 5) = east.at(i);
0147 }
0148 
0149 vector<unsigned short> L1RCTRegion::giveEastHE_FG() const {
0150   std::vector<unsigned short> east(4);
0151   for (int i = 0; i < 4; i++)
0152     east.at(i) = getHE_FGBit(i, 0);
0153   return east;
0154 }
0155 void L1RCTRegion::setEastHE_FG(const std::vector<unsigned short> &east) {
0156   for (int i = 0; i < 4; i++)
0157     totalRegionHE_FG.at(6 * (i + 1) + 5) = east.at(i);
0158 }
0159 
0160 unsigned short L1RCTRegion::giveNEEt() const {
0161   unsigned short et = getEtIn7Bits(3, 0);
0162   if (et > 7)
0163     return 7;
0164   else
0165     return et;
0166 }
0167 unsigned short L1RCTRegion::giveNEHE_FG() const { return getHE_FGBit(3, 0); }
0168 void L1RCTRegion::setNEEt(unsigned short ne) { totalRegionEt.at(5) = ne; }
0169 void L1RCTRegion::setNEHE_FG(unsigned short ne) { totalRegionHE_FG.at(5) = ne; }
0170 
0171 unsigned short L1RCTRegion::giveNWEt() const {
0172   unsigned short et = getEtIn7Bits(3, 3);
0173   if (et > 7)
0174     return 7;
0175   else
0176     return et;
0177 }
0178 unsigned short L1RCTRegion::giveNWHE_FG() const { return getHE_FGBit(3, 3); }
0179 void L1RCTRegion::setNWEt(unsigned short nw) { totalRegionEt.at(0) = nw; }
0180 void L1RCTRegion::setNWHE_FG(unsigned short nw) { totalRegionHE_FG.at(0) = nw; }
0181 
0182 unsigned short L1RCTRegion::giveSWEt() const {
0183   unsigned short et = getEtIn7Bits(0, 3);
0184   if (et > 7)
0185     return 7;
0186   else
0187     return et;
0188 }
0189 unsigned short L1RCTRegion::giveSWHE_FG() const { return getHE_FGBit(0, 3); }
0190 void L1RCTRegion::setSWEt(unsigned short sw) { totalRegionEt.at(30) = sw; }
0191 void L1RCTRegion::setSWHE_FG(unsigned short sw) { totalRegionHE_FG.at(30) = sw; }
0192 
0193 unsigned short L1RCTRegion::giveSEEt() const {
0194   unsigned short et = getEtIn7Bits(0, 0);
0195   if (et > 7)
0196     return 7;
0197   else
0198     return et;
0199 }
0200 unsigned short L1RCTRegion::giveSEHE_FG() const { return getHE_FGBit(0, 0); }
0201 void L1RCTRegion::setSEEt(unsigned short se) { totalRegionEt.at(35) = se; }
0202 void L1RCTRegion::setSEHE_FG(unsigned short se) { totalRegionHE_FG.at(35) = se; }
0203 
0204 void L1RCTRegion::print() {
0205   std::cout << " 7 Bit Energies ";
0206   for (int i = 0; i < 4; i++) {
0207     std::cout << std::endl;
0208     for (int j = 0; j < 4; j++) {
0209       std::cout << " " << getEtIn7Bits(i, j) << " ";
0210     }
0211   }
0212 
0213   std::cout << std::endl << std::endl;
0214   std::cout << " 9 Bit Energies ";
0215   for (int i = 0; i < 4; i++) {
0216     std::cout << std::endl;
0217     for (int j = 0; j < 4; j++) {
0218       std::cout << " " << getEtIn9Bits(i, j) << " ";
0219     }
0220   }
0221 
0222   std::cout << std::endl << std::endl;
0223   std::cout << " HE || FG bit ";
0224   for (int i = 0; i < 4; i++) {
0225     std::cout << std::endl;
0226     for (int j = 0; j < 4; j++) {
0227       std::cout << " " << getHE_FGBit(i, j) << " ";
0228     }
0229   }
0230 
0231   std::cout << std::endl << std::endl;
0232   std::cout << " Muon Bit ";
0233   for (int i = 0; i < 4; i++) {
0234     std::cout << std::endl;
0235     for (int j = 0; j < 4; j++) {
0236       std::cout << " " << getMuonBit(i, j) << " ";
0237     }
0238   }
0239   std::cout << std::endl;
0240 }
0241 
0242 void L1RCTRegion::printEdges() {
0243   std::cout << "North" << std::endl;
0244   for (int i = 0; i < 4; i++)
0245     std::cout << totalRegionEt.at(i + 1) << std::endl;
0246 
0247   std::cout << "West" << std::endl;
0248   for (int i = 0; i < 4; i++)
0249     std::cout << totalRegionEt.at(6 * (i + 1)) << std::endl;
0250 
0251   std::cout << "East" << std::endl;
0252   for (int i = 0; i < 4; i++)
0253     std::cout << totalRegionEt.at(6 * (i + 1) + 5) << std::endl;
0254 
0255   std::cout << "South" << std::endl;
0256   for (int i = 0; i < 4; i++)
0257     std::cout << totalRegionEt.at(31 + i) << std::endl;
0258 
0259   std::cout << "NE " << totalRegionEt.at(5) << std::endl;
0260   std::cout << "SE " << totalRegionEt.at(35) << std::endl;
0261   std::cout << "NW " << totalRegionEt.at(0) << std::endl;
0262   std::cout << "SW " << totalRegionEt.at(30) << std::endl;
0263 }