CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/Fireworks/ParticleFlow/src/FWPFLegoRecHit.cc

Go to the documentation of this file.
00001 #include "Fireworks/ParticleFlow/interface/FWPFLegoRecHit.h"
00002 #include "Fireworks/Core/interface/FWProxyBuilderBase.h"
00003 
00004 //______________________________________________________________________________
00005 FWPFLegoRecHit::FWPFLegoRecHit( const std::vector<TEveVector> &corners, TEveElement *comp, FWProxyBuilderBase*pb,
00006                                 const FWViewContext *vc, float e, float et )
00007    : m_energy(e), m_et(et), m_isTallest(false)
00008 {
00009    buildTower( corners, vc );
00010    buildLineSet( corners, vc );
00011 
00012    pb->setupAddElement( m_tower, comp );
00013    pb->setupAddElement( m_ls, comp );
00014 }
00015 
00016 //______________________________________________________________________________
00017 void
00018 FWPFLegoRecHit::setupEveBox( std::vector<TEveVector> &corners, float scale )
00019 {
00020    for( size_t i = 0; i < 4; ++i )
00021    {
00022       int j = i + 4;
00023       corners[i+4].fZ = corners[i].fZ + scale;
00024       m_tower->SetVertex( i, corners[i] );
00025       m_tower->SetVertex( j, corners[j] );
00026    }
00027 
00028    m_tower->SetPickable( true );
00029    m_tower->SetDrawFrame(false);
00030    m_tower->SetLineWidth( 1.0 );
00031    m_tower->SetLineColor( kBlack );
00032 }
00033 
00034 //______________________________________________________________________________
00035 void
00036 FWPFLegoRecHit::buildTower( const std::vector<TEveVector> &corners, const FWViewContext *vc )
00037 {
00038    m_tower = new TEveBox( "EcalRecHitTower" );
00039    std::vector<TEveVector> towerCorners = corners;
00040    FWViewEnergyScale *caloScale = vc->getEnergyScale();
00041    float val = caloScale->getPlotEt() ? m_et : m_energy;
00042    float scale = caloScale->getScaleFactorLego() * val;
00043 
00044    if( scale < 0 )
00045       scale *= -1;
00046 
00047    setupEveBox( towerCorners, scale );
00048 }
00049 
00050 //______________________________________________________________________________
00051 void
00052 FWPFLegoRecHit::buildLineSet( const std::vector<TEveVector> &corners, const FWViewContext *vc )
00053 {
00054    m_ls = new TEveStraightLineSet( "EcalRecHitLineSet" );
00055 
00056    // no need to set anything, all is re-set in updateScales()
00057    // reserve space for square outline
00058    TEveVector c;
00059    m_ls->AddLine( c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ );
00060    m_ls->AddLine( c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ );
00061    m_ls->AddLine( c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ );
00062    m_ls->AddLine( c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ );
00063 
00064    // last line is trick to add a marker in line set
00065    m_ls->SetMarkerStyle( 1 );
00066    m_ls->AddLine( c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ );
00067    m_ls->AddMarker( 0, 0. );
00068 }
00069 
00070 //______________________________________________________________________________
00071 void
00072 FWPFLegoRecHit::updateScale( const FWViewContext *vc, float maxLogVal )
00073 {
00074    FWViewEnergyScale *caloScale = vc->getEnergyScale();
00075    float val = caloScale->getPlotEt() ? m_et : m_energy;
00076    float scale = caloScale->getScaleFactorLego() * val;
00077 
00078    // printf("scale %f %f\n",  caloScale->getValToHeight(), val);
00079 
00080    if( scale < 0 )
00081       scale *= -1;
00082 
00083    // Reposition top points of tower
00084    const float *data;
00085    TEveVector c;
00086    for( unsigned int i = 0; i < 4; ++i )
00087    {
00088       data = m_tower->GetVertex( i );
00089       c.fX += data[0];
00090       c.fY += data[1];
00091       m_tower->SetVertex( i, data[0], data[1], 0 );
00092       m_tower->SetVertex( i+4,  data[0], data[1], scale);
00093    }
00094    c *= 0.25;
00095    // Scale lineset 
00096    float s = log( 1 + val ) / maxLogVal;
00097    float d = 0.5 * ( m_tower->GetVertex(1)[0]  -m_tower->GetVertex(0)[0]);
00098    d *= s;
00099    float z =  scale * 1.001;
00100    setLine(0, c.fX - d, c.fY -d, z, c.fX + d, c.fY -d, z);
00101    setLine(1, c.fX + d, c.fY -d, z, c.fX + d, c.fY +d, z);
00102    setLine(2, c.fX + d, c.fY +d, z, c.fX - d, c.fY +d, z);
00103    setLine(3, c.fX - d, c.fY +d, z, c.fX - d, c.fY -d, z);
00104 
00105    if( m_isTallest )
00106    {
00107       // This is the tallest tower and hence two additional lines needs scaling
00108       setLine( 4, c.fX - d, c.fY - d, z, c.fX + d, c.fY + d, z );
00109       setLine( 5, c.fX - d, c.fY + d, z, c.fX + d, c.fY - d, z );
00110    }
00111 
00112    TEveStraightLineSet::Marker_t* m = ((TEveStraightLineSet::Marker_t*)(m_ls->GetMarkerPlex().Atom(0)));
00113    m->fV[0] = c.fX; m->fV[1] = c.fY; m->fV[2] = z;
00114 
00115    // stamp changed elements
00116    m_tower->StampTransBBox();
00117    m_ls->StampTransBBox();
00118 }
00119 
00120 //______________________________________________________________________________
00121 void FWPFLegoRecHit::setLine(int idx, float x1, float y1, float z1, float x2, float y2, float z2)
00122 {
00123    // AMT: this func should go in TEveStraightLineSet class
00124 
00125    TEveStraightLineSet::Line_t* l = ((TEveStraightLineSet::Line_t*)(m_ls->GetLinePlex().Atom(idx)));
00126 
00127    l->fV1[0] = x1;
00128    l->fV1[1] = y1;
00129    l->fV1[2] = z1; 
00130 
00131    l->fV2[0] = x2;
00132    l->fV2[1] = y2;
00133    l->fV2[2] = z2;
00134 }
00135 
00136 //______________________________________________________________________________
00137 void
00138 FWPFLegoRecHit::setIsTallest( bool b )
00139 {
00140    m_isTallest = b;
00141    
00142    if( m_isTallest )
00143    {
00144       TEveVector vec;
00145       addLine( vec, vec );
00146       addLine( vec, vec );
00147    }
00148 }
00149 
00150 //______________________________________________________________________________
00151 void
00152 FWPFLegoRecHit::addLine( float x1, float y1, float z1, float x2, float y2, float z2 )
00153 {
00154    m_ls->AddLine( x1, y1, z1, x2, y2, z2 );
00155 }
00156 
00157 //______________________________________________________________________________
00158 void
00159 FWPFLegoRecHit::addLine( const TEveVector &v1, const TEveVector &v2 )
00160 {
00161    m_ls->AddLine(v1.fX, v1.fY, v1.fZ, v2.fX, v2.fY, v2.fZ);
00162 }