File indexing completed on 2024-04-06 12:11:29
0001 #include "Fireworks/Calo/interface/FWHistSliceSelector.h"
0002
0003 #include "Fireworks/Core/interface/FWModelChangeManager.h"
0004 #include "Fireworks/Core/interface/FWEventItem.h"
0005
0006 #include "TEveCaloData.h"
0007 #include "TH2F.h"
0008 #include "Rtypes.h"
0009
0010 FWHistSliceSelector::FWHistSliceSelector(TH2F* h, const FWEventItem* item) : FWFromSliceSelector(item) { m_hist = h; }
0011
0012 FWHistSliceSelector::~FWHistSliceSelector() {}
0013
0014 bool FWHistSliceSelector::matchCell(const TEveCaloData::CellId_t& iCell, int itemIdx) const {
0015 float eta, phi;
0016 getItemEntryEtaPhi(itemIdx, eta, phi);
0017
0018 int idx = m_hist->FindBin(eta, phi);
0019 int nBinsX = m_hist->GetXaxis()->GetNbins() + 2;
0020
0021 int etaBin, phiBin, w, newPhiBin;
0022 m_hist->GetBinXYZ(idx, etaBin, phiBin, w);
0023
0024 if (aggregatePhiCells()) {
0025 bool match = false;
0026 if (TMath::Abs(eta) > 4.716) {
0027 newPhiBin = ((phiBin + 1) / 4) * 4 - 1;
0028 if (newPhiBin <= 0)
0029 newPhiBin = 71;
0030
0031 idx = etaBin + newPhiBin * nBinsX;
0032 match |= (idx == iCell.fTower);
0033
0034 idx += nBinsX;
0035 match |= (idx == iCell.fTower);
0036
0037 idx += nBinsX;
0038 if (newPhiBin == 71)
0039 idx = etaBin + 1 * nBinsX;
0040 match |= (idx == iCell.fTower);
0041
0042 idx += nBinsX;
0043 match |= (idx == iCell.fTower);
0044 } else if (TMath::Abs(eta) > 1.873) {
0045 newPhiBin = ((phiBin + 1) / 2) * 2 - 1;
0046 idx = etaBin + newPhiBin * nBinsX;
0047 match = (idx == iCell.fTower || idx + nBinsX == iCell.fTower);
0048 } else {
0049 match = (idx == iCell.fTower);
0050 }
0051
0052 return match;
0053 } else {
0054 return idx == iCell.fTower;
0055 }
0056 }
0057
0058 void FWHistSliceSelector::doSelect(const TEveCaloData::CellId_t& iCell) {
0059 if (!m_item)
0060 return;
0061
0062 FWChangeSentry sentry(*(m_item->changeManager()));
0063 size_t size = m_item->size();
0064 for (size_t index = 0; index < size; ++index) {
0065 if (m_item->modelInfo(index).m_displayProperties.isVisible() && !m_item->modelInfo(index).isSelected()) {
0066 if (matchCell(iCell, index)) {
0067 m_item->select(index);
0068 break;
0069 }
0070 }
0071 }
0072 }
0073
0074 void FWHistSliceSelector::doUnselect(const TEveCaloData::CellId_t& iCell) {
0075 if (!m_item)
0076 return;
0077
0078
0079
0080 FWChangeSentry sentry(*(m_item->changeManager()));
0081
0082 size_t size = m_item->size();
0083 for (size_t index = 0; index < size; ++index) {
0084 if (m_item->modelInfo(index).m_displayProperties.isVisible() && m_item->modelInfo(index).isSelected()) {
0085 if (matchCell(iCell, index)) {
0086
0087 m_item->unselect(index);
0088 break;
0089 }
0090 }
0091 }
0092 }