Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
#include "Fireworks/Calo/interface/FWHistSliceSelector.h"

#include "Fireworks/Core/interface/FWModelChangeManager.h"
#include "Fireworks/Core/interface/FWEventItem.h"

#include "TEveCaloData.h"
#include "TH2F.h"
#include "Rtypes.h"

FWHistSliceSelector::FWHistSliceSelector(TH2F* h, const FWEventItem* item) : FWFromSliceSelector(item) { m_hist = h; }

FWHistSliceSelector::~FWHistSliceSelector() {}

bool FWHistSliceSelector::matchCell(const TEveCaloData::CellId_t& iCell, int itemIdx) const {
  float eta, phi;
  getItemEntryEtaPhi(itemIdx, eta, phi);

  int idx = m_hist->FindBin(eta, phi);
  int nBinsX = m_hist->GetXaxis()->GetNbins() + 2;

  int etaBin, phiBin, w, newPhiBin;
  m_hist->GetBinXYZ(idx, etaBin, phiBin, w);

  if (aggregatePhiCells()) {
    bool match = false;
    if (TMath::Abs(eta) > 4.716) {
      newPhiBin = ((phiBin + 1) / 4) * 4 - 1;
      if (newPhiBin <= 0)
        newPhiBin = 71;

      idx = etaBin + newPhiBin * nBinsX;
      match |= (idx == iCell.fTower);

      idx += nBinsX;
      match |= (idx == iCell.fTower);

      idx += nBinsX;
      if (newPhiBin == 71)
        idx = etaBin + 1 * nBinsX;
      match |= (idx == iCell.fTower);

      idx += nBinsX;
      match |= (idx == iCell.fTower);
    } else if (TMath::Abs(eta) > 1.873) {
      newPhiBin = ((phiBin + 1) / 2) * 2 - 1;
      idx = etaBin + newPhiBin * nBinsX;
      match = (idx == iCell.fTower || idx + nBinsX == iCell.fTower);
    } else {
      match = (idx == iCell.fTower);
    }

    return match;
  } else {
    return idx == iCell.fTower;
  }
}

void FWHistSliceSelector::doSelect(const TEveCaloData::CellId_t& iCell) {
  if (!m_item)
    return;

  FWChangeSentry sentry(*(m_item->changeManager()));
  size_t size = m_item->size();
  for (size_t index = 0; index < size; ++index) {
    if (m_item->modelInfo(index).m_displayProperties.isVisible() && !m_item->modelInfo(index).isSelected()) {
      if (matchCell(iCell, index)) {
        m_item->select(index);
        break;
      }
    }
  }
}

void FWHistSliceSelector::doUnselect(const TEveCaloData::CellId_t& iCell) {
  if (!m_item)
    return;

  //  std::cout <<"  doUnselect "<<std::endl;

  FWChangeSentry sentry(*(m_item->changeManager()));

  size_t size = m_item->size();
  for (size_t index = 0; index < size; ++index) {
    if (m_item->modelInfo(index).m_displayProperties.isVisible() && m_item->modelInfo(index).isSelected()) {
      if (matchCell(iCell, index)) {
        //  std::cout <<"  doUnselect "<<index<<std::endl;
        m_item->unselect(index);
        break;
      }
    }
  }
}