CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/TrackingTools/TrackAssociator/src/MuonDetIdAssociator.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    TrackAssociator
00004 // Class:      MuonDetIdAssociator
00005 // 
00006 /*
00007 
00008  Description: <one line class summary>
00009 
00010  Implementation:
00011      <Notes on implementation>
00012 */
00013 //
00014 // Original Author:  Dmytro Kovalskyi
00015 //         Created:  Fri Apr 21 10:59:41 PDT 2006
00016 // $Id: MuonDetIdAssociator.cc,v 1.13 2010/02/18 14:35:48 dmytro Exp $
00017 //
00018 //
00019 
00020 
00021 #include "TrackingTools/TrackAssociator/interface/MuonDetIdAssociator.h"
00022 // #include "Utilities/Timing/interface/TimerStack.h"
00023 #include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
00024 #include "DataFormats/GeometrySurface/interface/Plane.h"
00025 #include "Geometry/DTGeometry/interface/DTChamber.h"
00026 #include "Geometry/CSCGeometry/interface/CSCChamber.h"
00027 #include <deque>
00028 
00029 void MuonDetIdAssociator::check_setup() const {
00030    if (geometry_==0) throw cms::Exception("ConfigurationProblem") << "GlobalTrackingGeomtry is not set\n";
00031    if (cscbadchambers_==0) throw cms::Exception("ConfigurationProblem") << "CSCBadChambers is not set\n";
00032    DetIdAssociator::check_setup();
00033 }
00034 
00035 const GeomDet* MuonDetIdAssociator::getGeomDet( const DetId& id ) const
00036 {
00037    if (geometry_==0) throw cms::Exception("ConfigurationProblem") << "GlobalTrackingGeomtry is not set\n";
00038    const GeomDet* gd = geometry_->idToDet(id);
00039    if (gd == 0) throw cms::Exception("NoGeometry") << "Cannot find GeomDet for DetID: " << id.rawId() <<"\n";
00040    return gd;
00041 }
00042 
00043 
00044 GlobalPoint MuonDetIdAssociator::getPosition(const DetId& id) const {
00045    Surface::PositionType point(getGeomDet(id)->surface().position());
00046    return GlobalPoint(point.x(),point.y(),point.z());
00047 }
00048 
00049 const std::vector<DetId>& MuonDetIdAssociator::getValidDetIds(unsigned int subDectorIndex) const {
00050   validIds_.clear();
00051   if (geometry_==0) throw cms::Exception("ConfigurationProblem") << "GlobalTrackingGeomtry is not set\n";
00052   if (subDectorIndex!=0) throw cms::Exception("FatalError") << 
00053     "Muon sub-dectors are all handle as one sub-system, but subDetectorIndex is not zero.\n";
00054 
00055   // CSC 
00056   if (! geometry_->slaveGeometry(CSCDetId()) ) throw cms::Exception("FatalError") << "Cannnot CSCGeometry\n";
00057   const std::vector<GeomDet*>& geomDetsCSC = geometry_->slaveGeometry(CSCDetId())->dets();
00058   for(std::vector<GeomDet*>::const_iterator it = geomDetsCSC.begin(); it != geomDetsCSC.end(); ++it)
00059     if (CSCChamber* csc = dynamic_cast< CSCChamber*>(*it)) {
00060       if ((! includeBadChambers_) && (cscbadchambers_->isInBadChamber(CSCDetId(csc->id())))) continue;
00061       validIds_.push_back(csc->id());
00062     }
00063   
00064   // DT
00065   if (! geometry_->slaveGeometry(DTChamberId()) ) throw cms::Exception("FatalError") << "Cannnot DTGeometry\n";
00066   const std::vector<GeomDet*>& geomDetsDT = geometry_->slaveGeometry(DTChamberId())->dets();
00067   for(std::vector<GeomDet*>::const_iterator it = geomDetsDT.begin(); it != geomDetsDT.end(); ++it)
00068     if (DTChamber* dt = dynamic_cast< DTChamber*>(*it)) validIds_.push_back(dt->id());
00069 
00070   return validIds_;
00071 }
00072 
00073 bool MuonDetIdAssociator::insideElement(const GlobalPoint& point, const DetId& id) const {
00074    if (geometry_==0) throw cms::Exception("ConfigurationProblem") << "GlobalTrackingGeomtry is not set\n";
00075    LocalPoint lp = geometry_->idToDet(id)->toLocal(point);
00076    return geometry_->idToDet(id)->surface().bounds().inside(lp);
00077 }
00078 
00079 std::pair<DetIdAssociator::const_iterator,DetIdAssociator::const_iterator> 
00080 MuonDetIdAssociator::getDetIdPoints(const DetId& id) const 
00081 {
00082    points_.clear();
00083    const GeomDet* geomDet = getGeomDet( id );
00084    
00085    // the coners of muon detector elements are not stored and can be only calculated
00086    // based on methods defined in the interface class Bounds:
00087    //   width() - x
00088    //   length() - y 
00089    //   thinkness() - z
00090    // NOTE: this convention is implementation specific and can fail. Both
00091    //       RectangularPlaneBounds and TrapezoidalPlaneBounds use it.
00092    // Even though the CSC geomtry is more complicated (trapezoid),  it's enough 
00093    // to estimate which bins should contain this element. For the distance
00094    // calculation from the edge, we will use exact geometry to get it right.
00095             
00096    const Bounds* bounds = &(geometry_->idToDet(id)->surface().bounds());
00097    points_.push_back(geomDet->toGlobal(LocalPoint(+bounds->width()/2,+bounds->length()/2,+bounds->thickness()/2)));
00098    points_.push_back(geomDet->toGlobal(LocalPoint(-bounds->width()/2,+bounds->length()/2,+bounds->thickness()/2)));
00099    points_.push_back(geomDet->toGlobal(LocalPoint(+bounds->width()/2,-bounds->length()/2,+bounds->thickness()/2)));
00100    points_.push_back(geomDet->toGlobal(LocalPoint(-bounds->width()/2,-bounds->length()/2,+bounds->thickness()/2)));
00101    points_.push_back(geomDet->toGlobal(LocalPoint(+bounds->width()/2,+bounds->length()/2,-bounds->thickness()/2)));
00102    points_.push_back(geomDet->toGlobal(LocalPoint(-bounds->width()/2,+bounds->length()/2,-bounds->thickness()/2)));
00103    points_.push_back(geomDet->toGlobal(LocalPoint(+bounds->width()/2,-bounds->length()/2,-bounds->thickness()/2)));
00104    points_.push_back(geomDet->toGlobal(LocalPoint(-bounds->width()/2,-bounds->length()/2,-bounds->thickness()/2)));
00105    
00106    return std::pair<const_iterator,const_iterator>(points_.begin(),points_.end());
00107 }
00108 
00109 void MuonDetIdAssociator::setGeometry(const DetIdAssociatorRecord& iRecord)
00110 {
00111   edm::ESHandle<GlobalTrackingGeometry> geometryH;
00112   iRecord.getRecord<GlobalTrackingGeometryRecord>().get(geometryH);
00113   setGeometry(geometryH.product());
00114 }