Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-03 04:09:56

0001 // -*- C++ -*-
0002 //
0003 // Package: Fireworks
0004 // Class  : FWMET3DProxyBuilder.cc
0005 
0006 /*
0007 
0008  Description: [one line class summary]
0009 
0010  Usage:
0011     <usage>
0012 
0013 */
0014 //
0015 // Original Author:
0016 //         Created: Mon Jan 17 10:48:11 2011
0017 //
0018 //
0019 
0020 // system include files
0021 
0022 // user include files
0023 
0024 #include "TMath.h"
0025 #include "TEveArrow.h"
0026 #include "TEveScalableStraightLineSet.h"
0027 
0028 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
0029 #include "Fireworks/Core/interface/Context.h"
0030 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
0031 #include "DataFormats/METReco/interface/MET.h"
0032 
0033 // forward declarations
0034 
0035 class FWMET3DProxyBuilder : public FWSimpleProxyBuilderTemplate<reco::MET> {
0036 public:
0037   class Arrow : public TEveArrow {
0038   public:
0039     float m_et;
0040     float m_energy;
0041     const FWViewContext* m_vc;
0042 
0043     Arrow(Float_t x, Float_t y, Float_t z, Float_t xo, Float_t yo, Float_t zo = 0)
0044         : TEveArrow(x, y, z, xo, yo, zo), m_et(0), m_energy(0), m_vc(nullptr) {}
0045 
0046     void setScale(FWViewEnergyScale* caloScale) {
0047       static float maxW = 3;
0048       float scale = caloScale->getScaleFactor3D() * (caloScale->getPlotEt() ? m_et : m_energy);
0049       fVector.Normalize();
0050       fVector *= scale;
0051       fTubeR = TMath::Min(maxW / scale, 0.08f);
0052       fConeR = TMath::Min(maxW * 2.5f / scale, 0.25f);
0053     }
0054   };
0055 
0056   FWMET3DProxyBuilder();
0057   ~FWMET3DProxyBuilder() override;
0058 
0059   // ---------- const member functions ---------------------
0060 
0061   bool havePerViewProduct(FWViewType::EType) const override { return true; }  // used energy scaling
0062   void scaleProduct(TEveElementList* parent, FWViewType::EType, const FWViewContext* vc) override;
0063   void cleanLocal() override { m_arrows.clear(); }
0064 
0065   // ---------- static member functions --------------------
0066 
0067   // ---------- member functions ---------------------------
0068 
0069   REGISTER_PROXYBUILDER_METHODS();
0070 
0071   FWMET3DProxyBuilder(const FWMET3DProxyBuilder&) = delete;                   // stop default
0072   const FWMET3DProxyBuilder& operator=(const FWMET3DProxyBuilder&) = delete;  // stop default
0073 
0074 private:
0075   using FWSimpleProxyBuilderTemplate<reco::MET>::build;
0076   void build(const reco::MET&, unsigned int, TEveElement&, const FWViewContext*) override;
0077 
0078   // ---------- member data --------------------------------
0079   std::vector<Arrow*> m_arrows;
0080 };
0081 
0082 //
0083 // constructors and destructor
0084 //
0085 FWMET3DProxyBuilder::FWMET3DProxyBuilder() {}
0086 
0087 FWMET3DProxyBuilder::~FWMET3DProxyBuilder() {}
0088 
0089 //
0090 // member functions
0091 //
0092 void FWMET3DProxyBuilder::scaleProduct(TEveElementList* parent, FWViewType::EType type, const FWViewContext* vc) {
0093   // printf("scale prod \n");
0094   FWViewEnergyScale* caloScale = vc->getEnergyScale();
0095 
0096   for (std::vector<Arrow*>::iterator i = m_arrows.begin(); i != m_arrows.end(); ++i) {
0097     if (vc == (*i)->m_vc) {
0098       (*i)->setScale(caloScale);
0099     }
0100   }
0101 }
0102 
0103 void FWMET3DProxyBuilder::build(const reco::MET& met,
0104                                 unsigned int iIndex,
0105                                 TEveElement& oItemHolder,
0106                                 const FWViewContext* vc) {
0107   float r0;
0108   float phi = met.phi();
0109   float theta = met.theta();
0110 
0111   if (TMath::Abs(met.eta()) < context().caloTransEta())
0112     r0 = context().caloR1() / sin(theta);
0113   else
0114     r0 = context().caloZ1() / fabs(cos(theta));
0115 
0116   Arrow* arrow = new Arrow(sin(theta) * cos(phi),
0117                            sin(theta) * sin(phi),
0118                            cos(theta),
0119                            r0 * sin(theta) * cos(phi),
0120                            r0 * sin(theta) * sin(phi),
0121                            r0 * cos(theta));
0122   arrow->m_et = met.et();
0123   arrow->m_energy = met.energy();
0124   arrow->m_vc = vc;
0125   arrow->SetConeL(0.15);
0126   arrow->SetConeR(0.06);
0127   setupAddElement(arrow, &oItemHolder);
0128 
0129   m_arrows.push_back(arrow);
0130   arrow->setScale(vc->getEnergyScale());
0131   arrow->setScale(vc->getEnergyScale());
0132 
0133   context().voteMaxEtAndEnergy(met.et(), met.energy());
0134 }
0135 
0136 //
0137 // const member functions
0138 //
0139 
0140 //
0141 // static member functions
0142 //
0143 
0144 REGISTER_FWPROXYBUILDER(FWMET3DProxyBuilder, reco::MET, "recoMET", FWViewType::kAll3DBits);