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