Commit 10513647 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

EtaCorrection: make DETECTOR_MODULE

parent e9cb4506
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
......@@ -3,8 +3,8 @@
using namespace corryvreckan;
using namespace std;
EtaCorrection::EtaCorrection(Configuration config, std::vector<std::shared_ptr<Detector>> detectors)
: Module(std::move(config), std::move(detectors)) {
EtaCorrection::EtaCorrection(Configuration config, std::shared_ptr<Detector> detector)
: Module(std::move(config), detector), m_detector(detector) {
m_etaFormulaX = m_config.get<std::string>("EtaFormulaX", "[0] + [1]*x + [2]*x^2 + [3]*x^3 + [4]*x^4 + [5]*x^5");
m_etaFormulaY = m_config.get<std::string>("EtaFormulaY", "[0] + [1]*x + [2]*x^2 + [3]*x^3 + [4]*x^4 + [5]*x^5");
}
......@@ -12,40 +12,38 @@ EtaCorrection::EtaCorrection(Configuration config, std::vector<std::shared_ptr<D
void EtaCorrection::initialise() {
// Initialise histograms
for(auto& detector : get_detectors()) {
double pitchX = detector->pitch().X();
double pitchY = detector->pitch().Y();
// Get info from configuration:
std::vector<double> m_etaConstantsX = m_config.getArray<double>("EtaConstantsX_" + detector->name(), {});
std::vector<double> m_etaConstantsY = m_config.getArray<double>("EtaConstantsY_" + detector->name(), {});
if(!m_etaConstantsX.empty() || !m_etaConstantsY.empty()) {
LOG(INFO) << "Found Eta correction factors for detector \"" << detector->name()
<< "\": " << (m_etaConstantsX.empty() ? "" : "X ") << (m_etaConstantsY.empty() ? "" : "Y ");
}
double pitchX = m_detector->pitch().X();
double pitchY = m_detector->pitch().Y();
// Get info from configuration:
std::vector<double> m_etaConstantsX = m_config.getArray<double>("EtaConstantsX_" + m_detector->name(), {});
std::vector<double> m_etaConstantsY = m_config.getArray<double>("EtaConstantsY_" + m_detector->name(), {});
if(!m_etaConstantsX.empty() || !m_etaConstantsY.empty()) {
LOG(INFO) << "Found Eta correction factors for detector \"" << m_detector->name()
<< "\": " << (m_etaConstantsX.empty() ? "" : "X ") << (m_etaConstantsY.empty() ? "" : "Y ");
}
if(!m_etaConstantsX.empty()) {
m_correctX[detector->name()] = true;
m_etaCorrectorX[detector->name()] = new TF1("etaCorrectorX", m_etaFormulaX.c_str(), 0, pitchX);
for(size_t x = 0; x < m_etaConstantsX.size(); x++) {
m_etaCorrectorX[detector->name()]->SetParameter(static_cast<int>(x), m_etaConstantsX[x]);
}
} else {
m_correctX[detector->name()] = false;
if(!m_etaConstantsX.empty()) {
m_correctX = true;
m_etaCorrectorX = new TF1("etaCorrectorX", m_etaFormulaX.c_str(), 0, pitchX);
for(size_t x = 0; x < m_etaConstantsX.size(); x++) {
m_etaCorrectorX->SetParameter(static_cast<int>(x), m_etaConstantsX[x]);
}
} else {
m_correctX = false;
}
if(!m_etaConstantsY.empty()) {
m_correctY[detector->name()] = true;
m_etaCorrectorY[detector->name()] = new TF1("etaCorrectorY", m_etaFormulaY.c_str(), 0, pitchY);
for(size_t y = 0; y < m_etaConstantsY.size(); y++)
m_etaCorrectorY[detector->name()]->SetParameter(static_cast<int>(y), m_etaConstantsY[y]);
} else {
m_correctY[detector->name()] = false;
}
if(!m_etaConstantsY.empty()) {
m_correctY = true;
m_etaCorrectorY = new TF1("etaCorrectorY", m_etaFormulaY.c_str(), 0, pitchY);
for(size_t y = 0; y < m_etaConstantsY.size(); y++)
m_etaCorrectorY->SetParameter(static_cast<int>(y), m_etaConstantsY[y]);
} else {
m_correctY = false;
}
}
void EtaCorrection::applyEta(Cluster* cluster, std::shared_ptr<Detector> detector) {
void EtaCorrection::applyEta(Cluster* cluster) {
// Ignore single pixel clusters
if(cluster->size() == 1) {
return;
......@@ -55,44 +53,42 @@ void EtaCorrection::applyEta(Cluster* cluster, std::shared_ptr<Detector> detecto
double newY = cluster->localY();
if(cluster->columnWidth() == 2) {
double inPixelX = detector->pitch().X() * (cluster->column() - floor(cluster->column()));
double inPixelX = m_detector->pitch().X() * (cluster->column() - floor(cluster->column()));
// Apply the eta correction
if(m_correctX[detector->name()]) {
newX = floor(cluster->localX() / detector->pitch().X()) * detector->pitch().X() +
m_etaCorrectorX[detector->name()]->Eval(inPixelX);
if(m_correctX) {
newX = floor(cluster->localX() / m_detector->pitch().X()) * m_detector->pitch().X() +
m_etaCorrectorX->Eval(inPixelX);
}
}
if(cluster->rowWidth() == 2) {
double inPixelY = detector->pitch().Y() * (cluster->row() - floor(cluster->row()));
double inPixelY = m_detector->pitch().Y() * (cluster->row() - floor(cluster->row()));
// Apply the eta correction
if(m_correctY[detector->name()]) {
newY = floor(cluster->localY() / detector->pitch().Y()) * detector->pitch().Y() +
m_etaCorrectorY[detector->name()]->Eval(inPixelY);
if(m_correctY) {
newY = floor(cluster->localY() / m_detector->pitch().Y()) * m_detector->pitch().Y() +
m_etaCorrectorY->Eval(inPixelY);
}
}
PositionVector3D<Cartesian3D<double>> positionLocal(newX, newY, 0);
PositionVector3D<Cartesian3D<double>> positionGlobal = detector->localToGlobal(positionLocal);
PositionVector3D<Cartesian3D<double>> positionGlobal = m_detector->localToGlobal(positionLocal);
cluster->setClusterCentre(positionGlobal);
cluster->setClusterCentreLocal(positionLocal);
}
StatusCode EtaCorrection::run(Clipboard* clipboard) {
for(auto& detector : get_detectors()) {
// Get the clusters
Clusters* clusters = reinterpret_cast<Clusters*>(clipboard->get(detector->name(), "clusters"));
if(clusters == nullptr) {
LOG(DEBUG) << "Detector " << detector->name() << " does not have any clusters on the clipboard";
return Success;
}
// Get the clusters
Clusters* clusters = reinterpret_cast<Clusters*>(clipboard->get(m_detector->name(), "clusters"));
if(clusters == nullptr) {
LOG(DEBUG) << "Detector " << m_detector->name() << " does not have any clusters on the clipboard";
return Success;
}
for(auto& cluster : (*clusters)) {
applyEta(cluster, detector);
}
for(auto& cluster : (*clusters)) {
applyEta(cluster);
}
// Return value telling analysis to keep running
......
......@@ -20,7 +20,7 @@ namespace corryvreckan {
public:
// Constructors and destructors
EtaCorrection(Configuration config, std::vector<std::shared_ptr<Detector>> detectors);
EtaCorrection(Configuration config, std::shared_ptr<Detector> detector);
~EtaCorrection() {}
// Functions
......@@ -29,15 +29,15 @@ namespace corryvreckan {
void finalise(){};
private:
void applyEta(Cluster* cluster, std::shared_ptr<Detector> detector);
void applyEta(Cluster* cluster);
// Member variables
std::shared_ptr<Detector> m_detector;
std::string m_etaFormulaX;
std::map<std::string, TF1*> m_etaCorrectorX;
std::map<std::string, bool> m_correctX;
TF1* m_etaCorrectorX;
bool m_correctX;
std::string m_etaFormulaY;
std::map<std::string, TF1*> m_etaCorrectorY;
std::map<std::string, bool> m_correctY;
TF1* m_etaCorrectorY;
bool m_correctY;
};
} // namespace corryvreckan
#endif // EtaCorrection_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment