CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWPFLegoRecHit.cc
Go to the documentation of this file.
1 #include "FWPFLegoRecHit.h"
3 
4 //______________________________________________________________________________
5 FWPFLegoRecHit::FWPFLegoRecHit( const std::vector<TEveVector> &corners, TEveElement *comp, FWPFEcalRecHitLegoProxyBuilder *pb,
6  const FWViewContext *vc, float e, float et )
7  : m_builder(pb), m_energy(e), m_et(et), m_isTallest(false)
8 {
9  buildTower( corners, vc );
10  buildLineSet( corners, vc );
11 
12  pb->setupAddElement( m_tower, comp );
13  pb->setupAddElement( m_ls, comp );
14 }
15 
16 //______________________________________________________________________________
17 void
18 FWPFLegoRecHit::setupEveBox( const std::vector<TEveVector> &corners )
19 {
20  for( size_t i = 0; i < corners.size(); ++i )
21  m_tower->SetVertex( i, corners[i] );
22 
23  m_tower->SetPickable( true );
24  m_tower->SetDrawFrame(false);
25  m_tower->SetLineWidth( 1.0 );
26  m_tower->SetLineColor( kBlack );
27 }
28 
29 //______________________________________________________________________________
30 void
31 FWPFLegoRecHit::convertToTower( std::vector<TEveVector> &corners, float scale )
32 {
33  for( size_t i = 0; i < 4; ++i )
34  corners[i+4].fZ = corners[i].fZ + scale;
35 }
36 
37 //______________________________________________________________________________
38 void
39 FWPFLegoRecHit::buildTower( const std::vector<TEveVector> &corners, const FWViewContext *vc )
40 {
41  m_tower = new TEveBox( "EcalRecHitTower" );
42  std::vector<TEveVector> towerCorners = corners;
43  FWViewEnergyScale *caloScale = vc->getEnergyScale();
44  float val = caloScale->getPlotEt() ? m_et : m_energy;
45  float scale = caloScale->getScaleFactorLego() * val;
46 
47  if( scale < 0 )
48  scale *= -1;
49 
50  convertToTower( towerCorners, scale );
51  setupEveBox( towerCorners );
52 }
53 
54 //______________________________________________________________________________
55 void
56 FWPFLegoRecHit::buildLineSet( const std::vector<TEveVector> &corners, const FWViewContext *vc )
57 {
58  m_ls = new TEveStraightLineSet( "EcalRecHitLineSet" );
59 
60  // no need to set anything, all is re-set in updateScales()
61  // reserve space for square outline
62  TEveVector c;
63  m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
64  m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
65  m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
66  m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
67 
68  // last line is trick to add a marker in line set
69  m_ls->SetMarkerStyle(1);
70  m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
71  m_ls->AddMarker(0, 0.);
72 }
73 
74 //______________________________________________________________________________
75 void
77 {
78  FWViewEnergyScale *caloScale = vc->getEnergyScale();
79  float val = caloScale->getPlotEt() ? m_et : m_energy;
80  float scale = caloScale->getScaleFactorLego() * val;
81 
82  // printf("scale %f %f\n", caloScale->getValToHeight(), val);
83 
84  if( scale < 0 )
85  scale *= -1;
86 
87  // Reposition top points of tower
88  const float *data;
89  TEveVector c;
90  for( unsigned int i = 0; i < 4; ++i )
91  {
92  data = m_tower->GetVertex( i );
93  c.fX += data[0];
94  c.fY += data[1];
95  m_tower->SetVertex( i, data[0], data[1], 0 );
96  m_tower->SetVertex( i+4, data[0], data[1], scale);
97  }
98  c *= 0.25;
99  // Scale lineset
100  float s = log( 1 + val ) / m_builder->getMaxValLog(caloScale->getPlotEt());
101  float d = 0.5 * ( m_tower->GetVertex(1)[0] -m_tower->GetVertex(0)[0]);
102  d *= s;
103  float z = scale * 1.001;
104  setLine(0, c.fX - d, c.fY -d, z, c.fX + d, c.fY -d, z);
105  setLine(1, c.fX + d, c.fY -d, z, c.fX + d, c.fY +d, z);
106  setLine(2, c.fX + d, c.fY +d, z, c.fX - d, c.fY +d, z);
107  setLine(3, c.fX - d, c.fY +d, z, c.fX - d, c.fY -d, z);
108 
109  if( m_isTallest )
110  {
111  // This is the tallest tower and hence two additional lines needs scaling
112  setLine( 4, c.fX - d, c.fY - d, z, c.fX + d, c.fY + d, z );
113  setLine( 5, c.fX - d, c.fY + d, z, c.fX + d, c.fY - d, z );
114  }
115 
116  TEveStraightLineSet::Marker_t* m = ((TEveStraightLineSet::Marker_t*)(m_ls->GetMarkerPlex().Atom(0)));
117  m->fV[0] = c.fX; m->fV[1] = c.fY; m->fV[2] = z;
118 
119  // stamp changed elements
120  m_tower->StampTransBBox();
121  m_ls->StampTransBBox();
122 }
123 
124 //______________________________________________________________________________
125 void FWPFLegoRecHit::setLine(int idx, float x1, float y1, float z1, float x2, float y2, float z2)
126 {
127  // AMT: this func should go in TEveStraightLineSet class
128 
129  TEveStraightLineSet::Line_t* l = ((TEveStraightLineSet::Line_t*)(m_ls->GetLinePlex().Atom(idx)));
130 
131  l->fV1[0] = x1;
132  l->fV1[1] = y1;
133  l->fV1[2] = z1;
134 
135  l->fV2[0] = x2;
136  l->fV2[1] = y2;
137  l->fV2[2] = z2;
138 }
139 
140 //______________________________________________________________________________
141 void
143 {
144  m_isTallest = b;
145 
146  if( m_isTallest )
147  {
148  TEveVector vec;
149  addLine( vec, vec );
150  addLine( vec, vec );
151  }
152 }
153 
154 //______________________________________________________________________________
155 void
156 FWPFLegoRecHit::addLine( float x1, float y1, float z1, float x2, float y2, float z2 )
157 {
158  m_ls->AddLine( x1, y1, z1, x2, y2, z2 );
159 }
160 
161 //______________________________________________________________________________
162 void
163 FWPFLegoRecHit::addLine( const TEveVector &v1, const TEveVector &v2 )
164 {
165  m_ls->AddLine(v1.fX, v1.fY, v1.fZ, v2.fX, v2.fY, v2.fZ);
166 }
int i
Definition: DBlmapReader.cc:9
void setLine(int idx, float x1, float y1, float z1, float x2, float y2, float z2)
void convertToTower(std::vector< TEveVector > &corners, float scale)
FWPFEcalRecHitLegoProxyBuilder * m_builder
void addLine(float x1, float y1, float z1, float x2, float y2, float z2)
void buildTower(const std::vector< TEveVector > &corners, const FWViewContext *vc)
void setupAddElement(TEveElement *el, TEveElement *parent, bool set_color=true) const
FWViewEnergyScale * getEnergyScale() const
TEveBox * m_tower
FWPFLegoRecHit(const std::vector< TEveVector > &corners, TEveElement *comp, FWPFEcalRecHitLegoProxyBuilder *pb, const FWViewContext *vc, float e, float et)
Definition: DDAxes.h:10
float getScaleFactorLego() const
void updateScale(const FWViewContext *vc)
Log< T >::type log(const T &t)
Definition: Log.h:22
double b
Definition: hdecay.h:120
void setupEveBox(const std::vector< TEveVector > &corners)
void setIsTallest(bool b)
void buildLineSet(const std::vector< TEveVector > &corners, const FWViewContext *vc)
TEveStraightLineSet * m_ls
string s
Definition: asciidump.py:422
bool getPlotEt() const