CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/Fireworks/Calo/plugins/FWMET3DProxyBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package: Fireworks
00004 // Class  : FWMET3DProxyBuilder.cc
00005 
00006 /*
00007 
00008  Description: [one line class summary]
00009 
00010  Usage:
00011     <usage>
00012 
00013 */
00014 //
00015 // Original Author: 
00016 //         Created: Mon Jan 17 10:48:11 2011 
00017 //
00018 //
00019 
00020 // system include files
00021 
00022 // user include files
00023 
00024 #include "TMath.h"
00025 #include "TEveArrow.h"
00026 #include "TEveScalableStraightLineSet.h"
00027 
00028 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
00029 #include "Fireworks/Core/interface/Context.h"
00030 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
00031 #include "DataFormats/METReco/interface/MET.h"
00032 
00033 // forward declarations
00034 
00035 class FWMET3DProxyBuilder : public FWSimpleProxyBuilderTemplate<reco::MET> {
00036 public:
00037    class Arrow : public TEveArrow
00038    {
00039    public:
00040       float m_et;
00041       float m_energy;
00042       const FWViewContext* m_vc;
00043 
00044       Arrow(Float_t x, Float_t y, Float_t z,
00045             Float_t xo, Float_t yo, Float_t zo=0) : 
00046          TEveArrow(x, y, z, xo, yo, zo),
00047          m_et(0), m_energy(0), m_vc(0) {}
00048 
00049       void setScale(FWViewEnergyScale* caloScale)
00050       {
00051          static float maxW = 3;
00052          float scale = caloScale->getScaleFactor3D()*(caloScale->getPlotEt() ? m_et : m_energy);
00053          fVector.Normalize();
00054          fVector *= scale;
00055          fTubeR = TMath::Min(maxW/scale, 0.08f);
00056          fConeR = TMath::Min(maxW*2.5f/scale, 0.25f);
00057 
00058       }
00059    };
00060 
00061    FWMET3DProxyBuilder();
00062    virtual ~FWMET3DProxyBuilder();
00063 
00064    // ---------- const member functions ---------------------
00065 
00066    virtual bool havePerViewProduct(FWViewType::EType) const { return true; } // used energy scaling
00067    virtual void scaleProduct(TEveElementList* parent, FWViewType::EType, const FWViewContext* vc);
00068    virtual void cleanLocal() { m_arrows.clear(); }
00069 
00070    // ---------- static member functions --------------------
00071 
00072    // ---------- member functions ---------------------------
00073 
00074    REGISTER_PROXYBUILDER_METHODS();
00075 
00076 private:
00077    FWMET3DProxyBuilder(const FWMET3DProxyBuilder&); // stop default
00078    const FWMET3DProxyBuilder& operator=(const FWMET3DProxyBuilder&); // stop default
00079    
00080    void build(const reco::MET&, unsigned int, TEveElement&, const FWViewContext*);
00081 
00082    // ---------- member data --------------------------------
00083    std::vector<Arrow*> m_arrows;
00084 };
00085 
00086 //
00087 // constructors and destructor
00088 //
00089 FWMET3DProxyBuilder::FWMET3DProxyBuilder()
00090 {
00091 }
00092 
00093 FWMET3DProxyBuilder::~FWMET3DProxyBuilder()
00094 {
00095 }
00096 
00097 //
00098 // member functions
00099 //
00100 void
00101 FWMET3DProxyBuilder::scaleProduct(TEveElementList* parent, FWViewType::EType type, const FWViewContext* vc)
00102 {
00103    // printf("scale prod \n");
00104    FWViewEnergyScale* caloScale = vc->getEnergyScale();  
00105 
00106    for (std::vector<Arrow*>::iterator i = m_arrows.begin(); i!= m_arrows.end(); ++ i)
00107    {
00108       if ( vc == (*i)->m_vc)
00109       {
00110          (*i)->setScale(caloScale);  
00111       }
00112    }
00113 }
00114 
00115 void 
00116 FWMET3DProxyBuilder::build(const reco::MET& met, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext* vc)
00117 {
00118    float r0;
00119    float phi   = met.phi();
00120    float theta = met.theta();
00121 
00122    if (TMath::Abs(met.eta()) < context().caloTransEta())
00123       r0  = context().caloR1()/sin(theta);
00124    else
00125       r0  = context().caloZ1()/fabs(cos(theta));
00126 
00127    Arrow* arrow = new Arrow( sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta),
00128                              r0*sin(theta)*cos(phi), r0*sin(theta)*sin(phi), r0*cos(theta));
00129    arrow->m_et = met.et();
00130    arrow->m_energy = met.energy();
00131    arrow->m_vc = vc;
00132    arrow->SetConeL(0.15);
00133    arrow->SetConeR(0.06);
00134    setupAddElement(arrow, &oItemHolder );  
00135 
00136    m_arrows.push_back(arrow);
00137    arrow->setScale(vc->getEnergyScale()); 
00138    arrow->setScale(vc->getEnergyScale());
00139 
00140    context().voteMaxEtAndEnergy(met.et(), met.energy());
00141 
00142 }
00143 
00144 //
00145 // const member functions
00146 //
00147 
00148 //
00149 // static member functions
00150 //
00151 
00152 REGISTER_FWPROXYBUILDER(FWMET3DProxyBuilder, reco::MET, "recoMET", FWViewType::kAll3DBits);