HistCollection.hpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #ifndef histcollection_h
  2. #define histcollection_h
  3. #include <string>
  4. #include <sstream>
  5. #include <iostream>
  6. #include <map>
  7. #include <cmath>
  8. #include <TCanvas.h>
  9. #include <TH1.h>
  10. #include <TH2.h>
  11. #define PI 3.14159
  12. #define PDG_ELECTRON = 11
  13. #define PDG_MUON = 13
  14. struct HistWithPlottingInfo{
  15. TH1* hist;
  16. std::string draw_string;
  17. HistWithPlottingInfo()
  18. :hist(0),draw_string(""){};
  19. HistWithPlottingInfo(TH1* hist, std::string draw_string)
  20. :hist(hist),draw_string(draw_string){};
  21. };
  22. class HistCollection{
  23. private:
  24. map<std::string, HistWithPlottingInfo> histograms;
  25. std::string sample_name;
  26. unsigned int event_count;
  27. std::string hist_id(const std::string &id){
  28. return sample_name+"_"+id;
  29. }
  30. TH1D* book_histogram_1d(const std::string &id, const std::string &title,
  31. int nbins, double min, double max,
  32. const std::string draw_string = ""){
  33. std::string full_id = hist_id(id);
  34. TH1D *hist = new TH1D(full_id.c_str(), title.c_str(), nbins, min, max);
  35. histograms[id] = HistWithPlottingInfo(hist, draw_string);
  36. return hist;
  37. };
  38. TH2D* book_histogram_2d(const std::string id, const std::string title,
  39. int nbins_x, double min_x, double max_x,
  40. int nbins_y, double min_y, double max_y){
  41. std::string full_id = hist_id(id);
  42. TH2D *hist = new TH2D(full_id.c_str(), title.c_str(), nbins_x, min_x, max_x, nbins_y, min_y, max_y);
  43. histograms[id] = HistWithPlottingInfo(hist, "COLZ");
  44. return hist;
  45. };
  46. public:
  47. // List of included histogram objects
  48. TH1D *lepton_count;
  49. TH1D *lepton_count_pass_miniiso;
  50. TH1D *lepton_count_pass_miniiso_event;
  51. TH1D *lepton_count_pass_miniiso_ratio;
  52. TH1D *delta_pt;
  53. TH2D *lepton_count_vs_delta_pt;
  54. TH1D *top_quark_count;
  55. TH1D *jet_count_trilepton;
  56. TH1D *jet_count_ss_dilepton;
  57. TH1D *jet_count_os_dilepton;
  58. TH1D *jet_count;
  59. TH1D *b_jet_discriminator;
  60. TH1D *b_jet_count;
  61. TH1D *b_jet_pt_all;
  62. TH1D *b_jet_pt_3_or_more;
  63. TH1D *trilepton_iso_1;
  64. TH1D *trilepton_iso_2;
  65. TH1D *trilepton_iso_3;
  66. TH1D *trilepton_jet_iso_1;
  67. TH1D *trilepton_jet_iso_2;
  68. TH1D *trilepton_jet_iso_3;
  69. TH1D *dijet_mass;
  70. TH1D *dijet_mass_no_b;
  71. TH1D *dijet_mass_one_b;
  72. TH1D *dijet_mass_only_b;
  73. TH1D *trijet_mass;
  74. TH1D *trijet_mass_no_b;
  75. TH1D *trijet_mass_one_b;
  76. TH1D *trijet_mass_only_b;
  77. HistCollection(const std::string &sample_name)
  78. : sample_name(sample_name), event_count(0)
  79. {
  80. // ---------------------------------------------
  81. lepton_count = book_histogram_1d("lepton_count", "Lepton Multiplicity",
  82. 8, 0, 8);
  83. // ---------------------------------------------
  84. lepton_count_pass_miniiso = book_histogram_1d("lepton_count_pass_miniiso",
  85. "Number of Leptons passing mini-isolation",
  86. 8, 0, 8);
  87. // ---------------------------------------------
  88. lepton_count_pass_miniiso_event = book_histogram_1d("lepton_count_pass_miniiso_event",
  89. "Lepton Multiplicity - Mini-iso Cut",
  90. 8, 0, 8);
  91. // ---------------------------------------------
  92. lepton_count_pass_miniiso_ratio = book_histogram_1d("lepton_count_pass_miniiso_ratio",
  93. "Lepton Multiplicity - Mini-iso pass ratio",
  94. 8, 0, 8);
  95. // ---------------------------------------------
  96. delta_pt = book_histogram_1d("delta_pt", "{\\Delta P_T}",
  97. 100, -50, 50);
  98. // ---------------------------------------------
  99. lepton_count_vs_delta_pt = book_histogram_2d("lepton_count_vs_delta_pt",
  100. "Good Lepton Count Vs {\\Delta P_T}",
  101. 10, 0, 10, 100, -50, 50);
  102. // ---------------------------------------------
  103. top_quark_count = book_histogram_1d("top_quark_count", "Top Quark Multiplicity",
  104. 4, 0, 4);
  105. // ---------------------------------------------
  106. jet_count_trilepton = book_histogram_1d("jet_count_trilepton",
  107. "Jet Multiplicity - Trilepton",
  108. 13, 0, 13);
  109. jet_count_ss_dilepton = book_histogram_1d("jet_count_ss_dilepton",
  110. "Jet Multiplicity - Same-Sign Dilepton",
  111. 13, 0, 13);
  112. jet_count_os_dilepton = book_histogram_1d("jet_count_os_dilepton",
  113. "Jet Multiplicity - Opposite-Sign Dilepton",
  114. 13, 0, 13);
  115. // ---------------------------------------------
  116. jet_count = book_histogram_1d("jet_count", "Jet Multiplicity",
  117. 13, 0, 13);
  118. // ---------------------------------------------
  119. b_jet_discriminator = book_histogram_1d("b_jet_discriminator", "B-Jet Discriminator",
  120. 40, -1, 1);
  121. // ---------------------------------------------
  122. b_jet_count = book_histogram_1d("b_jet_count", "B-Jet Multiplicity",
  123. 10, 0, 10);
  124. // ---------------------------------------------
  125. b_jet_pt_all = book_histogram_1d("b_jet_pt_all", "B-Jet {P_T} - All",
  126. 50, 0, 2000);
  127. // ---------------------------------------------
  128. b_jet_pt_3_or_more = book_histogram_1d("b_jet_pt_3_or_more", "B-Jet {P_T} - 3 or more",
  129. 50, 0, 2000);
  130. // ---------------------------------------------
  131. trilepton_iso_1 = book_histogram_1d("trilepton_iso_1", "Trilepton Isolation - First",
  132. 25, 0, 2*PI);
  133. // ---------------------------------------------
  134. trilepton_iso_2 = book_histogram_1d("trilepton_iso_2", "Trilepton Isolation - Second",
  135. 25, 0, 2*PI);
  136. // ---------------------------------------------
  137. trilepton_iso_3 = book_histogram_1d("trilepton_iso_3", "Trilepton Isolation - Third",
  138. 25, 0, 2*PI);
  139. // ---------------------------------------------
  140. trilepton_jet_iso_1 = book_histogram_1d("trilepton_jet_iso_1", "Trilepton Jet Isolation - First",
  141. 25, 0, 2*PI);
  142. // ---------------------------------------------
  143. trilepton_jet_iso_2 = book_histogram_1d("trilepton_jet_iso_2", "Trilepton Jet Isolation - Second",
  144. 25, 0, 2*PI);
  145. // ---------------------------------------------
  146. trilepton_jet_iso_3 = book_histogram_1d("trilepton_jet_iso_3", "Trilepton Jet Isolation - Third",
  147. 25, 0, 2*PI);
  148. // ---------------------------------------------
  149. dijet_mass = book_histogram_1d("dijet_mass", "Di-Jet Mass",
  150. 100, 0, 1500);
  151. // ---------------------------------------------
  152. }
  153. HistCollection(): HistCollection("") {};
  154. ~HistCollection(){
  155. for(auto& p: histograms)
  156. delete p.second.hist;
  157. }
  158. void draw(TCanvas* canvas,
  159. std::pair<int, int> shape = {0,0}){
  160. std::pair<int, int> null_shape(0,0);
  161. if (shape == null_shape){
  162. int n = (int)ceil(sqrt(histograms.size()));
  163. shape.first = n;
  164. shape.second = n;
  165. }
  166. canvas->Clear();
  167. canvas->Divide(shape.first, shape.second);
  168. int i = 1;
  169. for(auto& p: histograms){
  170. canvas->cd(i++);
  171. p.second.hist->SetStats(false);
  172. p.second.hist->Draw(p.second.draw_string.c_str());
  173. }
  174. }
  175. std::string get_sample_name(){
  176. return sample_name;
  177. }
  178. unsigned int get_event_count(){
  179. return event_count;
  180. }
  181. vector<std::string> get_ids(){
  182. vector<std::string> vec;
  183. for(auto& p: histograms)
  184. vec.push_back(p.first);
  185. return vec;
  186. }
  187. TH1* get_by_id(const std::string &id){
  188. TH1* hist = histograms[id].hist;
  189. return hist;
  190. }
  191. HistCollection& operator++(){
  192. event_count++;
  193. return *this;
  194. }
  195. HistCollection operator++(int){
  196. HistCollection tmp(*this);
  197. operator++();
  198. return tmp;
  199. }
  200. };
  201. #endif // histcollection_h