Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 108.46 KB | None | 0 0
  1. # Run quiet mode
  2. import sys
  3. sys.argv.append( '-b' )
  4. import ROOT
  5. ROOT.gROOT.SetBatch(1)
  6. #from Helpers import *
  7. ROOT.gErrorIgnoreLevel=1001
  8. from ROOT import *
  9. import random
  10. import os
  11. import numpy as np
  12. from math import *
  13. from GEMCSCdPhiDict_wholeChamber import *
  14.  
  15. ROOT.gROOT.SetBatch(1)
  16. ROOT.gStyle.SetStatW(0.07)
  17. ROOT.gStyle.SetStatH(0.06)
  18.  
  19. ROOT.gStyle.SetOptStat(0)
  20.  
  21. #ROOT.gStyle.SetErrorX(0)
  22. #ROOT.gStyle.SetErrorY(0)
  23.  
  24. ROOT.gStyle.SetTitleStyle(0)
  25. ROOT.gStyle.SetTitleAlign(13) ## coord in top left
  26. ROOT.gStyle.SetTitleX(0.)
  27. ROOT.gStyle.SetTitleY(1.)
  28. ROOT.gStyle.SetTitleW(1)
  29. ROOT.gStyle.SetTitleH(0.058)
  30. ROOT.gStyle.SetTitleBorderSize(0)
  31.  
  32. ROOT.gStyle.SetPadLeftMargin(0.126)
  33. ROOT.gStyle.SetPadRightMargin(0.10)
  34. ROOT.gStyle.SetPadTopMargin(0.06)
  35. ROOT.gStyle.SetPadBottomMargin(0.13)
  36.  
  37. ROOT.gStyle.SetMarkerStyle(1)
  38.  
  39. #etabin = [1.0, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95,
  40. # 2.0, 2.05, 2.1, 2.15, 2.2, 2.25, 2.3, 2.35, 2.4, 2.45, 2.5]
  41. #myetabin = np.asarray(etabin)
  42. etabin = [1.0, 1.2, 1.3, 1.45, 1.55, 1.65, 1.75, 1.85, 1.95, 2.05, 2.15, 2.25, 2.35, 2.45, 2.55]
  43. myetabin = np.asarray(etabin)
  44. #binLow = [0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,12.0,14.0,16.0,18.0,20.0,24.0,28.0,32.0,36.0,42.0,50.0]
  45. #ptbins = np.asarray(binLow)
  46. #rateptbin = [5.0, 6.0, 7.0,8.0, 10.0, 12.0, 15.0, 20.0, 25.0, 30.0, 35.0]
  47. #color = [ROOT.kBlack, ROOT.kBlue, ROOT.kRed, ROOT.kGreen+2, ROOT.kMagenta+2,ROOT.kOrange+8]
  48. #color = [ROOT.kBlue, ROOT.kRed, ROOT.kMagenta+2, ROOT.kGreen+2,ROOT.kOrange+8]
  49. color = [ROOT.kBlack, ROOT.kBlue, ROOT.kGreen+2, ROOT.kRed, ROOT.kOrange+8] #ROOT.kMagenta+2,ROOT.kOrange+8]
  50. maker =[25, 22,21,20,24]
  51. pu=200
  52.  
  53. #ratesample = "RateTree_20170620.root"
  54. #ratesample = "RateTree_20170627.root"
  55. ratesample = "RateTree_20170722_GE11GE21.root"
  56. rfile = ROOT.TFile(ratesample)
  57. total = rfile.Get("h_eventcountME0Segment192").GetEntries()
  58. #signalsample = "../ME0Bending_20170427/out_ana_promptMu_PU200_192_20170715_fixedGE11GE21.root"
  59. signalsampleCSConly = "../ME0Bending_20170427/out_ana_promptMu_PU200_192_20170601.root"
  60. #signalsampleGE11only = "../ME0Bending_20170427/out_ana_promptMu_PU200_192_20170715_fixedGE11only.root"
  61. signalsample = "SingleMu_EMTF_ME0_PU200_GEMCSCANA_20170722_GE11GE21.root"
  62. signalsampleGE11only = "SingleMu_EMTF_ME0_PU200_GEMCSCANA_20170722_GE11only.root"
  63. #total = 284900.000000
  64. SF = 30.0*1000.0/total#khz
  65. SF140 = SF*14.0/20.0
  66.  
  67.  
  68.  
  69. #______________________________________________________________________________
  70. def getDPhiFromLUT(st, pt, fraction, evenodd):
  71. ststring = "ME11"
  72. if st==2:
  73. ststring = "ME21"
  74. fracstring = "Eff%d"%fraction
  75. ptstring = "Pt%d"%pt
  76. pt_string = ("%s"%(ptstring)).ljust(4)
  77. #dphi_lct_pad["ME11"]["Eff95"]["Pt10"]["even"]
  78. return dphi_lct_pad[ststring][fracstring][pt_string][evenodd]
  79. #______________________________________________________________________________
  80. def getDPhicut(st, pt, is_odd):
  81.  
  82. ME11GEMdPhi = [
  83. [-2, 1.0, 1.0],
  84. [5.0, 0.02131422, 0.00907379 ],
  85. [7.0, 0.01480166, 0.00658598 ],
  86. [10.0, 0.01019511, 0.00467867 ],
  87. [15.0, 0.00685720, 0.00336636 ],
  88. [20.0, 0.00528981, 0.00279064 ],
  89. [30.0, 0.00381797, 0.00231837 ],
  90. [40.0, 0.00313074, 0.00213513 ],
  91. ]
  92.  
  93. ME21GEMdPhi = [
  94. [-2, 1.0, 1.0],
  95. [5.0, 0.00884066, 0.00479478 ],
  96. [7.0, 0.00660301, 0.00403733 ],
  97. [10.0, 0.00503144, 0.00369953 ],
  98. [15.0, 0.00409270, 0.00358023 ],
  99. [20.0, 0.00378257, 0.00358023 ],
  100. [30.0, 0.00369842, 0.00358023 ],
  101. [40.0, 0.00369842, 0.00358023 ],
  102. ]
  103.  
  104.  
  105. dPhiLib = ME11GEMdPhi
  106. if st==2:
  107. dPhiLib = ME21GEMdPhi
  108. for ipt in range(0, len(dPhiLib)):
  109. if abs(dPhiLib[ipt][0]-pt)<1:
  110. if is_odd:
  111. return dPhiLib[ipt][1]
  112. else:
  113. return dPhiLib[ipt][2]
  114. def getME0dPhiLUTValue(pt, fraction, filename):
  115. readinLUT = open(filename,'r')
  116. startread = False; endread = False
  117.  
  118. for line in readinLUT:
  119. if endread:
  120. break
  121. #ME0pt5fraction96
  122. if line.startswith("ME0pt%dfraction%d"%(pt, fraction)):
  123. startread = True
  124. continue
  125. if startread and line=="}\n":
  126. endread = True
  127. continue
  128. if line=="{\n":
  129. continue
  130. if startread and not(endread):
  131. #print "line ",line ," float ",float(line)
  132. return float(line)
  133.  
  134. #evenodds = ["odd,even","odd,odd","even,even","even,odd","all pairs"]
  135.  
  136. def getFinalLUTValue(pt, fraction, etamin, etamax, npar, filename):
  137. algos_lut = {"GE11": -1, "GE21": -1,"Hybrid":[]}
  138. readinLUT = open(filename,'r')
  139. startread = [False, False, False]
  140. endread = [False, False, False]
  141. inpar = 0
  142. for line in readinLUT:
  143. #Positioneta16to18pt5fraction76
  144. getall = (endread[0] and endread[1] and endread[2])
  145. if getall:
  146. break
  147. ialgo = -1
  148. for algo in algos_lut:
  149. ialgo += 1
  150. if line.startswith("%seta%dto%dpt%dfraction%d"%(algo, int(etamin*10), int(etamax*10),pt, fraction)):
  151. startread[ialgo] = True
  152. continue
  153. if startread[ialgo] and line=="}\n":
  154. endread[ialgo] = True
  155. continue
  156. if line=="{\n":
  157. continue
  158. #evenodds = ["odd,even","odd,odd","even,even","even,odd","all pairs"]
  159. if startread[ialgo] and not(endread[ialgo]):
  160. if algo=="GE11":
  161. allnums = line.split(",")
  162. algos_lut[algo] = float(allnums[npar/2])
  163. endread[ialgo] = True
  164. elif algo=="GE21":
  165. allnums = line.split(",")
  166. algos_lut[algo] = float(allnums[(npar+1)%2])
  167. endread[ialgo] = True
  168. elif algo=="Hybrid" and inpar == npar:
  169. allnums = line[1:-3].split(",")
  170. for ipara in range(0,5):
  171. algos_lut[algo].append(float(allnums[ipara]))
  172. endread[ialgo] = True
  173. elif algo=="Hybrid":
  174. inpar += 1
  175.  
  176. #print "all lut for pt ",pt," fraction ",fraction, " etamin ", etamin, " etamax ",etamax, " npar ",npar
  177. #for key in algos_lut:
  178. # print "algo ",key, " value ",algos_lut[key]
  179. return algos_lut
  180.  
  181.  
  182. def getCut(ch, todraw, basecut, dphimin, dphimax, step, fraction):
  183. frac = 1.0
  184. fraction = fraction*0.01
  185. total = getEvents(ch, basecut)
  186. naccept = getEvents(ch, basecut+"&& abs(%s)<%f"%(todraw, dphimax))
  187. frac = float(naccept)/float(total)
  188. naccept2 = getEvents(ch, basecut+"&& abs(%s)<%f"%(todraw, dphimin))
  189. frac2 = float(naccept2)/float(total)
  190. if frac<fraction:
  191. print "error! , with init range max ",dphimax," efficiency is ",frac," required eff: ",fraction
  192. sys.exit(0)
  193. return dphimax
  194. elif frac2>fraction:
  195. print "error! , with init range min ",dphimin," efficiency is ",frac2," required eff: ",fraction
  196. sys.exit(0)
  197. return dphimin
  198. xcut = (dphimin+dphimax)/2.0
  199. naccept = getEvents(ch, basecut+"&& abs(%s)<%f"%(todraw, xcut))
  200. frac = float(naccept)/float(total)
  201. #print "naccept ",naccept," frac ",frac, " xcut ",xcut," dphimin ",dphimin, " dphimax ",dphimax," required eff: ",fraction
  202. while(dphimax-dphimin > step):
  203. if frac>fraction:
  204. dphimax = xcut
  205. elif frac<fraction:
  206. dphimin = xcut
  207. else:
  208. break
  209. xcut = (dphimin+dphimax)/2.0
  210. naccept = getEvents(ch, basecut+"&& abs(%s)<%f"%(todraw, xcut))
  211. frac = float(naccept)/float(total)
  212. #print "naccept ",naccept, " frac ",frac, " xcut ",xcut," dphimin ",dphimin, " dphimax ",dphimax," required eff: ",fraction
  213. return xcut
  214.  
  215. def getTefficiency(ch, todraw, dencut, numcut, nbins, xmin, xmax):
  216. hden = TH1F("hden","hden",nbins, xmin, xmax)
  217. hnum = TH1F("hnum","hnum",nbins, xmin, xmax)
  218. ch.Draw(todraw+">>hden", dencut)
  219. ch.Draw(todraw+">>hnum", numcut)
  220. Teff = TEfficiency(hnum, hden)
  221. SetOwnership(Teff, False)
  222. return Teff
  223.  
  224. def getOverallEff(Teff, xinit):
  225. hden = Teff.GetCopyTotalHisto()
  226. hnum = Teff.GetCopyPassedHisto()
  227. nbins = hden.GetXaxis().GetNbins()
  228. xbin = hden.FindBin(xinit)
  229. den = hden.Integral(xbin, nbins)
  230. num = hnum.Integral(xbin, nbins)
  231. eff = float(num)/float(den)
  232. #print "Teff ",Teff," den ",den," num ",num," eff ",eff
  233. return eff,sqrt(eff*(1.0-eff)/den)
  234. def frange(end,start=0,inc=0,precision=1):
  235. """A range function that accepts float increments."""
  236. import math
  237.  
  238. if not start:
  239. start = end + 0.0
  240. end = 0.0
  241. else: end += 0.0
  242.  
  243. if not inc:
  244. inc = 1.0
  245. count = int(math.ceil((start - end) / inc))
  246.  
  247. L = [None] * (count+1)
  248.  
  249. L[0] = end
  250. for i in (xrange(1,count)):
  251. L[i] = L[i-1] + inc
  252. L[count] = start
  253. return L
  254.  
  255. def addFilesToChain(ch, filedir):
  256. if os.path.isdir(filedir):
  257. ls = os.listdir(filedir)
  258. for x in ls:
  259. if not(x.endswith(".root")):
  260. #print "x.endswith(.root) ", x.endswith(".root")
  261. continue
  262. x = filedir[:]+x
  263. if os.path.isdir(x):
  264. continue
  265. ch.Add(x)
  266. elif os.path.isfile(filedir):
  267. ch.Add(filedir)
  268. else:
  269. print " it is not file or dir ", filedir
  270. ## draw an ellipse that includes 95% of the entries
  271.  
  272. signalAcceptance = 0.90
  273.  
  274. def getEllipse(x,y,a,b, alpha=0, x0=0, y0=0):
  275. x1 = x*cos(alpha)+y*sin(alpha)-x0
  276. y1 = x*sin(alpha)-y*cos(alpha)-y0
  277. if (alpha>0):
  278. angle = "#frac{#pi}{%d}"%(int(pi/alpha))
  279. elif (alpha<0):
  280. angle = "-#frac{#pi}{%d}"%(int(pi/fabs(alpha)))
  281. else:
  282. angle = "0"
  283. #print "x ",x," y ",y," a ",a," b ",b," alpha ",alpha," x1 ",x1," y1 ",y1," angle ",angle
  284. return x1*x1/(a*a) + y1*y1/(b*b)
  285.  
  286. def passEllipse(x,y,a,b,alpha, x0=0, y0=0):
  287. return getEllipse(x,y,a,b,alpha, x0, y0) <= 1
  288.  
  289. def failEllipse(x,y,a,b,alpha, x0=0, y0=0):
  290. return getEllipse(x,y,a,b,alpha,x0, y0) > 1
  291.  
  292. def getBackgroundRejectionEllipse(a_axis, b_axis, alpha, x0, y0, signalHist, backgroundHist):
  293. if signalHist.GetEntries()==0 or backgroundHist.GetEntries()==0:
  294. print "warning!!! entries (S and B) ",signalHist.GetEntries(),backgroundHist.GetEntries()
  295. return (1.0,0)
  296. #print "signal and bg, integral/entris ", signalHist.Integral() / signalHist.GetEntries(), backgroundHist.Integral() / backgroundHist.GetEntries()
  297. signalEntriesTotal = signalHist.GetEntries()*1.0
  298. backgroundEntriesTotal = backgroundHist.GetEntries()*1.0
  299.  
  300. entriesInEllipseSignal = 0
  301. entriesOutEllipseBackground = 0
  302. entriesInEllipseBackground = 0.0
  303.  
  304. signalAcceptanceFactor = 0
  305. background = 0
  306.  
  307. ## loop on entries in histogram
  308. for j in range(1,signalHist.GetNbinsX()+1):
  309. for k in range(1,signalHist.GetNbinsY()+1):
  310.  
  311. ## get the bin centers
  312. signal_x = signalHist.GetXaxis().GetBinCenter(j)
  313. signal_y = signalHist.GetYaxis().GetBinCenter(k)
  314.  
  315. background_x = backgroundHist.GetXaxis().GetBinCenter(j)
  316. background_y = backgroundHist.GetYaxis().GetBinCenter(k)
  317.  
  318. ## signal passes
  319. if passEllipse(signal_x, signal_y, a_axis, b_axis, alpha, x0, y0):
  320. entriesInEllipseSignal += signalHist.GetBinContent(j,k)
  321.  
  322. ## background fails
  323. #if failEllipse(background_x, background_y, a_axis, b_axis, alpha, x0, y0):
  324. # entriesOutEllipseBackground += backgroundHist.GetBinContent(j,k)
  325. if passEllipse(background_x, background_y, a_axis, b_axis, alpha, x0, y0):
  326. entriesInEllipseBackground += backgroundHist.GetBinContent(j,k)
  327.  
  328. ## current signal acceptance
  329. signalAcceptanceFactor = entriesInEllipseSignal / signalEntriesTotal
  330.  
  331. ## current background rejection
  332. #background = entriesOutEllipseBackground / backgroundEntriesTotal
  333. background = 1 - entriesInEllipseBackground/backgroundEntriesTotal
  334. #if background<0.50:
  335. # break
  336. #print j,k,signalAcceptanceFactor,background
  337.  
  338. return signalAcceptanceFactor, background
  339.  
  340.  
  341.  
  342.  
  343. def get_proptionality_factor(eta, npar):
  344. slope=0.0
  345. #slopes_1 = [0,0.645, 0.852,0]
  346. slopes_1 = [1.279, 0.6357, 1.001, 0.5252]
  347. slopes_2 = [0.630, .364, .541, .325]
  348. #slopes_1 = [1.279, 0.6457, 1.001, 0.5252]
  349. #slopes_2 = [0.648, 0.3542, 0.5636, 0.3217]
  350. if (abs(eta)<1.6):
  351. slope = slopes_1[npar]
  352. if (abs(eta)>=1.6):
  353. slope = slopes_2[npar]
  354.  
  355. return slope
  356.  
  357.  
  358. def drawEllipse(hist, hist2, nEvent_list, anglecut_list, a, b, alpha, x0, y0, eff1, nrate, xtitle, ytitle,st_title, text, picname):
  359. gStyle.SetTitleBorderSize(0);
  360. gStyle.SetPadLeftMargin(0.126);
  361. gStyle.SetPadRightMargin(0.04);
  362. gStyle.SetPadTopMargin(0.06);
  363. gStyle.SetPadBottomMargin(0.13);
  364. gPad.SetTickx(1)
  365. gPad.SetTicky(1)
  366. xBins = hist.GetXaxis().GetNbins()
  367. yBins = hist.GetYaxis().GetNbins()
  368. xmin = hist.GetXaxis().GetXmin()
  369. xmax = hist.GetXaxis().GetXmax()
  370. ymin = hist.GetYaxis().GetXmin()
  371. ymax = hist.GetYaxis().GetXmax()
  372. #btest = TH2F("btest","btest",xBins/2,xmin/2.0,xmax/2.0,yBins/2,ymin/2.0,ymax/2.0)
  373. btest = TH2F("btest","btest",xBins,xmin,xmax,yBins,ymin,ymax)
  374. btest.GetXaxis().SetTitle(hist2.GetXaxis().GetTitle())
  375. btest.GetYaxis().SetTitle(hist2.GetYaxis().GetTitle())
  376. btest.SetTitle(hist.GetTitle())
  377. el2 = TEllipse(x0,y0,a,b,0,360, alpha*180.0/pi);
  378. el2.SetLineColor(kBlack);
  379. #el2.SetLineWidth(3);
  380. el2.SetFillStyle(4000)
  381. #meanx_s = hist.GetMean(1)
  382. #meany_s = hist.GetMean(2)
  383. #meanx_b = hist2.GetMean(1)
  384. #meany_b = hist2.GetMean(2)
  385. c = TCanvas("c_%d_%d"%(int(a*100),int(b*100)),"c_%d_%d"%(int(a*100),int(b*100)),900,400)
  386. #c.Clear()
  387. c.Divide(2,1)
  388. c.cd(1)
  389. btest.Draw()
  390. #print "drawellipse , hist entries ",hist.GetEntries()
  391. #print "hist print ",hist.Print("ALL")
  392. hist.Draw("samecolz")
  393. hist.SetTitle(st_title[1])
  394.  
  395. el2.Draw("same")
  396.  
  397. xline1 = TLine(-anglecut_list[0], ymin/2, -anglecut_list[0], ymax/4)
  398. xline2 = TLine(anglecut_list[0], ymin/2, anglecut_list[0], ymax/4)
  399. xline1.SetLineColor(kBlack)
  400. xline2.SetLineColor(kBlack)
  401. xline1.SetLineStyle(2)
  402. xline2.SetLineStyle(2)
  403. xline1.Draw("same")
  404. xline2.Draw("same")
  405. angle = alpha*180/pi
  406. print "in Drawellipse a ",a," b ",b," alpha ",alpha," angle ", alpha*180.0/pi, " x0 ",x0, " y0 ",y0," xcut ",anglecut_list[0]," ycut ",anglecut_list[1]
  407. acep_x = float(nEvent_list[6])/float(nEvent_list[5])
  408. acep_y = float(nEvent_list[7])/float(nEvent_list[5])
  409. tex1 = ROOT.TLatex(0.15,.3,"%s"%(text))
  410. tex1.SetNDC()
  411. tex10 = TLatex(0.2,.9,"Singal entries %d"%(nEvent_list[5]))
  412. tex10.SetNDC()
  413. tex3 = TLatex(0.15, 0.7, "Acceptance %.3f(ST1) %.3f(ST2) %.3f(H)"%(acep_x, acep_y, eff1))
  414. tex3.SetTextSize(0.05)
  415. tex3.SetNDC()
  416. tex4 = TLatex(0.15, 0.8, "#splitline{HCut: a=%.3f,b=%.3f,angle=%.1f,center(%.3f,%.3f)}{St1-Cut: %.4f, St2-Cut: %.4f}"%(a, b, angle, x0, y0, anglecut_list[0],anglecut_list[1]))
  417. tex4.SetTextSize(0.05)
  418. tex4.SetNDC()
  419. tex4.SetNDC()
  420. tex4.Draw("same")
  421. tex3.Draw("same")
  422. tex1.Draw("same")
  423. tex10.Draw("same")
  424. c.cd(2)
  425. rej_x = 1-float(nEvent_list[2])/float(nEvent_list[1])
  426. rej_y = 1-float(nEvent_list[3])/float(nEvent_list[1])
  427. rej_h = 1-(nrate)/float(nEvent_list[1])
  428. #btest2 = TH2F("btest2","btest2",xBins/2,xmin/2.0,xmax/2.0,yBins/2,ymin/2.0,ymax/2.0)
  429. btest2 = TH2F("btest2","btest2",xBins,xmin,xmax,yBins,ymin,ymax)
  430. btest2.GetXaxis().SetTitle(hist2.GetXaxis().GetTitle())
  431. btest2.GetYaxis().SetTitle(hist2.GetYaxis().GetTitle())
  432. btest2.SetTitle(hist2.GetName())
  433. btest2.Draw()
  434. hist2.Draw("samecolz")
  435. hist2.SetTitle(st_title[0])
  436. el2.Draw("same")
  437. xline1.Draw("same")
  438. xline2.Draw("same")
  439. print "Singal Acceptance: X ",acep_x, " Y ",acep_y, " H ",eff1, " Rate nEvent ",nEvent_list[0]," this category ",nEvent_list[1]," Rejection: X ",rej_x," Y ",rej_y," H ",rej_h
  440. tex2 = TLatex(0.15, 0.7, "Rate: %.0f(ST1), %.0f(ST2), %.0f(H)"%(nEvent_list[2], nEvent_list[3], nrate))
  441. tex2.SetTextSize(0.05)
  442. tex2.SetNDC()
  443. #tex5 = TLatex(0.15, 0.9, "ellipse center(%.1f, %.3f)"%(x0, y0))
  444. #tex5 = TLatex(0.15, 0.85, "#splitline{Rate nEvent %d, this case: %d}{Hybrid %d+%d}"%(nEvent_list[0], nEvent_list[1], nrate, nEvent_list[-1]))
  445. tex5 = TLatex(0.15, 0.85, "#splitline{Rate nEvent %d, this case: %d}{}"%(nEvent_list[0], nEvent_list[1]))
  446. tex5.SetTextSize(0.05)
  447. tex5.SetNDC()
  448. tex2.Draw("same")
  449. tex5.Draw("same")
  450. #tex11.Draw("same")
  451. c.cd()
  452.  
  453.  
  454. #c.SaveAs(picname+ "_ellipse.pdf")
  455. c.SaveAs(picname+ "_ellipse.png")
  456.  
  457. #get events number by drawing tree???
  458. def getEvents(ch, cut):
  459. hist = TH2F("hist","hist", 1,-1,1, 1,-1,1)
  460. ch.Draw("1:1>>hist",cut)
  461. return hist.GetEntries()
  462. def loopEllipse(chain, chain1, nEvent_list, anglecut_list, fraction, astart, bstart, xaxis, yaxis,x_bins, y_bins,xtitle, ytitle,st_title, etamin, etamax, cuts,text,picname):
  463.  
  464. gStyle.SetOptFit(0111)
  465. gStyle.SetOptStat(0)
  466.  
  467. #xBins = b0.GetXaxis().GetNbins()
  468. #yBins = b0.GetYaxis().GetNbins()
  469. #xminBin = b0.GetXaxis().GetXmin()
  470. #xmaxBin = b0.GetXaxis().GetXmax()
  471. #yminBin = b0.GetYaxis().GetXmin()
  472. #ymaxBin = b0.GetYaxis().GetXmax()
  473. doTest = False
  474. xBins = int(x_bins[1:-1].split(',')[0])
  475. xminBin = float(x_bins[1:-1].split(',')[1])
  476. xmaxBin = float(x_bins[1:-1].split(',')[2])
  477. yBins = int(y_bins[1:-1].split(',')[0])
  478. yminBin = float(y_bins[1:-1].split(',')[1])
  479. ymaxBin = float(y_bins[1:-1].split(',')[2])
  480. xbinwidth = (xmaxBin-xminBin)/xBins
  481. ybinwidth = (ymaxBin-yminBin)/yBins
  482.  
  483. todrawb0 = "%s"%yaxis[0]+":"+"%s>>b0"%xaxis[0]
  484. todrawb_hist = "(%s*(abs(%s)<0.1)+0.025*(abs(%s)>.1))"%(yaxis[0], yaxis[0], yaxis[0])+":"+"(%s*(abs(%s)<0.1)+0.025*(abs(%s)>.1))"%(xaxis[0], xaxis[0], xaxis[0])
  485. todrawb01 = todrawb_hist+">>b01"
  486. #todrawb1 = "%s*charge"%yaxis+":"+"%s*charge>>b1"%xaxis
  487. todrawb1 = "%s"%yaxis[1]+":"+"%s>>b1"%xaxis[1]
  488. todrawb_hist1 = "(%s*(abs(%s)<0.1)+0.025*(abs(%s)>.1))"%(yaxis[1], yaxis[1], yaxis[1])+":"+"(%s*(abs(%s)<0.1)+0.025*(abs(%s)>.1))"%(xaxis[1], xaxis[1], xaxis[1])
  489. todrawb11 = todrawb_hist1+">>b11"
  490. b0 = TH2F("b0","b0",xBins,xminBin,xmaxBin,yBins,yminBin,ymaxBin)
  491. b01 = TH2F("b01","b01",xBins,xminBin,xmaxBin,yBins,yminBin,ymaxBin)
  492. b01.GetXaxis().SetTitle("%s"%xtitle)
  493. b01.GetYaxis().SetTitle("%s"%ytitle)
  494. #b0.SetTitle("%s Vs %s,%s"%(ytitle, xtitle, st_title))
  495. #b0.SetTitleSize(0.05)
  496. b01.SetStats(1)
  497. chain.Draw(todrawb0,cuts[0])#background
  498. chain.Draw(todrawb01,cuts[0])#background, for plotting
  499. #b0.Add(b01)
  500. print "background todraw ",todrawb0, " cuts ", cuts[0]," b0.Getentries ",b0.GetEntries()," b01 todraw ",todrawb01, " same cut, entries ",b01.GetEntries()
  501.  
  502.  
  503. b1 = TH2F("b1","b1",xBins,xminBin,xmaxBin,yBins,yminBin,ymaxBin)
  504. b11 = TH2F("b11","b11",xBins,xminBin,xmaxBin,yBins,yminBin,ymaxBin)
  505. b1.GetXaxis().SetTitle("%s"%xtitle)
  506. b1.GetYaxis().SetTitle("%s"%ytitle)
  507. #b1.SetTitle("%s Vs %s,%s"%(ytitle, xtitle, st_title))
  508. #b1.SetTitleFont(62)
  509. #b1.SetTitleSize(0.05)
  510. #b1.SetMaximum(30)
  511. b1.SetStats(1)
  512. chain1.Draw(todrawb1,cuts[1])#signal
  513. chain1.Draw(todrawb11,cuts[1])#signal, for plotting
  514. #b1.Add(b11)
  515. print "signal todraw ",todrawb1, " cuts ", cuts[1]," b1.Getentries ",b1.GetEntries()," b11 todraw ", todrawb11, " same cut, entries ",b11.GetEntries()
  516.  
  517.  
  518. totrate = b0.GetEntries()
  519. totsignal = b1.GetEntries()
  520.  
  521.  
  522. extraEvents_ellipse_b = getEvents(chain, cuts[0]+"&& abs(%s)<=%f"%(xaxis[0], anglecut_list[0])+"&& abs(%s) == 99"%(yaxis[0]))+getEvents(chain, cuts[0]+"&& abs(%s)<=%f"%(yaxis[0], anglecut_list[1])+"&& abs(%s) == 99"%(xaxis[0]))
  523. extraEvents_ellipse_s1 = getEvents(chain1, cuts[1]+"&& abs(%s)<=%f"%(xaxis[1], anglecut_list[0])+"&& abs(%s)>1"%(yaxis[1]))
  524. extraEvents_ellipse_s2 = getEvents(chain1, cuts[1]+"&& abs(%s)<=%f"%(yaxis[1], anglecut_list[1])+"&& abs(%s) >1"%(xaxis[1]))
  525. print "extraEvents_ellipse_s1 ",extraEvents_ellipse_s1," cut ",cuts[1]+"&& abs(%s)<=%f"%(xaxis[1], anglecut_list[0])+"&& abs(%s)>1"%(yaxis[1])," s2 ",extraEvents_ellipse_s2," cut ",cuts[1]+"&& abs(%s)<=%f"%(yaxis[1], anglecut_list[1])+"&& abs(%s) >1"%(xaxis[1])
  526. extraEvents_ellipse_s = extraEvents_ellipse_s1 + extraEvents_ellipse_s2
  527. nEvent_list.append(b0.GetEntries())
  528. nEvent_list.append(getEvents(chain, cuts[0]+"&& abs(%s)<=%f"%(xaxis[0], anglecut_list[0])))#rate, overflow and underflow are included
  529. nEvent_list.append(getEvents(chain, cuts[0]+"&& abs(%s)<=%f"%(yaxis[0], anglecut_list[1])))
  530. nEvent_list.append(extraEvents_ellipse_b)
  531. nEvent_list.append(b1.GetEntries())
  532. nEvent_list.append(getEvents(chain1, cuts[1]+"&& abs(%s)<=%f"%(xaxis[1], anglecut_list[0])))#rate, overflow and underflow are included
  533. nEvent_list.append(getEvents(chain1, cuts[1]+"&& abs(%s)<=%f"%(yaxis[1], anglecut_list[1])))
  534. nEvent_list.append(extraEvents_ellipse_s)
  535.  
  536. def getEffandRateFromEllipse(maxa, maxb, alpha, x0, y0):
  537. xaxis1 = "(%s*TMath::Cos(%f)+%s*TMath::Sin(%f)-%f)"%(xaxis[0], alpha, yaxis[0], alpha, x0)
  538. yaxis1 = "(%s*TMath::Sin(%f)-%s*TMath::Cos(%f)-%f)"%(xaxis[0], alpha, yaxis[0], alpha, y0)
  539. ellipse_b = "(%s*%s/(%f*%f)+%s*%s/(%f*%f))<=1.0"%(xaxis1, xaxis1, maxa, maxa, yaxis1, yaxis1, maxb, maxb)
  540. xaxis2 = "(%s*TMath::Cos(%f)+%s*TMath::Sin(%f)-%f)"%(xaxis[1], alpha, yaxis[1], alpha, x0)
  541. yaxis2 = "(%s*TMath::Sin(%f)-%s*TMath::Cos(%f)-%f)"%(xaxis[1], alpha, yaxis[1], alpha, y0)
  542. ellipse_s = "(%s*%s/(%f*%f)+%s*%s/(%f*%f))<=1.0"%(xaxis2, xaxis2, maxa, maxa, yaxis2, yaxis2, maxb, maxb)
  543.  
  544. cut_s = cuts[1]+"&& ( "+ellipse_s+" || "+"(abs(%s)<=%f && abs(%s)>1)"%(xaxis[1], anglecut_list[0], yaxis[1])+" || "+"(abs(%s)<=%f && abs(%s)>1))"%(yaxis[1], anglecut_list[1], xaxis[1])
  545. cut_b = cuts[0]+"&& ("+ellipse_b+" || "+"(abs(%s)<=%f && abs(%s)>1)"%(xaxis[0], anglecut_list[0], yaxis[0])+" || "+"(abs(%s)<=%f && abs(%s)>1))"%(yaxis[0], anglecut_list[1], xaxis[0])
  546. nsignal = getEvents(chain1, cut_s)
  547. #print "signal ellipse ",cuts[1]+"&&"+ellipse_s," nsignal ",nsignal
  548. nrate = getEvents(chain, cut_b)
  549. return float(nsignal)/float(totsignal),nrate
  550.  
  551. print "nEvent_list ",nEvent_list," anglecut_list ", anglecut_list
  552. """"
  553. xbin_m = Long(0)
  554. ybin_m = Long(0)
  555. zbin_m = Long(0)
  556. b1.GetMaximumBin(xbin_m, ybin_m, zbin_m)
  557. maxBin_x = b1.GetXaxis().GetBinCenter(xbin_m)
  558. maxBin_y = b1.GetYaxis().GetBinCenter(ybin_m)
  559. maxBin_alpha = 0
  560. if abs(maxBin_x)>0:
  561. maxBin_alpha = atan(maxBin_y/maxBin_x)#by default in radian
  562. print "maxBin_x ",maxBin_x," maxBin_y ",maxBin_y," maxBin_alpha ",maxBin_alpha
  563. """
  564. maxBin_alpha = atan(anglecut_list[1]/anglecut_list[0])
  565. if (b1.GetEntries()<1 or b0.GetEntries() <1 ):
  566. print "signal entries ",b1.GetEntries(), " bg entries ",b0.GetEntries()
  567. #print "signal integral/entris ", b1.Integral() / b1.GetEntries()," Bg ", b0.Integral() / b0.GetEntries()
  568. nalpha = 0
  569. alpha = 0.0
  570. xratio = 0.0
  571. yratio = 0.0
  572. #use (0,0) as center
  573. centerx = 0
  574. centery = 0
  575. for factor in [1.5, 1.7, 2.0, 2.5, 3.0]:
  576. max_a = anglecut_list[0]*factor
  577. max_b = anglecut_list[1]*factor
  578. print "find max a b, factor ", factor," max_a ",max_a, " max_b ",max_b
  579. signalAcceptanceFactor, background = getEffandRateFromEllipse(max_a, max_b, maxBin_alpha, centerx, centery)
  580. drawEllipse(b11, b0,nEvent_list, anglecut_list, max_a, max_b, 0, centerx, centery, signalAcceptanceFactor, background, xtitle, ytitle,st_title, text, picname+"_maxfactor%d_initial"%(int(factor*10)))
  581. if signalAcceptanceFactor > fraction+0.015 or signalAcceptanceFactor >= .99:#make sure fraction<.97
  582. break
  583. for factor in [0.5, 0.4, 0.3, .2, 0.1, 0.01, 0]:
  584. min_a = anglecut_list[0]*factor
  585. min_b = anglecut_list[1]*factor
  586. print "find min a b, factor ", factor," min_a ",min_a, " min_b ",min_b
  587. signalAcceptanceFactor, background = getEffandRateFromEllipse(min_a, min_b, maxBin_alpha, centerx, centery)
  588. drawEllipse(b11, b0,nEvent_list, anglecut_list, min_a, min_b, 0, centerx, centery, signalAcceptanceFactor, background, xtitle, ytitle,st_title, text, picname+"_minfractor%d_initial"%(int(factor*10)))
  589. if signalAcceptanceFactor < fraction-.15:#make sure fraction<.97
  590. break
  591.  
  592.  
  593. a_range = frange(min_a, max_a, xbinwidth)
  594. b_range = frange(min_b/2.0, max_b*2.0, ybinwidth)
  595. dalpha = maxBin_alpha #maximum alpha range : 16/180*pi
  596. if dalpha > pi*16/180.0:
  597. dalpha = pi*16/180.0
  598. alphas = [maxBin_alpha+n*dalpha/4.0 for n in range(-4, 5)]
  599. if doTest:
  600. a_range = frange(min_a, max_a, xbinwidth*4)
  601. b_range = frange(min_b/2.0, max_b*1.5, ybinwidth*4)
  602. dalpha = 8*pi/180.0
  603. alphas = [maxBin_alpha+n*dalpha/2.0 for n in range(-1, 2)]
  604. print "arange ",a_range," brange ", b_range, " xbinwidth ", xbinwidth ," xbins ",x_bins, " ybins ",y_bins," alphas ",alphas
  605.  
  606. preselected_axes_signalAcc_backRej = []
  607. fraction = fraction/100.0
  608. lena = len(a_range)
  609. lenb = len(b_range)
  610. maxRate = b0.GetEntries()
  611. maxAccept = 0
  612. max_alpha = 0.
  613. max_b_lowedge = b_range[0]
  614. max_b_highedge = b_range[-1]
  615. bstep = fabs(b_range[1]-b_range[0])
  616. max_centerx = 0.0
  617. max_centery = 0.0
  618. #signalAcceptanceFactor, background = getBackgroundRejectionEllipse(max_a, max_b, 0, centerx, centery, b1, b0)
  619. #signalAcceptanceFactor, background = getEffandRateFromEllipse(max_a, max_b, 0, centerx, centery)
  620.  
  621. #drawEllipse(b11, b0,nEvent_list, anglecut_list, max_a, max_b, 0, centerx, centery, signalAcceptanceFactor, background, xtitle, ytitle,st_title, text, picname+"_%d_initial"%(lena*lenb))
  622. totalnalpha = 7
  623.  
  624. #for nalpha in range(totalnalpha):
  625. #for nalpha in range(1):
  626. #for a_axis in range(0):
  627. #for xratio in [0.0]:
  628. #for xratio in [0.0]:
  629. for nalpha in range(0, len(alphas)):
  630. alpha = alphas[nalpha]
  631. centerx = 0.0
  632. centery = 0.0
  633. max_b_highedge = b_range[-1]
  634. b_axis = max_b_highedge
  635. m =0
  636. print "nalpha ", nalpha," alpha ",alpha, " max_b ",b_axis," high dege ",max_b_highedge," centerx ",centerx," centery ", centery
  637. for a_axis in a_range:
  638. #alpha = 0.0
  639. m = m+1
  640. max_b_lowedge = b_range[0]
  641. signalAcceptanceFactor, background = getEffandRateFromEllipse(a_axis, b_axis, alpha, centerx, centery)
  642. #signalAcceptanceFactor, background = getBackgroundRejectionEllipse(a_axis, b_axis, alpha, centerx, centery, b1, b0)
  643. #drawEllipse(b1, b0, a_axis, b_axis, alpha, meanx_s, meany_s, signalAcceptanceFactor, background, xtitle, ytitle,st_title, text, picname+"_nalpha%d_m%d"%(nalpha, m))
  644. print "new cnenter a ", a_axis, " b ", b_axis, " alpha ",alpha, " x0 ",centerx," y0 ",centery," bhigh ",max_b_highedge, " blow ", max_b_lowedge, " signal ", signalAcceptanceFactor, " bg ",background
  645. if signalAcceptanceFactor < fraction:
  646. continue
  647. step = max_b_highedge - max_b_lowedge
  648. n =0
  649. while (step> bstep):
  650. #for b_axis in b_range:
  651. b_axis = (max_b_highedge+max_b_lowedge)/2.0
  652. n = n+1
  653. #signalAcceptanceFactor, background = getBackgroundRejectionEllipse(a_axis, b_axis, alpha, centerx, centery, b1, b0)
  654. signalAcceptanceFactor, background = getEffandRateFromEllipse(a_axis, b_axis, alpha, centerx, centery)
  655. #print "n ", n," bstep ",step, " a ", a_axis, " b ", b_axis, " signal ", signalAcceptanceFactor, " bg ",background
  656. if signalAcceptanceFactor > fraction:
  657. max_b_highedge = b_axis
  658. if background < maxRate:
  659. print " n ", n," bstep ",step, " a ", a_axis, " b ", b_axis," nalpha ", nalpha, " alpha ",alpha," x0 ", centerx, " y0 ", centery," signal ", signalAcceptanceFactor, " bg ",background
  660. maxRate = background
  661. maxAccept = signalAcceptanceFactor
  662. max_a = a_axis
  663. max_b = b_axis
  664. max_alpha = alpha
  665. max_centerx = centerx
  666. max_centery = centery
  667. drawEllipse(b11, b0, nEvent_list, anglecut_list, a_axis, b_axis, max_alpha, max_centerx, max_centery, signalAcceptanceFactor, background, xtitle, ytitle,st_title, text, picname+"_nalpha%d_m%d_n%d"%(nalpha, m,n))
  668. #preselected_axes_signalAcc_backRej.append([a_axis, b_axis, signalAcceptanceFactor, background])
  669. else:
  670. max_b_lowedge = b_axis
  671. step = max_b_highedge - max_b_lowedge
  672. max_b_highedge = b_axis+2*ybinwidth
  673.  
  674.  
  675. nEvent_list[4] = maxRate
  676. nEvent_list[-1] = int(nEvent_list[5]*maxAccept)
  677. #ellipse = "%s*%s/(%f*%f)+%s*%s/(%f*%f)<1.0"%(xaxis, xaxis, max_a, max_a, yaxis, yaxis, max_b, max_b)
  678. print "max_a ",max_a," max_b ",max_b, " alpha ",max_alpha, " x0 ",max_centerx," y0 ",max_centery ," signalAcceptanceFactor ",maxAccept," background ",maxRate," final nEvent_list ",nEvent_list
  679. return (max_a, max_b, max_alpha, max_centerx, max_centery)
  680.  
  681.  
  682. def gethist1D(chain,den, todraw="pt"):
  683.  
  684. h1 = ROOT.TH1F("h1","h1",len(ptbins)-1, ptbins)
  685. chain.Draw("fabs(%s) >> h1"%todraw,den)
  686. #print "gethist1D, den ",den
  687. #h1.Print("ALL")
  688. return h1
  689.  
  690.  
  691. def gethist1DEta(chain, den, todraw="eta"):
  692. h1 = ROOT.TH1F("h1","h1", len(myetabin)-1, myetabin)
  693. chain.Draw("fabs(%s) >> h1"%todraw,den)
  694. return h1
  695.  
  696. def getUpperlimit(h, fractionToKeep):
  697.  
  698. ## just a safety to prevent it from crashing
  699. if h.GetEntries() == 0:
  700. return 0.0000
  701.  
  702. ax = h.GetXaxis()
  703. total = h.Integral()
  704. bin = 1
  705. fractionToKeep = fractionToKeep/100.0
  706. for b in range(ax.GetNbins()):
  707. if (h.Integral(0,b)/total > fractionToKeep):
  708. bin = b - 1
  709. break
  710.  
  711. ## interpolate
  712. x1 = ax.GetBinUpEdge(bin)
  713. x2 = ax.GetBinUpEdge(bin + 1)
  714. y1 = h.Integral(0, bin)/total
  715. y2 = h.Integral(0, bin + 1)/total
  716. x = x1 + (fractionToKeep - y1)/(y2-y1)*(x2-x1)
  717. return x
  718.  
  719. def getcuts(filedir, treename0, den, num, pt, npar,etamin, etamax, fractionToKeep,x_bins, xtitle, txt, picname):
  720.  
  721. xBins = int(x_bins[1:-1].split(',')[0])
  722. xminBin = float(x_bins[1:-1].split(',')[1])
  723. xmaxBin = float(x_bins[1:-1].split(',')[2])
  724. if (etamin<1.6):
  725. ring = 2
  726. if (etamin>=1.6):
  727. ring = 1
  728. chain = ROOT.TChain(treename0)
  729. chain3 = ROOT.TChain("GEMCSCAnalyzer/trk_eff_CSC_ME2%d"%ring)
  730. if os.path.isdir(filedir):
  731. ls = os.listdir(filedir)
  732. for x in ls:
  733. if not(x.endswith(".root")):
  734. #print "x.endswith(.root) ", x.endswith(".root")
  735. continue
  736. x = filedir[:]+x
  737. if os.path.isdir(x):
  738. continue
  739. chain.Add(x)
  740. chain3.Add(x)
  741. elif os.path.isfile(filedir):
  742. chain.Add(filedir)
  743. chain3.Add(filedir)
  744. else:
  745. print " it is not file or dir ", filedir
  746.  
  747. chain.AddFriend(chain3)
  748.  
  749. evenodds = ["odd,even","odd,odd","even,even","even,odd","all pairs"]
  750. #hasnum = "&& fabs(%s)>0"%(num)
  751. hist = ROOT.TH1F("hist","hist",3000,0.0,xmaxBin*1.5)
  752. if pt>2 and pt<10:
  753. deltapt=.5
  754. else:
  755. deltapt=1.0
  756. chain.Draw("TMath::Abs(%s)>>hist"%(num),den+"&& pt>%f && pt<%f"%(pt-deltapt, pt+deltapt))
  757. #hist.Print("ALL")
  758. upperlim = getUpperlimit(hist, fractionToKeep)
  759. print "cuts ",den+"&& pt>%f && pt<%f"%(pt-1, pt+1)," upperlim ",upperlim
  760. return upperlim
  761. """
  762. print "eta%dto%dnpar%d%spt%dfraction%d:%f"%(int(etamin*10), int(etamax*10), npar,num,pt,fractionToKeep,upperlim)
  763. c1 = ROOT.TCanvas()
  764. c1.SetGridx()
  765. c1.SetGridy()
  766. c1.SetTickx()
  767. c1.SetTicky()
  768. hist.Draw()
  769. hist.GetXaxis().SetTitle("%s"%xtitle)
  770. hist.GetYaxis().SetTitle("%s"%ytitle)
  771. hist.SetTitle("%s distribution "%xtitle)
  772. #tex = ROOT.TLatex(0.15,0.87,"%s"%txt)
  773. tex = ROOT.TLatex(0.4,0.6,"#splitline{%s}{p_{T}>%d GeV, cut:%.4f}"%(txt,pt, upperlim))
  774. tex.SetTextSize(0.05)
  775. tex.SetTextFont(62)
  776. tex.SetNDC()
  777. #tex.Draw("same")
  778. #return Teffs
  779. #c1.Update()
  780. #c1.SaveAs("%s_Plateau%d_binsimPt%d.png"%(picname, fractionToKeep,pt))
  781. #c1.SaveAs("%s_Plateau%d_binsimPt%d.pdf"%(picname, fractionToKeep,pt))
  782.  
  783. """
  784. #_____________________________________________________________
  785. def makeEffplot_v2(chainlist,todraw, den, num, etamin, etamax, xtitle,ytitle,leg, legheader, txt,picname):
  786.  
  787. b1 = ROOT.TH1F("b1","b1",len(ptbins)-1, ptbins)
  788. b1.GetYaxis().SetRangeUser(0.00,1.05)
  789. b1.GetYaxis().SetTitleOffset(1.1)
  790. b1.GetYaxis().SetNdivisions(520)
  791. b1.GetYaxis().SetTitle("Trigger efficiency")
  792. b1.GetXaxis().SetTitle("True muon p_{T} [GeV]")
  793. b1.GetXaxis().SetTitleSize(0.05)
  794. b1.GetXaxis().SetLabelSize(0.05)
  795. b1.GetYaxis().SetTitleSize(0.05)
  796. b1.GetYaxis().SetLabelSize(0.05)
  797. b1.SetTitle(" #scale[1.4]{#font[61]{CMS}} #font[52]{Simulation preliminary}"+" "*10+" 14 TeV, 0 PU")
  798.  
  799.  
  800. Teffs = []
  801. hdens = []
  802. hnums = []
  803. npars = 4
  804. Upperlimits = [0 for x in range(npars)]
  805. color = [ROOT.kBlue, ROOT.kRed, ROOT.kMagenta+2, ROOT.kGreen+2,ROOT.kCyan+2]
  806. maker = [20,21,22,23,33]
  807.  
  808. if (etamin<1.6):
  809. ring = 2
  810. if (etamin>=1.6):
  811. ring = 1
  812. #legend = ROOT.TLegend(0.45,0.15,0.9,0.5)
  813. legend = ROOT.TLegend(0.45,0.20,0.8,0.50)
  814. legend.SetFillColor(ROOT.kWhite)
  815. legend.SetTextFont(42)
  816. #legend.SetTextSize(.05)
  817. legend.SetHeader("%s"%legheader)
  818. #muons = ["Prompt Muons","Displaced Muons, 5<|d_{xy}|<50cm"]
  819. muons = ["Prompt Muons","Prompt Muons"]
  820. for n in range(len(chainlist)):
  821. #if n>=1:
  822. # continue
  823. #print "n ",n
  824. chain = chainlist[n]
  825. hden = ROOT.TH1F("hden%d"%n,"hden%d"%n,len(ptbins)-1, ptbins)
  826. hnum = ROOT.TH1F("hnum%d"%n,"hnum%d"%n,len(ptbins)-1, ptbins)
  827. for i in range(len(ptbins)):
  828. hden.SetBinContent(i, 0)
  829. hnum.SetBinContent(i,.0)
  830. #Teffs.append(ROOT.TEfficiency(hnum, hden))
  831. hdens.append(hden)
  832. hnums.append(hnum)
  833. hdens[n].Add(gethist1D(chain, den[n],todraw))
  834. hnums[n].Add(gethist1D(chain, den[n]+" && %s"%(num[n]), todraw))
  835. #print " den cut ",den[n]," entries ", hdens[n].GetEntries()," num cut ", den[n]+" && %s"%(num[n])," entries ",hnums[n].GetEntries()
  836.  
  837.  
  838. c1 = ROOT.TCanvas()
  839. c1.SetGridx()
  840. c1.SetGridy()
  841. c1.SetTickx()
  842. c1.SetTicky()
  843.  
  844. b1.SetStats(0)
  845. b1.Draw()
  846. for n in range(len(chainlist)):
  847. #if n>=1:
  848. # continue
  849. Teffs.append(ROOT.TEfficiency(hnums[n],hdens[n]))
  850. SetOwnership(Teffs[n], False)
  851. m = len(Teffs)-1
  852. Teffs[m].SetLineColor(color[n])
  853. Teffs[m].SetMarkerColor(color[n])
  854. Teffs[m].SetMarkerStyle(maker[n])
  855. Teffs[m].Draw("same")
  856. legend.AddEntry(Teffs[n],"%s"%leg[n],"pl")
  857. #print "Teffs ",Teffs
  858. #Teffs[0].Print("ALL")
  859. legend.Draw("same")
  860.  
  861. tex = ROOT.TLatex(0.35,0.57,"%s"%txt)
  862. #tex = ROOT.TLatex(0.45,0.57,"#splitline{%s}{%d%% eff at %d [GeV]}"%(txt,fractionToKeep,pt))
  863. #tex = ROOT.TLatex(0.45,0.57,"#splitline{%s}{check the sign of #Delta Y_{12} and #Delta Y_{23}}"%(txt))
  864. tex.SetTextSize(0.05)
  865. tex.SetTextFont(62)
  866. tex.SetNDC()
  867. tex.Draw("same")
  868. #c1.Update()
  869. c1.SaveAs("%s.png"%(picname))
  870. c1.SaveAs("%s.pdf"%(picname))
  871. c1.SaveAs("%s.C"%(picname))
  872. return Teffs
  873.  
  874.  
  875. #_____________________________________________________________
  876. def makeEffplot_eta(chainlist,todraw, den, num, etamin, etamax, xtitle,ytitle,leg, legheader, txt,picname):
  877.  
  878. b1 = ROOT.TH1F("b1","b1", len(myetabin)-1, myetabin)
  879. b1.GetYaxis().SetRangeUser(0.0,1.05)
  880. b1.GetYaxis().SetTitleOffset(1.1)
  881. b1.GetYaxis().SetNdivisions(520)
  882. b1.GetXaxis().SetTitle(xtitle)
  883. b1.GetYaxis().SetTitle(ytitle)
  884. b1.GetXaxis().SetTitleSize(0.05)
  885. b1.GetXaxis().SetLabelSize(0.05)
  886. b1.GetYaxis().SetTitleSize(0.05)
  887. b1.GetYaxis().SetLabelSize(0.05)
  888. b1.SetTitle(" #scale[1.4]{#font[61]{CMS}} #font[52]{Simulation preliminary}"+" "*8+" 14 TeV, 200 PU")
  889.  
  890.  
  891. Teffs = []
  892. hdens = []
  893. hnums = []
  894. npars = 4
  895. Upperlimits = [0 for x in range(npars)]
  896. #print "chainlist ",chainlist
  897.  
  898. if (etamin<1.6):
  899. ring = 2
  900. if (etamin>=1.6):
  901. ring = 1
  902. #legend = ROOT.TLegend(0.45,0.15,0.9,0.5)
  903. legend = ROOT.TLegend(0.45,0.20,0.8,0.50)
  904. legend.SetFillColor(ROOT.kWhite)
  905. legend.SetTextFont(42)
  906. #legend.SetTextSize(.05)
  907. legend.SetHeader("%s"%legheader)
  908. muons = ["Prompt Muons","Displaced Muons, 5<|d_{xy}|<50cm"]
  909. for n in range(len(chainlist)):
  910. # print "n ",n," den ",den[n]," num ",num[n]
  911. hden = ROOT.TH1F("hden%d"%n,"hden%d"%n,len(myetabin)-1, myetabin)
  912. hnum = ROOT.TH1F("hnum%d"%n,"hnum%d"%n,len(myetabin)-1, myetabin)
  913. for i in range(0, len(myetabin)-1):
  914. hden.SetBinContent(i, 0)
  915. hnum.SetBinContent(i,.0)
  916. #Teffs.append(ROOT.TEfficiency(hnum, hden))
  917. hdens.append(hden)
  918. hnums.append(hnum)
  919. chain = chainlist[n]
  920. #print "den ",den[n]," num ", num[n], " todraw ",todraw
  921. hdens[n].Add(gethist1DEta(chain, den[n],todraw))
  922. hnums[n].Add(gethist1DEta(chain, den[n]+" && %s"%(num[n]), todraw))
  923.  
  924. c1 = ROOT.TCanvas()
  925. c1.SetGridx()
  926. c1.SetGridy()
  927. c1.SetTickx()
  928. c1.SetTicky()
  929.  
  930. b1.SetStats(0)
  931. b1.Draw()
  932. for n in range(len(chainlist)):
  933. Teffs.append(ROOT.TEfficiency(hnums[n],hdens[n]))
  934. SetOwnership(Teffs[n], False)
  935. m = len(Teffs)-1
  936. Teffs[m].SetLineColor(color[n])
  937. Teffs[m].SetMarkerColor(color[n])
  938. Teffs[m].SetMarkerStyle(maker[n])
  939. Teffs[m].Draw("same")
  940. legend.AddEntry(Teffs[n],"%s"%leg[n],"pl")
  941. #print "Teffs ",Teffs
  942. #Teffs[0].Print("ALL")
  943. legend.Draw("same")
  944.  
  945. tex = ROOT.TLatex(0.35,0.57,"%s"%txt)
  946. #tex = ROOT.TLatex(0.45,0.57,"#splitline{%s}{%d%% eff at %d [GeV]}"%(txt,fractionToKeep,pt))
  947. #tex = ROOT.TLatex(0.45,0.57,"#splitline{%s}{check the sign of #Delta Y_{12} and #Delta Y_{23}}"%(txt))
  948. tex.SetTextSize(0.05)
  949. tex.SetTextFont(62)
  950. tex.SetNDC()
  951. tex.Draw("same")
  952. #c1.Update()
  953. c1.SaveAs("%s.png"%(picname))
  954. c1.SaveAs("%s.pdf"%(picname))
  955. c1.SaveAs("%s.C"%(picname))
  956. return Teffs
  957.  
  958. def makeplots(Teffs, legs, text, picname):
  959.  
  960. b1 = ROOT.TH1F("b1","b1",len(ptbins)-1, ptbins)
  961. b1.GetYaxis().SetRangeUser(0.0,1.05)
  962. b1.GetYaxis().SetTitleOffset(1.1)
  963. b1.GetYaxis().SetNdivisions(520)
  964. b1.GetYaxis().SetTitle("Trigger efficiency")
  965. b1.GetXaxis().SetTitle("True muon p_{T} [GeV]")
  966. b1.GetXaxis().SetTitleSize(0.05)
  967. b1.GetXaxis().SetLabelSize(0.05)
  968. b1.GetYaxis().SetTitleSize(0.05)
  969. b1.GetYaxis().SetLabelSize(0.05)
  970. b1.SetTitle(" #scale[1.4]{#font[61]{CMS}} #font[52]{Simulation preliminary}"+" "*10+" 14 TeV, 200 PU")
  971.  
  972.  
  973. c1 = ROOT.TCanvas()
  974. c1.SetGridx()
  975. c1.SetGridy()
  976. c1.SetTickx()
  977. c1.SetTicky()
  978.  
  979. dy_leg = 0.06*len(Teffs)
  980.  
  981. legend = ROOT.TLegend(0.4,0.2,0.9,0.2+dy_leg)
  982. legend.SetFillColor(ROOT.kWhite)
  983. legend.SetTextFont(42)
  984. #legend.SetTextSize(.04)
  985. #legend.SetHeader("%"%legheader)
  986. b1.SetStats(0)
  987. b1.Draw()
  988. for n in range(len(Teffs)):
  989. Teffs[n].SetLineColor(color[n])
  990. Teffs[n].SetMarkerColor(color[n])
  991. Teffs[n].SetMarkerStyle(maker[n])
  992. Teffs[n].Draw("samep")
  993. legend.AddEntry(Teffs[n],"%s"%legs[n],"pl")
  994. legend.Draw("same")
  995.  
  996. tex = ROOT.TLatex(0.4,0.6,"%s"%text)
  997. tex.SetTextSize(0.05)
  998. tex.SetTextFont(62)
  999. tex.SetNDC()
  1000. tex.Draw("same")
  1001. #c1.Update()
  1002. c1.SaveAs("%s.png"%(picname))
  1003. c1.SaveAs("%s.pdf"%(picname))
  1004. c1.SaveAs("%s.C"%(picname))
  1005.  
  1006.  
  1007. def makeplotsEta(Teffs, legs, legheader, text, picname):
  1008.  
  1009. color = [ROOT.kGreen+2, ROOT.kGreen+2, ROOT.kBlue, ROOT.kBlue, ROOT.kOrange+7]
  1010. marker = [20, 24, 21, 25, 26]
  1011. color = [ROOT.kBlue, ROOT.kBlue, ROOT.kOrange+7, ROOT.kGreen+2]
  1012. marker = [21, 25, 26, 20, 24]
  1013.  
  1014. etabin = [1.55, 1.65, 1.75, 1.85, 1.95, 2.05, 2.15, 2.25, 2.35, 2.45, 2.55]
  1015. myetabin = np.asarray(etabin)
  1016. b1 = ROOT.TH1F("b1","b1", len(myetabin)-1, myetabin)
  1017. b1.GetYaxis().SetRangeUser(0.60,1.05)
  1018. b1.GetYaxis().SetTitleOffset(1.1)
  1019. b1.GetYaxis().SetNdivisions(520)
  1020. b1.GetYaxis().SetTitle("Trigger efficiency")
  1021. b1.GetXaxis().SetTitle("Simulated |#eta|")
  1022. b1.GetXaxis().SetTitleSize(0.05)
  1023. b1.GetXaxis().SetLabelSize(0.05)
  1024. b1.GetYaxis().SetTitleSize(0.05)
  1025. b1.GetYaxis().SetLabelSize(0.05)
  1026. b1.SetTitle(" #scale[1.4]{#font[61]{CMS}} #font[52]{Simulation preliminary}"+" "*7+" 14 TeV, 200 PU")
  1027.  
  1028. c1 = ROOT.TCanvas()
  1029. c1.SetGridx()
  1030. c1.SetGridy()
  1031. c1.SetTickx()
  1032. c1.SetTicky()
  1033.  
  1034. dy_leg = 0.05*(len(Teffs)+1)
  1035.  
  1036. legend = ROOT.TLegend(0.2, 0.15,0.85,0.15+dy_leg)
  1037. legend.SetFillColor(ROOT.kWhite)
  1038. legend.SetTextFont(42)
  1039. #legend.SetTextSize(.05)
  1040. legend.SetHeader("%s"%legheader)
  1041. b1.SetStats(0)
  1042. b1.Draw()
  1043. for n in range(len(Teffs)):
  1044. Teffs[n].SetLineColor(color[n])
  1045. Teffs[n].SetMarkerColor(color[n])
  1046. Teffs[n].SetMarkerStyle(marker[n])
  1047. Teffs[n].Draw("samep")
  1048. legend.AddEntry(Teffs[n],"%s"%legs[n],"pl")
  1049. legend.Draw("same")
  1050.  
  1051. tex = ROOT.TLatex(0.15,0.88,"%s"%text)
  1052. tex.SetTextSize(0.04)
  1053. tex.SetTextFont(62)
  1054. tex.SetNDC()
  1055. tex.Draw("same")
  1056. #c1.Update()
  1057. c1.SaveAs("%s.png"%(picname))
  1058. c1.SaveAs("%s.pdf"%(picname))
  1059. c1.SaveAs("%s.C"%(picname))
  1060.  
  1061. def getRateVsEtav2(L1MuTriggerRate, histname, myetabin, cut):
  1062. etabin = [1.55, 1.65, 1.75, 1.85, 1.95, 2.05, 2.15, 2.25, 2.35, 2.45, 2.55]
  1063. myetabin = np.asarray(etabin)
  1064. hist = TH1F(histname, histname, len(myetabin)-1, myetabin)
  1065. L1MuTriggerRate.Draw("abs(L1Mu_eta)>>"+histname, cut)
  1066. hist.GetXaxis().SetTitle("L1Mu |#eta|")
  1067. hist.GetYaxis().SetTitle("Trigger Rate [kHz]")
  1068. SetOwnership(hist, False)
  1069. return hist
  1070.  
  1071.  
  1072. def getRateVsEta(L1MuTriggerRate, histname, myetabin, cut):
  1073. hist = TH1F(histname, histname, len(myetabin)-1, myetabin)
  1074. L1MuTriggerRate.Draw("abs(L1Mu_eta)>>"+histname, cut)
  1075. hist.GetXaxis().SetTitle("L1Mu |#eta|")
  1076. hist.GetYaxis().SetTitle("Trigger Rate [kHz]")
  1077. SetOwnership(hist, False)
  1078. return hist
  1079.  
  1080. def plotshistograms(hists, legs,legheader, text, picname, RateVsPt=False):
  1081.  
  1082. color = [ROOT.kGreen+2, ROOT.kGreen+2, ROOT.kBlue, ROOT.kBlue, ROOT.kOrange+7]
  1083. color = [ ROOT.kOrange+7, ROOT.kBlue, ROOT.kBlue, ROOT.kGreen+2]
  1084. marker = [26, 25, 21, 24, 20]
  1085. hs = ROOT.THStack("hs"," #scale[1.4]{#font[61]{CMS}} #font[52]{Simulation preliminary}"+" "*7+" 14 TeV, 200 PU")
  1086. c1 = ROOT.TCanvas()
  1087. c1.SetGridx()
  1088. c1.SetGridy()
  1089. c1.SetTickx()
  1090. c1.SetTicky()
  1091. c1.SetLogy()
  1092. if RateVsPt:
  1093. hs.SetMinimum(.1)
  1094. hs.SetMaximum(500.)
  1095. else:
  1096. hs.SetMinimum(.01)
  1097. #hs.SetMaximum(100.)
  1098. #pass
  1099.  
  1100. dy_leg = 0.04*(len(hists)+1)
  1101.  
  1102. x0 = 0.15; x1 =0.75; y0 = 0.15;
  1103. if RateVsPt:
  1104. x0 = 0.5; x1 = 0.88; y0 = 0.7
  1105. #legend = ROOT.TLegend(0.15,0.15,0.6,0.15+dy_leg)
  1106. legend = ROOT.TLegend(x0, y0, x1, y0+dy_leg)
  1107.  
  1108. legend.SetHeader(legheader)
  1109. legend.SetFillColor(ROOT.kWhite)
  1110. legend.SetTextFont(42)
  1111. #legend.SetTextSize(.05)
  1112. nhist = -1
  1113. for hist in hists:
  1114. nhist +=1
  1115. hist.SetMarkerColor(color[nhist])
  1116. hist.SetLineColor(color[nhist])
  1117. hist.SetMarkerStyle(marker[nhist])
  1118. hist.SetMarkerSize(1)
  1119. hist.SetLineWidth(2)
  1120. #for rate
  1121. #hist.Scale(SF)
  1122. hs.Add(hist)
  1123. #legend.AddEntry(hist, legs[nhist]+",event:%d"%hist.GetEntries(),"pl")
  1124. legend.AddEntry(hist, legs[nhist],"pl")
  1125. hs.Draw("nostacke")
  1126. legend.Draw("same")
  1127. if RateVsPt:
  1128. c1.SetLogy()
  1129. #c2.SetLogx()
  1130. c1.SetGridx()
  1131. c1.SetGridy()
  1132.  
  1133. c1.Update()
  1134. c1.Modified()
  1135. #print "hists[0] ",hists[0]
  1136. #hs.GetHistogram().GetXaxis().SetTitle(hists[0].GetXaxis().GetTitle())
  1137. #hs.GetHistogram().GetYaxis().SetTitle(hists[0].GetYaxis().GetTitle())
  1138. hs.GetHistogram().GetXaxis().SetTitle("L1Mu |#eta|")
  1139. texh=0.5
  1140. if RateVsPt:
  1141. hs.GetHistogram().GetXaxis().SetTitle("Trigger p_{T} threshold [GeV]")
  1142. texh = 0.2
  1143. hs.GetHistogram().GetYaxis().SetTitle("Trigger rate [kHz]")
  1144.  
  1145. tex = ROOT.TLatex(0.2,texh,"%s"%text)
  1146. tex.SetTextSize(0.045)
  1147. tex.SetTextFont(62)
  1148. tex.SetNDC()
  1149. tex.Draw("same")
  1150. #c1.Update()
  1151. c1.SaveAs("%s.png"%(picname))
  1152. c1.SaveAs("%s.pdf"%(picname))
  1153. c1.SaveAs("%s.C"%(picname))
  1154.  
  1155. ##############################################################3
  1156.  
  1157.  
  1158. treename = "GEMCSCAnalyzer/trk_eff_CSC_ALL"
  1159. filedir16 = "/eos/uscms/store/user/tahuang/SLHC23_patch1_2023Muon_gen_sim_Pt2_50_1M/GEMCSC_Ana_ctau0_Pt2_50_PU140_20170314/170315_023223/0000/combined/out_ana_prompt.root"
  1160. #filedir46 = "/eos/uscms/store/user/tahuang/SLHC23_patch1_2023Muon_gen_sim_Pt10_100k/GEMCSC_Ana_ctau0_Pt10_PU0_20170222/170222_173137/0000/combined/out_ana_fixedpt.root"
  1161. filedir16 = "out_ana_prompt_pu140_1M_20170314.root"
  1162. filedir46 = "/eos/uscms/store/user/tahuang/SLHC23_patch1_2023Muon_gen_sim_Pt7_100k/GEMCSC_Ana_ctau0_Pt7_PU0_20170303/170303_233949/0000/combined/out_ana_fixedpt.root"
  1163.  
  1164. #binLow = [0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,12.0,14.0,16.0,18.0,20.0,24.0,28.0,32.0,36.0,42.0,50.0]
  1165. binLow = [0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,12.0,14.0,16.0,18.0,20.0,24.0,28.0,32.0,36.0,42.0,50.0]
  1166. binLow = [x*1.0 for x in range(0,51)]
  1167. ptbins = np.asarray(binLow)
  1168. #etabin = [1.0, 1.2, 1.3, 1.4, 1.5, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95,
  1169. #2.0, 2.05, 2.1, 2.15, 2.2, 2.25, 2.3, 2.35, 2.4, 2.45, 2.5]
  1170. ptbin = [
  1171. #1, 2.0, 2.5,
  1172. 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 7.0, 8.0,
  1173. 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 25.0, 30.0, 35.0, 40.0,
  1174. 45.0, 50.0]# 60.0, 70.0, 80.0, 90.0, 100.0, 120.0, 140.0]
  1175. rateptbin = [5.0, 6.0, 7.0,8.0, 10.0, 12.0, 14.0, 16.0, 20.0, 25.0, 30.0, 35.0]
  1176. myptbin = np.asarray(ptbin)
  1177. myrateptbin = np.asarray(rateptbin)
  1178. evenodds = ["odd,even","odd,odd","even,even","even,odd","all pairs"]
  1179. netas = [1.2,1.4,1.6,1.8,2.0,2.2]
  1180. netas = [1.6,1.8,2.0,2.2]
  1181. allnpar = [0,1,2,3]
  1182. filedirs_v6 = [filedir16, filedir46]
  1183. #filedirs_v6 = ["out_ana.root","out_ana.root"]
  1184. fraction = 98
  1185. if len(sys.argv)>=3:
  1186. #take dir name from arguments, condor mode
  1187. #pt = int(sys.argv[])
  1188. #fraction = int(sys.argv[2])
  1189. outputdir1 = sys.argv[1]
  1190. outputdir2 = sys.argv[2]
  1191. #outputdir1 = "Profile_Ellipse_PT_0929_Pt%d_BGPt%d/"%(pt1,pt2)
  1192. #outputdir2 = "Hybrid_Ellipse_PT_0929_Pt%d_BGPt%d/"%(pt1,pt2)
  1193. #filedirs_v6 = ["out_ana_prompt.root","out_ana_displaced.root"]
  1194. filedirs_v6 = ["out_ana_prompt.root","out_ana_fixedpt.root"]
  1195. #if outputdir1[-1] != "/":
  1196. # outputdir1 = outputdir1+"/"
  1197. #if outputdir2[-1] != "/":
  1198. # outputdir2 = outputdir2+"/"
  1199. else:
  1200. pt = 10
  1201. pt1 = 0
  1202. outputdir1 = "GEMCSC_20170621_00_local_badGE11_20_ratept/"
  1203. outputdir2 = "GEMCSC_20170722_RateVsEff_pt10_eta12to24/"
  1204.  
  1205. #pt1 = 10
  1206. #pt2 = 7
  1207. #allLUTfile = "finalLUT_20170312.log"
  1208. allLUTfile = "finalLUT_20170314_all.log"
  1209. #LUT = open("GEMCSCBendinghybridLUT_Pt%d_fraction%d.log"%(pt, fraction),"w+")
  1210. #LUT_nEvent = open("EventNum_Pt%d_fraction%d.log"%(pt, fraction),"w+")
  1211. LUT_st1 = open("GEMCSCBendingGE11LUT_alltest.log","w+")
  1212. LUT_st2 = open("GEMCSCBendingGE21LUT_alltest.log","w+")
  1213. #for npt in range(len(Pts)):
  1214. def plotalleta(pt, pt1, netas, fraction, outputrootfile, badGE11bending=0):
  1215. badeff = badGE11bending*1.0/100.0
  1216. Teffs_0 = []
  1217. Teffs_0_ME11 = []
  1218. Teffs_0_ME21 = []
  1219. extrapic=""
  1220. extratxt=""
  1221. #fraction_d = 99
  1222. #LUT.write("eta%dto%dfraction%d"%(int(netas[0]*10), int(netas[-1]*10), fraction)+extratxt+"\n")
  1223. #LUT_nEvent.write("eta%dto%dfraction%d"%(int(netas[0]*10), int(netas[-1]*10), fraction)+extratxt+"\n")
  1224. LUT_st1.write("eta%dto%dpt%dfraction%d"%(int(netas[0]*10), int(netas[-1]*10),pt, fraction)+extratxt+"\n")
  1225. LUT_st2.write("eta%dto%dpt%dfraction%d"%(int(netas[0]*10), int(netas[-1]*10),pt, fraction)+extratxt+"\n")
  1226.  
  1227. ratefile = TFile(ratesample)
  1228. h_total = ratefile.Get("h_eventcountME0Segment192")
  1229. rateEvents = h_total.GetEntries()
  1230. L1MuTriggerRate = TChain("L1MuTriggerRateME0Segment192")
  1231. addFilesToChain(L1MuTriggerRate, ratesample)
  1232.  
  1233. GEMCSCTrackCh0 = TChain("GEMCSCAnalyzer/trk_eff_CSC_ALL")
  1234. GEMCSCME11Ch0 = TChain("GEMCSCAnalyzer/trk_eff_CSC_ME11")
  1235. GEMCSCME21Ch0 = TChain("GEMCSCAnalyzer/trk_eff_CSC_ME21")
  1236. GEMCSCTrackCh1 = TChain("GEMCSCAnalyzer/trk_eff_CSC_ALL")
  1237. GEMCSCME11Ch1 = TChain("GEMCSCAnalyzer/trk_eff_CSC_ME11")
  1238. GEMCSCME21Ch1 = TChain("GEMCSCAnalyzer/trk_eff_CSC_ME21")
  1239. addFilesToChain(GEMCSCTrackCh0, signalsampleGE11only)
  1240. addFilesToChain(GEMCSCME11Ch0, signalsampleGE11only)
  1241. addFilesToChain(GEMCSCME21Ch0, signalsampleGE11only)
  1242. addFilesToChain(GEMCSCTrackCh1, signalsample)
  1243. addFilesToChain(GEMCSCME11Ch1, signalsample)
  1244. addFilesToChain(GEMCSCME21Ch1, signalsample)
  1245. GEMCSCTrackCh0.AddFriend(GEMCSCME11Ch0)
  1246. GEMCSCTrackCh0.AddFriend(GEMCSCME21Ch0)
  1247. GEMCSCTrackCh1.AddFriend(GEMCSCME11Ch1)
  1248. GEMCSCTrackCh1.AddFriend(GEMCSCME21Ch1)
  1249.  
  1250. Teff_out = ROOT.TFile(outputrootfile,"UPDATE")
  1251. GE11Cuts = []
  1252. GE21Cuts = []
  1253. rate_x = "gemdphi_st1"
  1254. rate_y = "gemdphi_st2"
  1255. legs = ["prompt muon","prompt muon with fixed pt"]
  1256. legsall = ["CSC only","CSC + GE11"," CSC + GE11 + GE21"]
  1257. efflist = []
  1258. ratelist = []
  1259. ratehist_csc_list = []
  1260. ratehist_st1_list = []
  1261. ratehist_h_list = []
  1262. quality = 4; quality2 = 4
  1263. for neta in range(len(netas)-1):
  1264.  
  1265. if (netas[neta]<0 or netas[neta+1]<0):
  1266. continue
  1267. etamin = netas[neta]
  1268. etamax = netas[neta+1]
  1269. GE11Cuts.append([])
  1270. GE21Cuts.append([])
  1271. ratehist_h_all = 0
  1272. Teffallnpars = []
  1273. Teffallnpars_ME11 = []
  1274. Teffallnpars_ME21 = []
  1275. #pt = Pts[npt]
  1276. #pt1 = Pts_1[npt]
  1277. #etacuts = "fabs(L1Mu_eta)>%f && fabs(L1Mu_eta)<%f"%(netas[neta], netas[neta+1])
  1278. etacuts = "fabs(eta)>%f && fabs(eta)<%f"%(netas[neta], netas[neta+1])
  1279. ring = 1
  1280. #LUT.write("{\n")
  1281. #LUT_nEvent.write("{\n")
  1282. LUT_st1.write("{\n")
  1283. LUT_st2.write("{\n")
  1284. #basesignalcut = etacuts + "&& has_tfTrack>0 && has_gmtCand>0 && L1Mu_quality>=%d && nstubs>=2 && meRing==%d "%(quality, ring)
  1285. #basesignalcut = etacuts + "&& has_tfTrack>0 && has_gmtCand>0 && nstubs>=2 && meRing==%d "%(ring)
  1286. basesignalcut = etacuts
  1287.  
  1288. nevenodd = 1
  1289. for evenodd in ["odd","even"]:
  1290. if fraction==100:
  1291. xcut = 100
  1292. ycut = 100
  1293. else:
  1294. algos_lut = getFinalLUTValue(pt, fraction, etamin, etamax, nevenodd, allLUTfile)
  1295. xcut = algos_lut["GE11"]
  1296. ycut = algos_lut["GE21"]
  1297. #xaxis = "trk_eff_CSC_ME11.dphi_pad_fit_%s"%(evenodd)
  1298. #yaxis = "trk_eff_CSC_ME21.dphi_pad_fit_%s"%(evenodd)
  1299. #xcut = getCut(GEMCSCTrackCh0, xaxis, basesignalcut+"&& fabs(%s)<1"%(xaxis)+" && L1Mu_pt>=%f && pt>=%f"%(pt, pt), 0.0, 0.05, 0.0001, fraction)
  1300. #ycut = getCut(GEMCSCTrackCh0, yaxis, basesignalcut+"&& fabs(%s)<1"%(yaxis)+" && L1Mu_pt>=%f && pt>=%f"%(pt, pt), 0.0, 0.05, 0.0001, fraction)
  1301. print " xcut ",xcut, " ycut ",ycut
  1302. nevenodd += 1
  1303. LUT_st1.write("%f"%xcut)
  1304. LUT_st2.write("%f"%ycut)
  1305. if evenodd == "odd":
  1306. LUT_st1.write(",")
  1307. LUT_st2.write(",")
  1308. GE11Cuts[neta].append(xcut)
  1309. GE21Cuts[neta].append(ycut)
  1310.  
  1311. LUT_st1.write("\n},\n")
  1312. LUT_st2.write("\n},\n")
  1313. text1 = "%.2f<|#eta|<%.2f, p_{T}^{L1}>%d GeV"%(netas[neta],netas[neta+1], pt)
  1314. baseratecut = "maxPromptPt && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && L1Mu_pt>=%f"%(etamin, etamax,quality, pt)
  1315. baseratecut2 = "hasME1 && maxPromptPt && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && L1Mu_pt>=%f"%(etamin, etamax, quality2, pt)
  1316. #baseratecut_CSConly = "maxPromptPt && abs(L1Mu_eta)>1.6 && abs(L1Mu_eta)<2.4 && L1Mu_quality>=12 && L1Mu_pt>=%f"%( pt)
  1317. #ratehist_CSC = getRateVsEta(L1MuTriggerRate, "ratehist_CSConly_eta%dto%d_pt%d"%(int(netas[neta]*10),int(netas[neta+1]*10), pt), myetabin, baseratecut_CSConly)
  1318.  
  1319. L1MuQcut = "L1Mu_quality>=%d && "%quality
  1320. GE11bendingCut = L1MuQcut+ "L1Mu_pt>=%f && (abs(trk_eff_CSC_ME11.dphi_pad_fit_odd)<%f || abs(trk_eff_CSC_ME11.dphi_pad_fit_even)<%f)"%(pt, GE11Cuts[neta][0], GE11Cuts[neta][1])
  1321. GE11bendingCut_bad = L1MuQcut+"L1Mu_pt>=%f && (((abs(trk_eff_CSC_ME11.dphi_2strippad_fit_odd)<%f || abs(trk_eff_CSC_ME11.dphi_2strippad_fit_even)<%f)"%(pt, GE11Cuts[neta][0], GE11Cuts[neta][1])+"&& rand01_v1>%f) || (rand01_v1<%f && trk_eff_CSC_ME11.has_gem_pad>0))"%(badeff, badeff)
  1322. #GE11bendingCut = L1MuQcut+ "L1Mu_pt>=%f && hasME1 && (abs(trk_eff_CSC_ME11.dphi_pad_fit_odd)<%f || abs(trk_eff_CSC_ME11.dphi_pad_fit_even)<%f)"%(pt, GE11Cuts[neta][0], GE11Cuts[neta][1])
  1323. #GE11bendingCut_bad = L1MuQcut+"L1Mu_pt>=%f && hasME1 && (((abs(trk_eff_CSC_ME11.dphi_2strippad_fit_odd)<%f || abs(trk_eff_CSC_ME11.dphi_2strippad_fit_even)<%f)"%(pt, GE11Cuts[neta][0], GE11Cuts[neta][1])+"&& rand01_v1>%f) || (rand01_v1<%f && trk_eff_CSC_ME11.has_gem_pad>0))"%(badeff, badeff)
  1324. GE21bendingCut = L1MuQcut+ "L1Mu_pt>=%f && hasME1 && (abs(trk_eff_CSC_ME21.dphi_pad_fit_odd)<%f || abs(trk_eff_CSC_ME21.dphi_pad_fit_even)<%f)"%(pt, GE11Cuts[neta][0], GE11Cuts[neta][1])
  1325.  
  1326. GE11bendingRateCut = "hasME1 && CSCTF_dR1<.3 && ((CSCTF_ch1%%2==1 && abs(%s)<%f) || (CSCTF_ch1%%2==0 && abs(%s)<%f))"%(rate_x, GE11Cuts[neta][0], rate_x, GE11Cuts[neta][1])
  1327. GE11bendingRateCut_bad = "((hasME1&& CSCTF_dR1<.3 && ((CSCTF_ch1%%2==1 && abs(%s)<%f) || (CSCTF_ch1%%2==0 && abs(%s)<%f))"%(rate_x, GE11Cuts[neta][0], rate_x, GE11Cuts[neta][1])+"&& RandFloat01>%f) || (RandFloat01<%f))"%(badeff, badeff)
  1328. GE21bendingRateCut = "hasME2 && ((CSCTF_ch2%%2==1 && abs(%s)<%f) || (CSCTF_ch2%%2==0 && abs(%s)<%f))"%(rate_y, GE21Cuts[neta][0], rate_y, GE21Cuts[neta][1])
  1329. Teffs_cutx = makeEffplot_v2([GEMCSCTrackCh0], "pt",[basesignalcut],[GE11bendingCut], netas[neta], netas[neta+1],"true muon p_{T} GeV","bending angle cut efficiency",legs,"GE11-ME11" ,text1,outputdir2+"GEMCSC_St1_GE11cut_eff_20170208_pt%d_fraction%d_st2eta%dto%d_all"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10)))
  1330. print "GE11 basecut ",basesignalcut," bending angle cut ",GE11bendingCut
  1331. TeffsEta_cutx = makeEffplot_eta([GEMCSCTrackCh0], "abs(eta)",[basesignalcut+" && pt>=%d"%(pt+5)],[GE11bendingCut], netas[neta], netas[neta+1],"Simulated |#eta|","bending angle cut efficiency",legs,"GE11-ME11" ,text1,outputdir2+"GEMCSC_St1_GE11cut_effvseta_20170208_pt%d_fraction%d_st2eta%dto%d_all"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10)))
  1332.  
  1333. Teffs_cutx_badeff = makeEffplot_v2([GEMCSCTrackCh0], "pt",[basesignalcut],[GE11bendingCut_bad], netas[neta], netas[neta+1],"true muon p_{T} GeV","bending angle cut efficiency",legs,"GE11-ME11" ,text1,outputdir2+"GEMCSC_St1_GE11cut_eff_20170208_pt%d_fraction%d_st2eta%dto%d_badGE11frac%d_all"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10), badGE11bending))
  1334. TeffsEta_cutx_badeff = makeEffplot_eta([GEMCSCTrackCh0], "abs(eta)",[basesignalcut],[GE11bendingCut_bad], netas[neta], netas[neta+1],"Simulated |#eta|","bending angle cut efficiency",legs,"GE11-ME11" ,text1,outputdir2+"GEMCSC_St1_GE11cut_effvseta_20170208_pt%d_fraction%d_st2eta%dto%d_badGE11frac%d_all"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10), badGE11bending))
  1335. Teffs_cuty = makeEffplot_v2([GEMCSCTrackCh1], "pt",[basesignalcut], [GE21bendingCut], netas[neta], netas[neta+1],"true muon p_{T} GeV","bending angle cut efficiency",legs,"GE21-ME21" ,text1,outputdir2+"GEMCSC_St2_GE21cut_eff_20170208_pt%d_fraction%d_st2eta%dto%d_all"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10)))
  1336. TeffsEta_cuty = makeEffplot_eta([GEMCSCTrackCh1], "abs(eta)",[basesignalcut+" && pt>=%d"%(pt+5)], [GE21bendingCut], netas[neta], netas[neta+1],"Simulated |#eta|","bending angle cut efficiency",legs,"GE21-ME21" ,text1,outputdir2+"GEMCSC_St2_GE21cut_effvseta_20170208_pt%d_fraction%d_st2eta%dto%d_all"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10)))
  1337. ratehist_st1 = getRateVsEta(L1MuTriggerRate, "ratehist_GE11_eta%dto%d_frac%d_pt%d"%(int(netas[neta]*10),int(netas[neta+1]*10), fraction, pt), myetabin, baseratecut + "&&" +GE11bendingRateCut)
  1338. ratehist_st1_bad = getRateVsEta(L1MuTriggerRate, "ratehist_GE11_eta%dto%d_frac%d_pt%d_badGE11frac%d"%(int(netas[neta]*10),int(netas[neta+1]*10), fraction, pt, badGE11bending), myetabin, baseratecut + "&&" +GE11bendingRateCut_bad)
  1339. ratehist_st2 = getRateVsEta(L1MuTriggerRate, "ratehist_GE21_eta%dto%d_frac%d_pt%d"%(int(netas[neta]*10),int(netas[neta+1]*10), fraction, pt), myetabin, baseratecut + "&& "+GE21bendingRateCut)
  1340. #print "ratehist_st1_bad : ",baseratecut + "&&" +GE11bendingRateCut_bad," bad entries ",ratehist_st1_bad.GetEntries()," normal entries ", ratehist_st1.GetEntries()
  1341. #Teffs_cutx[0].SetName("GE11eta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"pt%d"%(pt)+"fraction%d"%fraction)
  1342. #Teffs_cuty[0].SetName("GE21eta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"pt%d"%(pt)+"fraction%d"%fraction)
  1343. #Teffs_cutx[0].Write()
  1344. #Teffs_cuty[0].Write()
  1345. Teffallnpars_ME11.append(Teffs_cutx)
  1346. Teffallnpars_ME21.append(Teffs_cuty)
  1347. GE11Ratecut_h = "("+GE11bendingRateCut+"&& abs(%s)>1"%(rate_y)+ " && npar_bending<0)"
  1348. GE11Ratecut_h_bad = "("+GE11bendingRateCut_bad+"&& abs(%s)>1"%(rate_y)+ "&& npar_bending<0)"
  1349. GE21Ratecut_h = "("+GE21bendingRateCut+"&& abs(%s)>1"%(rate_x)+" && npar_bending<0)"
  1350. GE21Ratecut_h_bad = "("+GE21bendingRateCut+"&& ((abs(%s)>1 && npar_bending<0) || RandFloat01<%f)"%(rate_x,badeff)+")"
  1351.  
  1352. GE11SignalCut_h = "("+GE11bendingCut+"&& trk_eff_CSC_ME21.has_lct==0"+")"
  1353. GE21SignalCut_h = "("+GE21bendingCut+"&& trk_eff_CSC_ME11.has_lct==0"+")"
  1354. GE11SignalCut_h_bad = "("+GE11bendingCut+"&& trk_eff_CSC_ME21.has_lct==0 && rand01_v1>%f"%badeff+")"
  1355. GE21SignalCut_h_bad = "("+GE21bendingCut+"&& (trk_eff_CSC_ME11.has_lct==0 || rand01_v1<%f)"%badeff+")"
  1356. #GE11SignalCut_h = "("+GE11bendingCut+"&& (!hasME2 || (abs(trk_eff_CSC_ME21.dphi_2strippad_fit_even)>1 && abs(trk_eff_CSC_ME21.dphi_2strippad_fit_odd)>1)) "+")"
  1357. #GE21SignalCut_h = "("+GE21bendingCut+"&& (!hasME1 || (abs(trk_eff_CSC_ME11.dphi_2strippad_fit_even)>1 && abs(trk_eff_CSC_ME11.dphi_2strippad_fit_odd)>1)) && abs(eta)>2.1"+")"
  1358. #GE11SignalCut_h_bad = "("+GE11bendingCut+"&& ((!hasME2 || (abs(trk_eff_CSC_ME21.dphi_2strippad_fit_even)>1 && abs(trk_eff_CSC_ME21.dphi_2strippad_fit_odd)>1)) && rand01_v1>%f)"%badeff+")"
  1359. #GE21SignalCut_h_bad = "("+GE21bendingCut+"&& ((!hasME1 || (abs(trk_eff_CSC_ME11.dphi_2strippad_fit_even)>1 && abs(trk_eff_CSC_ME11.dphi_2strippad_fit_odd)>1)) || rand01_v1<%f)"%badeff+")"
  1360. #ratehist_h_all = getRateVsEta(L1MuTriggerRate, "ratehist_hybrid_eta%dto%d_frac%d_pt%d"%(int(netas[neta]*10),int(netas[neta+1]*10), fraction, pt), myetabin, baseratecut + "&& ("+GE11Ratecut_h+" || "+GE21Ratecut_h+")" )
  1361. finalSignalCut_h = "("+GE11SignalCut_h+" || "+GE21SignalCut_h
  1362. finalSignalCut_h_bad = "("+GE11SignalCut_h_bad+" || "+GE21SignalCut_h_bad
  1363. #ratehist_h_all = getRateVsEta(L1MuTriggerRate, "ratehist_hybrid_eta%dto%d_frac%d_pt%d"%(int(netas[neta]*10),int(netas[neta+1]*10), fraction, pt), myetabin, baseratecut + "&& ("+GE11Ratecut_h+" || "+GE21Ratecut_h+")" )
  1364. #ratehist_h_all_bad = getRateVsEta(L1MuTriggerRate, "ratehist_hybrid_eta%dto%d_frac%d_pt%d_badGE11frac%d"%(int(netas[neta]*10),int(netas[neta+1]*10), fraction, pt, badGE11bending), myetabin, baseratecut + "&& ("+GE11Ratecut_h_bad+" || "+GE21Ratecut_h_bad+")" )
  1365. ratehist_h_all = getRateVsEta(L1MuTriggerRate, "ratehist_hybrid_eta%dto%d_frac%d_pt%d"%(int(netas[neta]*10),int(netas[neta+1]*10), fraction, pt), myetabin, baseratecut2 + "&& "+ GE11Ratecut_h )
  1366. ratehist_h_all_bad = getRateVsEta(L1MuTriggerRate, "ratehist_hybrid_eta%dto%d_frac%d_pt%d_badGE11frac%d"%(int(netas[neta]*10),int(netas[neta+1]*10), fraction, pt, badGE11bending), myetabin, baseratecut2 + "&& ("+GE11Ratecut_h_bad+" || "+GE21Ratecut_h_bad+")" )
  1367. #print "badGE11 cut ", baseratecut + "&& ("+GE11Ratecut_h_bad+" || "+GE21Ratecut_h_bad+")"," bad entries ",ratehist_h_all_bad.GetEntries()," normal cut ", baseratecut + "&& ("+GE11Ratecut_h+" || "+GE21Ratecut_h+")"," normal entries ",ratehist_h_all.GetEntries()
  1368. for npar in allnpar:
  1369. me11 = evenodds[npar].split(',')[0]
  1370. me21 = evenodds[npar].split(',')[1]
  1371. xaxis = "trk_eff_CSC_ME11.dphi_pad_fit_%s"%(me11)
  1372. yaxis = "trk_eff_CSC_ME21.dphi_pad_fit_%s"%(me21)
  1373. #xaxis = "trk_eff_CSC_ME11.dphi_pad_fit_%s"%(me11)
  1374. #yaxis = "trk_eff_CSC_ME21.dphi_pad_fit_%s"%(me21)
  1375. xcut = GE11Cuts[neta][0]
  1376. ycut = GE21Cuts[neta][0]
  1377. if me11 == "even":
  1378. xcut = GE11Cuts[neta][1]
  1379. if me21 == "even":
  1380. ycut = GE21Cuts[neta][1]
  1381. algos_lut = getFinalLUTValue(pt, fraction, etamin, etamax, npar, allLUTfile)
  1382. maxa = algos_lut["Hybrid"][0]
  1383. maxb = algos_lut["Hybrid"][1]
  1384. alpha= algos_lut["Hybrid"][2]
  1385. x0 = algos_lut["Hybrid"][3]
  1386. y0 = algos_lut["Hybrid"][4]
  1387. chambers = "ME1%d %s,ME2%d %s"%(ring, me11, ring, me21)
  1388. st_title = ["Prompt muon, 2<p_{T}<%d"%pt, "Prompt Muon, p_{T}=%d"%pt]
  1389. checkvalue = "&& fabs(%s)<1 && fabs(%s)<1"%(xaxis, yaxis)
  1390. checkx_sh = "&& (trk_eff_CSC_ME11.has_csc_sh&1)>0 && (trk_eff_CSC_ME11.has_gem_sh&1)>0"
  1391. checky_sh = "&& (trk_eff_CSC_ME21.has_csc_sh&1)>0 && (trk_eff_CSC_ME21.has_gem_sh&1)>0"
  1392. if me11 == "even":
  1393. checkx_sh = "&& (trk_eff_CSC_ME11.has_csc_sh&2)>0 && (trk_eff_CSC_ME11.has_gem_sh&2)>0"
  1394. if me21 == "even":
  1395. checky_sh = "&& (trk_eff_CSC_ME21.has_csc_sh&2)>0 && (trk_eff_CSC_ME21.has_gem_sh&2)>0"
  1396.  
  1397. cutsbase = [etacuts + "&& has_tfTrack>0 && has_gmtCand>0 && nstubs>=2 && meRing==%d "%(ring)+checkx_sh+checky_sh, etacuts + "&& has_tfTrack>0 && has_gmtCand && nstubs>=2 && meRing==%d"%(ring)+checkx_sh+checky_sh]
  1398. x_bins = "(400,-0.04,0.04)"
  1399. y_bins = "(300,-0.03,0.03)"
  1400. xtitle = "#Delta#phi_{GEMCSC}^{st1}"
  1401. ytitle = "#Delta#phi_{GEMCSC}^{st2}"
  1402. #ratecut = "maxPromptPt && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && npar_bending==%d && L1Mu_pt>=%f"%(etamin, etamax, npar, pt)
  1403. ratecut = baseratecut+"&& npar_bending==%d"%npar
  1404. text = "#splitline{%s}{%.2f<|#eta|<%.2f, p_{T}^{L1}>%d GeV}"%(chambers, netas[neta],netas[neta+1], pt)
  1405. """
  1406. #should be less than 98%
  1407. #nEvent_list = []
  1408. #nEvent_list.append(rateEvents)
  1409. #anglecut_list = [xcut, ycut]
  1410.  
  1411. #astart = .0001
  1412. #bstart = .0# not used
  1413. #xaxislist = [rate_x, xaxis]
  1414. #yaxislist = [rate_y, yaxis]
  1415. cutslist = [ratecut, cutsbase[1]+"&& pt>=%f"%(pt)+"&& trackpt>=%f"%(pt)]
  1416. #(maxa, maxb, alpha, x0, y0) = loopEllipse(L1MuTriggerRate, GEMCSCTrackCh0, nEvent_list, anglecut_list, fraction, astart, bstart, xaxislist, yaxislist, x_bins, y_bins, xtitle, ytitle, st_title, netas[neta], netas[neta+1], cutslist,text,outputdir1+"GEMCSC_St1St2_hyrid_profile_20170208_pt%d_ptbg%d_fraction%d_st2eta%dto%d_npar%d"%(pt, pt1, fraction, int(netas[neta]*10),int(netas[neta+1]*10), npar))
  1417. #print "max_a ",maxa," maxb ",maxb," alpha ",alpha," x0 ",x0, " y0 ",y0
  1418. #xaxis1 = "(%s*TMath::Cos(%f)*charge+%s*TMath::Sin(%f)*charge-%f)"%(xaxis, alpha, yaxis, alpha, x0)
  1419. #yaxis1 = "(%s*TMath::Sin(%f)*charge-%s*TMath::Cos(%f)*charge-%f)"%(xaxis, alpha, yaxis, alpha, y0)
  1420. """
  1421. xaxis1 = "(%s*TMath::Cos(%f)+%s*TMath::Sin(%f)-%f)"%(xaxis, alpha, yaxis, alpha, x0)
  1422. yaxis1 = "(%s*TMath::Sin(%f)-%s*TMath::Cos(%f)-%f)"%(xaxis, alpha, yaxis, alpha, y0)
  1423. ellipse = "((%s*%s/(%f*%f)+%s*%s/(%f*%f))<=1.0)"%(xaxis1, xaxis1, maxa, maxa, yaxis1, yaxis1, maxb, maxb)
  1424. ellipse_bad = "((%s*%s/(%f*%f)+%s*%s/(%f*%f))<=1.0"%(xaxis1, xaxis1, maxa, maxa, yaxis1, yaxis1, maxb, maxb)+" && rand01_v1>%f)"%badeff
  1425. #ellipse = "(hasME1 && hasME2 && (%s*%s/(%f*%f)+%s*%s/(%f*%f))<=1.0)"%(xaxis1, xaxis1, maxa, maxa, yaxis1, yaxis1, maxb, maxb)
  1426. #ellipse_bad = "(hasME1 && hasME2 &&(%s*%s/(%f*%f)+%s*%s/(%f*%f))<=1.0"%(xaxis1, xaxis1, maxa, maxa, yaxis1, yaxis1, maxb, maxb)+" && rand01_v1>%f)"%badeff
  1427. combinedCut = "L1Mu_pt>=%f"%pt+" && ("+ellipse+" || "+"(abs(%s)<%f && abs(%s)>1)"%(xaxis,xcut,yaxis)+" || "+"(abs(%s)<%f && abs(%s)>1)"%(yaxis,ycut,xaxis)+")"
  1428. finalSignalCut_h = finalSignalCut_h+"|| "+ellipse
  1429. finalSignalCut_h_bad = finalSignalCut_h_bad+"|| "+ellipse_bad
  1430. #Teffs = makeEffplot_v2([GEMCSCTrackCh0], "pt", [cutsbase[0], cutsbase[1]], [combinedCut, combinedCut], netas[neta], netas[neta+1],"true muon p_{T} GeV","bending angle cut efficiency",legs,"GE11-ME11 + GE21-ME21",text,outputdir2+"GEMCSC_St1St2_hybrid_eff_20170208_pt%d_ptbg%d_fraction%d_st2eta%dto%d_npar%d"%(pt, pt1, fraction, int(netas[neta]*10),int(netas[neta+1]*10), npar))
  1431. legs3 = ["GE11-ME11","GE21-ME21","GE11-ME11+GE21-ME21"]
  1432. #makeplots([Teffs_cutx[0], Teffs_cuty[0], Teffs[0]], legs3, text,outputdir2+"GEMCSC_St1St2_combined3_eff_20170208_pt%d_ptbg%d_fraction%d_St2eta%dto%d_npar%d"%(pt, pt1, fraction, int(netas[neta]*10),int(netas[neta+1]*10), npar))
  1433. #LUT.write("eta%dto%dnpar%dfraction%d:(%f,%f,%f,%f,%f)\n"%(int(netas[neta]*10), int(netas[neta+1]*10), npar,fraction,maxa,maxb,alpha, x0, y0))
  1434. xaxis_rate = "(%s*TMath::Cos(%f)+%s*TMath::Sin(%f)-%f)"%(rate_x, alpha, rate_y, alpha, x0)
  1435. yaxis_rate = "(%s*TMath::Sin(%f)-%s*TMath::Cos(%f)-%f)"%(rate_x, alpha, rate_y, alpha, y0)
  1436. ellipse_rate = "CSCTF_dR1<.3 && (%s*%s/(%f*%f)+%s*%s/(%f*%f))<=1.0"%(xaxis_rate, xaxis_rate, maxa, maxa, yaxis_rate, yaxis_rate, maxb, maxb)
  1437. #ratecut_ellipse = ratecut+"&& ("+ellipse_rate+" || (abs(%s)<=%f && abs(%s)>1) "%(rate_x, xcut, rate_y)+"|| (abs(%s)<=%f && abs(%s)>1))"%(rate_y, ycut, rate_x)
  1438. ratecut_ellipse = "npar_bending==%d"%npar +"&& "+ellipse_rate
  1439. ratecut_ellipse_bad = "npar_bending==%d"%npar +"&& "+ellipse_rate+" && RandFloat01>%f"%badeff
  1440. ratehist_h = getRateVsEta(L1MuTriggerRate, "ratehist_hybrid_eta%dto%d_npar%d_frac%d_pt%d"%(int(netas[neta]*10),int(netas[neta+1]*10), npar, fraction, pt), myetabin, baseratecut+ "&& "+ ratecut_ellipse)
  1441. ratehist_h_bad = getRateVsEta(L1MuTriggerRate, "ratehist_hybrid_eta%dto%d_npar%d_frac%d_pt%d_badGE11frac%d"%(int(netas[neta]*10),int(netas[neta+1]*10), npar, fraction, pt, badGE11bending), myetabin, baseratecut+ "&& "+ ratecut_ellipse_bad)
  1442. #print "rate ge11 ",ratehist_st1.GetEntries()," ge21 ",ratehist_st2.GetEntries()," hybrid ",ratehist_h.GetEntries()
  1443. #if npar==0:
  1444. # ratehist_h_all = ratehist_h.Clone()
  1445. #else:
  1446. ratehist_h_all.Add(ratehist_h)
  1447. ratehist_h_all_bad.Add(ratehist_h_bad)
  1448. #print "npar ",npar, " ratehist_h_bad cut ", baseratecut+ "&& "+ ratecut_ellipse_bad," entries now ",ratehist_h_all_bad.GetEntries()," normal entries ", ratehist_h_all.GetEntries()
  1449. #print "npar ",npar, " ratehist_h_bad cut entries ",ratehist_h_all_bad.GetEntries()," normal entries ", ratehist_h_all.GetEntries()
  1450. #ratehist_h.Write()
  1451. #Teffs[0].SetName("hybrideta%dto%dnpar%d"%(int(netas[neta]*10),int(netas[neta+1]*10), npar)+"pt%d"%(pt)+"fraction%d"%fraction)
  1452. #Teffs[0].Write()
  1453. #LUT.write("{%f,%f,%f,%f,%f},\n"%(maxa,maxb,alpha, x0, y0))
  1454. #for item in nEvent_list:
  1455. # LUT_nEvent.write("%f "%item)
  1456. #LUT_nEvent.write("\n")
  1457. #makeplots([Teffs_ddY[0], Teffs_dphi_dir[0], Teffs[0]], legs3, text,outputdir2+"GEMCSC_ctau0andctau1000_combined3_eff_20170120_pt%d_ptbg%d_fraction%d_fractiond%d_St2eta%dto%d_npar%d_dirinterstation%s"%(pt, pt1, fraction, fraction_d, int(netas[neta]*10),int(netas[neta+1]*10), npar, extrapic))
  1458. #Teffallnpars.append(Teffs)
  1459. #LUT.write("},\n")
  1460. #LUT_nEvent.write("},\n")
  1461. #finalSignalCut_h = L1MuQcut+finalSignalCut_h+")"
  1462. #finalSignalCut_h_bad = L1MuQcut+finalSignalCut_h_bad+")"
  1463. #finalSignalCut_h = finalSignalCut_h+") && L1Mu_pt>=%d && L1Mu_quality>=%d && hasME1"%(pt, quality2)
  1464. #finalSignalCut_h_bad = finalSignalCut_h_bad+") && L1Mu_pt>=%d && L1Mu_quality>=%d && hasME1"%(pt, quality2)
  1465. finalSignalCut_h = finalSignalCut_h+") && L1Mu_pt>=%d && L1Mu_quality>=%d"%(pt, quality2)
  1466. finalSignalCut_h_bad = finalSignalCut_h_bad+") && L1Mu_pt>=%d && L1Mu_quality>=%d"%(pt, quality2)
  1467. Teff0_v2 = makeEffplot_v2([GEMCSCTrackCh1], "pt",[basesignalcut],[finalSignalCut_h], netas[neta], netas[neta+1],"true muon p_{T} GeV","bending angle cut efficiency",legs,"GE11-ME11 and GE21-ME21" ,text1,outputdir2+"GEMCSC_hybrid_eff_20170208_pt%d_fraction%d_st2eta%dto%d_all"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10)))
  1468. TeffEta0_v2 = makeEffplot_eta([GEMCSCTrackCh1], "abs(eta)",[basesignalcut+" && pt>=%d"%(pt+5)],[finalSignalCut_h], netas[neta], netas[neta+1],"Simulted |#eta|","bending angle cut efficiency",legs,"GE11-ME11 and GE21-ME21" ,text1,outputdir2+"GEMCSC_hybrid_effvseta_20170208_pt%d_fraction%d_st2eta%dto%d_all"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10)))
  1469. Teff0_bad = makeEffplot_v2([GEMCSCTrackCh1], "pt",[basesignalcut],[finalSignalCut_h_bad], netas[neta], netas[neta+1],"true muon p_{T} GeV","bending angle cut efficiency",legs,"GE11-ME11 and GE21-ME21" ,text1,outputdir2+"GEMCSC_hybrid_eff_20170208_pt%d_fraction%d_st2eta%dto%d_badGE11frac%d_all"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10), badGE11bending))
  1470. TeffEta0_bad = makeEffplot_eta([GEMCSCTrackCh1], "abs(eta)",[basesignalcut+" && pt>=%d"%(pt+5)],[finalSignalCut_h_bad], netas[neta], netas[neta+1],"Simulated |#eta|","bending angle cut efficiency",legs,"GE11-ME11 and GE21-ME21" ,text1,outputdir2+"GEMCSC_hybrid_effvseta_20170208_pt%d_fraction%d_st2eta%dto%d_badGE11frac%d_all"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10), badGE11bending))
  1471. #Teff0 = Teffallnpars[0][0]
  1472. Teff0_h = Teff0_v2[0]
  1473. Teff0_h_bad = Teff0_bad[0]
  1474. #Teff1 = Teffallnpars[0][1]
  1475. Teff0_st1 = Teffallnpars_ME11[0][0]
  1476. Teff0_st1_bad = Teffs_cutx_badeff[0]
  1477. #Teff1_st1 = Teffallnpars_ME11[0][1]
  1478. Teff0_st2 = Teffallnpars_ME21[0][0]
  1479. #Teff1_st2 = Teffallnpars_ME21[0][1]
  1480. Teffeta0_h = TeffEta0_v2[0]
  1481. Teffeta0_h_bad = TeffEta0_bad[0]
  1482. Teffeta0_st1 = TeffsEta_cutx[0]
  1483. Teffeta0_st1_bad = TeffsEta_cutx_badeff[0]
  1484. #for xpar in range(len(Teffallnpars)-1):
  1485. #Teff0.Add(Teffallnpars[xpar+1][0])
  1486. #Teff1.Add(Teffallnpars[xpar+1][1])
  1487. #Teff0_st1.Add(Teffallnpars_ME11[xpar+1][0])
  1488. #Teff1_st1.Add(Teffallnpars_ME11[xpar+1][1])
  1489. #Teff0_st2.Add(Teffallnpars_ME21[xpar+1][0])
  1490. #Teff1_st2.Add(Teffallnpars_ME21[xpar+1][1])
  1491. efflist.append(getOverallEff(Teff0_st1, pt+5))
  1492. efflist.append(getOverallEff(Teff0_h, pt+5))
  1493. efflist.append(getOverallEff(Teff0_st1_bad, pt+5))
  1494. efflist.append(getOverallEff(Teff0_h_bad, pt+5))
  1495. ratelist.append(ratehist_st1.GetEntries())
  1496. ratelist.append(ratehist_h_all.GetEntries())
  1497. ratelist.append(ratehist_st1_bad.GetEntries())
  1498. ratelist.append(ratehist_h_all_bad.GetEntries())
  1499. print "efflist ",efflist, " ratelist ",ratelist
  1500. #print "eff ge11 ",getOverallEff(Teff0_st1, pt), " ge21 ",getOverallEff(Teff0_st2, pt), " hybrid ",getOverallEff(Teff0_v2[0], pt)," badGE11 ",badGE11bending," eff ge11 ",getOverallEff(Teff0_st1_bad, pt)," hybrid ",getOverallEff(Teff0_bad[0], pt)
  1501. #print "rate ge11 ",ratehist_st1.GetEntries()," ge21 ",ratehist_st2.GetEntries()," hybrid ",ratehist_h_all.GetEntries()," badGE11 case, ge11 rate ",ratehist_st1_bad.GetEntries(), " hybrid ",ratehist_h_all_bad.GetEntries()
  1502. #GE11eta16to21npar2pt5fraction95;1
  1503. Teff0_h.SetName("hybrideta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"pt%dfraction%d"%(pt,fraction))
  1504. Teffeta0_h.SetName("hybrideta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"pt%dfraction%dvseta"%(pt,fraction))
  1505. Teff0_h_bad.SetName("hybrideta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"pt%dfraction%dbadGE11frac%d"%(pt,fraction, badGE11bending))
  1506. Teffeta0_h_bad.SetName("hybrideta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"pt%dfraction%dbadGE11frac%dvseta"%(pt,fraction, badGE11bending))
  1507. #Teff1.SetName("hybrideta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"Singalpt%dptbg%d"%(pt,pt1))
  1508. Teff0_st1.SetName("GE11eta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"pt%dfraction%d"%(pt,fraction))
  1509. Teffeta0_st1.SetName("GE11eta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"pt%dfraction%dvseta"%(pt,fraction))
  1510. Teff0_st1_bad.SetName("GE11eta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"pt%dfraction%dbadGE11frac%d"%(pt,fraction, badGE11bending))
  1511. Teffeta0_st1_bad.SetName("GE11eta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"pt%dfraction%dbadGE11frac%dvseta"%(pt,fraction, badGE11bending))
  1512.  
  1513. #Teff1_st1.SetName("ME11eta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"Singalpt%dptbg%d"%(pt,pt1))
  1514. Teff0_st2.SetName("GE21eta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"pt%dfraction%d"%(pt,fraction))
  1515. #Teff0_st2.SetName("GE21eta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"pt%dfraction%d"%(pt,fraction))
  1516. #TeffsEta_cuty[0].SetName("GE21eta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"pt%dfraction%dvseta"%(pt,fraction))
  1517. #Teff1_st2.SetName("ME21eta%dto%d"%(int(netas[neta]*10),int(netas[neta+1]*10))+"Singalpt%dptbg%d"%(pt,pt1))
  1518. text_h = "#splitline{GE11-ME11+GE21-ME21}{%.2f<|#eta|<%.2f, p_{T}^{L1}>%d GeV%s}"%(netas[neta],netas[neta+1], pt, extratxt)
  1519. text_ME11 = "#splitline{GE11-ME11}{%.2f<|#eta|<%.2f, p_{T}^{L1}>%d GeV%s}"%(netas[neta],netas[neta+1], pt, extratxt)
  1520. text_ME21 = "#splitline{GE21-ME21}{%.2f<|#eta|<%.2f, p_{T}^{L1}>%d GeV%s}"%(netas[neta],netas[neta+1], pt, extratxt)
  1521. #makeplots([Teff0, Teff1], legs, text_h,outputdir2+"GEMCSC_hybrid_eff_20170120_pt%d_ptbg%d_fraction%d_fractiond%d_St2eta%dto%d_allnpar_dirinterstation%s"%(pt, pt1, fraction, fraction_d, int(netas[neta]*10),int(netas[neta+1]*10), extrapic))
  1522. #makeplots([Teff0_st1, Teff1_st1], legs, text_ME11,outputdir2+"GEMCSC_GE11ME11_eff_20170120_pt%d_fraction%d_St2eta%dto%d_allnpar_dirinterstation%s"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10), extrapic))
  1523. #makeplots([Teff0_st1, Teff1_st2], legs, text_ME21,outputdir2+"GEMCSC_GE21ME21_eff_20170120_pt%d_fraction%d_St2eta%dto%d_allnpar%s"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10), extrapic))
  1524. #text3 = "#splitline{%.2f<|#eta|<%.2f, p_{T}^{L1}>%d GeV%s}{Prompt muon}"%(netas[neta],netas[neta+1], pt, extratxt)
  1525. text3 = "%.2f<|#eta|<%.2f, p_{T}^{L1}>%d GeV%s"%(netas[neta],netas[neta+1], pt, extratxt)
  1526. makeplots([Teff0_st1, Teff0_st2, Teff0_v2[0]], legs3, text3,outputdir2+"GEMCSC_GE11ME11_GE21ME21_combined3_eff_20170120_pt%d_fraction%d_St2eta%dto%d_allnpar%s"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10), extrapic))
  1527. legs4 = ["YE11 bending angle cut","Combined cut with YE11 and YE21 bending", "YE11 bending angle cut+20% CSC aging", "#splitline{Combined cut with YE11 and YE21 bending}{+20% CSC aging}"]
  1528. makeplots([Teff0_st1, Teff0_h, Teff0_st1_bad, Teff0_h_bad], legs4, text3,outputdir2+"GEMCSC_GE11ME11_GE21ME21_combined3_eff_20170120_pt%d_fraction%d_St2eta%dto%d_allnpar_badGE11frac%d%s"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10), badGE11bending, extrapic))
  1529. text4 = "p_{T}^{L1}>%d GeV%s"%(pt, extratxt)
  1530. #plotshistograms([ratehist_CSC, ratehist_st1, ratehist_h_all], legsall, "L1Mu with Q>=12", text4, outputdir2+"TriggerRate_combiend_20170131_pt%d_fraction%d_St2eta%dto%d_allnpar"%(pt, fraction, int(etamin*10),int(etamax*10)))
  1531. #ratehist_csc_list.append(ratehist_CSC);
  1532. ratehist_st1_list.append(ratehist_st1); ratehist_h_list.append(ratehist_h_all)
  1533.  
  1534.  
  1535. etamin = netas[0]; etamax = netas[-1]
  1536. alletacut = "abs(eta)<%f && abs(eta)>%f"%(etamax, etamin)
  1537. #dencut = alletacut + "&& trk_eff_CSC_ME11.has_csc_sh>0 && trk_eff_CSC_ME21.has_csc_sh>0 && trk_eff_CSC_ME11.has_gem_sh>0 && trk_eff_CSC_ME21.has_gem_sh>0"
  1538. numcut = "has_tfTrack>0 && has_gmtCand>0 && nstubs>=2"
  1539.  
  1540. legs = ["GE11only","GE11GE21"]
  1541. L1MuEff = makeEffplot_v2([GEMCSCTrackCh0, GEMCSCTrackCh1], "pt",[alletacut, alletacut],[numcut, numcut], etamin, etamax, "true muon p_{T} GeV","bending angle cut efficiency",legs,"GE11-ME11 and GE21-ME21" ,text1,outputdir2+"GEMCSC_L1Mu_eff_20170208_pt%d_fraction%d_st2eta%dto%d_all"%(pt, fraction, int(etamin*10),int(etamax*10)))
  1542. L1MuEffeta = makeEffplot_eta([GEMCSCTrackCh0, GEMCSCTrackCh1], "abs(eta)",[alletacut+"&& pt>%d"%(pt+5), alletacut+"&& pt>%d"%(pt+5)],[numcut, numcut], etamin, etamax, "true muon p_{T} GeV","bending angle cut efficiency",legs,"GE11-ME11 and GE21-ME21" ,text1,outputdir2+"GEMCSC_L1Mu_etaeff_20170208_pt%d_fraction%d_st2eta%dto%d_all"%(pt, fraction, int(etamin*10),int(etamax*10)))
  1543. ratehist_st1.Scale(SF); ratehist_h_all.Scale(SF); ratehist_st1_bad.Scale(SF); ratehist_h_all_bad.Scale(SF)
  1544. plotshistograms([ratehist_st1, ratehist_h_all, ratehist_st1_bad, ratehist_h_all_bad], legs4, "L1Mu with hits in ME11", text3, outputdir2+"TriggerRate_combiend_20170120_pt%d_fraction%d_St2eta%dto%d_allnpar_badGE11frac%d%s"%(pt, fraction, int(etamin*10),int(etamax*10), badGE11bending, extrapic))
  1545. makeplotsEta([Teffeta0_st1, Teffeta0_h, Teffeta0_st1_bad, Teffeta0_h_bad], legs4, " ", "p_{T}^{sim}>%d GeV"%(pt+5), outputdir2+"TriggerEff_eta_eta164_215_GE11GE21_GE11GE21_combined")
  1546.  
  1547. legs4_v2 = ["L1Mu w/ GE21 (inputs to L1Trk+L1Mu)","L1Mu w/o GE21","L1Mu w/ GE21, hits in ME11, p_{T}^{L1}>=%d GeV (Standalone L1Mu)"%(pt),"L1Mu w/o GE21, hits in ME11, p_{T}^{L1}>=%d GeV (Standalone L1Mu)"%(pt)]
  1548. makeplots([L1MuEff[1], L1MuEff[0], Teff0_h, Teff0_st1], legs4_v2, text3, outputdir2+"GEMCSC_TriggerEff_pt%d_fraction%d_St2eta%dto%d_allnpar_badGE11frac%d_L1Mu%s"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10), badGE11bending, extrapic))
  1549. makeplotsEta([L1MuEffeta[1],L1MuEffeta[0], Teffeta0_h, Teffeta0_st1], legs4_v2, " ", "p_{T}^{sim}>%d GeV"%(pt+5), outputdir2+"GEMCSC_TriggerEtaEff_pt%d_fraction%d_St2eta%dto%d_allnpar_badGE11frac%d_L1Mu%s"%(pt, fraction, int(netas[neta]*10),int(netas[neta+1]*10), badGE11bending, extrapic))
  1550. #plotTeffs([triggereff1, triggereff3, triggereff1_GE11GE21, triggereff3_GE11GE21], legs, legheader, "Simulated p_{T} [GeV]", "Trigger efficiency", "%.2f<|#eta|<%.2f"%(etamin, etamax), SBPlots, "TriggerEff_eta_eta164_215_nstubs2_GE11GE21_combined")
  1551.  
  1552. #Teffs_0.append(Teff0)
  1553. #Teffs_0_ME21.append(Teff0_st2)
  1554. #Teffs_0_ME11.append(Teff0_st1)
  1555. Teff0_h.Write();Teff0_st1.Write();Teff0_st2.Write()
  1556. Teff0_h_bad.Write();Teff0_st1_bad.Write()
  1557. Teffeta0_h.Write();Teffeta0_st1.Write();Teffeta0_h_bad.Write();Teffeta0_st1_bad.Write()
  1558. ratehist_h_all.Write(); ratehist_st1.Write(); ratehist_st2.Write()
  1559. ratehist_h_all_bad.Write(); ratehist_st1_bad.Write()
  1560. """
  1561. #Teffs_1.append(Teff1)
  1562. Teffs0_alleta = Teffs_0[0]
  1563. Teffs0_alleta_st1 = Teffs_0_ME11[0]
  1564. Teffs0_alleta_st2 = Teffs_0_ME21[0]
  1565. #Teffs1_alleta = Teffs_1[0]
  1566. for xeta in range(len(Teffs_0)-1):
  1567. Teffs0_alleta.Add(Teffs_0[xeta+1])
  1568. Teffs0_alleta_st1.Add(Teffs_0_ME11[xeta+1])
  1569. Teffs0_alleta_st2.Add(Teffs_0_ME21[xeta+1])
  1570. #Teffs1_alleta.Add(Teffs_1[xeta+1])
  1571. Teffs0_alleta.SetName("hybrideta%dto%d"%(int(netas[0]*10),int(netas[-1]*10))+"BGt%dptbg%d"%(pt,pt1))
  1572. Teffs0_alleta_st1.SetName("ME11eta%dto%d"%(int(netas[0]*10),int(netas[-1]*10))+"BGpt%d"%(pt))
  1573. Teffs0_alleta_st2.SetName("ME21eta%dto%d"%(int(netas[0]*10),int(netas[-1]*10))+"BGpt%d"%(pt))
  1574. #Teffs1_alleta.SetName("hybrideta%dto%d"%(int(netas[0]*10),int(netas[-1]*10))+"Singalpt%dptbg%d"%(pt,pt1))
  1575. text_alleta = "#splitline{Hybrid algorithm}{%.1f<|#eta|<%.1f, p_{T}^{L1}>%d GeV%s}"%(netas[0],netas[-1], pt, extratxt)
  1576. text_alleta_3 = "#splitline{%.1f<|#eta|<%.1f, p_{T}^{L1}>%d GeV%s}{Prompt muon}"%(netas[0],netas[-1], pt, extratxt)
  1577. #makeplots([Teffs0_alleta, Teffs1_alleta], legs, text_alleta,outputdir2+"GEMCSC_GE11ME21_GE21ME21_hybrid_eff_20170120_pt%d_ptbg%d_fraction%d_fractiond%d_St2eta%dto%d_allnpar_dirinterstation%s"%(pt, pt1, fraction,fraction_d, int(netas[0]*10),int(netas[-1]*10), extrapic))
  1578. makeplots([Teffs0_alleta_st1, Teffs0_alleta_st2, Teffs0_alleta], legs3, text_alleta_3,outputdir2+"GEMCSC_GE11ME11_GE21ME21_combined3_eff_20170120_pt%d_ptbg%d_fraction%d_St2eta%dto%d_allnpar_dirinterstation%s"%(pt, pt1, fraction, int(netas[0]*10),int(netas[-1]*10), extrapic))
  1579. """
  1580. Teff_out.Close()
  1581. return efflist,ratelist
  1582. def plotall(pts, fractions, netas,outputrootfile, badGE11=0):
  1583. pt1 = 0
  1584. fraction_rate = 98
  1585. hrate_template = ROOT.TH1F("hrate_ge11","hrate_ge11",len(rateptbin)-1, myrateptbin)
  1586. hrate_ge11 = ROOT.TH1F("hrate_ge11","hrate_ge11",len(rateptbin)-1, myrateptbin)
  1587. hrate_h = ROOT.TH1F("hrate_h","hrate_h",len(rateptbin)-1, myrateptbin)
  1588. hrate_ge11_bad = ROOT.TH1F("hrate_ge11_bad","hrate_ge21_bad",len(rateptbin)-1, myrateptbin)
  1589. hrate_h_bad = ROOT.TH1F("hrate_h_bad","hrate_h_bad",len(rateptbin)-1, myrateptbin)
  1590. etamin = netas[0]
  1591. etamax = netas[-1]
  1592. for pt in pts:
  1593. ratelist_ge11 = []
  1594. rateErrlist_ge11 = []
  1595. ratelist_ge11_bad = []
  1596. rateErrlist_ge11_bad = []
  1597. ratelist_h = []
  1598. rateErrlist_h = []
  1599. ratelist_h_bad = []
  1600. rateErrlist_h_bad = []
  1601. efflist_ge11 = []
  1602. effErrlist_ge11 = []
  1603. efflist_ge11_bad = []
  1604. effErrlist_ge11_bad = []
  1605. efflist_h = []
  1606. effErrlist_h = []
  1607. efflist_h_bad = []
  1608. effErrlist_h_bad = []
  1609. for frac in fractions:
  1610. efflist, ratelist = plotalleta(pt, pt1, netas, frac, outputrootfile, badGE11)
  1611. if frac==fraction_rate:
  1612. hrate_ge11.Fill(pt, ratelist[0]*SF)
  1613. hrate_h.Fill(pt, ratelist[1]*SF)
  1614. hrate_ge11_bad.Fill(pt, ratelist[2]*SF)
  1615. hrate_h_bad.Fill(pt, ratelist[3]*SF)
  1616. ratelist_ge11.append(ratelist[0]*SF)
  1617. rateErrlist_ge11.append(sqrt(ratelist[0])*SF)
  1618. ratelist_h.append(ratelist[1]*SF)
  1619. rateErrlist_h.append(sqrt(ratelist[1])*SF)
  1620. ratelist_ge11_bad.append(ratelist[2]*SF)
  1621. rateErrlist_ge11_bad.append(sqrt(ratelist[2])*SF)
  1622. ratelist_h_bad.append(ratelist[3]*SF)
  1623. rateErrlist_h_bad.append(sqrt(ratelist[3])*SF)
  1624. efflist_ge11.append(efflist[0][0])
  1625. effErrlist_ge11.append(efflist[0][1])
  1626. efflist_h.append(efflist[1][0])
  1627. effErrlist_h.append(efflist[1][1])
  1628. efflist_ge11_bad.append(efflist[2][0])
  1629. effErrlist_ge11_bad.append(efflist[2][1])
  1630. efflist_h_bad.append(efflist[3][0])
  1631. effErrlist_h_bad.append(efflist[3][1])
  1632. Teff_out = ROOT.TFile(outputrootfile,"UPDATE")
  1633. graph_ge11 = TGraphErrors(len(efflist_ge11), np.array(efflist_ge11), np.array(ratelist_ge11), np.array(effErrlist_ge11), np.array(rateErrlist_ge11))
  1634. graph_h = TGraphErrors(len(efflist_h), np.array(efflist_h), np.array(ratelist_h), np.array(effErrlist_h), np.array(rateErrlist_h))
  1635. graph_ge11_bad = TGraphErrors(len(efflist_ge11_bad), np.array(efflist_ge11_bad), np.array(ratelist_ge11_bad), np.array(effErrlist_ge11_bad), np.array(rateErrlist_ge11_bad))
  1636. graph_h_bad = TGraphErrors(len(efflist_h_bad), np.array(efflist_h_bad), np.array(ratelist_h_bad), np.array(effErrlist_h_bad), np.array(rateErrlist_h_bad))
  1637. legend = TLegend(0.15,0.65,0.60,0.90)
  1638. legend.SetHeader("L1Mu with Q>=4")
  1639. legend.SetFillColor(ROOT.kWhite)
  1640. legend.SetTextFont(42)
  1641. tex = TLatex(0.15,.55, "%.2f<|#eta|<%.2f, p_{T}^{L1}>%d GeV"%(etamin, etamax, pt))
  1642. tex.SetNDC()
  1643. #legend.SetTextSize(.05)
  1644. c1 = TCanvas()
  1645. mgerr =TMultiGraph()
  1646. #print "size ", len(efflist_p[npar]), " ",efflist_p[npar]
  1647. graph_ge11.SetMarkerStyle(maker[0])
  1648. graph_ge11.SetMarkerColor(color[0])
  1649. graph_ge11.SetLineColor(color[0])
  1650. graph_ge11.SetFillColor(color[0])
  1651. graph_h.SetMarkerStyle(maker[1])
  1652. graph_h.SetMarkerColor(color[1])
  1653. graph_h.SetLineColor(color[1])
  1654. graph_h.SetFillColor(color[1])
  1655. graph_ge11_bad.SetMarkerStyle(maker[2])
  1656. graph_ge11_bad.SetMarkerColor(color[2])
  1657. graph_ge11_bad.SetLineColor(color[2])
  1658. graph_ge11_bad.SetFillColor(color[2])
  1659. graph_h_bad.SetMarkerStyle(maker[3])
  1660. graph_h_bad.SetMarkerColor(color[3])
  1661. graph_h_bad.SetLineColor(color[3])
  1662. graph_h_bad.SetFillColor(color[3])
  1663. mgerr.Add(graph_ge11)
  1664. mgerr.Add(graph_h)
  1665. mgerr.Add(graph_ge11_bad)
  1666. mgerr.Add(graph_h_bad)
  1667. graph_ge11.SetName("TriggerEffVsRate_GE11Cut_pt%d_eta%dto%d"%(pt,int(etamin*10), int(etamax*10)))
  1668. graph_h.SetName("TriggerEffVsRate_hybrid_pt%d_eta%dto%d"%(pt,int(etamin*10), int(etamax*10)))
  1669. graph_ge11_bad.SetName("TriggerEffVsRate_GE11Cut_pt%d_eta%dto%d_badGE11"%(pt,int(etamin*10), int(etamax*10)))
  1670. graph_h_bad.SetName("TriggerEffVsRate_hybrid_pt%d_eta%dto%d_badGE11"%(pt,int(etamin*10), int(etamax*10)))
  1671. graph_ge11.Write()
  1672. graph_h.Write()
  1673. graph_ge11_bad.Write()
  1674. graph_h_bad.Write()
  1675. legend.AddEntry(graph_ge11,"YE11 bending angle cut", "pl")
  1676. legend.AddEntry(graph_h,"Combined bending angle cut", "pl")
  1677. legend.AddEntry(graph_ge11_bad,"YE11 bending angle cut+20% CSC aging", "pl")
  1678. legend.AddEntry(graph_h_bad,"#splitline{Combined bending angle cut}{+20% CSC aging}", "pl")
  1679.  
  1680. mgerr.Draw("AP")
  1681. legend.Draw("same")
  1682. tex.Draw("same")
  1683. mgerr.SetMinimum(0.)
  1684. mgerr.SetTitle(" #scale[1.4]{#font[61]{CMS}} #font[52]{Simulation preliminary}"+" "*10+" 14 TeV, 200 PU")
  1685. mgerr.GetXaxis().SetTitle("Trigger efficiency")
  1686. mgerr.GetYaxis().SetTitle("Trigger rate [kHz]")
  1687. mgerr.SetName("TriggerEffVsRate_all_pt%d_eta%dto%d"%(pt,int(etamin*10), int(etamax*10)))
  1688. mgerr.Write()
  1689. c1.SaveAs(outputdir2+"TriggerEffVsRate_GEMCSCBending_pt%d_eta%dto%d_PU%d.png"%(pt,int(etamin*10), int(etamax*10), pu))
  1690. c1.SaveAs(outputdir2+"TriggerEffVsRate_GEMCSCBending_pt%d_eta%dto%d_PU%d.pdf"%(pt,int(etamin*10), int(etamax*10), pu))
  1691. c1.SaveAs(outputdir2+"TriggerEffVsRate_GEMCSCBending_pt%d_eta%dto%d_PU%d.C"%(pt,int(etamin*10), int(etamax*10), pu))
  1692. Teff_out.Close()
  1693. Teff_out = ROOT.TFile(outputrootfile,"UPDATE")
  1694. c2 = TCanvas()
  1695. legend2 = TLegend(0.4,0.7,0.90,0.85)
  1696. legend2.SetFillColor(ROOT.kWhite)
  1697. legend2.SetTextFont(42)
  1698. tex2 = TLatex(0.2,.88, "%.2f<|#eta|<%.2f, L1Mu with Q>=4"%(etamin, etamax))
  1699. tex2.SetNDC()
  1700. hrate_ge11.Sumw2(False)
  1701. hrate_h.Sumw2(False)
  1702. hrate_ge11_bad.Sumw2(False)
  1703. hrate_h_bad.Sumw2(False)
  1704. c2.SetLogy()
  1705. #c2.SetLogx()
  1706. c2.SetGridx()
  1707. c2.SetGridy()
  1708. hrate_template.SetMinimum(.2)
  1709. hrate_template.SetMaximum(2000)
  1710. hrate_template.SetTitle(" #scale[1.4]{#font[61]{CMS}} #font[52]{Simulation preliminary}"+" "*10+" 14 TeV, 200 PU")
  1711. hrate_template.GetXaxis().SetTitle("L1Mu p_{T} [GeV]")
  1712. hrate_template.GetYaxis().SetTitle("Trigger rate [kHz]")
  1713. hrate_ge11.SetMarkerStyle(maker[0])
  1714. hrate_ge11.SetMarkerColor(color[0])
  1715. hrate_ge11.SetLineColor(color[0])
  1716. hrate_ge11.SetFillColor(color[0])
  1717. hrate_h.SetMarkerStyle(maker[1])
  1718. hrate_h.SetMarkerColor(color[1])
  1719. hrate_h.SetLineColor(color[1])
  1720. hrate_h.SetFillColor(color[1])
  1721. hrate_ge11_bad.SetMarkerStyle(maker[2])
  1722. hrate_ge11_bad.SetMarkerColor(color[2])
  1723. hrate_ge11_bad.SetLineColor(color[2])
  1724. hrate_ge11_bad.SetFillColor(color[2])
  1725. hrate_h_bad.SetMarkerStyle(maker[3])
  1726. hrate_h_bad.SetMarkerColor(color[3])
  1727. hrate_h_bad.SetLineColor(color[3])
  1728. hrate_h_bad.SetFillColor(color[3])
  1729. legend2.AddEntry(hrate_ge11,"YE11 bending angle cut", "pl")
  1730. legend2.AddEntry(hrate_h,"Combined bending angle cut", "pl")
  1731. legend2.AddEntry(hrate_ge11_bad,"YE11 bending angle cut+20% CSC aging", "pl")
  1732. legend2.AddEntry(hrate_h_bad,"#splitline{Combined bending angle cut}{+20% CSC aging}", "pl")
  1733. hrate_template.Draw()
  1734. hrate_ge11.Draw("samee")
  1735. hrate_h.Draw("samee")
  1736. hrate_ge11_bad.Draw("samee")
  1737. hrate_h_bad.Draw("samee")
  1738. legend2.Draw("same")
  1739. tex2.Draw("same")
  1740. hrate_template.Write()
  1741. hrate_ge11.Write()
  1742. hrate_h.Write()
  1743. hrate_ge11_bad.Write()
  1744. hrate_h_bad.Write()
  1745.  
  1746. c2.SaveAs(outputdir2+"TriggerRate_q4_eta%dto%d_PU%d_Eff%d.png"%(int(etamin*10), int(etamax*10), pu, fraction_rate))
  1747. c2.SaveAs(outputdir2+"TriggerRate_q4_eta%dto%d_PU%d_Eff%d.pdf"%(int(etamin*10), int(etamax*10), pu, fraction_rate))
  1748. c2.SaveAs(outputdir2+"TriggerRate_q4_eta%dto%d_PU%d_Eff%d.C"%(int(etamin*10), int(etamax*10), pu, fraction_rate))
  1749. Teff_out.Close()
  1750.  
  1751.  
  1752. def getTriggerRateVsPt(pts, fractions_rate, netas,outputrootfile, badGE11=0):
  1753. pt1 = 0
  1754. hrate_template = ROOT.TH1F("hrate_ge11","hrate_ge11",len(rateptbin)-1, myrateptbin)
  1755. hrate_ge11 = ROOT.TH1F("hrate_ge11","hrate_ge11",len(rateptbin)-1, myrateptbin)
  1756. hrate_h = ROOT.TH1F("hrate_h","hrate_h",len(rateptbin)-1, myrateptbin)
  1757. hrate_ge11_bad = ROOT.TH1F("hrate_ge11_bad","hrate_ge21_bad",len(rateptbin)-1, myrateptbin)
  1758. hrate_h_bad = ROOT.TH1F("hrate_h_bad","hrate_h_bad",len(rateptbin)-1, myrateptbin)
  1759. hrate_Q1 = ROOT.TH1F("hrate_Q1","hrate_Q1",len(rateptbin)-1, myrateptbin)
  1760. hrate_Q2 = ROOT.TH1F("hrate_Q2","hrate_Q2",len(rateptbin)-1, myrateptbin)
  1761. etamin = netas[0]
  1762. etamax = netas[-1]
  1763. legsall = ["CSC only","CSC + GE11"," CSC + GE11 + GE21"]
  1764. quality1 = 4; quality2 = 12
  1765. ratefile = TFile(ratesample)
  1766. h_total = ratefile.Get("h_eventcountME0Segment192")
  1767. #h_total.Print()
  1768. rateEvents = h_total.GetEntries()
  1769. L1MuTriggerRate = TChain("L1MuTriggerRateME0Segment192")
  1770. addFilesToChain(L1MuTriggerRate, ratesample)
  1771.  
  1772. for pt in pts:
  1773. baseratecut1 = "maxPromptPt && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && L1Mu_pt>=%f"%(etamin, etamax,quality1, pt)
  1774. baseratecut2 = "maxPromptPt && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && L1Mu_pt>=%f"%(etamin, etamax,quality2, pt)
  1775. ratehist_Q1 = getRateVsEta(L1MuTriggerRate, "ratehist_Q1", myetabin, baseratecut1)
  1776. ratehist_Q2 = getRateVsEta(L1MuTriggerRate, "ratehist_Q1", myetabin, baseratecut2)
  1777. efflist1, ratelist1 = plotalleta(pt, pt1, netas, fractions_rate[0], outputrootfile, badGE11)
  1778. efflist2, ratelist2 = plotalleta(pt, pt1, netas, fractions_rate[1], outputrootfile, badGE11)
  1779. efflist3, ratelist3 = plotalleta(pt, pt1, netas, fractions_rate[2], outputrootfile, badGE11)
  1780. efflist4, ratelist4 = plotalleta(pt, pt1, netas, fractions_rate[3], outputrootfile, badGE11)
  1781.  
  1782. hrate_ge11.Fill(pt,ratelist1[0]*SF)
  1783. hrate_h.Fill(pt, ratelist2[1]*SF)
  1784. hrate_ge11_bad.Fill(pt, ratelist3[2]*SF)
  1785. hrate_h_bad.Fill(pt, ratelist4[3]*SF)
  1786. hrate_Q1.Fill(pt, ratehist_Q1.GetEntries()*SF)
  1787. hrate_Q2.Fill(pt, ratehist_Q2.GetEntries()*SF)
  1788. #ratehist_CSC = ratehist_cscs_1[0]; ratehist_st1 = ratehist_st1s_1[0]; ratehist_h_all = ratehist_hs_2[0]
  1789. #ratehist_CSC.Scale(SF); ratehist_st1.Scale(SF); ratehist_h_all(SF)
  1790. #text4 = "p_{T}^{L1} >%d GeV"%(pt)
  1791. #plotshistograms([ratehist_CSC, ratehist_st1, ratehist_h_all], legsall, "L1Mu with Q>=12", text4, outputdir2+"TriggerRate_combiend_20170131_pt%d_St2eta%dto%d_allnpar"%(pt, int(etamin*10),int(etamax*10)))
  1792. Teff_out = ROOT.TFile(outputrootfile,"UPDATE")
  1793. c2 = TCanvas()
  1794. legend2 = TLegend(0.4,0.6,0.90,0.85)
  1795. legend2.SetHeader("L1Mu with Q>=4")
  1796. legend2.SetFillColor(ROOT.kWhite)
  1797. legend2.SetTextFont(42)
  1798. tex2 = TLatex(0.2,.2, "%.2f<|#eta|<%.2f"%(etamin, etamax))
  1799. tex2.SetNDC()
  1800. hrate_ge11.Sumw2(False)
  1801. hrate_h.Sumw2(False)
  1802. hrate_ge11_bad.Sumw2(False)
  1803. hrate_h_bad.Sumw2(False)
  1804. c2.SetLogy()
  1805. #c2.SetLogx()
  1806. c2.SetGridx()
  1807. c2.SetGridy()
  1808. hrate_template.SetMinimum(.2)
  1809. hrate_template.SetMaximum(2000)
  1810. hrate_template.SetTitle(" #scale[1.4]{#font[61]{CMS}} #font[52]{Simulation preliminary}"+" "*10+" 14 TeV, 200 PU")
  1811. hrate_template.GetXaxis().SetTitle("L1Mu p_{T} [GeV]")
  1812. hrate_template.GetYaxis().SetTitle("Trigger rate [kHz]")
  1813. hrate_ge11.SetMarkerStyle(maker[0])
  1814. hrate_ge11.SetMarkerColor(color[0])
  1815. hrate_ge11.SetLineColor(color[0])
  1816. hrate_ge11.SetFillColor(color[0])
  1817. hrate_h.SetMarkerStyle(maker[1])
  1818. hrate_h.SetMarkerColor(color[1])
  1819. hrate_h.SetLineColor(color[1])
  1820. hrate_h.SetFillColor(color[1])
  1821. hrate_ge11_bad.SetMarkerStyle(maker[2])
  1822. hrate_ge11_bad.SetMarkerColor(color[2])
  1823. hrate_ge11_bad.SetLineColor(color[2])
  1824. hrate_ge11_bad.SetFillColor(color[2])
  1825. hrate_h_bad.SetMarkerStyle(maker[3])
  1826. hrate_h_bad.SetMarkerColor(color[3])
  1827. hrate_h_bad.SetLineColor(color[3])
  1828. hrate_h_bad.SetFillColor(color[3])
  1829. legend2.AddEntry(hrate_ge11,"YE11 bending angle cut", "pl")
  1830. legend2.AddEntry(hrate_h,"Combined bending angle cut", "pl")
  1831. legend2.AddEntry(hrate_ge11_bad,"YE11 bending angle cut+20% CSC aging", "pl")
  1832. legend2.AddEntry(hrate_h_bad,"#splitline{Combined bending angle cut}{+20% CSC aging}", "pl")
  1833. hrate_template.Draw()
  1834. hrate_ge11.Draw("samee")
  1835. hrate_h.Draw("samee")
  1836. hrate_ge11_bad.Draw("samee")
  1837. hrate_h_bad.Draw("samee")
  1838. legend2.Draw("same")
  1839. tex2.Draw("same")
  1840. hrate_template.Write()
  1841. hrate_ge11.Write()
  1842. hrate_h.Write()
  1843.  
  1844. c2.SaveAs(outputdir2+"TriggerRate_q4_eta%dto%d_PU%d_Eff%d.png"%(int(etamin*10), int(etamax*10), pu, fractions_rate[0]))
  1845. c2.SaveAs(outputdir2+"TriggerRate_q4_eta%dto%d_PU%d_Eff%d.pdf"%(int(etamin*10), int(etamax*10), pu, fractions_rate[0]))
  1846. c2.SaveAs(outputdir2+"TriggerRate_q4_eta%dto%d_PU%d_Eff%d.C"%(int(etamin*10), int(etamax*10), pu, fractions_rate[0]))
  1847. hrate_Q1.SetMarkerStyle(maker[2])
  1848. hrate_Q1.SetMarkerColor(color[2])
  1849. hrate_Q1.SetLineColor(color[2])
  1850. hrate_Q2.SetMarkerStyle(maker[3])
  1851. hrate_Q2.SetMarkerColor(color[3])
  1852. hrate_Q2.SetLineColor(color[3])
  1853. c3 = TCanvas()
  1854. legend3 = TLegend(0.4,0.6,0.90,0.85)
  1855. legend3.SetHeader("L1Mu ")
  1856. legend3.SetFillColor(ROOT.kWhite)
  1857. legend3.SetTextFont(42)
  1858. hrate_Q1.Sumw2(False)
  1859. hrate_Q2.Sumw2(False)
  1860. hrate_template.SetMinimum(.2)
  1861. hrate_template.SetMaximum(2000)
  1862. c3.SetLogy()
  1863. #c2.SetLogx()
  1864. c3.SetGridx()
  1865. c3.SetGridy()
  1866. legend3.AddEntry(hrate_Q1,"CSC only: EMTFQ>=4", "pl")
  1867. legend3.AddEntry(hrate_ge11,"CSC+GE11: EMTFQ>=4", "pl")
  1868. legend3.AddEntry(hrate_h,"CSC+GE11+GE21: EMTFQ>=4", "pl")
  1869. legend3.AddEntry(hrate_Q2,"CSC only: EMTFQ>=12", "pl")
  1870. hrate_template.Draw()
  1871. hrate_Q1.Draw("samee")
  1872. hrate_ge11.Draw("samee")
  1873. hrate_h.Draw("samee")
  1874. hrate_Q2.Draw("samee")
  1875. legend3.Draw("same")
  1876. c3.SaveAs(outputdir2+"TriggerRate_q4_eta%dto%d_PU%d_Eff%d_addCSC.png"%(int(etamin*10), int(etamax*10), pu, fractions_rate[0]))
  1877. c3.SaveAs(outputdir2+"TriggerRate_q4_eta%dto%d_PU%d_Eff%d_addCSC.pdf"%(int(etamin*10), int(etamax*10), pu, fractions_rate[0]))
  1878. c3.SaveAs(outputdir2+"TriggerRate_q4_eta%dto%d_PU%d_Eff%d_addCSC.C"%(int(etamin*10), int(etamax*10), pu, fractions_rate[0]))
  1879.  
  1880.  
  1881.  
  1882. Teff_out.Close()
  1883.  
  1884. #1. CSC+GE11+GE21+ME0, L1Mu+L1Tkr
  1885. #2. CSC+GE11, L1Mu+L1Tkr
  1886. #3. CSC only EMTFQ>=12
  1887. #4. CSC+GE11+GE21+ME0: EMTFQ>=4+ has hits in ME11 + bending angl cut
  1888. #5. CSC+GE11: EMTFQ>=4+has hits in ME11 + bending angle cut
  1889. def getallTriggerRateEffVsEta(outputrootfile, fractions, pt, netas):
  1890.  
  1891. L1MuTriggerRate = TChain("L1MuTriggerRateME0Segment192")
  1892. addFilesToChain(L1MuTriggerRate, ratesample)
  1893. #ME0dphi:10->0.005, 16: 0.004
  1894. ME0dPhifile = "ME0DPhiLUT.log"
  1895. ME0dphi = getME0dPhiLUTValue(pt, 99, ME0dPhifile)
  1896. #ME0dPhiLUT = {10:0.005, 16:.003, 20:0.0025}
  1897. ME0etamin = 2.15; ME0etamax = 2.4
  1898. quality = 4
  1899. ME0_dR = 0.2
  1900. baseratecut_step0 = "maxPromptPt && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d "%( ME0etamin, ME0etamax, quality)
  1901. baseratecut_step1 = "maxPromptPt && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && L1Mu_pt>=%f "%(ME0etamin, ME0etamax, quality, pt)
  1902. baseratecut_step2 = "maxPromptPt && L1Mu_me0_dR < %f && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && L1Mu_pt>=%f && L1Mu_me0_phi<99"%(ME0_dR, ME0etamin, ME0etamax, quality, pt)
  1903. baseratecut = "maxPromptPt && abs(L1Mu_me0_dPhi)<%f && L1Mu_me0_dR < %f && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && L1Mu_pt>=%f && L1Mu_me0_phi<99"%(ME0dphi, ME0_dR, ME0etamin, ME0etamax, quality, pt)
  1904. ratehist_ME0_step0 = getRateVsEta(L1MuTriggerRate, "ratehist_ME0_step0", myetabin, baseratecut_step0)
  1905. ratehist_ME0_step1 = getRateVsEta(L1MuTriggerRate, "ratehist_ME0_step1", myetabin, baseratecut_step1)
  1906. ratehist_ME0_step2 = getRateVsEta(L1MuTriggerRate, "ratehist_ME0_step2", myetabin, baseratecut_step2)
  1907. ratehist_ME0 = getRateVsEta(L1MuTriggerRate, "ratehist_ME0", myetabin, baseratecut)
  1908. print "Trigger rate event step0 ",ratehist_ME0_step0.GetEntries()," step1 ",ratehist_ME0_step1.GetEntries()," step2 ",ratehist_ME0_step2.GetEntries()," step3 ",ratehist_ME0.GetEntries()
  1909. #ratehist_ME0_step0.Scale(SF140); ratehist_ME0_step1.Scale(SF140); ratehist_ME0_step2.Scale(SF140); ratehist_ME0.Scale(SF140)
  1910. legsallME0 = ["No pt cut","p_{T}^{L1}>10 GeV","p_{T}^{L1}>10 GeV + L1Mu with ME0","p_{T}^{L1}>10 GeV + L1Mu with ME0+ME0 bending cut"]
  1911. textME0 = "Prompt muon trigger "
  1912. #plotshistograms([ratehist_ME0_step0, ratehist_ME0_step1, ratehist_ME0_step2, ratehist_ME0], legsallME0, "L1 Muon with EMTFQ>=4", textME0, outputdir2+"TriggerRateME0_combiend_20170131_pt%d_St2eta%dto%d_withME0_q%d_allnpar_dR02_me0dphi005_Andq12_PU140"%(pt, int(ME0etamin*10),int(ME0etamax*10), quality), False)
  1913.  
  1914. baseratecut_CSC = "maxPromptPt && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && L1Mu_pt>=%f "%(1.2, 2.4, quality, pt)
  1915. ratehist_CSC = getRateVsEtav2(L1MuTriggerRate, "ratehist_CSC", myetabin, baseratecut_CSC)
  1916.  
  1917. baseratecut_CSC_q12 = "maxPromptPt && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && L1Mu_pt>=%f "%(1.2, 2.4, 12, pt)
  1918. ratehist_CSC_q12 = getRateVsEtav2(L1MuTriggerRate, "ratehist_CSC", myetabin, baseratecut_CSC_q12)
  1919. #odd->1; even->2
  1920. algos_lut = getFinalLUTValue(pt, 95, 1.64, 2.15, 1, allLUTfile)
  1921. GE21cut_odd = algos_lut["GE21"]
  1922. algos_lut = getFinalLUTValue(pt, 95, 1.64, 2.15, 2, allLUTfile)
  1923. GE21cut_even = algos_lut["GE21"]
  1924. rate_y = "gemdphi_st2"
  1925. baseratecut_GE21only = "maxPromptPt && hasME1 && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && L1Mu_pt>=%f "%(2.15, 2.4, quality, pt)
  1926. ratehist_CSC = getRateVsEta(L1MuTriggerRate, "ratehist_CSC", myetabin, baseratecut_CSC)
  1927. print "GE21cut odd ",GE21cut_odd," even ",GE21cut_even
  1928. GE21bendingRateCut = "hasME2 && ((CSCTF_ch2%%2==1 && abs(%s)<%f) || (CSCTF_ch2%%2==0 && abs(%s)<%f))"%(rate_y, GE21cut_odd, rate_y, GE21cut_even)
  1929. #GE21bendingRateCut = "hasME2"
  1930.  
  1931. ratehist_GE21only = getRateVsEta(L1MuTriggerRate, "ratehist_GE21_eta%dto%d_frac%d_pt%d"%(int(2.15*10),int(2.4*10), fraction, pt), myetabin, baseratecut_GE21only + "&& "+GE21bendingRateCut)
  1932. #plotalleta(pt, 0, netas, fractions[0], outputrootfile, badGE11)
  1933. #plotalleta(pt, 0, netas, fractions[1], outputrootfile, badGE11)
  1934. ratehist_CSC.Scale(SF);ratehist_GE21only.Scale(SF); ratehist_ME0.Scale(SF); ratehist_CSC_q12.Scale(SF)
  1935. rfile = TFile(outputrootfile,"READ")
  1936.  
  1937. etamin = netas[0]; etamax = netas[-1]
  1938. legsall = ["CSC only + Q>=4","CSC + GE11 + Q>=4"," CSC + GE11 + GE21 + Q>=4", "CSC + GE11 + GE21 + ME0 + Q>=4", "CSC only + Q>=12"]
  1939. ratehist_h_all = rfile.Get("ratehist_hybrid_eta16to21_frac%d_pt%d"%(fractions[0], pt))
  1940. ratehist_st1 = rfile.Get("ratehist_GE11_eta16to21_frac%d_pt%d"%(fractions[1], pt))
  1941. eff_h_all = rfile.Get("hybrideta16to21pt%dfraction%dvseta"%(pt, fractions[0]))
  1942. eff_st1 = rfile.Get("GE11eta16to21pt%dfraction%dvseta"%(pt, fractions[1]))
  1943. ratehistfinal = ratehist_h_all.Clone()
  1944. #ratehist_h_all.Add(ratehist_GE21only)
  1945. ratehist_ME0.Add(ratehistfinal)
  1946.  
  1947. #ratehist_CSC = rfile.Get("ratehist_CSConly_eta16to21_pt10")
  1948. #ratehist_CSC.Scale(SF); ratehist_st1.Scale(SF); ratehist_h_all.Scale(SF); ratehist_ME0.Scale(SF); ratehist_CSC_q12.Scale(SF); ratehist_GE21only.Scale(SF)
  1949. #ratehist_CSC.Scale(SF140); ratehist_st1.Scale(SF140); ratehist_h_all.Scale(SF140); ratehist_ME0.Scale(SF140); ratehist_CSC_q12.Scale(SF140)
  1950. print "Rate number CSC ",ratehist_CSC.Integral()," GE11 ",ratehist_st1.Integral()," GE11GE21 ",ratehist_h_all.Integral()," GE11GE21ME0 ",ratehist_ME0.Integral()
  1951. text4 = "p_{T}^{L1} >%d GeV"%(pt)
  1952. legsv2 = ["CSC only: EMTFQ>=12","CSC+GE11: EMTFQ>=4","CSC+GE11+GE21+ME0: EMTFQ>=4","CSC+GE11+GE21: EMTFQ>=4"]
  1953. #legsv2 = ["CSC: EMTFQ>=4","CSC+GE11, EMTFQ>=4","CSC+GE11+GE21: EMTFQ>=4","CSC: EMTFQ>=12"]
  1954. legsv2 = ["CSC only: EMTFQ>=12","CSC+GE11: EMTFQ>=4","CSC+GE11+GE21+ME0: EMTFQ>=4"]
  1955.  
  1956.  
  1957. quality1 = 4; quality2 = 12; simpt = pt+5
  1958. legGE11 = "CSC+GE11: hits in ME11, bending angle cut, p_{T}^{L1}>%d"%(pt)
  1959. legs3 = ["CSC+GE11+GE21: No Q cut, No p_{T} cut","CSC+GE11: No Q cut, No p_{T} cut","CSC only: EMTF Q>=%d, p_{T}^{L1}>%d GeV"%(quality2, pt), " CSC+GE11+GE21: hits in ME11,p_{T}^{L1}>%d, GE21-ME21 bending angle cut"%(pt),"CSC+GE11+GE21+ME0:No Q cut,bending angle cut, p_{T}^{L1}>%d GeV"%(pt) ]
  1960. plotshistograms([ratehist_CSC_q12, ratehist_st1, ratehist_ME0, ratehist_GE21only], [legs3[2], legGE11, legs3[4], legs3[3]], "L1 standalone muon, p_{T}^{L1}>%d GeV"%(pt), text4, outputdir2+"TriggerRateVseta_combined_20170131_pt%d_St2eta%dto%d_withGE2195_q%d_allnpar_dR03_Andq12_PU200"%(pt, int(etamin*10),int(etamax*10), quality), False)
  1961. #plotshistograms([ratehist_CSC_q12, ratehist_st1, ratehist_ME0], [legs3[2], legGE11, legs3[4]], "L1 standalone muon", text4, outputdir2+"TriggerRateVSeta_combined_20170131_pt%d_St2eta%dto%d_q%d_allnpar_Andq12_PU200"%(pt, int(etamin*10),int(etamax*10), quality2), False)
  1962. GEMCSCTrackCh0 = TChain("GEMCSCAnalyzer/trk_eff_CSC_ALL")
  1963. addFilesToChain(GEMCSCTrackCh0, signalsample)
  1964. GEMCSCME21Ch0 = TChain("GEMCSCAnalyzer/trk_eff_CSC_ME21")
  1965. addFilesToChain(GEMCSCME21Ch0, signalsample)
  1966. GEMCSCTrackCh0.AddFriend(GEMCSCME21Ch0)
  1967. GEMCSCTrackCh0_GE11only = TChain("GEMCSCAnalyzer/trk_eff_CSC_ALL")
  1968. addFilesToChain(GEMCSCTrackCh0_GE11only, signalsampleGE11only)
  1969. GEMCSCTrackCh0_CSConly = TChain("GEMCSCAnalyzer/trk_eff_CSC_ALL")
  1970. addFilesToChain(GEMCSCTrackCh0_CSConly, signalsampleCSConly)
  1971.  
  1972.  
  1973.  
  1974. #use sim eta
  1975. texteff = "p_{T}^{L1} >%d GeV, p_{T}^{Sim}>%d GeV"%(pt, simpt)
  1976. #baseSignalcut_CSConly = "abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && pt>=%f"%(1.6, 2.4, quality1, simpt)
  1977. baseSignalcut_CSConly = "abs(eta)>%f && abs(eta)<%f && pt>=%f"%(1.2, 2.4, simpt)
  1978. numSignalcut_L1trk = "has_gmtCand>0"
  1979. numSignalcut_CSConly = "has_gmtCand>0 && L1Mu_pt>=%d && L1Mu_quality>=%d"%(pt, quality2)
  1980. numSignalcut_CSConly_q12 = "has_gmtCand>0 && L1Mu_quality>=%d && L1Mu_pt>=%d"%(quality2, pt)
  1981. #baseSignalcut_ME0 = "abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && pt>=%f"%(ME0etamin, ME0etamax, quality1, simpt)
  1982. baseSignalcut_ME0 = "abs(eta)>%f && abs(eta)<%f && pt>=%f"%(ME0etamin, ME0etamax, simpt)
  1983. baseSignalcut_GE21 = "abs(eta)>%f && abs(eta)<%f && pt>=%f "%(2.15, ME0etamax, simpt)
  1984. numSignalcut_ME0 = "abs(L1Mu_me0_dPhi)<%f && L1Mu_me0_dR<0.2 && L1Mu_pt>=%d && L1Mu_quality>=%d"%(ME0dphi, pt,quality1)
  1985. numsingalcut_GE21 = "L1Mu_pt>=%f && L1Mu_st1_dR<.3&& hasME2 && L1Mu_quality>=%d && (abs(trk_eff_CSC_ME21.dphi_pad_fit_odd)<%f || abs(trk_eff_CSC_ME21.dphi_pad_fit_even)<%f)"%(pt, quality1, GE21cut_odd, GE21cut_even )
  1986. #legs3 = [legsall[0], legsall[-1], legsall[2], legsall[-2]]
  1987.  
  1988.  
  1989. #Teff_all = makeEffplot_eta([GEMCSCTrackCh0, GEMCSCTrackCh0, GEMCSCTrackCh0, GEMCSCTrackCh0], "abs(eta)",[baseSignalcut_CSConly, baseSignalcut_CSConly,baseSignalcut_GE21, baseSignalcut_ME0],[numSignalcut_CSConly, numSignalcut_CSConly_q12, numsingalcut_GE21, numSignalcut_ME0], 1.6, 2.4,"Simulated |#eta|","",legs3,"L1 muon",texteff,outputdir2+"GEMCSC_CSC_ME0_eff_20170621_pt%d_simpt%d_eta%dto%d_MEdR03_q4_andq12_all"%(pt, pt+5, int(1.6*10),int(2.4*10)))
  1990. Teff_all = makeEffplot_eta([GEMCSCTrackCh0, GEMCSCTrackCh0_GE11only, GEMCSCTrackCh0_CSConly, GEMCSCTrackCh0, GEMCSCTrackCh0], "abs(eta)",[baseSignalcut_CSConly, baseSignalcut_CSConly, baseSignalcut_CSConly, baseSignalcut_GE21, baseSignalcut_ME0],[numSignalcut_L1trk, numSignalcut_L1trk, numSignalcut_CSConly_q12, numsingalcut_GE21, numSignalcut_ME0], 1.2, 2.4,"Simulated |#eta|","",legs3,"L1 muon",texteff,outputdir2+"GEMCSC_CSC_ME0_eff_20170719_pt%d_simpt%d_eta%dto%d_MEdR03_q4_andq12_all"%(pt, pt+5, int(1.6*10),int(2.4*10)))
  1991. efffinal = eff_h_all.Clone()
  1992. #eff_h_all.Add(Teff_all[2])
  1993. Teff_all[4].Add(efffinal)
  1994. legGE11 = "CSC+GE11: hits in ME11, bending angle cut, p_{T}^{L1}>%d"%(pt)
  1995. legL1Trk = ["CSC + GE11 + GE21","CSC + GE11"]
  1996. #makeplotsEta([Teff_all[0], Teff_all[1]], legL1Trk, "L1Mu Trigger (inputs to L1Trk+L1Mu)", texteff, outputdir2+"GEMCSC_promptMu_L1MuTrk_effvsetaf_20170719_pt%d_simpt%d_eta%dto%d_all"%(pt, pt+5, int(1.6*10),int(2.4*10)))
  1997. #makeplotsEta([Teff_all[0], Teff_all[1], Teff_all[4], eff_st1, Teff_all[2]], [legs3[0], legs3[1], legs3[4], legGE11, legs3[2]], "Muon trigger", texteff, outputdir2+"GEMCSC_promptMu_L1MuTrkAndL1StandaloneMu_effvsetaf_20170719_pt%d_simpt%d_eta%dto%d_all"%(pt, pt+5, int(1.6*10),int(2.4*10)))
  1998. #makeplotsEta([Teff_all[4], eff_st1, Teff_all[2]], [legs3[4],legGE11, legs3[2]], "L1 standalone muon p_{T}^{L1}>%d GeV"%(pt), texteff, outputdir2+"GEMCSC_promptMu_L1StandaloneMu_effvsetaf_20170719_pt%d_simpt%d_eta%dto%d_all"%(pt, pt+5, int(1.6*10),int(2.4*10)))
  1999. makeplotsEta([Teff_all[4], eff_st1, Teff_all[2], Teff_all[3]], [legs3[4],legGE11, legs3[2], legs3[3]], "L1 standalone muon p_{T}^{L1}>%d GeV"%(pt), texteff, outputdir2+"GEMCSC_promptMu_L1StandaloneMu_withGE2195_effvsetaf_20170719_pt%d_simpt%d_eta%dto%d_all"%(pt, pt+5, int(1.6*10),int(2.4*10)))
  2000.  
  2001.  
  2002.  
  2003.  
  2004. def getME0TriggerRateVsPt(ratesample, pts, fraction, etamin, etamax, quality):
  2005. L1MuTriggerRate = TChain("L1MuTriggerRateME0Segment192")
  2006. addFilesToChain(L1MuTriggerRate, ratesample)
  2007. hrate_template = ROOT.TH1F("hrate_tmp","hrate_tmp",len(rateptbin)-1, myrateptbin)
  2008. hrate_ge21 = ROOT.TH1F("hrate_ge21","hrate_ge21",len(rateptbin)-1, myrateptbin)
  2009. hrate_me0 = ROOT.TH1F("hrate_me0","hrate_me0",len(rateptbin)-1, myrateptbin)
  2010. hrate_q12 = ROOT.TH1F("hrate_q12","hrate_q12",len(rateptbin)-1, myrateptbin)
  2011. ME0_dR = 0.2
  2012. ME0dPhifile = "ME0DPhiLUT.log"
  2013. for pt in pts:
  2014. ME0dphi = getME0dPhiLUTValue(pt, fraction+1, ME0dPhifile)
  2015. baserateME0cut = "maxPromptPt && abs(L1Mu_me0_dPhi)<%f && L1Mu_me0_dR < %f && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && L1Mu_pt>=%f && L1Mu_me0_phi<99"%(ME0dphi, ME0_dR, etamin, etamax, quality, pt)
  2016. baseratecut_CSC_q12 = "maxPromptPt && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && L1Mu_pt>=%f "%(etamin, etamax, 12, pt)
  2017. baseratecut_GE21only = "maxPromptPt && hasME1 && CSCTF_dR1<.3 && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && L1Mu_pt>=%f "%(etamin, etamax, quality, pt)
  2018. ratehist_ME0 = getRateVsEta(L1MuTriggerRate, "ratehist_ME0", myetabin, baserateME0cut)
  2019. ratehist_CSC_q12 = getRateVsEtav2(L1MuTriggerRate, "ratehist_CSC", myetabin, baseratecut_CSC_q12)
  2020. #odd->1; even->2
  2021. algos_lut = getFinalLUTValue(pt, 95, 1.64, 2.15, 1, allLUTfile)
  2022. GE21cut_odd = algos_lut["GE21"]
  2023. algos_lut = getFinalLUTValue(pt, 95, 1.64, 2.15, 2, allLUTfile)
  2024. GE21cut_even = algos_lut["GE21"]
  2025. rate_y = "gemdphi_st2"
  2026. print "GE21cut odd ",GE21cut_odd," even ",GE21cut_even
  2027. GE21bendingRateCut = "hasME2 && ((CSCTF_ch2%%2==1 && abs(%s)<%f) || (CSCTF_ch2%%2==0 && abs(%s)<%f))"%(rate_y, GE21cut_odd, rate_y, GE21cut_even)
  2028. ratehist_GE21only = getRateVsEta(L1MuTriggerRate, "ratehist_GE21_eta%dto%d_frac%d_pt%d"%(int(2.15*10),int(2.4*10), fraction, pt), myetabin, baseratecut_GE21only + "&& "+GE21bendingRateCut)
  2029. hrate_ge21.Fill(pt, ratehist_GE21only.GetEntries()*SF)
  2030. hrate_me0.Fill(pt, ratehist_ME0.GetEntries()*SF)
  2031. hrate_q12.Fill(pt, ratehist_CSC_q12.GetEntries()*SF)
  2032. text = "%.2f<|#eta|<%.2f"%(etamin, etamax)
  2033. hrate_q12.Sumw2(False)
  2034. hrate_ge21.Sumw2(False)
  2035. hrate_me0.Sumw2(False)
  2036. plotshistograms([hrate_q12, hrate_ge21, hrate_me0], ["CSC only: EMTFQ>=12","CSC+GE21: hits in ME11, bending angle cut","CSC+GE21+ME0: ME0 bending angle cut"], "L1 standalone muon", text, outputdir2+"TriggerRateVSpt_combined_20170722_St2eta%dto%d_q%d_fraction%d_withGE2195_allnpar_Andq12_PU200"%(int(etamin*10),int(etamax*10), quality, fraction), True)
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042. #efficiency
  2043.  
  2044.  
  2045.  
  2046. def getTriggerRateNoCut(ratesample, pt, etamin, etamax, quality, hasME1):
  2047. #hrate_prompt = ROOT.TH1F("hrate_prompt","hrate_prompt",len(myetabin)-1, myetabin)
  2048.  
  2049. #ratesample = "../ME0Bending_20170427/RateTree_20170613.root"
  2050. ratefile = TFile(ratesample)
  2051. h_total = ratefile.Get("h_eventcountME0Segment192")
  2052. #h_total.Print()
  2053. rateEvents = h_total.GetEntries()
  2054. L1MuTriggerRate = TChain("L1MuTriggerRateME0Segment192")
  2055. addFilesToChain(L1MuTriggerRate, ratesample)
  2056.  
  2057. #hrate_prompt = TH1F("hrate","hrate",len(myetabin)-1, myetabin)
  2058. hrate_prompt = TH1F("hrate","hrate",16, 1.6, 2.4)
  2059. text1 = "%.2f<|#eta|<%.2f, p_{T}^{L1}>%d GeV"%(etamin, etamax, pt)
  2060. baseratecut = "maxPromptPt && abs(L1Mu_eta)>%f && abs(L1Mu_eta)<%f && L1Mu_quality>=%d && L1Mu_pt>=%f"%(etamin, etamax,quality, pt)
  2061. if hasME1:
  2062. baseratecut = baseratecut + "&& hasME1"
  2063. print "baseratecut ",baseratecut," todraw ","abs(L1Mu_eta)>>hrate_prompt"," L1MuTriggerRate ",L1MuTriggerRate
  2064. c1 = TCanvas()
  2065. c1.SetLogy()
  2066. c1.SetGridx()
  2067. c1.SetGridy()
  2068. L1MuTriggerRate.Draw("abs(L1Mu_eta)>>hrate",baseratecut)
  2069. #hrate_prompt.Print("ALL")
  2070. hrate_prompt.Scale(SF)
  2071. hrate_prompt.Draw("e")
  2072. total = hrate_prompt.Integral()
  2073. #hrate_prompt.Draw()
  2074. #hrate_prompt.SetMinimum(.2)
  2075. #hrate_prompt.SetMaximum(2000)
  2076. hrate_prompt.SetTitle(" #scale[1.4]{#font[61]{CMS}} #font[52]{Simulation preliminary}"+" "*10+" 14 TeV, 200 PU")
  2077. hrate_prompt.GetXaxis().SetTitle("L1Mu |#eta|")
  2078. hrate_prompt.GetYaxis().SetTitle("Trigger rate [kHz]")
  2079. #hrate_ge11.SetMarkerStyle(maker[0])
  2080. #hrate_ge11.SetMarkerColor(color[0])
  2081. tex = ROOT.TLatex(.2, .2, text1)
  2082. tex.SetNDC()
  2083. tex.Draw("same")
  2084. legend1 = TLegend(0.4,0.8,0.90,0.88)
  2085. legend1.SetHeader("Single L1Mu")
  2086. legend1.SetFillColor(ROOT.kWhite)
  2087. #legend1.AddEntry(hrate_prompt, "L1Mu with hit in ME1","pl")
  2088. legend1.AddEntry(hrate_prompt, "Quality >= 12, total %.1f kHz"%total,"pl")
  2089. legend1.Draw("same")
  2090.  
  2091. c1.SaveAs(outputdir2+"TriggerRateVseta_q%d_eta%dto%d_PU%d.png"%(quality, int(etamin*10), int(etamax*10), pu))
  2092. c1.SaveAs(outputdir2+"TriggerRateVseta_q%d_eta%dto%d_PU%d.pdf"%(quality, int(etamin*10), int(etamax*10), pu))
  2093. c1.SaveAs(outputdir2+"TriggerRateVseta_q%d_eta%dto%d_PU%d.C"%(quality, int(etamin*10), int(etamax*10), pu))
  2094.  
  2095. def produceME0dPhiLUT(ME0etamin, ME0etamax, ME0dR, pts, fractions):
  2096. for pt in pts:
  2097. for frac in fractions:
  2098. GEMCSCTrackCh0 = TChain("GEMCSCAnalyzer/trk_eff_CSC_ALL")
  2099. addFilesToChain(GEMCSCTrackCh0, signalsample)
  2100. #ME0etamin = 2.1; ME0etamax = 2.4; ME0dR = .2
  2101. baseSignalcut_ME0 = "abs(eta)>%f && abs(eta)<%f && L1Mu_me0_dR < %f && pt>=%f && pt<%f"%(ME0etamin, ME0etamax, ME0dR, pt, pt+5)
  2102. ME0dphicut = getCut(GEMCSCTrackCh0, "abs(L1Mu_me0_dPhi)", baseSignalcut_ME0, 0.0, 0.02, 0.0001, frac)
  2103. #print "pt ",pt, " frac ",frac, " ME0dphi cut ",ME0dphicut
  2104. print "ME0pt%dfraction%d:"%(pt, frac)
  2105. print "{\n%f\n}"%ME0dphicut
  2106.  
  2107.  
  2108.  
  2109. print "outputdir1 ",outputdir1," outputdir2 ",outputdir2
  2110. if not os.path.exists(outputdir1):
  2111. os.makedirs(outputdir1)
  2112. if not os.path.exists(outputdir2):
  2113. os.makedirs(outputdir2)
  2114. pt1 = 0
  2115. pts = [5, 7, 10, 12, 16, 20]
  2116. fractions = [90+x for x in range(0, 10)]
  2117.  
  2118. ME0dPhifile = "ME0DPhiLUT.log"
  2119. #getME0dPhiLUTValue(10, 98, ME0dPhifile)
  2120. #print "x ",x,type(x)
  2121. #pts = [10]
  2122. #fractions = [98]
  2123. badGE11 = 30
  2124. netas = [1.65, 2.15]
  2125.  
  2126. #outputrootfile = outputdir2+"TriggerRateVsEff.root"
  2127. outputrootfile = outputdir2+"TriggerRateVsPT10.root"
  2128. #getTriggerRateNoCut(ratesample, 10, 1.6, 2.4, 12, False)
  2129. #plotall([10], fractions, netas, outputrootfile, badGE11)
  2130. #plotall([10], [98], netas, outputrootfile, badGE11)
  2131.  
  2132. #getTriggerRateVsPt([10, 20], [98, 94, 98, 94], netas,outputrootfile, badGE11)
  2133. #getTriggerRateVsPt(pts, [98, 93, 98, 93], netas,outputrootfile, badGE11)
  2134.  
  2135. #getallTriggerRateEffVsEta(outputrootfile, [93, 98], 16, netas)
  2136. getME0TriggerRateVsPt(ratesample, pts, 98, 2.15, 2.4, 4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement