CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/Fireworks/ParticleFlow/plugins/FWPFBlockProxyBuilder.cc

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