1 #ifndef root_container_hpp 2 #define root_container_hpp 14 void _save_img(TObject* container,
const std::string& fname){
15 TCanvas* c1 =
new TCanvas(
"c1");
18 c1->SaveAs(fname.c_str());
22 void _save_bin(TObject* container){
23 INFO(
"Saving object: " << container->GetName() <<
" into file " << gDirectory->GetName());
25 container->Write(container->GetName(), TObject::kOverwrite);
29 void _save_as(TObject* container,
const std::string& fname,
const SaveOption& option = SaveOption::PNG) {
32 _save_img(container, fname+
".png");
break;
34 _save_img(container, fname+
".pdf");
break;
36 _save_bin(container);
break;
45 template <
typename V,
typename D>
49 if (container ==
nullptr){
50 if (value ==
nullptr){
51 CRITICAL(
"Container: \"" << get_name() <<
"\" has a null Value object. " 52 <<
"Probably built with imcompatible type",-1);
56 _do_fill(value->get_value());
65 virtual void init_TH1() = 0;
66 virtual void _do_fill(V& val) = 0;
70 int nbins, D low, D high)
72 title(title), nbins(nbins), low(low), high(high),
73 value(
dynamic_cast<Value<V>*
>(value)) { }
75 void save_as(
const std::string& fname,
const SaveOption& option = SaveOption::PNG) {
76 util::_save_as(get_container(), fname, option);
84 this->container =
new TH1D(this->get_name().c_str(), this->title.c_str(),
85 this->nbins, this->low, this->high);
91 void _do_fill(
double& val){
92 this->container->Fill(val);
98 void _do_fill(std::vector<double>& val){
100 this->container->Fill(x);
105 template <
typename V>
109 this->container =
new TH1F(this->get_name().c_str(), this->title.c_str(),
110 this->nbins, this->low, this->high);
116 void _do_fill(
float& val){
117 this->container->Fill(val);
123 void _do_fill(std::vector<float>& val){
125 this->container->Fill(x);
130 template <
typename V>
134 this->container =
new TH1I(this->get_name().c_str(), this->title.c_str(),
135 this->nbins, this->low, this->high);
141 void _do_fill(
int& val){
142 this->container->Fill(val);
148 void _do_fill(std::vector<int>& val){
150 this->container->Fill(x);
155 template <
typename V,
typename D>
159 if (container ==
nullptr){
160 if (value ==
nullptr){
161 CRITICAL(
"Container: \"" << get_name() <<
"\" has a null Value object. " 162 <<
"Probably built with imcompatible type",-1);
166 _do_fill(value->get_value());
178 virtual void init_TH2() = 0;
179 virtual void _do_fill(std::pair<V,V>& val) = 0;
182 explicit ContainerTH2(
const std::string& name,
const std::string& title,
184 int nbins_x, D low_x, D high_x,
185 int nbins_y, D low_y, D high_y)
187 nbins_x(nbins_x), low_x(low_x), high_x(high_x),
188 nbins_y(nbins_y), low_y(low_y), high_y(high_y),
191 void save_as(
const std::string& fname,
const SaveOption& option = SaveOption::PNG) {
192 util::_save_as(get_container(), fname, option);
196 template <
typename V>
200 this->container =
new TH2D(this->get_name().c_str(), this->title.c_str(),
201 this->nbins_x, this->low_x, this->high_x,
202 this->nbins_y, this->low_y, this->high_y);
208 void _do_fill(std::pair<double,double>& val){
209 this->container->Fill(val.first, val.second);
215 void _do_fill(std::pair<std::vector<double>,std::vector<double>>& val){
216 int min_size = std::min(val.first.size(), val.second.size());
217 for(
int i=0; i<min_size; i++)
218 this->container->Fill(val.first[i],val.second[i]);
222 template <
typename V>
226 this->container =
new TH2F(this->get_name().c_str(), this->title.c_str(),
227 this->nbins_x, this->low_x, this->high_x,
228 this->nbins_y, this->low_y, this->high_y);
234 void _do_fill(std::pair<float,float>& val){
235 this->container->Fill(val.first, val.second);
241 void _do_fill(std::pair<std::vector<float>,std::vector<float>>& val){
242 int min_size = std::min(val.first.size(), val.second.size());
243 for(
int i=0; i<min_size; i++)
244 this->container->Fill(val.first[i],val.second[i]);
248 template <
typename V>
252 this->container =
new TH2I(this->get_name().c_str(), this->title.c_str(),
253 this->nbins_x, this->low_x, this->high_x,
254 this->nbins_y, this->low_y, this->high_y);
260 void _do_fill(std::pair<int,int>& val){
261 this->container->Fill(val.first, val.second);
267 void _do_fill(std::pair<std::vector<int>,std::vector<int>>& val){
268 int min_size = std::min(val.first.size(), val.second.size());
269 for(
int i=0; i<min_size; i++)
270 this->container->Fill(val.first[i],val.second[i]);
277 std::vector<int> x_data;
278 std::vector<int> y_data;
282 x_data.push_back(val.first);
283 y_data.push_back(val.second);
284 data_modified =
true;
290 data_modified(
false){ }
292 TGraph* get_container(){
295 container =
new TGraph(x_data.size(), x_data.data(), y_data.data());
296 container->SetName(get_name().c_str());
297 data_modified =
false;
301 void save_as(
const std::string& fname,
const SaveOption& option = SaveOption::PNG) {
302 util::_save_as(get_container(), fname, option);
307 #endif // root_container_hpp Definition: value.hpp:184
Definition: container.hpp:13
Definition: container.hpp:46
Definition: container.hpp:232
Definition: container.hpp:89
Definition: container.hpp:258
Definition: container.hpp:131
Definition: container.hpp:96
Definition: container.hpp:81
Definition: container.hpp:121
Definition: container.hpp:223
Definition: container.hpp:146
Definition: container.hpp:206
Definition: container.hpp:213
Definition: container.hpp:114
Definition: container.hpp:249
Definition: container.hpp:156
Definition: container.hpp:139
Definition: container.hpp:197
Definition: container.hpp:239
Definition: container.hpp:106
virtual T & get_value()=0
Calculate, if necessary, and return the value held by this object.
Definition: container.hpp:274
Definition: container.hpp:54
Definition: container.hpp:265