File indexing completed on 2024-04-06 12:11:28
0001 #include "TEveCompound.h"
0002
0003 #include "Fireworks/Calo/interface/FWBoxRecHit.h"
0004 #include "Fireworks/Core/interface/Context.h"
0005 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
0006 #include "Fireworks/Core/interface/CmsShowCommon.h"
0007
0008
0009 FWBoxRecHit::FWBoxRecHit(const std::vector<TEveVector> &corners, TEveElement *list, float e, float et)
0010 : m_tower(nullptr), m_ls(nullptr), m_energy(e), m_et(et), m_isTallest(false) {
0011 buildTower(corners);
0012 buildLineSet(corners);
0013
0014 TEveCompound *h = new TEveCompound("rechit box", "tower");
0015 list->AddElement(h);
0016 h->CSCApplyMainColorToAllChildren();
0017 h->AddElement(m_tower);
0018 h->AddElement(m_ls);
0019 }
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 void FWBoxRecHit::setupEveBox(std::vector<TEveVector> &corners, float scale) {
0032
0033
0034 for (size_t i = 0; i < 4; ++i) {
0035 int j = i + 4;
0036 corners[i + 4].fZ = scale;
0037 m_tower->SetVertex(i, corners[i]);
0038 m_tower->SetVertex(j, corners[j]);
0039
0040 }
0041
0042 m_tower->SetLineWidth(1.0);
0043 m_tower->SetLineColor(kBlack);
0044 }
0045
0046
0047 void FWBoxRecHit::buildTower(const std::vector<TEveVector> &corners) {
0048 m_tower = new TEveBox("EcalRecHitTower");
0049 std::vector<TEveVector> towerCorners = corners;
0050
0051
0052
0053
0054
0055
0056
0057
0058 setupEveBox(towerCorners, 0.01f);
0059 }
0060
0061
0062 void FWBoxRecHit::buildLineSet(const std::vector<TEveVector> &corners) {
0063 m_ls = new TEveStraightLineSet("EcalRecHitLineSet");
0064
0065 const float *data;
0066 TEveVector c;
0067 for (unsigned int i = 0; i < 4; ++i) {
0068 data = m_tower->GetVertex(i);
0069 c.fX += data[0];
0070 c.fY += data[1];
0071 m_ls->AddLine(data[0], data[1], 0, data[0], data[1], 0);
0072 }
0073 c *= 0.25;
0074
0075
0076 m_ls->SetMarkerStyle(1);
0077 m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
0078 m_ls->AddMarker(0, 0.);
0079
0080 m_ls->ResetBBox();
0081 m_ls->ComputeBBox();
0082 }
0083
0084
0085 void FWBoxRecHit::updateScale(float scaleFac, float maxLogVal, bool plotEt) {
0086
0087
0088
0089
0090
0091 float val = plotEt ? m_et : m_energy;
0092 float scale = scaleFac * val;
0093
0094 const float *data;
0095 TEveVector c;
0096 for (unsigned int i = 0; i < 4; ++i) {
0097 data = m_tower->GetVertex(i);
0098 c.fX += data[0];
0099 c.fY += data[1];
0100 m_tower->SetVertex(i, data[0], data[1], 0);
0101 m_tower->SetVertex(i + 4, data[0], data[1], scale);
0102 }
0103 c *= 0.25;
0104 if (false)
0105 c.Dump();
0106
0107
0108 float s = log(1 + val) / maxLogVal;
0109 float d = 0.5 * (m_tower->GetVertex(1)[0] - m_tower->GetVertex(0)[0]);
0110 d *= s;
0111 float z = scale * 1.001;
0112 setLine(0, c.fX - d, c.fY - d, z, c.fX + d, c.fY - d, z);
0113 setLine(1, c.fX + d, c.fY - d, z, c.fX + d, c.fY + d, z);
0114 setLine(2, c.fX + d, c.fY + d, z, c.fX - d, c.fY + d, z);
0115 setLine(3, c.fX - d, c.fY + d, z, c.fX - d, c.fY - d, z);
0116
0117 if (m_isTallest) {
0118 m_ls->AddLine(c.fX - d, c.fY - d, z, c.fX + d, c.fY + d, z);
0119 m_ls->AddLine(c.fX - d, c.fY + d, z, c.fX + d, c.fY - d, z);
0120 m_ls->GetMarkerPlex().Refit();
0121 }
0122
0123 TEveStraightLineSet::Marker_t *m = ((TEveStraightLineSet::Marker_t *)(m_ls->GetMarkerPlex().Atom(0)));
0124 m->fV[0] = c.fX;
0125 m->fV[1] = c.fY;
0126 m->fV[2] = z;
0127
0128
0129
0130 m_ls->ComputeBBox();
0131
0132 m_tower->StampTransBBox();
0133 m_ls->StampTransBBox();
0134 }
0135
0136
0137 void FWBoxRecHit::setLine(int idx, float x1, float y1, float z1, float x2, float y2, float z2) {
0138
0139
0140 TEveStraightLineSet::Line_t *l = ((TEveStraightLineSet::Line_t *)(m_ls->GetLinePlex().Atom(idx)));
0141
0142 l->fV1[0] = x1;
0143 l->fV1[1] = y1;
0144 l->fV1[2] = z1;
0145
0146 l->fV2[0] = x2;
0147 l->fV2[1] = y2;
0148 l->fV2[2] = z2;
0149 }
0150
0151
0152 void FWBoxRecHit::setIsTallest() { m_isTallest = true; }
0153
0154
0155 void FWBoxRecHit::addLine(float x1, float y1, float z1, float x2, float y2, float z2) {
0156 m_ls->AddLine(x1, y1, z1, x2, y2, z2);
0157 }
0158
0159
0160 void FWBoxRecHit::addLine(const TEveVector &v1, const TEveVector &v2) {
0161 m_ls->AddLine(v1.fX, v1.fY, v1.fZ, v2.fX, v2.fY, v2.fZ);
0162 }