CMS 3D CMS Logo

VisLocalPosition.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "VisReco/Analyzer/interface/VisLocalPosition.h"
00004 #include "DataFormats/DetId/interface/DetId.h"
00005 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
00006 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00007 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00008 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00009 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00010 #include "Iguana/Utilities/classlib/utils/DebugAids.h"
00011 
00012 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00013 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00014 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00015 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00016 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00017 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00018 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00019 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00020 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00021 
00022 LocalPoint 
00023 VisLocalPosition::localPosition(const TrackingRecHit * rechit , const TrackingGeometry * geometry)
00024 {
00025     if (rechit->geographicalId().det() == DetId::Tracker)
00026     {
00027         std::vector<LocalPoint> points;
00028         localPositions(rechit,geometry,points);
00029         if (points.size()==1)
00030             return points.front();
00031         else
00032         {
00033             //this is not really nice, but that's all we can do there.
00034             const SiStripMatchedRecHit2D* matched = dynamic_cast<const SiStripMatchedRecHit2D*>(rechit);
00035             if (matched)
00036             {
00037                 GlobalPoint pos_1 = geometry->idToDetUnit(matched->monoHit()->geographicalId())->surface().toGlobal(points[0]);
00038                 GlobalPoint pos_2 = geometry->idToDetUnit(matched->stereoHit()->geographicalId())->surface().toGlobal(points[1]);
00039                 GlobalPoint average((pos_1.x()+pos_2.x())/2,
00040                                     (pos_1.y()+pos_2.y())/2,
00041                                     (pos_1.z()+pos_2.z())/2);      
00042                 return geometry->idToDet(rechit->geographicalId())->surface().toLocal(average);
00043             }
00044             else return LocalPoint();
00045         }
00046     }
00047     else
00048     {
00049         return rechit->localPosition();
00050     }
00051 }
00052 
00053 void  
00054 VisLocalPosition::localPositions(const TrackingRecHit* rechit, const TrackingGeometry* geometry, std::vector<LocalPoint>& points)
00055 {
00056     if (rechit->geographicalId().det() == DetId::Tracker)
00057     {
00058         const RecHit2DLocalPos* rechit2D = dynamic_cast<const RecHit2DLocalPos*>(rechit);
00059         const SiStripRecHit2D* single = dynamic_cast<const SiStripRecHit2D*>(rechit);
00060         //matched or single rechits
00061         if (single)
00062         {
00063             DetId detectorId = rechit2D->geographicalId();
00064      
00065             const SiStripCluster* Cluster = 0;
00066             if (single->cluster().isNonnull())
00067                 Cluster = single->cluster().get();
00068             else if (single->cluster_regional().isNonnull())
00069                 Cluster = single->cluster_regional().get();
00070             else points.push_back(LocalPoint());
00071             const StripTopology* topology = dynamic_cast<const StripTopology*>(&(geometry->idToDetUnit(detectorId)->topology()));
00072             ASSERT(topology);
00073                          
00074             points.push_back(topology->localPosition(Cluster->barycenter()));
00075         }
00076         else
00077         {
00078             const SiStripMatchedRecHit2D* matched = dynamic_cast<const SiStripMatchedRecHit2D*>(rechit);
00079             if (matched)
00080             {
00081                 localPositions(matched->monoHit(),geometry,points);
00082                 localPositions(matched->stereoHit(),geometry,points);
00083             }
00084         }
00085     }   
00086     else
00087     {
00088         points.push_back(rechit->localPosition());
00089     }
00090 }

Generated on Tue Jun 9 17:50:08 2009 for CMSSW by  doxygen 1.5.4