52def template_method(hmo, hms, hno, hns, hto, hts, do_scale, lb_minus_one_reco_eff, corr = None, MC = False):
53 no_sign = False
54
55 tbin1 = hmo.GetXaxis().FindBin(75000)
56 tbin2 = hmo.GetXaxis().FindBin(104000)
57 tbin3 = hmo.GetXaxis().FindBin(120000)
58 tbin4 = hmo.GetXaxis().FindBin(250000)
59
60 if no_sign:
61 hmo.Add(hms)
62 hno.Add(hns)
63 hto.Add(hts)
64
65 matchos_peak, matchos_peakerr = extract(hmo, tbin1, tbin2)
66 matchos_tail, matchos_tailerr = extract(hmo, tbin3, tbin4)
67 matchss_peak, matchss_peakerr = extract(hms, tbin1, tbin2)
68 matchss_tail, matchss_tailerr = extract(hms, tbin3, tbin4)
69
70 nomatchos_peak, nomatchos_peakerr = extract(hno, tbin1, tbin2)
71 nomatchos_tail, nomatchos_tailerr = extract(hno, tbin3, tbin4)
72 nomatchss_peak, nomatchss_peakerr = extract(hns, tbin1, tbin2)
73 nomatchss_tail, nomatchss_tailerr = extract(hns, tbin3, tbin4)
74
75 templateos_peak, templateos_peakerr = extract(hto, tbin1, tbin2)
76 templateos_tail, templateos_tailerr = extract(hto, tbin3, tbin4)
77 templatess_peak, templatess_peakerr = extract(hts, tbin1, tbin2)
78 templatess_tail, templatess_tailerr = extract(hts, tbin3, tbin4)
79
80 totalos_peak = matchos_peak + nomatchos_peak
81 totalos_tail = matchos_tail + nomatchos_tail
82
83
84
85
86
87
88
89
90 if MC:
91 n1 = matchos_peak
92 d1 = totalos_peak
93 sum_w_m, sum_w2_m = extract(hmo, tbin1, tbin2)
94 sum_w_n, sum_w2_n = extract(hno, tbin1, tbin2)
95
96 sum_w = sum_w_m + sum_w_n
97 sum_w2 = (sum_w2_m**2) + (sum_w2_n**2)
98
99 eff = n1/d1
100
101 err = (eff*(1-eff)*sum_w2/sum_w**2)**0.5
102 return eff, err
103
104 if templatess_tail == 0:
105 eff = lb_minus_one_reco_eff[0]
106 err = lb_minus_one_reco_eff[1]
107 elif templateos_tail == 0:
108 eff = lb_minus_one_reco_eff[0]
109 err = lb_minus_one_reco_eff[1]
110
111 if templatess_tail != 0 and templateos_tail != 0:
112 n1 = matchos_peak
113 n2 = templateos_peak*(matchss_tail/templatess_tail)
114 d1 = totalos_peak
115 if not do_scale:
116 d2 = templateos_peak*(nomatchos_tail/templateos_tail)
117 else:
118 d2 = templateos_peak*( (totalos_tail - matchos_tail/corr) /templateos_tail )
119
120 try:
121 eff = (n1 - n2)/(d1 - d2)
122 err = template_method_error(hmo, hms, hno, hns, hto, hts)
123 except ZeroDivisionError:
124 eff = lb_minus_one_reco_eff[0]
125 err = lb_minus_one_reco_eff[1]
126
127 return eff, err
128
129