1 #ifndef root_container_hpp 2 #define root_container_hpp 14 #include "filval/container.hpp" 23 void save_as(TObject* container,
const std::string& fname,
const SaveOption& option = SaveOption::PNG) {
25 auto save_img = [](TObject* container,
const std::string& fname){
26 TCanvas* c1 =
new TCanvas(
"c1");
29 c1->SaveAs(fname.c_str());
33 auto save_bin = [](TObject* container){
34 INFO(
"Saving object: " << container->GetName() <<
" into file " << gDirectory->GetName());
35 container->Write(container->GetName(), TObject::kOverwrite);
40 save_img(container, fname+
".png");
break;
42 save_img(container, fname+
".pdf");
break;
44 save_bin(container);
break;
58 void save_as_stl(
void* container,
const std::string& type_name,
59 const std::string& obj_name,
60 const SaveOption& option = SaveOption::PNG) {
63 INFO(
"Cannot save STL container " << type_name <<
" as png");
66 INFO(
"Cannot save STL container " << type_name <<
" as pdf");
69 gDirectory->WriteObjectAny(container, type_name.c_str(), obj_name.c_str());
83 if (container ==
nullptr){
84 if (value ==
nullptr){
85 CRITICAL(
"Container: \"" << get_name() <<
"\" has a null Value object. " 86 <<
"Probably built with imcompatible type",-1);
88 this->container =
new TH1D(this->get_name().c_str(), this->title.c_str(),
89 this->nbins, this->low, this->high);
101 virtual void _do_fill() = 0;
105 int nbins,
double low,
double high)
107 title(title), nbins(nbins), low(low), high(high),
110 void save_as(
const std::string& fname,
const SaveOption& option = SaveOption::PNG) {
111 util::save_as(get_container(), fname, option);
115 template <
typename V>
119 this->container->Fill(this->value->get_value());
123 template <
typename V>
127 for(V x : this->value->get_value())
128 this->container->Fill(x);
134 template <
typename V>
138 if (container ==
nullptr){
139 if (value ==
nullptr){
140 CRITICAL(
"Container: \"" << get_name() <<
"\" has a null Value object. " 141 <<
"Probably built with imcompatible type",-1);
143 this->container =
new TH2D(this->get_name().c_str(), this->title.c_str(),
144 this->nbins_x, this->low_x, this->high_x,
145 this->nbins_y, this->low_y, this->high_y);
147 _do_fill(value->get_value());
160 virtual void _do_fill(std::pair<V,V>& val) = 0;
163 explicit _ContainerTH2(
const std::string& name,
const std::string& title,
164 Value<std::pair<V, V>>* value,
165 int nbins_x,
double low_x,
double high_x,
166 int nbins_y,
double low_y,
double high_y)
168 nbins_x(nbins_x), low_x(low_x), high_x(high_x),
169 nbins_y(nbins_y), low_y(low_y), high_y(high_y),
172 void save_as(
const std::string& fname,
const SaveOption& option = SaveOption::PNG) {
173 util::save_as(get_container(), fname, option);
177 template <
typename V>
180 void _do_fill(std::pair<V,V>& val){
181 this->container->Fill(val.first,val.second);
185 template <
typename V>
188 void _do_fill(std::pair<std::vector<V>,std::vector<V>>& val){
189 int min_size = std::min(val.first.size(), val.second.size());
190 for(
int i=0; i<min_size; i++)
191 this->container->Fill(val.first[i],val.second[i]);
198 std::vector<int> x_data;
199 std::vector<int> y_data;
204 x_data.push_back(val.first);
205 y_data.push_back(val.second);
206 data_modified =
true;
209 ContainerTGraph(
const std::string& name,
const std::string& title,
Value<std::pair<int, int>>* value)
212 data_modified(
false){ }
214 TGraph* get_container(){
217 container =
new TGraph(x_data.size(), x_data.data(), y_data.data());
218 container->SetName(get_name().c_str());
219 container->SetTitle(title.c_str());
220 data_modified =
false;
224 void save_as(
const std::string& fname,
const SaveOption& option = SaveOption::PNG) {
225 util::save_as(get_container(), fname, option);
230 template <
typename V,
typename D>
239 void save_as(
const std::string& fname,
const SaveOption& option = SaveOption::PNG) {
240 std::string type_name =
"std::map<"+fv::util::get_type_name(
typeid(D))+
",int>";
241 util::save_as_stl(this->get_container(), type_name, this->get_name(), option);
250 template <
typename V>
254 (*this->container)[this->value->get_value()]++;
261 template <
typename V>
265 for(V& val : this->value->get_value())
266 (*this->container)[val]++;
270 #endif // root_container_hpp Definition: container.hpp:231
Definition: container.hpp:16
Definition: container.hpp:116
Same as Counter but accepts multiple values per fill.
Definition: container.hpp:262
Definition: container.hpp:135
A Counter that keeps a mapping of the number of occurances of each input value.
Definition: container.hpp:251
Definition: container.hpp:80
Definition: container.hpp:124
Definition: container.hpp:186
Definition: container.hpp:178
virtual T & get_value()=0
Calculate, if necessary, and return the value held by this object.
Definition: container.hpp:195
Definition: container.hpp:73