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.

378 lines
11 KiB

  1. import subprocess
  2. from subprocess import Popen, PIPE
  3. decay_number_dict = {
  4. "SigMC" : {
  5. "2011": {
  6. "E": "3500",
  7. "nu": "2",
  8. "trigger": "0x40760037",
  9. "stripping": "21r1",
  10. "reco": "Reco14c",
  11. "simVer": "Sim09a",
  12. "dst": "DST",
  13. "merge": ""
  14. },
  15. "2012": {
  16. "E": "4000",
  17. "nu": "2.5",
  18. "trigger": "0x409f0045",
  19. "stripping": "21",
  20. "reco": "Reco14c",
  21. "simVer": "Sim09a",
  22. "dst": "DST",
  23. "merge": ""
  24. },
  25. "2015": {
  26. "E": "6500",
  27. "nu": "1.6-25ns",
  28. "trigger": "0x411400a2",
  29. "stripping": "24r2",
  30. "reco": "Reco15a/Turbo02",
  31. "simVer": "Sim09i",
  32. "dst": "DST",
  33. "merge": ""
  34. },
  35. "2016": {
  36. "E": "6500",
  37. "nu": "1.6-25ns",
  38. "trigger": "0x6139160F",
  39. "stripping": "28r2",
  40. "reco": "Reco16/Turbo03a",
  41. "simVer": "Sim09i",
  42. "dst": "DST",
  43. "merge": ""
  44. },
  45. "2017": {
  46. "E": "6500",
  47. "nu": "1.6-25ns",
  48. "trigger": "0x62661709",
  49. "stripping": "29r2",
  50. "reco": "Reco17/Turbo04a-WithTurcal",
  51. "simVer": "Sim09e",
  52. "dst": "MDST",
  53. "merge": ""
  54. },
  55. "2018": {
  56. "E": "6500",
  57. "nu": "1.6-25ns",
  58. "trigger": "0x617d18a4",
  59. "stripping": "34r0p1", #34 for 12115102
  60. "reco": "Reco18/Turbo05-WithTurcal",
  61. "simVer": "Sim09h", #Sim09f for 12115102
  62. "dst": "DST",
  63. "merge": ""
  64. },
  65. "general":{
  66. "dec_ID": "12113100", #same for 12115102
  67. "filter": "NoPrescalingFlagged",
  68. "stream": "ALLSTREAMS",
  69. "pythiaVer": "8"
  70. }
  71. },
  72. "RefMC" : {
  73. "2011": {
  74. "E": "3500",
  75. "nu": "2",
  76. "trigger": "0x40760037",
  77. "stripping": "21r1",
  78. "reco": "Reco14c",
  79. "simVer": "Sim09a",
  80. "dst": "DST",
  81. "merge": ""
  82. },
  83. "2012": {
  84. "E": "4000",
  85. "nu": "2.5",
  86. "trigger": "0x409f0045",
  87. "stripping": "21",
  88. "reco": "Reco14c",
  89. "simVer": "Sim09a",
  90. "dst": "DST",
  91. "merge": ""
  92. },
  93. "2015": {
  94. "E": "6500",
  95. "nu": "1.6-25ns",
  96. "trigger": "0x411400a2",
  97. "stripping": "24r1",
  98. "reco": "Reco15a/Turbo02",
  99. "simVer": "Sim09e",
  100. "dst": "DST",
  101. "merge": ""
  102. },
  103. "2016": {
  104. "E": "6500",
  105. "nu": "1.6-25ns",
  106. "trigger": "0x6139160F",
  107. "stripping": "28r1",
  108. "reco": "Reco16/Turbo03",
  109. "simVer": "Sim09e",
  110. "dst": "DST",
  111. "merge": ""
  112. },
  113. "general":{
  114. "dec_ID": "12143401", #same for 12145102
  115. "filter": "NoPrescalingFlagged",
  116. "stream": "ALLSTREAMS",
  117. "pythiaVer": "8"
  118. }
  119. },
  120. "PHSP" : { #same for 12115179
  121. "2011": {
  122. "E": "3500",
  123. "nu": "2",
  124. "trigger": "0x40760037",
  125. "stripping": "21r1p1",
  126. "reco": "Reco14c",
  127. "simVer": "Sim09f",
  128. "dst": "DST",
  129. "merge": "Merge14/",
  130. "pythiaVer": "8"
  131. },
  132. "2012": {
  133. "E": "4000",
  134. "nu": "2.5",
  135. "trigger": "0x409f0045",
  136. "stripping": "21r0p1",
  137. "reco": "Reco14c",
  138. "simVer": "Sim09f",
  139. "dst": "DST",
  140. "merge": "Merge14/",
  141. "pythiaVer": "8"
  142. },
  143. "2015": {
  144. "E": "6500",
  145. "nu": "1.6-25ns",
  146. "trigger": "0x411400a2",
  147. "stripping": "24r1",
  148. "reco": "Reco15a/Turbo02",
  149. "simVer": "Sim09h",
  150. "dst": "MDST",
  151. "merge": "",
  152. "pythiaVer": "6"
  153. },
  154. "2016": {
  155. "E": "6500",
  156. "nu": "1.6-25ns",
  157. "trigger": "0x6139160F",
  158. "stripping": "28r1",
  159. "reco": "Reco16/Turbo03",
  160. "simVer": "Sim09f",
  161. "dst": "MDST",
  162. "merge": "Merge14/",
  163. "pythiaVer": "8"
  164. },
  165. "2017": {
  166. "E": "6500",
  167. "nu": "1.6-25ns",
  168. "trigger": "0x62661709",
  169. "stripping": "29r2",
  170. "reco": "Reco17/Turbo04a-WithTurcal",
  171. "simVer": "Sim09f",
  172. "dst": "MDST",
  173. "merge": "Merge14/",
  174. "pythiaVer": "8"
  175. },
  176. "2018": {
  177. "E": "6500",
  178. "nu": "1.6-25ns",
  179. "trigger": "0x617d18a4",
  180. "stripping": "34",
  181. "reco": "Reco18/Turbo05-WithTurcal",
  182. "simVer": "Sim09f",
  183. "dst": "MDST",
  184. "merge": "Merge14/",
  185. "pythiaVer": "8"
  186. },
  187. "general":{
  188. "dec_ID": "12113446", #same for 12115179
  189. "filter": "Filtered",
  190. "stream": "B2XMUMU.STRIP"
  191. }
  192. },
  193. "data" : {
  194. "11": {
  195. "E": "3500",
  196. "nu": "2",
  197. "trigger": "",
  198. "stripping": "21r1",
  199. "reco": "Reco14",
  200. "dst": "MDST"
  201. },
  202. "12": {
  203. "E": "4000",
  204. "nu": "2.5",
  205. "trigger": "",
  206. "stripping": "21r0p1a",
  207. "reco": "Reco14",
  208. "dst": "MDST"
  209. },
  210. "15": {
  211. "E": "6500",
  212. "nu": "1.6-25ns",
  213. "trigger": "",
  214. "stripping": "24r2",
  215. "reco": "Reco15a",
  216. "dst": "MDST"
  217. },
  218. "16": {
  219. "E": "6500",
  220. "nu": "1.6-25ns",
  221. "trigger": "",
  222. "stripping": "28r2",
  223. "reco": "Reco16",
  224. "dst": "MDST"
  225. },
  226. "17": {
  227. "E": "6500",
  228. "nu": "1.6-25ns",
  229. "trigger": "",
  230. "stripping": "29r2",
  231. "reco": "Reco17",
  232. "dst": "MDST"
  233. },
  234. "18": {
  235. "E": "6500",
  236. "nu": "1.6-25ns",
  237. "trigger": "",
  238. "stripping": "34r0p1", #34 for 12115102
  239. "reco": "Reco18",
  240. "dst": "MDST"
  241. },
  242. "general":{
  243. "dec_ID": "90000000",
  244. "filter": "NoPrescalingFlagged",
  245. "stream": "ALLSTREAMS",
  246. "pythiaVer": "8",
  247. "merge": "",
  248. "simVer": "",
  249. "trigger": ""
  250. }
  251. }
  252. }
  253. year_dict ={"SigMC": ["2011", "2012","2015", "2016", "2017", "2018"],
  254. "RefMC": ["2011", "2012","2015", "2016"],
  255. "PHSP": ["2011", "2012","2015", "2016", "2017", "2018"],
  256. "data": ["11", "12","15", "16", "17", "18"]
  257. }
  258. def getPath(year, pol, sample):
  259. tmp_dict = dict(decay_number_dict[sample][year])
  260. gen_dict = dict(decay_number_dict[sample]["general"])
  261. tmp_dict.update(gen_dict)
  262. tmp_dict["year"] = year
  263. tmp_dict["pol"] = pol
  264. if (sample == "data"): #data
  265. PATH ="/LHCb/Collision%(year)s/Beam%(E)sGeV-VeloClosed-Mag%(pol)s/Real Data/%(reco)s/Stripping%(stripping)s/%(dec_ID)s/LEPTONIC.%(dst)s" % tmp_dict
  266. else: #MC
  267. PATH = "/MC/%(year)s/Beam%(E)sGeV-%(year)s-Mag%(pol)s-Nu%(nu)s-Pythia%(pythiaVer)s/%(simVer)s/Trig%(trigger)s/%(reco)s/Stripping%(stripping)s%(filter)s/%(merge)s%(dec_ID)s/%(stream)s.%(dst)s" % tmp_dict
  268. print PATH
  269. OUTFILE = "%(dec_ID)s_%(year)s%(pol)s.py" % tmp_dict
  270. #print 'LFN output file: ', OUTFILE
  271. return PATH, OUTFILE
  272. def getLFNs(nFiles,BKKpath):
  273. #Call Dirac
  274. dirac_command = subprocess.Popen('lb-run LHCbDIRAC dirac-bookkeeping-get-files --BKQuery \"{0}\"'.format(BKKpath), shell=True, stdout=subprocess.PIPE)
  275. #Read in Dirac output
  276. stdout = dirac_command.communicate()[0]
  277. #Split the output per line
  278. stdout = stdout.split('\n')
  279. #Create an empty list
  280. LFNlist= []
  281. #Check how many files are required
  282. if (nFiles == -1): max_file = len(stdout)-2
  283. else: max_file = min(nFiles+3,len(stdout)-2)
  284. #First 3 entries are junk from LHCbDIRAC dirac-bookkeeping-get-files
  285. for i in range(3, max_file+1):
  286. tmpLFN = [stdout[i].split(' ')][0]
  287. tmpLFN = tmpLFN[0]
  288. LFNlist.append(tmpLFN)
  289. return LFNlist
  290. def writeLFNs(nFiles, year, pol, sample):
  291. #Get the paths
  292. BKKpath, LFNfile = getPath(year,pol, sample)
  293. #Get the LFNs from the paths
  294. lfn_list = getLFNs(nFiles,BKKpath)
  295. #Open the lfn target file and write all the lfns into it
  296. address_file = open(LFNfile,'w')
  297. address_file.write("""from Gaudi.Configuration import *\n""")
  298. address_file.write("""from GaudiConf import IOHelper\n""")
  299. address_file.write("""IOHelper('ROOT').inputFiles([\n""")
  300. for lfn in lfn_list:
  301. address_file.write("""'LFN:""" + lfn + """'\n""")
  302. address_file.write("""], clear=True)\n""")
  303. return
  304. def getProductionID(year, pol, sample):
  305. #Exctract the production ID from LFN
  306. path = getPath(year,pol,sample)
  307. lfn = getLFNs(1,path[0])[0]
  308. lfn_split = lfn.split('/')
  309. return lfn_split[5]
  310. def printAllProductionIDs(sample):
  311. for year in year_dict[sample]:
  312. print "Production ID for", sample, "year", year, "\t", getProductionID(year,"Down",sample)
  313. return
  314. def get_eff(year, pol, sample):
  315. import os
  316. command = "lb-run LHCbDirac/prod dirac-bookkeeping-rejection-stats -B " + str(getPath(year,pol, sample)[0])
  317. print command
  318. os.system(command)
  319. def get_tags(year, pol, sample):
  320. import os
  321. #command = "lb-run LHCbDirac/prod dirac-bookkeeping-production-information " + str(getProductionID(year,pol, sample)) + " | grep CONDDB"
  322. #print command
  323. #os.system(command)
  324. command = "lb-run LHCbDirac/prod dirac-bookkeeping-production-information " + str(getProductionID(year,pol, sample)) + " | grep DDB"
  325. #print command2
  326. os.system(command)
  327. #getPath("2011","Down", "SigMC")
  328. #getPath("2012","Down", "SigMC")
  329. #getPath("2015","Down", "SigMC")
  330. getPath("2016","Down", "SigMC")
  331. #getPath("2017","Down", "SigMC")
  332. #getPath("2018","Down", "SigMC")
  333. #getPath("2011","Down", "RefMC")
  334. #getPath("2012","Down", "RefMC")
  335. #getPath("2015","Down", "RefMC")
  336. #getPath("2016","Down", "RefMC")
  337. #getPath("2011","Down", "PHSP")
  338. #getPath("2012","Down", "PHSP")
  339. #getPath("2015","Down", "PHSP")
  340. #getPath("2016","Down", "PHSP")
  341. #getPath("2017","Down", "PHSP")
  342. #getPath("2018","Down", "PHSP")
  343. #printAllProductionIDs("RefMC")
  344. #printAllProductionIDs("PHSP")