sipm-characterisation 0.1.0
SiPM characterisation for ePIC — IV/DCR/gain, laser, readout, irradiation
Loading...
Searching...
No Matches
utility.h
Go to the documentation of this file.
1#pragma once
2#include "general_utility.h"
3struct TObjects
4{
5 std::map<std::string, TH1F *> _TH1F;
6 std::map<std::string, TH1D *> _TH1D;
7 std::map<std::string, TH2F *> _TH2F;
8 std::map<std::string, TH2I *> _TH2I;
9 std::map<std::string, TH3F *> _TH3F;
10 std::map<std::string, TProfile *> _TProfile;
11 std::map<std::string, TGraph *> _TGraph;
12 std::map<std::string, TGraphErrors *> _TGraphErrors;
13};
14
16{
17 for (auto [label, object] : target._TProfile)
18 object->Write(label.c_str());
19 for (auto [label, object] : target._TH1F)
20 object->Write(label.c_str());
21 for (auto [label, object] : target._TH1D)
22 object->Write(label.c_str());
23 for (auto [label, object] : target._TH2F)
24 object->Write(label.c_str());
25 for (auto [label, object] : target._TH2I)
26 object->Write(label.c_str());
27 for (auto [label, object] : target._TH3F)
28 object->Write(label.c_str());
29 for (auto [label, object] : target._TGraph)
30 object->Write(label.c_str());
31 for (auto [label, object] : target._TGraphErrors)
32 object->Write(label.c_str());
33}
34
35template <bool logx = true, bool logy = true>
36TCanvas *standard_canvas(std::string name, std::string title, float nXpixels = 1000, float nYpixels = 1000)
37{
38 TCanvas *cResult = new TCanvas(name.c_str(), title.c_str(), nXpixels, nYpixels);
39 gStyle->SetOptStat(0);
40 gPad->SetGridx(logx);
41 gPad->SetGridy(logy);
42 gPad->SetRightMargin(0.05);
43 gPad->SetTopMargin(0.05);
44 gPad->SetLeftMargin(0.15);
45 gPad->SetBottomMargin(0.15);
46 return cResult;
47}
48
49template <bool logx = true, bool logy = true>
50TCanvas *standard_canvas_2D(std::string name, std::string title, float nXpixels = 1145, float nYpixels = 1000)
51{
52 TCanvas *cResult = new TCanvas(name.c_str(), title.c_str(), nXpixels, nYpixels);
53 gStyle->SetOptStat(0);
54 gPad->SetGridx(logx);
55 gPad->SetGridy(logy);
56 gPad->SetRightMargin(0.15);
57 gPad->SetTopMargin(0.05);
58 gPad->SetLeftMargin(0.15);
59 gPad->SetBottomMargin(0.15);
60 return cResult;
61}
62
63std::time_t s_ts(const std::string &datetime)
64{
65 std::tm tm = {};
66 std::stringstream ss(datetime);
67
68 // Parse the datetime string into the tm structure
69 ss >> std::get_time(&tm, "%Y%m%d-%H%M%S");
70
71 if (ss.fail())
72 {
73 // throw std::runtime_error("Failed to parse date time string");
74 return 0;
75 }
76
77 // Convert tm to time_t (seconds since the epoch)
78 std::time_t timestamp = std::mktime(&tm);
79
80 if (timestamp == -1)
81 {
82 // throw std::runtime_error("Failed to convert to time_t");
83 return 0;
84 }
85
86 return timestamp;
87}
88
89template <typename th1_type = TH1F>
91make_log_th1(int n_bins, double min_x, double max_x)
92{
93 // swap values is mi max are swapped
94 if (min_x > max_x)
96
97 // Create an array to hold bin edges
98 double bin_edges[n_bins + 1];
99
100 // Calculate the bin edges in log scale
101 double log_min_x = std::log10(min_x);
102 double log_max_x = std::log10(max_x);
103 double log_step_ = (log_max_x - log_min_x) / n_bins;
104 for (int i = 0; i <= n_bins; ++i)
105 {
106 bin_edges[i] = std::pow(10, log_min_x + i * log_step_);
107 }
108
109 // Build the TH1
110 th1_type *result = new th1_type("", "", n_bins, bin_edges);
111
112 return result;
113}
114
115std::array<std::array<float, 2>, 2> get_intercept(TF1 *pol1, TF1 *pol2) { return utility::get_intercept(pol1->GetParameter(1), pol1->GetParError(1), pol1->GetParameter(0), pol1->GetParError(0), pol2->GetParameter(1), pol2->GetParError(1), pol2->GetParameter(0), pol2->GetParError(0)); }
TH2_Type * build_fine_tune_raw_histogram(std::vector< TString > kInputFileNames, TString kRunTag, TString kOutputFileName, bool kRecalculate)
Functions -------------------------------------------------------------------------------------------...
Definition fine_analysis.h:80
void swap_values(arg_type &first_element, arg_type &second_element)
Definition general_utility.h:49
std::array< std::array< float, 2 >, 2 > get_intercept(float x0_1, float ex0_1, float x1_1, float ex1_1, float x0_2, float ex0_2, float x1_2, float ex1_2)
Definition general_utility.h:385
Definition utility.h:4
std::map< std::string, TH3F * > _TH3F
Definition utility.h:9
std::map< std::string, TH2F * > _TH2F
Definition utility.h:7
std::map< std::string, TH2I * > _TH2I
Definition utility.h:8
std::map< std::string, TH1D * > _TH1D
Definition utility.h:6
std::map< std::string, TH1F * > _TH1F
Definition utility.h:5
std::map< std::string, TProfile * > _TProfile
Definition utility.h:10
std::map< std::string, TGraph * > _TGraph
Definition utility.h:11
std::map< std::string, TGraphErrors * > _TGraphErrors
Definition utility.h:12
void write_all(TObjects target)
Definition utility.h:15
std::array< std::array< float, 2 >, 2 > get_intercept(TF1 *pol1, TF1 *pol2)
Definition utility.h:115
TCanvas * standard_canvas_2D(std::string name, std::string title, float nXpixels=1145, float nYpixels=1000)
Definition utility.h:50
std::time_t s_ts(const std::string &datetime)
Definition utility.h:63
th1_type * make_log_th1(int n_bins, double min_x, double max_x)
Definition utility.h:91
TCanvas * standard_canvas(std::string name, std::string title, float nXpixels=1000, float nYpixels=1000)
Definition utility.h:36