Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "TH2F.h"
00018 #include "TMath.h"
00019 #include "Fireworks/Calo/plugins/FWCaloTowerSliceSelector.h"
00020 #include "Fireworks/Core/interface/FWModelChangeManager.h"
00021 #include "Fireworks/Core/interface/FWEventItem.h"
00022 #include "DataFormats/CaloTowers/interface/CaloTower.h"
00023 #include "DataFormats/CaloTowers/interface/CaloTowerFwd.h"
00024
00025
00026 FWCaloTowerSliceSelector::FWCaloTowerSliceSelector(TH2F* h, const FWEventItem* i):
00027 FWFromSliceSelector(i),
00028 m_hist(h)
00029 {
00030 }
00031
00032 FWCaloTowerSliceSelector::~FWCaloTowerSliceSelector()
00033 {
00034 }
00035
00036
00037
00038
00039
00040
00041 bool
00042 FWCaloTowerSliceSelector::matchCell(const TEveCaloData::CellId_t& iCell, const CaloTower& tower) const
00043 {
00044 bool match = false;
00045 int idx = m_hist->FindBin(tower.eta(), tower.phi());
00046 int nBinsX = m_hist->GetXaxis()->GetNbins() + 2;
00047
00048 int etaBin, phiBin, w, newPhiBin;
00049 m_hist->GetBinXYZ(idx, etaBin, phiBin, w);
00050
00051 if (tower.ietaAbs() > 39)
00052 {
00053 newPhiBin = ((phiBin + 1) / 4) * 4 - 1;
00054 if (newPhiBin <= 0) newPhiBin = 71;
00055
00056 idx = etaBin + newPhiBin*nBinsX;
00057 match |= (idx == iCell.fTower);
00058
00059 idx += nBinsX;
00060 match |= (idx == iCell.fTower);
00061
00062 idx += nBinsX;
00063 if (newPhiBin == 71)
00064 idx = etaBin + 1*nBinsX;
00065 match |= (idx == iCell.fTower);
00066
00067 idx += nBinsX;
00068 match |= (idx == iCell.fTower);
00069 }
00070 else if (tower.ietaAbs() > 20)
00071 {
00072 newPhiBin = ((phiBin + 1) / 2) * 2 -1;
00073 idx = etaBin + newPhiBin*nBinsX;
00074 match = ( idx == iCell.fTower || idx + nBinsX == iCell.fTower);
00075 }
00076 else
00077 {
00078 match = ( idx == iCell.fTower);
00079 }
00080 return match;
00081 }
00082
00083 void
00084 FWCaloTowerSliceSelector::doSelect(const TEveCaloData::CellId_t& iCell)
00085 {
00086 if (!m_item) return;
00087
00088 const CaloTowerCollection* towers=0;
00089 m_item->get(towers);
00090 assert(0!=towers);
00091 int index = 0;
00092
00093 FWChangeSentry sentry(*(m_item->changeManager()));
00094 for(CaloTowerCollection::const_iterator tower = towers->begin(); tower != towers->end(); ++tower,++index)
00095 {
00096 if (m_item->modelInfo(index).m_displayProperties.isVisible() && !m_item->modelInfo(index).isSelected())
00097 {
00098 if (matchCell(iCell, *tower))
00099 {
00100 m_item->select(index);
00101 break;
00102 }
00103 }
00104 }
00105 }
00106
00107 void
00108 FWCaloTowerSliceSelector::doUnselect(const TEveCaloData::CellId_t& iCell)
00109 {
00110 if (!m_item) return;
00111
00112
00113
00114 const CaloTowerCollection* towers=0;
00115 m_item->get(towers);
00116 assert(0!=towers);
00117 int index = 0;
00118 FWChangeSentry sentry(*(m_item->changeManager()));
00119 for(CaloTowerCollection::const_iterator tower = towers->begin(); tower != towers->end(); ++tower,++index)
00120 {
00121 if ( m_item->modelInfo(index).m_displayProperties.isVisible() &&
00122 m_item->modelInfo(index).isSelected()) {
00123 if (matchCell(iCell, *tower))
00124 {
00125
00126 m_item->unselect(index);
00127 break;
00128 }
00129 }
00130 }
00131 }