00001 #include "FWPFLegoRecHit.h"
00002 #include "FWPFEcalRecHitLegoProxyBuilder.h"
00003
00004
00005 FWPFLegoRecHit::FWPFLegoRecHit( const std::vector<TEveVector> &corners, TEveElement *comp, FWPFEcalRecHitLegoProxyBuilder *pb,
00006 const FWViewContext *vc, float e, float et )
00007 : m_builder(pb), 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( const std::vector<TEveVector> &corners )
00019 {
00020 for( size_t i = 0; i < corners.size(); ++i )
00021 m_tower->SetVertex( i, corners[i] );
00022
00023 m_tower->SetPickable( true );
00024 m_tower->SetDrawFrame(false);
00025 m_tower->SetLineWidth( 1.0 );
00026 m_tower->SetLineColor( kBlack );
00027 }
00028
00029
00030 void
00031 FWPFLegoRecHit::convertToTower( std::vector<TEveVector> &corners, float scale )
00032 {
00033 for( size_t i = 0; i < 4; ++i )
00034 corners[i+4].fZ = corners[i].fZ + scale;
00035 }
00036
00037
00038 void
00039 FWPFLegoRecHit::buildTower( const std::vector<TEveVector> &corners, const FWViewContext *vc )
00040 {
00041 m_tower = new TEveBox( "EcalRecHitTower" );
00042 std::vector<TEveVector> towerCorners = corners;
00043 FWViewEnergyScale *caloScale = vc->getEnergyScale();
00044 float val = caloScale->getPlotEt() ? m_et : m_energy;
00045 float scale = caloScale->getScaleFactorLego() * val;
00046
00047 if( scale < 0 )
00048 scale *= -1;
00049
00050 convertToTower( towerCorners, scale );
00051 setupEveBox( towerCorners );
00052 }
00053
00054
00055 void
00056 FWPFLegoRecHit::buildLineSet( const std::vector<TEveVector> &corners, const FWViewContext *vc )
00057 {
00058 m_ls = new TEveStraightLineSet( "EcalRecHitLineSet" );
00059
00060
00061
00062 TEveVector c;
00063 m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
00064 m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
00065 m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
00066 m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
00067
00068
00069 m_ls->SetMarkerStyle(1);
00070 m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
00071 m_ls->AddMarker(0, 0.);
00072 }
00073
00074
00075 void
00076 FWPFLegoRecHit::updateScale( const FWViewContext *vc )
00077 {
00078 FWViewEnergyScale *caloScale = vc->getEnergyScale();
00079 float val = caloScale->getPlotEt() ? m_et : m_energy;
00080 float scale = caloScale->getScaleFactorLego() * val;
00081
00082
00083
00084 if( scale < 0 )
00085 scale *= -1;
00086
00087
00088 const float *data;
00089 TEveVector c;
00090 for( unsigned int i = 0; i < 4; ++i )
00091 {
00092 data = m_tower->GetVertex( i );
00093 c.fX += data[0];
00094 c.fY += data[1];
00095 m_tower->SetVertex( i, data[0], data[1], 0 );
00096 m_tower->SetVertex( i+4, data[0], data[1], scale);
00097 }
00098 c *= 0.25;
00099
00100 float s = log( 1 + val ) / m_builder->getMaxValLog(caloScale->getPlotEt());
00101 float d = 0.5 * ( m_tower->GetVertex(1)[0] -m_tower->GetVertex(0)[0]);
00102 d *= s;
00103 float z = scale * 1.001;
00104 setLine(0, c.fX - d, c.fY -d, z, c.fX + d, c.fY -d, z);
00105 setLine(1, c.fX + d, c.fY -d, z, c.fX + d, c.fY +d, z);
00106 setLine(2, c.fX + d, c.fY +d, z, c.fX - d, c.fY +d, z);
00107 setLine(3, c.fX - d, c.fY +d, z, c.fX - d, c.fY -d, z);
00108
00109 if( m_isTallest )
00110 {
00111
00112 setLine( 4, c.fX - d, c.fY - d, z, c.fX + d, c.fY + d, z );
00113 setLine( 5, c.fX - d, c.fY + d, z, c.fX + d, c.fY - d, z );
00114 }
00115
00116 TEveStraightLineSet::Marker_t* m = ((TEveStraightLineSet::Marker_t*)(m_ls->GetMarkerPlex().Atom(0)));
00117 m->fV[0] = c.fX; m->fV[1] = c.fY; m->fV[2] = z;
00118
00119
00120 m_tower->StampTransBBox();
00121 m_ls->StampTransBBox();
00122 }
00123
00124
00125 void FWPFLegoRecHit::setLine(int idx, float x1, float y1, float z1, float x2, float y2, float z2)
00126 {
00127
00128
00129 TEveStraightLineSet::Line_t* l = ((TEveStraightLineSet::Line_t*)(m_ls->GetLinePlex().Atom(idx)));
00130
00131 l->fV1[0] = x1;
00132 l->fV1[1] = y1;
00133 l->fV1[2] = z1;
00134
00135 l->fV2[0] = x2;
00136 l->fV2[1] = y2;
00137 l->fV2[2] = z2;
00138 }
00139
00140
00141 void
00142 FWPFLegoRecHit::setIsTallest( bool b )
00143 {
00144 m_isTallest = b;
00145
00146 if( m_isTallest )
00147 {
00148 TEveVector vec;
00149 addLine( vec, vec );
00150 addLine( vec, vec );
00151 }
00152 }
00153
00154
00155 void
00156 FWPFLegoRecHit::addLine( float x1, float y1, float z1, float x2, float y2, float z2 )
00157 {
00158 m_ls->AddLine( x1, y1, z1, x2, y2, z2 );
00159 }
00160
00161
00162 void
00163 FWPFLegoRecHit::addLine( const TEveVector &v1, const TEveVector &v2 )
00164 {
00165 m_ls->AddLine(v1.fX, v1.fY, v1.fZ, v2.fX, v2.fY, v2.fZ);
00166 }