CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/Fireworks/SimData/plugins/FWPSimHitProxyBuilder.cc

Go to the documentation of this file.
00001 /*
00002  *  FWPSimHitProxyBuilder.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/FWEventItem.h"
00011 #include "Fireworks/Core/interface/FWGeometry.h"
00012 #include "Fireworks/Core/interface/fwLog.h"
00013 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00014 #include <DataFormats/MuonDetId/interface/DTWireId.h>
00015 
00016 #include "TEvePointSet.h"
00017 
00018 class FWPSimHitProxyBuilder : public FWSimpleProxyBuilderTemplate<PSimHit>
00019 {
00020 public:
00021    FWPSimHitProxyBuilder( void ) {} 
00022    virtual ~FWPSimHitProxyBuilder( void ) {}
00023 
00024    virtual bool haveSingleProduct() const { return false; }
00025 
00026    REGISTER_PROXYBUILDER_METHODS();
00027 
00028 private:
00029    // Disable default copy constructor
00030    FWPSimHitProxyBuilder( const FWPSimHitProxyBuilder& );
00031    // Disable default assignment operator
00032    const FWPSimHitProxyBuilder& operator=( const FWPSimHitProxyBuilder& );
00033 
00034    void buildViewType( const PSimHit& iData, unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType type, const FWViewContext* );
00035 };
00036 
00037 void
00038 FWPSimHitProxyBuilder::buildViewType( const PSimHit& iData, unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType type, const FWViewContext* )
00039 {
00040    TEvePointSet* pointSet = new TEvePointSet;
00041    setupAddElement( pointSet, &oItemHolder );
00042    const FWGeometry *geom = item()->getGeom();
00043    unsigned int rawid = iData.detUnitId();
00044    if( ! geom->contains( rawid ))
00045    {
00046       fwLog( fwlog::kError )
00047         << "failed to get geometry of detid: " 
00048         << rawid << std::endl;
00049       return;
00050    }
00051    
00052    float local[3] = { iData.localPosition().x(), iData.localPosition().y(), iData.localPosition().z() };
00053    float global[3];
00054 
00055    // Specialized for DT simhits
00056    DetId id(rawid);
00057    if (id.det()==DetId::Muon && id.subdetId()==1) {   
00058      DTWireId wId(rawid);
00059      rawid = wId.layerId().rawId(); // DT simhits are in the RF of the DTLayer, but their ID is the id of the wire!
00060      if (abs(iData.particleType())!=13){
00061        pointSet->SetMarkerStyle(26); // Draw non-muon simhits (e.g. delta rays) with a different marker
00062      } 
00063      if (type == FWViewType::kRhoZ) { // 
00064        // In RhoZ view, draw hits at the middle of the layer in the global Z coordinate, 
00065        // otherwise they won't align with 1D rechits, for which only one coordinate is known.
00066        if (wId.superLayer()==2) {
00067          local[1]=0;
00068        } else {
00069          local[0]=0;
00070        }
00071      }
00072    }
00073 
00074    geom->localToGlobal( rawid, local, global );
00075    pointSet->SetNextPoint( global[0], global[1], global[2] );
00076 }
00077 
00078 REGISTER_FWPROXYBUILDER( FWPSimHitProxyBuilder, PSimHit, "PSimHits", FWViewType::kAll3DBits | FWViewType::kAllRPZBits );