CMS 3D CMS Logo

FWMETProxyBuilder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Calo
4 // Class : FWMETProxyBuilder
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author:
10 // Created: Sun Jan 6 23:57:00 EST 2008
11 //
12 
13 // system include files
14 #include "TEveGeoNode.h"
15 #include "TEveScalableStraightLineSet.h"
16 #include "TGeoTube.h"
17 #include "TMath.h"
18 
19 // user include files
27 
29 
31 //
32 // RPZ proxy builder with shared MET shape
33 //
35 
37 public:
39  ~FWMETProxyBuilder() override {}
40 
41  bool haveSingleProduct() const override { return false; } // use buildViewType instead of buildView
42 
43  bool havePerViewProduct(FWViewType::EType) const override { return true; } // used energy scaling
44 
45  void scaleProduct(TEveElementList* parent, FWViewType::EType, const FWViewContext* vc) override;
46 
47  void cleanLocal() override { m_lines.clear(); }
48 
50 
51 private:
52  FWMETProxyBuilder(const FWMETProxyBuilder&) = delete; // stop default
53  const FWMETProxyBuilder& operator=(const FWMETProxyBuilder&) = delete; // stop default
54 
56  void buildViewType(const reco::MET& iData,
57  unsigned int iIndex,
58  TEveElement& oItemHolder,
60  const FWViewContext*) override;
61 
62  std::vector<fireworks::scaleMarker> m_lines;
63 };
64 
66  typedef std::vector<fireworks::scaleMarker> Lines_t;
67  FWViewEnergyScale* caloScale = vc->getEnergyScale();
68 
69  // printf("MET %s %p -> %f\n", item()->name().c_str(), vc, caloScale->getScaleFactor3D() );
70  for (Lines_t::iterator i = m_lines.begin(); i != m_lines.end(); ++i) {
71  if (vc == (*i).m_vc) {
72  // printf("lineset %s %p val %f ...%f\n", item()->name().c_str(), (*i).m_ls , (*i).m_et, caloScale->getScaleFactor3D()*(*i).m_et);
73  float value = caloScale->getPlotEt() ? (*i).m_et : (*i).m_energy;
74 
75  (*i).m_ls->SetScale(caloScale->getScaleFactor3D() * value);
76 
77  TEveProjectable* pable = static_cast<TEveProjectable*>((*i).m_ls);
78  for (TEveProjectable::ProjList_i j = pable->BeginProjecteds(); j != pable->EndProjecteds(); ++j) {
79  (*j)->UpdateProjection();
80  }
81  }
82  }
83 }
84 
86  unsigned int iIndex,
87  TEveElement& oItemHolder,
89  const FWViewContext* vc) {
90  using namespace TMath;
91  double phi = met.phi();
92  double theta = met.theta();
93  double size = 1.f;
94 
95  FWViewEnergyScale* caloScale = vc->getEnergyScale();
96 
97  TEveScalableStraightLineSet* marker = new TEveScalableStraightLineSet("MET marker");
98  marker->SetLineWidth(2);
99 
100  if (type == FWViewType::kRhoZ) {
101  // body
102  double r0;
103  if (TMath::Abs(met.eta()) < context().caloTransEta()) {
104  r0 = context().caloR1() / sin(theta);
105  } else {
106  r0 = context().caloZ1() / fabs(cos(theta));
107  }
108  marker->SetScaleCenter(0., Sign(r0 * sin(theta), phi), r0 * cos(theta));
109  double r1 = r0 + 1;
110  marker->AddLine(0., Sign(r0 * sin(theta), phi), r0 * cos(theta), 0., Sign(r1 * sin(theta), phi), r1 * cos(theta));
111 
112  // arrow pointer
113  double r2 = r1 - 0.1;
114  double dy = 0.05 * size;
115  marker->AddLine(0.,
116  Sign(r2 * sin(theta) + dy * cos(theta), phi),
117  r2 * cos(theta) - dy * sin(theta),
118  0.,
119  Sign(r1 * sin(theta), phi),
120  r1 * cos(theta));
121  dy = -dy;
122  marker->AddLine(0.,
123  Sign(r2 * sin(theta) + dy * cos(theta), phi),
124  r2 * cos(theta) - dy * sin(theta),
125  0.,
126  Sign(r1 * sin(theta), phi),
127  r1 * cos(theta));
128 
129  // segment
131  this, &oItemHolder, context().caloR1() - 1, context().caloZ1() - 1, theta - 0.04, theta + 0.04, phi);
132  } else {
133  // body
134  double r0 = context().caloR1();
135  double r1 = r0 + 1;
136  marker->SetScaleCenter(r0 * cos(phi), r0 * sin(phi), 0);
137  marker->AddLine(r0 * cos(phi), r0 * sin(phi), 0, r1 * cos(phi), r1 * sin(phi), 0);
138 
139  // arrow pointer, xy rotate offset point ..
140  double r2 = r1 - 0.1;
141  double dy = 0.05 * size;
142 
143  marker->AddLine(r2 * cos(phi) - dy * sin(phi), r2 * sin(phi) + dy * cos(phi), 0, r1 * cos(phi), r1 * sin(phi), 0);
144  dy = -dy;
145  marker->AddLine(r2 * cos(phi) - dy * sin(phi), r2 * sin(phi) + dy * cos(phi), 0, r1 * cos(phi), r1 * sin(phi), 0);
146 
147  // segment
148  double min_phi = phi - M_PI / 36 / 2;
149  double max_phi = phi + M_PI / 36 / 2;
150  TEveGeoManagerHolder gmgr(TEveGeoShape::GetGeoMangeur());
151  TEveGeoShape* element =
152  fireworks::getShape("spread", new TGeoTubeSeg(r0 - 2, r0, 1, min_phi * 180 / M_PI, max_phi * 180 / M_PI), 0);
153  element->SetPickable(kTRUE);
154  setupAddElement(element, &oItemHolder);
155  }
156 
157  marker->SetScale(caloScale->getScaleFactor3D() * (caloScale->getPlotEt() ? met.et() : met.energy()));
158  setupAddElement(marker, &oItemHolder);
159 
160  // printf("add line %s %f %f .... eta %f theta %f\n", item()->name().c_str(), met.et(), met.energy(), met.eta(), met.theta());
161  m_lines.push_back(fireworks::scaleMarker(marker, met.et(), met.energy(), vc)); // register for scales
162 
163  context().voteMaxEtAndEnergy(met.et(), met.energy());
164 }
165 
static float caloTransEta()
Definition: Context.cc:187
size
Write out results.
type
Definition: HCALResponse.h:21
const fireworks::Context & context() const
float getScaleFactor3D() const
std::vector< fireworks::scaleMarker > m_lines
double eta() const final
momentum pseudorapidity
static const int kAllRPZBits
Definition: FWViewType.h:67
double theta() const final
momentum polar angle
T Sign(T A, T B)
Definition: MathUtil.h:54
void voteMaxEtAndEnergy(float Et, float energy) const
Definition: Context.cc:162
void setupAddElement(TEveElement *el, TEveElement *parent, bool set_color=true) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
FWViewEnergyScale * getEnergyScale() const
Geom::Theta< T > theta() const
const FWMETProxyBuilder & operator=(const FWMETProxyBuilder &)=delete
float caloR1()
Definition: FWPFGeom.h:20
~FWMETProxyBuilder() override
void buildViewType(const reco::MET &iData, unsigned int iIndex, TEveElement &oItemHolder, FWViewType::EType type, const FWViewContext *) override
double et() const final
transverse energy
Definition: MET.h:41
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
T Abs(T a)
Definition: MathUtil.h:49
double energy() const final
energy
static float caloR1(bool offset=true)
Definition: Context.cc:180
Definition: value.py:1
void cleanLocal() override
#define M_PI
bool havePerViewProduct(FWViewType::EType) const override
void addRhoZEnergyProjection(FWProxyBuilderBase *, TEveElement *, double r_ecal, double z_ecal, double theta_min, double theta_max, double phi)
Definition: BuilderUtils.cc:57
void scaleProduct(TEveElementList *parent, FWViewType::EType, const FWViewContext *vc) override
float caloZ1()
Definition: FWPFGeom.h:21
#define REGISTER_PROXYBUILDER_METHODS()
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
static float caloZ1(bool offset=true)
Definition: Context.cc:183
TEveGeoShape * getShape(const char *name, TGeoBBox *shape, Color_t color)
Definition: BuilderUtils.cc:43
double phi() const final
momentum azimuthal angle
bool getPlotEt() const
bool haveSingleProduct() const override