Go to the documentation of this file.00001 #include "Fireworks/ParticleFlow/interface/FWPFUtils.h"
00002
00003
00004 FWPFUtils::FWPFUtils() : m_trackerTrackPropagator(0), m_trackPropagator(0), m_magField(0)
00005 {
00006
00007 m_caloR1 = 129;
00008 m_caloZ1 = 303.353;
00009
00010
00011 m_caloR2 = 177.7;
00012 m_caloR3 = 287.65;
00013 m_caloZ2 = 400.458;
00014 }
00015
00016
00017 TEveTrack *
00018 FWPFUtils::getTrack( const reco::Track &iData )
00019 {
00020 TEveTrackPropagator *propagator = ( !iData.extra().isAvailable() ) ? m_trackerTrackPropagator : m_trackPropagator;
00021
00022 TEveRecTrack t;
00023 t.fBeta = 1;
00024 t.fP = TEveVector( iData.px(), iData.py(), iData.pz() );
00025 t.fV = TEveVector( iData.vertex().x(), iData.vertex().y(), iData.vertex().z() );
00026 t.fSign = iData.charge();
00027 TEveTrack *trk = new TEveTrack( &t, propagator );
00028 trk->MakeTrack();
00029
00030 return trk;
00031 }
00032
00033
00034 TEveVector
00035 FWPFUtils::lineCircleIntersect( const TEveVector &v1, const TEveVector &v2, float r )
00036 {
00037
00038 float x, y;
00039 float dx = v1.fX - v2.fX;
00040 float dy = v1.fY - v2.fY;
00041 float dr = sqrt( ( dx * dx ) + ( dy * dy ) );
00042 float D = ( ( v2.fX * v1.fY ) - ( v1.fX * v2.fY ) );
00043
00044 float rtDescrim = sqrt( ( ( r * r ) * ( dr * dr ) ) - ( D * D ) );
00045
00046 if( dy < 0 )
00047 {
00048 x = ( D * dy ) - ( ( sgn(dy) * dx ) * rtDescrim );
00049 x /= ( dr * dr );
00050
00051 y = ( -D * dx ) - ( fabs( dy ) * rtDescrim );
00052 y /= ( dr * dr );
00053 }
00054 else
00055 {
00056
00057 x = ( D * dy ) + ( ( sgn(dy) * dx ) * rtDescrim );
00058 x /= ( dr * dr );
00059
00060 y = ( -D * dx ) + ( fabs( dy ) * rtDescrim );
00061 y /= ( dr * dr );
00062 }
00063
00064 TEveVector result = TEveVector( x, y, 0.001 );
00065 return result;
00066 }
00067
00068
00069 TEveVector
00070 FWPFUtils::lineLineIntersect( const TEveVector &p1, const TEveVector &p2, const TEveVector &p3, const TEveVector &p4 )
00071 {
00072 TEveVector a = p2 - p1;
00073 TEveVector b = p4 - p3;
00074 TEveVector c = p3 - p1;
00075 TEveVector result;
00076 float s, val;
00077
00078 s = dot( cross( c, b ), cross( a, b ) );
00079 val = dot( cross( a, b ), cross( a, b ) );
00080 s /= val;
00081
00082 result = p1 + ( a * s );
00083 return result;
00084 }
00085
00086
00087 TEveVector
00088 FWPFUtils::cross( const TEveVector &v1, const TEveVector &v2 )
00089 {
00090 TEveVector vec;
00091
00092 vec.fX = ( v1.fY * v2.fZ ) - ( v1.fZ * v2.fY );
00093 vec.fY = ( v1.fZ * v2.fX ) - ( v1.fX * v2.fZ );
00094 vec.fZ = ( v1.fX * v2.fY ) - ( v1.fY * v2.fX );
00095
00096 return vec;
00097 }
00098
00099
00100 float
00101 FWPFUtils::linearInterpolation( const TEveVector &p1, const TEveVector &p2, float z )
00102 {
00103 float y;
00104
00105 y = ( ( z - fabs( p1.fZ ) ) * p2.fY ) + ( ( fabs( p2.fZ ) - z ) * p1.fY );
00106 y /= ( fabs( p2.fZ) - fabs( p1.fZ ) );
00107
00108 return y;
00109 }
00110
00111
00112 float
00113 FWPFUtils::dot( const TEveVector &v1, const TEveVector &v2 )
00114 {
00115 float result = ( v1.fX * v2.fX ) + ( v1.fY * v2.fY ) + ( v1.fZ * v1.fZ );
00116
00117 return result;
00118 }
00119
00120
00121 float
00122 FWPFUtils::sgn( float val )
00123 {
00124 return ( val < 0 ) ? -1 : 1;
00125 }
00126
00127
00128 bool
00129 FWPFUtils::checkIntersect( const TEveVector &p, float r )
00130 {
00131 float h = sqrt( ( p.fX * p.fX ) + ( p.fY * p.fY ) );
00132
00133 if( h >= r )
00134 return true;
00135
00136 return false;
00137 }
00138
00139
00140 void
00141 FWPFUtils::initPropagator()
00142 {
00143 m_magField = new FWMagField();
00144
00145
00146 m_trackPropagator = new TEveTrackPropagator();
00147 m_trackPropagator->SetMagFieldObj( m_magField, false );
00148 m_trackPropagator->SetMaxR( m_caloR3 );
00149 m_trackPropagator->SetMaxZ( m_caloZ2 );
00150 m_trackPropagator->SetDelta( 0.01 );
00151 m_trackPropagator->SetProjTrackBreaking( TEveTrackPropagator::kPTB_UseLastPointPos );
00152 m_trackPropagator->SetRnrPTBMarkers( kTRUE );
00153 m_trackPropagator->IncDenyDestroy();
00154
00155
00156 m_trackerTrackPropagator = new TEveTrackPropagator();
00157 m_trackerTrackPropagator->SetStepper( TEveTrackPropagator::kRungeKutta );
00158 m_trackerTrackPropagator->SetMagFieldObj( m_magField, false );
00159 m_trackerTrackPropagator->SetDelta( 0.01 );
00160 m_trackerTrackPropagator->SetMaxR( m_caloR3 );
00161 m_trackerTrackPropagator->SetMaxZ( m_caloZ2 );
00162 m_trackerTrackPropagator->SetProjTrackBreaking( TEveTrackPropagator::kPTB_UseLastPointPos );
00163 m_trackerTrackPropagator->SetRnrPTBMarkers( kTRUE );
00164 m_trackerTrackPropagator->IncDenyDestroy();
00165 }
00166