Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:02

0001 /** \file
0002  *
0003  *  \author G. Cerminara - INFN Torino
0004  */
0005 
0006 #include "DataFormats/DTRecHit/interface/DTRecHit1DPair.h"
0007 #include "DataFormats/DTDigi/interface/DTDigi.h"
0008 
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 
0011 using namespace DTEnums;
0012 using namespace std;
0013 
0014 // Constructor without components: must use setPos and Err!
0015 DTRecHit1DPair::DTRecHit1DPair(const DTWireId& wireId, const DTDigi& digi)
0016     : theLeftHit(wireId, Left, digi.time()), theRightHit(wireId, Right, digi.time()) {}
0017 
0018 // Default constructor
0019 DTRecHit1DPair::DTRecHit1DPair() : theLeftHit(), theRightHit() {}
0020 
0021 // Destructor
0022 DTRecHit1DPair::~DTRecHit1DPair() {}
0023 
0024 DTRecHit1DPair* DTRecHit1DPair::clone() const { return new DTRecHit1DPair(*this); }
0025 
0026 // Return the 3-dimensional local position.
0027 // The average theLeftHit/theRightHit hits position, namely the wire position
0028 // is returned.
0029 LocalPoint DTRecHit1DPair::localPosition() const {
0030   return theLeftHit.localPosition() + (theRightHit.localPosition() - theLeftHit.localPosition()) / 2.;
0031 }
0032 
0033 // Return the 3-dimensional error on the local position.
0034 // The error is defiened as half
0035 // the distance between theLeftHit and theRightHit pos
0036 LocalError DTRecHit1DPair::localPositionError() const {
0037   return LocalError((theRightHit.localPosition().x() - theLeftHit.localPosition().x()) / 2., 0., 0.);
0038 }
0039 
0040 // Access to component RecHits.
0041 vector<const TrackingRecHit*> DTRecHit1DPair::recHits() const {
0042   vector<const TrackingRecHit*> result;
0043   result.push_back(componentRecHit(Left));
0044   result.push_back(componentRecHit(Right));
0045   return result;
0046 }
0047 
0048 // Non-const access to component RecHits.
0049 vector<TrackingRecHit*> DTRecHit1DPair::recHits() {
0050   vector<TrackingRecHit*> result;
0051   result.push_back(componentRecHit(Left));
0052   result.push_back(componentRecHit(Right));
0053   return result;
0054 }
0055 
0056 // Return the detId of the Det (a DTLayer).
0057 DetId DTRecHit1DPair::geographicalId() const { return wireId().layerId(); }
0058 
0059 // Comparison operator, based on the wireId and the digi time
0060 bool DTRecHit1DPair::operator==(const DTRecHit1DPair& hit) const {
0061   return wireId() == hit.wireId() && fabs(digiTime() - hit.digiTime()) < 0.1;
0062 }
0063 
0064 // Return position in the local (layer) coordinate system for a
0065 // certain hypothesis about the L/R cell side
0066 LocalPoint DTRecHit1DPair::localPosition(DTCellSide lrside) const { return componentRecHit(lrside)->localPosition(); }
0067 
0068 // Return position error in the local (layer) coordinate system for a
0069 // certain hypothesis about the L/R cell side
0070 LocalError DTRecHit1DPair::localPositionError(DTCellSide lrside) const {
0071   return componentRecHit(lrside)->localPositionError();
0072 }
0073 
0074 // Set the 3-dimensional local position for the component hit
0075 // corresponding to the given cell side. Default value is assumed for the error.
0076 void DTRecHit1DPair::setPosition(DTCellSide lrside, const LocalPoint& point) {
0077   if (lrside != undefLR)
0078     componentRecHit(lrside)->setPosition(point);
0079   else
0080     throw cms::Exception("DTRecHit1DPair::setPosition with undefined LR");
0081 }
0082 
0083 // Set the 3-dimensional local position and error for the component hit
0084 // corresponding to the given cell side. Default value is assumed for the error.
0085 void DTRecHit1DPair::setPositionAndError(DTCellSide lrside, const LocalPoint& point, const LocalError& err) {
0086   if (lrside != undefLR) {
0087     componentRecHit(lrside)->setPosition(point);
0088     componentRecHit(lrside)->setError(err);
0089   } else
0090     throw cms::Exception("DTRecHit1DPair::setPosition with undefined LR");
0091 }
0092 
0093 // Return the left/right DTRecHit1D
0094 const DTRecHit1D* DTRecHit1DPair::componentRecHit(DTCellSide lrSide) const {
0095   if (lrSide == Left) {
0096     return &theLeftHit;
0097   } else if (lrSide == Right) {
0098     return &theRightHit;
0099   } else {
0100     throw cms::Exception("DTRecHit1DPair::recHit with undefined LR");
0101   }
0102 }
0103 
0104 // Non const access to left/right DTRecHit1D
0105 DTRecHit1D* DTRecHit1DPair::componentRecHit(DTCellSide lrSide) {
0106   if (lrSide == Left) {
0107     return &theLeftHit;
0108   } else if (lrSide == Right) {
0109     return &theRightHit;
0110   } else {
0111     throw cms::Exception("DTRecHit1DPair::recHit with undefined LR");
0112   }
0113 }
0114 
0115 /// Get the left and right 1D rechits (first and second respectively).
0116 pair<const DTRecHit1D*, const DTRecHit1D*> DTRecHit1DPair::componentRecHits() const {
0117   return make_pair(componentRecHit(Left), componentRecHit(Right));
0118 }
0119 
0120 // Ostream operator
0121 ostream& operator<<(ostream& os, const DTRecHit1DPair& hit) {
0122   os << "Pos: " << hit.localPosition();
0123   return os;
0124 }