CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/Geometry/TrackerGeometryBuilder/src/StackedTrackerGeometry.cc

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #include "Geometry/TrackerGeometryBuilder/interface/StackedTrackerGeometry.h"
00009 #include "Geometry/TrackerGeometryBuilder/interface/StackedTrackerDetUnit.h"
00010 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00011 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00012 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00013 
00014 StackedTrackerGeometry::StackedTrackerGeometry( const TrackerGeometry *i ) : theTracker(i) {}
00015 StackedTrackerGeometry::~StackedTrackerGeometry() {}
00016 
00017 const StackedTrackerGeometry::StackContainer& StackedTrackerGeometry::stacks() const
00018 {
00019   return theStacks;
00020 }
00021 
00022 const StackedTrackerGeometry::StackIdContainer& StackedTrackerGeometry::stackIds() const
00023 {
00024   return theStackIds;
00025 }
00026 
00027 void StackedTrackerGeometry::addStack(StackedTrackerDetUnit* aStack)
00028 {
00029   theStacks.push_back( aStack );
00030   theStackIds.push_back( aStack->Id() );
00031   theMap.insert( std::make_pair(aStack->Id(),aStack) );
00032 }
00033 
00034 const StackedTrackerDetUnit* StackedTrackerGeometry::idToStack( StackedTrackerDetId anId ) const
00035 {
00036   if ( theMap.find(anId) != theMap.end() )
00037   {
00038     return theMap.find(anId)->second;
00039   }
00040   return NULL;
00041 }
00042 
00045 const GeomDetUnit* StackedTrackerGeometry::idToDetUnit( StackedTrackerDetId anId , 
00046                                                         unsigned int stackMemberIdentifier ) const
00047 {
00048   if ( const StackedTrackerDetUnit* temp=(this->idToStack(anId)) )
00049   {
00050     return theTracker->idToDetUnit( temp->stackMember(stackMemberIdentifier) );
00051   }
00052   return NULL;
00053 }
00054 
00055 const GeomDet* StackedTrackerGeometry::idToDet( StackedTrackerDetId anId , 
00056                                                 unsigned int stackMemberIdentifier ) const
00057   {
00058   if ( const StackedTrackerDetUnit* temp=(this->idToStack(anId)) )
00059   {
00060     return theTracker->idToDet( temp->stackMember(stackMemberIdentifier) );
00061   }
00062   return NULL;
00063 }
00064 
00065 Plane::PlanePointer StackedTrackerGeometry::meanPlane( StackedTrackerDetId anId ) const
00066 {
00067   double x = 0.0,  y = 0.0,  z = 0.0;
00068   double xx = 0.0, xy = 0.0, xz = 0.0, yx = 0.0, yy = 0.0, yz = 0.0, zx = 0.0, zy = 0.0, zz = 0.0;
00069 
00070   const StackedTrackerDetUnit* theStack = this->idToStack( anId );
00071 
00072   if ( theStack == NULL )
00073   {
00074     return NULL;
00075   }
00076   else
00077   {
00078     for ( StackedTrackerDetUnit::StackContentsIterator i = theStack->theStackMembers().begin();
00079           i != theStack->theStackMembers().end();
00080           ++i )
00081     {
00082       Surface::RotationType rot = theTracker->idToDet(i->second)->rotation();
00083       Surface::PositionType pos = theTracker->idToDet(i->second)->position();
00084 
00085       x  += pos.x();
00086       y  += pos.y();
00087       z  += pos.z();
00088       xx += rot.xx();
00089       xy += rot.xy();
00090       xz += rot.xz();
00091       yx += rot.yx();
00092       yy += rot.yy();
00093       yz += rot.yz();
00094       zx += rot.zx();
00095       zy += rot.zy();
00096       zz += rot.zz();
00097     }
00098 
00099     float sizeInv = 1.0/theStack->theStackMembers().size();
00100     x  *= sizeInv;
00101     y  *= sizeInv;
00102     z  *= sizeInv;
00103     xx *= sizeInv;
00104     xy *= sizeInv;
00105     xz *= sizeInv;
00106     yx *= sizeInv;
00107     yy *= sizeInv;
00108     yz *= sizeInv;
00109     zx *= sizeInv;
00110     zy *= sizeInv;
00111     zz *= sizeInv;
00112 
00113     Surface::PositionType meanPos( x , y , z );
00114     Surface::RotationType meanRot( xx , xy , xz , yx , yy , yz , zx , zy , zz );
00115 
00116     return Plane::build( meanPos, meanRot );
00117   }
00118 }
00119 
00120   template<>
00121   LocalPoint StackedTrackerGeometry::findHitLocalPosition( const L1TkCluster< edm::Ref< edm::PSimHitContainer > > *cluster,
00122                                                            unsigned int hitIdx ) const
00123 {
00124   return cluster->getHits().at(hitIdx)->localPosition();
00125 }
00126 
00130   template<>
00131   GlobalPoint StackedTrackerGeometry::findHitGlobalPosition( const L1TkCluster< edm::Ref< edm::PSimHitContainer > > *cluster,
00132                                                              unsigned int hitIdx ) const
00133 {
00134   const GeomDetUnit* geomDetUnit = idToDetUnit( cluster->getDetId(), cluster->getStackMember() );
00135   return geomDetUnit->surface().toGlobal( cluster->getHits().at(hitIdx)->localPosition() );
00136 }
00137 
00141 template<>
00142 void StackedTrackerGeometry::checkSimTrack( L1TkCluster< edm::Ref< edm::PSimHitContainer > > *cluster,
00143                                             edm::Handle<edm::DetSetVector<PixelDigiSimLink> >  thePixelDigiSimLinkHandle,
00144                                             edm::Handle<edm::SimTrackContainer>   simTrackHandle ) const
00145 {
00147   std::vector< edm::Ref< edm::PSimHitContainer > > hits=cluster->getHits();
00148   for ( unsigned int i = 0; i < hits.size(); i++ ) {
00149 
00151     unsigned int curSimTrkId = hits.at(i)->trackId();
00152 
00157     bool foundSimTrack = false;
00158     for ( unsigned int j = 0; j < simTrackHandle->size() && !foundSimTrack; j++ )
00159       {
00160         if ( simTrackHandle->at(j).trackId() == curSimTrkId )
00161           {
00162             foundSimTrack = true;
00163             edm::Ptr< SimTrack > testSimTrack( simTrackHandle, j );
00164             cluster->addSimTrack( testSimTrack );
00165           }
00166       }
00167     if ( !foundSimTrack )
00168       {
00169         edm::Ptr< SimTrack > testSimTrack;
00170         cluster->addSimTrack( testSimTrack );
00171       }
00172   } 
00173 }
00174 
00175 
00176