Angular analysis of B+->K*+(K+pi0)mumu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
9.0 KiB

  1. //Renata Kopecna
  2. #ifndef HELPERS_HH
  3. #define HELPERS_HH
  4. #include <string>
  5. #include <vector>
  6. #include <TF1.h>
  7. #include <TH1D.h>
  8. #include <TStopwatch.h>
  9. #include <parse.hh>
  10. //indexed auto looping over vectors
  11. #define for_indexed(...) for_indexed_v(i, __VA_ARGS__)
  12. #define for_indexed_v(v, ...) for(bool _i_ = true, _break_ = false; _i_;) for(size_t v = 0; _i_; _i_ = false) for(__VA_ARGS__) if(_break_) break; else for(bool _j_ = true; _j_;) for(_break_ = true; _j_; _j_ = false) for(bool _k_ = true; _k_; v++, _k_ = false, _break_ = false)
  13. /// usage:
  14. /// std::vector<int> v{1, 2, 3};
  15. ///for_indexed (auto const& item : v) { //the index is always i
  16. /// if (i > 0) std::cout << ", ";
  17. /// std::cout << i << ": " << item;
  18. ///}
  19. /// for_indexed_v (my_counter, auto const& item : v) //the index is v here
  20. //TODO: work on more forward declarations, it reduces the compiler time as cross-referencing is not recompiled 400 times anymore
  21. //TODO: simirarly move your includes into .cpp in order to avoid this
  22. namespace fcnc { //Forward declaration, fully defined in options.hh
  23. class options;
  24. class parameters;
  25. class bu2kstarmumu_parameters;
  26. class event;
  27. }
  28. //----------------------//
  29. // Print utils //
  30. //----------------------//
  31. std::string boolToString(bool isTrue);
  32. //reset the spdlog into my default
  33. void reset_spdlog();
  34. //set spdlog level
  35. void set_spdlog_level(int verboseLvl);
  36. //what lever is the spdlog?
  37. bool spdlog_trace();
  38. bool spdlog_debug();
  39. bool spdlog_info();
  40. bool spdlog_warn();
  41. bool spdlog_error();
  42. //Get job_id and turn it in a string
  43. std::string get_sample_from_jobID(int job_id);
  44. //Make pretty outputs with given precision (feault is two)
  45. std::string format_double(double value, unsigned int digits=2);
  46. std::string format_value(double value, double error, unsigned int digits=2);
  47. std::string format_error(double error, unsigned int digits=2);
  48. //----------------------//
  49. // Year utils //
  50. //----------------------//
  51. //Get years according to a run
  52. std::vector<int> get_years(int Run, bool MCsig, bool MCref);
  53. //Check if year makes sense
  54. void check_year(int year);
  55. int get_yearFromRun(int year);
  56. int MC_dataset(bool Reference, bool PHSP);
  57. //--------------------------------------//
  58. // General helpers //
  59. //--------------------------------------//
  60. //Copy file
  61. int copyFile(std::string from, std::string to);
  62. //Check if file/folder exists
  63. bool existsTest (const std::string& name);
  64. //Create new folder
  65. void makeFolder (const std::string& name);
  66. //Convert vector into number-space-number... string
  67. std::string convert_vector_to_string(std::vector<int> myVector);
  68. std::string convert_vector_to_string(std::vector<double> myVector);
  69. std::string convert_vector_to_string(std::vector<std::string> myVector);
  70. //Merge two vectors
  71. std::vector<double> merge_two_vecs(std::vector<double> one, std::vector<double> two);
  72. std::vector<int> merge_two_vecs(std::vector<int> one, std::vector<int> two);
  73. std::vector<std::string> merge_two_vecs(std::vector<std::string> one, std::vector<std::string> two);
  74. //Replace a part of a string
  75. bool replace(std::string& str, const std::string& from, const std::string& to);
  76. //Sum a vectors
  77. int sum_vector(std::vector<int> vec);
  78. double sum_vector(std::vector<double> vec);
  79. //Return the center of a bin
  80. double bin_center(double low, double high);
  81. //Return the center of a q2 bin
  82. double bin_center_q2(fcnc::options opts, int b);
  83. double bin_center_q2(fcnc::options *opts, int b);
  84. double bin_center_q2(std::vector<double> q2min, std::vector<double> q2max , int b);
  85. //Return half of the width (useful for errors)
  86. double bin_halfWidth(double low, double high);
  87. double bin_halfWidth_q2(fcnc::options opts, int b);
  88. double bin_halfWidth_q2(fcnc::options *opts, int b);
  89. double bin_halfWidth_q2(std::vector<double> q2min, std::vector<double> q2max, int b);
  90. //Check if the angles are in the correct range given by options
  91. bool isEvtInAngleRange(fcnc::event *evt, fcnc::options *opts);
  92. //Check if the angles are in the correct range given by default
  93. bool isEvtInAngleRange(fcnc::event *evt);
  94. //For now filter out events that are dumb dumb for folding four
  95. bool filterFldFour(fcnc::event *evt, fcnc::options *opts);
  96. //Check if value is in a vector
  97. bool isInVec(int key, std::vector<int>vec);
  98. bool isInVec(double key, std::vector<double>vec);
  99. bool isInVec(std::string key, std::vector<std::string>vec);
  100. //--------------------------------------//
  101. // Helpers for converting the tuples //
  102. //--------------------------------------//
  103. //Return's OG tuple name
  104. std::string get_inputTree_name(int job_id);
  105. //--------------------------------------//
  106. // Helpers for angular corrections //
  107. //--------------------------------------//
  108. TF1 *fitStraightLine(TH1D* hist, std::string lineName, double lowEdge, double highEdge);
  109. //--------------------------------------//
  110. // Helpers for bu2kstarmumu_pdf //
  111. //--------------------------------------//
  112. //Returns a vector with the {p wave observables, obervable in tex}, useful for histograms in a loop
  113. const std::vector<std::vector<std::string>> get_angObser_withTeX_vec();
  114. //Returns a vector with the p wave observables
  115. std::vector<std::string> get_angObser_vec();
  116. //Returns a vector with the p wave observables in tex
  117. std::vector<std::string> get_angObserTeX_vec();
  118. //--------------------------------------//
  119. // Helpers for time measuring //
  120. //--------------------------------------//
  121. struct runTime{
  122. //Measure the time for the fit:
  123. std::vector<Double_t> real_times;
  124. std::vector<Double_t> cpu_times;
  125. std::vector<Double_t> cpp_times;
  126. TStopwatch * sw;// = new TStopwatch();
  127. runTime(){
  128. sw = new TStopwatch();
  129. }
  130. void print(unsigned int nBins);
  131. void start();
  132. void stop(time_t startTime);
  133. };
  134. //--------------------------------------//
  135. // Helpers for fit scripts //
  136. //--------------------------------------//
  137. //get a vector of all available angle bkg parameters
  138. std::vector<std::string> param_string_bkg();
  139. //get a vector of all available angle mkpi parameters
  140. std::vector<std::string> param_string_bkg_mkpi();
  141. //get a string vector of all effectivelly used parameters
  142. std::vector<std::string> param_string(fcnc::options opts, bool MC);
  143. //get a string vector of mass parameters
  144. std::vector<std::string> params_string_mass(fcnc::options opts);
  145. //Reads MC fit files (massFitOnly) and gets the sigma ratio of ref/MC for given bin and pdf
  146. double get_sigmaRatio_fromMC(basic_params params, int nBins, int bin, int pdf);
  147. //---------------------------------------------//
  148. // Helpers for printing and saving fit results //
  149. //---------------------------------------------//
  150. void print_all_parameters(unsigned int nBins, fcnc::bu2kstarmumu_parameters *theParams[],
  151. int spdlog_level, std::string savePath);
  152. void print_all_parameters(unsigned int nBins, std::vector<UInt_t> pdf_idx,
  153. std::vector<fcnc::parameters*> theParams[],
  154. int spdlog_level);
  155. void tex_all_parameters(unsigned int nBins, std::vector<UInt_t> pdf_idx,
  156. std::vector<fcnc::parameters*> theParams[]);
  157. void print_fit_results(unsigned int nBins, std::vector<Int_t> fitresults);
  158. void print_fit_results(unsigned int nBins, std::vector<UInt_t> pdf_idx, std::vector<Int_t> fitresults[], bool simFit);
  159. void print_sig_yields(unsigned int nBins, std::vector<UInt_t> pdf_idx,
  160. std::vector<UInt_t> *evts_cntr, std::vector<double> *f_sigs, std::vector<double> *f_sigserr);
  161. void print_bkg_yields(unsigned int nBins, std::vector<UInt_t> pdf_idx,
  162. std::vector<UInt_t> *evts_cntr, std::vector<double> *f_sigs, std::vector<double> *f_sigserr);
  163. void print_bkgOnly_yields(unsigned int nBins, std::vector<UInt_t> pdf_idx,
  164. std::vector<fcnc::bu2kstarmumu_parameters*> theParams[],
  165. std::vector<double> bkg_int_full_range[], std::vector<UInt_t> *evts_cntr);
  166. void print_sig_yields_tex(std::string texFiletag,
  167. unsigned int nBins, std::vector<UInt_t> pdf_idx,
  168. fcnc::options *theOptions,
  169. std::vector<UInt_t> *evts_cntr, std::vector<double> *f_sigs, std::vector<double> *f_sigserr);
  170. int save_results(std::string results_file, unsigned int nBins, std::vector<UInt_t> pdf_idx, std::vector<int>*fit_results, std::vector<fcnc::parameters*> *theParams, bool simFit, fcnc::options *opts);
  171. int save_results(std::string results_file, unsigned int nBins, int n_pdf, std::vector<int> fit_results, fcnc::bu2kstarmumu_parameters **theParams, fcnc::options *opts);
  172. //--------------------------------------//
  173. // Helpers for writting latex stuff //
  174. //--------------------------------------//
  175. int clear_Latex_noteFile(std::string tag); //Deletes the old file
  176. int open_Latex_noteFile(std::string tag, std::ofstream &myfile); //Appends output at the end of the file
  177. //--------------------------------------//
  178. // Helpers for reading the parameters //
  179. //--------------------------------------//
  180. std::vector<double> load_param_values_into_vector(std::string paramName, std::string fileName);
  181. #endif // HELPERS_HH