Commit 0673c639 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Merge branch 'AnalysisTiming' into 'master'

Merge AnalysisTimingATLASpix module

See merge request corryvreckan/corryvreckan!105
parents 0a057690 86706ca2
Pipeline #862987 passed with stages
in 17 minutes and 11 seconds
This diff is collapsed.
/**
* @file
* @brief Definition of [AnalysisTimingATLASpix] module
* @copyright Copyright (c) 2018 CERN and the Allpix Squared authors.
* This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md".
* In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
* *
* Refer to the User's Manual for more details.
*/
#include <iostream>
#include "TGraphErrors.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TProfile2D.h"
#include "core/module/Module.hpp"
namespace corryvreckan {
/** @ingroup Modules
* @brief Module to do function
*
* More detailed explanation of module
*/
class AnalysisTimingATLASpix : public Module {
public:
/**
* @brief Constructor for this unique module
* @param config Configuration object for this module as retrieved from the steering file
* @param detector Pointer to the detector for this module instance
*/
AnalysisTimingATLASpix(Configuration config, std::shared_ptr<Detector> detector);
void initialise();
StatusCode run(std::shared_ptr<Clipboard> clipboard);
void finalise();
private:
std::shared_ptr<Detector> m_detector;
// timing correction functions:
void correctClusterTimestamp(Cluster*, int mode);
// 1D histograms:
TH1F* hTrackCorrelationTime;
TH1F* hTrackCorrelationTimeAssoc;
TH1F* hTrackCorrelationTime_rowCorr;
TH1F* hTrackCorrelationTime_rowAndTimeWalkCorr;
TH1F* hTrackCorrelationTime_rowAndTimeWalkCorr_l25;
TH1F* hTrackCorrelationTime_rowAndTimeWalkCorr_l40;
TH1F* hTrackCorrelationTime_rowAndTimeWalkCorr_g40;
TH1D* hTrackCorrelationTime_example;
TH1F* hClusterTimeMinusPixelTime;
// 2D histograms:
TH2F* hTrackCorrelationTimeVsCol; // control plot only
TH2F* hTrackCorrelationTimeVsRow;
TH2F* hTrackCorrelationTimeVsRow_1px;
TH2F* hTrackCorrelationTimeVsRow_npx;
TH2F* hTrackCorrelationTimeVsRow_rowCorr;
TH2F* hTrackCorrelationTimeVsTot;
TH2F* hTrackCorrelationTimeVsTot_1px;
TH2F* hTrackCorrelationTimeVsTot_npx;
TH2F* hTrackCorrelationTimeVsTot_rowCorr;
TH2F* hTrackCorrelationTimeVsTot_rowCorr_1px;
TH2F* hTrackCorrelationTimeVsTot_rowCorr_npx;
TH2F* hTrackCorrelationTimeVsRow_rowAndTimeWalkCorr;
TH2F* hTrackCorrelationTimeVsTot_rowAndTimeWalkCorr;
TH2F* hClusterSizeVsTot_Assoc;
TH2F* hHitMapAssoc;
TH2F* hHitMapAssoc_highCharge;
TH2F* hHitMapAssoc_inPixel;
TH2F* hHitMapAssoc_inPixel_highCharge;
TH2F* hClusterMapAssoc;
TH2F* hTotVsTime_low;
TH2F* hTotVsTime_high;
// Control Plots for "left tail":
TH2F* hClusterMap_leftTail;
TH1F* hTot_leftTail;
TH1F* hPixelTimestamp_leftTail;
TH1F* hClusterSize_leftTail;
TH2F* hClusterMap_mainpeak;
TH1F* hTot_mainpeak;
TH1F* hPixelTimestamp_mainpeak;
TH1F* hClusterSize_mainpeak;
// TGraphErrors:
TGraphErrors* gTimeCorrelationVsRow;
TGraphErrors* gTimeCorrelationVsTot_rowCorr;
TGraphErrors* gTimeCorrelationVsTot_rowCorr_1px;
TGraphErrors* gTimeCorrelationVsTot_rowCorr_npx;
TGraphErrors* gRowCorr;
TGraphErrors* gTimeWalkCorr;
// Member Variables:
std::string m_DUT;
double m_timingCut;
double m_chi2ndofCut;
double m_timeCutFrameEdge;
double m_clusterChargeCut;
size_t m_clusterSizeCut;
int m_highTotCut; // for pixel->tot()
double m_highChargeCut; // for cluster->charge()
double m_leftTailCut;
std::string m_correctionFile_row;
std::string m_correctionGraph_row;
std::string m_correctionFile_timewalk;
std::string m_correctionGraph_timewalk;
bool m_calcCorrections;
bool m_pointwise_correction_row;
bool m_pointwise_correction_timewalk;
int m_totBinExample;
int total_tracks_uncut;
int tracks_afterChi2Cut;
int tracks_hasIntercept;
int tracks_isWithinROI;
int tracks_afterMasking;
int total_tracks;
int matched_tracks;
int tracks_afterClusterChargeCut;
int tracks_afterClusterSizeCut;
};
} // namespace corryvreckan
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
CORRYVRECKAN_DETECTOR_TYPE(${MODULE_NAME} "ATLASpix")
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
AnalysisTimingATLASpix.cpp
# ADD SOURCE FILES HERE...
)
# Provide standard install target
CORRYVRECKAN_MODULE_INSTALL(${MODULE_NAME})
# AnalysisTimingATLASpix
**Maintainer**: Jens Kroeger (jens.kroeger@cern.ch)
**Module Type**: *DUT*
**Detector Type**: *ATLASpix*
**Status**: work in progress
### Description
This module contains everything that's necessary for an in-depth timing analysis of the ATLASpix, including row and timewalk corrections.
Before being able to apply the row and timewalk correction, correction files need to be provided.
These can be generated by setting `calc_corrections=true`.
The calculation of the timewalk correction is based on a row-corrected histogram such that this procedure needs to be performed in 2 steps.
1. Calculated row correction.
2. Use row correction file and calculated timewalk correction.
After this both corrections can be applied on top of each other.
### Parameters
* `timing_cut`: Timing cut for associating a track with an ATLASpix cluster. Defaults to `1us`.
* `chi2ndof_cut`: Acceptance criterion for telescope tracks, defaults to a value of `3`.
* `time_cut_frame_edge`: Parameter to discard telescope tracks at the frame edges (start and end of the current frame). Defaults to `20ns`.
* `cluster_charge_cut`: Parameter to discard clusters with a charge larger than the cut. Defaults to `100000e` (inifitely large).
* `cluster_size_cut`: Parameter to discard clusters with a size too large, only for debugging purposes, default is 100 (inifitely large).
* `high_tot_cut`: Cut dividing 'low' and 'high' ToT events (based on seed pixel ToT). Defaults to `40`.
* `high_charge_cut`: Cut dividing 'low' and 'high' charge events (based on cluster charge). Defaults to `40e`.
* `left_tail_cut`: Cut to divide into left tail and main peak of time correlation histogram. Only used to investigate characteristics of left tail. Defaults to `-10ns`.
* `calc_corrections`: If `true`, TGraphErrors for row and timewalk corrections are produced.
* `correction_file_row`, `correction_file_timewalk`. Defaults to `false`.
* `correction_file_row`: Path to file which contains TGraphErrors for row correction. If this parameter is set, also `correction_graph_row` needs to be set. No default.
* `correction_file_timewalk`: Path to file which contains TGraphErrors for timewalk correction. If this parameter is set, also `correction_graph_timewalk` needs to be set. No default.
* `correction_graph_row`: Name of the TGraphErrors including its path in the root file used for row correction. E.g. "AnalysisTimingATLASpix/apx_0/gTimeCorrelationVsRow". No default.
* `correction_graph_timewalk`: Name of the TGraphErrors including its path in the root file used for row correction. E.g. "AnalysisTimingATLASpix/apx_0/gTimeCorrelationVsTot". No default.
### Plots produced
* 1D histograms
* Track time correlation (all clusters)
* Track time correlation (track-associated clusters)
* Track time correlation (after row correction)
* Track time correlation (after row and timewalk correction)
* Track time correlation (after row and timewalk correction) for clusterToT < 25 lsb
* Track time correlation (after row and timewalk correction) for clusterToT < 40 lsb
* Track time correlation (after row and timewalk correction) for clusterToT > 40 lsb
* Track time correlation example slice of 2D plot to investigate quality of Gaussian fit
* Cluster time minus pixel time (for all pixels in cluster) to confirm that cluster time = time of earliest pixel
* Pixel ToT for left tail events in time correlation (track timestamp - cluster timestamp < left_tail_cut)
* Pixel ToT for main peak events in time correlation (track timestamp - cluster timestamp > left_tail_cut)
* Pixel timestamp for left tail events in time correlation (track timestamp - cluster timestamp < left_tail_cut)
* Pixel timestamp main peak events in time correlation (track timestamp - cluster timestamp > left_tail_cut)
* Cluster size for left tail events in time correlation (track timestamp - cluster timestamp < left_tail_cut)
* Cluster size for main peak events in time correlation (track timestamp - cluster timestamp > left_tail_cut)
* 2D histograms
* Track time correlation vs. column (only control plot)
* Track time correlation vs. cluster row (for row correction)
* Track time correlation vs. cluster row (only single pixel clusters)
* Track time correlation vs. cluster row (only multi-pixel clusters)
* Track time correlation vs. cluster row (after row correction)
* Track time correlation vs. seed pixel ToT (for timewalk correction)
* Track time correlation vs. seed pixel ToT (only single pixel clusters)
* Track time correlation vs. seed pixel ToT (only multi-pixel clusters)
* Track time correlation vs. cluster row (after row correction)
* Track time correlation vs. cluster row (after row correction, only single pixel clusters)
* Track time correlation vs. cluster row (after row correction, only multi-pixel clusters)
* Track time correlation vs. cluster row (after row and timewalk correction)
* Track time correlation vs. seed pixel (after row and timewalk correction)
* Cluster size vs. cluster ToT (only associated clusters)
* Hit map of all pixels from associated clusters
* Hit map of all pixels from associated clusters with high ToT
* In-pixel distribution of tracks
* In-pixel distribution of tracks (for clusters with high ToT)
* Map of associated clusters
* Pixel ToT vs. time for low ToT clusters
* Pixel ToT vs. time for high ToT clusters
* Cluster map for left tail events in time correlation (track timestamp - cluster timestamp < left_tail_cut)
* Cluster map for main peak events in time correlation (track timestamp - cluster timestamp > left_tail_cut)
* TGraphErrors
* Peak of time correlation vs. row
* Peak of time correlation vs. ToT (after row correction)
* Peak of time correlation vs. row (after row correction, only single pixel clusters)
* Peak of time correlation vs. row (after row correction, only multi-pixel clusters)
### Usage
```toml
[AnalysisTiming]
calc_corrections = false
correction_file_row = "correction_files/row_correction_file.root"
correction_graph_row = "AnalysisTimingATLASpix/apx0/gRTimeCorrelationVsRow"
correction_file_timewalk = "correction_files/timewalk_correction_file.root"
correction_graph_timewalk = "AnalysisTimingATLASpix/apx0/gTimCorrelationVsTot"
```
......@@ -16,6 +16,8 @@ EventLoaderATLASpix::EventLoaderATLASpix(Configuration config, std::shared_ptr<D
// m_clkdivendM = m_config.get<int>("clkdivend", 0.) + 1;
m_clkdivend2M = m_config.get<int>("clkdivend2", 0.) + 1;
m_highToTCut = m_config.get<int>("high_tot_cut", 40);
if(m_config.has("calibration_file")) {
m_calibrationFile = m_config.getPath("calibration_file");
}
......@@ -112,7 +114,7 @@ void EventLoaderATLASpix::initialise() {
// Make histograms for debugging
hHitMap = new TH2F("hitMap",
"hitMap",
"hitMap; pixel column; pixel row; # events",
m_detector->nPixels().X(),
0,
m_detector->nPixels().X(),
......@@ -120,12 +122,54 @@ void EventLoaderATLASpix::initialise() {
0,
m_detector->nPixels().Y());
hPixelToT = new TH1F("pixelToT", "pixelToT", 64, 0, 64);
hPixelToT->GetXaxis()->SetTitle("ToT in TS2 clock cycles.");
hPixelToTCal = new TH1F("pixelToTCal", "pixelToT", 100, 0, 100);
hPixelToA = new TH1F("pixelToA", "pixelToA", 100, 0, 100);
hPixelsPerFrame = new TH1F("pixelsPerFrame", "pixelsPerFrame", 200, 0, 200);
hPixelsOverTime = new TH1F("pixelsOverTime", "pixelsOverTime", 2e6, 0, 2e6);
hHitMap_highTot = new TH2F("hitMap_highTot",
"hitMap_hithTot; pixel column; pixel row; # events",
m_detector->nPixels().X(),
0,
m_detector->nPixels().X(),
m_detector->nPixels().Y(),
0,
m_detector->nPixels().Y());
hHitMap_totWeighted = new TProfile2D("hHitMap_totWeighted",
"hHitMap_totWeighted; pixel column; pixel row; # events",
m_detector->nPixels().X(),
0,
m_detector->nPixels().X(),
m_detector->nPixels().Y(),
0,
m_detector->nPixels().Y(),
0,
100);
hPixelToT = new TH1F("pixelToT", "pixelToT; pixel ToT in TS2 clock cycles; # events", 64, 0, 64);
hPixelToT_beforeCorrection = new TH1F(
"pixelToT_beforeCorrection", "pixelToT_beforeCorrection; pixel ToT in TS2 clock cycles; # events", 2 * 64, -64, 64);
hPixelCharge = new TH1F("pixelCharge", "pixelCharge; pixel charge [e]; # events", 100, 0, 100);
hPixelToA = new TH1F("pixelToA", "pixelToA; pixel ToA [ns]; # events", 100, 0, 100);
hPixelsPerFrame = new TH1F("pixelsPerFrame", "pixelsPerFrame; pixels per frame; # events", 200, 0, 200);
hPixelsOverTime = new TH1F("pixelsOverTime", "pixelsOverTime; time [ms]; # events", 2e6, 0, 2e6);
hPixelTS1 = new TH1F("pixelTS1", "pixelTS1; pixel TS1 [lsb]; # events", 2050, 0, 2050);
hPixelTS2 = new TH1F("pixelTS2", "pixelTS2; pixel TS2 [lsb]; # events", 130, 0, 130);
hPixelTS1bits = new TH1F("pixelTS1bits", "pixelTS1bits; pixel TS1 bit [lsb->msb]; # events", 12, 0, 12);
hPixelTS2bits = new TH1F("pixelTS2bits", "pixelTS2bits; pixel TS2 bit [lsb->msb]; # events", 8, 0, 8);
// low ToT:
hPixelTS1_lowToT = new TH1F("pixelTS1_lowToT", "pixelTS1_lowToT; pixel TS1 [lsb]; # events", 2050, 0, 2050);
hPixelTS2_lowToT = new TH1F("pixelTS2_lowToT", "pixelTS2_lowToT; pixel TS2 [lsb]; # events", 130, 0, 130);
hPixelTS1bits_lowToT =
new TH1F("pixelTS1bits_lowToT", "pixelTS1bits_lowToT; pixel TS1 bit [lsb->msb]; # events", 12, 0, 12);
hPixelTS2bits_lowToT =
new TH1F("pixelTS2bits_lowToT", "pixelTS2bits_lowToT; pixel TS2 bit [lsb->msb]; # events", 8, 0, 8);
// high ToT:
hPixelTS1_highToT = new TH1F("pixelTS1_highToT", "pixelTS1_highToT; pixel TS1 [lsb]; # events", 2050, 0, 2050);
hPixelTS2_highToT = new TH1F("pixelTS2_highToT", "pixelTS2_highToT; pixel TS2 [lsb]; # events", 130, 0, 130);
hPixelTS1bits_highToT =
new TH1F("pixelTS1bits_highToT", "pixelTS1bits_highToT; pixel TS1 bit [lsb->msb]; # events", 12, 0, 12);
hPixelTS2bits_highToT =
new TH1F("pixelTS2bits_highToT", "pixelTS2bits_highToT; pixel TS2 bit [lsb->msb]; # events", 8, 0, 8);
// Read calibration:
m_calibrationFactors.resize(static_cast<size_t>(m_detector->nPixels().X() * m_detector->nPixels().Y()), 1.0);
......@@ -175,8 +219,12 @@ StatusCode EventLoaderATLASpix::run(std::shared_ptr<Clipboard> clipboard) {
for(auto px : (*pixels)) {
hHitMap->Fill(px->column(), px->row());
if(px->raw() > m_highToTCut) {
hHitMap_highTot->Fill(px->column(), px->row());
}
hHitMap_totWeighted->Fill(px->column(), px->row(), px->raw());
hPixelToT->Fill(px->raw());
hPixelToTCal->Fill(px->charge());
hPixelCharge->Fill(px->charge());
hPixelToA->Fill(px->timestamp());
// Pixels per 100us:
......@@ -311,12 +359,42 @@ Pixels* EventLoaderATLASpix::read_caribou_data(double start_time, double end_tim
// calculate ToT only when pixel is good for storing (division is time consuming)
int tot = static_cast<int>(ts2 - ((hit_ts % static_cast<long long>(64 * m_clkdivend2M)) / m_clkdivend2M));
hPixelToT_beforeCorrection->Fill(tot);
if(tot < 0) {
tot += 64;
}
// convert ToT to nanoseconds
// double tot_ns = tot * m_clockCycle;
hPixelTS1->Fill(static_cast<double>(ts1));
hPixelTS2->Fill(static_cast<double>(ts2));
if(tot < m_highToTCut) {
hPixelTS1_lowToT->Fill(static_cast<double>(ts1));
hPixelTS2_lowToT->Fill(static_cast<double>(ts2));
} else {
hPixelTS1_highToT->Fill(static_cast<double>(ts1));
hPixelTS2_highToT->Fill(static_cast<double>(ts2));
}
// histogram each bit of the 10-bit TS1
for(int i = 0; i < 12; i++) {
hPixelTS1bits->Fill(static_cast<double>(i), static_cast<double>((ts1 >> i) & 0b1));
if(tot < m_highToTCut) {
hPixelTS1bits_lowToT->Fill(static_cast<double>(i), static_cast<double>((ts1 >> i) & 0b1));
} else {
hPixelTS1bits_highToT->Fill(static_cast<double>(i), static_cast<double>((ts1 >> i) & 0b1));
}
}
// histogram each bit of the 6-bit TS2
for(int i = 0; i < 8; i++) {
hPixelTS2bits->Fill(static_cast<double>(i), static_cast<double>((ts2 >> i) & 0b1));
if(tot < m_highToTCut) {
hPixelTS2bits_lowToT->Fill(static_cast<double>(i), static_cast<double>((ts1 >> i) & 0b1));
} else {
hPixelTS2bits_highToT->Fill(static_cast<double>(i), static_cast<double>((ts1 >> i) & 0b1));
}
}
LOG(TRACE) << "HIT: TS1: " << ts1 << "\t0x" << std::hex << ts1 << "\tTS2: " << ts2 << "\t0x" << std::hex << ts2
<< "\tTS_FULL: " << hit_ts << "\t" << Units::display(timestamp, {"s", "us", "ns"})
<< "\tTOT: " << tot; // << "\t" << Units::display(tot_ns, {"s", "us", "ns"});
......
......@@ -4,6 +4,7 @@
#include <TCanvas.h>
#include <TH1F.h>
#include <TH2F.h>
#include <TProfile2D.h>
#include <dirent.h>
#include <fstream>
#include <iostream>
......@@ -61,17 +62,35 @@ namespace corryvreckan {
int ts2Range;
TH2F* hHitMap;
TH2F* hHitMap_highTot;
TProfile2D* hHitMap_totWeighted;
TH1F* hPixelToT;
TH1F* hPixelToTCal;
TH1F* hPixelToT_beforeCorrection;
TH1F* hPixelCharge;
TH1F* hPixelToA;
TH1F* hPixelsPerFrame;
TH1F* hPixelsOverTime;
// TS1 and TS2 specific histograms:
TH1F* hPixelTS1;
TH1F* hPixelTS2;
TH1F* hPixelTS1bits;
TH1F* hPixelTS2bits;
TH1F* hPixelTS1_lowToT;
TH1F* hPixelTS2_lowToT;
TH1F* hPixelTS1bits_lowToT;
TH1F* hPixelTS2bits_lowToT;
TH1F* hPixelTS1_highToT;
TH1F* hPixelTS2_highToT;
TH1F* hPixelTS1bits_highToT;
TH1F* hPixelTS2bits_highToT;
// Parameters:
std::string m_inputDirectory;
bool m_detectorBusy;
bool m_legacyFormat;
double m_clockCycle;
int m_highToTCut;
std::string m_calibrationFile;
std::vector<double> m_calibrationFactors;
// int m_clkdivendM;
......
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