Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "Fireworks/Calo/plugins/FWCaloRecHitDigitSetProxyBuilder.h"
0002 #include "TEveBoxSet.h"
0003 #include "FWCaloRecHitDigitSetProxyBuilder.h"
0004 #include "Fireworks/Core/interface/FWDigitSetProxyBuilder.h"
0005 #include "Fireworks/Core/interface/FWEventItem.h"
0006 #include "Fireworks/Core/interface/FWGeometry.h"
0007 #include "Fireworks/Core/interface/BuilderUtils.h"
0008 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
0009 #include "DataFormats/CaloRecHit/interface/CaloRecHit.h"
0010 
0011 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
0012 
0013 FWCaloRecHitDigitSetProxyBuilder::FWCaloRecHitDigitSetProxyBuilder()
0014     : m_invertBox(false), m_ignoreGeoShapeSize(false), m_enlarge(1.0) {}
0015 
0016 //______________________________________________________________________________
0017 
0018 void FWCaloRecHitDigitSetProxyBuilder::setItem(const FWEventItem* iItem) {
0019   FWProxyBuilderBase::setItem(iItem);
0020   if (iItem) {
0021     iItem->getConfig()->assertParam("Enlarge", 1.0, 1.0, 5.0);
0022     // iItem->getConfig()->assertParam( "IgnoreShapeSize", false);
0023   }
0024 }
0025 //______________________________________________________________________________
0026 
0027 void FWCaloRecHitDigitSetProxyBuilder::viewContextBoxScale(
0028     const float* corners, float scale, bool plotEt, std::vector<float>& scaledCorners, const CaloRecHit*) {
0029   scale *= m_enlarge;
0030   if (m_ignoreGeoShapeSize) {
0031     // Same functionality as fireworks::energyTower3DCorners()
0032 
0033     for (int i = 0; i < 24; ++i)
0034       scaledCorners[i] = corners[i];
0035 
0036     // Coordinates of a front face scaled
0037     if (m_invertBox) {
0038       // We know, that an ES rechit geometry in -Z needs correction.
0039       // The back face is actually its front face.
0040       for (unsigned int i = 0; i < 12; i += 3) {
0041         m_vector.Set(corners[i] - corners[i + 12], corners[i + 1] - corners[i + 13], corners[i + 2] - corners[i + 14]);
0042         m_vector.Normalize();
0043         m_vector *= scale;
0044 
0045         scaledCorners[i] = corners[i] + m_vector.fX;
0046         scaledCorners[i + 1] = corners[i + 1] + m_vector.fY;
0047         scaledCorners[i + 2] = corners[i + 2] + m_vector.fZ;
0048       }
0049     } else {
0050       for (unsigned int i = 0; i < 12; i += 3) {
0051         m_vector.Set(corners[i + 12] - corners[i], corners[i + 13] - corners[i + 1], corners[i + 14] - corners[i + 2]);
0052         m_vector.Normalize();
0053         m_vector *= scale;
0054 
0055         scaledCorners[i] = corners[i + 12];
0056         scaledCorners[i + 1] = corners[i + 13];
0057         scaledCorners[i + 2] = corners[i + 14];
0058 
0059         scaledCorners[i + 12] = corners[i + 12] + m_vector.fX;
0060         scaledCorners[i + 13] = corners[i + 13] + m_vector.fY;
0061         scaledCorners[i + 14] = corners[i + 14] + m_vector.fZ;
0062       }
0063     }
0064   } else {
0065     // Same functionality as fireworks::energyScaledBox3DCorners().
0066 
0067     m_vector.Set(0.f, 0.f, 0.f);
0068     for (unsigned int i = 0; i < 24; i += 3) {
0069       m_vector[0] += corners[i];
0070       m_vector[1] += corners[i + 1];
0071       m_vector[2] += corners[i + 2];
0072     }
0073     m_vector *= 1.f / 8.f;
0074 
0075     if (plotEt) {
0076       scale *= m_vector.Perp() / m_vector.Mag();
0077     }
0078 
0079     // Coordinates for a scaled version of the original box
0080     for (unsigned int i = 0; i < 24; i += 3) {
0081       scaledCorners[i] = m_vector[0] + (corners[i] - m_vector[0]) * scale;
0082       scaledCorners[i + 1] = m_vector[1] + (corners[i + 1] - m_vector[1]) * scale;
0083       scaledCorners[i + 2] = m_vector[2] + (corners[i + 2] - m_vector[2]) * scale;
0084     }
0085 
0086     if (m_invertBox)
0087       fireworks::invertBox(scaledCorners);
0088   }
0089 }
0090 //_____________________________________________________________________________
0091 
0092 float FWCaloRecHitDigitSetProxyBuilder::scaleFactor(const FWViewContext* vc) {
0093   // printf("scale face %f \n", vc->getEnergyScale()->getScaleFactor3D());
0094   return vc->getEnergyScale()->getScaleFactor3D() / 50;
0095 }
0096 
0097 //______________________________________________________________________________
0098 
0099 void FWCaloRecHitDigitSetProxyBuilder::scaleProduct(TEveElementList* parent,
0100                                                     FWViewType::EType type,
0101                                                     const FWViewContext* vc) {
0102   size_t size = item()->size();
0103   if (!size)
0104     return;
0105 
0106   std::vector<float> scaledCorners(24);
0107   float scale = scaleFactor(vc);
0108 
0109   assert(parent->NumChildren() == 1);
0110   TEveBoxSet* boxSet = static_cast<TEveBoxSet*>(*parent->BeginChildren());
0111 
0112   for (int index = 0; index < static_cast<int>(size); ++index) {
0113     const CaloRecHit* hit = (const CaloRecHit*)item()->modelData(index);
0114     const float* corners = item()->getGeom()->getCorners(hit->detid());
0115     if (corners == nullptr)
0116       continue;
0117 
0118     FWDigitSetProxyBuilder::BFreeBox_t* b = (FWDigitSetProxyBuilder::BFreeBox_t*)boxSet->GetPlex()->Atom(index);
0119 
0120     viewContextBoxScale(corners, hit->energy() * scale, vc->getEnergyScale()->getPlotEt(), scaledCorners, hit);
0121     memcpy(b->fVertices, &scaledCorners[0], sizeof(b->fVertices));
0122   }
0123   boxSet->ElementChanged();
0124 }
0125 //______________________________________________________________________________
0126 
0127 void FWCaloRecHitDigitSetProxyBuilder::build(const FWEventItem* iItem,
0128                                              TEveElementList* product,
0129                                              const FWViewContext* vc) {
0130   size_t size = iItem->size();
0131   if (!size)
0132     return;
0133 
0134   // m_ignoreGeoShapeSize = item()->getConfig()->value<bool>("IgnoreShapeSize");
0135   m_enlarge = item()->getConfig()->value<double>("Enlarge");
0136 
0137   std::vector<float> scaledCorners(24);
0138 
0139   float scale = scaleFactor(vc);
0140 
0141   TEveBoxSet* boxSet = addBoxSetToProduct(product);
0142   boxSet->SetAntiFlick(kTRUE);
0143   for (int index = 0; index < static_cast<int>(size); ++index) {
0144     const CaloRecHit* hit = (const CaloRecHit*)item()->modelData(index);
0145 
0146     const float* corners = context().getGeom()->getCorners(hit->detid());
0147     if (corners) {
0148       m_vector.Set(0.f, 0.f, 0.f);
0149       for (unsigned int i = 0; i < 24; i += 3) {
0150         m_vector[0] += corners[i];
0151         m_vector[1] += corners[i + 1];
0152         m_vector[2] += corners[i + 2];
0153       }
0154       m_vector.Normalize();
0155       context().voteMaxEtAndEnergy(m_vector.Perp() * hit->energy(), hit->energy());
0156       viewContextBoxScale(corners, hit->energy() * scale, vc->getEnergyScale()->getPlotEt(), scaledCorners, hit);
0157     }
0158 
0159     addBox(boxSet, &scaledCorners[0], iItem->modelInfo(index).displayProperties());
0160   }
0161 }