00001 #include "Fireworks/ParticleFlow/interface/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
00027 TEveVector sc1 = m_corners[1];
00028 TEveVector sc2 = m_corners[0];
00029
00030
00031 TEveVector v1 = sc1;
00032 TEveVector v2 = sc2;
00033
00034 v1.Normalize();
00035 v2.Normalize();
00036
00037 v1 *= scale;
00038 v2 *= scale;
00039
00040
00041
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
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
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
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
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;
00086 m_corners[3] = sc1 + v1;
00087
00088 if( m_hasChild )
00089 {
00090 m_child->setCorners( 0, m_corners[2] );
00091 m_child->setCorners( 1, m_corners[3] );
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 )
00112 m_child->addChild( pb, itemHolder, vc, E, et );
00113 else
00114 {
00115 std::vector<TEveVector> corners(2);
00116 corners[0] = m_corners[2];
00117 corners[1] = m_corners[3];
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];
00137 v2 = bCorners[1];
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 );
00151 m_ls->AddLine( v3.fX, v3.fY, 0, v4.fX, v4.fY, 0 );
00152 m_ls->AddLine( v4.fX, v4.fY, 0, v2.fX, v2.fY, 0 );
00153 m_ls->AddLine( v2.fX, v2.fY, 0, v1.fX, v1.fY, 0 );
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 }