MuonSegment.cxx 6.42 KB
Newer Older
1
/*
2
  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3
4
5
6
*/

#include "MuonSegment/MuonSegment.h"
// TrkEvent
7
8
9
10
#include "CxxUtils/sincos.h"
#include "EventPrimitives/EventPrimitivesToStringConverter.h"
#include "GeoPrimitives/GeoPrimitivesToStringConverter.h"
#include "TrkEventPrimitives/DefinedParameter.h"
11
12
13
14
15
#include "TrkEventPrimitives/FitQuality.h"
#include "TrkEventPrimitives/LocalParameters.h"
#include "TrkEventPrimitives/ParamDefs.h"
#include "TrkRIO_OnTrack/RIO_OnTrack.h"

16
#include <cfloat>
17
18
19
20
#include <iostream>
namespace Muon {

const float MuonSegment::kNoValue = FLT_MAX;
21
22
23
24
25
26
27
28

MuonSegment::MuonSegment()
  : Segment()
  , SpaceTimePointBase(kNoValue, kNoValue, 1.)
  , Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>(nullptr)
  , m_globalPosition()
  , m_globalDirection()
  , m_localDirection()
29
{}
30
31
32
33
34
35
36
37

MuonSegment::MuonSegment(const MuonSegment& seg)
  : Segment(seg)
  , SpaceTimePointBase(seg)
  , Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>(nullptr)
  , m_globalPosition(seg.m_globalPosition)
  , m_globalDirection(seg.m_globalDirection)
  , m_localDirection(seg.m_localDirection)
38
{
39
40
41
  m_associatedSurface = (seg.m_associatedSurface->associatedDetectorElement())
                          ? seg.m_associatedSurface
                          : seg.m_associatedSurface->clone();
42
43
}

44
45
MuonSegment&
MuonSegment::operator=(const MuonSegment& seg)
46
{
47
48
49
50
51
52
53
54
55
  if (this != &seg) {
    Trk::Segment::operator=(seg);
    Trk::SpaceTimePointBase::operator=(seg);
    Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>::operator=(seg);
    m_globalPosition = seg.m_globalPosition;
    m_globalDirection = seg.m_globalDirection;
    m_localDirection = seg.m_localDirection;
  }
  return (*this);
56
57
}

58
59
60
61
62
63
64
65
66
67
68
69
MuonSegment::MuonSegment(const Trk::LocalParameters& locpars,
                         const Amg::MatrixX& locerr,
                         Trk::PlaneSurface* psf,
                         DataVector<const Trk::MeasurementBase>* cmeas,
                         Trk::FitQuality* fqual,
                         Segment::Author author)
  : Segment(locpars, locerr, cmeas, fqual, author)
  , SpaceTimePointBase(kNoValue, kNoValue, 1.)
  , Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>(psf)
  , m_globalPosition()
  , m_globalDirection()
  , m_localDirection()
70
71
{
  recalculateCache();
72
  psf->globalToLocalDirection(m_globalDirection, m_localDirection);
73
74
}

75
76
77
78
79
80
81
82
83
84
85
86
87
MuonSegment::MuonSegment(const Amg::Vector2D& locSegPos,
                         const Trk::LocalDirection& locSegDir,
                         const Amg::MatrixX& locErr,
                         Trk::PlaneSurface* psf,
                         DataVector<const Trk::MeasurementBase>* cmeas,
                         Trk::FitQuality* fqual,
                         Segment::Author author)
  : Segment(Trk::LocalParameters(), locErr, cmeas, fqual, author)
  , SpaceTimePointBase(kNoValue, kNoValue, 1.)
  , Trk::SurfacePtrHolderImplDetEl<Trk::PlaneSurface>(psf)
  , m_globalPosition()
  , m_globalDirection()
  , m_localDirection(locSegDir)
88
{
89
  psf->localToGlobalDirection(locSegDir, m_globalDirection);
90
91
92
93
94
95

  Amg::Vector2D lpos(locSegPos[Trk::locX], locSegPos[Trk::locY]);
  m_associatedSurface->localToGlobal(lpos, m_globalDirection, m_globalPosition);

  double phi = m_globalDirection.phi();
  double theta = m_globalDirection.theta();
96
97
98
99
100
101
  std::vector<Trk::DefinedParameter> pars;
  pars.emplace_back(locSegPos[Trk::locX], Trk::locX);
  pars.emplace_back(locSegPos[Trk::locY], Trk::locY);
  pars.emplace_back(phi, Trk::phi);
  pars.emplace_back(theta, Trk::theta);
  m_localParams = Trk::LocalParameters(pars);
102
103
}

104
MuonSegment::~MuonSegment() = default;
105

106
107
108
109
110
111
void
MuonSegment::recalculateCache()
{

  CxxUtils::sincos scphi(m_localParams[Trk::phi]);
  CxxUtils::sincos sctheta(m_localParams[Trk::theta]);
112

113
114
115
116
117
118
  double sintheta = sctheta.sn;
  double costheta = sctheta.cs;
  double sinphi = scphi.sn;
  double cosphi = scphi.cs;
  m_globalDirection =
    Amg::Vector3D(cosphi * sintheta, sinphi * sintheta, costheta);
119
120
121
122
  Amg::Vector2D lpos(m_localParams[Trk::locX], m_localParams[Trk::locY]);
  m_associatedSurface->localToGlobal(lpos, m_globalPosition, m_globalPosition);
}

123
124
MsgStream&
MuonSegment::dump(MsgStream& out) const
125
{
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
  out << "Muon::MuonSegment " << std::endl;
  out << "  - global position      : " << std::endl
      << Amg::toString(globalPosition()) << std::endl;
  out << std::endl << localDirection() << std::endl;
  out << "  - local parameters     : " << std::endl
      << localParameters() << std::endl;
  out << "  - local Err Matrix     : ";
  out << std::endl << Amg::toString(localCovariance()) << std::endl;
  if (nullptr != m_fitQuality)
    out << "  - fit Quality          : " << std::endl
        << (*fitQuality()) << std::endl;
  else
    out << "  - fit Quality          : NO " << std::endl;
  out << "  - associated Surface   : " << std::endl
      << associatedSurface() << std::endl;
  out << "  - t0 (error) : " << time() << "(" << errorTime() << ")"
      << std::endl;
  out << "  - it contains   : " << numberOfContainedROTs()
      << " RIO_OnTrack object" << std::endl;
  unsigned int numRoT = 1;
  for (const Trk::MeasurementBase* m : containedMeasurements()) {
    const Trk::RIO_OnTrack* rot = dynamic_cast<const Trk::RIO_OnTrack*>(m);
    if (rot) {
      out << "RoT " << numRoT++ << std::endl << *rot << std::endl;
150
    }
151
152
153
  }
  return out;
}
154

155
156
std::ostream&
MuonSegment::dump(std::ostream& out) const
157
{
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
  out << "Muon::MuonSegment " << std::endl;
  out << "  - global position      : " << std::endl
      << Amg::toString(globalPosition()) << std::endl;
  out << std::endl << localDirection() << std::endl;
  out << "  - local parameters     : " << std::endl
      << localParameters() << std::endl;
  out << "  - local Err Matrix     : ";
  out << std::endl << Amg::toString(localCovariance()) << std::endl;
  if (nullptr != m_fitQuality)
    out << "  - fit Quality          : " << std::endl
        << (*fitQuality()) << std::endl;
  else
    out << "  - fit Quality          : NO " << std::endl;
  out << "  - associated Surface   : " << std::endl
      << associatedSurface() << std::endl;
  out << "  - t0 (error) : " << time() << "(" << errorTime() << ")"
      << std::endl;
  out << "  - it contains   : " << numberOfContainedROTs()
      << " RIO_OnTrack object" << std::endl;
  unsigned int numRoT = 1;
  for (const Trk::MeasurementBase* m : containedMeasurements()) {
    const Trk::RIO_OnTrack* rot = dynamic_cast<const Trk::RIO_OnTrack*>(m);
    if (rot) {
      out << "RoT " << numRoT++ << std::endl << *rot << std::endl;
182
    }
183
184
  }
  return out;
185
186
187
188
}

}