Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:31

0001 #include "Fireworks/ParticleFlow/interface/FWPFLegoRecHit.h"
0002 #include "Fireworks/Core/interface/FWProxyBuilderBase.h"
0003 
0004 //______________________________________________________________________________
0005 FWPFLegoRecHit::FWPFLegoRecHit(const std::vector<TEveVector> &corners,
0006                                TEveElement *comp,
0007                                FWProxyBuilderBase *pb,
0008                                const FWViewContext *vc,
0009                                float e,
0010                                float et)
0011     : m_energy(e), m_et(et), m_isTallest(false) {
0012   buildTower(corners, vc);
0013   buildLineSet(corners, vc);
0014 
0015   pb->setupAddElement(m_tower, comp);
0016   pb->setupAddElement(m_ls, comp);
0017 }
0018 
0019 //______________________________________________________________________________
0020 void FWPFLegoRecHit::setupEveBox(std::vector<TEveVector> &corners, float scale) {
0021   for (size_t i = 0; i < 4; ++i) {
0022     int j = i + 4;
0023     corners[i + 4].fZ = corners[i].fZ + scale;
0024     m_tower->SetVertex(i, corners[i]);
0025     m_tower->SetVertex(j, corners[j]);
0026   }
0027 
0028   m_tower->SetPickable(true);
0029   m_tower->SetDrawFrame(false);
0030   m_tower->SetLineWidth(1.0);
0031   m_tower->SetLineColor(kBlack);
0032 }
0033 
0034 //______________________________________________________________________________
0035 void FWPFLegoRecHit::buildTower(const std::vector<TEveVector> &corners, const FWViewContext *vc) {
0036   m_tower = new TEveBox("EcalRecHitTower");
0037   std::vector<TEveVector> towerCorners = corners;
0038   FWViewEnergyScale *caloScale = vc->getEnergyScale();
0039   float val = caloScale->getPlotEt() ? m_et : m_energy;
0040   float scale = caloScale->getScaleFactorLego() * val;
0041 
0042   if (scale < 0)
0043     scale *= -1;
0044 
0045   setupEveBox(towerCorners, scale);
0046 }
0047 
0048 //______________________________________________________________________________
0049 void FWPFLegoRecHit::buildLineSet(const std::vector<TEveVector> &corners, const FWViewContext *vc) {
0050   m_ls = new TEveStraightLineSet("EcalRecHitLineSet");
0051 
0052   // no need to set anything, all is re-set in updateScales()
0053   // reserve space for square outline
0054   TEveVector c;
0055   m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
0056   m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
0057   m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
0058   m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
0059 
0060   // last line is trick to add a marker in line set
0061   m_ls->SetMarkerStyle(1);
0062   m_ls->AddLine(c.fX, c.fY, c.fZ, c.fX, c.fY, c.fZ);
0063   m_ls->AddMarker(0, 0.);
0064 }
0065 
0066 //______________________________________________________________________________
0067 void FWPFLegoRecHit::updateScale(const FWViewContext *vc, float maxLogVal) {
0068   FWViewEnergyScale *caloScale = vc->getEnergyScale();
0069   float val = caloScale->getPlotEt() ? m_et : m_energy;
0070   float scale = caloScale->getScaleFactorLego() * val;
0071 
0072   // printf("scale %f %f\n",  caloScale->getValToHeight(), val);
0073 
0074   if (scale < 0)
0075     scale *= -1;
0076 
0077   // Reposition top points of tower
0078   const float *data;
0079   TEveVector c;
0080   for (unsigned int i = 0; i < 4; ++i) {
0081     data = m_tower->GetVertex(i);
0082     c.fX += data[0];
0083     c.fY += data[1];
0084     m_tower->SetVertex(i, data[0], data[1], 0);
0085     m_tower->SetVertex(i + 4, data[0], data[1], scale);
0086   }
0087   c *= 0.25;
0088   // Scale lineset
0089   float s = log(1 + val) / maxLogVal;
0090   float d = 0.5 * (m_tower->GetVertex(1)[0] - m_tower->GetVertex(0)[0]);
0091   d *= s;
0092   float z = scale * 1.001;
0093   setLine(0, c.fX - d, c.fY - d, z, c.fX + d, c.fY - d, z);
0094   setLine(1, c.fX + d, c.fY - d, z, c.fX + d, c.fY + d, z);
0095   setLine(2, c.fX + d, c.fY + d, z, c.fX - d, c.fY + d, z);
0096   setLine(3, c.fX - d, c.fY + d, z, c.fX - d, c.fY - d, z);
0097 
0098   if (m_isTallest) {
0099     // This is the tallest tower and hence two additional lines needs scaling
0100     setLine(4, c.fX - d, c.fY - d, z, c.fX + d, c.fY + d, z);
0101     setLine(5, c.fX - d, c.fY + d, z, c.fX + d, c.fY - d, z);
0102   }
0103 
0104   TEveStraightLineSet::Marker_t *m = ((TEveStraightLineSet::Marker_t *)(m_ls->GetMarkerPlex().Atom(0)));
0105   m->fV[0] = c.fX;
0106   m->fV[1] = c.fY;
0107   m->fV[2] = z;
0108 
0109   // stamp changed elements
0110   m_tower->StampTransBBox();
0111   m_ls->StampTransBBox();
0112 }
0113 
0114 //______________________________________________________________________________
0115 void FWPFLegoRecHit::setLine(int idx, float x1, float y1, float z1, float x2, float y2, float z2) {
0116   // AMT: this func should go in TEveStraightLineSet class
0117 
0118   TEveStraightLineSet::Line_t *l = ((TEveStraightLineSet::Line_t *)(m_ls->GetLinePlex().Atom(idx)));
0119 
0120   l->fV1[0] = x1;
0121   l->fV1[1] = y1;
0122   l->fV1[2] = z1;
0123 
0124   l->fV2[0] = x2;
0125   l->fV2[1] = y2;
0126   l->fV2[2] = z2;
0127 }
0128 
0129 //______________________________________________________________________________
0130 void FWPFLegoRecHit::setIsTallest(bool b) {
0131   m_isTallest = b;
0132 
0133   if (m_isTallest) {
0134     TEveVector vec;
0135     addLine(vec, vec);
0136     addLine(vec, vec);
0137   }
0138 }
0139 
0140 //______________________________________________________________________________
0141 void FWPFLegoRecHit::addLine(float x1, float y1, float z1, float x2, float y2, float z2) {
0142   m_ls->AddLine(x1, y1, z1, x2, y2, z2);
0143 }
0144 
0145 //______________________________________________________________________________
0146 void FWPFLegoRecHit::addLine(const TEveVector &v1, const TEveVector &v2) {
0147   m_ls->AddLine(v1.fX, v1.fY, v1.fZ, v2.fX, v2.fY, v2.fZ);
0148 }