CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  time_t t( event.time().value() >> 32 );
116  std::string text( asctime( localtime( &t ) ) );
117  size_t pos = text.find('\n');
118  if( pos != std::string::npos ) text = text.substr( 0, pos );
119  text += " ";
120  if( daylight )
121  text += tzname[1];
122  else
123  text += tzname[0];
124  return text;
125  }
126 
127  void invertBox( std::vector<float> &corners )
128  {
129  std::swap( corners[0], corners[9] );
130  std::swap( corners[1], corners[10] );
131  std::swap( corners[2], corners[11] );
132 
133  std::swap( corners[3], corners[6] );
134  std::swap( corners[4], corners[7] );
135  std::swap( corners[5], corners[8] );
136 
137  std::swap( corners[12], corners[21] );
138  std::swap( corners[13], corners[22] );
139  std::swap( corners[14], corners[23] );
140 
141  std::swap( corners[15], corners[18] );
142  std::swap( corners[16], corners[19] );
143  std::swap( corners[17], corners[20] );
144  }
145 
146  void addBox( const std::vector<float> &corners, TEveElement* comp, FWProxyBuilderBase* pb )
147  {
148  TEveBox* eveBox = new TEveBox( "Box" );
149  eveBox->SetDrawFrame( false );
150  eveBox->SetPickable( true );
151  eveBox->SetVertices( &corners[0] );
152 
153  pb->setupAddElement( eveBox, comp );
154  }
155 
156  void addCircle( double eta, double phi, double radius, const unsigned int nLineSegments, TEveElement* comp, FWProxyBuilderBase* pb )
157  {
158  TEveStraightLineSet* container = new TEveStraightLineSet;
159 
160  for( unsigned int iphi = 0; iphi < nLineSegments; ++iphi )
161  {
162  container->AddLine( eta + radius * cos( 2 * M_PI / nLineSegments * iphi ),
163  phi + radius * sin( 2 * M_PI / nLineSegments * iphi ),
164  0.01,
165  eta + radius * cos( 2 * M_PI / nLineSegments * ( iphi + 1 )),
166  phi + radius * sin( 2 * M_PI / nLineSegments * ( iphi + 1 )),
167  0.01 );
168  }
169  pb->setupAddElement( container, comp );
170  }
171 
172  void addDashedArrow( double phi, double size, TEveElement* comp, FWProxyBuilderBase* pb )
173  {
174  TEveScalableStraightLineSet* marker = new TEveScalableStraightLineSet;
175  marker->SetLineWidth( 1 );
176  marker->SetLineStyle( 2 );
177  marker->AddLine( 0, 0, 0, size * cos( phi ), size * sin( phi ), 0 );
178  marker->AddLine( size * 0.9 * cos( phi + 0.03 ), size * 0.9 * sin( phi + 0.03 ), 0, size * cos( phi ), size * sin( phi ), 0 );
179  marker->AddLine( size * 0.9 * cos( phi - 0.03 ), size * 0.9 * sin( phi - 0.03 ), 0, size * cos( phi ), size * sin( phi ), 0 );
180  pb->setupAddElement( marker, comp );
181  }
182 
183  void addDashedLine( double phi, double theta, double size, TEveElement* comp, FWProxyBuilderBase* pb )
184  {
185  double r( 0 );
186  if( theta < pb->context().caloTransAngle() || M_PI - theta < pb->context().caloTransAngle())
187  r = pb->context().caloZ2() / fabs( cos( theta ));
188  else
189  r = pb->context().caloR1() / sin( theta );
190 
191  TEveStraightLineSet* marker = new TEveStraightLineSet;
192  marker->SetLineWidth( 2 );
193  marker->SetLineStyle( 2 );
194  marker->AddLine( r * cos( phi ) * sin( theta ), r * sin( phi ) * sin( theta ), r * cos( theta ),
195  ( r + size ) * cos( phi ) * sin( theta ), ( r + size ) * sin( phi ) * sin( theta ), ( r + size ) * cos( theta ));
196  pb->setupAddElement( marker, comp );
197  }
198 
199  void addDoubleLines( double phi, TEveElement* comp, FWProxyBuilderBase* pb )
200  {
201  TEveStraightLineSet* mainLine = new TEveStraightLineSet;
202  mainLine->AddLine( -5.191, phi, 0.01, 5.191, phi, 0.01 );
203  pb->setupAddElement( mainLine, comp );
204 
205  phi = phi > 0 ? phi - M_PI : phi + M_PI;
206  TEveStraightLineSet* secondLine = new TEveStraightLineSet;
207  secondLine->SetLineStyle( 7 );
208  secondLine->AddLine( -5.191, phi, 0.01, 5.191, phi, 0.01 );
209  pb->setupAddElement( secondLine, comp );
210  }
211 
212  //______________________________________________________________________________
213  void energyScaledBox3DCorners( const float* corners, float scale, std::vector<float>& scaledCorners, bool invert)
214  {
215  std::vector<float> centre( 3, 0 );
216 
217  for( unsigned int i = 0; i < 24; i += 3 )
218  {
219  centre[0] += corners[i];
220  centre[1] += corners[i + 1];
221  centre[2] += corners[i + 2];
222  }
223 
224  for( unsigned int i = 0; i < 3; ++i )
225  centre[i] *= 1.0f / 8.0f;
226 
227  // Coordinates for a scaled version of the original box
228  for( unsigned int i = 0; i < 24; i += 3 )
229  {
230  scaledCorners[i] = centre[0] + ( corners[i] - centre[0] ) * scale;
231  scaledCorners[i + 1] = centre[1] + ( corners[i + 1] - centre[1] ) * scale;
232  scaledCorners[i + 2] = centre[2] + ( corners[i + 2] - centre[2] ) * scale;
233  }
234 
235  if( invert )
236  invertBox( scaledCorners );
237  }
238 
239  void drawEnergyScaledBox3D( const float* corners, float scale, TEveElement* comp, FWProxyBuilderBase* pb, bool invert )
240  {
241  std::vector<float> scaledCorners( 24 );
242  energyScaledBox3DCorners(corners, scale, scaledCorners, invert);
243  addBox( scaledCorners, comp, pb );
244  }
245  //______________________________________________________________________________
246 
247  void etScaledBox3DCorners( const float* corners, float energy, float maxEnergy, std::vector<float>& scaledCorners, bool invert)
248  {
249  std::vector<float> centre( 3, 0 );
250 
251  for( unsigned int i = 0; i < 24; i += 3 )
252  {
253  centre[0] += corners[i];
254  centre[1] += corners[i + 1];
255  centre[2] += corners[i + 2];
256  }
257 
258  for( unsigned int i = 0; i < 3; ++i )
259  centre[i] *= 1.0f / 8.0f;
260 
261  TEveVector c( centre[0], centre[1], centre[2] );
262  float scale = energy / maxEnergy * sin( c.Theta());
263 
264  // Coordinates for a scaled version of the original box
265  for( unsigned int i = 0; i < 24; i += 3 )
266  {
267  scaledCorners[i] = centre[0] + ( corners[i] - centre[0] ) * scale;
268  scaledCorners[i + 1] = centre[1] + ( corners[i + 1] - centre[1] ) * scale;
269  scaledCorners[i + 2] = centre[2] + ( corners[i + 2] - centre[2] ) * scale;
270  }
271 
272  if( invert )
273  invertBox( scaledCorners );
274  }
275 
276  void drawEtScaledBox3D( const float* corners, float energy, float maxEnergy, TEveElement* comp, FWProxyBuilderBase* pb, bool invert )
277  {
278  std::vector<float> scaledCorners( 24 );
279  etScaledBox3DCorners(corners, energy, maxEnergy, scaledCorners, invert);
280  addBox( scaledCorners, comp, pb );
281  }
282 
283  //______________________________________________________________________________
284  void energyTower3DCorners( const float* corners, float scale, std::vector<float>& scaledCorners, bool reflect)
285  {
286  for( int i = 0; i < 24; ++i )
287  scaledCorners[i] = corners[i];
288  // Coordinates of a front face scaled
289  if( reflect )
290  {
291  // We know, that an ES rechit geometry in -Z needs correction.
292  // The back face is actually its front face.
293  for( unsigned int i = 0; i < 12; i += 3 )
294  {
295  TEveVector diff( corners[i] - corners[i + 12], corners[i + 1] - corners[i + 13], corners[i + 2] - corners[i + 14] );
296  diff.Normalize();
297  diff *= scale;
298 
299  scaledCorners[i] = corners[i] + diff.fX;
300  scaledCorners[i + 1] = corners[i + 1] + diff.fY;
301  scaledCorners[i + 2] = corners[i + 2] + diff.fZ;
302  }
303  }
304  else
305  {
306  for( unsigned int i = 0; i < 12; i += 3 )
307  {
308  TEveVector diff( corners[i + 12] - corners[i], corners[i + 13] - corners[i + 1], corners[i + 14] - corners[i + 2] );
309  diff.Normalize();
310  diff *= scale;
311 
312  scaledCorners[i] = corners[i + 12];
313  scaledCorners[i + 1] = corners[i + 13];
314  scaledCorners[i + 2] = corners[i + 14];
315 
316  scaledCorners[i + 12] = corners[i + 12] + diff.fX;
317  scaledCorners[i + 13] = corners[i + 13] + diff.fY;
318  scaledCorners[i + 14] = corners[i + 14] + diff.fZ;
319  }
320  }
321  }
322 
323  void drawEnergyTower3D( const float* corners, float scale, TEveElement* comp, FWProxyBuilderBase* pb, bool reflect )
324  {
325  std::vector<float> scaledCorners( 24 );
326  energyTower3DCorners(corners, scale, scaledCorners, reflect);
327  addBox( scaledCorners, comp, pb );
328  }
329 
330  //______________________________________________________________________________
331 
332  void etTower3DCorners( const float* corners, float scale, std::vector<float>& scaledCorners, bool reflect)
333  {
334  for( int i = 0; i < 24; ++i )
335  scaledCorners[i] = corners[i];
336  // Coordinates of a front face scaled
337  if( reflect )
338  {
339  // We know, that an ES rechit geometry in -Z needs correction.
340  // The back face is actually its front face.
341  for( unsigned int i = 0; i < 12; i += 3 )
342  {
343  TEveVector diff( corners[i] - corners[i + 12], corners[i + 1] - corners[i + 13], corners[i + 2] - corners[i + 14] );
344  diff.Normalize();
345  diff *= ( scale * sin( diff.Theta()));
346 
347  scaledCorners[i] = corners[i] + diff.fX;
348  scaledCorners[i + 1] = corners[i + 1] + diff.fY;
349  scaledCorners[i + 2] = corners[i + 2] + diff.fZ;
350  }
351  }
352  else
353  {
354  for( unsigned int i = 0; i < 12; i += 3 )
355  {
356  TEveVector diff( corners[i + 12] - corners[i], corners[i + 13] - corners[i + 1], corners[i + 14] - corners[i + 2] );
357  diff.Normalize();
358  diff *= ( scale * sin( diff.Theta()));
359 
360  scaledCorners[i] = corners[i + 12];
361  scaledCorners[i + 1] = corners[i + 13];
362  scaledCorners[i + 2] = corners[i + 14];
363 
364  scaledCorners[i + 12] = corners[i + 12] + diff.fX;
365  scaledCorners[i + 13] = corners[i + 13] + diff.fY;
366  scaledCorners[i + 14] = corners[i + 14] + diff.fZ;
367  }
368  }
369  }
370 
371 
372  void drawEtTower3D( const float* corners, float scale, TEveElement* comp, FWProxyBuilderBase* pb, bool reflect )
373  {
374  std::vector<float> scaledCorners( 24 );
375  etTower3DCorners(corners, scale, scaledCorners, reflect);
376  addBox( scaledCorners, comp, pb );
377  }
378 
379 
380 } // namespace fireworks
const fireworks::Context & context() const
int i
Definition: DBlmapReader.cc:9
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:224
T eta() const
void addDashedLine(double phi, double theta, double size, TEveElement *comp, FWProxyBuilderBase *pb)
void drawEtTower3D(const float *corners, float scale, TEveElement *, FWProxyBuilderBase *, bool reflect=false)
const T & max(const T &a, const T &b)
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:209
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
double f[11][100]
tuple text
Definition: runonSM.py:42
void addCircle(double eta, double phi, double radius, const unsigned int nLineSegments, TEveElement *comp, FWProxyBuilderBase *pb)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
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
#define M_PI
Definition: BFit3D.cc:3
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
tuple size
Write out results.
edm::Timestamp time() const
Definition: EventBase.h:57
void drawEtScaledBox3D(const float *corners, float energy, float maxEnergy, TEveElement *, FWProxyBuilderBase *, bool reflect=false)
Definition: DDAxes.h:10