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 "TEveGeoShape.h"
16 #include "TEveScalableStraightLineSet.h"
17 #include "TGeoTube.h"
18 #include "TMath.h"
19 
20 // user include files
28 
30 
32 //
33 // RPZ proxy builder with shared MET shape
34 //
36 
38 public:
40  ~FWMETProxyBuilder() override {}
41 
42  bool haveSingleProduct() const override { return false; } // use buildViewType instead of buildView
43 
44  bool havePerViewProduct(FWViewType::EType) const override { return true; } // used energy scaling
45 
46  void scaleProduct(TEveElementList* parent, FWViewType::EType, const FWViewContext* vc) override;
47 
49 
50  FWMETProxyBuilder(const FWMETProxyBuilder&) = delete; // stop default
51  const FWMETProxyBuilder& operator=(const FWMETProxyBuilder&) = delete; // stop default
52 
53 private:
55  void buildViewType(const reco::MET& iData,
56  unsigned int iIndex,
57  TEveElement& oItemHolder,
59  const FWViewContext*) override;
60 };
61 
62 void FWMETProxyBuilder::scaleProduct(TEveElementList* product, FWViewType::EType type, const FWViewContext* vc) {
63  int idx = 0;
64  for (auto& c : product->RefChildren()) {
65  // line set element is added at the end of the buildViewType function, therefore last child
66  TEveScalableStraightLineSet* lineSet = dynamic_cast<TEveScalableStraightLineSet*>(c->LastChild());
67  if (lineSet) {
68  // compund index in the product is an index of model data in the collection
69  const void* modelData = item()->modelData(idx);
70  const reco::MET* met = (const reco::MET*)(modelData);
71  float value = vc->getEnergyScale()->getPlotEt() ? met->et() : met->energy();
72  lineSet->SetScale(vc->getEnergyScale()->getScaleFactor3D() * value);
73  for (TEveProjectable::ProjList_i j = lineSet->BeginProjecteds(); j != lineSet->EndProjecteds(); ++j) {
74  (*j)->UpdateProjection();
75  }
76  }
77  idx++;
78  }
79 }
80 
82  unsigned int iIndex,
83  TEveElement& oItemHolder,
85  const FWViewContext* vc) {
86  using namespace TMath;
87  double phi = met.phi();
88  double theta = met.theta();
89  double size = 1.f;
90 
91  FWViewEnergyScale* caloScale = vc->getEnergyScale();
92 
93  TEveScalableStraightLineSet* marker = new TEveScalableStraightLineSet("MET marker");
94  marker->SetLineWidth(2);
95 
96  if (type == FWViewType::kRhoZ) {
97  // body
98  double r0;
99  if (TMath::Abs(met.eta()) < context().caloTransEta()) {
100  r0 = context().caloR1() / sin(theta);
101  } else {
102  r0 = context().caloZ1() / fabs(cos(theta));
103  }
104  marker->SetScaleCenter(0., Sign(r0 * sin(theta), phi), r0 * cos(theta));
105  double r1 = r0 + 1;
106  marker->AddLine(0., Sign(r0 * sin(theta), phi), r0 * cos(theta), 0., Sign(r1 * sin(theta), phi), r1 * cos(theta));
107 
108  // arrow pointer
109  double r2 = r1 - 0.1;
110  double dy = 0.05 * size;
111  marker->AddLine(0.,
112  Sign(r2 * sin(theta) + dy * cos(theta), phi),
113  r2 * cos(theta) - dy * sin(theta),
114  0.,
115  Sign(r1 * sin(theta), phi),
116  r1 * cos(theta));
117  dy = -dy;
118  marker->AddLine(0.,
119  Sign(r2 * sin(theta) + dy * cos(theta), phi),
120  r2 * cos(theta) - dy * sin(theta),
121  0.,
122  Sign(r1 * sin(theta), phi),
123  r1 * cos(theta));
124 
125  // segment
127  this, &oItemHolder, context().caloR1() - 1, context().caloZ1() - 1, theta - 0.04, theta + 0.04, phi);
128  } else {
129  // body
130  double r0 = context().caloR1();
131  double r1 = r0 + 1;
132  marker->SetScaleCenter(r0 * cos(phi), r0 * sin(phi), 0);
133  marker->AddLine(r0 * cos(phi), r0 * sin(phi), 0, r1 * cos(phi), r1 * sin(phi), 0);
134 
135  // arrow pointer, xy rotate offset point ..
136  double r2 = r1 - 0.1;
137  double dy = 0.05 * size;
138 
139  marker->AddLine(r2 * cos(phi) - dy * sin(phi), r2 * sin(phi) + dy * cos(phi), 0, r1 * cos(phi), r1 * sin(phi), 0);
140  dy = -dy;
141  marker->AddLine(r2 * cos(phi) - dy * sin(phi), r2 * sin(phi) + dy * cos(phi), 0, r1 * cos(phi), r1 * sin(phi), 0);
142 
143  // segment
144  double min_phi = phi - M_PI / 36 / 2;
145  double max_phi = phi + M_PI / 36 / 2;
146  TEveGeoManagerHolder gmgr(TEveGeoShape::GetGeoMangeur());
147  TEveGeoShape* element =
148  fireworks::getShape("spread", new TGeoTubeSeg(r0 - 2, r0, 1, min_phi * 180 / M_PI, max_phi * 180 / M_PI), 0);
149  element->SetPickable(kTRUE);
150  setupAddElement(element, &oItemHolder);
151  }
152 
153  marker->SetScale(caloScale->getScaleFactor3D() * (caloScale->getPlotEt() ? met.et() : met.energy()));
154  setupAddElement(marker, &oItemHolder);
155 
156  // printf("add line %s %f %f .... eta %f theta %f\n", item()->name().c_str(), met.et(), met.energy(), met.eta(), met.theta());
157 
158  context().voteMaxEtAndEnergy(met.et(), met.energy());
159 }
160 
static float caloTransEta()
Definition: Context.cc:194
size
Write out results.
const void * modelData(int iIndex) const
Definition: FWEventItem.cc:466
#define REGISTER_PROXYBUILDER_METHODS()
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
static const int kAllRPZBits
Definition: FWViewType.h:57
bool haveSingleProduct() const override
void setupAddElement(TEveElement *el, TEveElement *parent, bool set_color=true) const
bool havePerViewProduct(FWViewType::EType) const override
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const FWMETProxyBuilder & operator=(const FWMETProxyBuilder &)=delete
const fireworks::Context & context() const
bool getPlotEt() const
FWViewEnergyScale * getEnergyScale() const
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
Definition: MET.h:41
void voteMaxEtAndEnergy(float Et, float energy) const
Definition: Context.cc:169
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
static float caloR1(bool offset=true)
Definition: Context.cc:187
Definition: value.py:1
#define M_PI
float getScaleFactor3D() const
void addRhoZEnergyProjection(FWProxyBuilderBase *, TEveElement *, double r_ecal, double z_ecal, double theta_min, double theta_max, double phi)
Definition: BuilderUtils.cc:58
void scaleProduct(TEveElementList *parent, FWViewType::EType, const FWViewContext *vc) override
float caloZ1()
Definition: FWPFGeom.h:21
static float caloZ1(bool offset=true)
Definition: Context.cc:190
TEveGeoShape * getShape(const char *name, TGeoBBox *shape, Color_t color)
Definition: BuilderUtils.cc:44
Geom::Theta< T > theta() const
const FWEventItem * item() const