Back to home page

Project CMSSW displayed by LXR

 
 

    


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  FWViewEnergyScale*
0024  FWBoxRecHit::getEnergyScale() const
0025  {
0026     return  fireworks::Context::getInstance()->commonPrefs()->getEnergyScale();
0027  }
0028 */
0029 
0030 //______________________________________________________________________________
0031 void FWBoxRecHit::setupEveBox(std::vector<TEveVector> &corners, float scale) {
0032   // printf("---\n");
0033   //   TEveVector z(0.f, 0.f, 0.f);
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     //  printf("%ld -> %f, %f , height=%f \n",i, corners[i].fX, corners[i].fY, scale);
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    FWViewEnergyScale *caloScale = 1;//getEnergyScale();
0052    float val = caloScale->getPlotEt() ? m_et : m_energy;
0053    float scale = caloScale->getScaleFactorLego() * val;
0054 
0055    if( scale < 0 )
0056       scale *= -1;
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   // last line is trick to add a marker in line set
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   //   FWViewEnergyScale *caloScale = getEnergyScale();
0087   //
0088   //float scale = caloScale->getScaleFactorLego() * val;
0089 
0090   // printf("scale %f %f\n",  caloScale->getValToHeight(), val);
0091   float val = plotEt ? m_et : m_energy;
0092   float scale = scaleFac * val;
0093   // Reposition top points of tower
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   // Scale lineset
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   // stamp changed elements
0129 
0130   m_ls->ComputeBBox();
0131   //   float* bb = m_ls->GetBBox();
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   // AMT: this func should go in TEveStraightLineSet class
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 }