Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:57

0001 // -*- C++ -*-
0002 //
0003 // Package:     Calo
0004 // Class  :     FWHGTowerSliceSelector
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Alja Mrak-Tadel
0010 //         Created:  Wed Jun  2 17:39:44 CEST 2010
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "TEveVector.h"
0017 #include "TEveCaloData.h"
0018 #include "TH2F.h"
0019 
0020 #include "Fireworks/Calo/plugins/FWHGTowerSliceSelector.h"
0021 #include "Fireworks/Core/interface/FWModelChangeManager.h"
0022 #include "Fireworks/Core/interface/FWEventItem.h"
0023 #include "Fireworks/Core/interface/FWGeometry.h"
0024 #include "Fireworks/Core/interface/fwLog.h"
0025 #include "DataFormats/DetId/interface/DetId.h"
0026 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0027 
0028 //
0029 // member functions
0030 //
0031 
0032 void FWHGTowerSliceSelector::doSelect(const TEveCaloData::CellId_t& iCell) {
0033   if (!m_item)
0034     return;
0035 
0036   const HGCRecHitCollection* hits = nullptr;
0037   m_item->get(hits);
0038   assert(nullptr != hits);
0039 
0040   int index = 0;
0041   FWChangeSentry sentry(*(m_item->changeManager()));
0042   for (HGCRecHitCollection::const_iterator it = hits->begin(); it != hits->end(); ++it, ++index) {
0043     DetId id((*it).detid());
0044     if (findBinFromId(id, iCell.fTower) && m_item->modelInfo(index).m_displayProperties.isVisible() &&
0045         !m_item->modelInfo(index).isSelected()) {
0046       // std::cout <<"  doSelect "<<index<<std::endl;
0047       m_item->select(index);
0048     }
0049   }
0050 }
0051 
0052 void FWHGTowerSliceSelector::doUnselect(const TEveCaloData::CellId_t& iCell) {
0053   if (!m_item)
0054     return;
0055 
0056   const HGCRecHitCollection* hits = nullptr;
0057   m_item->get(hits);
0058   assert(nullptr != hits);
0059 
0060   int index = 0;
0061   FWChangeSentry sentry(*(m_item->changeManager()));
0062   for (HGCRecHitCollection::const_iterator it = hits->begin(); it != hits->end(); ++it, ++index) {
0063     DetId id((*it).detid());
0064     if (findBinFromId(id, iCell.fTower) && m_item->modelInfo(index).m_displayProperties.isVisible() &&
0065         m_item->modelInfo(index).isSelected()) {
0066       // std::cout <<"  doUnselect "<<index<<std::endl;
0067       m_item->unselect(index);
0068     }
0069   }
0070 }
0071 
0072 bool FWHGTowerSliceSelector::findBinFromId(DetId& detId, int tower) const {
0073   TEveCaloData::vCellId_t cellIds;
0074   const float* corners = m_item->getGeom()->getCorners(detId);
0075   if (corners == nullptr) {
0076     fwLog(fwlog::kInfo) << "FWHGTowerSliceSelector cannot get geometry for DetId: " << detId.rawId() << ". Ignored.\n";
0077     return false;
0078   }
0079   std::vector<TEveVector> front(4);
0080   float eta = 0, phi = 0;
0081   int j = 0;
0082   for (int i = 0; i < 4; ++i) {
0083     front[i] = TEveVector(corners[j], corners[j + 1], corners[j + 2]);
0084     j += 3;
0085 
0086     eta += front[i].Eta();
0087     phi += front[i].Phi();
0088   }
0089   eta /= 4;
0090   phi /= 4;
0091 
0092   const TEveCaloData::CellGeom_t& cg = m_vecData->GetCellGeom()[tower];
0093   if ((eta >= cg.fEtaMin && eta <= cg.fEtaMax) && (phi >= cg.fPhiMin && phi <= cg.fPhiMax)) {
0094     return true;
0095   }
0096 
0097   return false;
0098 }