CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/Fireworks/Calo/plugins/FWEcalRecHitProxyBuilder.cc

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