LSST Applications g04e9c324dd+8c5ae1fdc5,g134cb467dc+1b3060144d,g18429d2f64+f642bf4753,g199a45376c+0ba108daf9,g1fd858c14a+2dcf163641,g262e1987ae+7b8c96d2ca,g29ae962dfc+3bd6ecb08a,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+53e1a9e7c5,g4595892280+fef73a337f,g47891489e3+2efcf17695,g4d44eb3520+642b70b07e,g53246c7159+8c5ae1fdc5,g67b6fd64d1+2efcf17695,g67fd3c3899+b70e05ef52,g74acd417e5+317eb4c7d4,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+2efcf17695,g8d7436a09f+3be3c13596,g8ea07a8fe4+9f5ccc88ac,g90f42f885a+a4e7b16d9b,g97be763408+ad77d7208f,g9dd6db0277+b70e05ef52,ga681d05dcb+a3f46e7fff,gabf8522325+735880ea63,gac2eed3f23+2efcf17695,gb89ab40317+2efcf17695,gbf99507273+8c5ae1fdc5,gd8ff7fe66e+b70e05ef52,gdab6d2f7ff+317eb4c7d4,gdc713202bf+b70e05ef52,gdfd2d52018+b10e285e0f,ge365c994fd+310e8507c4,ge410e46f29+2efcf17695,geaed405ab2+562b3308c0,gffca2db377+8c5ae1fdc5,w.2025.35
LSST Data Management Base Package
Loading...
Searching...
No Matches
Detector.h
Go to the documentation of this file.
1// -*- lsst-c++ -*-
2/*
3 * Developed for the LSST Data Management System.
4 * This product includes software developed by the LSST Project
5 * (https://www.lsst.org).
6 * See the COPYRIGHT file at the top-level directory of this distribution
7 * for details of code ownership.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23#if !defined(LSST_AFW_CAMERAGEOM_DETECTOR_H)
24#define LSST_AFW_CAMERAGEOM_DETECTOR_H
25
26#include <string>
27#include <vector>
28#include <unordered_map>
29#include "lsst/base.h"
36
37namespace lsst {
38namespace afw {
39namespace cameraGeom {
40
50
51
57public:
58
59 using CrosstalkMatrix = ndarray::Array<float const, 2>;
60
61 virtual ~DetectorBase() noexcept = default;
62
64 std::string getName() const { return getFields().name; }
65
67 int getId() const { return getFields().id; }
68
70 DetectorType getType() const { return getFields().type; }
71
73 std::string getSerial() const { return getFields().serial; }
74
83
86
89
92
94 bool hasCrosstalk() const {
95 return !(getFields().crosstalk.isEmpty() ||
96 getFields().crosstalk.getShape() == ndarray::makeVector(0, 0));
97 }
98
101
110 CameraSys makeCameraSys(CameraSys const &cameraSys) const { return cameraSys; }
111
118 CameraSys makeCameraSys(CameraSysPrefix const &cameraSysPrefix) const {
119 return CameraSys(cameraSysPrefix, getFields().name);
120 }
121
124
125protected:
126
127 // Simple struct containing all simple fields (everything not related
128 // to coordinate systems/transforms or associated with an Amplifier).
129 // See docs for corresponding getters (each field has one) for
130 // descriptions.
142
144
148 DetectorBase() = default;
149 DetectorBase(DetectorBase const &) = default;
151 DetectorBase & operator=(DetectorBase const &) = default;
154
160 virtual Fields const & getFields() const = 0;
161
162};
163
164
181class Detector final :
182 public DetectorBase,
183 public table::io::PersistableFacade<Detector>
184{
185public:
186
187 class Builder;
188 class PartialRebuilder;
189 class InCameraBuilder;
190
197
200
202 std::vector<lsst::geom::Point2D> getCorners(CameraSysPrefix const &cameraSysPrefix) const;
203
205 lsst::geom::Point2D getCenter(CameraSys const &cameraSys) const;
206
208 lsst::geom::Point2D getCenter(CameraSysPrefix const &cameraSysPrefix) const;
209
211 bool hasTransform(CameraSys const &cameraSys) const;
212
214 bool hasTransform(CameraSysPrefix const &cameraSysPrefix) const;
215
228 template <typename FromSysT, typename ToSysT>
230 ToSysT const &toSys) const;
231
244 template <typename FromSysT, typename ToSysT>
245 lsst::geom::Point2D transform(lsst::geom::Point2D const &point, FromSysT const &fromSys,
246 ToSysT const &toSys) const;
247
260 template <typename FromSysT, typename ToSysT>
262 FromSysT const &fromSys, ToSysT const &toSys) const;
263
264
266 std::shared_ptr<TransformMap const> getTransformMap() const { return _transformMap; }
267
269 std::vector<std::shared_ptr<Amplifier const>> const & getAmplifiers() const { return _amplifiers; }
270
272
277 auto begin() const { return _amplifiers.begin(); }
278 auto end() const { return _amplifiers.end(); }
279 //}
280
286 std::shared_ptr<Amplifier const> operator[](size_t i) const { return _amplifiers.at(i); }
287
294
298 std::size_t size() const { return _amplifiers.size(); }
299
301 bool isPersistable() const noexcept override { return true; }
302
303protected:
304
305 Fields const & getFields() const override { return _fields; }
306
307private:
308
309 class Factory;
310
311 // Pass fields by value to move when we can and copy when we can't;
312 // pass amplifiers by rvalue ref because we always move those.
313 Detector(Fields fields, std::shared_ptr<TransformMap const> transformMap,
315
316 std::string getPersistenceName() const override;
317
318 std::string getPythonModule() const override;
319
320 void write(OutputArchiveHandle& handle) const override;
321
322 Fields const _fields;
324 // Given that the number of amplifiers in a detector is generally quite
325 // small (even LSST only has 16), we just use a vector and do linear
326 // searches for name lookups, as adding a map of some kind is definitely
327 // more storage and code complexity, without necessarily being any faster.
329};
330
331
362public:
363
364 // Builder's current subclasses have no need for copy or assignment, and
365 // the hierarchy should be considered closed.
366 Builder(Builder const &) = delete;
367 Builder(Builder &&) = delete;
368 Builder & operator=(Builder const &) = delete;
369 Builder & operator=(Builder &&) = delete;
370
371 ~Builder() noexcept override = 0;
372
374 void setBBox(lsst::geom::Box2I const & bbox) { _fields.bbox = bbox; }
375
377 void setType(DetectorType type) { _fields.type = type; }
378
380 void setSerial(std::string const & serial) { _fields.serial = serial; }
381
387 void setPhysicalType(std::string const & physicalType) { _fields.physicalType = physicalType; }
388
399 void setCrosstalk(CrosstalkMatrix const & crosstalk) { _fields.crosstalk = crosstalk; }
400
402 void unsetCrosstalk() { _fields.crosstalk = CrosstalkMatrix(); }
403
404 // We return non-const Amplifier::Builder objects by shared_ptr, via const
405 // methods. That's a bit counterintuitive, but there's no solution to the
406 // problem of constness in containers of pointers in C++ that *is*
407 // intuitive. The alternative would be to have const methods that return
408 // pointer-to-const and non-const methods that return
409 // pointer-to-not-const. The only gain from that would be that it'd be
410 // possible to have a const reference to a Detector::Builder that would
411 // prevent modifications to its amplifiers. That's a lot more code
412 // (writing the iterators would be especially unpleasant) for essentially
413 // no gain, because users who want to prevent changes to the amplifiers
414 // essentially always Detector itself, not Detector::Builder.
415
417 std::vector<std::shared_ptr<Amplifier::Builder>> const & getAmplifiers() const { return _amplifiers; }
418
420
425 auto begin() { return _amplifiers.begin(); }
426 auto end() { return _amplifiers.end(); }
428
434 std::shared_ptr<Amplifier::Builder> operator[](size_t i) const { return _amplifiers.at(i); }
435
442
445
447 void clear() { _amplifiers.clear(); }
448
450 std::size_t size() const { return _amplifiers.size(); }
451
452protected:
453
459
464 Builder(std::string const & name, int id);
465
471 _fields(std::move(fields)),
472 _amplifiers(std::move(amplifiers))
473 {}
474
475 Fields const & getFields() const override { return _fields; }
476
481
489 void setOrientation(Orientation const & orientation) { _fields.orientation = orientation; }
490
498 void setPixelSize(lsst::geom::Extent2D const & pixelSize) { _fields.pixelSize = pixelSize; }
499
500private:
501 Fields _fields;
503};
504
505
520public:
521
526 PartialRebuilder(Detector const & detector);
527
532
533private:
535};
536
555public:
556
560 void setOrientation(Orientation const & orientation) { Detector::Builder::setOrientation(orientation); }
561
566
577 CameraSysPrefix const & toSys,
579 );
580
594 CameraSys const & toSys,
596 );
597
606
617 bool discardTransformFromPixelsTo(CameraSys const & toSys);
618
622 void clearTransforms() { _connections.clear(); }
623
624private:
625
626 // We'd really like to friend Camera::Builder, but can't forward declare
627 // an inner class. So instead we friend Camera, and it has static members
628 // that make the needed functionality accessible to Camera::Builder.
629 friend class Camera;
630
631 // Construct from an existing Detector. For use only by Camera.
632 InCameraBuilder(Detector const & detector);
633
634 // Construct a completely new detector. For use only by Camera.
635 InCameraBuilder(std::string const & name, int id);
636
637 // Construct a Detector from the builder. For use only by Camera.
638 //
639 // @param[in] transformMap All transforms known to the entire Camera.
640 //
642
643 // Transforms and coordinate systems that are specific to this detector.
644 // This does not include the FOCAL_PLANE<->PIXELS connection, as that's
645 // derived from the orientation and pixel size.
647};
648
649} // namespace cameraGeom
650} // namespace afw
651} // namespace lsst
652
653#endif
Basic LSST definitions.
Camera coordinate system; used as a key in in TransformMap.
Definition CameraSys.h:83
Camera coordinate system prefix.
Definition CameraSys.h:44
A helper class for Detector that allows amplifiers and most fields to be modified.
Definition Detector.h:361
Builder & operator=(Builder const &)=delete
auto begin()
An iterator range over amplifers.
Definition Detector.h:425
void setSerial(std::string const &serial)
Set the detector serial "number".
Definition Detector.h:380
void setBBox(lsst::geom::Box2I const &bbox)
Set the bounding box.
Definition Detector.h:374
void setPhysicalType(std::string const &physicalType)
Set the detector's physical type.
Definition Detector.h:387
Builder & operator=(Builder &&)=delete
std::vector< std::shared_ptr< Amplifier const > > finishAmplifiers() const
Create a vector of Amplifiers from the Amplifier::Builder sequence.
Definition Detector.cc:398
void setPixelSize(lsst::geom::Extent2D const &pixelSize)
Set the pixel size (in mm).
Definition Detector.h:498
static std::vector< std::shared_ptr< Amplifier::Builder > > rebuildAmplifiers(Detector const &detector)
Create a vector of Amplifier::Builders from the Amplifiers in a Detector.
Definition Detector.cc:380
Builder(Fields fields, std::vector< std::shared_ptr< Amplifier::Builder > > &&amplifiers)
Construct a Detector::Builder with the given field values and amplifiers.
Definition Detector.h:470
void setCrosstalk(CrosstalkMatrix const &crosstalk)
Set the crosstalk coefficients.
Definition Detector.h:399
std::vector< std::shared_ptr< Amplifier::Builder > > const & getAmplifiers() const
Return the sequence of Amplifier::Builders directly.
Definition Detector.h:417
void setType(DetectorType type)
Set the purpose of this detector.
Definition Detector.h:377
Fields const & getFields() const override
Return a reference to a Fields struct.
Definition Detector.h:475
void unsetCrosstalk()
Remove the crosstalk coefficient matrix.
Definition Detector.h:402
void setOrientation(Orientation const &orientation)
Set the orientation of the detector in the focal plane.
Definition Detector.h:489
void append(std::shared_ptr< Amplifier::Builder > builder)
Append a new amplifier.
Definition Detector.cc:376
std::size_t size() const
Return the number of amplifiers (renamed to len in Python).
Definition Detector.h:450
std::shared_ptr< Amplifier::Builder > operator[](size_t i) const
Get the amplifier builder specified by index.
Definition Detector.h:434
void clear()
Remove all amplifiers.
Definition Detector.h:447
A helper class that allows the properties of a detector to be modified in the course of modifying a f...
Definition Detector.h:554
void setOrientation(Orientation const &orientation)
Set the orientation of the detector in the focal plane.
Definition Detector.h:560
void setTransformFromPixelsTo(CameraSysPrefix const &toSys, std::shared_ptr< afw::geom::TransformPoint2ToPoint2 const > transform)
Set the transformation from PIXELS to the given coordinate system.
Definition Detector.cc:438
bool discardTransformFromPixelsTo(CameraSysPrefix const &toSys)
Remove any transformation from PIXELS to the given coordinate system.
Definition Detector.cc:466
void setPixelSize(lsst::geom::Extent2D const &pixelSize)
Set the pixel size (in mm).
Definition Detector.h:565
void clearTransforms()
Remove all coordinate transforms.
Definition Detector.h:622
A helper class that allows the properties of a single detector to be modified in isolation.
Definition Detector.h:519
PartialRebuilder(Detector const &detector)
Construct a PartialRebuilder initialized to the state of the given Detector.
Definition Detector.cc:408
std::shared_ptr< Detector const > finish() const
Construct a new Detector from the current state of the Builder.
Definition Detector.cc:413
DetectorBase(DetectorBase const &)=default
lsst::geom::Box2I getBBox() const
Get the bounding box.
Definition Detector.h:85
DetectorBase(DetectorBase &&)=default
virtual ~DetectorBase() noexcept=default
DetectorBase & operator=(DetectorBase &&)=default
DetectorBase & operator=(DetectorBase const &)=default
DetectorBase()=default
DetectorBase has no state, and is hence default-constructable, copyable, and movable.
lsst::geom::Extent2D getPixelSize() const
Get size of pixel along (mm)
Definition Detector.h:91
CameraSys makeCameraSys(CameraSysPrefix const &cameraSysPrefix) const
Get a coordinate system from a detector system prefix (add detector name)
Definition Detector.h:118
std::string getName() const
Get the detector name.
Definition Detector.h:64
CameraSys getNativeCoordSys() const
The "native" coordinate system of this detector.
Definition Detector.h:123
virtual Fields const & getFields() const =0
Return a reference to a Fields struct.
bool hasCrosstalk() const
Have we got crosstalk coefficients?
Definition Detector.h:94
int getId() const
Get the detector ID.
Definition Detector.h:67
std::string getPhysicalType() const
Get the detector's physical type.
Definition Detector.h:82
Orientation getOrientation() const
Get detector's orientation in the focal plane.
Definition Detector.h:88
std::string getSerial() const
Get the detector serial "number".
Definition Detector.h:73
CameraSys makeCameraSys(CameraSys const &cameraSys) const
Get a coordinate system from a coordinate system (return input unchanged and untested)
Definition Detector.h:110
CrosstalkMatrix getCrosstalk() const
Get the crosstalk coefficients.
Definition Detector.h:100
ndarray::Array< float const, 2 > CrosstalkMatrix
Definition Detector.h:59
DetectorType getType() const
Return the purpose of this detector.
Definition Detector.h:70
A representation of a detector in a mosaic camera.
Definition Detector.h:184
std::vector< std::shared_ptr< Amplifier const > > const & getAmplifiers() const
Return the sequence of Amplifiers directly.
Definition Detector.h:269
auto begin() const
An iterator range over amplifers.
Definition Detector.h:277
bool hasTransform(CameraSys const &cameraSys) const
Can this object convert between PIXELS and the specified camera coordinate system?
Definition Detector.cc:82
std::shared_ptr< afw::geom::TransformPoint2ToPoint2 > getTransform(FromSysT const &fromSys, ToSysT const &toSys) const
Get a Transform from one camera coordinate system, or camera coordinate system prefix,...
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition Detector.cc:325
std::size_t size() const
Get the number of amplifiers.
Definition Detector.h:298
bool isPersistable() const noexcept override
Detector is always persistable.
Definition Detector.h:301
std::shared_ptr< Amplifier const > operator[](size_t i) const
Get the amplifier specified by index.
Definition Detector.h:286
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition Detector.cc:319
std::shared_ptr< TransformMap const > getTransformMap() const
Get the transform registry.
Definition Detector.h:266
Fields const & getFields() const override
Return a reference to a Fields struct.
Definition Detector.h:305
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition Detector.cc:329
lsst::geom::Point2D transform(lsst::geom::Point2D const &point, FromSysT const &fromSys, ToSysT const &toSys) const
Transform a point from one camera system to another.
Definition Detector.cc:95
std::vector< lsst::geom::Point2D > getCorners(CameraSys const &cameraSys) const
Get the corners of the detector in the specified camera coordinate system.
Definition Detector.cc:62
lsst::geom::Point2D getCenter(CameraSys const &cameraSys) const
Get the center of the detector in the specified camera coordinate system.
Definition Detector.cc:72
std::shared_ptr< PartialRebuilder > rebuild() const
Return a Builder object initialized with the state of this Detector.
Definition Detector.cc:58
Describe a detector's orientation in the focal plane.
Definition Orientation.h:51
A CRTP facade class for subclasses of Persistable.
io::OutputArchiveHandle OutputArchiveHandle
Interface supporting iteration over heterogenous containers.
Definition Storable.h:58
An integer coordinate rectangle.
Definition Box.h:55
CameraSysPrefix const PIXELS
Pixel coordinates: Nominal position on the entry surface of a given detector (x, y unbinned pixels).
Definition CameraSys.cc:34
DetectorType
Type of imaging detector.
Definition Detector.h:44
Extent< double, 2 > Extent2D
Definition Extent.h:400
Point< double, 2 > Point2D
Definition Point.h:324
STL namespace.