wavecatcher-analysis
Loading...
Searching...
No Matches
Legacy_functions.cc
Go to the documentation of this file.
1#include "Legacy_functions.h"
2
15void Legacy_functions::FractionEventsAboveThreshold(float threshold, bool max, bool greater, double from, double to, bool verbose) {
16
17 int occurences = 0;
18 int occurences2ch = 0;
19 int o2ch = 0;
20 int current_channel = 0;
21 int currevent = 0;
22 int lastevent = 0;
24 vector<int> counter_abovethr(static_cast<int>(plot_active_channels.size()));
25 // DORAMAS: It stores a counter of events above threshold for each channel that will be plotted
26
27 cout << "\nSearching for fraction of events with " << (max ? "max" : "min") << (greater ? " > " : " < ") << threshold << " mV:" << endl;
28
29 for (int j = 0; j < nwf; j++) {
30 auto his = (TH1F*)(Getwf(j))->Clone(); // use Clone() to not change ranges of original histogram
31
32 // set range where to search for amplitudes above threshold
33 if (from >= 0 && to > 0) {
34 his->GetXaxis()->SetRange(his->GetXaxis()->FindBin(from), his->GetXaxis()->FindBin(to));
35 }
36
37 current_channel = GetCurrentChannel(j);
39 if ((max && greater && his->GetMaximum() > threshold) || (max && !greater && his->GetMaximum() < threshold) || (!max && greater && his->GetMinimum() > threshold) || (!max && !greater && his->GetMinimum() < threshold)) {
40 currevent = eventnr_storage[GetCurrentEvent(j)];
41
42 if (verbose) cout << "\nevent:\t" << currevent << "\tchannel:\t" << active_channels[current_channel];
43
44 // We must use 'distance' to make sure the position in 'counter_above' matches with the corresponding channel's position at 'plot_active_channels'
45 counter_abovethr[distance(plot_active_channels.begin(), find(plot_active_channels.begin(), plot_active_channels.end(), active_channels[current_channel]))] += 1;
46 // This is to detect events w/ at least two channels above threshold
47 if (lastevent != currevent) occurences += 1;
48 if (lastevent == currevent && o2ch != occurences) {
49 occurences2ch += 1;
50 o2ch = occurences;
51 }
52 lastevent = currevent;
53 }
54 }
55 delete his;
57 }
58
59 // Loop to show the fraction of events above threshold for each channel that will be plotted
60 for (int i = 0; i < static_cast<int>(plot_active_channels.size()); i++) {
61 cout << "Fraction of events in channel " << plot_active_channels[i] << " above threshold: "
62 << 100. * static_cast<float>(counter_abovethr[i]) / static_cast<float>(nevents) << "%\n";
63 }
64
65 cout << "Fraction of events w/ at least 2 channels above threshold: "
66 << 100. * static_cast<float>(occurences2ch) / static_cast<float>(nevents) << "%\n"
67 << "For a total of " << nevents << " events" << endl;
68}
static bool Contains(const vector< T > &vec, const T &val)
Returns true if vector vec contains value val.
Definition Helpers.h:55
static void PrintProgressBar(int, int)
Print progress bar for a loop in steps of 10 percent.
Definition Helpers.cc:28
void FractionEventsAboveThreshold(float=4, bool=true, bool=true, double=0., double=0., bool=false)
Find events with max/min above/below a certain threshold.
TH1F * Getwf(int)
Helper that returns the waveform histogram for a certain waveform number number.
Definition ReadRun.cc:2698
int nevents
Number of triggered events in data.
Definition ReadRun.h:282
vector< int > active_channels
Stores the numbers of the active channels.
Definition ReadRun.h:311
int nwf
Total number of waveforms read from data: number of active channels x number of events.
Definition ReadRun.h:286
virtual int GetCurrentEvent(int)
Get the current event index for a certain waveform index.
Definition ReadRun.cc:2810
vector< int > plot_active_channels
Stores the numbers of the active channels which should be plotted.
Definition ReadRun.h:316
virtual int GetCurrentChannel(int)
Get the current channel index for a certain waveform index.
Definition ReadRun.cc:2803
vector< unsigned int > eventnr_storage
Events will be stored here in the order they have been read.
Definition ReadRun.h:138