CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Geometry/ForwardGeometry/src/CastorTopology.cc

Go to the documentation of this file.
00001 #include "Geometry/ForwardGeometry/interface/CastorTopology.h"
00002 #include <cmath>
00003 #include <iostream>
00004 #include <algorithm>
00005 
00006 static const int MODULE_EM_MAX = 2;
00007 static const int MODULE_HAD_MAX = 12;
00008 
00009 CastorTopology::CastorTopology() :
00010    excludeEM_(false),
00011    excludeHAD_(false),
00012    excludeZP_(false),
00013    excludeZN_(false),
00014    firstEMModule_(1),
00015    lastEMModule_(2),
00016    firstHADModule_(3),
00017    lastHADModule_(14)
00018 {
00019 }
00020 
00021 bool 
00022 CastorTopology::valid(const HcalCastorDetId& id) const 
00023 {
00024    return ( validRaw( id )  &&
00025             !isExcluded( id )  ) ;
00026 }
00027 
00028 bool CastorTopology::isExcluded(const HcalCastorDetId& id) const {
00029   bool exed=false;
00030 
00031   //check the for side exclusions
00032   switch(id.zside()){
00033   case( 1): exed = excludeZP_; break;
00034   case(-1): exed = excludeZN_; break;
00035   default: exed = false;
00036   }
00037 
00038   // check for section exclutions
00039   switch (id.section()) {
00040   case(HcalCastorDetId::EM)  : exed = excludeEM_; break; 
00041   case(HcalCastorDetId::HAD) : exed = excludeHAD_; break; 
00042   default: exed = false;
00043   }
00044 
00045   // check the entire list
00046   if (!exed && !exclusionList_.empty()) {
00047     std::vector<HcalCastorDetId>::const_iterator 
00048       i=std::lower_bound(exclusionList_.begin(),exclusionList_.end(),id);
00049     if (i!=exclusionList_.end() && *i==id) exed=true;
00050   }
00051   return exed;
00052 }
00053 
00054 void CastorTopology::exclude(const HcalCastorDetId& id) {
00055   std::vector<HcalCastorDetId>::iterator 
00056     i=std::lower_bound(exclusionList_.begin(),exclusionList_.end(),id);
00057   if (i==exclusionList_.end() || *i!=id) {
00058     exclusionList_.insert(i,id);
00059   }
00060 }
00061 
00062 void CastorTopology::exclude(int zside) {
00063  switch(zside){
00064   case( 1): excludeZP_ = true; break;
00065   case(-1): excludeZN_ = true; break;
00066   default: break;
00067   }
00068 }
00069 
00070 void CastorTopology::exclude(int zside, HcalCastorDetId::Section section) {
00071   switch(zside){
00072   case( 1): excludeZP_ = true; break;
00073   case(-1): excludeZN_ = true; break;
00074   default: break;
00075   }
00076   switch (section) {
00077   case(HcalCastorDetId::EM)  : excludeEM_ = true; break; 
00078   case(HcalCastorDetId::HAD) : excludeHAD_ = true; break; 
00079   default: break;
00080   }
00081 }
00082 
00083 int CastorTopology::exclude(int zside, HcalCastorDetId::Section section1, int isec1, int imod1, 
00084 HcalCastorDetId::Section section2, int isec2, int imod2) {
00085   bool exed = false;
00086   switch(zside){
00087   case( 1): exed = excludeZP_; break;
00088   case(-1): exed = excludeZN_; break;
00089   default: exed = false;
00090   }
00091   if (exed) return 0;
00092 
00093 
00094 /* NOTE not so sure about the exclusion */
00095   if (section1 == HcalCastorDetId::EM && section2 == HcalCastorDetId::EM) {
00096         exed = excludeEM_; }
00097   else if (section1 == HcalCastorDetId::HAD && section2 == HcalCastorDetId::HAD) {
00098         exed = excludeHAD_; }
00099   else { exed = false; };
00100 
00101   if (exed) return 0;
00102 
00103   bool isPositive = false;
00104   if(zside == 1)isPositive = true;
00105 
00106   int n = 0;
00107   for (int isec = isec1; isec < isec2; isec++){
00108      for (int imod = imod1; imod < imod2; imod++) {
00109     HcalCastorDetId id(section1, isPositive, isec, imod);  
00110     if(validRaw(id))exclude(id);
00111     n++;
00112    }
00113   }
00114   return n;
00115 }
00116 
00117 bool CastorTopology::validRaw(const HcalCastorDetId& id) const
00118 {
00119    return HcalCastorDetId::validDetId( id.section(),
00120                                        id.zside()>0,
00121                                        id.sector(),
00122                                        id.module()  )  ;
00123 }
00124 
00125 std::vector<DetId> CastorTopology::incSector(const DetId& id) const{
00126   std::vector<DetId> vNeighborsDetId;
00127   HcalCastorDetId castorId = HcalCastorDetId(id);
00128   HcalCastorDetId castorDetId;
00129   if(validRaw(castorId)) {
00130     bool isPositive = false;
00131     if(castorId.zside()==1)isPositive = true;
00132     if(castorId.sector()==1) {
00133       castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector()+1, 
00134 castorId.module());
00135       vNeighborsDetId.push_back(castorDetId.rawId());
00136       return vNeighborsDetId;
00137     }
00138     if(castorId.sector()== 16){
00139       castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector()-1, 
00140 castorId.module());
00141       vNeighborsDetId.push_back(castorDetId.rawId());
00142       return vNeighborsDetId;
00143     }
00144     castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector()-1, 
00145 castorId.module());
00146     vNeighborsDetId.push_back(castorDetId.rawId());
00147     castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector()+1, 
00148 castorId.module());
00149     vNeighborsDetId.push_back(castorDetId.rawId());
00150   }
00151   return vNeighborsDetId;
00152 }
00153 
00154 std::vector<DetId> CastorTopology::incModule(const DetId& id) const{
00155   std::vector<DetId> vNeighborsDetId;
00156   HcalCastorDetId castorId = HcalCastorDetId(id);
00157   HcalCastorDetId castorDetId;
00158   if(validRaw(castorId) && castorId.section()== HcalCastorDetId::EM){
00159     bool isPositive = false;
00160     if(castorId.zside()==1)isPositive = true;
00161     if(castorId.module()==1){
00162       castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()+1);
00163       vNeighborsDetId.push_back(castorDetId.rawId());
00164       return vNeighborsDetId;
00165     }
00166     if(castorId.module()== MODULE_EM_MAX){
00167       castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()-1);
00168       vNeighborsDetId.push_back(castorDetId.rawId());
00169       return vNeighborsDetId;
00170     }
00171     castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()-1);
00172     vNeighborsDetId.push_back(castorDetId.rawId());
00173     castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()+1);
00174     vNeighborsDetId.push_back(castorDetId.rawId());
00175   }
00176   if(validRaw(castorId) && castorId.section()== HcalCastorDetId::HAD){
00177     bool isPositive = false;
00178     if(castorId.zside()==1)isPositive = true;
00179     if(castorId.module()==1){
00180       castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()+1);
00181       vNeighborsDetId.push_back(castorDetId.rawId());
00182       return vNeighborsDetId;
00183     }
00184     if(castorId.module()== MODULE_HAD_MAX){
00185       castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()-1);
00186       vNeighborsDetId.push_back(castorDetId.rawId());
00187       return vNeighborsDetId;
00188     }
00189   }
00190   return vNeighborsDetId;
00191 }
00192 
00193   
00194 std::vector<DetId> CastorTopology::east(const DetId& /*id*/) const
00195 {
00196   std::cout << "CastorTopology::east() not yet implemented" << std::endl;
00197   std::vector<DetId> vNeighborsDetId;
00198   return  vNeighborsDetId;
00199 }
00200 
00201 std::vector<DetId> CastorTopology::west(const DetId& /*id*/) const
00202 {
00203   std::cout << "CastorTopology::west() not yet implemented" << std::endl;
00204   std::vector<DetId> vNeighborsDetId;
00205   return  vNeighborsDetId;
00206 }
00207 
00208 std::vector<DetId> CastorTopology::north(const DetId& /*id*/) const
00209 {
00210   std::cout << "CastorTopology::north() not yet implemented" << std::endl;
00211   std::vector<DetId> vNeighborsDetId;
00212   return  vNeighborsDetId;
00213 }
00214 std::vector<DetId> CastorTopology::south(const DetId& /*id*/) const
00215 {
00216   std::cout << "CastorTopology::south() not yet implemented" << std::endl;
00217   std::vector<DetId> vNeighborsDetId;
00218   return  vNeighborsDetId;
00219 }
00220 std::vector<DetId> CastorTopology::up(const DetId& /*id*/) const
00221 {
00222   std::cout << "CastorTopology::up() not yet implemented" << std::endl;
00223   std::vector<DetId> vNeighborsDetId;
00224   return  vNeighborsDetId;
00225 }
00226 std::vector<DetId> CastorTopology::down(const DetId& /*id*/) const
00227 {
00228   std::cout << "CastorTopology::down() not yet implemented" << std::endl;
00229   std::vector<DetId> vNeighborsDetId;
00230   return  vNeighborsDetId;
00231 }
00232 
00233 int CastorTopology::ncells(HcalCastorDetId::Section section) const{
00234   int ncells = 0;
00235   switch (section) {
00236   case(HcalCastorDetId::EM)  : ncells = MODULE_EM_MAX*16; break;
00237   case(HcalCastorDetId::HAD) : ncells = MODULE_HAD_MAX*16; break; 
00238   case(HcalCastorDetId::Unknown) : ncells =0; break;
00239   }
00240   return ncells;
00241 }
00242 
00243 int CastorTopology::firstCell(HcalCastorDetId::Section section)const {
00244   int firstCell = 0;
00245   switch (section) {
00246   case(HcalCastorDetId::EM) : firstCell = firstEMModule_ ; break;
00247   case(HcalCastorDetId::HAD) : firstCell = firstHADModule_; break; 
00248   case(HcalCastorDetId::Unknown) : firstCell  = 0; break;
00249   }
00250   return firstCell;
00251 }
00252 
00253 int CastorTopology::lastCell(HcalCastorDetId::Section section) const {
00254   int lastCell = 0;
00255   switch (section) {
00256   case(HcalCastorDetId::EM) : lastCell = lastEMModule_; break;
00257   case(HcalCastorDetId::HAD) : lastCell = lastHADModule_; break; 
00258   case(HcalCastorDetId::Unknown) : lastCell  = 0; break;
00259   }
00260   return lastCell;
00261 }
00262 
00263 
00264