CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Fireworks/Calo/plugins/FWCaloTowerSliceSelector.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Calo
00004 // Class  :     FWCaloTowerSliceSelector
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Alja Mrak-Tadel
00010 //         Created:  Wed Jun  2 17:36:23 CEST 2010
00011 // $Id: FWCaloTowerSliceSelector.cc,v 1.3 2010/12/01 21:40:31 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
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 // member functions
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    //  std::cout <<"  doUnselect "<<std::endl;
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             //  std::cout <<"  doUnselect "<<index<<std::endl;
00126             m_item->unselect(index);
00127             break;
00128          }
00129       }
00130    }
00131 }