CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Fireworks/ParticleFlow/plugins/FWPFBlockProxyBuilder.cc

Go to the documentation of this file.
00001 #include "FWPFBlockProxyBuilder.h"
00002 
00003 //______________________________________________________________________________
00004 void
00005 FWPFBlockProxyBuilder::scaleProduct( TEveElementList *parent, FWViewType::EType viewType, const FWViewContext *vc )
00006 {
00007    typedef std::vector<ScalableLines> Lines_t;
00008    FWViewEnergyScale *caloScale = vc->getEnergyScale();
00009 
00010    if( viewType == FWViewType::kRhoPhiPF || viewType == FWViewType::kRhoZ )
00011    {  /* Handle the rhophi and rhoz cluster scaling */
00012       for( Lines_t::iterator i = m_clusters.begin(); i != m_clusters.end(); ++i )
00013       {
00014          if( vc == (*i).m_vc )
00015          {
00016             float value = caloScale->getPlotEt() ? (*i).m_et : (*i).m_energy;
00017             (*i).m_ls->SetScale( caloScale->getScaleFactor3D() * value );
00018             TEveProjected *proj = *(*i).m_ls->BeginProjecteds();
00019             proj->UpdateProjection();
00020          }
00021       }
00022    } /* Handle cluster scaling in lego view(s) */
00023    else if( viewType == FWViewType::kLego || viewType == FWViewType::kLegoPFECAL )
00024    {  // Loop products
00025       for( TEveElement::List_i i = parent->BeginChildren(); i != parent->EndChildren(); ++i )
00026       {
00027          if( (*i)->HasChildren() )
00028          {  // Loop elements of block
00029             for( TEveElement::List_i j = (*i)->BeginChildren(); j != (*i)->EndChildren(); ++j )
00030             {
00031                if( strcmp( (*j)->GetElementName(), "BlockCluster" ) == 0 )
00032                {
00033                   FWPFLegoCandidate *cluster = dynamic_cast<FWPFLegoCandidate*>( *j );
00034                   cluster->updateScale( vc, context() );
00035                }
00036             }
00037          }
00038       }
00039    }
00040 }
00041 
00042 //______________________________________________________________________________
00043 void
00044 FWPFBlockProxyBuilder::setupTrackElement( const reco::PFBlockElement &blockElement, 
00045                                               TEveElement &oItemHolder, const FWViewContext *vc, FWViewType::EType viewType )
00046 {
00047    if( blockElement.trackType( reco::PFBlockElement::DEFAULT ) )
00048    {
00049       reco::Track track = *blockElement.trackRef();
00050       FWPFTrackUtils *trackUtils = new FWPFTrackUtils();
00051 
00052       if( viewType == FWViewType::kLego || viewType == FWViewType::kLegoPFECAL )       // Lego views
00053       {
00054          TEveStraightLineSet *legoTrack = trackUtils->setupLegoTrack( track );
00055          setupAddElement( legoTrack, &oItemHolder );
00056       }
00057       else if( viewType == FWViewType::kRhoPhiPF )   // RhoPhi view
00058       {
00059          TEveTrack *trk = trackUtils->setupTrack( track );
00060          TEvePointSet *ps = trackUtils->getCollisionMarkers( trk );
00061          setupAddElement( trk, &oItemHolder );
00062          if( ps->GetN() != 0 )
00063             setupAddElement( ps, &oItemHolder );
00064          else
00065             delete ps;
00066       }
00067       else if ( viewType == FWViewType::kRhoZ )       // RhoZ view
00068       {
00069          TEveTrack *trk = trackUtils->setupTrack( track );
00070          TEvePointSet *markers = trackUtils->getCollisionMarkers( trk );
00071          TEvePointSet *ps = new TEvePointSet();
00072          setupAddElement( trk, &oItemHolder );
00073 
00074          Float_t *trackPoints = trk->GetP();
00075          unsigned int last = ( trk->GetN() - 1 ) * 3;
00076          float y = trackPoints[last+1];
00077          float z = trackPoints[last+2];
00078 
00079          // Reposition any points that have been translated in RhoZ
00080          for( signed int i = 0; i < markers->GetN(); ++i )
00081          {
00082             Float_t a,b,c;
00083             markers->GetPoint( i, a, b, c );
00084             
00085             if( y < 0 && b > 0 )
00086                b *= -1;
00087             else if( y > 0 && b < 0 )
00088                b *= -1;
00089 
00090             if( z < 0 && c > 0 )
00091                c *= -1;
00092             else if( z > 0 && c < 0 )
00093                c *= -1;
00094 
00095             ps->SetNextPoint( a, b, c );
00096          }
00097 
00098          if( ps->GetN() != 0 )
00099             setupAddElement( ps, &oItemHolder );
00100          else
00101             delete ps;
00102          delete markers;
00103       }
00104       
00105       delete trackUtils;
00106    }
00107 }
00108 
00109 //______________________________________________________________________________
00110 void
00111 FWPFBlockProxyBuilder::setupClusterElement( const reco::PFBlockElement &blockElement, TEveElement &oItemHolder, 
00112                                                 const FWViewContext *vc, FWViewType::EType viewType, float r )
00113 {
00114    // Get reference to PFCluster
00115    reco::PFCluster cluster = *blockElement.clusterRef();
00116    TEveVector centre = TEveVector( cluster.x(), cluster.y(), cluster.z() );
00117    float energy = cluster.energy();
00118    float et = FWPFMaths::calculateEt( centre, energy );
00119    float pt = et;
00120    float eta = cluster.eta();
00121    float phi = cluster.phi();
00122 
00123    FWProxyBuilderBase::context().voteMaxEtAndEnergy( et, energy );
00124 
00125    if( viewType == FWViewType::kLego || viewType == FWViewType::kLegoPFECAL )
00126    {
00127       FWPFLegoCandidate *legoCluster = new FWPFLegoCandidate( vc, FWProxyBuilderBase::context(), energy, et, pt, eta, phi );
00128       legoCluster->SetMarkerColor( FWProxyBuilderBase::item()->defaultDisplayProperties().color() );
00129       legoCluster->SetElementName( "BlockCluster" );
00130       setupAddElement( legoCluster, &oItemHolder );
00131    }
00132    if( viewType == FWViewType::kRhoPhiPF )
00133    {
00134       const FWDisplayProperties &dp = item()->defaultDisplayProperties();
00135       FWPFClusterRPZUtils *clusterUtils = new FWPFClusterRPZUtils();
00136       TEveScalableStraightLineSet *rpCluster = clusterUtils->buildRhoPhiClusterLineSet( cluster, vc, energy, et, r );
00137       rpCluster->SetLineColor( dp.color() );
00138       m_clusters.push_back( ScalableLines( rpCluster, et, energy, vc ) );
00139       setupAddElement( rpCluster, &oItemHolder );
00140       delete clusterUtils;
00141    }
00142    else if( viewType == FWViewType::kRhoZ )
00143    {
00144       const FWDisplayProperties &dp = item()->defaultDisplayProperties();
00145       FWPFClusterRPZUtils *clusterUtils = new FWPFClusterRPZUtils();
00146       TEveScalableStraightLineSet *rzCluster = clusterUtils->buildRhoZClusterLineSet( cluster, vc, context().caloTransAngle(),
00147                                                                                       energy, et, r, context().caloZ1() );
00148       rzCluster->SetLineColor( dp.color() );
00149       m_clusters.push_back( ScalableLines( rzCluster, et, energy, vc ) );
00150       setupAddElement( rzCluster, &oItemHolder );
00151       delete clusterUtils;
00152    }
00153 }
00154 
00155 //______________________________________________________________________________
00156 void
00157 FWPFBlockProxyBuilder::buildViewType( const reco::PFBlock &iData, unsigned int iIndex, TEveElement &oItemHolder, 
00158                                   FWViewType::EType viewType, const FWViewContext *vc )
00159 {
00160    const edm::OwnVector<reco::PFBlockElement> &elements = iData.elements();
00161    
00162    for( unsigned int i = 0; i < elements.size(); ++i )
00163    {
00164       reco::PFBlockElement::Type type = elements[i].type();
00165       switch( type )
00166       {
00167          case 1:  // TRACK
00168             if( e_builderType == BASE )
00169                setupTrackElement( elements[i], oItemHolder, vc, viewType );
00170          break;
00171 
00172          case 4:  // ECAL
00173             if( e_builderType == ECAL )
00174                setupClusterElement( elements[i], oItemHolder, vc, viewType, FWPFUtils::caloR1() );
00175          break;
00176 
00177          case 5:  // HCAL
00178             if( e_builderType == HCAL )
00179             {
00180                if( viewType == FWViewType::kRhoPhiPF )
00181                   setupClusterElement( elements[i], oItemHolder, vc, viewType, FWPFUtils::caloR2() );
00182                else  // RhoZ
00183                   setupClusterElement( elements[i], oItemHolder, vc, viewType, context().caloR1() );
00184             }
00185          break;
00186 
00187          default: // Ignore anything that isn't wanted
00188          break;
00189       }
00190    }
00191 }
00192 
00193 //______________________________________________________________________________
00194 REGISTER_FWPROXYBUILDER( FWPFBlockProxyBuilder, reco::PFBlock, "PF Block", FWViewType::kRhoPhiPFBit | FWViewType::kLegoBit |
00195                                                                                FWViewType::kRhoZBit | FWViewType::kLegoPFECALBit );
00196 REGISTER_FWPROXYBUILDER( FWPFBlockEcalProxyBuilder, reco::PFBlock, "PF Block", FWViewType::kLegoPFECALBit | FWViewType::kRhoPhiPFBit |
00197                                                                                FWViewType::kRhoZBit );
00198 REGISTER_FWPROXYBUILDER( FWPFBlockHcalProxyBuilder, reco::PFBlock, "PF Block", FWViewType::kLegoBit | FWViewType::kRhoPhiPFBit |
00199                                                                                FWViewType::kRhoZBit );