CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/Geometry/TrackerGeometryBuilder/interface/StackedTrackerGeometry.h

Go to the documentation of this file.
00001 /*********************************/
00002 /*********************************/
00008 /*********************************/
00009 /*********************************/
00010 
00011 #ifndef STACKED_TRACKER_GEOMETRY_H
00012 #define STACKED_TRACKER_GEOMETRY_H
00013 
00014 #include <typeinfo>
00015 
00016 #include "DataFormats/SiPixelDetId/interface/StackedTrackerDetId.h"
00017 #include "DataFormats/GeometrySurface/interface/Plane.h"
00018 #include "SimDataFormats/SLHC/interface/L1TkStub.h" //yes this needs to be a DataFormat eventually
00019 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00020 #include "Geometry/CommonTopologies/interface/Topology.h"
00021 
00022 
00023 #include <vector>
00024 #include <ext/hash_map>
00025 
00026 class StackedTrackerDetUnit;
00027 class GeomDet;
00028 class TrackerGeometry;
00029 
00030 class StackedTrackerGeometry {
00031 public:
00032   typedef       std::vector<StackedTrackerDetUnit*>     StackContainer;
00033   typedef       std::vector<StackedTrackerDetUnit*>::const_iterator     StackContainerIterator;
00034   typedef       std::vector<StackedTrackerDetId>                StackIdContainer;
00035   typedef       std::vector<StackedTrackerDetId>::const_iterator                StackIdContainerIterator;
00036   typedef  __gnu_cxx::hash_map< unsigned int, StackedTrackerDetUnit*> mapIdToStack;
00037 
00038   StackedTrackerGeometry( const TrackerGeometry *i );  
00039   virtual ~StackedTrackerGeometry();  
00040 
00041   const StackContainer&         stacks()        const;
00042   const StackIdContainer&       stackIds()      const;
00043  
00044   void  addStack(StackedTrackerDetUnit *aStack);
00045 
00046   const StackedTrackerDetUnit*          idToStack( StackedTrackerDetId anId )   const;
00047 
00048 
00049 //analagous to the methods in TrackerGeomety except that you pass it a stack id and an identifier to a stack member
00050   const GeomDetUnit*       idToDetUnit( StackedTrackerDetId anId , unsigned int stackMemberIdentifier ) const;
00051   const GeomDet*           idToDet( StackedTrackerDetId anId , unsigned int stackMemberIdentifier )     const;
00052 
00053 
00054 //helper functions
00055   Plane::PlanePointer meanPlane(StackedTrackerDetId anId) const;
00056 
00057   //stub functions
00058   template< typename T >
00059   double findRoughPt( double aMagneticFieldStrength, const L1TkStub<T> *stub) const;
00060 
00061   template< typename T >
00062   GlobalPoint  findGlobalPosition( const L1TkStub<T> *stub ) const;
00063 
00064   template< typename T >
00065   GlobalVector findGlobalDirection( const L1TkStub<T> *stub ) const;
00066   
00067 
00068   //cluster functions
00069 
00070   template< typename T >
00071     LocalPoint       findHitLocalPosition( const L1TkCluster<T> *cluster , unsigned int hitIdx ) const;
00072   template< typename T >
00073     GlobalPoint      findHitGlobalPosition( const L1TkCluster<T> *cluster,  unsigned int hitIdx ) const;
00074   template< typename T >
00075     LocalPoint       findAverageLocalPosition(  const L1TkCluster<T> *cluster  ) const;
00076   template< typename T >
00077     GlobalPoint      findAverageGlobalPosition( const L1TkCluster<T> *cluster ) const;
00078   template< typename T >
00079     void checkSimTrack( L1TkCluster<T> *cluster,
00080                         edm::Handle<edm::DetSetVector<PixelDigiSimLink> > thePixelDigiSimLinkHandle,
00081                         edm::Handle<edm::SimTrackContainer> simTrackHandle ) const;
00082 
00083 
00084 
00085 private:
00086 
00087   const TrackerGeometry* theTracker;
00088 
00089   StackContainer        theStacks;
00090   StackIdContainer      theStackIds;
00091 
00092   mapIdToStack    theMap;
00093 
00094 };
00095 
00096 
00097   //bunch of specializations
00098   template<>
00099   LocalPoint StackedTrackerGeometry::findHitLocalPosition( const L1TkCluster< edm::Ref< edm::PSimHitContainer > > *cluster,
00100                                                            unsigned int hitIdx ) const;
00101 
00102   template<>
00103   GlobalPoint StackedTrackerGeometry::findHitGlobalPosition( const L1TkCluster< edm::Ref< edm::PSimHitContainer > > *cluster,
00104                                                              unsigned int hitIdx ) const;
00105 
00106 
00107   template<>
00108   LocalPoint StackedTrackerGeometry::findHitLocalPosition( const L1TkCluster< edm::Ref< edm::PSimHitContainer > > *cluster, unsigned int hitIdx ) const;
00109   
00110 
00111   template<>
00112   void StackedTrackerGeometry::checkSimTrack( L1TkCluster< edm::Ref< edm::PSimHitContainer > > *cluster,
00113                                               edm::Handle<edm::DetSetVector<PixelDigiSimLink> >  thePixelDigiSimLinkHandle,
00114                                               edm::Handle<edm::SimTrackContainer> simTrackHandle ) const;
00115 
00116 
00117 
00120 
00121   template< typename T >
00122   double StackedTrackerGeometry::findRoughPt( double aMagneticFieldStrength, const L1TkStub<T> *stub) const {
00125     //iSetup.get<IdealMagneticFieldRecord>().get(magnet);
00126     //magnet_ = magnet.product();
00127     //mMagneticFieldStrength = magnet_->inTesla(GlobalPoint(0,0,0)).z();
00132     double mPtFactor = (floor(aMagneticFieldStrength*10.0 + 0.5))/10.0*0.0015;
00133 
00135     GlobalPoint innerHitPosition = findAverageGlobalPosition( stub->getClusterPtr(0).get() );
00136     GlobalPoint outerHitPosition = findAverageGlobalPosition( stub->getClusterPtr(1).get() );
00137 
00139     double outerPointRadius = outerHitPosition.perp();
00140     double innerPointRadius = innerHitPosition.perp();
00141     double outerPointPhi = outerHitPosition.phi();
00142     double innerPointPhi = innerHitPosition.phi();
00143     double deltaRadius = outerPointRadius - innerPointRadius;
00144 
00146     StackedTrackerDetId tempDetId(stub->getDetId());
00147     if (tempDetId.isBarrel())
00148     {
00151       double deltaPhi = outerPointPhi - innerPointPhi;
00152       if (deltaPhi < 0)
00153         deltaPhi = -deltaPhi;
00154       if (deltaPhi > M_PI)
00155         deltaPhi = 2*M_PI - deltaPhi;
00156 
00158       return ( deltaRadius * mPtFactor / deltaPhi );
00159     }
00160     else if (tempDetId.isEndcap())
00161     {
00164       double roughPt = innerPointRadius * innerPointRadius * mPtFactor / fabs(findAverageLocalPosition( stub->getClusterPtr(0).get() ).x()) ;
00165       roughPt +=       outerPointRadius * outerPointRadius * mPtFactor / fabs(findAverageLocalPosition( stub->getClusterPtr(1).get() ).x()) ;
00166       roughPt = roughPt / 2.;
00167 
00169       return roughPt;
00170     }
00171 
00174     std::cerr << "W A R N I N G! L1TkStub::findRoughPt() \t we should never get here" << std::endl;
00175     return 99999.9;
00176   }
00177 
00178 
00179   template< typename T >
00180   GlobalPoint StackedTrackerGeometry::findGlobalPosition( const L1TkStub< T > *stub ) const
00181 {
00183   return findAverageGlobalPosition( stub->getClusterPtr(0).get() );
00184 }
00185 
00186 template< typename T >
00187 GlobalVector StackedTrackerGeometry::findGlobalDirection( const L1TkStub< T > *stub ) const
00188 {
00190   GlobalPoint innerHitPosition = findAverageGlobalPosition( stub->getClusterPtr(0).get() );
00191   GlobalPoint outerHitPosition = findAverageGlobalPosition( stub->getClusterPtr(1).get() );
00192 
00194   GlobalVector directionVector( outerHitPosition.x()-innerHitPosition.x(),
00195                                 outerHitPosition.y()-innerHitPosition.y(),
00196                                 outerHitPosition.z()-innerHitPosition.z() );
00197 
00198   return directionVector;
00199 }
00200 
00203   template< typename T >
00204   LocalPoint StackedTrackerGeometry::findHitLocalPosition( const L1TkCluster< T > *cluster, unsigned int hitIdx ) const
00205 {
00207   const GeomDetUnit* geomDetUnit = idToDetUnit( cluster->getDetId(), cluster->getStackMember() );
00208   T hit=cluster->getHits().at(hitIdx); 
00209   MeasurementPoint mp( hit->row() + 0.5, hit->column() + 0.5 );
00210   return geomDetUnit->topology().localPosition( mp );
00211 }
00212 
00215   template< typename T >
00216   GlobalPoint StackedTrackerGeometry::findHitGlobalPosition( const L1TkCluster< T > *cluster, unsigned int hitIdx ) const
00217 {
00219   const GeomDetUnit* geomDetUnit = idToDetUnit( cluster->getDetId(), cluster->getStackMember() );
00220   T hit=cluster->getHits().at(hitIdx); 
00221   MeasurementPoint mp( hit->row() + 0.5, hit->column() + 0.5 );
00222   return geomDetUnit->surface().toGlobal( geomDetUnit->topology().localPosition( mp ) );
00223 }
00224 
00226 template< typename T >
00227 LocalPoint StackedTrackerGeometry::findAverageLocalPosition( const L1TkCluster< T > *cluster ) const
00228 {
00229   double averageX = 0.0;
00230   double averageY = 0.0;
00231 
00233   std::vector<T> hits=cluster->getHits();
00234 
00235   if ( hits.size() != 0 )
00236     {
00237       for ( unsigned int i = 0; i < hits.size(); i++ )
00238         {
00239           LocalPoint thisHitPosition = findHitLocalPosition( cluster, i );
00240           averageX += thisHitPosition.x();
00241           averageY += thisHitPosition.y();
00242         }
00243       averageX /= hits.size();
00244       averageY /= hits.size();
00245     }
00246   return LocalPoint( averageX, averageY );
00247 }
00248 
00250 template< typename T >
00251 GlobalPoint StackedTrackerGeometry::findAverageGlobalPosition( const L1TkCluster< T > *cluster ) const
00252 {
00253   double averageX = 0.0;
00254   double averageY = 0.0;
00255   double averageZ = 0.0;
00256 
00257   std::vector<T> hits=cluster->getHits();
00258 
00260   if ( hits.size() != 0 )
00261     {
00262       for ( unsigned int i = 0; i < hits.size(); i++ )
00263         {
00264           GlobalPoint thisHitPosition = findHitGlobalPosition( cluster, i );
00265           averageX += thisHitPosition.x();
00266           averageY += thisHitPosition.y();
00267           averageZ += thisHitPosition.z();
00268         }
00269       averageX /= hits.size();
00270       averageY /= hits.size();
00271       averageZ /= hits.size();
00272     }
00273   return GlobalPoint( averageX, averageY, averageZ );
00274 }
00275 
00276 template< typename T >
00277 void StackedTrackerGeometry::checkSimTrack( L1TkCluster< T > *cluster,
00278                                             edm::Handle<edm::DetSetVector<PixelDigiSimLink> >  thePixelDigiSimLinkHandle,
00279                                             edm::Handle<edm::SimTrackContainer>   simTrackHandle ) const
00280 {
00282 
00284   const DetId detId = idToDet( cluster->getDetId(), cluster->getStackMember() )->geographicalId();
00285   edm::DetSet<PixelDigiSimLink> thisDigiSimLink = (*(thePixelDigiSimLinkHandle) )[detId.rawId()];
00286   edm::DetSet<PixelDigiSimLink>::const_iterator iterSimLink;
00287 
00288   std::vector<T> hits=cluster->getHits(); 
00290   for ( unsigned int i = 0; i < hits.size(); i++ )
00291     {
00293       for ( iterSimLink = thisDigiSimLink.data.begin();
00294             iterSimLink != thisDigiSimLink.data.end();
00295             iterSimLink++ )
00296         {
00298           //if ( theHit.adc() <= 30 ) continue;
00300           if ( (int)iterSimLink->channel() != hits.at(i)->channel() ) continue;
00301 
00303           unsigned int curSimTrkId = iterSimLink->SimTrackId();
00308           bool foundSimTrack = false;
00309           for ( unsigned int j = 0; j < simTrackHandle->size() && !foundSimTrack; j++ )
00310             {
00311               if ( simTrackHandle->at(j).trackId() == curSimTrkId )
00312                 {
00313                   foundSimTrack = true;
00314                   edm::Ptr< SimTrack > testSimTrack( simTrackHandle, j );
00315                   cluster->addSimTrack( testSimTrack );
00316                 }
00317             }
00318 
00319           if ( !foundSimTrack )
00320             {
00321               edm::Ptr< SimTrack > testSimTrack;
00322               cluster->addSimTrack( testSimTrack );
00323             }
00324         }
00325     } 
00326 }
00327 
00328 
00329 
00330 #endif
00331