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

Rework objects to eb a bit safer and use modern loops

parent 8f8526dd
......@@ -58,9 +58,9 @@ public:
double localX() { return m_localX; }
double localY() { return m_localY; }
double localZ() { return m_localZ; }
int size() { return m_pixels.size(); }
int columnWidth() { return m_columnWidth; }
int rowWidth() { return m_rowWidth; }
size_t size() { return m_pixels.size(); }
double columnWidth() { return m_columnWidth; }
double rowWidth() { return m_rowWidth; }
long long int timestamp() { return m_timestamp; }
std::string detectorID() { return m_detectorID; }
Pixels* pixels() { return (&m_pixels); }
......@@ -83,6 +83,7 @@ public:
void setTimestamp(long long int timestamp) { m_timestamp = timestamp; }
void setDetectorID(std::string detectorID) { m_detectorID = detectorID; }
private:
// Member variables
Pixels m_pixels;
double m_row;
......
......@@ -4,15 +4,20 @@
#include "TestBeamObject.h"
#include "Track.h"
#include "core/utils/exceptions.h"
ClassImp(TestBeamObject)
// Return class type for fixed object types (that don't depend on detector
// type)
TestBeamObject* TestBeamObject::Factory(std::string objectType, TestBeamObject* object) {
// Return class type for fixed object types (that don't depend on detector
// type)
TestBeamObject* TestBeamObject::Factory(std::string objectType, TestBeamObject* object) {
// Track class
if(objectType == "tracks")
return (object == NULL) ? new Track() : new Track(*(Track*)object);
if(objectType == "tracks") {
return (object == NULL) ? new Track() : new Track(*static_cast<Track*>(object));
}
return new TestBeamObject();
}
// Return class type for objects which change with detector type
......@@ -21,8 +26,10 @@ TestBeamObject* TestBeamObject::Factory(std::string detectorType, std::string ob
// Timepix types both use generic classes
if(detectorType == "Timepix1" || detectorType == "Timepix3") {
if(objectType == "pixels")
return (object == NULL) ? new Pixel() : new Pixel(*(Pixel*)object);
return (object == NULL) ? new Pixel() : new Pixel(*static_cast<Pixel*>(object));
if(objectType == "clusters")
return (object == NULL) ? new Cluster() : new Cluster(*(Cluster*)object);
return (object == NULL) ? new Cluster() : new Cluster(*static_cast<Cluster*>(object));
}
return new TestBeamObject();
}
......@@ -37,7 +37,7 @@ public:
double localX() { return m_localX; }
double localY() { return m_localY; }
double localZ() { return m_localZ; }
int size() { return m_pixels.size(); }
size_t size() { return m_pixels.size(); }
long long int timestamp() { return m_timestamp; }
std::string detectorID() { return m_detectorID; }
Timepix3Pixels pixels() { return m_pixels; }
......
......@@ -27,16 +27,14 @@ public:
m_fitterXZ->SetFormula("pol1");
m_fitterYZ = new TLinearFitter();
m_fitterYZ->SetFormula("pol1");
Timepix3Clusters trackClusters = track->clusters();
for(int iTrackCluster = 0; iTrackCluster < trackClusters.size(); iTrackCluster++) {
Timepix3Cluster* trackCluster = trackClusters[iTrackCluster];
Timepix3Cluster* cluster = new Timepix3Cluster(trackCluster);
for(auto& track_cluster : track->clusters()) {
Timepix3Cluster* cluster = new Timepix3Cluster(track_cluster);
m_trackClusters.push_back(cluster);
}
Timepix3Clusters associatedClusters = track->associatedClusters();
for(int iAssociatedCluster = 0; iAssociatedCluster < associatedClusters.size(); iAssociatedCluster++) {
Timepix3Cluster* associatedCluster = associatedClusters[iAssociatedCluster];
Timepix3Cluster* cluster = new Timepix3Cluster(associatedCluster);
for(auto& assoc_cluster : track->associatedClusters()) {
Timepix3Cluster* cluster = new Timepix3Cluster(assoc_cluster);
m_associatedClusters.push_back(cluster);
}
m_state = track->m_state;
......@@ -57,14 +55,9 @@ public:
m_fitterXZ->ClearPoints();
m_fitterYZ->ClearPoints();
// Check how many clusters there are
int nClusters = m_trackClusters.size();
// Loop over all clusters
double* z = new double[0];
for(int iCluster = 0; iCluster < nClusters; iCluster++) {
// Get the cluster
Timepix3Cluster* cluster = m_trackClusters[iCluster];
for(auto& cluster : m_trackClusters) {
// Add it to the fitter
z[0] = cluster->globalZ();
m_fitterXZ->AddPoint(z, cluster->globalX(), cluster->error());
......@@ -112,18 +105,12 @@ public:
// Calculate the chi2 of the track
void calculateChi2() {
// Get the number of clusters
int nClusters = m_trackClusters.size();
m_ndof = nClusters - 2.;
m_ndof = static_cast<double>(m_trackClusters.size()) - 2.;
m_chi2 = 0.;
m_chi2ndof = 0.;
// Loop over all clusters
for(int iCluster = 0; iCluster < nClusters; iCluster++) {
// Get the cluster
Timepix3Cluster* cluster = m_trackClusters[iCluster];
for(auto& cluster : m_trackClusters) {
// Get the distance^2 and the error^2
double error2 = cluster->error() * cluster->error();
m_chi2 += (this->distance2(cluster) / error2);
......@@ -140,7 +127,7 @@ public:
long long int timestamp() { return m_timestamp; }
Timepix3Clusters clusters() { return m_trackClusters; }
Timepix3Clusters associatedClusters() { return m_associatedClusters; }
int nClusters() { return m_trackClusters.size(); }
size_t nClusters() { return m_trackClusters.size(); }
ROOT::Math::XYZPoint intercept(double z) {
ROOT::Math::XYZPoint point = m_state + m_direction * z;
return point;
......
......@@ -26,15 +26,14 @@ public:
// Copy constructor (also copies clusters from the original track)
Track(Track* track) {
Clusters trackClusters = track->clusters();
for(int iTrackCluster = 0; iTrackCluster < trackClusters.size(); iTrackCluster++) {
Cluster* trackCluster = trackClusters[iTrackCluster];
Cluster* cluster = new Cluster(trackCluster);
for(auto& track_cluster : trackClusters) {
Cluster* cluster = new Cluster(track_cluster);
m_trackClusters.push_back(cluster);
}
Clusters associatedClusters = track->associatedClusters();
for(int iAssociatedCluster = 0; iAssociatedCluster < associatedClusters.size(); iAssociatedCluster++) {
Cluster* associatedCluster = associatedClusters[iAssociatedCluster];
Cluster* cluster = new Cluster(associatedCluster);
for(auto & assoc_cluster : associatedClusters) {
Cluster* cluster = new Cluster(assoc_cluster);
m_associatedClusters.push_back(cluster);
}
m_state = track->m_state;
......@@ -69,17 +68,12 @@ public:
void calculateChi2() {
// Get the number of clusters
int nClusters = m_trackClusters.size();
m_ndof = nClusters - 2.;
m_ndof = static_cast<double>(m_trackClusters.size()) - 2.;
m_chi2 = 0.;
m_chi2ndof = 0.;
// Loop over all clusters
for(int iCluster = 0; iCluster < nClusters; iCluster++) {
// Get the cluster
Cluster* cluster = m_trackClusters[iCluster];
for(auto &cluster : m_trackClusters) {
// Get the distance^2 and the error^2
double error2 = cluster->error() * cluster->error();
m_chi2 += (this->distance2(cluster) / error2);
......@@ -104,7 +98,7 @@ public:
this->calculateChi2();
// Return this to minuit
return (const double)m_chi2;
return m_chi2;
}
// Fit the track (linear regression)
......@@ -116,9 +110,7 @@ public:
double maty[2][2] = {{0., 0.}, {0., 0.}};
// Loop over all clusters and fill the matrices
for(int iCluster = 0; iCluster < m_trackClusters.size(); iCluster++) {
// Get the cluster
Cluster* cluster = m_trackClusters[iCluster];
for(auto & cluster : m_trackClusters) {
// Get the global point details
double x = cluster->globalX();
double y = cluster->globalY();
......@@ -172,7 +164,7 @@ public:
long long int timestamp() { return m_timestamp; }
Clusters clusters() { return m_trackClusters; }
Clusters associatedClusters() { return m_associatedClusters; }
int nClusters() { return m_trackClusters.size(); }
size_t nClusters() { return m_trackClusters.size(); }
ROOT::Math::XYZPoint intercept(double z) {
ROOT::Math::XYZPoint point = m_state + m_direction * z;
return point;
......
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