Commit 0dc0d0be authored by Daniel Hynds's avatar Daniel Hynds
Browse files

added generic algorithm and macro for quickly producing new algorithms


Former-commit-id: dada8c68be73644c65015f79370a4d80bfbbf8d0
parent 60543cf2
#include "GenericAlgorithm.h"
#include "Timepix3Pixel.h"
#include "Timepix3Cluster.h"
#include "Timepix3Track.h"
GenericAlgorithm::GenericAlgorithm(bool debugging)
: Algorithm("GenericAlgorithm"){
debug = debugging;
}
void GenericAlgorithm::initialise(Parameters* par){
parameters = par;
// Initialise histograms per device
for(int det = 0; det<parameters->nDetectors; det++){
// Check if they are a Timepix3
string detectorID = parameters->detectors[det];
if(parameters->detector[detectorID]->type() != "Timepix3") continue;
// Simple histogram per device
string name = "plotForDevice_"+detectorID;
plotPerDevice[detectorID] = new TH2F(name.c_str(),name.c_str(),256,0,256,256,0,256);
}
// Initialise single histograms
string name = "singlePlot";
singlePlot = new TH1F(name.c_str(),name.c_str(),1000,0,1000);
// Initialise member variables
m_eventNumber = 0;
}
int GenericAlgorithm::run(Clipboard* clipboard){
// Loop over all Timepix3 and make plots
for(int det = 0; det<parameters->nDetectors; det++){
// Check if they are a Timepix3
string detectorID = parameters->detectors[det];
if(parameters->detector[detectorID]->type() != "Timepix3") continue;
// Get the pixels
Timepix3Pixels* pixels = (Timepix3Pixels*)clipboard->get(detectorID,"pixels");
if(pixels == NULL){
if(debug) tcout<<"Detector "<<detectorID<<" does not have any pixels on the clipboard"<<endl;
continue;
}
// Get the clusters
Timepix3Clusters* clusters = (Timepix3Clusters*)clipboard->get(detectorID,"clusters");
if(clusters == NULL){
if(debug) tcout<<"Detector "<<detectorID<<" does not have any clusters on the clipboard"<<endl;
continue;
}
// Loop over all pixels and make hitmaps
for(int iP=0;iP<pixels->size();iP++){
// Get the pixel
Timepix3Pixel* pixel = (*pixels)[iP];
// Fill the plots for this device
plotPerDevice[detectorID]->Fill(pixel->m_column,pixel->m_row);
}
}
// Fill single histogram
singlePlot->Fill(m_eventNumber);
// Increment event counter
m_eventNumber++;
// Return value telling analysis to keep running
return 1;
}
void GenericAlgorithm::finalise(){
if(debug) tcout<<"Analysed "<<m_eventNumber<<" events"<<endl;
}
#ifndef GenericAlgorithm_H
#define GenericAlgorithm_H 1
#include "Algorithm.h"
#include <iostream>
#include "TH1F.h"
#include "TH2F.h"
#include "TCanvas.h"
class GenericAlgorithm : public Algorithm {
public:
// Constructors and destructors
GenericAlgorithm(bool);
~GenericAlgorithm(){}
// Functions
void initialise(Parameters*);
int run(Clipboard*);
void finalise();
// Histograms for several devices
map<string, TH2F*> plotPerDevice;
// Single histograms
TH1F* singlePlot;
// Member variables
int m_eventNumber;
};
#endif // GenericAlgorithm_H
#!/bin/bash
# Check that only one argument was given
ARGS=1
if [ $# -ne "$ARGS" ]
then
echo "Please enter the new algorithm name"
exit
fi
# Copy the GenericAlgorithm and replace the name with the new algorithm name
NEWALGORITHM=$1
cp ../algorithms/GenericAlgorithm.C ../algorithms/${NEWALGORITHM}.C
cp ../algorithms/GenericAlgorithm.h ../algorithms/${NEWALGORITHM}.h
# If running on mac, use this sed command
sed -i "" s/"GenericAlgorithm"/"${NEWALGORITHM}"/g ../algorithms/${NEWALGORITHM}.C
sed -i "" s/"GenericAlgorithm"/"${NEWALGORITHM}"/g ../algorithms/${NEWALGORITHM}.h
# If running on linux, use this command
#sed -i s/"GenericAlgorithm"/"${NEWALGORITHM}"/g ../algorithms/${NEWALGORITHM}.C
#sed -i s/"GenericAlgorithm"/"${NEWALGORITHM}"/g ../algorithms/${NEWALGORITHM}.C
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