Commit 0d5219d5 authored by Lennart Huth's avatar Lennart Huth
Browse files

added global and local residuals to all track objects

parent 40b92d88
......@@ -37,7 +37,8 @@ void GblTrack::fit() {
if(logging_)
std::cout << "Starting fit" << std::endl;
isFitted_ = false;
residual_.clear();
residual_local_.clear();
residual_global_.clear();
kink_.clear();
corrections_.clear();
local_track_points_.clear();
......@@ -293,16 +294,16 @@ void GblTrack::fit() {
local_track_points_.at(name).y() + corrections_.at(name).y(),
0));
ROOT::Math::XYZPoint clusterPos = plane.getCluster()->global();
residual_[name] = ROOT::Math::XYPoint(clusterPos.x() - corPos.x(), clusterPos.y() - corPos.y());
// m_residual[plane.name()] = ROOT::Math::XYPoint(gblResiduals(0),gblResiduals(1));
residual_global_[name] = clusterPos - corPos;
residual_local_[plane.getName()] = ROOT::Math::XYPoint(gblResiduals(0), gblResiduals(1));
if(logging_) {
std::cout << "Results for detector " << name << "\n Fitted res local:\t" << residual_.at(name)
std::cout << "Results for detector " << name << "\n Fitted res local:\t" << residual_global_.at(name)
<< "\n seed res:\t" << initital_residual_.at(name) << " \n fitted res global:\t"
<< ROOT::Math::XYPoint(clusterPos.x() - corPos.x(), clusterPos.y() - corPos.y()) << std::endl;
}
}
if(logging_) {
std::cout << "Plane: " << name << ": res" << residual_[name] << "\t kink: " << kink_[name] << std::endl;
std::cout << "Plane: " << name << ": res" << residual_global_[name] << "\t kink: " << kink_[name] << std::endl;
}
}
isFitted_ = true;
......
......@@ -41,7 +41,10 @@ void Multiplet::calculateChi2() {
void Multiplet::calculateResiduals() {
for(auto c : track_clusters_) {
auto cluster = dynamic_cast<Cluster*>(c.GetObject());
residual_[cluster->detectorID()] = cluster->global() - getIntercept(cluster->global().z());
residual_global_[cluster->detectorID()] = cluster->global() - getIntercept(cluster->global().z());
if(getPlane(cluster->detectorID()) != nullptr)
residual_local_[cluster->detectorID()] =
cluster->local() - getPlane(cluster->detectorID())->getToLocal() * getIntercept(cluster->global().z());
}
}
......
......@@ -62,7 +62,12 @@ void StraightLineTrack::calculateChi2() {
void StraightLineTrack::calculateResiduals() {
for(auto c : track_clusters_) {
auto cluster = dynamic_cast<Cluster*>(c.GetObject());
residual_[cluster->detectorID()] = cluster->global() - getIntercept(cluster->global().z());
// fixme: cluster->global.z() is only an approximation for the plane intersect. Can be fixed after !115
residual_global_[cluster->detectorID()] = cluster->global() - getIntercept(cluster->global().z());
if(getPlane(cluster->detectorID()) != nullptr) {
residual_local_[cluster->detectorID()] =
cluster->local() - getPlane(cluster->detectorID())->getToLocal() * getIntercept(cluster->global().z());
}
}
}
......
......@@ -221,8 +221,12 @@ XYZVector Track::getDirection(const std::string&) const {
return ROOT::Math::XYZVector(0.0, 0.0, 0.0);
}
XYPoint Track::getResidual(const std::string& detectorID) const {
return residual_.at(detectorID);
XYPoint Track::getLocalResidual(const std::string& detectorID) const {
return residual_local_.at(detectorID);
}
XYZPoint Track::getGlobalResidual(const std::string& detectorID) const {
return residual_global_.at(detectorID);
}
double Track::getMaterialBudget(const std::string& detectorID) const {
......@@ -252,6 +256,14 @@ void Track::replacePlane(Plane p) {
planes_.begin(), planes_.end(), [&p](Plane const& plane) { return plane.getName() == p.getName(); }, std::move(p));
}
Plane* Track::getPlane(std::string detetorID) {
auto plane =
std::find_if(planes_.begin(), planes_.end(), [&detetorID](Plane const& p) { return p.getName() == detetorID; });
if(plane == planes_.end())
return nullptr;
return &(*plane);
}
std::shared_ptr<Track> corryvreckan::Track::Factory(std::string trackModel) {
if(trackModel == "straightline") {
return std::make_shared<StraightLineTrack>();
......
......@@ -233,11 +233,18 @@ namespace corryvreckan {
bool isFitted() const { return isFitted_; }
/**
* @brief Get the residual for a given detector layer
* @brief Get the local residual for a given detector layer
* @param detectorID
* @return 2D residual as ROOT::Math::XYPoint
* @return 2D local residual as ROOT::Math::XYPoint
*/
ROOT::Math::XYPoint getResidual(const std::string& detectorID) const;
ROOT::Math::XYPoint getLocalResidual(const std::string& detectorID) const;
/**
* @brief Get the global residual for a given detector layer
* @param detectorID
* @return 3D global residual as ROOT::Math::XYPoint
*/
ROOT::Math::XYZPoint getGlobalResidual(const std::string& detectorID) const;
/**
* @brief Get the kink at a given detector layer. This is ill defined for last and first layer
......@@ -262,9 +269,11 @@ namespace corryvreckan {
void replacePlane(Plane p);
protected:
Plane* getPlane(std::string detetorID);
std::vector<TRef> track_clusters_;
std::vector<TRef> associated_clusters_;
std::map<std::string, ROOT::Math::XYPoint> residual_;
std::map<std::string, ROOT::Math::XYPoint> residual_local_;
std::map<std::string, ROOT::Math::XYZPoint> residual_global_;
std::map<std::string, ROOT::Math::XYZPoint> corrections_{};
std::vector<Plane> planes_{};
bool logging_ = false;
......
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