CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/Fireworks/Calo/plugins/FWHBHERecHitProxyBuilder.cc

Go to the documentation of this file.
00001 #include "TEveCompound.h"
00002 #include "TEveBoxSet.h"
00003 
00004 #include "Fireworks/Core/interface/FWDigitSetProxyBuilder.h"
00005 #include "Fireworks/Core/interface/FWEventItem.h"
00006 #include "Fireworks/Core/interface/FWGeometry.h"
00007 #include "Fireworks/Core/interface/BuilderUtils.h"
00008 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
00009 #include "DataFormats/HcalRecHit/interface/HBHERecHit.h"
00010 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00011 
00012 class FWHBHERecHitProxyBuilder : public FWDigitSetProxyBuilder
00013 {
00014 public:
00015    FWHBHERecHitProxyBuilder( void )
00016       : m_maxEnergy( 0.85 ), m_plotEt(true)
00017     {}
00018   
00019    virtual ~FWHBHERecHitProxyBuilder( void ) 
00020     {}
00021 
00022    virtual bool havePerViewProduct(FWViewType::EType) const { return true; }
00023    virtual void scaleProduct(TEveElementList* parent, FWViewType::EType, const FWViewContext* vc);
00024 
00025    REGISTER_PROXYBUILDER_METHODS();
00026 
00027 private:
00028    virtual void build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* );
00029 
00030    Float_t m_maxEnergy;
00031    bool m_plotEt;
00032 
00033    FWHBHERecHitProxyBuilder( const FWHBHERecHitProxyBuilder& );
00034    const FWHBHERecHitProxyBuilder& operator=( const FWHBHERecHitProxyBuilder& );
00035 };
00036 
00037 void
00038 FWHBHERecHitProxyBuilder::scaleProduct(TEveElementList* parent, FWViewType::EType type, const FWViewContext* vc)
00039 {
00040    if (m_plotEt != vc->getEnergyScale()->getPlotEt() )
00041    {
00042       m_plotEt = !m_plotEt;
00043 
00044       const HBHERecHitCollection* collection = 0;
00045       item()->get( collection );
00046       if (! collection)
00047          return;
00048 
00049       int index = 0;
00050       std::vector<float> scaledCorners(24);
00051       for (std::vector<HBHERecHit>::const_iterator it = collection->begin() ; it != collection->end(); ++it, ++index)
00052       {
00053          const float* corners = item()->getGeom()->getCorners((*it).detid());
00054          if (corners == 0) 
00055             continue;
00056          FWDigitSetProxyBuilder::BFreeBox_t* b = (FWDigitSetProxyBuilder::BFreeBox_t*)getBoxSet()->GetPlex()->Atom(index);
00057 
00058          /*          
00059          printf("--------------------scale product \n");
00060          for (int i = 0; i < 8 ; ++i)
00061             printf("[%f %f %f ]\n",b->fVertices[i][0], b->fVertices[i][1],b->fVertices[i][2] );
00062          */
00063 
00064          if (m_plotEt)
00065             fireworks::etScaledBox3DCorners(corners, (*it).energy(),  m_maxEnergy, scaledCorners, true);
00066          else
00067             fireworks::energyScaledBox3DCorners(corners, (*it).energy() / m_maxEnergy, scaledCorners, true);
00068          
00069          /*
00070          printf("after \n");
00071          for (int i = 0; i < 8 ; ++i)
00072             printf("[%f %f %f ]\n",b->fVertices[i][0], b->fVertices[i][1],b->fVertices[i][2] );        
00073          */
00074          memcpy(b->fVertices, &scaledCorners[0], sizeof(b->fVertices));
00075 
00076       }
00077       getBoxSet()->ElementChanged();
00078    }
00079 }
00080 
00081 //______________________________________________________________________________
00082 
00083 void
00084 FWHBHERecHitProxyBuilder::build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* vc)
00085 {
00086    m_plotEt = vc->getEnergyScale()->getPlotEt();
00087 
00088    const HBHERecHitCollection* collection = 0;
00089    iItem->get( collection );
00090 
00091    if( 0 == collection )
00092    {
00093       return;
00094    }
00095    std::vector<HBHERecHit>::const_iterator it = collection->begin();
00096    std::vector<HBHERecHit>::const_iterator itEnd = collection->end();
00097    std::vector<float> scaledCorners(24);
00098 
00099    for( ; it != itEnd; ++it )
00100    {
00101       if(( *it ).energy() > m_maxEnergy )
00102          m_maxEnergy = ( *it ).energy();
00103    }
00104 
00105    TEveBoxSet* boxSet = addBoxSetToProduct(product);
00106    int index = 0;
00107    for (std::vector<HBHERecHit>::const_iterator it = collection->begin() ; it != collection->end(); ++it)
00108    {  
00109       const float* corners = context().getGeom()->getCorners((*it).detid());
00110       if (corners)
00111       {
00112          if (m_plotEt)
00113             fireworks::etScaledBox3DCorners(corners, (*it).energy(), m_maxEnergy, scaledCorners, true);
00114          else
00115             fireworks::energyScaledBox3DCorners(corners, (*it).energy() / m_maxEnergy, scaledCorners, true);
00116       }
00117       addBox(boxSet, &scaledCorners[0], iItem->modelInfo(index++).displayProperties());
00118    }
00119 }
00120 
00121 REGISTER_FWPROXYBUILDER( FWHBHERecHitProxyBuilder, HBHERecHitCollection, "HBHE RecHit", FWViewType::kISpyBit );