CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/Fireworks/Calo/plugins/FWHFTowerSliceSelector.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Calo
00004 // Class  :     FWHFTowerSliceSelector
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Alja Mrak-Tadel
00010 //         Created:  Wed Jun  2 17:39:44 CEST 2010
00011 // $Id: FWHFTowerSliceSelector.cc,v 1.9 2010/09/07 15:46:45 yana Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "TEveVector.h"
00018 #include "TEveCaloData.h"
00019 #include "TH2F.h"
00020 
00021 #include "Fireworks/Calo/plugins/FWHFTowerSliceSelector.h"
00022 #include "Fireworks/Core/interface/FWModelChangeManager.h"
00023 #include "Fireworks/Core/interface/FWEventItem.h"
00024 #include "Fireworks/Core/interface/FWGeometry.h"
00025 #include "Fireworks/Core/interface/fwLog.h"
00026 #include "DataFormats/HcalRecHit/interface/HFRecHit.h"
00027 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00028 
00029 
00030 //
00031 // member functions
00032 //
00033 
00034 void
00035 FWHFTowerSliceSelector::doSelect(const TEveCaloData::CellId_t& iCell)
00036 {
00037    if (!m_item) return;
00038 
00039    const HFRecHitCollection* hits=0;
00040    m_item->get(hits);
00041    assert(0!=hits);
00042 
00043    int index = 0;
00044    FWChangeSentry sentry(*(m_item->changeManager()));
00045    for(HFRecHitCollection::const_iterator it = hits->begin(); it != hits->end(); ++it,++index)
00046    {
00047       HcalDetId id ((*it).detid().rawId());
00048       if (findBinFromId(id, iCell.fTower) && 
00049           m_item->modelInfo(index).m_displayProperties.isVisible() &&
00050           !m_item->modelInfo(index).isSelected()) {
00051          // std::cout <<"  doSelect "<<index<<std::endl;
00052          m_item->select(index);
00053       }
00054    }
00055 }
00056 
00057 void
00058 FWHFTowerSliceSelector::doUnselect(const TEveCaloData::CellId_t& iCell)
00059 {
00060    if (!m_item) return;
00061 
00062    const HFRecHitCollection* hits=0;
00063    m_item->get(hits);
00064    assert(0!=hits);
00065 
00066    int index = 0;
00067    FWChangeSentry sentry(*(m_item->changeManager()));
00068    for(HFRecHitCollection::const_iterator it = hits->begin(); it != hits->end(); ++it,++index)
00069    {
00070       HcalDetId id ((*it).detid().rawId());
00071       if (findBinFromId(id, iCell.fTower) && 
00072           m_item->modelInfo(index).m_displayProperties.isVisible() &&
00073           m_item->modelInfo(index).isSelected()) {
00074          // std::cout <<"  doUnselect "<<index<<std::endl;
00075          m_item->unselect(index);
00076       }
00077    }
00078 }
00079 
00080 bool
00081 FWHFTowerSliceSelector::findBinFromId( HcalDetId& detId, int tower) const
00082 {    
00083    TEveCaloData::vCellId_t cellIds;
00084    const float* corners = m_item->getGeom()->getCorners( detId.rawId());
00085    if( corners == 0 )
00086    {
00087      fwLog( fwlog::kInfo ) << "FWHFTowerSliceSelector cannot get geometry for DetId: "<< detId.rawId() << ". Ignored.\n";
00088      return false;
00089    }
00090    std::vector<TEveVector> front( 4 );
00091    float eta = 0, phi = 0;
00092    int j = 0;
00093    for( int i = 0; i < 4; ++i )
00094    {
00095      front[i] = TEveVector( corners[j], corners[j + 1], corners[j + 2] );
00096      j +=3;
00097 
00098      eta += front[i].Eta();
00099      phi += front[i].Phi();
00100    }
00101    eta /= 4;
00102    phi /= 4;
00103 
00104    const TEveCaloData::CellGeom_t &cg = m_vecData->GetCellGeom()[tower] ;
00105    if(( eta >= cg.fEtaMin && eta <= cg.fEtaMax) && (phi >= cg.fPhiMin && phi <= cg.fPhiMax))
00106    {
00107       return true;
00108    }
00109 
00110    return false;
00111 }