CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Fireworks/ParticleFlow/plugins/FWPFRhoPhiRecHit.cc

Go to the documentation of this file.
00001 #include "FWPFRhoPhiRecHit.h"
00002 
00003 //______________________________________________________________________________
00004 FWPFRhoPhiRecHit::FWPFRhoPhiRecHit( FWProxyBuilderBase *pb, TEveElement *iH, const FWViewContext *vc,
00005                                     float E, float et, double lPhi, double rPhi, std::vector<TEveVector> &bCorners )
00006 : m_hasChild(false), m_energy(E), m_et(et), m_lPhi(lPhi), m_rPhi(rPhi)
00007 {
00008    buildRecHit( pb, iH, vc, bCorners );
00009 }
00010 
00011 //______________________________________________________________________________
00012 FWPFRhoPhiRecHit::~FWPFRhoPhiRecHit(){}
00013 
00014 //______________________________________________________________________________
00015 void
00016 FWPFRhoPhiRecHit::updateScale( const FWViewContext *vc )
00017 {
00018    FWViewEnergyScale *caloScale = vc->getEnergyScale();
00019    float value = caloScale->getPlotEt() ? m_et : m_energy;
00020    Double_t scale = caloScale->getScaleFactor3D() * value;
00021    unsigned int a = 0;
00022 
00023    if( scale < 0.f )
00024       scale *= -1.f;
00025 
00026    // Scale centres
00027    TEveVector sc1 = m_corners[1];
00028    TEveVector sc2 = m_corners[0];
00029 
00030    // Used to store normalized vectors
00031    TEveVector v1 = sc1;   // Bottom right corner
00032    TEveVector v2 = sc2;   // Bottom left corner
00033 
00034    v1.Normalize();
00035    v2.Normalize();
00036 
00037    v1 *= scale;                           // Now at new height
00038    v2 *= scale;
00039 
00040 
00041    // Get line parameters and scale coordinates
00042    TEveChunkManager::iterator li( m_ls->GetLinePlex() );
00043    while( li.next() )
00044    {
00045       TEveStraightLineSet::Line_t &l = *( TEveStraightLineSet::Line_t* ) li();
00046       switch( a )
00047       {
00048          case 0:
00049             // Left side of tower first
00050             l.fV1[0] = sc2.fX;
00051             l.fV1[1] = sc2.fY;
00052             l.fV2[0] = sc2.fX + v2.fX;
00053             l.fV2[1] = sc2.fY + v2.fY;
00054          break;
00055 
00056          case 1:
00057             // Top of tower
00058             l.fV1[0] = sc2.fX + v2.fX;
00059             l.fV1[1] = sc2.fY + v2.fY;
00060             l.fV2[0] = sc1.fX + v1.fX;
00061             l.fV2[1] = sc1.fY + v1.fY;
00062          break;
00063 
00064          case 2:
00065             // Right hand side of tower
00066             l.fV1[0] = sc1.fX + v1.fX;
00067             l.fV1[1] = sc1.fY + v1.fY;
00068             l.fV2[0] = sc1.fX;
00069             l.fV2[1] = sc1.fY;
00070          break;
00071 
00072          case 3:
00073             // Bottom of tower
00074             l.fV1[0] = sc1.fX;
00075             l.fV1[1] = sc1.fY;
00076             l.fV2[0] = sc2.fX;
00077             l.fV2[1] = sc2.fY;
00078          break;
00079       }
00080       a++;
00081    }
00082    TEveProjected *proj = *(m_ls)->BeginProjecteds();
00083    proj->UpdateProjection();
00084    
00085    m_corners[2] = sc2 + v2;      // New top left of tower
00086    m_corners[3] = sc1 + v1;      // New top right of tower
00087 
00088    if( m_hasChild )
00089    {
00090       m_child->setCorners( 0, m_corners[2] );
00091       m_child->setCorners( 1, m_corners[3] );      // Base of child is now top of parent
00092       m_child->updateScale( vc );
00093    }
00094 }
00095 
00096 //______________________________________________________________________________
00097 void
00098 FWPFRhoPhiRecHit::clean()
00099 {
00100    m_corners.clear();
00101    if( m_hasChild )
00102       m_child->clean();
00103 
00104    delete this;
00105 }
00106 
00107 //______________________________________________________________________________
00108 void
00109 FWPFRhoPhiRecHit::addChild( FWProxyBuilderBase *pb, TEveElement *itemHolder, const FWViewContext *vc, float E, float et )
00110 {
00111    if( m_hasChild )  // Already has a child stacked on top so move on to child
00112       m_child->addChild( pb, itemHolder, vc, E, et );
00113    else
00114    {
00115       std::vector<TEveVector> corners(2);
00116       corners[0] = m_corners[2]; // Top left of current tower
00117       corners[1] = m_corners[3]; // Top right of current tower
00118       m_child = new FWPFRhoPhiRecHit( pb, itemHolder, vc, E, et, m_lPhi, m_rPhi, corners );
00119       m_hasChild = true;
00120    }
00121 }
00122 
00123 //______________________________________________________________________________
00124 void
00125 FWPFRhoPhiRecHit::buildRecHit( FWProxyBuilderBase *pb, TEveElement *itemHolder, const FWViewContext *vc, std::vector<TEveVector> &bCorners )
00126 {
00127    float scale = 0;
00128    float value = 0;
00129    TEveVector v1, v2, v3, v4;
00130    TEveVector vec;
00131 
00132    FWViewEnergyScale *caloScale = vc->getEnergyScale();
00133    value = caloScale->getPlotEt() ? m_et : m_energy;
00134    scale = caloScale->getScaleFactor3D() * value;
00135 
00136    v1 = bCorners[0];       // Bottom left
00137    v2 = bCorners[1];       // Bottom right
00138    
00139    v3 = v1;
00140    vec = v3;
00141    vec.Normalize();
00142    v3 = v3 + ( vec * scale );
00143 
00144    v4 = v2;
00145    vec = v4;
00146    vec.Normalize();
00147    v4 = v4 + ( vec * scale );
00148 
00149    m_ls = new TEveScalableStraightLineSet( "rhophiRecHit" );
00150    m_ls->AddLine( v1.fX, v1.fY, 0, v3.fX, v3.fY, 0 );    // Bottom left - Top left
00151    m_ls->AddLine( v3.fX, v3.fY, 0, v4.fX, v4.fY, 0 );    // Top left - Top right
00152    m_ls->AddLine( v4.fX, v4.fY, 0, v2.fX, v2.fY, 0 );    // Top right - Bottom right
00153    m_ls->AddLine( v2.fX, v2.fY, 0, v1.fX, v1.fY, 0 );    // Bottom right - Bottom left
00154 
00155    m_corners.push_back( v1 );
00156    m_corners.push_back( v2 );
00157    m_corners.push_back( v3 );
00158    m_corners.push_back( v4 );
00159 
00160    pb->setupAddElement( m_ls, itemHolder );
00161 }