Commit 4e1703ba authored by Jens Kroeger's avatar Jens Kroeger
Browse files

added new functions to count different event types

parent c489fccd
This diff is collapsed.
/**
* @file
* @brief Definition of [AnalysisTiming] 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 AnalysisTiming : 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
*/
AnalysisTiming(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;
// 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;
TH1F* hClusterTimeMinusPixelTime;
TH2F* hTrackCorrelationTimeVsTot_rowCorr;
TH2F* hTrackCorrelationTimeVsTot_rowCorr_1px;
TH2F* hTrackCorrelationTimeVsTot_rowCorr_npx;
TH2F* hTrackCorrelationTimeVsRow_rowAndTimeWalkCorr;
TH2F* hTrackCorrelationTimeVsTot_rowAndTimeWalkCorr;
TH2F* hClusterSizeVsTot_Assoc;
TH2F* hHitMapAssoc;
TH2F* hHitMapAssoc_highTot;
TH2F* hClusterMapAssoc;
TH2F* hTotVsTime_low;
TH2F* hTotVsTime_high;
// Control Plots for "left tail":
TH2F* hClusterMap_leftTail;
TH1F* hTot_leftTail;
TH1F* hPixelTS1_leftTail;
TH1F* hPixelTS2_leftTail;
TH1F* hPixelTS1bits_leftTail;
TH1F* hPixelTS2bits_leftTail;
TH1F* hClusterSize_leftTail;
TH2F* hClusterMap_rightTail;
TH1F* hTot_rightTail;
TH1F* hPixelTS1_rightTail;
TH1F* hPixelTS2_rightTail;
TH1F* hPixelTS1bits_rightTail;
TH1F* hPixelTS2bits_rightTail;
TH1F* hClusterSize_rightTail;
// 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_clusterTotCut;
size_t m_clusterSizeCut;
std::string m_correctionFile_row;
std::string m_correctionFile_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_afterClusterTotCut;
int tracks_afterClusterSizeCut;
};
} // namespace corryvreckan
......@@ -40,6 +40,32 @@ EventLoaderEUDAQ2::get_event_times(double start, double end, std::shared_ptr<Cli
return evt_times;
}
void EventLoaderEUDAQ2::increment_event_type_counter(eudaq::EventSPC evt) {
if(evt->GetDescription() == "CaribouCLICpix2Event") {
m_eventCount_cpx2++;
}
if(m_detector->name() != "MIMOSA26_0")
return;
if(evt->GetDescription() == "TluRawDataEvent") {
m_eventCount_tlu++;
} else if(evt->GetDescription() == "NiRawDataEvent") {
m_eventCount_ni++;
}
}
void EventLoaderEUDAQ2::increment_event_type_counter_in_frame(eudaq::EventSPC evt) {
if(evt->GetDescription() == "CaribouCLICpix2Event") {
m_eventCount_cpx2_inFrame++;
}
if(m_detector->name() != "MIMOSA26_0")
return;
if(evt->GetDescription() == "TluRawDataEvent") {
m_eventCount_tlu_inFrame++;
} else if(evt->GetDescription() == "NiRawDataEvent") {
m_eventCount_ni_inFrame++;
}
}
EventLoaderEUDAQ2::EventPosition EventLoaderEUDAQ2::process_tlu_event(eudaq::EventSPC evt,
std::shared_ptr<Clipboard>& clipboard) {
......@@ -77,7 +103,8 @@ EventLoaderEUDAQ2::EventPosition EventLoaderEUDAQ2::process_tlu_event(eudaq::Eve
LOG(DEBUG) << "Frame dropped because frame begins BEFORE event: "
<< Units::display(event_search_times.first, {"ns", "us", "ms", "s"}) << " earlier than "
<< Units::display(clipboard_event_times.first, {"ns", "us", "ms", "s"});
// hTluTrigTimeToFrameBegin->Fill(clipboard_event_times.first - tlu_timestamp));
// hTluTrigTimeToFrameBegin->Fill (clipboard_event_times.first - tlu_timestamp));
increment_event_type_counter_in_frame(evt);
return before_window;
}
......@@ -242,6 +269,10 @@ void EventLoaderEUDAQ2::initialise() {
auto detectorID = m_detector->name();
LOG(DEBUG) << "Initialise for detector " + detectorID;
m_eventCount_cpx2 = 0;
m_eventCount_ni = 0;
m_eventCount_tlu = 0;
m_skipBeforeT0 = m_config.get<bool>("skip_before_t0", false);
// Some simple histograms:
......@@ -340,6 +371,7 @@ StatusCode EventLoaderEUDAQ2::run(std::shared_ptr<Clipboard> clipboard) {
// All this is necessary because 1 DUT event (e.g. CLICpix2 event) might need to be compared to multiple Mimosa frames.
// However, it's implemented in a generic way so it also works for the simple case of only 1 detector.
while(1) {
if(!current_evt) {
LOG(DEBUG) << "!ev --> return, empty event --> end of file!";
......@@ -359,6 +391,8 @@ StatusCode EventLoaderEUDAQ2::run(std::shared_ptr<Clipboard> clipboard) {
if(sub_events.size() == 0) {
LOG(DEBUG) << "No subevent, process event.";
increment_event_type_counter(current_evt);
process_event(current_evt, clipboard);
// read next event for next run:
current_evt = reader->GetNextEvent();
......@@ -368,18 +402,19 @@ StatusCode EventLoaderEUDAQ2::run(std::shared_ptr<Clipboard> clipboard) {
// Important: first process TLU event (if available) --> sets event begin/end, then others
// Note: at the moment, we're not checking if there is a 2nd TLU subevent (but that shouldn't occur).
// drop frame if number of subevents==1, i.e. there is only telescope but not tlu data or vice versa
if(sub_events.size() == 1) {
LOG(INFO) << "Dropping frame because there is only 1 subevent of type " << sub_events[0]->GetDescription();
current_evt = reader->GetNextEvent();
return StatusCode::NoData;
}
// // drop frame if number of subevents==1, i.e. there is only telescope but not tlu data or vice
// versa if(sub_events.size() == 1) {
// LOG(INFO) << "Dropping frame because there is only 1 subevent of type " <<
// sub_events[0]->GetDescription(); increment_event_type_counter(sub_events[0]); current_evt =
// reader->GetNextEvent(); return StatusCode::NoData;
// }
// loop over subevents and process ONLY TLU event:
bool found_tlu_event = false;
enum EventPosition event_position;
for(auto& subevt : sub_events) {
LOG(DEBUG) << "Processing subevent.";
increment_event_type_counter(subevt);
if(subevt->GetDescription() != "TluRawDataEvent") {
LOG(DEBUG) << "\t---> Subevent is no TLU event -> continue.";
continue;
......@@ -413,6 +448,7 @@ StatusCode EventLoaderEUDAQ2::run(std::shared_ptr<Clipboard> clipboard) {
LOG(DEBUG) << "\t---> Subevent is TLU event -> continue.";
continue;
} // end if
increment_event_type_counter_in_frame(subevt);
process_event(subevt, clipboard);
} // end for
......@@ -430,3 +466,12 @@ StatusCode EventLoaderEUDAQ2::run(std::shared_ptr<Clipboard> clipboard) {
} // end while(1)
}
void EventLoaderEUDAQ2::finalise() {
LOG(STATUS) << "Number of CPX2 events: " << m_eventCount_cpx2 << ",\t"
<< "Number of TLU events: " << m_eventCount_tlu << ",\t"
<< "Number of NI events: " << m_eventCount_ni << ",\n"
<< "Number of CPX2 events in frame: " << m_eventCount_cpx2_inFrame << ",\t"
<< "Number of TLU events in frame: " << m_eventCount_tlu_inFrame << ",\t"
<< "Number of NI events in frame: " << m_eventCount_ni_inFrame;
}
......@@ -48,6 +48,10 @@ namespace corryvreckan {
* @brief [Run the function of this module]
*/
StatusCode run(std::shared_ptr<Clipboard> clipboard);
/**
* @brief [Finalize this module]
*/
void finalise();
private:
/**
......@@ -60,6 +64,9 @@ namespace corryvreckan {
*/
std::pair<double, double> get_event_times(double start, double end, std::shared_ptr<Clipboard>& clipboard);
void increment_event_type_counter(eudaq::EventSPC evt);
void increment_event_type_counter_in_frame(eudaq::EventSPC evt);
/**
* @brief Process events: extract hits and put onto clipboard, also define event start/end
* @param evt: event or subevent to be processed, clipboard
......@@ -84,6 +91,13 @@ namespace corryvreckan {
TH1F* hPixelsPerFrame;
TH1D* hEventBegin;
TH1D* hTluTrigTimeToFrameBegin;
int m_eventCount_cpx2;
int m_eventCount_ni;
int m_eventCount_tlu;
int m_eventCount_cpx2_inFrame;
int m_eventCount_ni_inFrame;
int m_eventCount_tlu_inFrame;
};
} // namespace corryvreckan
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