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.

227 lines
7.5 KiB

  1. //Renata Kopecna
  2. #include "parse.hh"
  3. #include <iostream>
  4. #include <assert.h>
  5. #include <help.hh>
  6. #include <constants.hh>
  7. #include <spdlog.h>
  8. //--------------------------------------//
  9. // Helpers for parsing the options //
  10. //--------------------------------------//
  11. int parseOpts(int argc, char *argv[], basic_params &par, basic_actions &act, int nMCEvents){
  12. int opt = 0;
  13. //Check if there are any arguments
  14. if(argc > 1){
  15. spdlog::info("Got a total of {0:d} input options.", argc);
  16. }
  17. else{
  18. spdlog::error("No arguments given to the program. Use '-h' to see options. Exit...");
  19. return 1;
  20. }
  21. //Loop over all arguments and set par and act accordingly
  22. //no questionmark: value afterwards, questionamrk = bool
  23. while((opt = getopt(argc, argv, "a?:b:c?:d:e:f:g:h?:i:j:k?:l?:m?:o:p?:q?:r:s:t?:u:v:w?:x?:y:z:")) != -1){
  24. switch(opt) {
  25. case 'a': //action: do angular resolution
  26. spdlog::info("Get angular resolutions!");
  27. act.angRes = true;
  28. break;
  29. case 'b':
  30. par.bin = atoi(optarg);
  31. spdlog::info("Running on q2 bin ", par.bin);
  32. break;
  33. case 'c':
  34. spdlog::info("Get angular corrections!");
  35. //par.dataset = 3; //Always use MC //Not needed, as PHSP is hardcoded in the corrections obvsly
  36. act.angCorr = true;
  37. break;
  38. case 'd':
  39. par.dataset = atoi(optarg);
  40. if (par.dataset < 0 || par.dataset > 5){
  41. spdlog::error("Dataset can be only 0 - 5!");
  42. spdlog::info("0 for signal data");
  43. spdlog::info("1 for signal MC, 2 for Jpsi MC");
  44. spdlog::info("3 for PHSP");
  45. spdlog::info("4 for PHSP genLVL MC");
  46. spdlog::info("5 for signal genLvl MC");
  47. return 1;
  48. }
  49. else{
  50. spdlog::info("Using dataset {0:d}", par.dataset);
  51. }
  52. break;
  53. case 'e':
  54. par.nEvents = atoi(optarg);
  55. spdlog::info("Running on {0:d} events.", par.nEvents);
  56. break;
  57. case 'f':
  58. act.fitType = atoi(optarg);
  59. if (act.fitType < 0 || act.fitType > 6){
  60. spdlog::error("Fit option can be only 0 - 6!");
  61. return 1;
  62. }
  63. else{
  64. spdlog::info("Fitting with option {0:d}!", act.fitType);
  65. }
  66. break;
  67. case 'g':
  68. par.folding = atoi(optarg);
  69. if (par.folding < 0 || par.folding > 5){
  70. spdlog::error("Use only folding 0 - 4. Plus option 5 for looping over all foldings.");
  71. return 1;
  72. }
  73. spdlog::info("Using folding {0:d}.", par.folding);
  74. break;
  75. case 'h':
  76. print_help();
  77. print_errorCodes();
  78. return 0;
  79. case 'i':
  80. par.index = atoi(optarg);
  81. spdlog::info("Using index {0:d}.", par.index);
  82. break;
  83. case 'j':
  84. par.jobID = atoi(optarg);
  85. spdlog::info("Using job index {0:d}.", par.jobID);
  86. break;
  87. case 'k':
  88. spdlog::info("Convert events!");
  89. spdlog::info("Don't forget to specify what year/run/dataset.");
  90. act.convert = true;
  91. break;
  92. case 'l':
  93. spdlog::info("Likelyhood profiles on!");
  94. par.likelyhood = true;
  95. break;
  96. case 'm':
  97. spdlog::info("Getting pulls from MC");
  98. act.pullsMC = true;
  99. break;
  100. case 'o':
  101. spdlog::info("Feldman cousins!");
  102. par.FeldCous = true;
  103. break;
  104. case 'p':
  105. spdlog::info("Using P' instead of S!");
  106. par.usePprime = true;
  107. break;
  108. case 'q':
  109. spdlog::info("Looking into reference channel!");
  110. par.reference = true;
  111. break;
  112. case 'r':
  113. par.Run = atoi(optarg);
  114. if(par.Run != 0 && par.Run != 1 && par.Run != 2 && par.Run != 12 && par.Run != 21 && par.Run != 22){
  115. spdlog::error("Used incorrect input as Run number! Can be 1, 2, 12, 21, 22 or 0 in case of per-year running.");
  116. return 1;
  117. }
  118. else{
  119. spdlog::info("Use data of Run {0:d}", par.Run);
  120. }
  121. break;
  122. case 's':
  123. act.systematics = atoi(optarg);
  124. spdlog::info("Systematic study {0:d}.", act.systematics);
  125. break;
  126. case 't':
  127. act.pullsToys = true;
  128. spdlog::info("Getting pulls from toys");
  129. break;
  130. case 'u':
  131. par.nBins = atoi(optarg);
  132. spdlog::info("Number of used q2 bins: {0:d}.", par.nBins);
  133. if (par.nBins != 0 && par.nBins != 1 && par.nBins != 2 && par.nBins !=4 && par.nBins !=5
  134. && par.nBins !=8 && par.nBins !=9){ //I hope that is all :D
  135. spdlog::error("Wrong number of bins! Can be either 1, 2, 4 or 5 (or 8)!");
  136. return 1;
  137. }
  138. break;
  139. case 'v':
  140. par.verbosity = atoi(optarg); //Set verbosity level
  141. break;
  142. case 'w':
  143. act.genToys = true; //Fit generated toys. It requires -e to be set!
  144. break;
  145. case 'x':
  146. act.script = true; //Run whatever script you like
  147. spdlog::info("Running whatever is defined in RunningScripts");
  148. break;
  149. case 'y':
  150. par.year = atoi(optarg);
  151. spdlog::info("Running on year {0:d}.", par.year);
  152. par.Run = 0; //Set Run=0 so it is clear what is used
  153. break;
  154. case 'z':
  155. par.testInt = atoi(optarg);
  156. spdlog::info("testInt: {0:d}.", par.testInt);
  157. break;
  158. }
  159. }
  160. return 0;
  161. //parse the options
  162. }
  163. int checkYear(basic_params par){
  164. if (par.Run == -1 && par.year == -1){
  165. spdlog::error("I need run/years specified!");
  166. return 1;
  167. }
  168. else return 0;
  169. }
  170. int checkDataset(basic_params par){
  171. if (par.dataset == -1){
  172. spdlog::error("I need dataset specified!");
  173. return 1;
  174. }
  175. if (par.dataset == 2){
  176. par.reference = true;
  177. }
  178. return 0;
  179. }
  180. int checkOpts(basic_params &par, basic_actions &act){
  181. //TODO: enhance as you add more options to act
  182. if (act.angRes){ //-a
  183. if (checkYear(par) == 1) return 1;
  184. }
  185. if (act.angCorr){ //-c
  186. if (par.index != -1){ //-i, means to scan the corrections
  187. act.angCorrScan = true;
  188. act.angCorr = false;
  189. }
  190. }
  191. if (act.convert){
  192. if (checkYear(par) == 1) return 1;
  193. if (checkDataset(par) == 1) return 1;
  194. }
  195. if (act.fitType != -1){
  196. if (checkYear(par) == 1) return 1;
  197. if (checkDataset(par) == 1) return 1;
  198. }
  199. if (act.fitType == 4){ //Check if dataset is not data
  200. if (par.dataset == 0) return 1;
  201. //If MC fit, i can set the polarity, useful for checks
  202. if (par.index == 1) par.polarity = 1;
  203. if (par.index == 2) par.polarity = -1;
  204. }
  205. if (par.nBins == -1){
  206. spdlog::warn("Number of bins in q2 is not set! Using default settings of {0:d} bins!",NBINS_DEFAULT);
  207. par.nBins = NBINS_DEFAULT;
  208. }
  209. if (act.genToys){
  210. if (par.nEvents == -1){
  211. spdlog::warn("Number of events ot be generated is not set! Using default settings of 100 events!");
  212. par.nEvents = 100; //Generate a default number of toy events
  213. }
  214. }
  215. return 0;
  216. }