CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Fireworks/ParticleFlow/src/FWPFTrackUtils.cc

Go to the documentation of this file.
00001 #include "Fireworks/ParticleFlow/interface/FWPFTrackUtils.h"
00002 
00003 //______________________________________________________________________________
00004 TEveStraightLineSet *
00005 FWPFTrackUtils::setupLegoTrack( const reco::Track &iData )
00006 {
00007    // Declarations
00008    int wraps[3] = { -1, -1, -1 };
00009    bool ECAL = false;
00010    TEveTrack *trk = m_trackUtils->getTrack( iData );
00011    std::vector<TEveVector> trackPoints( trk->GetN() - 1 );
00012    const Float_t *points = trk->GetP();
00013    TEveStraightLineSet *legoTrack = new TEveStraightLineSet();
00014 
00015    if( m_trackUtils->getField()->getSource() == FWMagField::kNone );
00016    {
00017       if( fabs( iData.eta() ) < 2.0 && iData.pt() > 0.5 && iData.pt() < 30 )
00018       {
00019          double estimate = fw::estimate_field( iData, true );
00020          if( estimate >= 0 ) m_trackUtils->getField()->guessField( estimate );
00021       }
00022    }
00023 
00024    // Convert to Eta/Phi and store in vector
00025    for( Int_t i = 1; i < trk->GetN(); ++i )
00026    {
00027       int j = i * 3;
00028       TEveVector temp = TEveVector( points[j], points[j+1], points[j+2] );
00029       TEveVector vec = TEveVector( temp.Eta(), temp.Phi(), 0.001 );
00030 
00031       trackPoints[i-1] = vec;
00032    }
00033 
00034    // Add first point to ps if necessary
00035    for( Int_t i = 1; i < trk->GetN(); ++i )
00036    {
00037       int j = i * 3;
00038       TEveVector v1 = TEveVector( points[j], points[j+1], points[j+2] );
00039 
00040       if( !ECAL )
00041       {
00042          if( m_trackUtils->checkIntersect( v1, m_trackUtils->getCaloR1() ) )
00043          {        
00044             TEveVector v2 = TEveVector( points[j-3], points[j-2], points[j-1] );
00045             TEveVector xyPoint = m_trackUtils->lineCircleIntersect( v1, v2, m_trackUtils->getCaloR1() );
00046             TEveVector zPoint;
00047             if( v1.fZ < 0 )
00048                zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ - 50.f );
00049             else
00050                zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ + 50.f );
00051 
00052             TEveVector vec = m_trackUtils->lineLineIntersect( v1, v2, xyPoint, zPoint );
00053             legoTrack->AddMarker( vec.Eta(), vec.Phi(), 0.001, 0 );
00054 
00055             wraps[0] = i;        // There is now a chance that the track will also reach the HCAL radius
00056             ECAL = true;
00057          }
00058          else if( fabs( v1.fZ ) >= m_trackUtils->getCaloZ1() )
00059          {
00060             TEveVector p1, p2;
00061             TEveVector vec, v2 = TEveVector( points[j-3], points[j-2], points[j-1] );
00062             float z, y = m_trackUtils->linearInterpolation( v2, v1, m_trackUtils->getCaloZ1() );
00063 
00064             if( v2.fZ > 0 )
00065                z = m_trackUtils->getCaloZ1();
00066             else
00067                z = m_trackUtils->getCaloZ1() * -1;
00068 
00069             p1 = TEveVector( v2.fX + 50, y, z );
00070             p2 = TEveVector( v2.fX - 50, y, z );
00071             vec = m_trackUtils->lineLineIntersect( v1, v2, p1, p2 );
00072 
00073             legoTrack->AddMarker( vec.Eta(), vec.Phi(), 0.001, 0 );
00074             wraps[0] = i;
00075             ECAL = true;
00076          }
00077       }
00078       else if( m_trackUtils->checkIntersect( v1, m_trackUtils->getCaloR2() ) )
00079       {
00080          TEveVector v2 = TEveVector( points[j-3], points[j-2], points[j-1] );
00081          TEveVector xyPoint = m_trackUtils->lineCircleIntersect( v1, v2, m_trackUtils->getCaloR2() );
00082          TEveVector zPoint;
00083          if( v1.fZ < 0 )
00084             zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ - 50.f );
00085          else
00086             zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ + 50.f );
00087 
00088          TEveVector vec = m_trackUtils->lineLineIntersect( v1, v2, xyPoint, zPoint );
00089          legoTrack->AddMarker( vec.Eta(), vec.Phi(), 0.001, 1 );
00090 
00091          wraps[1] = i;        // There is now a chance that the track will also reach the HCAL radius
00092          break;
00093       }
00094    }
00095 
00096    if( wraps[0] != -1 ) //if( ECAL )
00097    {
00098       int i = ( trk->GetN() - 1 ) * 3;
00099       int j = trk->GetN() - 2;   // This is equal to the last index in trackPoints vector
00100       TEveVector vec = TEveVector( points[i], points[i+1], points[i+2] );
00101 
00102       if( m_trackUtils->checkIntersect( vec, m_trackUtils->getCaloR3() - 1 ) )
00103       {
00104          legoTrack->AddMarker( vec.Eta(), vec.Phi(), 0.001, 2 );
00105          wraps[2] = j;
00106       }
00107       else if( fabs( vec.fZ ) >= m_trackUtils->getCaloZ2() )
00108       {
00109          legoTrack->AddMarker( vec.Eta(), vec.Phi(), 0.001, 2 );
00110          wraps[2] = j;
00111       }
00112    }
00113 
00114    // Handle phi wrapping
00115    for( int i = 0; i < static_cast<int>( trackPoints.size() - 1 ); ++i )
00116    {
00117       if( ( trackPoints[i+1].fY - trackPoints[i].fY ) > 1 )
00118       {
00119          trackPoints[i+1].fY -= TMath::TwoPi();
00120          if( i == wraps[0] )
00121          {
00122             TEveChunkManager::iterator mi( legoTrack->GetMarkerPlex() );
00123             mi.next();  // First point
00124             TEveStraightLineSet::Marker_t &m = * ( TEveStraightLineSet::Marker_t* ) mi();
00125             m.fV[0] = trackPoints[i+1].fX; m.fV[1] = trackPoints[i+1].fY; m.fV[2] = 0.001;
00126          }
00127          else if( i == wraps[1] )
00128          {
00129             TEveChunkManager::iterator mi( legoTrack->GetMarkerPlex() );
00130             mi.next(); mi.next();  // Second point
00131             TEveStraightLineSet::Marker_t &m = * ( TEveStraightLineSet::Marker_t* ) mi();
00132             m.fV[0] = trackPoints[i+1].fX; m.fV[1] = trackPoints[i+1].fY; m.fV[2] = 0.001;
00133          }
00134       }
00135 
00136       if( ( trackPoints[i].fY - trackPoints[i+1].fY ) > 1 )
00137       {
00138          trackPoints[i+1].fY += TMath::TwoPi();
00139          if( i == wraps[0] )
00140          {
00141             TEveChunkManager::iterator mi( legoTrack->GetMarkerPlex() );
00142             mi.next();  // First point
00143             TEveStraightLineSet::Marker_t &m = * ( TEveStraightLineSet::Marker_t* ) mi();
00144             m.fV[0] = trackPoints[i+1].fX; m.fV[1] = trackPoints[i+1].fY; m.fV[2] = 0.001;
00145          }
00146          else if( i == wraps[1] )
00147          {
00148             TEveChunkManager::iterator mi( legoTrack->GetMarkerPlex() );
00149             mi.next();  mi.next(); // Second point
00150             TEveStraightLineSet::Marker_t &m = * ( TEveStraightLineSet::Marker_t* ) mi();
00151             m.fV[0] = trackPoints[i+1].fX; m.fV[1] = trackPoints[i+1].fY; m.fV[2] = 0.001;
00152          }
00153       }
00154    }
00155 
00156    int end = static_cast<int>( trackPoints.size() - 1 );
00157    if( wraps[2] == end )
00158    {
00159       TEveChunkManager::iterator mi( legoTrack->GetMarkerPlex() );
00160       mi.next(); mi.next(); mi.next();   // Third point
00161       TEveStraightLineSet::Marker_t &m = * ( TEveStraightLineSet::Marker_t* ) mi();
00162       m.fV[0] = trackPoints[end].fX; m.fV[1] = trackPoints[end].fY; m.fV[2] = 0.001;
00163    }
00164 
00165    // Set points on TEveLineSet object ready for displaying
00166    for( unsigned int i = 0;i < trackPoints.size() - 1; ++i )
00167       legoTrack->AddLine( trackPoints[i], trackPoints[i+1] );
00168 
00169    legoTrack->SetDepthTest( false );
00170    legoTrack->SetMarkerStyle( 4 );
00171    legoTrack->SetMarkerSize( 1 );
00172    legoTrack->SetRnrMarkers( false );
00173 
00174    delete trk;    // Release memory that is no longer required*/
00175 
00176    return legoTrack;
00177 }
00178 
00179 //______________________________________________________________________________
00180 TEveTrack *
00181 FWPFTrackUtils::setupRPZTrack( const reco::Track &iData )
00182 {
00183    if( m_trackUtils->getField()->getSource() == FWMagField::kNone );
00184    {
00185       if( fabs( iData.eta() ) < 2.0 && iData.pt() > 0.5 && iData.pt() < 30 )
00186       {
00187          double estimate = fw::estimate_field( iData, true );
00188          if( estimate >= 0 ) m_trackUtils->getField()->guessField( estimate );
00189       }
00190    }
00191 
00192    TEveTrack *trk = m_trackUtils->getTrack( iData );
00193    
00194    return trk;
00195 }
00196 
00197 
00198 //______________________________________________________________________________
00199 TEvePointSet *
00200 FWPFTrackUtils::getCollisionMarkers( const TEveTrack *trk )
00201 {
00202    bool ECAL = false;
00203    const Float_t *points = trk->GetP();
00204    TEvePointSet *ps = new TEvePointSet();
00205 
00206    for( Int_t i = 1; i < trk->GetN(); ++i )
00207    {
00208       int j = i * 3;
00209       TEveVector v1 = TEveVector( points[j], points[j+1], points[j+2] );
00210 
00211       if( !ECAL )
00212       {
00213          if( m_trackUtils->checkIntersect( v1, m_trackUtils->getCaloR1() ) )
00214          {
00215             TEveVector v2 = TEveVector( points[j-3], points[j-2], points[j-1] );
00216             TEveVector xyPoint = m_trackUtils->lineCircleIntersect( v1, v2, m_trackUtils->getCaloR1() );
00217             TEveVector zPoint;
00218             if( v1.fZ < 0 )
00219                zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ - 50.f );
00220             else
00221                zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ + 50.f );
00222 
00223             TEveVector vec = m_trackUtils->lineLineIntersect( v1, v2, xyPoint, zPoint );
00224             ps->SetNextPoint( vec.fX, vec.fY, vec.fZ );
00225 
00226             ECAL = true;
00227          }
00228          else if( fabs( v1.fZ ) >= m_trackUtils->getCaloZ1() )
00229          {
00230             TEveVector p1, p2;
00231             TEveVector vec, v2 = TEveVector( points[j-3], points[j-2], points[j-1] );
00232             float z, y = m_trackUtils->linearInterpolation( v2, v1, m_trackUtils->getCaloZ1() );
00233 
00234             if( v2.fZ > 0 )
00235                z = m_trackUtils->getCaloZ1();
00236             else
00237                z = m_trackUtils->getCaloZ1() * -1;
00238 
00239             p1 = TEveVector( v2.fX + 50, y, z );
00240             p2 = TEveVector( v2.fX - 50, y, z );
00241             vec = m_trackUtils->lineLineIntersect( v1, v2, p1, p2 );
00242 
00243             ps->SetNextPoint( vec.fX, vec.fY, vec.fZ );
00244             ECAL = true;
00245          }
00246       }
00247       else if ( m_trackUtils->checkIntersect( v1, m_trackUtils->getCaloR2() ) )
00248       {
00249          TEveVector v2 = TEveVector( points[j-3], points[j-2], points[j-1] );
00250          TEveVector xyPoint = m_trackUtils->lineCircleIntersect( v1, v2,  m_trackUtils->getCaloR2() );
00251          TEveVector zPoint;
00252          if( v1.fZ < 0 )
00253             zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ - 50.f );
00254          else
00255             zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ + 50.f );
00256 
00257          TEveVector vec = m_trackUtils->lineLineIntersect( v1, v2, xyPoint, zPoint );
00258          ps->SetNextPoint( vec.fX, vec.fY, vec.fZ );
00259          break;   // ECAL and HCAL collisions found so stop looping
00260       }
00261    }
00262 
00263    // HCAL collisions (outer radius and endcap)
00264    int i = ( trk->GetN() - 1 ) * 3;
00265    TEveVector vec = TEveVector( points[i], points[i+1], points[i+2] );
00266 
00267    if( m_trackUtils->checkIntersect( vec, m_trackUtils->getCaloR3() - 1 ) )
00268       ps->SetNextPoint( vec.fX, vec.fY, vec.fZ );
00269    else if( fabs( vec.fZ ) >= m_trackUtils->getCaloZ2() )
00270       ps->SetNextPoint( vec.fX, vec.fY, vec.fZ );
00271 
00272    return ps;
00273 }