Skip to content
Snippets Groups Projects
Commit cd1986e6 authored by Claire David's avatar Claire David
Browse files

Init commit.

parents
Branches
No related tags found
No related merge requests found
config/tthbb_isovar_FebProd19.json
{
"output_directory": "../comparator_tthbb_isovars",
"plots_directory": "../analysis_plots/data_mc_isoVars/20190812",
"title": "Comparison of isolation variables for estimating fakes   –   ttH(bb) single lepton channel",
"subtitle": "Distributions of data and total MC background for 4 isolation points (nominal in red). The ratio pad accounts for relative fake contribution and/or MC mis-modelling.",
"placeholder": "./img/no_plot_for_this_combination.png",
"tags": {
"YEAR": {
"active": true,
"htmlLabel": "Year",
"values": {"20152016": "2015 - 2016", "2017": "2017", "2018": "2018"}
},
"LEPTON": {
"active": true,
"htmlLabel": "Lepton",
"values": {"el": "Electron", "mu": "Muon"}
},
"TIGHT": {
"active": false,
"htmlLabel": "Tightness",
"values": {"tight": "Tight", "loose": "Loose" }
},
"VAR": {
"active": true,
"htmlLabel": "Variables",
"values": {"HT_jets": "H<sub>T</sub>", "met_met": "Met", "mtw": "Mtw", "lep_pt": "Lepton p<sub>T</sub> (all bins)", "nJets": "N jets", "nBTags_MV2c10_70": "N b-jets @ 70%"}
},
"NJETS": {
"active": true,
"htmlLabel": "Number of jets",
"values": {"4ij": " &ge;4 jets", "5ij": " &ge;5 jets"}
},
"NBJETS": {
"active": true,
"htmlLabel": "Number of b-jets",
"values": {"0b": "&ge;2b @85%", "1ib": "&ge;1b @70%", "2ib": "&ge;2b @70%", "3ib": "&ge;3b @70%", "4ib": "&ge;4b @70%"}
},
"PTRANGE": {
"active": true,
"htmlLabel": "Lepton p<sub>T</sub> bins [GeV]",
"values": {"pTlepFull": "Full range", "pTlep25-30": "25 - 30", "pTlep30-40": "30 - 40", "pTlep40-60": "40 - 60", "pTlep60-100": "60 - 100", "pTlep100-500": "100 - 500"}
},
"CUT": {
"active": true,
"htmlLabel": "Cuts",
"values": {"none": "None", "HT_jets_above_200": "H<sub>T</sub> &#60; 200 GeV"}
}
}
}
html, body {
height: 100%;
}
body
{
font-family: 'Open Sans', sans-serif, Helvetica,Arial;
text-align: center;
display: flex;
flex-direction: column;
}
.content {
flex: 1 0 auto;
}
h1
{
color: #003399;
font-size:1.9em;
/*margin: 30px 0 30px 0;*/
}
#subtitle
{
font: 300 16px/1.7 'Open Sans', sans-serif;
color:#3c3c3c;
}
#left {
width:49.5%;
float:left;
/*border: 2px solid red;*/
}
#right {
width:49.5%;
float:left;
/*border: 2px solid green;*/
}
.panel {
text-align: left;
padding: 0 10px 0 10px;
}
.panel img
{
max-width:100%;
height:auto;
}
.display_container {
margin-top:20px;
/*border: 2px solid grey;*/
}
.form-radio
{
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
display: inline-block;
position: relative;
background-color: #f1f1f1;
color: #666;
top: 10px;
height: 30px;
width: 30px;
border: 0;
border-radius: 50px;
cursor: pointer;
margin-right: 7px;
outline: none;
}
.form-radio:checked::before
{
position: absolute;
font: 13px/1 'Open Sans', sans-serif;
left: 11px;
top: 7px;
content: '\02143';
transform: rotate(40deg);
}
.form-radio:hover
{
background-color: #f7f7f7;
}
.form-radio:checked
{
background-color: #f1f1f1;
}
.form-radio:disabled {
background-color: #f1f1f1;
}
.form-radio:disabled label {
color:#ffa500;
}
.tag_label {
font-size:16px;
font-weight: bold;
}
label
{
font: 300 16px/1.7 'Open Sans', sans-serif;
color: #3c3c3c;
cursor: pointer;
}
.footer {
flex-shrink: 0;
width: 100%;
font: 12px/1.7 'Open Sans', sans-serif;
color: silver;
text-align: center;
}
.footer a {
color: #003399;
}
img/no_plot_for_this_combination.png

