Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:51

0001 #include "Fireworks/ParticleFlow/interface/FWPFRhoPhiRecHit.h"
0002 
0003 //______________________________________________________________________________
0004 FWPFRhoPhiRecHit::FWPFRhoPhiRecHit(FWProxyBuilderBase *pb,
0005                                    TEveElement *iH,
0006                                    const FWViewContext *vc,
0007                                    float E,
0008                                    float et,
0009                                    double lPhi,
0010                                    double rPhi,
0011                                    std::vector<TEveVector> &bCorners)
0012     : m_hasChild(false), m_energy(E), m_et(et), m_lPhi(lPhi), m_rPhi(rPhi), m_child(nullptr) {
0013   buildRecHit(pb, iH, vc, bCorners);
0014 }
0015 
0016 //______________________________________________________________________________
0017 FWPFRhoPhiRecHit::~FWPFRhoPhiRecHit() {}
0018 
0019 //______________________________________________________________________________
0020 void FWPFRhoPhiRecHit::updateScale(const FWViewContext *vc) {
0021   FWViewEnergyScale *caloScale = vc->getEnergyScale();
0022   float value = caloScale->getPlotEt() ? m_et : m_energy;
0023   Double_t scale = caloScale->getScaleFactor3D() * value;
0024   unsigned int a = 0;
0025 
0026   if (scale < 0.f)
0027     scale *= -1.f;
0028 
0029   // Scale centres
0030   TEveVector sc1 = m_corners[1];
0031   TEveVector sc2 = m_corners[0];
0032 
0033   // Used to store normalized vectors
0034   TEveVector v1 = sc1;  // Bottom right corner
0035   TEveVector v2 = sc2;  // Bottom left corner
0036 
0037   v1.Normalize();
0038   v2.Normalize();
0039 
0040   v1 *= scale;  // Now at new height
0041   v2 *= scale;
0042 
0043   // Get line parameters and scale coordinates
0044   TEveChunkManager::iterator li(m_ls->GetLinePlex());
0045   while (li.next()) {
0046     TEveStraightLineSet::Line_t &l = *(TEveStraightLineSet::Line_t *)li();
0047     switch (a) {
0048       case 0:
0049         // Left side of tower first
0050         l.fV1[0] = sc2.fX;
0051         l.fV1[1] = sc2.fY;
0052         l.fV2[0] = sc2.fX + v2.fX;
0053         l.fV2[1] = sc2.fY + v2.fY;
0054         break;
0055 
0056       case 1:
0057         // Top of tower
0058         l.fV1[0] = sc2.fX + v2.fX;
0059         l.fV1[1] = sc2.fY + v2.fY;
0060         l.fV2[0] = sc1.fX + v1.fX;
0061         l.fV2[1] = sc1.fY + v1.fY;
0062         break;
0063 
0064       case 2:
0065         // Right hand side of tower
0066         l.fV1[0] = sc1.fX + v1.fX;
0067         l.fV1[1] = sc1.fY + v1.fY;
0068         l.fV2[0] = sc1.fX;
0069         l.fV2[1] = sc1.fY;
0070         break;
0071 
0072       case 3:
0073         // Bottom of tower
0074         l.fV1[0] = sc1.fX;
0075         l.fV1[1] = sc1.fY;
0076         l.fV2[0] = sc2.fX;
0077         l.fV2[1] = sc2.fY;
0078         break;
0079     }
0080     a++;
0081   }
0082   TEveProjected *proj = *(m_ls)->BeginProjecteds();
0083   proj->UpdateProjection();
0084 
0085   m_corners[2] = sc2 + v2;  // New top left of tower
0086   m_corners[3] = sc1 + v1;  // New top right of tower
0087 
0088   if (m_hasChild) {
0089     m_child->setCorners(0, m_corners[2]);
0090     m_child->setCorners(1, m_corners[3]);  // Base of child is now top of parent
0091     m_child->updateScale(vc);
0092   }
0093 }
0094 
0095 //______________________________________________________________________________
0096 void FWPFRhoPhiRecHit::clean() {
0097   m_corners.clear();
0098   if (m_hasChild)
0099     m_child->clean();
0100 
0101   delete this;
0102 }
0103 
0104 //______________________________________________________________________________
0105 void FWPFRhoPhiRecHit::addChild(
0106     FWProxyBuilderBase *pb, TEveElement *itemHolder, const FWViewContext *vc, float E, float et) {
0107   if (m_hasChild)  // Already has a child stacked on top so move on to child
0108     m_child->addChild(pb, itemHolder, vc, E, et);
0109   else {
0110     std::vector<TEveVector> corners(2);
0111     corners[0] = m_corners[2];  // Top left of current tower
0112     corners[1] = m_corners[3];  // Top right of current tower
0113     m_child = new FWPFRhoPhiRecHit(pb, itemHolder, vc, E, et, m_lPhi, m_rPhi, corners);
0114     m_hasChild = true;
0115   }
0116 }
0117 
0118 //______________________________________________________________________________
0119 void FWPFRhoPhiRecHit::buildRecHit(FWProxyBuilderBase *pb,
0120                                    TEveElement *itemHolder,
0121                                    const FWViewContext *vc,
0122                                    std::vector<TEveVector> &bCorners) {
0123   float scale = 0;
0124   float value = 0;
0125   TEveVector v1, v2, v3, v4;
0126   TEveVector vec;
0127 
0128   FWViewEnergyScale *caloScale = vc->getEnergyScale();
0129   value = caloScale->getPlotEt() ? m_et : m_energy;
0130   scale = caloScale->getScaleFactor3D() * value;
0131 
0132   v1 = bCorners[0];  // Bottom left
0133   v2 = bCorners[1];  // Bottom right
0134 
0135   v3 = v1;
0136   vec = v3;
0137   vec.Normalize();
0138   v3 = v3 + (vec * scale);
0139 
0140   v4 = v2;
0141   vec = v4;
0142   vec.Normalize();
0143   v4 = v4 + (vec * scale);
0144 
0145   m_ls = new TEveScalableStraightLineSet("rhophiRecHit");
0146   m_ls->AddLine(v1.fX, v1.fY, 0, v3.fX, v3.fY, 0);  // Bottom left - Top left
0147   m_ls->AddLine(v3.fX, v3.fY, 0, v4.fX, v4.fY, 0);  // Top left - Top right
0148   m_ls->AddLine(v4.fX, v4.fY, 0, v2.fX, v2.fY, 0);  // Top right - Bottom right
0149   m_ls->AddLine(v2.fX, v2.fY, 0, v1.fX, v1.fY, 0);  // Bottom right - Bottom left
0150 
0151   m_corners.push_back(v1);
0152   m_corners.push_back(v2);
0153   m_corners.push_back(v3);
0154   m_corners.push_back(v4);
0155 
0156   pb->setupAddElement(m_ls, itemHolder);
0157 }