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.

348 lines
16 KiB

  1. # Renata Kopecna
  2. #########################################################
  3. # #
  4. # Define Parser and add all options #
  5. # #
  6. #########################################################
  7. import sys
  8. import argparse
  9. RunList = [1,2,12]
  10. class ShowArgumentsParser(argparse.ArgumentParser):
  11. def error(self, message):
  12. sys.stderr.write('error: %s\n\n' %message)
  13. parser.print_usage(sys.stderr)
  14. sys.stderr.write('\n'+self.description)
  15. sys.exit(2)
  16. def addAllArgs(parser):
  17. #Basic options
  18. parser.add_argument("-v", "--verbosity",
  19. metavar = '<intVerbosity>',
  20. default = 2,
  21. type = int,
  22. help="Set verbosity level. Default is INFO.\n"+
  23. "Available levels are:\n"+
  24. "0: Trace\n"+
  25. "1: Debug\n"+
  26. "2: Info\n"+
  27. "3: Warn\n"+
  28. "4: Error\n"+
  29. "5: Critical\n\n")
  30. parser.add_argument("-log", "--log",
  31. metavar = '<strLog>',
  32. default = "",
  33. type = str,
  34. help="Set log file. Default is no log, streaming right into console.\n\n")
  35. parser.add_argument("-hilfe", "--hilfe",
  36. action="store_true",
  37. help="Print full help.\n\n")
  38. #Compile
  39. parser.add_argument("-compile", "--compile",
  40. action="store_true",
  41. help="Compile the code before runing.\n\n")
  42. parser.add_argument("-dontCompile", "--dontCompile",
  43. action="store_true",
  44. help="Don't compile the code before runing.\n\n")
  45. # #Set dataset
  46. parser.add_argument('-Run', '--Run',
  47. metavar='<Run>',
  48. default = 1,
  49. type = int,
  50. help="Set the Run number. Default is Run 1.\n\n")
  51. parser.add_argument('-allRun', '--allRun',
  52. action="store_true",
  53. default = False,
  54. help="Run on Runs 1, 2 and 12.\n\n")
  55. parser.add_argument('-year', '--year', #TODO
  56. metavar='<year>',
  57. default = -1,
  58. type = int,
  59. help="Run only on one year.\n\n") #TODO
  60. parser.add_argument("-PHSP", "--PHSP",
  61. action="store_true",
  62. default = False,
  63. help="Run on PHSP\n\n")
  64. parser.add_argument("-Data", "--Data",
  65. action="store_true",
  66. default = False,
  67. help="Run on Data\n\n")
  68. parser.add_argument("-Ref", "--Ref",
  69. action="store_true",
  70. default = False,
  71. help="Run on reference channel Jpsi\n\n")
  72. parser.add_argument("-MC", "--MC",
  73. action="store_true",
  74. default = False,
  75. help="Run on signal MC\n\n")
  76. parser.add_argument("-all", "--all",
  77. action="store_true",
  78. default = False,
  79. help = "Run on data, signal MC, reference MC and PHSP\n\n" )
  80. parser.add_argument("-allMC", "--allMC",
  81. action="store_true",
  82. default = False,
  83. help = "Run on signal MC, reference MC and PHSP\n\n" )
  84. parser.add_argument("-genMC", "--genMC",
  85. action="store_true",
  86. default = False,
  87. help="Run on generator level MC\n\n")
  88. parser.add_argument("-boost", "--boost",
  89. action="store_true",
  90. default = False,
  91. help="Run on boosted sample, turn on also generator level MC option!\n\n")
  92. #Set tasks
  93. parser.add_argument("-convert", "--convert",
  94. action="store_true",
  95. help="Convert selection tuples to FCNC tuples.\n\n")
  96. parser.add_argument("-angCorr", "--angCorr",
  97. action="store_true",
  98. help="Obtain angular acceptance correction coefficients from PHSP Monte Carlo events.\n\n")
  99. parser.add_argument("-scan", "--scan",
  100. action="store_true",
  101. help="Scan whatever you are doing :)\n\n")
  102. parser.add_argument("-fit", "--fit",
  103. action="store_true",
  104. help="Run the main fit\n\n")
  105. parser.add_argument("-angRes", "--angRes",
  106. action="store_true",
  107. help="Get angular resolution from signal MC.\n\n")
  108. parser.add_argument('-toys', '--toys', #TODO
  109. action="store_true",
  110. help="Generate toys. Add -evts to generate custom number of events.\n\n")
  111. parser.add_argument('-script', '--script',
  112. action="store_true",
  113. help="Run whatever script you decided.\n\n")
  114. parser.add_argument('-job', '--job',
  115. metavar='<job>',
  116. default = -1,
  117. type = int,
  118. help="Set the job number\n\n")
  119. #Set toy options
  120. parser.add_argument('-evts', '--evts',
  121. metavar='<evts>',
  122. default = -1,
  123. type = int,
  124. help="Set number of used/generated events\n\n")
  125. #Set fit options
  126. parser.add_argument('-onlyBkg', '--onlyBkg',
  127. action="store_true",
  128. help="Fit only angular background.\n\n")
  129. parser.add_argument('-upper', '--upper',
  130. action="store_true",
  131. help="Fit only upper-mass side-band.\n\n")
  132. parser.add_argument('-lower', '--lower',
  133. action="store_true",
  134. help="Fit only lower-mass side-band.\n\n")
  135. parser.add_argument('-bin', '--bin',
  136. metavar='<bin>',
  137. default = -1,
  138. type = int,
  139. help="Which angular bin would you like to fit?\n\n")
  140. parser.add_argument('-nBins', '--nBins',
  141. metavar='<nBins>',
  142. default = -1,
  143. type = int,
  144. help="Set total number q2 bins.\n\n")
  145. parser.add_argument("-MagDown", "--MagDown",
  146. action="store_true",
  147. default = False,
  148. help="Run only on MagDown\n\n")
  149. parser.add_argument("-MagUp", "--MagUp",
  150. action="store_true",
  151. default = False,
  152. help="Run only on MagUp\n\n")
  153. parser.add_argument('-trueMC', '--trueMC',
  154. action="store_true",
  155. help="Use MC true information.\n\n")
  156. parser.add_argument('-likelyhood', '--likelyhood',
  157. action="store_true",
  158. help="Likelihood profile scans.\n\n")
  159. parser.add_argument('-massDim', '--massDim',
  160. action="store_true",
  161. help="Fit mass dimension\n\n")
  162. parser.add_argument('-MoM', '--MoM',
  163. action="store_true",
  164. help="Use Method of Moments instead of the fit.\n\n")
  165. parser.add_argument('-observeP', '--observeP',
  166. action="store_true",
  167. help="use P(') angular observables in the fit instead of the S(')\n\n")
  168. parser.add_argument('-folding', '--folding',
  169. metavar='<folding>',
  170. default = -1,
  171. type = int,
  172. help="Set the folding of angles.\n"
  173. +"Five possibilities use range [0-4]\n"
  174. +"\t0: phi' = phi + pi for phi < 0\n"
  175. +"\t1: phi' = -phi for phi < 0\n"
  176. +"\t phi' = pi - phi for ctl < 0\n"
  177. +"\t ctl' = -ctl for ctl < 0\n"
  178. +"\t2: phi' = -phi for phi < 0\n"
  179. +"\t ctl' = -ctl for ctl < 0\n"
  180. +"\t3: phi' = pi - phi for phi > pi/2\n"
  181. +"\t phi' = -pi - phi for phi < -pi/2\n"
  182. +"\t ctl' = -ctl for ctl < 0\n"
  183. +"\t4: phi' = pi - phi for phi > pi/2\n"
  184. +"\t phi' = -pi - phi for phi < -pi/2\n"
  185. +"\t ctk' = -ctk for ctk < 0\n"
  186. +"\t ctl' = -ctl for ctl < 0\n"
  187. +"Default is -1, meaning no folding.\n\n")
  188. parser.add_argument('-loopFolds', '--loopFolds',
  189. action="store_true",
  190. help="Evaluate all five foldings\n\n")
  191. # #Other options
  192. #parser.add_argument('-FC', '--FC', #TODO
  193. # action="store_true",
  194. # help="Run Feldman-Cousins: par=<int>/8 and q2bin=<int>%%8") #TODO
  195. #parser.add_argument('-pullsMC', '--pullsMC', #TODO
  196. # action="store_true",
  197. # help="Create -pullsMC pulls using specified signal MC events.") #TODO
  198. parser.add_argument('-index', '--index', #TODO
  199. metavar='<index>',
  200. default = -1,
  201. type = int,
  202. help="Set index, used for various checks.")
  203. #Systematics
  204. #parser.add_argument('-systematics', '--systematics', #TODO "-s <int>"
  205. # metavar='<systematics>',
  206. # default = -1,
  207. # type = int,
  208. # help="Run a systematic study number:\n"
  209. # +"\t1\t:Bootstrapping of PHSP MC\n"
  210. # +"\t2\t:Perform fit with non-symmetric acceptance in ctl\n"
  211. # +"\t3\t:Increase Legendre poly order by 2 for PHSP MC\n"
  212. # +"\t4\t:Randomly change PHSP MC reweighting wihtin it's uncertainties\n"
  213. # +"\t5\t:Check non-homogeneous FS distributions in q2\n"
  214. # +"\t6\t:Vary angles (ctk, ctl and phi) within the angular resoluation\n"
  215. # +"\t7\t:Generate toy events with double-gaussian profile and fit with CB\n"
  216. # +"\t8\t:Systematic study on angular background model, add 10%% contribution of higher order\n"
  217. # +"\t9\t:Investigate systematic effects due to trigger selection\n"
  218. # +"\t10\t:Reweight PHSP MC according to pion PT disagreement in DD\n"
  219. # +"\t11\t:Background systematic for mimicing the B0 -> KS mu mu veto\n")
  220. #Test parameter
  221. parser.add_argument('-test', '--test', #TODO
  222. metavar='<test>',
  223. default = -1,
  224. type = int,
  225. help="Test parameter. When !=-1, verbosity automatically on debug.\n\n") #TODO
  226. def getDatasetCommands(opts):
  227. arg_list = []
  228. if (opts.all): return ["-d 0", "-d 1", "-d 2", "-d 3", "-d 4"]
  229. if (opts.allMC): return ["-d 1", "-d 2", "-d 3", "-d 4"]
  230. if (opts.Data): arg_list.append("-d 0")
  231. if (opts.genMC):
  232. if (opts.PHSP): arg_list.append("-d 4")
  233. else: arg_list.append("-d 5")
  234. else:
  235. if (opts.MC):
  236. if (opts.Ref): arg_list.append("-d 2")
  237. else: arg_list.append("-d 1")
  238. if (opts.PHSP): arg_list.append("-d 3")
  239. return arg_list
  240. def setDataOpts(opts,arg):
  241. if (arg == "-d 0"):
  242. opts.Data = True
  243. opts.MC = False
  244. opts.PHSP = False
  245. elif (arg == "-d 1"):
  246. opts.Data = False
  247. opts.MC = True
  248. opts.Ref = False
  249. opts.PHSP = False
  250. if (arg == "-d 2"):
  251. opts.Data = False
  252. opts.MC = True
  253. opts.Ref = True
  254. opts.PHSP = False
  255. if (arg == "-d 3"):
  256. opts.Data = False
  257. opts.MC = True
  258. opts.PHSP = True
  259. def getActionCommands(opts):
  260. arg_list = []
  261. if (opts.test!=-1):
  262. arg_list.append("-z " + str(opts.test))
  263. opts.verbosity = 1
  264. if (opts.angRes): arg_list.append("-a")
  265. if (opts.angCorr):
  266. arg_list.append("-c")
  267. if (opts.scan): arg_list.append("-i 1")
  268. if (opts.fit):
  269. if (opts.onlyBkg):
  270. arg_list.append("-f 0")
  271. if (opts.upper): arg_list.append("-i 2")
  272. if (opts.lower): arg_list.append("-i 1")
  273. elif (opts.massDim): arg_list.append("-f 2")
  274. elif (opts.MoM): arg_list.append("-f 3")
  275. elif (opts.MC or opts.PHSP):
  276. arg_list.append("-f 4") #TODO: I'm working on this one
  277. if (opts.MagDown): arg_list.append("-i 2")
  278. if (opts.MagUp): arg_list.append("-i 1")
  279. elif (opts.genMC): arg_list.append("-f 5")
  280. else : arg_list.append("-f 1")
  281. if (opts.toys): arg_list.append("-w")
  282. if (opts.convert): arg_list.append("-k")
  283. #if (opts.pullsMC): arg_list.append("-m") #or -t when form toys TODO
  284. #if (opts.systematics != -1): arg_list.append("-s " + str(opts.systematics)) TODO
  285. if (opts.script): arg_list.append("-x")
  286. if (opts.upper): arg_list.append("") #TODO
  287. if (opts.lower): arg_list.append("") #TODO
  288. if (opts.trueMC): arg_list.append("") #TODO
  289. return arg_list
  290. def getParameterCommands(opts):
  291. arg_list = []
  292. if (opts.bin!=-1): arg_list.append("-b " + str(opts.bin))
  293. if (opts.evts!=-1): arg_list.append("-e " + str(opts.evts))
  294. if (opts.folding!=-1): arg_list.append("-g " + str(opts.folding))
  295. if (opts.loopFolds): arg_list.append("-g 5")
  296. if (opts.likelyhood): arg_list.append("-l")
  297. if (opts.observeP): arg_list.append("-p")
  298. #if (opts.FC): arg_list.append("-o") TODO
  299. if (opts.nBins!=-1): arg_list.append("-u " + str(opts.nBins))
  300. if (opts.Ref): arg_list.append("-q")
  301. if (opts.index !=-1): arg_list.append("-i " + str(opts.index))
  302. if (opts.job!=-1): arg_list.append("-j " + str(opts.job))
  303. return arg_list
  304. def fullArgListPerRun(opts):
  305. runs = []
  306. if (opts.allRun): runs = RunList
  307. else: runs = [opts.Run]
  308. argListList = []
  309. for dataArg in getDatasetCommands(opts):
  310. for r in runs:
  311. arg_list = []
  312. arg_list.append('-v ' + str(opts.verbosity))
  313. setDataOpts(opts,dataArg)
  314. if (opts.Run!=-1): arg_list.append("-r " + str(r))
  315. if (opts.year!=-1): arg_list.append('-y' + str(opts.year))
  316. if (len(arg_list)==0): print ("The script needs at least run or year! Crashing now")
  317. arg_list.extend([dataArg])
  318. arg_list.extend(getActionCommands(opts))
  319. arg_list.extend(getParameterCommands(opts))
  320. argListList.append(arg_list)
  321. return argListList