CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/FastSimulation/CaloGeometryTools/src/CaloDirectionOperations.cc

Go to the documentation of this file.
00001 #include "FastSimulation/CaloGeometryTools/interface/CaloDirectionOperations.h"
00002 
00003 
00004 CaloDirection CaloDirectionOperations::add2d(const CaloDirection& dir1, const CaloDirection & dir2)
00005 {
00006   //  unsigned d1=Side(dir1);
00007   //  unsigned d2=Side(dir2);
00008   static CaloDirection tab[4][4]={{NORTH,NORTHEAST,NONE,NORTHWEST},
00009                                   {NORTHEAST,EAST,SOUTHEAST,NONE},
00010                                   {NONE,SOUTHEAST,SOUTH,SOUTHWEST},
00011                                   {NORTHWEST,NONE,SOUTHWEST,WEST}};
00012   return tab[Side(dir1)][Side(dir2)];
00013 }
00014 
00015 CaloDirection CaloDirectionOperations::Side(unsigned i) 
00016 {
00017   static CaloDirection sides[6]={NORTH,EAST,SOUTH,WEST,UP,DOWN};
00018   //  if(i<0||i>5) return DOWN;
00019   return sides[i];
00020 }
00021 
00022 unsigned CaloDirectionOperations::neighbourDirection(const CaloDirection& side)
00023 {
00024   unsigned result;
00025   switch (side)
00026     {
00027     case NORTH:
00028       result=0;
00029       break;
00030     case EAST:
00031       result=1;
00032       break;
00033     case SOUTH:
00034       result=2;
00035       break;
00036     case WEST:
00037       result=3;
00038       break;
00039     case NORTHEAST:
00040       result=4;
00041       break;
00042     case SOUTHEAST:
00043       result=5;
00044       break;
00045     case SOUTHWEST:
00046       result=6;
00047       break;
00048     case NORTHWEST:
00049       result=7;
00050       break;
00051     default:
00052       result=999;
00053     }
00054   return result;
00055 }
00056 
00057 
00058 // It should be merged with the previous one. But I am afraid to break something
00059 CaloDirection CaloDirectionOperations::neighbourDirection(unsigned i)
00060 {
00061   static CaloDirection sides[8]={NORTH,EAST,SOUTH,WEST,NORTHEAST,SOUTHEAST,SOUTHWEST,NORTHWEST};
00062   //  if(i<0||i>7) return SOUTH;
00063   return sides[i];
00064 }
00065 
00066 
00067 unsigned CaloDirectionOperations::Side(const CaloDirection& side)
00068 {
00069   unsigned result;
00070   switch (side)
00071     {
00072     case NORTH:
00073       result=0;
00074       break;
00075     case EAST:
00076       result=1;
00077       break;
00078     case SOUTH:
00079       result=2;
00080       break;
00081     case WEST:
00082       result=3;
00083       break;
00084     case UP:
00085       result=4;
00086       break;
00087     case DOWN:
00088       result=5;
00089       break;
00090     default:
00091       result=999;
00092     }
00093   return result;
00094 }
00095 
00096 
00097 CaloDirection CaloDirectionOperations::oppositeSide(const CaloDirection& side) 
00098 {
00099   CaloDirection result;
00100   switch (side)
00101     {
00102     case UP:
00103       result=DOWN;
00104       break;
00105     case DOWN:
00106       result=UP;
00107       break;
00108     case EAST:
00109       result=WEST;
00110       break;
00111     case WEST:
00112       result=EAST;
00113       break;
00114     case NORTH:
00115       result=SOUTH;
00116       break;
00117     case SOUTH:
00118       result=NORTH;
00119       break;
00120     case NORTHEAST:
00121       result=SOUTHWEST;
00122       break;
00123     case NORTHWEST:
00124       result=SOUTHEAST;
00125       break;
00126     case SOUTHEAST:
00127       result=NORTHWEST;
00128       break;
00129     case SOUTHWEST:
00130       result=NORTHEAST;
00131       break;
00132       
00133     default:
00134       result=NONE;
00135     }
00136   return result;
00137 }
00138 
00139 
00140 unsigned CaloDirectionOperations::oppositeDirection(unsigned iside)
00141 {
00142   static unsigned od[8]={2,3,0,1,6,7,4,5};
00143   return od[iside];
00144   //  if(iside>=0&&iside<8) return od[iside];
00145   //  return 999;
00146 }