CMS 3D CMS Logo

BuilderUtils.cc
Go to the documentation of this file.
4 
6 
7 #include "TGeoBBox.h"
8 #include "TColor.h"
9 #include "TROOT.h"
10 #include "TEveBox.h"
11 #include "TEveScalableStraightLineSet.h"
12 #include "TEveStraightLineSet.h"
13 #include "TEveTrans.h"
14 #include "TEveGeoNode.h"
15 
16 #include <math.h>
17 #include <time.h>
18 
19 namespace fireworks
20 {
21  std::pair<double,double> getPhiRange( const std::vector<double>& phis, double phi )
22  {
23  double min = 100;
24  double max = -100;
25 
26  for( std::vector<double>::const_iterator i = phis.begin();
27  i != phis.end(); ++i )
28  {
29  double aphi = *i;
30  // make phi continuous around jet phi
31  if( aphi - phi > M_PI ) aphi -= 2*M_PI;
32  if( phi - aphi > M_PI ) aphi += 2*M_PI;
33  if( aphi > max ) max = aphi;
34  if( aphi < min ) min = aphi;
35  }
36 
37  if( min > max ) return std::pair<double,double>( 0, 0 );
38 
39  return std::pair<double,double>( min, max );
40  }
41 
42  TEveGeoShape* getShape( const char* name,
43  TGeoBBox* shape,
44  Color_t color )
45  {
46  TEveGeoShape* egs = new TEveGeoShape( name );
47  TColor* c = gROOT->GetColor( color );
48  Float_t rgba[4] = { 1, 0, 0, 1 };
49  if( c )
50  {
51  rgba[0] = c->GetRed();
52  rgba[1] = c->GetGreen();
53  rgba[2] = c->GetBlue();
54  }
55  egs->SetMainColorRGB( rgba[0], rgba[1], rgba[2] );
56  egs->SetShape( shape );
57  return egs;
58  }
59 
60  void addRhoZEnergyProjection( FWProxyBuilderBase* pb, TEveElement* container,
61  double r_ecal, double z_ecal,
62  double theta_min, double theta_max,
63  double phi )
64  {
65  TEveGeoManagerHolder gmgr( TEveGeoShape::GetGeoMangeur());
66  double z1 = r_ecal / tan( theta_min );
67  if( z1 > z_ecal ) z1 = z_ecal;
68  if( z1 < -z_ecal ) z1 = -z_ecal;
69  double z2 = r_ecal / tan( theta_max );
70  if( z2 > z_ecal ) z2 = z_ecal;
71  if( z2 < -z_ecal ) z2 = -z_ecal;
72  double r1 = z_ecal * fabs( tan( theta_min ));
73  if( r1 > r_ecal ) r1 = r_ecal;
74  if( phi < 0 ) r1 = -r1;
75  double r2 = z_ecal * fabs( tan( theta_max ));
76  if( r2 > r_ecal ) r2 = r_ecal;
77  if( phi < 0 ) r2 = -r2;
78 
79  if( fabs(r2 - r1) > 1 )
80  {
81  TGeoBBox *sc_box = new TGeoBBox( 0., fabs( r2 - r1 ) / 2, 1 );
82  TEveGeoShape *element = new TEveGeoShape("r-segment");
83  element->SetShape(sc_box);
84  TEveTrans &t = element->RefMainTrans();
85  t(1,4) = 0;
86  t(2,4) = (r2+r1)/2;
87  t(3,4) = fabs(z2)>fabs(z1) ? z2 : z1;
88  pb->setupAddElement(element, container);
89  }
90  if( fabs(z2 - z1) > 1 )
91  {
92  TGeoBBox *sc_box = new TGeoBBox( 0., 1, ( z2 - z1 ) / 2 );
93  TEveGeoShape *element = new TEveGeoShape("z-segment");
94  element->SetShape( sc_box );
95  TEveTrans &t = element->RefMainTrans();
96  t(1,4) = 0;
97  t(2,4) = fabs(r2)>fabs(r1) ? r2 : r1;
98  t(3,4) = (z2+z1)/2;
99  pb->setupAddElement(element, container);
100  }
101  }
102 
104  {
105  time_t t( event.time().value() >> 32 );
106  std::string text( asctime( gmtime( &t ) ) );
107  size_t pos = text.find( '\n' );
108  if( pos != std::string::npos ) text = text.substr( 0, pos );
109  text += " GMT";
110  return text;
111  }
112 
114  {
115 
116  time_t t( event.time().value() >> 32 );
117  struct tm * xx = localtime( &t );
118  std::string text( asctime(xx) );
119  size_t pos = text.find('\n');
120  if( pos != std::string::npos ) text = text.substr( 0, pos );
121  text += " ";
122  if( xx->tm_isdst )
123  text += tzname[1];
124  else
125  text += tzname[0];
126  return text;
127  }
128 
129  void invertBox( std::vector<float> &corners )
130  {
131  std::swap( corners[0], corners[9] );
132  std::swap( corners[1], corners[10] );
133  std::swap( corners[2], corners[11] );
134 
135  std::swap( corners[3], corners[6] );
136  std::swap( corners[4], corners[7] );
137  std::swap( corners[5], corners[8] );
138 
139  std::swap( corners[12], corners[21] );
140  std::swap( corners[13], corners[22] );
141  std::swap( corners[14], corners[23] );
142 
143  std::swap( corners[15], corners[18] );
144  std::swap( corners[16], corners[19] );
145  std::swap( corners[17], corners[20] );
146  }
147 
148  void addBox( const std::vector<float> &corners, TEveElement* comp, FWProxyBuilderBase* pb )
149  {
150  TEveBox* eveBox = new TEveBox( "Box" );
151  eveBox->SetDrawFrame( false );
152  eveBox->SetPickable( true );
153  eveBox->SetVertices( &corners[0] );
154 
155  pb->setupAddElement( eveBox, comp );
156  }
157 
158  void addCircle( double eta, double phi, double radius, const unsigned int nLineSegments, TEveElement* comp, FWProxyBuilderBase* pb )
159  {
160  TEveStraightLineSet* container = new TEveStraightLineSet;
161 
162  for( unsigned int iphi = 0; iphi < nLineSegments; ++iphi )
163  {
164  container->AddLine( eta + radius * cos( 2 * M_PI / nLineSegments * iphi ),
165  phi + radius * sin( 2 * M_PI / nLineSegments * iphi ),
166  0.01,
167  eta + radius * cos( 2 * M_PI / nLineSegments * ( iphi + 1 )),
168  phi + radius * sin( 2 * M_PI / nLineSegments * ( iphi + 1 )),
169  0.01 );
170  }
171  pb->setupAddElement( container, comp );
172  }
173 
174  void addDashedArrow( double phi, double size, TEveElement* comp, FWProxyBuilderBase* pb )
175  {
176  TEveScalableStraightLineSet* marker = new TEveScalableStraightLineSet;
177  marker->SetLineWidth( 1 );
178  marker->SetLineStyle( 2 );
179  marker->AddLine( 0, 0, 0, size * cos( phi ), size * sin( phi ), 0 );
180  marker->AddLine( size * 0.9 * cos( phi + 0.03 ), size * 0.9 * sin( phi + 0.03 ), 0, size * cos( phi ), size * sin( phi ), 0 );
181  marker->AddLine( size * 0.9 * cos( phi - 0.03 ), size * 0.9 * sin( phi - 0.03 ), 0, size * cos( phi ), size * sin( phi ), 0 );
182  pb->setupAddElement( marker, comp );
183  }
184 
185  void addDashedLine( double phi, double theta, double size, TEveElement* comp, FWProxyBuilderBase* pb )
186  {
187  double r( 0 );
188  if( theta < pb->context().caloTransAngle() || M_PI - theta < pb->context().caloTransAngle())
189  r = pb->context().caloZ2() / fabs( cos( theta ));
190  else
191  r = pb->context().caloR1() / sin( theta );
192 
193  TEveStraightLineSet* marker = new TEveStraightLineSet;
194  marker->SetLineWidth( 2 );
195  marker->SetLineStyle( 2 );
196  marker->AddLine( r * cos( phi ) * sin( theta ), r * sin( phi ) * sin( theta ), r * cos( theta ),
197  ( r + size ) * cos( phi ) * sin( theta ), ( r + size ) * sin( phi ) * sin( theta ), ( r + size ) * cos( theta ));
198  pb->setupAddElement( marker, comp );
199  }
200 
201  void addDoubleLines( double phi, TEveElement* comp, FWProxyBuilderBase* pb )
202  {
203  TEveStraightLineSet* mainLine = new TEveStraightLineSet;
204  mainLine->AddLine( -5.191, phi, 0.01, 5.191, phi, 0.01 );
205  pb->setupAddElement( mainLine, comp );
206 
207  phi = phi > 0 ? phi - M_PI : phi + M_PI;
208  TEveStraightLineSet* secondLine = new TEveStraightLineSet;
209  secondLine->SetLineStyle( 7 );
210  secondLine->AddLine( -5.191, phi, 0.01, 5.191, phi, 0.01 );
211  pb->setupAddElement( secondLine, comp );
212  }
213 
214  //______________________________________________________________________________
215  void energyScaledBox3DCorners( const float* corners, float scale, std::vector<float>& scaledCorners, bool invert)
216  {
217  std::vector<float> centre( 3, 0 );
218 
219  for( unsigned int i = 0; i < 24; i += 3 )
220  {
221  centre[0] += corners[i];
222  centre[1] += corners[i + 1];
223  centre[2] += corners[i + 2];
224  }
225 
226  for( unsigned int i = 0; i < 3; ++i )
227  centre[i] *= 1.0f / 8.0f;
228 
229  // Coordinates for a scaled version of the original box
230  for( unsigned int i = 0; i < 24; i += 3 )
231  {
232  scaledCorners[i] = centre[0] + ( corners[i] - centre[0] ) * scale;
233  scaledCorners[i + 1] = centre[1] + ( corners[i + 1] - centre[1] ) * scale;
234  scaledCorners[i + 2] = centre[2] + ( corners[i + 2] - centre[2] ) * scale;
235  }
236 
237  if( invert )
238  invertBox( scaledCorners );
239  }
240 
241  void drawEnergyScaledBox3D( const float* corners, float scale, TEveElement* comp, FWProxyBuilderBase* pb, bool invert )
242  {
243  std::vector<float> scaledCorners( 24 );
244  energyScaledBox3DCorners(corners, scale, scaledCorners, invert);
245  addBox( scaledCorners, comp, pb );
246  }
247  //______________________________________________________________________________
248 
249  void etScaledBox3DCorners( const float* corners, float energy, float maxEnergy, std::vector<float>& scaledCorners, bool invert)
250  {
251  std::vector<float> centre( 3, 0 );
252 
253  for( unsigned int i = 0; i < 24; i += 3 )
254  {
255  centre[0] += corners[i];
256  centre[1] += corners[i + 1];
257  centre[2] += corners[i + 2];
258  }
259 
260  for( unsigned int i = 0; i < 3; ++i )
261  centre[i] *= 1.0f / 8.0f;
262 
263  TEveVector c( centre[0], centre[1], centre[2] );
264  float scale = energy / maxEnergy * sin( c.Theta());
265 
266  // Coordinates for a scaled version of the original box
267  for( unsigned int i = 0; i < 24; i += 3 )
268  {
269  scaledCorners[i] = centre[0] + ( corners[i] - centre[0] ) * scale;
270  scaledCorners[i + 1] = centre[1] + ( corners[i + 1] - centre[1] ) * scale;
271  scaledCorners[i + 2] = centre[2] + ( corners[i + 2] - centre[2] ) * scale;
272  }
273 
274  if( invert )
275  invertBox( scaledCorners );
276  }
277 
278  void drawEtScaledBox3D( const float* corners, float energy, float maxEnergy, TEveElement* comp, FWProxyBuilderBase* pb, bool invert )
279  {
280  std::vector<float> scaledCorners( 24 );
281  etScaledBox3DCorners(corners, energy, maxEnergy, scaledCorners, invert);
282  addBox( scaledCorners, comp, pb );
283  }
284 
285  //______________________________________________________________________________
286  void energyTower3DCorners( const float* corners, float scale, std::vector<float>& scaledCorners, bool reflect)
287  {
288  for( int i = 0; i < 24; ++i )
289  scaledCorners[i] = corners[i];
290  // Coordinates of a front face scaled
291  if( reflect )
292  {
293  // We know, that an ES rechit geometry in -Z needs correction.
294  // The back face is actually its front face.
295  for( unsigned int i = 0; i < 12; i += 3 )
296  {
297  TEveVector diff( corners[i] - corners[i + 12], corners[i + 1] - corners[i + 13], corners[i + 2] - corners[i + 14] );
298  diff.Normalize();
299  diff *= scale;
300 
301  scaledCorners[i] = corners[i] + diff.fX;
302  scaledCorners[i + 1] = corners[i + 1] + diff.fY;
303  scaledCorners[i + 2] = corners[i + 2] + diff.fZ;
304  }
305  }
306  else
307  {
308  for( unsigned int i = 0; i < 12; i += 3 )
309  {
310  TEveVector diff( corners[i + 12] - corners[i], corners[i + 13] - corners[i + 1], corners[i + 14] - corners[i + 2] );
311  diff.Normalize();
312  diff *= scale;
313 
314  scaledCorners[i] = corners[i + 12];
315  scaledCorners[i + 1] = corners[i + 13];
316  scaledCorners[i + 2] = corners[i + 14];
317 
318  scaledCorners[i + 12] = corners[i + 12] + diff.fX;
319  scaledCorners[i + 13] = corners[i + 13] + diff.fY;
320  scaledCorners[i + 14] = corners[i + 14] + diff.fZ;
321  }
322  }
323  }
324 
325  void drawEnergyTower3D( const float* corners, float scale, TEveElement* comp, FWProxyBuilderBase* pb, bool reflect )
326  {
327  std::vector<float> scaledCorners( 24 );
328  energyTower3DCorners(corners, scale, scaledCorners, reflect);
329  addBox( scaledCorners, comp, pb );
330  }
331 
332  //______________________________________________________________________________
333 
334  void etTower3DCorners( const float* corners, float scale, std::vector<float>& scaledCorners, bool reflect)
335  {
336  for( int i = 0; i < 24; ++i )
337  scaledCorners[i] = corners[i];
338  // Coordinates of a front face scaled
339  if( reflect )
340  {
341  // We know, that an ES rechit geometry in -Z needs correction.
342  // The back face is actually its front face.
343  for( unsigned int i = 0; i < 12; i += 3 )
344  {
345  TEveVector diff( corners[i] - corners[i + 12], corners[i + 1] - corners[i + 13], corners[i + 2] - corners[i + 14] );
346  diff.Normalize();
347  diff *= ( scale * sin( diff.Theta()));
348 
349  scaledCorners[i] = corners[i] + diff.fX;
350  scaledCorners[i + 1] = corners[i + 1] + diff.fY;
351  scaledCorners[i + 2] = corners[i + 2] + diff.fZ;
352  }
353  }
354  else
355  {
356  for( unsigned int i = 0; i < 12; i += 3 )
357  {
358  TEveVector diff( corners[i + 12] - corners[i], corners[i + 13] - corners[i + 1], corners[i + 14] - corners[i + 2] );
359  diff.Normalize();
360  diff *= ( scale * sin( diff.Theta()));
361 
362  scaledCorners[i] = corners[i + 12];
363  scaledCorners[i + 1] = corners[i + 13];
364  scaledCorners[i + 2] = corners[i + 14];
365 
366  scaledCorners[i + 12] = corners[i + 12] + diff.fX;
367  scaledCorners[i + 13] = corners[i + 13] + diff.fY;
368  scaledCorners[i + 14] = corners[i + 14] + diff.fZ;
369  }
370  }
371  }
372 
373 
374  void drawEtTower3D( const float* corners, float scale, TEveElement* comp, FWProxyBuilderBase* pb, bool reflect )
375  {
376  std::vector<float> scaledCorners( 24 );
377  etTower3DCorners(corners, scale, scaledCorners, reflect);
378  addBox( scaledCorners, comp, pb );
379  }
380 
381 
382 } // namespace fireworks
size
Write out results.
const fireworks::Context & context() const
std::pair< double, double > getPhiRange(const std::vector< double > &phis, double phi)
Definition: BuilderUtils.cc:21
void addDoubleLines(double phi, TEveElement *comp, FWProxyBuilderBase *pb)
void etTower3DCorners(const float *corners, float scale, std::vector< float > &, bool reflect=false)
void drawEnergyScaledBox3D(const float *corners, float scale, TEveElement *, FWProxyBuilderBase *, bool invert=false)
void setupAddElement(TEveElement *el, TEveElement *parent, bool set_color=true) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
static float caloZ2(bool offset=true)
Definition: Context.cc:223
void addDashedLine(double phi, double theta, double size, TEveElement *comp, FWProxyBuilderBase *pb)
void drawEtTower3D(const float *corners, float scale, TEveElement *, FWProxyBuilderBase *, bool reflect=false)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
void invertBox(std::vector< float > &corners)
void addDashedArrow(double phi, double size, TEveElement *comp, FWProxyBuilderBase *pb)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
static float caloR1(bool offset=true)
Definition: Context.cc:208
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
double f[11][100]
void addCircle(double eta, double phi, double radius, const unsigned int nLineSegments, TEveElement *comp, FWProxyBuilderBase *pb)
T min(T a, T b)
Definition: MathUtil.h:58
#define M_PI
std::string getTimeGMT(const edm::EventBase &event)
void energyTower3DCorners(const float *corners, float scale, std::vector< float > &, bool reflect=false)
void addRhoZEnergyProjection(FWProxyBuilderBase *, TEveElement *, double r_ecal, double z_ecal, double theta_min, double theta_max, double phi)
Definition: BuilderUtils.cc:60
void energyScaledBox3DCorners(const float *corners, float scale, std::vector< float > &, bool invert=false)
void addBox(const std::vector< float > &corners, TEveElement *, FWProxyBuilderBase *)
std::string getLocalTime(const edm::EventBase &event)
void etScaledBox3DCorners(const float *corners, float energy, float maxEnergy, std::vector< float > &scaledCorners, bool reflect=false)
void drawEnergyTower3D(const float *corners, float scale, TEveElement *, FWProxyBuilderBase *, bool reflect=false)
TEveGeoShape * getShape(const char *name, TGeoBBox *shape, Color_t color)
Definition: BuilderUtils.cc:42
TimeValue_t value() const
Definition: Timestamp.h:56
edm::Timestamp time() const
Definition: EventBase.h:59
Definition: event.py:1
void drawEtScaledBox3D(const float *corners, float energy, float maxEnergy, TEveElement *, FWProxyBuilderBase *, bool reflect=false)