CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Fireworks/SimData/plugins/FWTrackingParticleProxyBuilder.cc

Go to the documentation of this file.
00001 /*
00002  *  FWTrackingParticleProxyBuilder.cc
00003  *  FWorks
00004  *
00005  *  Created by Ianna Osborne on 9/9/10.
00006  *
00007  */
00008 
00009 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
00010 #include "Fireworks/Core/interface/Context.h"
00011 #include "Fireworks/Core/interface/FWEventItem.h"
00012 #include "Fireworks/Core/interface/FWGeometry.h"
00013 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
00014 
00015 #include "TEveTrack.h"
00016 
00017 class FWTrackingParticleProxyBuilder : public FWSimpleProxyBuilderTemplate<TrackingParticle>
00018 {
00019 public:
00020    FWTrackingParticleProxyBuilder( void ) {} 
00021    virtual ~FWTrackingParticleProxyBuilder( void ) {}
00022 
00023    REGISTER_PROXYBUILDER_METHODS();
00024 
00025 private:
00026    // Disable default copy constructor
00027    FWTrackingParticleProxyBuilder( const FWTrackingParticleProxyBuilder& );
00028    // Disable default assignment operator
00029    const FWTrackingParticleProxyBuilder& operator=( const FWTrackingParticleProxyBuilder& );
00030 
00031    void build( const TrackingParticle& iData, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext* );
00032 };
00033 
00034 void
00035 FWTrackingParticleProxyBuilder::build( const TrackingParticle& iData, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext* )
00036 {
00037    TEveRecTrack t;
00038    t.fBeta = 1.0;
00039    t.fP = TEveVector( iData.px(), iData.py(), iData.pz() );
00040    t.fV = TEveVector( iData.vx(), iData.vy(), iData.vz() );
00041    t.fSign = iData.charge();
00042   
00043    TEveTrack* track = new TEveTrack(&t, context().getTrackPropagator());
00044    if( t.fSign == 0 )
00045       track->SetLineStyle( 7 );
00046    
00047    TEvePointSet* pointSet = new TEvePointSet;
00048    setupAddElement( pointSet, track );
00049    const FWGeometry *geom = item()->getGeom();
00050    const std::vector<PSimHit>& hits = iData.trackPSimHit();
00051 
00052    float local[3];
00053    float localDir[3];
00054    float global[3] = { 0.0, 0.0, 0.0 };
00055    float globalDir[3] = { 0.0, 0.0, 0.0 };
00056    std::vector<PSimHit>::const_iterator it = hits.begin();
00057    std::vector<PSimHit>::const_iterator end = hits.end();
00058    if( it != end )
00059    {
00060       unsigned int trackid = hits.begin()->trackId();
00061 
00062       for( ; it != end; ++it )
00063       {
00064          const PSimHit& phit = (*it);
00065          if( phit.trackId() != trackid )
00066          {
00067             trackid = phit.trackId();
00068             track->AddPathMark( TEvePathMark( TEvePathMark::kDecay, TEveVector( global[0], global[1], global[2] ),
00069                                               TEveVector( globalDir[0], globalDir[1], globalDir[2] )));
00070          }
00071          local[0] = phit.localPosition().x();
00072          local[1] = phit.localPosition().y();
00073          local[2] = phit.localPosition().z();
00074          localDir[0] = phit.momentumAtEntry().x();
00075          localDir[1] = phit.momentumAtEntry().y();
00076          localDir[2] = phit.momentumAtEntry().z();
00077          geom->localToGlobal( phit.detUnitId(), local, global );
00078          geom->localToGlobal( phit.detUnitId(), localDir, globalDir );
00079          pointSet->SetNextPoint( global[0], global[1], global[2] );
00080          track->AddPathMark( TEvePathMark( TEvePathMark::kReference/*kDaughter*/, TEveVector( global[0], global[1], global[2] ),
00081                                            TEveVector( globalDir[0], globalDir[1], globalDir[2] )));
00082       }
00083       if( hits.size() > 1 )
00084          track->AddPathMark( TEvePathMark( TEvePathMark::kDecay, TEveVector( global[0], global[1], global[2] ),
00085                                            TEveVector( globalDir[0], globalDir[1], globalDir[2] )));
00086    }
00087    
00088    track->MakeTrack();
00089    setupAddElement( track, &oItemHolder );
00090 }
00091 
00092 REGISTER_FWPROXYBUILDER( FWTrackingParticleProxyBuilder, TrackingParticle, "TrackingParticles", FWViewType::kAll3DBits | FWViewType::kAllRPZBits );