Commit c54845ab authored by Daniel Hynds's avatar Daniel Hynds
Browse files

updated timepix1 code to use generic base class objects


Former-commit-id: 1a0dc794068d1800d2fcd5050b35f391efca4e69
parent b496881e
#include "SpatialTracking.h"
#include "Timepix1Cluster.h"
#include "Timepix1Track.h"
#include "KDTreeTimepix1.h"
#include "KDTree.h"
SpatialTracking::SpatialTracking(bool debugging)
: Algorithm("SpatialTracking"){
......@@ -31,7 +29,7 @@ void SpatialTracking::initialise(Parameters* par){
trackAngleX = new TH1F("trackAngleX","trackAngleX",2000,-0.01,0.01);
trackAngleY = new TH1F("trackAngleY","trackAngleY",2000,-0.01,0.01);
// Loop over all Timepix3
// Loop over all Timepix1
for(int det = 0; det<parameters->nDetectors; det++){
// Check if they are a Timepix3
string detectorID = parameters->detectors[det];
......@@ -40,8 +38,6 @@ void SpatialTracking::initialise(Parameters* par){
residualsX[detectorID] = new TH1F(name.c_str(),name.c_str(),400,-0.05,0.05);
name = "residualsY_"+detectorID;
residualsY[detectorID] = new TH1F(name.c_str(),name.c_str(),400,-0.05,0.05);
tcout<<"Detector "<<detectorID<<": (x,y,z) = ("<<parameters->detector[detectorID]->displacementX()<<","<<parameters->detector[detectorID]->displacementY()<<","<<parameters->detector[detectorID]->displacementZ()<<") (rx,ry,rz) = ("<<parameters->detector[detectorID]->rotationX()<<","<<parameters->detector[detectorID]->rotationY()<<","<<parameters->detector[detectorID]->rotationZ()<<")"<<endl;
}
// Initialise member variables
......@@ -52,12 +48,12 @@ void SpatialTracking::initialise(Parameters* par){
StatusCode SpatialTracking::run(Clipboard* clipboard){
// Container for all clusters, and detectors in tracking
map<string,KDTreeTimepix1> trees;
map<string,KDTree> trees;
vector<string> detectors;
Timepix1Clusters* referenceClusters;
Clusters* referenceClusters;
// Output track container
Timepix1Tracks* tracks = new Timepix1Tracks();
Tracks* tracks = new Tracks();
// Loop over all Timepix1 and get clusters
double minZ = 1000.;
......@@ -68,7 +64,7 @@ StatusCode SpatialTracking::run(Clipboard* clipboard){
if(parameters->detector[detectorID]->type() != "Timepix1") continue;
// Get the clusters
Timepix1Clusters* tempClusters = (Timepix1Clusters*)clipboard->get(detectorID,"clusters");
Clusters* tempClusters = (Clusters*)clipboard->get(detectorID,"clusters");
if(tempClusters == NULL){
if(debug) tcout<<"Detector "<<detectorID<<" does not have any clusters on the clipboard"<<endl;
}else{
......@@ -80,7 +76,8 @@ StatusCode SpatialTracking::run(Clipboard* clipboard){
if(tempClusters->size() == 0) continue;
// Make trees of the clusters on each plane
KDTreeTimepix1 clusterTree(*tempClusters);
KDTree clusterTree;
clusterTree.buildSpatialTree(*tempClusters);
trees[detectorID] = clusterTree;
detectors.push_back(detectorID);
if(debug) tcout<<"Picked up "<<tempClusters->size()<<" clusters on device "<<detectorID<<endl;
......@@ -91,7 +88,7 @@ StatusCode SpatialTracking::run(Clipboard* clipboard){
if(detectors.size() == 0) return Success;
// Keep a note of which clusters have been used
map<Timepix1Cluster*, bool> used;
map<Cluster*, bool> used;
// Loop over all clusters
int nSeedClusters = referenceClusters->size();
......@@ -100,10 +97,10 @@ StatusCode SpatialTracking::run(Clipboard* clipboard){
if(debug) tcout<<"==> seed cluster "<<iSeedCluster<<endl;
// Make a new track
Timepix1Track* track = new Timepix1Track();
Track* track = new Track();
// Get the cluster
Timepix1Cluster* cluster = (*referenceClusters)[iSeedCluster];
Cluster* cluster = (*referenceClusters)[iSeedCluster];
// Add the cluster to the track
track->addCluster(cluster);
......@@ -123,7 +120,7 @@ StatusCode SpatialTracking::run(Clipboard* clipboard){
// Get the closest neighbour
if(debug)tcout<<"- looking for nearest cluster on device "<<detectors[det]<<endl;
Timepix1Cluster* closestCluster = trees[detectors[det]].getClosestNeighbour(cluster);
Cluster* closestCluster = trees[detectors[det]].getClosestNeighbour(cluster);
// If it is used do nothing
// if(used[closestCluster]) continue;
......@@ -158,9 +155,9 @@ StatusCode SpatialTracking::run(Clipboard* clipboard){
trackAngleY->Fill(atan(track->m_direction.Y()));
// Make residuals
Timepix1Clusters trackClusters = track->clusters();
Clusters trackClusters = track->clusters();
for(int iTrackCluster=0; iTrackCluster<trackClusters.size(); iTrackCluster++){
Timepix1Cluster* trackCluster = trackClusters[iTrackCluster];
Cluster* trackCluster = trackClusters[iTrackCluster];
string detectorID = trackCluster->detectorID();
ROOT::Math::XYZPoint intercept = track->intercept(trackCluster->globalZ());
residualsX[detectorID]->Fill(intercept.X() - trackCluster->globalX());
......@@ -175,7 +172,7 @@ StatusCode SpatialTracking::run(Clipboard* clipboard){
if(debug) tcout<<"- produced "<<tracks->size()<<" tracks"<<endl;
tracksPerEvent->Fill(tracks->size());
if(tracks->size() > 0){
clipboard->put("Timepix1","tracks",(TestBeamObjects*)tracks);
clipboard->put("tracks",(TestBeamObjects*)tracks);
}
return Success;
......
......@@ -6,8 +6,8 @@
#include "TH1F.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "Timepix1Cluster.h"
#include "Timepix1Track.h"
#include "Cluster.h"
#include "Track.h"
class SpatialTracking : public Algorithm {
......
#include "Timepix1Clustering.h"
#include "Timepix1Pixel.h"
#include "Timepix1Cluster.h"
#include "Pixel.h"
Timepix1Clustering::Timepix1Clustering(bool debugging)
: Algorithm("Timepix1Clustering"){
......@@ -43,7 +42,7 @@ StatusCode Timepix1Clustering::run(Clipboard* clipboard){
if(parameters->detector[detectorID]->type() != "Timepix1") continue;
// Get the pixels
Timepix1Pixels* pixels = (Timepix1Pixels*)clipboard->get(detectorID,"pixels");
Pixels* pixels = (Pixels*)clipboard->get(detectorID,"pixels");
if(pixels == NULL){
if(debug) tcout<<"Detector "<<detectorID<<" does not have any pixels on the clipboard"<<endl;
continue;
......@@ -51,8 +50,8 @@ StatusCode Timepix1Clustering::run(Clipboard* clipboard){
// Make the cluster container and the maps for clustering
TestBeamObjects* deviceClusters = new TestBeamObjects();
map<Timepix1Pixel*,bool> used;
map<int, map<int,Timepix1Pixel*> > hitmap;
map<Pixel*,bool> used;
map<int, map<int,Pixel*> > hitmap;
bool addedPixel;
// Get the device dimensions
......@@ -61,7 +60,7 @@ StatusCode Timepix1Clustering::run(Clipboard* clipboard){
// Fill the hitmap with pixels
for(int iP=0;iP<pixels->size();iP++){
Timepix1Pixel* pixel = (Timepix1Pixel*)(*pixels)[iP];
Pixel* pixel = (Pixel*)(*pixels)[iP];
hitmap[pixel->m_row][pixel->m_column] = pixel;
}
......@@ -69,12 +68,12 @@ StatusCode Timepix1Clustering::run(Clipboard* clipboard){
for(int iP=0;iP<pixels->size();iP++){
// Get the pixel. If it is already used then do nothing
Timepix1Pixel* pixel = (Timepix1Pixel*)(*pixels)[iP];
Pixel* pixel = (Pixel*)(*pixels)[iP];
// tcout<<"==> seed pixel row, col: "<<pixel->m_row<<","<<pixel->m_column<<endl;
if(used[pixel]) continue;
// New pixel => new cluster
Timepix1Cluster* cluster = new Timepix1Cluster();
Cluster* cluster = new Cluster();
cluster->addPixel(pixel);
used[pixel] = true;
addedPixel = true;
......@@ -110,7 +109,6 @@ StatusCode Timepix1Clustering::run(Clipboard* clipboard){
// Finalise the cluster and save it
calculateClusterCentre(cluster);
// tcout<<"cluster size "<<cluster->size()<<endl;
deviceClusters->push_back(cluster);
}
......@@ -138,17 +136,17 @@ void Timepix1Clustering::finalise(){
Function to calculate the centre of gravity of a cluster.
Sets the local and global cluster positions as well.
*/
void Timepix1Clustering::calculateClusterCentre(Timepix1Cluster* cluster){
void Timepix1Clustering::calculateClusterCentre(Cluster* cluster){
if(debug)tcout<<"== Making cluster centre"<<endl;
// Empty variables to calculate cluster position
double row(0), column(0), tot(0);
// Get the pixels on this cluster
Timepix1Pixels pixels = cluster->pixels();
Pixels pixels = cluster->pixels();
string detectorID = pixels[0]->m_detectorID;
if(debug)tcout<<"- cluster has "<<pixels.size()<<" pixels"<<endl;
// Loop over all pixels
for(int pix=0; pix<pixels.size(); pix++){
tot += pixels[pix]->m_adc;
......
......@@ -6,7 +6,7 @@
#include "TH1F.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "Timepix1Cluster.h"
#include "Cluster.h"
class Timepix1Clustering : public Algorithm {
......@@ -20,7 +20,7 @@ public:
StatusCode run(Clipboard*);
void finalise();
void calculateClusterCentre(Timepix1Cluster*);
void calculateClusterCentre(Cluster*);
// Member variables
int m_eventNumber;
......
#include "Timepix1Correlator.h"
#include "Timepix1Pixel.h"
#include "Timepix1Cluster.h"
#include "Timepix1Track.h"
#include "Pixel.h"
#include "Cluster.h"
#include "Track.h"
Timepix1Correlator::Timepix1Correlator(bool debugging)
: Algorithm("Timepix1Correlator"){
......@@ -52,7 +52,7 @@ StatusCode Timepix1Correlator::run(Clipboard* clipboard){
// Get the clusters for the reference detector
string referenceDetector = parameters->reference;
Timepix1Clusters* referenceClusters = (Timepix1Clusters*)clipboard->get(referenceDetector,"clusters");
Clusters* referenceClusters = (Clusters*)clipboard->get(referenceDetector,"clusters");
if(referenceClusters == NULL){
if(debug) tcout<<"Detector "<<referenceDetector<<" does not have any clusters on the clipboard"<<endl;
return Success;
......@@ -61,12 +61,12 @@ StatusCode Timepix1Correlator::run(Clipboard* clipboard){
// Loop over all Timepix1 and make plots
for(int det = 0; det<parameters->nDetectors; det++){
// Check if they are a Timepix3
// Check if they are a Timepix1
string detectorID = parameters->detectors[det];
if(parameters->detector[detectorID]->type() != "Timepix1") continue;
// Get the clusters
Timepix1Clusters* clusters = (Timepix1Clusters*)clipboard->get(detectorID,"clusters");
Clusters* clusters = (Clusters*)clipboard->get(detectorID,"clusters");
if(clusters == NULL){
if(debug) tcout<<"Detector "<<detectorID<<" does not have any clusters on the clipboard"<<endl;
continue;
......@@ -76,12 +76,12 @@ StatusCode Timepix1Correlator::run(Clipboard* clipboard){
for(int itCluster=0;itCluster<clusters->size();itCluster++){
// Get the cluster
Timepix1Cluster* cluster = (*clusters)[itCluster];
Cluster* cluster = (*clusters)[itCluster];
for(int itRefCluster=0;itRefCluster<referenceClusters->size();itRefCluster++){
// Get the reference cluster
Timepix1Cluster* refCluster = (*referenceClusters)[itRefCluster];
Cluster* refCluster = (*referenceClusters)[itRefCluster];
// Fill the plots for this device
if(fabs(cluster->globalY()-refCluster->globalY()) < 1.) correlationPlotsX[detectorID]->Fill(cluster->globalX()-refCluster->globalX());
......
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