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

Remove obsolete objects and one algorithm not maintained anymore

parent 3afc4a89
#include "EventDisplay.h"
#include "TApplication.h"
#include "TPolyLine3D.h"
using namespace corryvreckan;
EventDisplay::EventDisplay(Configuration config, Clipboard* clipboard) : Algorithm(std::move(config), clipboard) {}
void EventDisplay::initialise(Parameters* par) {
parameters = par;
// Set up histograms
eventMap = new TH3F("eventMap", "eventMap", 100, -10, 10, 100, -10, 10, 105, -10, 200);
}
StatusCode EventDisplay::run(Clipboard* clipboard) {
// Get the tracks
Timepix3Tracks* tracks = (Timepix3Tracks*)clipboard->get("Timepix3", "tracks");
if(tracks == NULL) {
return Success;
}
TApplication* rootapp = new TApplication("example", 0, 0);
TCanvas* canv = new TCanvas();
eventMap->DrawCopy("");
// Loop over all tracks. Add the cluster points to the histogram and draw a
// line for the tracks
for(int iTrack = 0; iTrack < tracks->size(); iTrack++) {
// Get the track
Timepix3Track* track = (*tracks)[iTrack];
// Get all clusters on the track
Timepix3Clusters trackClusters = track->clusters();
// Fill the event map
for(int iTrackCluster = 0; iTrackCluster < trackClusters.size(); iTrackCluster++) {
Timepix3Cluster* trackCluster = trackClusters[iTrackCluster];
eventMap->Fill(trackCluster->globalX(), trackCluster->globalY(), trackCluster->globalZ());
}
ROOT::Math::XYZPoint linestart = track->intercept(0);
ROOT::Math::XYZPoint linestop = track->intercept(200);
TPolyLine3D* line = new TPolyLine3D(2);
line->SetPoint(0, linestart.X(), linestart.Y(), linestart.Z());
line->SetPoint(1, linestop.X(), linestop.Y(), linestop.Z());
line->SetLineColor(2);
line->Draw("same");
}
eventMap->DrawCopy("same,box");
canv->Update();
rootapp->Run();
return Success;
}
void EventDisplay::finalise() {}
#ifndef EVENTDISPLAY_H
#define EVENTDISPLAY_H 1
#include <iostream>
#include "TCanvas.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TH3F.h"
#include "core/Algorithm.h"
#include "objects/Timepix3Cluster.h"
#include "objects/Timepix3Pixel.h"
#include "objects/Timepix3Track.h"
namespace corryvreckan {
class EventDisplay : public Algorithm {
public:
// Constructors and destructors
EventDisplay(Configuration config, Clipboard* clipboard);
~EventDisplay() {}
// Functions
void initialise(Parameters*);
StatusCode run(Clipboard*);
void finalise();
TH3F* eventMap;
};
}
#endif // EVENTDISPLAY_H
#include "FileReader.h"
#include "objects/Timepix3Cluster.h"
#include "objects/Timepix3Pixel.h"
#include "objects/Timepix3Track.h"
using namespace corryvreckan;
using namespace std;
......@@ -81,7 +78,6 @@ void FileReader::initialise(Parameters* par) {
m_inputTrees[objectID]->SetBranchAddress("time", &m_time);
// Cast the TestBeamObject as a specific type using a Factory
// This will return a Timepix1Pixel*, Timepix3Pixel* etc.
m_objects[objectID] = TestBeamObject::Factory(detectorType, objectType);
m_inputTrees[objectID]->SetBranchAddress(objectType.c_str(), &m_objects[objectID]);
m_currentPosition[objectID] = 0;
......
......@@ -4,7 +4,6 @@
// Local include files
#include "Analysis.h"
#include "objects/Timepix3Track.h"
#include "utils/log.h"
#include <dlfcn.h>
......@@ -320,14 +319,6 @@ void Analysis::run() {
if(check == Failure)
run = false;
}
// Count number of tracks produced
// Timepix3Tracks* tracks =
// (Timepix3Tracks*)m_clipboard->get("Timepix3","tracks");
// if(tracks != NULL) nTracks += tracks->size();
// LOG(DEBUG) << "\r[Analysis] Current time is
// "<<fixed<<setw(10)<<m_parameters->currentTime<<". Produced
// "<<nTracks<<" tracks"<<flush;
// Clear objects from this iteration from the clipboard
m_clipboard->clear();
......
......@@ -19,13 +19,9 @@ ROOT_GENERATE_DICTIONARY(CorryvreckanObjectsDictionary
${CMAKE_CURRENT_SOURCE_DIR}/Cluster.h
${CMAKE_CURRENT_SOURCE_DIR}/GuiDisplay.h
${CMAKE_CURRENT_SOURCE_DIR}/KDTree.h
${CMAKE_CURRENT_SOURCE_DIR}/KDTreeTimepix3.h
${CMAKE_CURRENT_SOURCE_DIR}/Pixel.h
${CMAKE_CURRENT_SOURCE_DIR}/SpidrSignal.h
${CMAKE_CURRENT_SOURCE_DIR}/TestBeamObject.h
${CMAKE_CURRENT_SOURCE_DIR}/Timepix3Cluster.h
${CMAKE_CURRENT_SOURCE_DIR}/Timepix3Pixel.h
${CMAKE_CURRENT_SOURCE_DIR}/Timepix3Track.h
${CMAKE_CURRENT_SOURCE_DIR}/Track.h
MODULE
CorryvreckanObjects
......
#ifndef KDTREE_TIMEPIX3_H
#define KDTREE_TIMEPIX3_H 1
#include <map>
#include "TKDTree.h"
#include "TestBeamObject.h"
#include "Timepix3Cluster.h"
#include "core/utils/log.h"
// This class is effectively just a wrapper for the root TKDTree class that
// handles Timepix3 clusters and converts them into the format needed by
// ROOT.
class KDTreeTimepix3 : public TestBeamObject {
public:
// Constructors and destructors
KDTreeTimepix3() {}
virtual ~KDTreeTimepix3() {
// delete timeKdtree;
// delete times;
}
// Constructor with Timepix3Cluster data
KDTreeTimepix3(Timepix3Clusters inputClusters) {
// Store the vector of cluster pointers
clusters = inputClusters;
// Create the data for the ROOT KDTree
int npoints = clusters.size();
// xpositions = new double[npoints];
// ypositions = new double[npoints];
times = new double[npoints];
// Fill the x and y data from the global cluster positions
for(int cluster = 0; cluster < npoints; cluster++) {
// xpositions[cluster] = clusters[cluster]->globalX();
// ypositions[cluster] = clusters[cluster]->globalY();
times[cluster] = double(clusters[cluster]->timestamp()) / (4096. * 40000000.);
iteratorNumber[clusters[cluster]] = cluster;
}
// Place the data into the trees and build the structure
// positionKdtree = new TKDTreeID(npoints,2,1);
// positionKdtree->SetData(0,xpositions);
// positionKdtree->SetData(1,ypositions);
// positionKdtree->Build();
timeKdtree = new TKDTreeID(npoints, 1, 1);
timeKdtree->SetData(0, times);
timeKdtree->Build();
timeKdtree->SetOwner(kTRUE);
}
// Function to get back all clusters within a given time period
Timepix3Clusters getAllClustersInTimeWindow(Timepix3Cluster* cluster, double timeWindow) {
LOG(TRACE) << "Getting all clusters in time window" << timeWindow;
// Find out which iterator number this cluster corresponds to
// int iterator = iteratorNumber[cluster];
// Get iterators of all clusters within the time window
std::vector<int> results;
double* time;
time[0] = double(cluster->timestamp()) / (4096. * 40000000.);
timeKdtree->FindInRange(time, timeWindow, results);
LOG(TRACE) << " -- found: " << results.size();
// Turn this into a vector of clusters
Timepix3Clusters resultClusters;
// delete time;
for(int res = 0; res < results.size(); res++)
resultClusters.push_back(clusters[results[res]]);
// Return the vector of clusters
return resultClusters;
}
// Member variables
double* xpositions; //!
double* ypositions; //!
double* times; //!
TKDTreeID* positionKdtree;
TKDTreeID* timeKdtree;
Timepix3Clusters clusters;
std::map<Timepix3Cluster*, int> iteratorNumber;
// ROOT I/O class definition - update version number when you change this
// class!
ClassDef(KDTreeTimepix3, 1)
};
#endif // KDTREE_TIMEPIX3_H
#ifndef TIMEPIX3CLUSTER_H
#define TIMEPIX3CLUSTER_H 1
#include <iostream>
#include "Timepix3Pixel.h"
class Timepix3Cluster : public TestBeamObject {
public:
// Constructors and destructors
Timepix3Cluster() {}
virtual ~Timepix3Cluster() {}
// Copy constructor
Timepix3Cluster(Timepix3Cluster* cluster) {
m_globalX = cluster->globalX();
m_globalY = cluster->globalY();
m_globalZ = cluster->globalZ();
m_localX = cluster->localX();
m_localY = cluster->localY();
m_localZ = cluster->localZ();
m_error = cluster->error();
m_detectorID = cluster->detectorID();
m_timestamp = cluster->timestamp();
}
// Functions
// Add a new pixel to the cluster
void addPixel(Timepix3Pixel* pixel) { m_pixels.push_back(pixel); }
// Retrieve cluster parameters
double row() { return m_row; }
double column() { return m_column; }
double tot() { return m_tot; }
double error() { return m_error; }
double globalX() { return m_globalX; }
double globalY() { return m_globalY; }
double globalZ() { return m_globalZ; }
double localX() { return m_localX; }
double localY() { return m_localY; }
double localZ() { return m_localZ; }
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; }
// Set cluster parameters
void setRow(double row) { m_row = row; }
void setColumn(double col) { m_column = col; }
void setTot(double tot) { m_tot = tot; }
void setClusterCentre(double x, double y, double z) {
m_globalX = x;
m_globalY = y;
m_globalZ = z;
}
void setClusterCentreLocal(double x, double y, double z) {
m_localX = x;
m_localY = y;
m_localZ = z;
}
void setError(double error) { m_error = error; }
void setTimestamp(long long int timestamp) { m_timestamp = timestamp; }
void setDetectorID(std::string detectorID) { m_detectorID = detectorID; }
// Member variables
Timepix3Pixels m_pixels;
double m_row;
double m_column;
double m_tot;
double m_error;
long long int m_timestamp;
double m_globalX;
double m_globalY;
double m_globalZ;
double m_localX;
double m_localY;
double m_localZ;
std::string m_detectorID;
// ROOT I/O class definition - update version number when you change this
// class!
ClassDef(Timepix3Cluster, 1)
};
// Vector type declaration
typedef std::vector<Timepix3Cluster*> Timepix3Clusters;
#endif // TIMEPIX3CLUSTER_H
#ifndef TIMEPIX3PIXEL_H
#define TIMEPIX3PIXEL_H 1
#include "Pixel.h"
class Timepix3Pixel : public TestBeamObject {
public:
// Constructors and destructors
Timepix3Pixel() {}
virtual ~Timepix3Pixel() {}
Timepix3Pixel(std::string detectorID, int row, int col, int tot, long long int time) {
m_detectorID = detectorID;
m_row = row;
m_column = col;
m_adc = tot;
m_timestamp = time;
}
// Member variables
int m_row;
int m_column;
int m_adc;
// ROOT I/O class definition - update version number when you change this
// class!
ClassDef(Timepix3Pixel, 1)
};
// Vector type declaration
typedef std::vector<Timepix3Pixel*> Timepix3Pixels;
#endif // TIMEPIX3PIXEL_H
#ifndef TIMEPIX3TRACK_H
#define TIMEPIX3TRACK_H 1
#include "Math/Point3D.h"
#include "Math/Vector3D.h"
#include "TLinearFitter.h"
#include "Timepix3Cluster.h"
class Timepix3Track : public TestBeamObject {
public:
// Constructors and destructors
Timepix3Track() {
m_fitterXZ = new TLinearFitter();
m_fitterXZ->SetFormula("pol1");
m_fitterYZ = new TLinearFitter();
m_fitterYZ->SetFormula("pol1");
}
virtual ~Timepix3Track() {
delete m_fitterXZ;
delete m_fitterYZ;
}
// Copy constructor (also copies clusters from the original track)
Timepix3Track(Timepix3Track* track) {
m_fitterXZ = new TLinearFitter();
m_fitterXZ->SetFormula("pol1");
m_fitterYZ = new TLinearFitter();
m_fitterYZ->SetFormula("pol1");
for(auto& track_cluster : track->clusters()) {
Timepix3Cluster* cluster = new Timepix3Cluster(track_cluster);
m_trackClusters.push_back(cluster);
}
for(auto& assoc_cluster : track->associatedClusters()) {
Timepix3Cluster* cluster = new Timepix3Cluster(assoc_cluster);
m_associatedClusters.push_back(cluster);
}
m_state = track->m_state;
m_direction = track->m_direction;
}
// -----------
// Functions
// -----------
// Add a new cluster to the track
void addCluster(Timepix3Cluster* cluster) { m_trackClusters.push_back(cluster); }
void addAssociatedCluster(Timepix3Cluster* cluster) { m_associatedClusters.push_back(cluster); }
// Fit the track
void fit() {
m_fitterXZ->ClearPoints();
m_fitterYZ->ClearPoints();
// Loop over all clusters
double* z = new double[0];
for(auto& cluster : m_trackClusters) {
// Add it to the fitter
z[0] = cluster->globalZ();
m_fitterXZ->AddPoint(z, cluster->globalX(), cluster->error());
m_fitterYZ->AddPoint(z, cluster->globalY(), cluster->error());
}
// Fit the two lines
m_fitterXZ->Eval();
m_fitterYZ->Eval();
// Get the slope and intercept
double interceptXZ = m_fitterXZ->GetParameter(0);
double slopeXZ = m_fitterXZ->GetParameter(1);
double interceptYZ = m_fitterYZ->GetParameter(0);
double slopeYZ = m_fitterYZ->GetParameter(1);
// Set the track state and direction
m_state.SetX(interceptXZ);
m_state.SetY(interceptYZ);
m_state.SetZ(0.);
m_direction.SetX(slopeXZ);
m_direction.SetY(slopeYZ);
m_direction.SetZ(1.);
delete z;
this->calculateChi2();
}
// Calculate the 2D distance^2 between the fitted track and a cluster
double distance2(Timepix3Cluster* cluster) {
// Get the track X and Y at the cluster z position
double trackX = m_state.X() + m_direction.X() * cluster->globalZ();
double trackY = m_state.Y() + m_direction.Y() * cluster->globalZ();
// Calculate the 1D residuals
double dx = (trackX - cluster->globalX());
double dy = (trackY - cluster->globalY());
// Return the distance^2
return (dx * dx + dy * dy);
}
// Calculate the chi2 of the track
void calculateChi2() {
m_ndof = static_cast<double>(m_trackClusters.size()) - 2.;
m_chi2 = 0.;
m_chi2ndof = 0.;
// Loop over all clusters
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);
}
// Store also the chi2/degrees of freedom
m_chi2ndof = m_chi2 / m_ndof;
}
// Retrieve track parameters
double chi2() { return m_chi2; }
double chi2ndof() { return m_chi2ndof; }
double ndof() { return m_ndof; }
long long int timestamp() { return m_timestamp; }
Timepix3Clusters clusters() { return m_trackClusters; }
Timepix3Clusters associatedClusters() { return m_associatedClusters; }
size_t nClusters() { return m_trackClusters.size(); }
ROOT::Math::XYZPoint intercept(double z) {
ROOT::Math::XYZPoint point = m_state + m_direction * z;
return point;
}
// Set track parameters
void setTimestamp(long long int timestamp) { m_timestamp = timestamp; }
// Member variables
Timepix3Clusters m_trackClusters;
Timepix3Clusters m_associatedClusters;
long long int m_timestamp;
double m_chi2;
double m_ndof;
double m_chi2ndof;
TLinearFitter* m_fitterXZ;
TLinearFitter* m_fitterYZ;
ROOT::Math::XYZPoint m_state;
ROOT::Math::XYZVector m_direction;
// ROOT I/O class definition - update version number when you change this
// class!
ClassDef(Timepix3Track, 1)
};
// Vector type declaration
typedef std::vector<Timepix3Track*> Timepix3Tracks;
#endif // TIMEPIX3TRACK_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