8.62 KiB

img/pegasus_lama_pink.png

808 KiB

img/ti_click.png

6.53 KiB

window.onload=function()
{
/*alert(data.title);*/
document.getElementsByTagName("h1")[0].innerHTML = data.title;
document.getElementById("subtitle").innerHTML = data.subtitle;
var displayOnload = "<a href=\""+ data.firstPlot +"\"><img src=\""+ data.firstPlot +"\"></a>";
document.getElementById("left").getElementsByClassName("display_container")[0].innerHTML = displayOnload;
document.getElementById("right").getElementsByClassName("display_container")[0].innerHTML = displayOnload;
// List all radio buttons from left (0) and right (1) panels:
var leftRBs = document.forms[0].getElementsByClassName('form-radio');
var rightRBs = document.forms[1].getElementsByClassName('form-radio');
// Loop left and right radio buttons in // and attach click event handler:
for (var j = [0]; j < leftRBs.length; j++) {
leftRBs[j].onclick=radioClicked;
rightRBs[j].onclick=radioClicked;
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function loadPlotNotFound()
{
alert('Image could not be loaded');
this.src=data.plotNotFound;
alert(this.src);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function radioClicked()
{
// is the clicked radio button from left or right panel?
var formName = this.parentNode.parentNode.parentNode.id;
var formID = formName.startsWith("left") ? 0 : 1; //alert(formID);
var plotFileName = "";
// Loop over tags in order to build the string plotFileName
for (var i = [0]; i < data.tagArray.length; i++) {
// Get all radio buttons from current tag:
var RBs = document.forms[formID].elements[data.tagArray[i]];
// What is the clicked value?
for (var j = [0]; j < RBs.length ; j++) {
if (RBs[j].checked){
plotFileName += RBs[j].value;
if (i < data.tagArray.length - 1) // not last
plotFileName += "__";
}
}
}
//alert(plotFileName);
var plotPath = data.plots_directory + "/" + plotFileName;
// Does the plot exist?
var innerHTML = "<a href=\"" + plotPath + ".pdf\"><img src=\"" + plotPath+ ".png\" onerror=\"javascript:this.src='" + data.plotNotFound + "'\"></a>";
//alert(innerHTML);
document.getElementById(formName).getElementsByClassName("display_container")[0].innerHTML = innerHTML;
}
#!/usr/bin/python3
# ##########################################################
# Script to create a web-based plot comparator
#
# Author: Claire David
# Date: August 2019
#
# Using python3
#
# Takes a json file as argument
#
# See a working example in ___________
#
#
# ##########################################################
import os
import sys
import json
import glob
import subprocess
import shutil
# *************************************************
def usage():
print("Usage:")
print('python '+sys.argv[0]+' PATH_TO_JSON_CONFIG_FILE')
print('Example:\npython '+sys.argv[0]+' ___________')
sys.exit(2)
# *************************************************
def get_tag_container(tag, tagDict):
htlm_div = ""
# Unactive tags won't be displayed but need to be check
# for the javascript to get the plot file name properly
isActive = True if tagDict["active"] == True else False
display = "" if isActive else " style=\"display:none;\""
htlm_div += ' <div class="tag_container"'+ display +'>\n'
htlm_div += ' <span class="tag_label">'+ tagDict["htmlLabel"] +'</span>\n'
# Listing radio buttons (first one is checked by default)
first = True
checked = " checked"
for buttonKey, buttonLabel in tagDict["values"].items():
htlm_div += ' <input type="radio" name="'+ tag +'" class="form-radio" value="'+ buttonKey +'"'+ checked +'><label>'+ buttonLabel +'</label>\n'
if first:
checked = ""
first = False
# Non-active tag: need to display a dummy radio button
# for the javascript to pick the non-display first one in a list
if not isActive:
htlm_div += ' <input type="radio" name="'+ tag +'" class="form-radio" value="dummy"><label>dummy</label>\n'
htlm_div += ' </div>\n'
return htlm_div
# *************************************************
def main():
if len(sys.argv[1:]) < 1:
usage()
f_json = sys.argv[1]
print("\n Starting script " + sys.argv[0] + " ... \n Parsing json file: " + f_json)
try:
with open(f_json) as f:
data = json.load(f)
except ValueError as e:
print("\nIssue while parsing json file.")
sys.exit(1)
outDir = data["output_directory"]
print("\n============= C o n f i g u r a t i o n =============\n")
print("Plot source directory : " + data["plots_directory"])
print("Page title : " + data["title"])
print("Unactive tags : ", end=''); print(*[utag for utag, utagData in data["tags"].items() if utagData["active"] == False], sep = ', ' , end = '\n')
print("Active tags : ", end=''); print(*[atag for atag, atagData in data["tags"].items() if atagData["active"] == True ], sep = ', ' , end = '\n')
print("Number of plots (png format) : " + str(len(glob.glob(data["plots_directory"] + "/*.png" ))))
print("Number of plots (pdf format) : " + str(len(glob.glob(data["plots_directory"] + "/*.pdf" ))))
print("Output directory (created) : " + outDir)
#----- Creating output directory and copying files
if not os.path.exists(outDir):
os.makedirs(outDir)
os.makedirs(outDir + "/css")
os.makedirs(outDir + "/js")
os.makedirs(outDir + "/img")
shutil.copy2("css/style_plot_comparator.css", outDir + "/css")
shutil.copy2("js/plot_comparator.js", outDir + "/js")
shutil.copy2("img/ti_click.png", outDir + "/img")
shutil.copy2(data["placeholder"], outDir + "/img")
#----- Writing index.html
print("\n ... Generating plot comparator index HTML ... \n")
content = r'''<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" media="screen" type="text/css" title="Design" href="css/style_plot_comparator.css">
<title>Plot comparator</title>
<script type="text/javascript">
window.data = {
'''
content += ' title : "' + data["title"] + '", \n'
content += ' subtitle : "' + data["subtitle"] + '", \n'
content += ' plots_directory : "' + data["plots_directory"] + '", \n'
content += ' firstPlot : "./img/ti_click.png",\n'
content += ' plotNotFound : "' + data["placeholder"] + '",\n'
strListTags = ""
#for tag, tagData in data["tags"].items():
# strListTags += "\"" + + "\", "
listTags = [tag for tag, tagData in data["tags"].items()]
content += ' tagArray : ' + str(listTags) + '\n'
content += r''' };
</script>
<script type="text/javascript" src="js/plot_comparator.js"></script>
</head>
<body>
<div class="content">
<h1>Title</h1>
<p id="subtitle">Subtitle</p>
<form id="left">
<div class="panel">
'''
#----- Tags and radio buttons left panel:
for tag, tagData in data["tags"].items():
content += get_tag_container(tag, tagData)
#----- Closing left panel, opening right panel:
content += r'''
</div>
<div class="display_container">
</div>
</form>
<form id="right">
<div class="panel">
'''
#----- Tags and radio buttons right panel:
for tag, tagData in data["tags"].items():
content += get_tag_container(tag, tagData)
#----- Closing right panel and html document
content += r'''
</div>
<div class="display_container">
</div>
</form>
</div>
<footer class="footer">
<p>This online plot comparator is available <a href="https://gitlab.cern.ch/davidc/plot_comparator">here</a>.</p>
</footer>
</body>
</html>'''
#----- Saving html file
f_html = outDir + "/index.html"
with open(f_html,'w') as f:
f.write(content)
#----- Say bye
print("HTML file created in : " + f_html)
print("\n======================= b y e =======================\n")
# *************************************************
if __name__ == '__main__':
main()
setupATLAS
lsetup "lcgenv -p LCG_95apython3 x86_64-slc6-gcc8-opt Python"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment