Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:54

0001 // -*- C++ -*-
0002 //
0003 // Package:     Vertexs
0004 // Class  :     FWVertexProxyBuilder
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/CmsShowCommon.h"
0018 #include "Fireworks/Core/interface/Context.h"
0019 #include "Fireworks/Core/interface/FWParameters.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/Core/interface/fwLog.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 FWVertexProxyBuilder : public FWSimpleProxyBuilderTemplate<reco::Vertex> {
0042 public:
0043   FWVertexProxyBuilder() {}
0044   ~FWVertexProxyBuilder() 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       iItem->getConfig()->assertParam("Event Center Index", -1l, -1l, 500l);
0056     }
0057   }
0058 
0059   REGISTER_PROXYBUILDER_METHODS();
0060 
0061   FWVertexProxyBuilder(const FWVertexProxyBuilder&) = delete;                   // stop default
0062   const FWVertexProxyBuilder& operator=(const FWVertexProxyBuilder&) = delete;  // stop default
0063 
0064 private:
0065   using FWSimpleProxyBuilderTemplate<reco::Vertex>::build;
0066   void build(const reco::Vertex& iData, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext*) override;
0067 
0068   void localModelChanges(const FWModelId& iId,
0069                          TEveElement* iCompound,
0070                          FWViewType::EType viewType,
0071                          const FWViewContext* vc) override;
0072 };
0073 
0074 void FWVertexProxyBuilder::build(const reco::Vertex& iData,
0075                                  unsigned int iIndex,
0076                                  TEveElement& oItemHolder,
0077                                  const FWViewContext* vc) {
0078   const reco::Vertex& v = iData;
0079 
0080   // marker
0081   TEveGeoManagerHolder gmgr(TEveGeoShape::GetGeoMangeur());
0082   TEvePointSet* pointSet = new TEvePointSet();
0083   pointSet->SetNextPoint(v.x(), v.y(), v.z());
0084   setupAddElement(pointSet, &oItemHolder);
0085 
0086   // ellipse
0087   if (item()->getConfig()->value<bool>("Draw Ellipse")) {
0088     TEveEllipsoid* eveEllipsoid = new TEveEllipsoid("Ellipsoid", Form("Ellipsoid %d", iIndex));
0089 
0090     eveEllipsoid->RefPos().Set(v.x(), v.y(), v.z());
0091 
0092     reco::Vertex::Error e = v.error();
0093     TMatrixDSym m(3);
0094     for (int i = 0; i < 3; i++)
0095       for (int j = 0; j < 3; j++) {
0096         m(i, j) = e(i, j);
0097         eveEllipsoid->RefEMtx()(i + 1, j + 1) = e(i, j);
0098       }
0099 
0100     // external scaling
0101     double ellipseScale = 1.;
0102     if (item()->getConfig()->value<long>("Scale Ellipse"))
0103       ellipseScale = item()->getConfig()->value<long>("Scale Ellipse");
0104 
0105     eveEllipsoid->SetScale(ellipseScale);
0106 
0107     // cache 3D extend used in eval bbox and render 3D
0108     TMatrixDEigen eig(m);
0109     TVectorD vv(eig.GetEigenValuesRe());
0110     eveEllipsoid->RefExtent3D().Set(sqrt(vv(0)) * ellipseScale, sqrt(vv(1)) * ellipseScale, sqrt(vv(2)) * ellipseScale);
0111 
0112     eveEllipsoid->SetLineWidth(2);
0113     setupAddElement(eveEllipsoid, &oItemHolder);
0114     eveEllipsoid->SetMainTransparency(TMath::Min(100, 80 + item()->defaultDisplayProperties().transparency() / 5));
0115 
0116     Color_t color = item()->getConfig()->value<long>("Ellipse Color Index");
0117     // eveEllipsoid->SetFillColor(item()->defaultDisplayProperties().color());
0118     // eveEllipsoid->SetLineColor(item()->defaultDisplayProperties().color());
0119     eveEllipsoid->SetMainColor(color + context().colorManager()->offsetOfLimitedColors());
0120   }
0121 
0122   // tracks
0123   if (item()->getConfig()->value<bool>("Draw Tracks")) {
0124     for (reco::Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); ++it) {
0125       float w = v.trackWeight(*it);
0126       if (w < 0.5)
0127         continue;
0128 
0129       const reco::Track& track = *it->get();
0130       TEveRecTrack t;
0131       t.fBeta = 1.;
0132       t.fV = TEveVector(track.vx(), track.vy(), track.vz());
0133       t.fP = TEveVector(track.px(), track.py(), track.pz());
0134       t.fSign = track.charge();
0135       TEveTrack* trk = new TEveTrack(&t, context().getTrackPropagator());
0136       trk->SetMainColor(item()->defaultDisplayProperties().color());
0137       trk->MakeTrack();
0138       setupAddElement(trk, &oItemHolder);
0139     }
0140   }
0141   if (item()->getConfig()->value<bool>("Draw Pseudo Track")) {
0142     TEveRecTrack t;
0143     t.fBeta = 1.;
0144     t.fV = TEveVector(v.x(), v.y(), v.z());
0145     t.fP = TEveVector(-v.p4().px(), -v.p4().py(), -v.p4().pz());
0146     t.fSign = 1;
0147     TEveTrack* trk = new TEveTrack(&t, context().getTrackPropagator());
0148     trk->SetLineStyle(7);
0149     trk->MakeTrack();
0150     setupAddElement(trk, &oItemHolder);
0151   }
0152 
0153   fireworks::Context* context = fireworks::Context::getInstance();
0154   int cIdx = item()->getConfig()->value<long>("Event Center Index");
0155   if (cIdx == -1) {
0156     context->commonPrefs()->resetEventCenter();
0157   }
0158   if (cIdx >= 0 && int(iIndex) == int(cIdx)) {
0159     fwLog(fwlog::kInfo) << "FWVertexProxyBuilder set event center "
0160                         << Form("idx [%d], (%f %f %f) \n", cIdx, v.x(), v.y(), v.z());
0161     context->commonPrefs()->setEventCenter(v.x(), v.y(), v.z());
0162   }
0163 }
0164 
0165 void FWVertexProxyBuilder::localModelChanges(const FWModelId& iId,
0166                                              TEveElement* iCompound,
0167                                              FWViewType::EType viewType,
0168                                              const FWViewContext* vc) {
0169   increaseComponentTransparency(iId.index(), iCompound, "Ellipsoid", 80);
0170   TEveElement* el = iCompound->FindChild("Ellipsoid");
0171   if (el)
0172     el->SetMainColor(item()->getConfig()->value<long>("Ellipse Color Index") +
0173                      context().colorManager()->offsetOfLimitedColors());
0174 }
0175 
0176 //
0177 // static member functions
0178 //
0179 REGISTER_FWPROXYBUILDER(FWVertexProxyBuilder, reco::Vertex, "Vertices", FWViewType::k3DBit | FWViewType::kAllRPZBits);