CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/Fireworks/Vertices/plugins/FWVertexProxyBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Vertexs
00004 // Class  :     FWVertexProxyBuilder
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Tue Dec  2 14:17:03 EST 2008
00011 // $Id: FWVertexProxyBuilder.cc,v 1.7 2011/08/16 01:16:06 amraktad Exp $
00012 //
00013 // user include files// user include files
00014 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
00015 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
00016 #include "Fireworks/Core/interface/FWEventItem.h"
00017 #include "Fireworks/Core/interface/FWParameters.h"
00018 #include "DataFormats/VertexReco/interface/Vertex.h"
00019 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00020 #include "TEvePointSet.h"
00021 
00022 #include "TMatrixDEigen.h"
00023 #include "TMatrixDSym.h"
00024 #include "TDecompSVD.h"
00025 #include "TVectorD.h"
00026 #include "TEveTrans.h"
00027 #include "TEveTrack.h"
00028 #include "TEveTrackPropagator.h"
00029 #include "TEveBoxSet.h"
00030 #include "TGeoSphere.h"
00031 #include "TEveGeoNode.h"
00032 #include "TEveVSDStructs.h"
00033 
00034 class FWVertexProxyBuilder : public FWSimpleProxyBuilderTemplate<reco::Vertex> 
00035 {
00036 public:
00037    FWVertexProxyBuilder() {}
00038    virtual ~FWVertexProxyBuilder() {}
00039 
00040    virtual void setItem(const FWEventItem* iItem)
00041    {
00042       FWProxyBuilderBase::setItem(iItem);
00043       iItem->getConfig()->assertParam("Draw Tracks", false);
00044    }
00045 
00046    REGISTER_PROXYBUILDER_METHODS();
00047 
00048 private:
00049    FWVertexProxyBuilder(const FWVertexProxyBuilder&); // stop default
00050    const FWVertexProxyBuilder& operator=(const FWVertexProxyBuilder&); // stop default
00051 
00052    virtual void build(const reco::Vertex& iData, unsigned int iIndex,TEveElement& oItemHolder, const FWViewContext*);
00053 };
00054 
00055 //
00056 // member functions
00057 //
00058 void
00059 FWVertexProxyBuilder::build(const reco::Vertex& iData, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext*) 
00060 {
00061    const reco::Vertex & v = iData;
00062 
00063    TEveGeoManagerHolder gmgr(TEveGeoShape::GetGeoMangeur());
00064    TEvePointSet* pointSet = new TEvePointSet();
00065    pointSet->SetMainColor(item()->defaultDisplayProperties().color());
00066    pointSet->SetNextPoint( v.x(), v.y(), v.z() );
00067    oItemHolder.AddElement( pointSet );
00068 
00069    if ( item()->getConfig()->value<bool>("Draw Tracks")) 
00070    {
00071       // do we need this stuff?
00072       TGeoSphere * sphere = new TGeoSphere(0, 0.002); //would that leak?
00073       TEveGeoShape * shape = new TEveGeoShape();
00074       sphere->SetBoxDimensions(2.5,2.5,2.5);
00075       shape->SetShape(sphere);
00076       shape->SetMainColor(item()->defaultDisplayProperties().color());
00077       shape->SetMainTransparency(10);
00078 
00079       TEveTrans & t =   shape->RefMainTrans();
00080       reco::Vertex::Error e= v.error();
00081       TMatrixDSym m(3);
00082       for(int i=0;i<3;i++)
00083          for(int j=0;j<3;j++)
00084          {
00085             m(i,j) = e(i,j);
00086          }
00087       TMatrixDEigen eig(m);
00088       TDecompSVD svd(m);
00089       TMatrixD mm = svd.GetU();
00090       //   TMatrixD mm =  eig.GetEigenVectors().Print();
00091       for(int i=0;i<3;i++)
00092          for(int j=0;j<3;j++)
00093          {
00094             t(i+1,j+1) = mm(i,j);
00095          }
00096 
00097       TVectorD vv ( eig.GetEigenValuesRe())   ;
00098       t.Scale(sqrt(vv(0))*1000.,sqrt(vv(1))*1000.,sqrt(vv(2))*1000.);
00099       t.SetPos(v.x(),v.y(),v.z());
00100       oItemHolder.AddElement(shape);
00101       for(reco::Vertex::trackRef_iterator it = v.tracks_begin() ;
00102           it != v.tracks_end()  ; ++it)
00103       {
00104          float w = v.trackWeight(*it);
00105          if (w < 0.5) continue;
00106 
00107          const reco::Track & track = *it->get();
00108          TEveRecTrack t;
00109          t.fBeta = 1.;
00110          t.fV = TEveVector(track.vx(), track.vy(), track.vz());
00111          t.fP = TEveVector(track.px(), track.py(), track.pz());
00112          t.fSign = track.charge();
00113          TEveTrack* trk = new TEveTrack(&t, context().getTrackPropagator());
00114          trk->SetMainColor(item()->defaultDisplayProperties().color());
00115          trk->MakeTrack();
00116          oItemHolder.AddElement( trk );
00117       }
00118    }
00119 }
00120 
00121 //
00122 // static member functions
00123 //
00124 REGISTER_FWPROXYBUILDER(FWVertexProxyBuilder, reco::Vertex, "Vertices", FWViewType::k3DBit | FWViewType::kAllRPZBits);