Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-03 04:10:05

0001 // -*- C++ -*-
0002 //
0003 // Package:     Vertexs
0004 // Class  :     FWVertexCandidateProxyBuilder
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Tue Dec  2 14:17:03 EST 2008
0011 //
0012 // user include files// user include files
0013 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
0014 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
0015 #include "Fireworks/Core/interface/FWColorManager.h"
0016 #include "Fireworks/Core/interface/FWEventItem.h"
0017 #include "Fireworks/Core/interface/Context.h"
0018 #include "Fireworks/Core/interface/FWParameters.h"
0019 #include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h"
0020 #include "DataFormats/VertexReco/interface/Vertex.h"
0021 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0022 
0023 #include "Fireworks/Vertices/interface/TEveEllipsoid.h"
0024 #include "Fireworks/Candidates/interface/CandidateUtils.h"
0025 
0026 #include "TEvePointSet.h"
0027 #include "TMatrixDEigen.h"
0028 #include "TMatrixDSym.h"
0029 #include "TDecompSVD.h"
0030 #include "TVectorD.h"
0031 #include "TEveTrans.h"
0032 #include "TEveTrack.h"
0033 #include "TEveTrackPropagator.h"
0034 #include "TEveStraightLineSet.h"
0035 #include "TEveBoxSet.h"
0036 #include "TGeoSphere.h"
0037 #include "TEveGeoNode.h"
0038 #include "TEveGeoShape.h"
0039 #include "TEveVSDStructs.h"
0040 
0041 class FWVertexCandidateProxyBuilder : public FWSimpleProxyBuilderTemplate<reco::VertexCompositePtrCandidate> {
0042 public:
0043   FWVertexCandidateProxyBuilder() {}
0044   ~FWVertexCandidateProxyBuilder() override {}
0045 
0046   void setItem(const FWEventItem* iItem) override {
0047     FWProxyBuilderBase::setItem(iItem);
0048     if (iItem) {
0049       iItem->getConfig()->assertParam("Draw Tracks", false);
0050       iItem->getConfig()->assertParam("Draw Pseudo Track", false);
0051       iItem->getConfig()->assertParam("Draw Ellipse", false);
0052       iItem->getConfig()->assertParam("Scale Ellipse", 2l, 1l, 10l);
0053       iItem->getConfig()->assertParam(
0054           "Ellipse Color Index", 6l, 0l, (long)context().colorManager()->numberOfLimitedColors());
0055     }
0056   }
0057 
0058   REGISTER_PROXYBUILDER_METHODS();
0059 
0060   FWVertexCandidateProxyBuilder(const FWVertexCandidateProxyBuilder&) = delete;                   // stop default
0061   const FWVertexCandidateProxyBuilder& operator=(const FWVertexCandidateProxyBuilder&) = delete;  // stop default
0062 
0063 private:
0064   using FWSimpleProxyBuilderTemplate<reco::VertexCompositePtrCandidate>::build;
0065   void build(const reco::VertexCompositePtrCandidate& iData,
0066              unsigned int iIndex,
0067              TEveElement& oItemHolder,
0068              const FWViewContext*) override;
0069 
0070   void localModelChanges(const FWModelId& iId,
0071                          TEveElement* iCompound,
0072                          FWViewType::EType viewType,
0073                          const FWViewContext* vc) override;
0074 };
0075 
0076 void FWVertexCandidateProxyBuilder::build(const reco::VertexCompositePtrCandidate& iData,
0077                                           unsigned int iIndex,
0078                                           TEveElement& oItemHolder,
0079                                           const FWViewContext*) {
0080   const reco::VertexCompositePtrCandidate& v = iData;
0081 
0082   // marker
0083   TEveGeoManagerHolder gmgr(TEveGeoShape::GetGeoMangeur());
0084   TEvePointSet* pointSet = new TEvePointSet();
0085   pointSet->SetNextPoint(v.vx(), v.vy(), v.vz());
0086   setupAddElement(pointSet, &oItemHolder);
0087 
0088   // ellipse
0089   if (item()->getConfig()->value<bool>("Draw Ellipse")) {
0090     TEveEllipsoid* eveEllipsoid = new TEveEllipsoid("Ellipsoid", Form("Ellipsoid %d", iIndex));
0091 
0092     eveEllipsoid->RefPos().Set(v.vx(), v.vy(), v.vz());
0093 
0094     reco::Vertex::Error e = v.error();
0095     TMatrixDSym m(3);
0096     for (int i = 0; i < 3; i++)
0097       for (int j = 0; j < 3; j++) {
0098         m(i, j) = e(i, j);
0099         eveEllipsoid->RefEMtx()(i + 1, j + 1) = e(i, j);
0100       }
0101 
0102     // external scaling
0103     double ellipseScale = 1.;
0104     if (item()->getConfig()->value<long>("Scale Ellipse"))
0105       ellipseScale = item()->getConfig()->value<long>("Scale Ellipse");
0106 
0107     eveEllipsoid->SetScale(ellipseScale);
0108 
0109     // cache 3D extend used in eval bbox and render 3D
0110     TMatrixDEigen eig(m);
0111     TVectorD vv(eig.GetEigenValuesRe());
0112     eveEllipsoid->RefExtent3D().Set(sqrt(vv(0)) * ellipseScale, sqrt(vv(1)) * ellipseScale, sqrt(vv(2)) * ellipseScale);
0113 
0114     eveEllipsoid->SetLineWidth(2);
0115     setupAddElement(eveEllipsoid, &oItemHolder);
0116     eveEllipsoid->SetMainTransparency(TMath::Min(100, 80 + item()->defaultDisplayProperties().transparency() / 5));
0117 
0118     Color_t color = item()->getConfig()->value<long>("Ellipse Color Index");
0119     // eveEllipsoid->SetFillColor(item()->defaultDisplayProperties().color());
0120     // eveEllipsoid->SetLineColor(item()->defaultDisplayProperties().color());
0121     eveEllipsoid->SetMainColor(color + context().colorManager()->offsetOfLimitedColors());
0122   }
0123 
0124   // tracks
0125   if (item()->getConfig()->value<bool>("Draw Tracks")) {
0126     for (unsigned int j = 0; j < v.numberOfDaughters(); j++) {
0127       const reco::Candidate* c = v.daughter(j);
0128       std::cout << c << std::endl;
0129       TEveTrack* trk = fireworks::prepareCandidate(*c, context().getTrackPropagator());
0130 
0131       trk->SetMainColor(item()->defaultDisplayProperties().color());
0132       trk->MakeTrack();
0133       setupAddElement(trk, &oItemHolder);
0134     }
0135   }
0136   if (item()->getConfig()->value<bool>("Draw Pseudo Track")) {
0137     TEveRecTrack t;
0138     t.fBeta = 1.;
0139     t.fV = TEveVector(v.vx(), v.vy(), v.vz());
0140     t.fP = TEveVector(-v.p4().px(), -v.p4().py(), -v.p4().pz());
0141     t.fSign = 1;
0142     TEveTrack* trk = new TEveTrack(&t, context().getTrackPropagator());
0143     trk->SetLineStyle(7);
0144     trk->MakeTrack();
0145     setupAddElement(trk, &oItemHolder);
0146   }
0147 }
0148 
0149 void FWVertexCandidateProxyBuilder::localModelChanges(const FWModelId& iId,
0150                                                       TEveElement* iCompound,
0151                                                       FWViewType::EType viewType,
0152                                                       const FWViewContext* vc) {
0153   increaseComponentTransparency(iId.index(), iCompound, "Ellipsoid", 80);
0154   TEveElement* el = iCompound->FindChild("Ellipsoid");
0155   if (el)
0156     el->SetMainColor(item()->getConfig()->value<long>("Ellipse Color Index") +
0157                      context().colorManager()->offsetOfLimitedColors());
0158 }
0159 
0160 //
0161 // static member functions
0162 //
0163 REGISTER_FWPROXYBUILDER(FWVertexCandidateProxyBuilder,
0164                         reco::VertexCompositePtrCandidate,
0165                         "CandVertices",
0166                         FWViewType::k3DBit | FWViewType::kAllRPZBits);