CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/Fireworks/Calo/plugins/FWCaloTowerProxyBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Calo
00004 // Class  :     FWCaloTowerProxyBuilderBase
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Wed Dec  3 11:28:28 EST 2008
00011 // $Id: FWCaloTowerProxyBuilder.cc,v 1.25 2011/02/23 11:34:52 amraktad Exp $
00012 //
00013 
00014 // system includes
00015 #include <math.h>
00016 
00017 // user includes
00018 #include "TEveCaloData.h"
00019 #include "TEveCalo.h"
00020 #include "TH2F.h"
00021 
00022 #include "Fireworks/Core/interface/Context.h"
00023 #include "Fireworks/Core/interface/FWEventItem.h"
00024 #include "Fireworks/Core/interface/FWModelChangeManager.h"
00025 
00026 #include "Fireworks/Core/interface/fw3dlego_xbins.h"
00027 #include "Fireworks/Calo/plugins/FWCaloTowerProxyBuilder.h"
00028 #include "Fireworks/Calo/plugins/FWCaloTowerSliceSelector.h"
00029 
00030 #include "DataFormats/CaloTowers/interface/CaloTower.h"
00031 
00032 
00033 
00034 //
00035 // constructors , dectructors
00036 //
00037 FWCaloTowerProxyBuilderBase::FWCaloTowerProxyBuilderBase():
00038 m_towers(0),
00039 m_hist(0)
00040 {
00041 }
00042 
00043 FWCaloTowerProxyBuilderBase::~FWCaloTowerProxyBuilderBase()
00044 {
00045 }
00046 
00047 //
00048 // member functions
00049 //
00050 
00051 void
00052 FWCaloTowerProxyBuilderBase::setCaloData(const fireworks::Context&)
00053 {
00054   m_caloData = context().getCaloData();
00055 }
00056 
00057 
00058 void
00059 FWCaloTowerProxyBuilderBase::build(const FWEventItem* iItem,
00060                                    TEveElementList* el, const FWViewContext* ctx)
00061 {
00062    m_towers=0;
00063    if (iItem)
00064    {
00065       iItem->get(m_towers);
00066       FWCaloDataProxyBuilderBase::build(iItem, el, ctx);
00067    }
00068 }
00069 
00070 void
00071 FWCaloTowerProxyBuilderBase::itemBeingDestroyed(const FWEventItem* iItem)
00072 {
00073   
00074    if(0!=m_hist) {
00075       m_hist->Reset();
00076    }
00077    FWCaloDataProxyBuilderBase::itemBeingDestroyed(iItem);
00078 }
00079 
00080 double
00081 wrapPi(double val)
00082 {
00083    using namespace TMath;
00084 
00085    if (val< -Pi())
00086    {
00087       return val += TwoPi();
00088    }
00089    if (val> Pi())
00090    {
00091       return val -= TwoPi();
00092    }
00093    return val;
00094 }
00095 
00096 void
00097 FWCaloTowerProxyBuilderBase::fillCaloData()
00098 {
00099    static float d = 2.5*TMath::Pi()/180;
00100    m_hist->Reset();
00101 
00102    if (m_towers)
00103    {
00104       TEveCaloData::vCellId_t& selected = m_caloData->GetCellsSelected();
00105 
00106       if(item()->defaultDisplayProperties().isVisible()) {
00107          // assert(item()->size() >= m_towers->size());
00108          unsigned int index=0;
00109          for(CaloTowerCollection::const_iterator tower = m_towers->begin(); tower != m_towers->end(); ++tower,++index) {
00110             const FWEventItem::ModelInfo& info = item()->modelInfo(index);
00111             if(info.displayProperties().isVisible()) {
00112                if (tower->ietaAbs() > 39)
00113                {
00114                   m_hist->Fill(tower->eta(),wrapPi(tower->phi() - 3*d), getEt(*tower) *0.25);
00115                   m_hist->Fill(tower->eta(),wrapPi(tower->phi() -   d), getEt(*tower) *0.25);
00116                   m_hist->Fill(tower->eta(),wrapPi(tower->phi() +   d), getEt(*tower) *0.25);
00117                   m_hist->Fill(tower->eta(),wrapPi(tower->phi() + 3*d), getEt(*tower) *0.25);
00118                }
00119                else if (tower->ietaAbs() > 20)
00120                {
00121                   m_hist->Fill(tower->eta(),wrapPi(tower->phi() - d), getEt(*tower) *0.5);
00122                   m_hist->Fill(tower->eta(),wrapPi(tower->phi() + d), getEt(*tower) *0.5);
00123                }
00124                else
00125                {
00126                   m_hist->Fill(tower->eta(),tower->phi(), getEt(*tower));
00127                }
00128             }
00129             if(info.isSelected()) {
00130                //NOTE: I tried calling TEveCalo::GetCellList but it always returned 0, probably because of threshold issues
00131                // but looking at the TEveCaloHist::GetCellList code the CellId_t is just the histograms bin # and the slice
00132                // printf("applyChangesToAllModels ...check selected \n");
00133 
00134                if (tower->ietaAbs() > 39)
00135                {
00136                   selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() -3*d)),m_sliceIndex));
00137                   selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() -d))  ,m_sliceIndex));
00138                   selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() +d))  ,m_sliceIndex));
00139                   selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() +3*d)),m_sliceIndex));
00140                }
00141                else if (tower->ietaAbs() > 20)
00142                {
00143                   selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() -d)), m_sliceIndex));
00144                   selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(), wrapPi(tower->phi() +d)), m_sliceIndex));
00145                }
00146                else
00147                {
00148                   selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(tower->eta(),tower->phi()),m_sliceIndex));
00149                }
00150             }
00151          }
00152       }
00153    }
00154 
00155 }
00156 
00157 //______________________________________________________________________________
00158 bool
00159 FWCaloTowerProxyBuilderBase::assertCaloDataSlice()
00160 {
00161    if (m_hist == 0)
00162    {
00163       // add new slice
00164       Bool_t status = TH1::AddDirectoryStatus();
00165       TH1::AddDirectory(kFALSE); //Keeps histogram from going into memory
00166       m_hist = new TH2F("caloHist",
00167                         "caloHist",
00168                         fw3dlego::xbins_n - 1, fw3dlego::xbins,
00169                         72, -M_PI, M_PI);
00170       TH1::AddDirectory(status);
00171       TEveCaloDataHist* ch = static_cast<TEveCaloDataHist*>(m_caloData);
00172       m_sliceIndex = ch->AddHistogram(m_hist);
00173 
00174 
00175 
00176       m_caloData->RefSliceInfo(m_sliceIndex).Setup(item()->name().c_str(), 0., 
00177                                                    item()->defaultDisplayProperties().color(),
00178                                                    item()->defaultDisplayProperties().transparency());
00179 
00180       // add new selector
00181       FWFromTEveCaloDataSelector* sel = 0;
00182       if (m_caloData->GetUserData())
00183       {
00184          FWFromEveSelectorBase* base = reinterpret_cast<FWFromEveSelectorBase*>(m_caloData->GetUserData());
00185          assert(0!=base);
00186          sel = dynamic_cast<FWFromTEveCaloDataSelector*> (base);
00187          assert(0!=sel);
00188       }
00189       else
00190       {
00191          sel = new FWFromTEveCaloDataSelector(m_caloData);
00192          //make sure it is accessible via the base class
00193          m_caloData->SetUserData(static_cast<FWFromEveSelectorBase*>(sel));
00194       }
00195      
00196       sel->addSliceSelector(m_sliceIndex, new FWCaloTowerSliceSelector(m_hist,item()));
00197      
00198       return true;
00199    }
00200    return false;
00201 }
00202 
00203 REGISTER_FWPROXYBUILDER(FWECalCaloTowerProxyBuilder,CaloTowerCollection,"ECal",FWViewType::k3DBit|FWViewType::kAllRPZBits|FWViewType::kAllLegoBits);
00204 REGISTER_FWPROXYBUILDER(FWHCalCaloTowerProxyBuilder,CaloTowerCollection,"HCal",FWViewType::k3DBit|FWViewType::kAllRPZBits|FWViewType::kAllLegoBits );
00205 REGISTER_FWPROXYBUILDER(FWHOCaloTowerProxyBuilder,CaloTowerCollection,"HCal Outer",FWViewType::k3DBit|FWViewType::kAllRPZBits|FWViewType::kAllLegoBits );
00206 
00207 
00208