CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DataFormats/DTRecHit/src/DTRecHit1DPair.cc

Go to the documentation of this file.
00001 
00008 #include "DataFormats/DTRecHit/interface/DTRecHit1DPair.h"
00009 #include "DataFormats/DTDigi/interface/DTDigi.h"
00010 
00011 #include "FWCore/Utilities/interface/Exception.h"
00012 
00013 
00014 using namespace DTEnums;
00015 using namespace std;
00016 
00017 
00018 
00019 // Constructor without components: must use setPos and Err!
00020 DTRecHit1DPair::DTRecHit1DPair(const DTWireId& wireId,
00021                                const DTDigi& digi) : theLeftHit(wireId, Left, digi.time()),
00022                                                      theRightHit(wireId, Right, digi.time()) {}
00023 
00024 
00025 // Default constructor
00026 DTRecHit1DPair::DTRecHit1DPair() : theLeftHit(),
00027                                    theRightHit() {}
00028 
00029 
00030 // Destructor
00031 DTRecHit1DPair::~DTRecHit1DPair(){}
00032 
00033 
00034 
00035 DTRecHit1DPair * DTRecHit1DPair::clone() const {
00036   return new DTRecHit1DPair(*this);
00037 }
00038 
00039 
00040 
00041 // Return the 3-dimensional local position.
00042 // The average theLeftHit/theRightHit hits position, namely the wire position
00043 // is returned.
00044 LocalPoint DTRecHit1DPair::localPosition() const {
00045   return theLeftHit.localPosition() + 
00046     (theRightHit.localPosition()-theLeftHit.localPosition())/2.;
00047 }
00048 
00049 
00050 
00051 // Return the 3-dimensional error on the local position. 
00052 // The error is defiened as half
00053 // the distance between theLeftHit and theRightHit pos
00054 LocalError DTRecHit1DPair::localPositionError() const {
00055   return LocalError((theRightHit.localPosition().x()-
00056                      theLeftHit.localPosition().x())/2.,0.,0.);
00057 }
00058 
00059 
00060 
00061 // Access to component RecHits.
00062 vector<const TrackingRecHit*> DTRecHit1DPair::recHits() const {
00063   vector<const TrackingRecHit*> result;
00064   result.push_back(componentRecHit(Left));
00065   result.push_back(componentRecHit(Right));
00066   return result;
00067 }
00068 
00069 
00070 
00071 // Non-const access to component RecHits.
00072 vector<TrackingRecHit*> DTRecHit1DPair::recHits() {
00073   vector<TrackingRecHit*> result;
00074   result.push_back(const_cast<DTRecHit1D*>(componentRecHit(Left)));
00075   result.push_back(const_cast<DTRecHit1D*>(componentRecHit(Right)));
00076   return result;
00077 }
00078 
00079 
00080 
00081 // Return the detId of the Det (a DTLayer).
00082 DetId DTRecHit1DPair::geographicalId() const { 
00083   return wireId().layerId();
00084 }
00085 
00086 
00087   
00088 // Comparison operator, based on the wireId and the digi time
00089 bool DTRecHit1DPair::operator==(const DTRecHit1DPair& hit) const {
00090   return wireId() == hit.wireId() && fabs(digiTime() - hit.digiTime()) < 0.1;
00091 }
00092 
00093 
00094 
00095 // Return position in the local (layer) coordinate system for a
00096 // certain hypothesis about the L/R cell side
00097 LocalPoint DTRecHit1DPair::localPosition(DTCellSide lrside) const {
00098   return componentRecHit(lrside)->localPosition();
00099 }
00100 
00101 
00102 
00103 // Return position error in the local (layer) coordinate system for a
00104  // certain hypothesis about the L/R cell side
00105  LocalError DTRecHit1DPair::localPositionError(DTCellSide lrside) const {
00106    return componentRecHit(lrside)->localPositionError();
00107 }
00108 
00109 
00110 
00111 // Set the 3-dimensional local position for the component hit
00112 // corresponding to the given cell side. Default value is assumed for the error.
00113 void DTRecHit1DPair::setPosition(DTCellSide lrside, const LocalPoint& point) {
00114   if(lrside != undefLR) 
00115     componentRecHit(lrside)->setPosition(point);
00116   else throw cms::Exception("DTRecHit1DPair::setPosition with undefined LR");
00117 }
00118 
00119 
00120 
00121 // Set the 3-dimensional local position and error for the component hit
00122 // corresponding to the given cell side. Default value is assumed for the error.
00123 void DTRecHit1DPair::setPositionAndError(DTCellSide lrside,
00124                                          const LocalPoint& point, 
00125                                          const LocalError& err) {
00126   if(lrside != undefLR) {
00127     componentRecHit(lrside)->setPosition(point);
00128     componentRecHit(lrside)->setError(err);
00129      }
00130   else throw cms::Exception("DTRecHit1DPair::setPosition with undefined LR");
00131 }
00132 
00133 
00134 
00135 // Return the left/right DTRecHit1D
00136 const DTRecHit1D* DTRecHit1DPair::componentRecHit(DTCellSide lrSide) const {
00137   if(lrSide == Left) {
00138     return const_cast<const DTRecHit1D*>(&theLeftHit);
00139   } else if(lrSide == Right) {
00140     return const_cast<const DTRecHit1D*>(&theRightHit);
00141   } else {
00142     throw cms::Exception("DTRecHit1DPair::recHit with undefined LR");
00143   }
00144 }
00145 
00146 
00147   
00148 // Non const access to left/right DTRecHit1D
00149 DTRecHit1D* DTRecHit1DPair::componentRecHit(DTCellSide lrSide) {
00150   if(lrSide == Left) {
00151     return &theLeftHit;
00152   } else if(lrSide == Right) {
00153     return &theRightHit;
00154   } else {
00155     throw cms::Exception("DTRecHit1DPair::recHit with undefined LR");
00156   }
00157 }
00158 
00159 
00160 
00162 pair<const DTRecHit1D*, const DTRecHit1D*> DTRecHit1DPair::componentRecHits() const {
00163   return make_pair(componentRecHit(Left), componentRecHit(Right));
00164 }
00165 
00166 
00167 
00168 // Ostream operator
00169 ostream& operator<<(ostream& os, const DTRecHit1DPair& hit) {
00170   os << "Pos: " << hit.localPosition() ;
00171   return os;
00172 }