HistCollection.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef histcollection_h
  2. #define histcollection_h
  3. #include <string>
  4. #include <sstream>
  5. #include <map>
  6. #include <TH1.h>
  7. #include <TH2.h>
  8. class HistCollection{
  9. private:
  10. map<std::string, TH1*> histograms;
  11. std::string prefix;
  12. TH1D* book_histogram_1d(const std::string &id, const std::string &title,
  13. int nbins, double min, double max){
  14. const char* full_id = (prefix+id).c_str();
  15. TH1D *hist = new TH1D(full_id, title.c_str(), nbins, min, max);
  16. histograms[id] = hist;
  17. return hist;
  18. };
  19. TH2D* book_histogram_2d(const std::string id, const std::string title,
  20. int nbins_x, double min_x, double max_x,
  21. int nbins_y, double min_y, double max_y){
  22. const char* full_id = (prefix+id).c_str();
  23. TH2D *hist = new TH2D(full_id, title.c_str(), nbins_x, min_x, max_x, nbins_y, min_y, max_y);
  24. histograms[id] = hist;
  25. return hist;
  26. };
  27. public:
  28. /* List of included histogram objects
  29. */
  30. TH1D *lepton_count;
  31. TH1D *delta_pt;
  32. TH2D *lepton_count_vs_delta_pt;
  33. HistCollection(const std::string &filename)
  34. : prefix(filename.substr(0, filename.size()-5))
  35. {
  36. // this->prefix = prefix.substr(0, prefix.size()-5);
  37. lepton_count = book_histogram_1d("lepton_count", "Good Lepton Count", 10, 0, 10);
  38. delta_pt = book_histogram_1d("delta_pt", "{\\\\Delta P_T}", 100, -50, 50);
  39. lepton_count_vs_delta_pt = book_histogram_2d("lepton_count_vs_delta_pt", "Good Lepton Count Vs {\\\\delta P_T}",
  40. 10, 0, 10,
  41. 100, -50, 50);
  42. };
  43. HistCollection(): HistCollection("") {};
  44. ~HistCollection(){
  45. for(auto& p: histograms)
  46. delete p.second;
  47. };
  48. vector<std::string> get_ids(){
  49. vector<std::string> vec;
  50. for(auto& p: histograms)
  51. vec.push_back(p.first);
  52. return vec;
  53. }
  54. TH1* get_by_id(const std::string &id){
  55. TH1* hist = histograms[id];
  56. return hist;
  57. }
  58. };
  59. #endif // histcollection_h