CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/Fireworks/Electrons/plugins/FWElectronProxyBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Electrons
00004 // Class  :     FWElectronProxyBuilder
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: FWElectronProxyBuilder.cc,v 1.19 2010/11/11 20:25:28 amraktad Exp $
00012 //
00013 #include "TEveCompound.h"
00014 #include "TEveTrack.h"
00015 #include "TEveScalableStraightLineSet.h"
00016 
00017 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
00018 #include "Fireworks/Core/interface/FWEventItem.h"
00019 #include "Fireworks/Core/interface/FWViewType.h"
00020 
00021 #include "Fireworks/Candidates/interface/CandidateUtils.h"
00022 #include "Fireworks/Tracks/interface/TrackUtils.h"
00023 #include "Fireworks/Electrons/interface/makeSuperCluster.h" 
00024 
00025 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00026 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00027 
00029 //
00030 //   3D and RPZ proxy builder with shared track list
00031 // 
00033 
00034 class FWElectronProxyBuilder : public FWSimpleProxyBuilderTemplate<reco::GsfElectron> {
00035 
00036 public:
00037    FWElectronProxyBuilder() ;
00038    virtual ~FWElectronProxyBuilder();
00039 
00040    virtual bool haveSingleProduct() const { return false; }
00041    virtual void cleanLocal();
00042 
00043    REGISTER_PROXYBUILDER_METHODS();
00044 
00045 private:
00046    FWElectronProxyBuilder( const FWElectronProxyBuilder& ); // stop default
00047    const FWElectronProxyBuilder& operator=( const FWElectronProxyBuilder& ); // stop default
00048   
00049    virtual void buildViewType(const reco::GsfElectron& iData, unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType type , const FWViewContext*);
00050 
00051    TEveElementList* requestCommon();
00052 
00053    TEveElementList* m_common;
00054 };
00055 
00056 
00057 FWElectronProxyBuilder::FWElectronProxyBuilder():
00058    m_common(0)
00059 {
00060    m_common = new TEveElementList( "common electron scene" );
00061    m_common->IncDenyDestroy();
00062 }
00063 
00064 FWElectronProxyBuilder::~FWElectronProxyBuilder()
00065 {
00066    m_common->DecDenyDestroy();
00067 }
00068 
00069 TEveElementList*
00070 FWElectronProxyBuilder::requestCommon()
00071 {
00072    if( m_common->HasChildren() == false )
00073    {
00074       for (int i = 0; i < static_cast<int>(item()->size()); ++i)
00075       {
00076          const reco::GsfElectron& electron = modelData(i);
00077 
00078          TEveTrack* track(0);
00079          if( electron.gsfTrack().isAvailable() )
00080             track = fireworks::prepareTrack( *electron.gsfTrack(),
00081                                              context().getTrackPropagator());
00082          else
00083             track = fireworks::prepareCandidate( electron,
00084                                                  context().getTrackPropagator());
00085          track->MakeTrack();
00086          setupElement( track );
00087          m_common->AddElement( track );
00088       }
00089    }
00090    return m_common;
00091 }
00092 
00093 void
00094 FWElectronProxyBuilder::cleanLocal()
00095 {
00096    m_common->DestroyElements();
00097 }
00098 
00099 void
00100 FWElectronProxyBuilder::buildViewType(const reco::GsfElectron& electron, unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType type , const FWViewContext*)
00101 {
00102    TEveElementList*   tracks = requestCommon();
00103    TEveElement::List_i trkIt = tracks->BeginChildren();
00104    std::advance(trkIt, iIndex);
00105    setupAddElement(*trkIt, &oItemHolder );
00106 
00107    if( type == FWViewType::kRhoPhi || type == FWViewType::kRhoPhiPF )
00108       fireworks::makeRhoPhiSuperCluster( this,
00109                                          electron.superCluster(),
00110                                          electron.phi(),
00111                                          oItemHolder );
00112    else if( type == FWViewType::kRhoZ )
00113       fireworks::makeRhoZSuperCluster( this,
00114                                        electron.superCluster(),
00115                                        electron.phi(),
00116                                        oItemHolder );
00117 }
00118 
00119 REGISTER_FWPROXYBUILDER( FWElectronProxyBuilder, reco::GsfElectron, "Electrons", FWViewType::kAll3DBits | FWViewType::kAllRPZBits );
00120 
00121 
00122 
00124 //
00125 //   GLIMPSE specific proxy builder
00126 // 
00128 
00129 class FWElectronGlimpseProxyBuilder : public FWSimpleProxyBuilderTemplate<reco::GsfElectron> {
00130 public:
00131    FWElectronGlimpseProxyBuilder() {}
00132    virtual ~FWElectronGlimpseProxyBuilder() {}
00133 
00134    REGISTER_PROXYBUILDER_METHODS();
00135 
00136 private:
00137    FWElectronGlimpseProxyBuilder(const FWElectronGlimpseProxyBuilder&); // stop default
00138 
00139    const FWElectronGlimpseProxyBuilder& operator=(const FWElectronGlimpseProxyBuilder&); // stop default
00140 
00141    virtual void build(const reco::GsfElectron& iData, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext*);
00142 };
00143 
00144 void
00145 FWElectronGlimpseProxyBuilder::build( const reco::GsfElectron& iData, unsigned int iIndex,TEveElement& oItemHolder , const FWViewContext*) 
00146 {
00147    TEveScalableStraightLineSet* marker = new TEveScalableStraightLineSet("", "");
00148    marker->SetLineWidth(2);
00149    fireworks::addStraightLineSegment( marker, &iData, 1.0 );
00150    setupAddElement(marker, &oItemHolder);
00151    //add to scaler at end so that it can scale the line after all ends have been added
00152    // FIXME: It's not a part of a standard FWSimpleProxyBuilderTemplate: the scaler is not set!
00153 //    assert(scaler());
00154 //    scaler()->addElement(marker);
00155 }
00156 REGISTER_FWPROXYBUILDER(FWElectronGlimpseProxyBuilder, reco::GsfElectron, "Electrons", FWViewType::kGlimpseBit);