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