9 TSystemDirectory dir(dirname, dirname);
10 TList* files = dir.GetListOfFiles();
13 TObjString* objString;
14 while ((objString = (TObjString*)next())) {
15 const char* fileName = objString->GetString().Data();
17 if (fileName[0] ==
'.')
continue;
19 if (strstr(fileName, ext) !=
nullptr) ss << fileName <<
"\n";
21 if (ss.str().empty())
throw runtime_error(
"Error: No .bin files found in " +
static_cast<string>(dirname) +
"\n");
29 static int lastProgress = -1;
30 int progress = (10 * (index + 1)) / length;
31 if (progress != lastProgress) {
32 lastProgress = progress;
33 cout <<
"\r[" << string(progress * 5,
'#')
34 << string(50 - progress * 5,
' ')
35 <<
"] " << progress * 10 <<
"%";
38 if (index + 1 == length) cout << endl << endl;
46 int rclrs[nclrs] = { 1, 2, 3, 4, 6, 8, 9, 13, 20, 28, 30, 34, 38, 40, 31, 46, 49 };
47 return rclrs[i -
static_cast<int>(floor(i / nclrs)) * nclrs];
59void Helpers::SetRangeCanvas(TCanvas*& c,
double x_range_min,
double x_range_max,
double y_range_min,
double y_range_max) {
62 auto setAxisRanges = [&](TH1* his) {
63 if (x_range_min != x_range_max) his->GetXaxis()->SetRangeUser(x_range_min, x_range_max);
64 if (y_range_min != y_range_max) his->GetYaxis()->SetRangeUser(y_range_min, y_range_max);
68 TList* pads = c->GetListOfPrimitives();
71 while ((
object = nextPad())) {
72 if (object->InheritsFrom(TPad::Class())) {
73 TPad* pad =
static_cast<TPad*
>(object);
76 TList* primitives = pad->GetListOfPrimitives();
77 TIter nextPrimitive(primitives);
79 while ((primitive = nextPrimitive())) {
80 if (primitive->InheritsFrom(TH1::Class())) {
81 setAxisRanges(
static_cast<TH1*
>(primitive));
85 else if (object->InheritsFrom(TH1::Class())) {
86 setAxisRanges(
static_cast<TH1*
>(
object));
100 for (
int channel : user_channels) {
102 cout <<
"\n ------------ WARNING ------------\n"
103 <<
"YOUR SELECTED CHANNEL " << channel <<
" DOES NOT EXIST IN DATA" << endl;
104 rmv.push_back(channel);
108 for (
int channel : rmv) {
109 auto it = find(user_channels.begin(), user_channels.end(), channel);
110 if (it != user_channels.end()) {
111 user_channels.erase(it);
125 if (plot_active_channels.empty()) {
126 c->Divide(TMath::Min(
static_cast<double>(active_channels.size()), 4.), TMath::Max(TMath::Ceil(
static_cast<double>(active_channels.size()) / 4.), 1.), 0, 0);
128 else if (
static_cast<int>(plot_active_channels.size()) > 1) {
129 c->Divide(TMath::Min(
static_cast<double>(plot_active_channels.size()), 4.), TMath::Max(ceil(
static_cast<double>(plot_active_channels.size()) / 4.), 1.), 0, 0);
137template <
typename HistType>
139 static_assert(is_base_of<TH1, HistType>::value,
"ERROR in Helpers::gety():\n Argument must be ROOT TH1 histogram.");
140 double* yvals =
new double[his->GetNbinsX()];
141 for (
int i = 0; i < his->GetNbinsX(); ++i) {
142 yvals[i] =
static_cast<double>(his->GetBinContent(i + 1));
146template double* Helpers::gety<TH1F>(TH1F*);
147template double* Helpers::gety<TH1D>(TH1D*);
148template double* Helpers::gety<TH1I>(TH1I*);
156template <
typename HistType>
158 static_assert(is_base_of<TH1, HistType>::value,
"ERROR in Helpers::gety():\n Argument must be ROOT TH1 histogram.");
160 if (start_at < 0 || end_at > his->GetNbinsX() || end_at <= start_at) {
161 cout <<
"\nError: Helpers::gety out of range" << endl;
164 const int n_bins_new = end_at - start_at;
165 double* yvals =
new double[n_bins_new];
166 for (
int i = start_at; i < end_at; i++) {
167 yvals[i - start_at] = his->GetBinContent(i + 1);
171template double* Helpers::gety<TH1F>(TH1F*,
int,
int);
172template double* Helpers::gety<TH1D>(TH1D*,
int,
int);
173template double* Helpers::gety<TH1I>(TH1I*,
int,
int);
180double*
Helpers::gety(
const vector<float>& waveform,
int start_at,
int end_at) {
181 if (start_at < 0 || end_at >
static_cast<int>(waveform.size()) || end_at <= start_at) {
182 cout <<
"\nError: Helpers::gety out of range" << endl;
185 const int n_bins_new = end_at - start_at;
186 double* yvals =
new double[n_bins_new];
187 for (
int i = start_at; i < end_at; i++) {
188 yvals[i - start_at] =
static_cast<double>(waveform[i]);
198template <
typename HistType>
200 static_assert(is_base_of<TH1, HistType>::value,
"ERROR in Helpers::gety():\n Argument must be ROOT TH1 histogram.");
201 int nbins = his->GetNbinsX();
202 shift_bins = shift_bins % nbins;
205 for (
int i = 0; i < nbins; i++) {
206 int new_bin = (i + shift_bins) % nbins;
207 if (new_bin < 0) new_bin += nbins;
208 his->SetBinContent(i + 1, yvals[new_bin]);
212template void Helpers::ShiftTH1<TH1F>(TH1F*&,
int);
213template void Helpers::ShiftTH1<TH1D>(TH1D*&,
int);
214template void Helpers::ShiftTH1<TH1I>(TH1I*&,
int);
static void SplitCanvas(TCanvas *&, vector< int >, vector< int >)
Helper to split canvas according to the number of channels to be plotted.
static double * gety(HistType *his)
Get array of y values for a histogram.
static void SetRangeCanvas(TCanvas *&, double, double, double=-999, double=-999)
Set consistent x-axis and y-axis range for all TH1 histograms on a canvas.
static int rcolor(unsigned int)
Translate a random number into a useful root color https://root.cern.ch/doc/master/classTColor....
static void filterChannelUserInput(vector< int > &, const vector< int >)
Check if user input exists in data and remove channels that are not there.
static bool Contains(const vector< T > &vec, const T &val)
Returns true if vector vec contains value val.
static void ShiftTH1(HistType *&, int)
Shift a histogram in x The histogram will be cycled, so bins at the end will be attached at the fron...
static void PrintProgressBar(int, int)
Print progress bar for a loop in steps of 10 percent.
static string ListFiles(const char *, const char *)
Helper. Creates a list of .bin data files in data folder to be read in.