CMS 3D CMS Logo

FWVertexCandidateProxyBuilder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Vertexs
4 // Class : FWVertexCandidateProxyBuilder
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 // user include files// user include files
22 
25 
26 #include "TEvePointSet.h"
27 #include "TMatrixDEigen.h"
28 #include "TMatrixDSym.h"
29 #include "TDecompSVD.h"
30 #include "TVectorD.h"
31 #include "TEveTrans.h"
32 #include "TEveTrack.h"
33 #include "TEveTrackPropagator.h"
34 #include "TEveStraightLineSet.h"
35 #include "TEveBoxSet.h"
36 #include "TGeoSphere.h"
37 #include "TEveGeoNode.h"
38 #include "TEveGeoShape.h"
39 #include "TEveVSDStructs.h"
40 
41 class FWVertexCandidateProxyBuilder : public FWSimpleProxyBuilderTemplate<reco::VertexCompositePtrCandidate> {
42 public:
45 
46  void setItem(const FWEventItem* iItem) override {
48  if (iItem) {
49  iItem->getConfig()->assertParam("Draw Tracks", false);
50  iItem->getConfig()->assertParam("Draw Pseudo Track", false);
51  iItem->getConfig()->assertParam("Draw Ellipse", false);
52  iItem->getConfig()->assertParam("Scale Ellipse", 2l, 1l, 10l);
53  iItem->getConfig()->assertParam(
54  "Ellipse Color Index", 6l, 0l, (long)context().colorManager()->numberOfLimitedColors());
55  }
56  }
57 
59 
60  FWVertexCandidateProxyBuilder(const FWVertexCandidateProxyBuilder&) = delete; // stop default
61  const FWVertexCandidateProxyBuilder& operator=(const FWVertexCandidateProxyBuilder&) = delete; // stop default
62 
63 private:
65  void build(const reco::VertexCompositePtrCandidate& iData,
66  unsigned int iIndex,
67  TEveElement& oItemHolder,
68  const FWViewContext*) override;
69 
70  void localModelChanges(const FWModelId& iId,
71  TEveElement* iCompound,
72  FWViewType::EType viewType,
73  const FWViewContext* vc) override;
74 };
75 
77  unsigned int iIndex,
78  TEveElement& oItemHolder,
79  const FWViewContext*) {
80  const reco::VertexCompositePtrCandidate& v = iData;
81 
82  // marker
83  TEveGeoManagerHolder gmgr(TEveGeoShape::GetGeoMangeur());
84  TEvePointSet* pointSet = new TEvePointSet();
85  pointSet->SetNextPoint(v.vx(), v.vy(), v.vz());
86  setupAddElement(pointSet, &oItemHolder);
87 
88  // ellipse
89  if (item()->getConfig()->value<bool>("Draw Ellipse")) {
90  TEveEllipsoid* eveEllipsoid = new TEveEllipsoid("Ellipsoid", Form("Ellipsoid %d", iIndex));
91 
92  eveEllipsoid->RefPos().Set(v.vx(), v.vy(), v.vz());
93 
94  reco::Vertex::Error e = v.error();
95  TMatrixDSym m(3);
96  for (int i = 0; i < 3; i++)
97  for (int j = 0; j < 3; j++) {
98  m(i, j) = e(i, j);
99  eveEllipsoid->RefEMtx()(i + 1, j + 1) = e(i, j);
100  }
101 
102  // external scaling
103  double ellipseScale = 1.;
104  if (item()->getConfig()->value<long>("Scale Ellipse"))
105  ellipseScale = item()->getConfig()->value<long>("Scale Ellipse");
106 
107  eveEllipsoid->SetScale(ellipseScale);
108 
109  // cache 3D extend used in eval bbox and render 3D
110  TMatrixDEigen eig(m);
111  TVectorD vv(eig.GetEigenValuesRe());
112  eveEllipsoid->RefExtent3D().Set(sqrt(vv(0)) * ellipseScale, sqrt(vv(1)) * ellipseScale, sqrt(vv(2)) * ellipseScale);
113 
114  eveEllipsoid->SetLineWidth(2);
115  setupAddElement(eveEllipsoid, &oItemHolder);
116  eveEllipsoid->SetMainTransparency(TMath::Min(100, 80 + item()->defaultDisplayProperties().transparency() / 5));
117 
118  Color_t color = item()->getConfig()->value<long>("Ellipse Color Index");
119  // eveEllipsoid->SetFillColor(item()->defaultDisplayProperties().color());
120  // eveEllipsoid->SetLineColor(item()->defaultDisplayProperties().color());
121  eveEllipsoid->SetMainColor(color + context().colorManager()->offsetOfLimitedColors());
122  }
123 
124  // tracks
125  if (item()->getConfig()->value<bool>("Draw Tracks")) {
126  for (unsigned int j = 0; j < v.numberOfDaughters(); j++) {
127  const reco::Candidate* c = v.daughter(j);
128  std::cout << c << std::endl;
129  TEveTrack* trk = fireworks::prepareCandidate(*c, context().getTrackPropagator());
130 
131  trk->SetMainColor(item()->defaultDisplayProperties().color());
132  trk->MakeTrack();
133  setupAddElement(trk, &oItemHolder);
134  }
135  }
136  if (item()->getConfig()->value<bool>("Draw Pseudo Track")) {
137  TEveRecTrack t;
138  t.fBeta = 1.;
139  t.fV = TEveVector(v.vx(), v.vy(), v.vz());
140  t.fP = TEveVector(-v.p4().px(), -v.p4().py(), -v.p4().pz());
141  t.fSign = 1;
142  TEveTrack* trk = new TEveTrack(&t, context().getTrackPropagator());
143  trk->SetLineStyle(7);
144  trk->MakeTrack();
145  setupAddElement(trk, &oItemHolder);
146  }
147 }
148 
150  TEveElement* iCompound,
151  FWViewType::EType viewType,
152  const FWViewContext* vc) {
153  increaseComponentTransparency(iId.index(), iCompound, "Ellipsoid", 80);
154  TEveElement* el = iCompound->FindChild("Ellipsoid");
155  if (el)
156  el->SetMainColor(item()->getConfig()->value<long>("Ellipse Color Index") +
157  context().colorManager()->offsetOfLimitedColors());
158 }
159 
160 //
161 // static member functions
162 //
165  "CandVertices",
TEveVector & RefPos()
Definition: TEveEllipsoid.h:36
#define REGISTER_PROXYBUILDER_METHODS()
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
static const int kAllRPZBits
Definition: FWViewType.h:67
void setupAddElement(TEveElement *el, TEveElement *parent, bool set_color=true) const
FWProxyBuilderConfiguration * getConfig() const
Definition: FWEventItem.h:150
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
int index() const
Definition: FWModelId.h:41
const fireworks::Context & context() const
void SetScale(float x)
Definition: TEveEllipsoid.h:40
void setItem(const FWEventItem *iItem) override
T sqrt(T t)
Definition: SSEVec.h:19
virtual void setItem(const FWEventItem *iItem)
TEveTrans & RefEMtx()
Definition: TEveEllipsoid.h:38
FWGenericParameter< T > * assertParam(const std::string &name, T def)
TEveVector & RefExtent3D()
Definition: TEveEllipsoid.h:37
const FWVertexCandidateProxyBuilder & operator=(const FWVertexCandidateProxyBuilder &)=delete
TEveTrack * prepareCandidate(const reco::Candidate &track, TEveTrackPropagator *propagator)
void localModelChanges(const FWModelId &iId, TEveElement *iCompound, FWViewType::EType viewType, const FWViewContext *vc) override
const FWEventItem * item() const
void increaseComponentTransparency(unsigned int index, TEveElement *holder, const std::string &name, Char_t transpOffset)