-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFullBackgroundValidation.py
222 lines (193 loc) · 14.5 KB
/
FullBackgroundValidation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
##################################################################################################
# #
# ```...` #
# `......-::::.`...---.` #
# `` `.-::-.....---:::-` #
# ..` `.--:://- #
# `//:` .-:::/+: #
# +m/`sy `.-:://+` #
# ` :mMmdN/ .::.`.-:://+- #
# ``-//-----------odMMMs` -yh:/m+.-:///+- #
# `..--------/oyy/---::/+sh. -mNd/omh-:://++. #
# `.-------------:------::///:. yNMMMMNs-:///+: #
# `------------------------:::://:` omNNNmy-:///+:` #
# .--------........---------:::::/+/. `+sys/-::/+++:` #
# .---------.---------------:::::///++:..------::://+o+. #
# .---------...-------------:::::://++/----------:::///+o- #
# -------------------------::::::////:---.-------::::///+o. #
# `:----------------------:::::::///:---..-------:::::///+o/ #
# .:--------------------:::::://///:-------------::::////+o+ `.- #
# `::---------------:::::::://////:------------::::::///+++/ ..-: #
# `::::--------:::::::////////////-----------::::://///++++- .--:/` ``.. #
# -/:::::::::::://///////////////--------::::://////+++++/` .--:/+...--/. #
# :///::::://////++++++++++++++/-----::::///////++++++//. `.---::----:/: #
# :+//////++++++++++++++++++o+/-:::::///////++++++++/:` `..-------:/+/`````.` #
# ./++++ooooooooooooooooooo/:::::///+++++++++++++//-` `.---------///-..--:- #
# `-+osssso/+sssssssssso+/::://+++ooooooooo+++/:-` `----------------://- #
# .:+:.` `-+ossyyyysooo++++oosssssoooo++//+:. ---------------:/+/. #
# `-/+osyyyyyysssyysssssoo++++++oso/.----.````.-------------://+/` #
# `..-://+++osysssssooosyso+ooossydhs+----------------:://++: #
# `+ssssssssssyyyo+++++/:--------------::::////////-` #
# ` -+osooooooooosshhs/:----..--------::://////++//:----. #
# ..` ...` :ssooooossssssyyy+:------------::/++ooooooooooo+/:----.` #
# .--..``-.--` .oysssssssssshdo:----------::/++ossyhddhhdo....--------` #
# `` `:-.---:----` .----------:+mh:------:://++oohhhdddddddddms` #
# `.......-:----------.` .-...```````..smy++//++ooooooooyddddddddddddmy` #
# `.-------------------.`````..-/:--.....`````.:shhhdddho/::/+oohdddddhhhhhddms #
# `-------....--------------/:-...````````````..----:/.` ``-/+hddddhhhddddmd: #
# `.-----.--..-----------:/:-....````````````````..::`` `.:ommddhdddmmmmms #
# `---------------::://++:--......``````````....--/:`````.:sdddmmmmmdddmh` #
# .--------:://+++++//:-//:--.....................-/-````.-/yydhyyyhhhhdd` #
# `..----:://///:--..`` :+::--------..............-//.```.-:sdhyyyyyhhhhd` #
# ..--::://::-..-://+///:-`.o/::----.................-:+:.``..:+hyyyyyyhhhhs #
# .-::-..` `:+ooooooooooso/o+:::---------------------:++-....:/yyyyyyyyhhh: #
# ` .syso+++++++oooosso+/::::::-----------::::::+s/-..--:shyyyyyhhys` #
# `.../yysoooooo+oooossyso///::------------::://++yo:---:/ohyyyyhhys. #
# :o+:`.oysoooooooooossyhhoo+:----------:::::://++dh+::::/+dhhhhhys. #
# .ooo:``ohyssoooooosssyhhoooo+:------::::::////++ymo//::/+dhhddh/` #
# /sso:``ohyyssssssssyyhdysooooo/:::://++///++++shds+////+mddho- #
# :sss/.`odhyyyyyyyyyyhdddyssooso///+oysooooosshNhso++//+hyo- #
# -syy+-.sdhhhyyyyyyyyyyhhhyyssssoosyyysssyhdmNdysso++/ossso+/-. #
# `/syo:-sddhhhyyyyysssyyhhhhyyyysosssssossyyhyyssso+ossoo++//- #
# `+hy/-oddhhyyyyssssyyyhddddhh+ `/oosssssssssoo+ydhho/:-.` #
# :osso:+ddhhyyyssssyyyhddhhyo. `/oosssssssssssyhhhhhhhhy+. #
# -sso+::yddhyyyyyyyyyhho ` `:+osssssssssyhsoshdhhhhddo-` #
# .oys/--odddhhhhyyhhhs. .:osyyyyyyhsoooyhdhyssyhds/ #
# `/yy+:-/dmdddhhhhyo. `yhhhhhysoosyhddhsoosyyds- #
# .+ys+/+dmdddhy+. `shyssoosyhdddhysooosyhdo-` #
# .+so:-/::-. `-+oshhhhhhyyssoooosyhd/- #
# `` .:+oooo++oooooooooooosyhh-. #
# `+oooo++++++++++++++ooosyho` #
# +ssooooo++++++++++++oosyhd/. #
# `yyysssoooooooo+++oooosyyhh-. #
# sdhhyyyssssssssssssyyyhhd+-. #
# .hmddddhhhhhhhhhhhhhddddo:- #
# `:ohddmmddddddddddhyso/:: #
# -:/++ooooooo++//:--.` #
##################################################################################################
# ____ _ #
# / ___| __ _| | __ _ _ __ __ _ __ _ ___ #
# | | _ / _` | |/ _` | '_ \ / _` |/ _` |/ _ \ #
# | |_| | (_| | | (_| | |_) | (_| | (_| | (_) | #
# _____\____|\__,_|_|\__,_| .__/ \__,_|\__, |\___/ _ #
# | ___| __ __ _ _ __ ___ |_|____ |___/ _ __| | _ #_
# | |_ | '__/ _` | '_ ` _ \ / _ \ \ /\ / / _ \| '__| |/ / #
# | _|| | | (_| | | | | | | __/\ V V / (_) | | | < #
# |_| |_| \__,_|_| |_| |_|\___| \_/\_/ \___/|_| |_|\_\ #
# #
##################################################################################################
import ROOT as r
from ROOT import gROOT, TCanvas, TFile, TGraphErrors, SetOwnership
import math, sys, optparse, array, copy, os
import gc, inspect, __main__
import numpy as np
import time
import include.Sample as Sample
import include.Launcher as Launcher
import include.helper as helper
import include.Canvas as Canvas
import include.CutManager as CutManager
from include.Utils import *
####################################### CLASS DEFINITION #########################################
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
################################# GLOBAL VARIABLES DEFINITION ####################################
runningfile = os.path.abspath(__file__)
WORKPATH = ''
for level in runningfile.split('/')[:-1]:
WORKPATH += level
WORKPATH += '/'
if __name__ == "__main__":
print bcolors.HEADER
print " ```.....` "
print " `.````.-:::-.-------. "
print " `` .--.`````.--://- "
print " ` ` `-::://` "
print " `os/y: .-::/+/ "
print " yNdod+ ````-:://+` "
print " ``-/-..------.-hNMMs` `oy/sy.-:://+. "
print " `..------:+ss/--::/+sh. `dNh/sN/-://+/` "
print " `.-------------------::///. /NMMMNm::///+- "
print " `.---------------------:::://:` -dmNNh/:///+- "
print " `--------.---.----------:::::/+/.``-++/:-://+o+. "
print " `--------..--------------:::://++/---------:://++: "
print " .----------------------::::::/++:----------::://+o: "
print " ---------------------::::::://:---..------:::://++o` "
print " `:-------------------::::::///:----.------::::://++o. "
print " `::--------------::::::://///:-----------:::::///+++. "
print " ::::------:::::::://////////----------:::::////+++/` "
print " ./:::::::::::///////////////-------:::://////++++/- "
print " -///////////++++++++++++++/----:::///////++++++/- "
print " ./+///+++++ooooooooo+ooo+::::::///++++++++++//. "
print " `-+ooosssooooosssssso+/:::///+++++oooo+++//-` "
print " `-+so/-.:+sssyyysso++///+oooooooooo++//-` "
print " `` `.:+osyyyyysssssssssssoo++++oo+:`..``` "
print " `.-:/+++oooyyysssooosso+ooosoyhyo/-. "
print " ``+sssssssssyyso++++/:------:: "
print " -+oooooooooosyhy+:----.-------:: "
print '########################################################################'
print ' Starting IFCA-LLP analysis... '
print '########################################################################' + bcolors.ENDC
parser = optparse.OptionParser(usage='usage: %prog [opts] FilenameWithSamples', version='%prog 1.0')
parser.add_option('-o', '--out', action='store', type=str, dest='out', default='', help='Output tag')
parser.add_option('-q', '--qenv', action='store', type=str, dest='qenv', default='', help='Select if you want to send the job a condor queue')
parser.add_option('-t', '--test', action='store_true', dest='test', default='', help='Test tag')
(opts, args) = parser.parse_args()
if opts.qenv == '': opts.qenv = False
############# Set the TDR plot style
r.gROOT.LoadMacro(WORKPATH + 'include/tdrstyle.C+')
r.gROOT.SetBatch(1)
r.setTDRStyle()
############# Muon data definition
DoubleMuon = []
DoubleMuon.append('DoubleMuon_Run2016F')
############# Electron data definition
DoubleEG = []
DoubleEG.append('DoubleEG_Run2016B')
DoubleEG.append('DoubleEG_Run2016C')
DoubleEG.append('DoubleEG_Run2016D')
DoubleEG.append('DoubleEG_Run2016E')
DoubleEG.append('DoubleEG_Run2016F')
DoubleEG.append('DoubleEG_Run2016G')
DoubleEG.append('DoubleEG_Run2016H')
############# Background definition
Backgrounds = []
Backgrounds.append('DYJetsToLL_M-50')
Backgrounds.append('DYJetsToLL_M-10to50')
Backgrounds.append('WW')
Backgrounds.append('WZ')
Backgrounds.append('ZZ')
# Backgrounds.append('WJetsToLNu')
Backgrounds.append('TT')
############# Parameter definition
lumiB = 5.79
lumiC = 2.57
lumiD = 4.25
lumiE = 4.01
lumiF = 3.10
lumiG = 7.54
lumiH = 8.61
lumi = 35.86 # luminosity
############# Tree creation
filename = 'dat/Samples_cern_test.dat' if opts.test else 'dat/Samples_cern.dat'
treeEGDATA = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, DoubleEG, 'DATA'), name = 'DATA', isdata = 1 )
treeMuonDATA = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, DoubleMuon, 'DATA'), name = 'DATA', isdata = 1 )
treeMC = Sample.Tree( fileName = helper.selectSamples(WORKPATH + filename, Backgrounds, 'MC'), name = 'MC', isdata = 0 )
############# Cut definition
cuts = CutManager.CutManager()
EESR = cuts.AddListB([cuts.nTrack, cuts.EEChannel, cuts.haveEEBase, cuts.EESR_dPhi])
EECR = cuts.AddListB([cuts.nTrack, cuts.EEChannel, cuts.haveEEBase, cuts.EECR_dPhi])
MMSR = cuts.AddListB([cuts.nTrack, cuts.MMChannel, cuts.haveMM, cuts.MMSR_dPhi, cuts.cosmicRejection])
MMCR = cuts.AddListB([cuts.nTrack, cuts.MMChannel, cuts.haveMM, cuts.MMCR_dPhi, cuts.cosmicRejection])
############# Plotting
start_time = time.time()
makeBkgClosureTestInMC(queue = opts.qenv, lumi = lumiF, var = 'DMDMBase_trackIxy[DMDMBase_maxIxy]', name = 'DMDM_trackIxy', nbin = 20, xmin = 0, xmax = 20, xlabel = 'Dimuon candidate |d_{0}|/#sigma', ylog = True, treeMC = treeMC, treeDATA = treeMuonDATA, cuts1 = MMSR, cuts2 = MMCR, outtag = opts.out)
makeBkgClosureTestInMC(queue = opts.qenv, lumi = lumi, var = 'EEBase_trackIxy[EEBase_maxIxy]', name = 'EE_trackIxy', nbin = 20, xmin = 0, xmax = 20, xlabel = 'Dielectron candidate |d_{0}|/#sigma', ylog = True, treeMC = treeMC, treeDATA = treeEGDATA, cuts1 = EESR, cuts2 = EECR, outtag = opts.out)
print("--- %s seconds ---" % (time.time() - start_time))