CMS 3D CMS Logo

FWJetProxyBuilder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Calo
4 // Class : FWJetProxyBuilder
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Tue Dec 2 14:17:03 EST 2008
11 //
12 
13 #include "TEveJetCone.h"
14 #include "TEveScalableStraightLineSet.h"
15 
21 // user include files
29 
31 
32 namespace fireworks {
33 
34  struct jetScaleMarker : public scaleMarker {
35  jetScaleMarker(TEveScalableStraightLineSet* ls, float et, float e, const FWViewContext* vc)
36  : scaleMarker(ls, et, e, vc), m_text(nullptr) {}
37 
39  };
40 } // namespace fireworks
41 
42 static const std::string kJetLabelsRhoPhiOn("Draw Labels in RhoPhi View");
43 static const std::string kJetLabelsRhoZOn("Draw Labels in RhoZ View");
44 static const std::string kJetOffset("Label Offset");
45 static const std::string kJetApexBeamSpot("Place Apex In BeamSpot");
46 
48 public:
50  ~FWJetProxyBuilder() override;
51 
52  bool havePerViewProduct(FWViewType::EType) const override { return true; }
53  bool haveSingleProduct() const override { return false; } // different view types
54  void cleanLocal() override;
55 
56  void setItem(const FWEventItem* iItem) override {
58  if (iItem) {
59  iItem->getConfig()->assertParam(kJetLabelsRhoPhiOn, false);
60  iItem->getConfig()->assertParam(kJetLabelsRhoZOn, false);
61  iItem->getConfig()->assertParam(kJetOffset, 2.1, 1.0, 5.0);
62  }
63  }
64 
66 
67 protected:
69  void buildViewType(const reco::Jet& iData,
70  unsigned int iIndex,
71  TEveElement& oItemHolder,
73  const FWViewContext*) override;
74 
75  void localModelChanges(const FWModelId& iId,
76  TEveElement* iCompound,
77  FWViewType::EType viewType,
78  const FWViewContext* vc) override;
79 
80  void scaleProduct(TEveElementList* parent, FWViewType::EType, const FWViewContext* vc) override;
81 
82 private:
83  typedef std::vector<fireworks::jetScaleMarker> Lines_t;
84 
85  FWJetProxyBuilder(const FWJetProxyBuilder&) = delete; // stop default
86  const FWJetProxyBuilder& operator=(const FWJetProxyBuilder&) = delete; // stop default
87 
88  TEveElementList* requestCommon();
89  void setTextPos(fireworks::jetScaleMarker& s, const FWViewContext* vc, FWViewType::EType);
90 
91  TEveElementList* m_common;
92 };
93 
94 //______________________________________________________________________________
96  m_common = new TEveElementList("common electron scene");
97  m_common->IncDenyDestroy();
98 }
99 
101 
103  if (m_common->HasChildren() == false) {
104  for (int i = 0; i < static_cast<int>(item()->size()); ++i) {
105  TEveJetCone* cone = fireworks::makeEveJetCone(modelData(i), context());
106 
107  cone->SetFillColor(item()->defaultDisplayProperties().color());
108  cone->SetLineColor(item()->defaultDisplayProperties().color());
109 
110  m_common->AddElement(cone);
111  }
112  }
113  return m_common;
114 }
115 
117  unsigned int iIndex,
118  TEveElement& oItemHolder,
120  const FWViewContext* vc) {
121  // add cone from shared pool
122  TEveElementList* cones = requestCommon();
123  TEveElement::List_i coneIt = cones->BeginChildren();
124  std::advance(coneIt, iIndex);
125 
127  setupAddElement(*coneIt, &oItemHolder);
128  (*coneIt)->SetMainTransparency(TMath::Min(100, 80 + dp.transparency() / 5));
129 
130  TEveVector p1;
131  TEveVector p2;
132 
133  // scale markers in projected views
134  if (FWViewType::isProjected(type)) {
135  fireworks::jetScaleMarker markers(new TEveScalableStraightLineSet("jetline"), iData.et(), iData.energy(), vc);
136 
137 
138  float size = 1.f; // values are saved in scale
139  double theta = iData.theta();
140  double phi = iData.phi();
141 
142  if (type == FWViewType::kRhoZ) {
143  static const float_t offr = 4;
144  float r_ecal = context().caloR1() + offr;
145  float z_ecal = context().caloZ1() + offr / tan(context().caloTransAngle());
146  double r(0);
147  if (theta < context().caloTransAngle() || M_PI - theta < context().caloTransAngle()) {
148  z_ecal = context().caloZ2() + offr / tan(context().caloTransAngle());
149  r = z_ecal / fabs(cos(theta));
150  } else {
151  r = r_ecal / sin(theta);
152  }
153 
154  p1.Set(0., (phi > 0 ? r * fabs(sin(theta)) : -r * fabs(sin(theta))), r * cos(theta));
155  p2.Set(0., (phi > 0 ? (r + size) * fabs(sin(theta)) : -(r + size) * fabs(sin(theta))), (r + size) * cos(theta));
156  } else {
157  float ecalR = context().caloR1() + 4;
158  p1.Set(ecalR * cos(phi), ecalR * sin(phi), 0);
159  p2.Set((ecalR + size) * cos(phi), (ecalR + size) * sin(phi), 0);
160  }
161 
162  markers.m_ls->SetScaleCenter(p1.fX, p1.fY, p1.fZ);
163  markers.m_ls->AddLine(p1, p2);
164 
165  markers.m_ls->SetLineWidth(4);
166  markers.m_ls->SetLineColor(dp.color());
167  FWViewEnergyScale* caloScale = vc->getEnergyScale();
168  markers.m_ls->SetScale(caloScale->getScaleFactor3D() * (caloScale->getPlotEt() ? iData.et() : iData.energy()));
169 
170  if ((type == FWViewType::kRhoZ && item()->getConfig()->value<bool>(kJetLabelsRhoZOn)) ||
171  (type == FWViewType::kRhoPhi && item()->getConfig()->value<bool>(kJetLabelsRhoPhiOn))) {
172  markers.m_text = new FWEveText(Form("%.1f", vc->getEnergyScale()->getPlotEt() ? iData.et() : iData.energy()));
173  markers.m_text->SetMainColor(item()->defaultDisplayProperties().color());
174  setTextPos(markers, vc, type);
175  }
176 
177  markers.m_ls->SetMarkerColor(markers.m_ls->GetMainColor());
178  setupAddElement(markers.m_ls, &oItemHolder);
179  if (markers.m_text)
180  setupAddElement(markers.m_text, &oItemHolder, false);
181  }
182  context().voteMaxEtAndEnergy(iData.et(), iData.energy());
183 }
184 
186  TEveElement* iCompound,
187  FWViewType::EType viewType,
188  const FWViewContext* vc) {
189  increaseComponentTransparency(iId.index(), iCompound, "TEveJetCone", 80);
190 }
191 
193  m_common->DestroyElements();
194 }
195 
196 void FWJetProxyBuilder::scaleProduct(TEveElementList* product, FWViewType::EType viewType, const FWViewContext* vc) {
197  // move jets to eventCenter
199  TEveVector cv;
200  contextGl->commonPrefs()->getEventCenter(cv.Arr());
201  for (TEveElement::List_i i = m_common->BeginChildren(); i != m_common->EndChildren(); ++i) {
202  TEveJetCone* cone = dynamic_cast<TEveJetCone*>(*i);
203  if (cone) {
204  cone->SetApex(cv);
205  }
206  }
207 
208  // loop compounds in projected product
209  int idx = 0;
210  for (auto& c : product->RefChildren()) {
211  TEveElement* parent = c;
212  // check the compound has more than one element (the first one is jet)
213  if (parent->NumChildren() > 1) {
214  auto compIt = parent->BeginChildren();
215  compIt++;
216  TEveScalableStraightLineSet* lineSet = dynamic_cast<TEveScalableStraightLineSet*>(*compIt);
217  if (lineSet) {
218  // compund index in the product is an index of model data in the collection
219  const void* modelData = item()->modelData(idx);
220  const reco::Jet* jet = (const reco::Jet*)(modelData);
221  float value = vc->getEnergyScale()->getPlotEt() ? jet->et() : jet->energy();
222  lineSet->SetScale(vc->getEnergyScale()->getScaleFactor3D() * value);
223  for (TEveProjectable::ProjList_i j = lineSet->BeginProjecteds(); j != lineSet->EndProjecteds(); ++j) {
224  (*j)->UpdateProjection();
225  }
226  }
227  }
228  idx++;
229  }
230 }
231 
233  TEveChunkManager::iterator li(s.m_ls->GetLinePlex());
234  li.next();
235  TEveStraightLineSet::Line_t& l = *(TEveStraightLineSet::Line_t*)li();
236  TEveVector v(l.fV2[0] - l.fV1[0], l.fV2[1] - l.fV1[1], l.fV2[2] - l.fV1[2]);
237  v.Normalize();
238 
239  double off = item()->getConfig()->value<double>(kJetOffset) - 1;
240  float value = vc->getEnergyScale()->getPlotEt() ? s.m_et : s.m_energy;
241  double trs = off * 130 * value / context().getMaxEnergyInEvent(vc->getEnergyScale()->getPlotEt());
242  v *= trs;
243 
244  float x = l.fV1[0] + v[0];
245  float y = l.fV1[1] + v[1];
246  float z = l.fV1[2] + v[2];
247 
249  s.m_text->RefMainTrans().SetPos(x, y, z);
250  if ((s.m_text)->BeginProjecteds() != (s.m_text)->EndProjecteds()) {
251  FWEveTextProjected* textProjected = (FWEveTextProjected*)(*(s.m_text)->BeginProjecteds());
252  textProjected->UpdateProjection();
253  }
254 }
255 
257  reco::Jet,
258  "Jets",
size
Write out results.
type
Definition: HCALResponse.h:21
bool haveSingleProduct() const override
const fireworks::Context & context() const
void scaleProduct(TEveElementList *parent, FWViewType::EType, const FWViewContext *vc) override
FWProxyBuilderConfiguration * getConfig() const
Definition: FWEventItem.h:169
float getScaleFactor3D() const
static const std::string kJetApexBeamSpot("Place Apex In BeamSpot")
void UpdateProjection() override
const FWDisplayProperties & defaultDisplayProperties() const
Definition: FWEventItem.cc:453
#define REGISTER_PROXYBUILDER_METHODS()
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
float m_offsetZ
static const std::string kJetLabelsRhoPhiOn("Draw Labels in RhoPhi View")
static const int kAllRPZBits
Definition: FWViewType.h:58
double theta() const final
momentum polar angle
Base class for all types of Jets.
Definition: Jet.h:20
void voteMaxEtAndEnergy(float Et, float energy) const
Definition: Context.cc:183
void setupAddElement(TEveElement *el, TEveElement *parent, bool set_color=true) const
jetScaleMarker(TEveScalableStraightLineSet *ls, float et, float e, const FWViewContext *vc)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
FWViewEnergyScale * getEnergyScale() const
Geom::Theta< T > theta() const
void getEventCenter(float *inC) const
static float caloZ2(bool offset=true)
Definition: Context.cc:223
cv
Definition: cuy.py:362
std::vector< fireworks::jetScaleMarker > Lines_t
static const std::string kJetOffset("Label Offset")
T Min(T a, T b)
Definition: MathUtil.h:39
#define nullptr
const FWEventItem * item() const
static const int kAll3DBits
Definition: FWViewType.h:59
Color_t color() const
static bool isProjected(int)
Definition: FWViewType.cc:128
Char_t transparency() const
int index() const
Definition: FWModelId.h:49
double et() const final
transverse energy
virtual void setItem(const FWEventItem *iItem)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void setItem(const FWEventItem *iItem) override
double energy() const final
energy
static float caloR1(bool offset=true)
Definition: Context.cc:208
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
static const std::string kJetLabelsRhoZOn("Draw Labels in RhoZ View")
float getMaxEnergyInEvent(bool isEt) const
Definition: Context.cc:199
Definition: value.py:1
double p2[4]
Definition: TauolaWrapper.h:90
static Context * getInstance()
Definition: Context.cc:243
#define M_PI
TEveElementList * m_common
FWGenericParameter< T > * assertParam(const std::string &name, T def)
def ls(path, rec=False)
Definition: eostools.py:348
size_t size() const
Definition: FWEventItem.cc:550
auto dp
Definition: deltaR.h:22
CmsShowCommon * commonPrefs() const
Definition: Context.cc:177
et
define resolution functions of each parameter
TEveScalableStraightLineSet * m_ls
Definition: scaleMarker.h:37
void buildViewType(const reco::Jet &iData, unsigned int iIndex, TEveElement &oItemHolder, FWViewType::EType type, const FWViewContext *) override
double p1[4]
Definition: TauolaWrapper.h:89
bool havePerViewProduct(FWViewType::EType) const override
static float caloZ1(bool offset=true)
Definition: Context.cc:218
void cleanLocal() override
TEveElementList * requestCommon()
const void * modelData(int iIndex) const
Definition: FWEventItem.cc:569
~FWJetProxyBuilder() override
double phi() const final
momentum azimuthal angle
void localModelChanges(const FWModelId &iId, TEveElement *iCompound, FWViewType::EType viewType, const FWViewContext *vc) override
void setTextPos(fireworks::jetScaleMarker &s, const FWViewContext *vc, FWViewType::EType)
void increaseComponentTransparency(unsigned int index, TEveElement *holder, const std::string &name, Char_t transpOffset)
TEveJetCone * makeEveJetCone(const reco::Jet &iData, const fireworks::Context &context)
bool getPlotEt() const