Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:00:39

0001 //FAMOS headers
0002 #include "FastSimulation/CaloGeometryTools/interface/CrystalWindowMap.h"
0003 #include "FastSimulation/CaloGeometryTools/interface/CaloGeometryHelper.h"
0004 
0005 #include <algorithm>
0006 
0007 CrystalWindowMap::CrystalWindowMap(const CaloGeometryHelper* calo, const std::vector<Crystal>& cw)
0008     : myCalorimeter_(calo), originalVector_(cw) {
0009   size_ = cw.size();
0010   if (size_ == 0)
0011     return;
0012 
0013   // Loop over the crystals in the grid and stores the index number of the 8 neighbours
0014   myNeighbours_.resize(size_);
0015 
0016   for (unsigned ic = 0; ic < size_; ++ic) {
0017     const CaloGeometryHelper::NeiVect& neighbours = myCalorimeter_->getNeighbours(cw[ic].getDetId());
0018     myNeighbours_[ic].reserve(8);
0019     for (unsigned in = 0; in < 8; ++in) {
0020       // Check that the crystal is in the grid
0021 
0022       Crystal::crystalEqual myCrystal(neighbours[in]);
0023       std::vector<Crystal>::const_iterator itcheck;
0024       itcheck = find_if(cw.begin(), cw.end(), myCrystal);
0025       // The neighbour might not be in the grid
0026       if (itcheck == cw.end()) {
0027         //        std::cout << " Ouh la " << std::endl;
0028         //        for(unsigned ic=0;ic<size_;++ic)
0029         //      {
0030         //        std::cout << cw[ic].getDetId().rawId()<<  " " ;
0031         //      }
0032         //        std::cout << std::endl ;
0033         //        std::cout << " We are looking for " << neighbours[in].rawId() << std::endl;
0034         //        edm::LogWarning("CrystalWindowMap") << " Inconsistency in the CellWindow " << std::endl;
0035       } else {
0036         myNeighbours_[ic].push_back(itcheck - cw.begin());
0037         //        std::cout << " index " << itcheck-cw.begin() << std::endl;
0038       }
0039     }
0040   }
0041 }
0042 
0043 bool CrystalWindowMap::getCrystalWindow(unsigned iq, std::vector<unsigned>& cw) const {
0044   if (iq < size_)  // iq >= 0, since iq is unsigned
0045   {
0046     cw = myNeighbours_[iq];
0047     return true;
0048   } else
0049     return false;
0050 }
0051 
0052 bool CrystalWindowMap::getCrystalWindow(unsigned iq, const std::vector<unsigned>* cw) const {
0053   if (iq < size_)  // iq >= 0, since iq is unsigned
0054   {
0055     cw = &myNeighbours_[iq];
0056     return true;
0057   } else
0058     return false;
0059   //  std::map<CrystalID,CrystalWindow>::const_iterator itcheck=myMap.find(cell);
0060 }
0061 
0062 const std::vector<unsigned>& CrystalWindowMap::getCrystalWindow(unsigned iq, bool& status) const {
0063   return myNeighbours_[iq];
0064 }