CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/L1Trigger/RegionalCaloTrigger/src/L1RCTRegion.cc

Go to the documentation of this file.
00001 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTRegion.h"
00002 
00003 #include <vector>
00004 using std::vector;
00005 
00006 #include <iostream>
00007 using std::cout;
00008 using std::cerr;
00009 using std::endl;
00010 
00011 L1RCTRegion::L1RCTRegion() : totalRegionEt(36),
00012                              totalRegionHE_FG(36),
00013                              etIn9Bits(16),
00014                              muonBit(16),
00015                              activityBit(16)
00016 {
00017 }
00018 
00019 
00020 L1RCTRegion::~L1RCTRegion()
00021 {}
00022 
00023 //So the whole point of the following two functions is that they provide
00024 //an interface to the "real" 4x4 region 7 bit energies and h/e||fg bits
00025 //that are used in electron finding.  
00026 //Now, you actually *can* give them arguments ranging from -1 to 4 
00027 //representing the outer neighbors.
00028 //This is actually quite helpful and allows you to write the electronfinding
00029 //algorithm in the same form no matter what tower you're centered on.
00030 //
00031 //As a reminder i is row and j is column, just like matrices.
00032 //row -1 is the northern neighbors and column -1 is the western neighbors
00033 unsigned short L1RCTRegion::getEtIn7Bits(int i, int j) const{
00034   //i & j run 0-3
00035   return totalRegionEt.at(6*(i+1) + j+1);
00036 }
00037 
00038 void L1RCTRegion::setEtIn7Bits(int i, int j,unsigned short energy){
00039   //i & j should be 0-3
00040   if(energy <= 127)
00041     totalRegionEt.at(6*(i+1) + j+1) = energy;
00042   else
00043     totalRegionEt.at(6*(i+1) + j+1) = 127;
00044 }
00045 
00046 
00047 unsigned short L1RCTRegion::getHE_FGBit(int i, int j) const{
00048   return totalRegionHE_FG.at(6*(i+1)+j+1);
00049 }
00050 
00051 void L1RCTRegion::setHE_FGBit(int i, int j, unsigned short HE_FG){
00052   totalRegionHE_FG.at(6*(i+1)+j+1) = HE_FG;
00053 }
00054 
00055 
00056 //The rest of the data stored in a region only works if i and j are
00057 //in the 0-3 range.  The arrays truly are 4x4 and will signal an error
00058 //if misused thanks to the vector function .at
00059 unsigned short L1RCTRegion::getEtIn9Bits(int i, int j) const{
00060   return etIn9Bits.at(4*i + j);
00061 }
00062 
00063 void L1RCTRegion::setEtIn9Bits(int i, int j,unsigned short energy){
00064   if(energy <=511)
00065     etIn9Bits.at(4*i+j) = energy;
00066   else 
00067     etIn9Bits.at(4*i+j) = 511;
00068 }
00069 
00070 unsigned short L1RCTRegion::getMuonBit(int i, int j) const{
00071   return muonBit.at(4*i+j);
00072 }
00073 
00074 void L1RCTRegion::setMuonBit(int i, int j,unsigned short muon) {
00075   muonBit.at(4*i+j) = muon;
00076 }
00077 
00078 void L1RCTRegion::setActivityBit(int i, int j, unsigned short activity){
00079   activityBit.at(4*i+j) = activity;
00080 }
00081 
00082 unsigned short L1RCTRegion::getActivityBit(int i, int j) const{
00083   return activityBit.at(4*i+j);
00084 }
00085 
00086 //The following list of give and set functions are the core
00087 //of the work for neighbor sharing swept under the rug.
00088 //Basically, the way it works is that "give" methods return
00089 //what would be the appropriate neighbor information so that you can
00090 //use the set methods on the other region in order to set the neighbor
00091 //information.  For example, r0:crate 0 card 0 region 0 is the northern
00092 //neighbor of r1:crate 0 card 1 region 0.  Then to set the northern
00093 //neighbor information you call r1.setNorthEt(r0.getNorthEt())
00094 //That's why it's give insted of get.  It doesn't return the region's
00095 //northern neighbor information, it returns what would be its southern
00096 //neighbor's northern neighbor information.
00097 vector<unsigned short> L1RCTRegion::giveNorthEt() const{
00098   std::vector<unsigned short> north(4);
00099   for(int i = 0; i<4;i++)
00100     north.at(i) = getEtIn7Bits(3,i);
00101   return north;
00102 }
00103 void L1RCTRegion::setNorthEt(std::vector<unsigned short> north) {
00104   for(int i = 0; i<4; i++)
00105     totalRegionEt.at(i+1) = north.at(i);
00106 }
00107 vector<unsigned short> L1RCTRegion::giveNorthHE_FG() const{
00108   std::vector<unsigned short> north(4);
00109   for(int i = 0; i<4; i++)
00110     north.at(i) = getHE_FGBit(3,i);
00111   return north;
00112 }
00113 void L1RCTRegion::setNorthHE_FG(std::vector<unsigned short> north){
00114   for(int i = 0; i<4; i++)
00115     totalRegionHE_FG.at(i+1) = north.at(i);
00116 }
00117 
00118 vector<unsigned short> L1RCTRegion::giveSouthEt() const{
00119   std::vector<unsigned short> south(4);
00120   for(int i = 0; i<4; i++)
00121     south.at(i) = getEtIn7Bits(0,i);
00122   return south;
00123 }
00124 void L1RCTRegion::setSouthEt(std::vector<unsigned short> south){
00125   for(int i = 0; i<4; i++)
00126     totalRegionEt.at(31+i) = south.at(i);
00127 }
00128 
00129 vector<unsigned short> L1RCTRegion::giveSouthHE_FG() const{
00130   std::vector<unsigned short> south(4);
00131   for(int i = 0; i<4; i++)
00132     south.at(i) = getHE_FGBit(0,i);
00133   return south;
00134 }
00135 void L1RCTRegion::setSouthHE_FG(std::vector<unsigned short> south){
00136   for(int i=0; i<4; i++)
00137     totalRegionHE_FG.at(31+i) = south.at(i);
00138 }
00139 
00140 vector<unsigned short> L1RCTRegion::giveWestEt() const{
00141   std::vector<unsigned short> west(4);
00142   for(int i =0; i<4; i++)
00143     west.at(i) = getEtIn7Bits(i,3);
00144   return west;
00145 }
00146 void L1RCTRegion::setWestEt(std::vector<unsigned short> west){
00147   for(int i = 0; i<4; i++)
00148     totalRegionEt.at(6*(i+1)) = west.at(i);
00149 }
00150 
00151 vector<unsigned short> L1RCTRegion::giveWestHE_FG() const{
00152   std::vector<unsigned short> west(4);
00153   for(int i = 0; i<4; i++)
00154     west.at(i) = getHE_FGBit(i,3);
00155   return west;
00156 }
00157 void L1RCTRegion::setWestHE_FG(std::vector<unsigned short> west){
00158   for(int i = 0; i<4; i++)
00159     totalRegionHE_FG.at(6*(i+1)) = west.at(i);
00160 }
00161 
00162 vector<unsigned short> L1RCTRegion::giveEastEt() const{
00163   std::vector<unsigned short> east(4);
00164   for(int i = 0; i<4; i++)
00165     east.at(i) = getEtIn7Bits(i,0);
00166   return east;
00167 }
00168 void L1RCTRegion::setEastEt(std::vector<unsigned short> east){
00169   for(int i = 0; i<4; i++)
00170     totalRegionEt.at(6*(i+1) + 5) = east.at(i);
00171 }
00172 
00173 vector<unsigned short> L1RCTRegion::giveEastHE_FG() const{
00174   std::vector<unsigned short> east(4);
00175   for(int i = 0; i<4; i++)
00176     east.at(i) = getHE_FGBit(i,0);
00177   return east;
00178 }
00179 void L1RCTRegion::setEastHE_FG(std::vector<unsigned short> east){
00180   for(int i = 0; i<4; i++)
00181     totalRegionHE_FG.at(6*(i+1) + 5) = east.at(i);
00182 }
00183 
00184 unsigned short L1RCTRegion::giveNEEt() const{
00185   unsigned short et = getEtIn7Bits(3,0);
00186   if(et > 7)
00187     return 7;
00188   else
00189     return et;
00190 }
00191 unsigned short L1RCTRegion::giveNEHE_FG() const{
00192   return getHE_FGBit(3,0);
00193 }
00194 void L1RCTRegion::setNEEt(unsigned short ne){
00195   totalRegionEt.at(5) = ne;
00196 }
00197 void L1RCTRegion::setNEHE_FG(unsigned short ne){
00198   totalRegionHE_FG.at(5) = ne;
00199 }
00200 
00201 unsigned short L1RCTRegion::giveNWEt() const{
00202   unsigned short et = getEtIn7Bits(3,3);
00203   if(et > 7)
00204     return 7;
00205   else 
00206     return et;
00207 }
00208 unsigned short L1RCTRegion::giveNWHE_FG() const{
00209   return getHE_FGBit(3,3);
00210 }
00211 void L1RCTRegion::setNWEt(unsigned short nw){
00212   totalRegionEt.at(0) = nw;
00213 }
00214 void L1RCTRegion::setNWHE_FG(unsigned short nw){
00215   totalRegionHE_FG.at(0) = nw;
00216 }
00217 
00218 unsigned short L1RCTRegion::giveSWEt() const{
00219   unsigned short et = getEtIn7Bits(0,3);
00220   if(et > 7)
00221     return 7;
00222   else
00223     return et;
00224 }
00225 unsigned short L1RCTRegion::giveSWHE_FG() const{
00226   return getHE_FGBit(0,3);
00227 }
00228 void L1RCTRegion::setSWEt(unsigned short sw){
00229   totalRegionEt.at(30) = sw;
00230 }
00231 void L1RCTRegion::setSWHE_FG(unsigned short sw){
00232   totalRegionHE_FG.at(30) = sw;
00233 }
00234 
00235 unsigned short L1RCTRegion::giveSEEt() const{
00236   unsigned short et = getEtIn7Bits(0,0);
00237   if(et > 7)
00238     return 7;
00239   else
00240     return et;
00241 }
00242 unsigned short L1RCTRegion::giveSEHE_FG() const{
00243   return getHE_FGBit(0,0);
00244 }
00245 void L1RCTRegion::setSEEt(unsigned short se) {
00246   totalRegionEt.at(35) = se;
00247 }
00248 void L1RCTRegion::setSEHE_FG(unsigned short se) {
00249   totalRegionHE_FG.at(35) = se;
00250 }
00251 
00252 void L1RCTRegion::print() {
00253   
00254   std::cout << " 7 Bit Energies ";
00255   for(int i = 0; i<4; i++){
00256     std::cout << std::endl;
00257     for(int j = 0; j<4; j++){
00258       std::cout << " " << getEtIn7Bits(i,j) << " ";
00259     }
00260   }
00261 
00262   std::cout << std::endl << std::endl;
00263   std::cout << " 9 Bit Energies ";
00264   for(int i = 0; i<4; i++){
00265     std::cout << std::endl;
00266     for(int j = 0; j<4; j++){
00267       std::cout << " " << getEtIn9Bits(i,j) << " ";
00268     }
00269   }
00270   
00271   std::cout << std::endl << std::endl;
00272   std::cout << " HE || FG bit ";
00273   for(int i = 0; i<4; i++){
00274     std::cout << std::endl;
00275     for(int j = 0; j<4; j++){
00276       std::cout << " " << getHE_FGBit(i,j) << " ";
00277     }
00278   }
00279 
00280   std::cout << std::endl << std::endl;
00281   std::cout << " Muon Bit ";
00282   for(int i = 0; i<4; i++){
00283     std::cout << std::endl;
00284     for(int j = 0; j<4; j++){
00285       std::cout << " " << getMuonBit(i,j) << " ";
00286     }
00287   }
00288   std::cout << std::endl;
00289 }
00290 
00291 void L1RCTRegion::printEdges(){
00292   std::cout << "North" << std::endl;
00293   for(int i=0; i<4;i++)
00294     std::cout << totalRegionEt.at(i+1) << std::endl;
00295   
00296   std::cout << "West" << std::endl;
00297   for(int i=0; i<4;i++)
00298     std::cout << totalRegionEt.at(6*(i+1)) << std::endl;
00299 
00300   std::cout << "East" << std::endl;
00301   for(int i=0; i<4;i++)
00302     std::cout << totalRegionEt.at(6*(i+1)+5) << std::endl;
00303   
00304   std::cout << "South" << std::endl;
00305   for(int i=0; i<4;i++)
00306     std::cout << totalRegionEt.at(31+i) << std::endl;
00307  
00308   std::cout << "NE " << totalRegionEt.at(5) << std::endl;
00309   std::cout << "SE " << totalRegionEt.at(35) << std::endl;
00310   std::cout << "NW " << totalRegionEt.at(0) << std::endl;
00311   std::cout << "SW " << totalRegionEt.at(30) << std::endl;
00312 }