1 #ifndef BOOK_FOR_ROOT_HISTOGRAMS 2 #define BOOK_FOR_ROOT_HISTOGRAMS 7 #include "TDirectory.h" 13 #include <boost/regex.hpp> 14 #include <boost/iterator/filter_iterator.hpp> 21 typedef std::map<std::string, TH1*>
book_t;
36 Book(string_t
t) : title_(t), directory(new TDirectory(t.c_str(),t.c_str())) {}
39 bool empty()
const {
return book_.empty(); }
40 long size ()
const {
return book_.size(); }
42 TH1*
book(string_t
name, TH1*
const hist) { book_[
name]=
hist; hist->SetDirectory(directory);
if(!hist->GetSumw2N()) hist->Sumw2();
return hist;}
44 const TH1*
operator[](string_t
name)
const { book_t::const_iterator it = book_.find(name);
return it==book_.end() ?
nullptr : it->second;}
46 typedef boost::filter_iterator<match_name,book_t::iterator>
iterator;
47 typedef boost::filter_iterator<match_name,book_t::const_iterator>
const_iterator;
48 iterator
begin(string_t re =
".*") {book_t::iterator
b(book_.begin()),
e(book_.end());
return boost::make_filter_iterator(
match_name(re),
b,
e);}
49 const_iterator
begin(string_t re =
".*")
const {book_t::const_iterator
b(book_.begin()),
e(book_.end());
return boost::make_filter_iterator(
match_name(re),
b,
e);}
50 iterator
end( string_t re =
".*") {book_t::iterator
e(book_.end());
return boost::make_filter_iterator(
match_name(re),
e,
e);}
51 const_iterator
end( string_t re =
".*")
const {book_t::const_iterator
e(book_.end());
return boost::make_filter_iterator(
match_name(re),
e,
e);}
52 iterator
find (string_t
name, string_t re =
".*") {
return boost::make_filter_iterator(
match_name(re),book_.find(name),book_.end()); }
53 const_iterator
find (string_t
name, string_t re =
".*")
const {
return boost::make_filter_iterator(
match_name(re),book_.find(name),book_.end()); }
54 std::pair<iterator,iterator>
filter_range(string_t re =
".*") {
return std::make_pair(
begin(re),
end(re) ); }
55 std::pair<const_iterator,const_iterator>
filter_range(string_t re =
".*")
const {
return std::make_pair(
begin(re),
end(re) ); }
57 void erase(string_t
name) { book_t::iterator it = book_.find(name);
if(it!=book_.end()) {
delete it->second; book_.erase(it); } }
58 void erase(iterator it) {
delete it->second; book_.erase(it.base()); }
61 uint_t NbinsX, double_t Xlow, double_t Xup, double_t W=1 ) {
fill(X,
std::string(name),NbinsX,Xlow,Xup,W);}
63 uint_t NbinsX, double_t Xlow, double_t Xup, double_t W=1 )
65 for(
auto const&
name : names) {
66 book_t::const_iterator current = book_.find(
name);
67 if( current == book_.end() )
68 book(
name,
new TH1D(
name.c_str(),
"", NbinsX, Xlow, Xup))->Fill(X,W);
69 else current->second->Fill(X,W);
73 uint_t NbinsX, double_t Xlow, double_t Xup, double_t W=1 ) {
fill(X,Y,
std::string(name),NbinsX,Xlow,Xup,W);}
75 uint_t NbinsX, double_t Xlow, double_t Xup, double_t W=1 )
77 for(
auto const&
name : names) {
78 book_t::const_iterator current = book_.find(
name);
79 if( current == book_.end() )
80 static_cast<TProfile*>(
book(
name,
new TProfile(
name.c_str(),
"", NbinsX, Xlow, Xup)))->
Fill(X,Y,W);
81 else static_cast<TProfile*
>(current->second)->
Fill(X,Y,W);
85 uint_t NbinsX, double_t Xlow, double_t Xup,
86 uint_t NbinsY, double_t Ylow, double_t Yup, double_t W=1 ) {
fill(X,Y,
std::string(name),NbinsX,Xlow,Xup,NbinsY,Ylow,Yup,W);}
88 uint_t NbinsX, double_t Xlow, double_t Xup,
89 uint_t NbinsY, double_t Ylow, double_t Yup, double_t W=1 )
91 for(
auto const&
name : names) {
92 book_t::const_iterator current = book_.find(
name);
93 if( current == book_.end() )
94 static_cast<TH2*>(
book(
name,
new TH2D(
name.c_str(),
"", NbinsX, Xlow, Xup, NbinsY, Ylow, Yup)))->
Fill(X,Y,W);
95 else static_cast<TH2*
>(current->second)->
Fill(X,Y,W);
98 void fill( double_t
X, double_t
Y, double_t
Z,
const char*
name,
99 uint_t NbinsX, double_t Xlow, double_t Xup,
100 uint_t NbinsY, double_t Ylow, double_t Yup,
101 uint_t NbinsZ, double_t Zlow, double_t Zup, double_t W=1 ) {
fill(X,Y,Z,
std::string(name),NbinsX,Xlow,Xup,NbinsY,Ylow,Yup,NbinsZ,Zlow,Zup);}
103 uint_t NbinsX, double_t Xlow, double_t Xup,
104 uint_t NbinsY, double_t Ylow, double_t Yup,
105 uint_t NbinsZ, double_t Zlow, double_t Zup, double_t W=1 )
107 for(
auto const&
name : names) {
108 book_t::const_iterator current = book_.find(
name);
109 if( current == book_.end() )
110 static_cast<TH3*>(
book(
name,
new TH3D(
name.c_str(),
"", NbinsX, Xlow, Xup, NbinsY, Ylow, Yup, NbinsZ, Zlow, Zup)))->
Fill(X,Y,Z,W);
111 else static_cast<TH3*
>(current->second)->
Fill(X,Y,Z,W);
const_iterator end(string_t re=".*") const
void fill(double_t X, const poly< std::string > &names, uint_t NbinsX, double_t Xlow, double_t Xup, double_t W=1)
const std::string names[nVars_]
std::pair< const_iterator, const_iterator > filter_range(string_t re=".*") const
const TH1 * operator[](string_t name) const
void fill(double_t X, double_t Y, double_t Z, const char *name, uint_t NbinsX, double_t Xlow, double_t Xup, uint_t NbinsY, double_t Ylow, double_t Yup, uint_t NbinsZ, double_t Zlow, double_t Zup, double_t W=1)
std::pair< iterator, iterator > filter_range(string_t re=".*")
const std::string string_t
void fill(double_t X, double_t Y, const char *name, uint_t NbinsX, double_t Xlow, double_t Xup, uint_t NbinsY, double_t Ylow, double_t Yup, double_t W=1)
Container::value_type value_type
const_iterator begin(string_t re=".*") const
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void fill(double_t X, double_t Y, const char *name, uint_t NbinsX, double_t Xlow, double_t Xup, double_t W=1)
std::map< std::string, TH1 * > book_t
void fill(double_t X, double_t Y, const poly< std::string > &names, uint_t NbinsX, double_t Xlow, double_t Xup, uint_t NbinsY, double_t Ylow, double_t Yup, double_t W=1)
iterator begin(string_t re=".*")
void fill(double_t X, double_t Y, double_t Z, const poly< std::string > &names, uint_t NbinsX, double_t Xlow, double_t Xup, uint_t NbinsY, double_t Ylow, double_t Yup, uint_t NbinsZ, double_t Zlow, double_t Zup, double_t W=1)
TH1 *& operator[](string_t name)
void fill(double_t X, const char *name, uint_t NbinsX, double_t Xlow, double_t Xup, double_t W=1)
void fill(double_t X, double_t Y, const poly< std::string > &names, uint_t NbinsX, double_t Xlow, double_t Xup, double_t W=1)
boost::filter_iterator< match_name, book_t::const_iterator > const_iterator
bool operator()(const book_t::const_iterator::value_type &p)
const unsigned long uint_t
iterator find(string_t name, string_t re=".*")
void erase(string_t name)
boost::filter_iterator< match_name, book_t::iterator > iterator
iterator end(string_t re=".*")
TH1 * book(string_t name, TH1 *const hist)
const_iterator find(string_t name, string_t re=".*") const