CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Fireworks/Tracks/plugins/FWBeamSpotProxyBuilder.cc

Go to the documentation of this file.
00001 /*
00002  *  FWBeamSpotProxyBuilder.cc
00003  *  FWorks
00004  *
00005  *  Created by Ianna Osborne on 7/29/10.
00006  *
00007  */
00008 #include "TEveStraightLineSet.h"
00009 
00010 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
00011 #include "Fireworks/Core/interface/FWEventItem.h"
00012 
00013 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00014 
00015 class FWBeamSpotProxyBuilder : public FWSimpleProxyBuilderTemplate<reco::BeamSpot>
00016 {
00017 public:
00018   FWBeamSpotProxyBuilder( void ) {}
00019   virtual ~FWBeamSpotProxyBuilder( void ) {}
00020    
00021   REGISTER_PROXYBUILDER_METHODS();
00022 
00023 private:
00024   // Disable default copy constructor
00025   FWBeamSpotProxyBuilder( const FWBeamSpotProxyBuilder& );
00026   // Disable default assignment operator
00027   const FWBeamSpotProxyBuilder& operator=( const FWBeamSpotProxyBuilder& );
00028   virtual void localModelChanges(const FWModelId& iId, TEveElement* parent, FWViewType::EType viewType, const FWViewContext* vc);
00029 
00030   virtual void build( const reco::BeamSpot& iData, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext* );
00031 };
00032 
00033 void FWBeamSpotProxyBuilder::localModelChanges(const FWModelId& iId, TEveElement* parent, FWViewType::EType viewType, const FWViewContext* vc)
00034 {
00035   if( TEveStraightLineSet *ls = dynamic_cast<TEveStraightLineSet*> ( *parent->BeginChildren() ))
00036   { 
00037     Color_t c = FWProxyBuilderBase::item()->modelInfo( iId.index() ).displayProperties().color();
00038     for (TEveProjectable::ProjList_i j = ls->BeginProjecteds(); j != ls->EndProjecteds(); ++j)
00039     {
00040       if( TEveStraightLineSet *pls = dynamic_cast<TEveStraightLineSet*> (*j))
00041       {
00042         pls->SetMarkerColor(c);
00043         pls->ElementChanged();
00044       }
00045     }
00046 
00047     ls->SetMarkerColor(c);
00048     ls->ElementChanged();
00049   }
00050 }
00051 
00052 void
00053 FWBeamSpotProxyBuilder::build( const reco::BeamSpot& bs, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext* )
00054 {  
00055    TEveStraightLineSet* ls = new TEveStraightLineSet();
00056 
00057    double pos[3] = { bs.x0(), bs.y0(), bs.z0() };
00058    double e[3] = { bs.x0Error(), bs.y0Error(), bs.z0Error() };
00059 
00060    const Int_t   N = 32;
00061    const Float_t S = 2*TMath::Pi()/N;
00062 
00063    Float_t a = e[0], b = e[1];
00064    for (Int_t i = 0; i<N; i++)
00065       ls->AddLine(a*TMath::Cos(i*S)  , b*TMath::Sin(i*S)  , 0,
00066                   a*TMath::Cos(i*S+S), b*TMath::Sin(i*S+S), 0);
00067 
00068    a = e[0]; b = e[2];
00069    for (Int_t i = 0; i<N; i++)
00070       ls->AddLine(a*TMath::Cos(i*S)  , 0, b*TMath::Sin(i*S),
00071                   a*TMath::Cos(i*S+S), 0, b*TMath::Sin(i*S+S));
00072 
00073    a = e[1]; b = e[2];
00074    for (Int_t i = 0; i<N; i++)
00075       ls->AddLine(0, a*TMath::Cos(i*S)  ,  b*TMath::Sin(i*S),
00076                   0, a*TMath::Cos(i*S+S),  b*TMath::Sin(i*S+S));
00077 
00078    ls->AddLine(0,0,0,0,0,0);
00079    ls->AddMarker(0,0,0);
00080    ls->SetMarkerStyle(21);
00081    const FWDisplayProperties &dp = 
00082       FWProxyBuilderBase::item()->defaultDisplayProperties();
00083    ls->SetMarkerColor( dp.color() );
00084 
00085    ls->RefMainTrans().SetPos(pos);
00086    setupAddElement(ls, &oItemHolder);
00087 }
00088 
00089 REGISTER_FWPROXYBUILDER( FWBeamSpotProxyBuilder, reco::BeamSpot, "Beam Spot",  FWViewType::kAll3DBits | FWViewType::kAllRPZBits );