Commit 3a70ae68 authored by Daniel Hynds's avatar Daniel Hynds
Browse files

Merge branch 'master' of ssh://gitlab.cern.ch:7999/CLICdp/tbAnalysis


Former-commit-id: 6c25b8ee8a00f959ab011b72a509d3099f58ca4a
parents 74677ecf 4df16563
......@@ -9,7 +9,7 @@ BasicTracking::BasicTracking(bool debugging)
// Default values for cuts
timingCut = 200./1000000000.; // 200 ns
spatialCut = 0.2; // 200 um
minHitsOnTrack = 4;
minHitsOnTrack = 6;
}
......
......@@ -8,11 +8,11 @@ CLICpixEventLoader::CLICpixEventLoader(bool debugging)
void CLICpixEventLoader::initialise(Parameters* par){
parameters = par;
// File structure is RunX/CLICpix/RunX.dat
// Take input directory from global parameters
string inputDirectory = parameters->inputDirectory + "/CLICpix";
......@@ -35,11 +35,18 @@ void CLICpixEventLoader::initialise(Parameters* par){
// Open the data file for later
m_file.open(m_filename.c_str());
// Make histograms for debugging
hHitMap = new TH2F("hitMap","hitMap",64,0,64,64,0,64);
hPixelToT = new TH1F("pixelToT","pixelToT",20,0,20);
hShutterLength = new TH1F("shutterLength","shutterLength",3000,0,0.3);
hPixelsPerFrame = new TH1F("pixelsPerFrame","pixelsPerFrame",4100,0,4100);
}
StatusCode CLICpixEventLoader::run(Clipboard* clipboard){
// tcout<<"Running"<<endl;
// Assume that the CLICpix is the DUT (if running this algorithm
string detectorID = parameters->DUT;
......@@ -52,15 +59,18 @@ StatusCode CLICpixEventLoader::run(Clipboard* clipboard){
// Otherwise load a new frame
// Pixel container, shutter information
Pixels* pixels;
Pixels* pixels = new Pixels();
long double shutterStartTime, shutterStopTime;
string data;
int npixels=0;
// Read file and load data
while(getline(m_file,data)){
while(getline(m_file,data)){
// tcout<<"Data: "<<data<<endl;
// If line is empty then we have finished this event, stop looping
if(data.length() == 0) break;
if(data.length() < 5) break;
// Check if this is a header/shutter/power info
if(data.find("PWR_RISE") != string::npos || data.find("PWR_FALL") != string::npos) continue;
......@@ -69,7 +79,8 @@ StatusCode CLICpixEventLoader::run(Clipboard* clipboard){
long int timeInt; string name;
istringstream header(data);
header >> name >> timeInt;
shutterStartTime = (double)timeInt/(4096. * 40000000.);
shutterStartTime = (double)timeInt/(40000000.);
// tcout<<"Shutter rise time: "<<shutterStartTime<<endl;
continue;
}
if(data.find("SHT_FALL") != string::npos){
......@@ -77,27 +88,43 @@ StatusCode CLICpixEventLoader::run(Clipboard* clipboard){
long int timeInt; string name;
istringstream header(data);
header >> name >> timeInt;
shutterStopTime = (double)timeInt/(4096. * 40000000.);
shutterStopTime = (double)timeInt/(40000000.);
// tcout<<"Shutter fall time: "<<shutterStopTime<<endl;
continue;
}
// Otherwise load data
int row, col, tot;
int row, col, counter, tot(0);
long int time;
// tcout<<"Pixel data: "<<data<<endl;
istringstream pixelData(data);
pixelData >> col >> row >> tot;
Pixel* pixel = new Pixel(detectorID,row,col,tot);
pixels->push_back(pixel);
pixelData >> col >> row >> counter >> tot;
tot++;
row=63-row;
// tcout<<"New pixe: "<<col<<","<<row<<" with tot "<<tot<<endl;
// If this pixel is masked, do not save it
if(parameters->detector[detectorID]->masked(col,row)) continue;
Pixel* pixel = new Pixel(detectorID,row,col,tot,0);
pixels->push_back(pixel);
npixels++;
hHitMap->Fill(col,row);
hPixelToT->Fill(tot);
}
// Now set the event time so that the Timepix3 data is loaded correctly
parameters->currentTime = shutterStartTime;
parameters->eventLength = (shutterStopTime-shutterStartTime);
// tcout<<"Loaded "<<npixels<<" pixels"<<endl;
// Put the data on the clipboard
clipboard->put(detectorID,"pixels",(TestBeamObjects*)pixels);
if(pixels->size() > 0) clipboard->put(detectorID,"pixels",(TestBeamObjects*)pixels);
// Fill histograms
hPixelsPerFrame->Fill(npixels);
hShutterLength->Fill(shutterStopTime-shutterStartTime);
// Return value telling analysis to keep running
return Success;
}
......
......@@ -31,6 +31,11 @@ public:
string m_filename;
ifstream m_file;
TH2F* hHitMap;
TH1F* hPixelToT;
TH1F* hShutterLength;
TH1F* hPixelsPerFrame;
};
#endif // CLICpixEventLoader_H
......@@ -7,7 +7,7 @@ ClicpixAnalysis::ClicpixAnalysis(bool debugging)
: Algorithm("ClicpixAnalysis"){
debug = debugging;
m_associationCut = 0.1; // 100 um
m_proximityCut = 0.125; // 125 um
m_proximityCut = 0.00001; // 125 um
timepix3Telescope = false;
}
......@@ -103,6 +103,7 @@ void ClicpixAnalysis::initialise(Parameters* par){
hTrackInterceptsPixelAssociated = new TH2F("hTrackInterceptsPixelAssociated","hTrackInterceptsPixelAssociated",50,0,50,25,0,25);
hTrackInterceptsChip = new TH2F("hTrackInterceptsChip","hTrackInterceptsChip",65,-0.5,64.5,65,-0.5,64.5);
hTrackInterceptsChipAssociated = new TH2F("hTrackInterceptsChipAssociated","hTrackInterceptsChipAssociated",65,-0.5,64.5,65,-0.5,64.5);
hTrackInterceptsChipUnassociated = new TH2F("hTrackInterceptsChipUnassociated","hTrackInterceptsChipUnassociated",65,-0.5,64.5,65,-0.5,64.5);
hTrackInterceptsChipLost = new TH2F("hTrackInterceptsChipLost","hTrackInterceptsChipLost",65,-0.5,64.5,65,-0.5,64.5);
hPixelEfficiencyMap = new TH2F("hPixelEfficiencyMap","hPixelEfficiencyMap",50,0,50,25,0,25);
......@@ -121,13 +122,6 @@ void ClicpixAnalysis::initialise(Parameters* par){
StatusCode ClicpixAnalysis::run(Clipboard* clipboard){
// Get the tracks in this event
Tracks* tracks = (Tracks*)clipboard->get("tracks");
if(tracks == NULL){
if(debug) tcout<<"No tracks on the clipboard"<<endl;
return Success;
}
// Get the clicpix clusters in this event
Clusters* clusters = (Clusters*)clipboard->get(dutID,"clusters");
if(clusters == NULL){
......@@ -145,6 +139,13 @@ StatusCode ClicpixAnalysis::run(Clipboard* clipboard){
// Fill the histograms that only need clusters/pixels
fillClusterHistos(clusters);
// Get the tracks in this event
Tracks* tracks = (Tracks*)clipboard->get("tracks");
if(tracks == NULL){
if(debug) tcout<<"No tracks on the clipboard"<<endl;
return Success;
}
//Set counters
double nClustersAssociated=0, nValidTracks=0;
......@@ -280,13 +281,15 @@ StatusCode ClicpixAnalysis::run(Clipboard* clipboard){
// Search for lost hits. Basically loop through all pixels in all clusters and see if any are close.
// Large clusters (such as from deltas) can pull the cluster centre sufficiently far from the track
bool pixelMatch = false; int size=0;
for (itCorrelate = clusters->begin(); itCorrelate != clusters->end(); ++itCorrelate) {
/* for (itCorrelate = clusters->begin(); itCorrelate != clusters->end(); ++itCorrelate) {
if(pixelMatch) break;
// Loop over pixels
Pixels::const_iterator itPixel;
for (itPixel = (*itCorrelate)->pixels().begin(); itPixel != (*itCorrelate)->pixels().end(); itPixel++) {
// Get the pixel global position
tcout<<"New pixel"<<endl;
tcout<<"Row = "<<(*itPixel)->m_row<<", column = "<<(*itPixel)->m_column<<endl;
PositionVector3D<Cartesian3D<double> > pixelPositionLocal = parameters->detector[dutID]->getLocalPosition((*itPixel)->m_row,(*itPixel)->m_column);
PositionVector3D<Cartesian3D<double> > pixelPositionGlobal = *(parameters->detector[dutID]->m_localToGlobal) * pixelPositionLocal;
......@@ -302,7 +305,9 @@ StatusCode ClicpixAnalysis::run(Clipboard* clipboard){
if(pixelMatch){
m_lostHits++;
hTrackInterceptsChipLost->Fill(chipInterceptCol,chipInterceptRow);
}
}*/
if(!pixelMatch) hTrackInterceptsChipUnassociated->Fill(chipInterceptCol,chipInterceptRow);
}
}
......
......@@ -98,6 +98,7 @@ public:
TH2F* hTrackInterceptsPixelAssociated;
TH2F* hTrackInterceptsChip;
TH2F* hTrackInterceptsChipAssociated;
TH2F* hTrackInterceptsChipUnassociated;
TH2F* hTrackInterceptsChipLost;
TH2F* hPixelEfficiencyMap;
TH2F* hChipEfficiencyMap;
......
......@@ -12,6 +12,7 @@
#include <dirent.h>
#include <sstream>
#include <fstream>
#include <stdint.h>
class DataDump : public Algorithm {
......
......@@ -13,8 +13,18 @@ Timepix1EventLoader::Timepix1EventLoader(bool debugging)
bool sortByTime(string filename1, string filename2){
double filetime1 = stod(filename1.substr(filename1.length()-13,9));
double filetime2 = stod(filename2.substr(filename2.length()-13,9));
//double filetime1 = stod(filename1.substr(filename1.length()-13,9));
//double filetime2 = stod(filename2.substr(filename2.length()-13,9));
string timestring1 = filename1.substr(filename1.length()-13,9);
string timestring2 = filename2.substr(filename2.length()-13,9);
std::istringstream timestream1(timestring1);
std::istringstream timestream2(timestring2);
double filetime1, filetime2;
timestream1 >> filetime1;
timestream2 >> filetime2;
return (filetime1 < filetime2);
}
......@@ -171,7 +181,12 @@ StatusCode Timepix1EventLoader::run(Clipboard* clipboard){
}
void Timepix1EventLoader::processHeader(string header, string& device, long long int& time){
time = stod(header.substr(header.find("Start time : ")+13,13));
//time = stod(header.substr(header.find("Start time : ")+13,13));
string timestring = header.substr(header.find("Start time : ")+13,13);
std::istringstream timestream(timestring);
timestream >> time;
device = header.substr(header.find("ChipboardID : ")+14,header.find(" # DACs")-(header.find("ChipboardID : ")+14));
}
......
......@@ -8,6 +8,7 @@
#include "TCanvas.h"
#include <sstream>
#include <fstream>
#include <string>
class Timepix1EventLoader : public Algorithm {
......
......@@ -263,12 +263,17 @@ bool Timepix3EventLoader::loadData(string detectorID, Pixels* devicedata, SpidrS
if(header2 == 0x5){
// The data is shifted 16 bits to the right, then 44 to the left in order to match the timestamp format (net 28 left)
m_syncTime[detectorID] = (m_syncTime[detectorID] & 0x00000FFFFFFFFFFF) + ((pixdata & 0x00000000FFFF0000) << 28);
if( m_syncTime[detectorID] < 0x0000010000000000 && !m_clearedHeader[detectorID]) m_clearedHeader[detectorID] = true;
// if( m_syncTime[detectorID] < 0x0000010000000000 && !m_clearedHeader[detectorID]) m_clearedHeader[detectorID] = true;
if(!m_clearedHeader[detectorID] && (double)m_syncTime[detectorID]/(4096. * 40000000.) < 6.) m_clearedHeader[detectorID] = true;
}
// if(detectorID == "W0019_F07") tcout<<"Updating heartbeat. Now syncTime = "<<(double)m_syncTime[detectorID]/(4096. * 40000000.)<<endl;
// if(extra) tcout<<"Updating heartbeat. Now syncTime = "<<(double)m_syncTime[detectorID]/(4096. * 40000000.)<<endl;
//tcout<<"Updating heartbeat. Now syncTime = "<<(double)m_syncTime[detectorID]/(4096. * 40000000.)<<" for detector "<<detectorID<<endl;
}
if(!m_clearedHeader[detectorID]) continue;
// Header 0x06 and 0x07 are the start and stop signals for power pulsing
if(header == 0x0){
......@@ -293,12 +298,14 @@ bool Timepix3EventLoader::loadData(string detectorID, Pixels* devicedata, SpidrS
continue;
}
// Stop looking at data if the signal is after the current event window (and rewind the file
// reader so that we start with this signal next event)
if( parameters->eventLength != 0. &&
((double)time/(4096. * 40000000.)) > (parameters->currentTime + parameters->eventLength) ){
fseek(m_currentFile[detectorID], -1 * sizeof(ULong64_t), SEEK_CUR);
fileNotFinished = true;
// if(debug) tcout<<"Signal has a time beyond the current event: "<<(double)time/(4096. * 40000000.)<<endl;
break;
}
......@@ -429,6 +436,8 @@ bool Timepix3EventLoader::loadData(string detectorID, Pixels* devicedata, SpidrS
}
debug = false;
// If no data was loaded, return false
if(npixels == 0) return false;
......
......@@ -103,7 +103,7 @@ void Timepix3MaskCreator::finalise(){
for(int col=0;col<256;col++){
for(int row=0;row<256;row++){
int channelID =row + 256*col;
if(pixelhits[detectorID][channelID] > 1000){
if(pixelhits[detectorID][channelID] > 10*meanHits){
trimdacs >> t_col >> t_row >> t_trim >> t_mask >> t_tpen;
newtrimdacs << t_col << "\t" << t_row << "\t" << t_trim << "\t" << "1" << "\t" << t_tpen << endl;
tcout<<"Masking pixel "<<col<<","<<row<<" on detector "<<detectorID<<endl;
......
......@@ -194,6 +194,7 @@ void Parameters::readDutMask() {
if(dutMaskFile == "defaultMask.dat") return;
detector[this->DUT]->setMaskFile(dutMaskFile);
// Open the file with masked pixels
std::cout<<"Reading DUT mask file from "<<dutMaskFile<<std::endl;
std::fstream inputMaskFile(dutMaskFile.c_str(), std::ios::in);
int row,col; std::string id;
std::string line;
......
Markdown is supported
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