Files
Jungfraujoch/common/DiffractionSpot.cpp

68 lines
2.0 KiB
C++

// Copyright (2019-2023) Paul Scherrer Institute
#include "DiffractionSpot.h"
#include "DiffractionGeometry.h"
DiffractionSpot::DiffractionSpot(uint32_t col, uint32_t line, int64_t in_photons) {
if (in_photons < 0) in_photons = 0;
x = col * static_cast<float>(in_photons);
y = line * static_cast<float>(in_photons);
pixel_count = 1;
photons = in_photons;
max_photons = in_photons;
}
DiffractionSpot& DiffractionSpot::operator+=(const DiffractionSpot &other) {
this->x += other.x;
this->y += other.y;
this->photons += other.photons;
this->max_photons = std::max(this->max_photons, other.max_photons);
this->pixel_count += other.pixel_count;
return *this;
}
int64_t DiffractionSpot::Count() const {
return photons;
}
int64_t DiffractionSpot::MaxCount() const {
return max_photons;
}
Coord DiffractionSpot::RawCoord() const {
return {x / (float)photons, y / (float)photons, 0};
}
int64_t DiffractionSpot::PixelCount() const {
return pixel_count;
}
Coord DiffractionSpot::LabCoord(const DiffractionExperiment &experiment) const {
return experiment.LabCoord(x / (float)photons, y / (float)photons);
}
Coord DiffractionSpot::ReciprocalCoord(const DiffractionExperiment &experiment) const {
return DetectorToRecip(experiment, x / (float)photons, y / (float)photons);
}
double DiffractionSpot::GetResolution(const DiffractionExperiment &experiment) const {
return PxlToRes(experiment, x / (float)photons, y / (float)photons);
}
DiffractionSpot::operator SpotToSave() const {
return {
.x = x / static_cast<float>(photons),
.y = y / static_cast<float>(photons),
.intensity = static_cast<float>(photons),
.indexed = false
};
}
void DiffractionSpot::AddPixel(uint32_t col, uint32_t line, int64_t photons) {
this->x += col * (float) photons;
this->y += line * (float) photons;
this->photons += photons;
this->max_photons = std::max(this->max_photons, photons);
this->pixel_count += 1;
}