CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/FastSimulation/CaloGeometryTools/src/CrystalWindowMap.cc

Go to the documentation of this file.
00001 //FAMOS headers
00002 #include "FastSimulation/CaloGeometryTools/interface/CrystalWindowMap.h"
00003 #include "FastSimulation/CaloGeometryTools/interface/CaloGeometryHelper.h"
00004 
00005 #include <algorithm>
00006 
00007 CrystalWindowMap::CrystalWindowMap(const CaloGeometryHelper *calo,const std::vector<Crystal> & cw):
00008   myCalorimeter_(calo),originalVector_(cw)
00009 {
00010   size_=cw.size();
00011   if(size_==0) return;
00012   
00013   // Loop over the crystals in the grid and stores the index number of the 8 neighbours
00014   myNeighbours_.resize(size_);
00015 
00016   for(unsigned ic=0; ic<size_; ++ic)
00017     {
00018       const std::vector<DetId>& neighbours=myCalorimeter_->getNeighbours(cw[ic].getDetId());
00019       myNeighbours_[ic].reserve(8);
00020       for(unsigned in=0; in<8;++in)
00021         {
00022           // Check that the crystal is in the grid
00023 
00024           Crystal::crystalEqual myCrystal(neighbours[in]);
00025           std::vector<Crystal>::const_iterator itcheck;
00026           itcheck=find_if(cw.begin(),cw.end(),myCrystal);
00027           // The neighbour might not be in the grid
00028           if(itcheck==cw.end())
00029             {
00030 //            std::cout << " Ouh la " << std::endl;
00031 //            for(unsigned ic=0;ic<size_;++ic)
00032 //              {
00033 //                std::cout << cw[ic].getDetId().rawId()<<  " " ;
00034 //              }
00035 //            std::cout << std::endl ; 
00036 //            std::cout << " We are looking for " << neighbours[in].rawId() << std::endl;
00037 //            edm::LogWarning("CrystalWindowMap") << " Inconsistency in the CellWindow " << std::endl;      
00038             }
00039           else
00040             {
00041               myNeighbours_[ic].push_back(itcheck-cw.begin());
00042               //              std::cout << " index " << itcheck-cw.begin() << std::endl;
00043             }
00044         }
00045     }
00046 }
00047 
00048 bool 
00049 CrystalWindowMap::getCrystalWindow(unsigned iq,std::vector<unsigned>&  cw ) const
00050 {
00051   if(iq<size_) // iq >= 0, since iq is unsigned
00052     {
00053       cw=myNeighbours_[iq];
00054       return true;
00055     }
00056   else
00057     return false;
00058 }
00059 
00060 bool 
00061 CrystalWindowMap::getCrystalWindow(unsigned iq,const std::vector<unsigned>*  cw) const
00062 {
00063   
00064   if(iq<size_) // iq >= 0, since iq is unsigned
00065     {
00066       cw=&myNeighbours_[iq];
00067       return true;
00068     }
00069   else
00070     return false;
00071     //  std::map<CrystalID,CrystalWindow>::const_iterator itcheck=myMap.find(cell);
00072 }
00073 
00074 const std::vector<unsigned>& 
00075 CrystalWindowMap::getCrystalWindow(unsigned iq, bool& status) const
00076 {
00077   return myNeighbours_[iq];
00078 }
00079