Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /** \file ME0egment.cc
0002  *
0003  *  $Date: 2014/02/04 12:41:33 $
0004  *  \author Marcello Maggi
0005  */
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "DataFormats/GEMRecHit/interface/ME0Segment.h"
0008 #include <iostream>
0009 
0010 namespace {
0011   // define a Super Layer Id from the first layer of the first rechits, and put to first layer
0012   inline DetId buildDetId(ME0DetId id) { return ME0DetId(id.chamberId()); }
0013 }  // namespace
0014 
0015 class ProjectionMatrixDiag {
0016   // Aider class to make the return of the projection Matrix thread-safe
0017 protected:
0018   AlgebraicMatrix theProjectionMatrix;
0019 
0020 public:
0021   ProjectionMatrixDiag() : theProjectionMatrix(4, 5, 0) {
0022     theProjectionMatrix[0][1] = 1;
0023     theProjectionMatrix[1][2] = 1;
0024     theProjectionMatrix[2][3] = 1;
0025     theProjectionMatrix[3][4] = 1;
0026   }
0027   const AlgebraicMatrix& getMatrix() const { return (theProjectionMatrix); }
0028 };
0029 
0030 ME0Segment::ME0Segment(const std::vector<const ME0RecHit*>& proto_segment,
0031                        const LocalPoint& origin,
0032                        const LocalVector& direction,
0033                        const AlgebraicSymMatrix& errors,
0034                        float chi2)
0035     : RecSegment(buildDetId(proto_segment.front()->me0Id())),
0036       theOrigin(origin),
0037       theLocalDirection(direction),
0038       theCovMatrix(errors),
0039       theChi2(chi2),
0040       theTimeValue(0.),
0041       theTimeUncrt(0.),
0042       theDeltaPhi(0.) {
0043   for (const auto* rh : proto_segment)
0044     theME0RecHits.push_back(*rh);
0045 }
0046 
0047 ME0Segment::ME0Segment(const std::vector<const ME0RecHit*>& proto_segment,
0048                        const LocalPoint& origin,
0049                        const LocalVector& direction,
0050                        const AlgebraicSymMatrix& errors,
0051                        float chi2,
0052                        float time,
0053                        float timeErr,
0054                        float deltaPhi)
0055     : RecSegment(buildDetId(proto_segment.front()->me0Id())),
0056       theOrigin(origin),
0057       theLocalDirection(direction),
0058       theCovMatrix(errors),
0059       theChi2(chi2),
0060       theTimeValue(time),
0061       theTimeUncrt(timeErr),
0062       theDeltaPhi(deltaPhi) {
0063   for (const auto* rh : proto_segment)
0064     theME0RecHits.push_back(*rh);
0065 }
0066 
0067 ME0Segment::~ME0Segment() {}
0068 
0069 std::vector<const TrackingRecHit*> ME0Segment::recHits() const {
0070   std::vector<const TrackingRecHit*> pointersOfRecHits;
0071   pointersOfRecHits.reserve(theME0RecHits.size());
0072   for (const auto& rh : theME0RecHits)
0073     pointersOfRecHits.push_back(&rh);
0074   return pointersOfRecHits;
0075 }
0076 
0077 std::vector<TrackingRecHit*> ME0Segment::recHits() {
0078   std::vector<TrackingRecHit*> pointersOfRecHits;
0079   pointersOfRecHits.reserve(theME0RecHits.size());
0080   for (auto& rh : theME0RecHits)
0081     pointersOfRecHits.push_back(&rh);
0082   return pointersOfRecHits;
0083 }
0084 
0085 LocalError ME0Segment::localPositionError() const {
0086   return LocalError(theCovMatrix[2][2], theCovMatrix[2][3], theCovMatrix[3][3]);
0087 }
0088 
0089 LocalError ME0Segment::localDirectionError() const {
0090   return LocalError(theCovMatrix[0][0], theCovMatrix[0][1], theCovMatrix[1][1]);
0091 }
0092 
0093 AlgebraicVector ME0Segment::parameters() const {
0094   // For consistency with DT and CSC  and what we require for the TrackingRecHit interface,
0095   // the order of the parameters in the returned vector should be (dx/dz, dy/dz, x, z)
0096 
0097   AlgebraicVector result(4);
0098 
0099   if (theLocalDirection.z() != 0) {
0100     result[0] = theLocalDirection.x() / theLocalDirection.z();
0101     result[1] = theLocalDirection.y() / theLocalDirection.z();
0102   }
0103   result[2] = theOrigin.x();
0104   result[3] = theOrigin.y();
0105 
0106   return result;
0107 }
0108 
0109 AlgebraicMatrix ME0Segment::projectionMatrix() const {
0110   static const ProjectionMatrixDiag theProjectionMatrix;
0111   return (theProjectionMatrix.getMatrix());
0112 }
0113 
0114 //
0115 void ME0Segment::print() const { LogDebug("ME0Segment") << *this; }
0116 
0117 std::ostream& operator<<(std::ostream& os, const ME0Segment& seg) {
0118   os << "ME0Segment: local pos = " << seg.localPosition() << " posErr = (" << sqrt(seg.localPositionError().xx()) << ","
0119      << sqrt(seg.localPositionError().yy()) << "0,)\n"
0120      << "            dir = " << seg.localDirection() << " dirErr = (" << sqrt(seg.localDirectionError().xx()) << ","
0121      << sqrt(seg.localDirectionError().yy()) << "0,)\n"
0122      << "            chi2/ndf = " << ((seg.degreesOfFreedom() != 0.) ? seg.chi2() / double(seg.degreesOfFreedom()) : 0)
0123      << " #rechits = " << seg.specificRecHits().size() << " time = " << seg.time() << " +/- " << seg.timeErr()
0124      << " ns ";
0125 
0126   return os;
0127 }