Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:29

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   for (const auto& rh : theME0RecHits)
0072     pointersOfRecHits.push_back(&rh);
0073   return pointersOfRecHits;
0074 }
0075 
0076 std::vector<TrackingRecHit*> ME0Segment::recHits() {
0077   std::vector<TrackingRecHit*> pointersOfRecHits;
0078   for (auto& rh : theME0RecHits)
0079     pointersOfRecHits.push_back(&rh);
0080   return pointersOfRecHits;
0081 }
0082 
0083 LocalError ME0Segment::localPositionError() const {
0084   return LocalError(theCovMatrix[2][2], theCovMatrix[2][3], theCovMatrix[3][3]);
0085 }
0086 
0087 LocalError ME0Segment::localDirectionError() const {
0088   return LocalError(theCovMatrix[0][0], theCovMatrix[0][1], theCovMatrix[1][1]);
0089 }
0090 
0091 AlgebraicVector ME0Segment::parameters() const {
0092   // For consistency with DT and CSC  and what we require for the TrackingRecHit interface,
0093   // the order of the parameters in the returned vector should be (dx/dz, dy/dz, x, z)
0094 
0095   AlgebraicVector result(4);
0096 
0097   if (theLocalDirection.z() != 0) {
0098     result[0] = theLocalDirection.x() / theLocalDirection.z();
0099     result[1] = theLocalDirection.y() / theLocalDirection.z();
0100   }
0101   result[2] = theOrigin.x();
0102   result[3] = theOrigin.y();
0103 
0104   return result;
0105 }
0106 
0107 AlgebraicMatrix ME0Segment::projectionMatrix() const {
0108   static const ProjectionMatrixDiag theProjectionMatrix;
0109   return (theProjectionMatrix.getMatrix());
0110 }
0111 
0112 //
0113 void ME0Segment::print() const { LogDebug("ME0Segment") << *this; }
0114 
0115 std::ostream& operator<<(std::ostream& os, const ME0Segment& seg) {
0116   os << "ME0Segment: local pos = " << seg.localPosition() << " posErr = (" << sqrt(seg.localPositionError().xx()) << ","
0117      << sqrt(seg.localPositionError().yy()) << "0,)\n"
0118      << "            dir = " << seg.localDirection() << " dirErr = (" << sqrt(seg.localDirectionError().xx()) << ","
0119      << sqrt(seg.localDirectionError().yy()) << "0,)\n"
0120      << "            chi2/ndf = " << ((seg.degreesOfFreedom() != 0.) ? seg.chi2() / double(seg.degreesOfFreedom()) : 0)
0121      << " #rechits = " << seg.specificRecHits().size() << " time = " << seg.time() << " +/- " << seg.timeErr()
0122      << " ns ";
0123 
0124   return os;
0125 }