Skip to content

Commit

Permalink
Automated Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
prayagyadav committed Dec 17, 2023
1 parent c5a834e commit 5f9e3ae
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 1 deletion.
59 changes: 59 additions & 0 deletions Debug/condor_issue/condor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
This is a helper file. This file sets the proxy for condor jobs and allocates resources.
"""

import os
from coffea import processor

def move_X509():
try:
_x509_localpath = (
[
line
for line in os.popen("voms-proxy-info").read().split("\n")
if line.startswith("path")
][0]
.split(":")[-1]
.strip()
)
except Exception as err:
raise RuntimeError(
"x509 proxy could not be parsed, try creating it with 'voms-proxy-init'"
) from err
_x509_path = f'/scratch/{os.environ["USER"]}/{_x509_localpath.split("/")[-1]}'
os.system(f"cp {_x509_localpath} {_x509_path}")
return os.path.basename(_x509_localpath)

def runCondor(cores=1, memory="2 GB", disk="1 GB", death_timeout = '60', workers=4):
from distributed import Client
from dask_jobqueue import HTCondorCluster

os.environ["CONDOR_CONFIG"] = "/etc/condor/condor_config"
_x509_path = move_X509()

cluster = HTCondorCluster(
cores=1,
memory="2 GB",
disk="1 GB",
death_timeout = '60',
job_extra_directives={
"+JobFlavour": '"tomorrow"',
"log": "dask_job_output.$(PROCESS).$(CLUSTER).log",
"output": "dask_job_output.$(PROCESS).$(CLUSTER).out",
"error": "dask_job_output.$(PROCESS).$(CLUSTER).err",
"should_transfer_files": "yes",
"when_to_transfer_output": "ON_EXIT_OR_EVICT",
"+SingularityImage": '"/cvmfs/unpacked.cern.ch/registry.hub.docker.com/coffeateam/coffea-dask-cc7:latest"',
"Requirements": "HasSingularityJobStart",
"request_GPUs" : "1",
"InitialDir": f'/scratch/{os.environ["USER"]}',
"transfer_input_files": f'{_x509_path},{os.environ["EXTERNAL_BIND"]}'
},
job_script_prologue=[
"export XRD_RUNFORKHANDLER=1",
f"export X509_USER_PROXY={_x509_path}",
]
)
cluster.adapt(minimum=1, maximum=workers)
executor = processor.DaskExecutor(client=Client(cluster))
return executor, Client(cluster)
148 changes: 148 additions & 0 deletions Debug/condor_issue/plotter_simple_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#################################
# Import the necessary packages #
#################################

import argparse
from coffea.analysis_tools import util
import matplotlib.pyplot as plt
import mplhep as hep
import numpy as np
plt.style.use(hep.style.CMS)

###############
# Load Inputs #
###############
parser = argparse.ArgumentParser()
parser.add_argument(
"Mode",
help="Enter MC to run Monte Carlo Samples or enter Data to run Data samples"
)
inputs = parser.parse_args()
Mode = inputs.Mode

#####################
#Load the output file
#####################
Output = util.load("Debug.coffea")
print("The flow of events :\n ", Output["Cutflow"])
Tag_Hist = Output["Histograms"]["Tag"]
Jetpt_Hist = Output["Histograms"]["Jetpt"]
DiJetMass_Hist = Output["Histograms"]["DiJetMass"]
MET_Hist = Output["Histograms"]["MET"]

#######################
# Plot the histograms #
#######################

#1. bTag score histogram
x_min = 0.
x_max = 1.
bin_size = 0.05
n_bins=int((x_max - x_min)/bin_size)
fig , ax = plt.subplots()
hep.histplot(
Tag_Hist ,
histtype="fill",
color='#8A307F',#purple-ish
edgecolor="black",
label=r"Tag" ,
lw=1,
ax=ax
)
ax.set_title("BTag Score", y=1.0, pad = -35 , fontsize=25, color="#053B50") #Teal
ax.set_xlabel("Score", fontsize=20)
ax.set_ylabel(f"Events / {bin_size}", fontsize=20)
ax.set_xticks(np.arange(x_min,x_max+bin_size,bin_size*10))
hep.cms.label("Preliminary",data = Mode == "Data", rlabel="")
fig.savefig(f"Tag{Mode}.png", dpi= 320)
plt.clf()

#2. Jets pt : Untagged and Tagged
x_min = 0.
x_max = 500.
bin_size = 10
n_bins=int((x_max - x_min)/bin_size)
#fig , ax= plt.subplots(figsize=(10,10))
fig , ax = plt.subplots()
hep.histplot(Jetpt_Hist["Untagged",:],
#bins=bins ,
histtype="fill",
color="#79A7D3",#pale sky blue
edgecolor="black",
label=r"Untagged",
lw=1,
ax=ax
)
hep.histplot(Jetpt_Hist["btagDeepFlavB",:],
#bins=bins ,
histtype="fill",
color="#8A307F",#purple-ish
edgecolor="black",
label=r"btagDeepFlavB",
lw=1,
ax=ax
)
ax.set_title("Jet $p_t$", y=1.0, pad = -35 , fontsize=25, color="#053B50") #Teal
ax.set_xlabel("$p_t$ (GeV)", fontsize=20)
ax.set_ylabel(f"Events / {bin_size} GeV", fontsize=20)
ax.set_xticks(np.arange(x_min,x_max+bin_size,bin_size*10))
hep.cms.label("Preliminary",data = Mode == "Data" , rlabel="")
ax.legend()
fig.savefig(f"Jets{Mode}.png", dpi= 300)
plt.clf()

#3. DiJets Mass : Untagged and Tagged
x_min = 0.
x_max = 500.
bin_size = 10
n_bins=int((x_max - x_min)/bin_size)
fig , ax= plt.subplots()
hep.histplot(DiJetMass_Hist["Untagged",:],
#bins=bins ,
histtype="fill",
color="#79A7D3",#pale sky blue
edgecolor="black",
label=r"Untagged",
lw=1,
ax=ax
)
hep.histplot(DiJetMass_Hist["btagDeepFlavB",:],
#bins=bins ,
histtype="fill",
color="#8A307F",#purple-ish
edgecolor="black",
label=r"btagDeepFlavB",
lw=1,
ax=ax
)
ax.set_title("DiJet Invariant Mass", y=1.0, pad = 35 , fontsize=25, color="#053B50" ) #Teal
ax.set_xlabel("Mass (GeV)", fontsize=20)
ax.set_ylabel(f"Events / {bin_size} GeV", fontsize=20)
ax.set_xticks(np.arange(x_min,x_max+bin_size,bin_size*10))
hep.cms.label("Preliminary",data = Mode == "Data" , rlabel="")
ax.legend()
fig.savefig(f"DiJets{Mode}.png", dpi= 300)
plt.clf()

#4. MET histogram
x_min = 0.
x_max = 500.
bin_size = 10
n_bins=int((x_max - x_min)/bin_size)
fig , ax = plt.subplots()
hep.histplot(
MET_Hist ,
histtype="fill",
color='#8A307F',#purple-ish
edgecolor="black",
label=r"MET $p_t$" ,
lw=1,
ax=ax
)
ax.set_title("MET $p_t$", y=1.0, pad = -35 , fontsize=25, color="#053B50") #Teal
ax.set_xlabel("$p_t$ (GeV)", fontsize=20)
ax.set_ylabel(f"Events / {bin_size} GeV", fontsize=20)
ax.set_xticks(np.arange(x_min,x_max+bin_size,bin_size*10))
hep.cms.label("Preliminary",data = Mode == "Data", rlabel="")
fig.savefig(f"MET{Mode}.png", dpi= 320)
plt.clf()
86 changes: 86 additions & 0 deletions Debug/condor_issue/processor_simple_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#################################
# Import the necessary packages #
#################################

import awkward as ak
from coffea.analysis_tools import PackedSelection
from coffea import processor
import hist

########################
# Define the processor #
########################

class JetKinem(processor.ProcessorABC):
def __init__(self):
# Initialize the cutflow dictionary
self.cutflow = {}
pass
def process(self, events):
self.cutflow["Total_Events"] = len(events) #Total Number of events
#Apply the basic cuts like pt and eta
BasicCuts = PackedSelection()
BasicCuts.add("pt_cut", ak.all(events.Jet.pt > 25.0 , axis = 1))
BasicCuts.add("eta_cut", ak.all(abs( events.Jet.eta ) < 2.5 , axis = 1))
events = events[BasicCuts.all("pt_cut")]
Jets = events.Jet
self.cutflow["ReducedJets"] = ak.sum(ak.num(Jets)) #No of jets passing the BasicCuts

#Apply the btag
btag_WP_medium = 0.3040 # Medium Weight Parameter
GoodJetCut = Jets.btagDeepFlavB > btag_WP_medium
ak4_BJets_med = Jets[GoodJetCut]
self.cutflow["ak4bJetsMedium"] = ak.sum(ak.num(ak4_BJets_med)) #No of ak4 medium bjets

#Create Dijets
def ObtainDiJets(jet, bjet):
jet = jet[ak.num(jet)>1]
bjet = bjet[ak.num(bjet)>1]
Dijet = jet[:,0]+jet[:,1]
Dibjet = bjet[:,0]+bjet[:,1]
return Dijet , Dibjet
DiJets , DiJets_bb = ObtainDiJets(Jets, ak4_BJets_med)
self.cutflow["DiJets"] = len(DiJets) #No of Dijets
self.cutflow["bbDiJets"] = len(DiJets_bb) #No of bb Dijets

#Create the histograms
#1. bTag score histogram
TagHist = hist.Hist.new.Reg(20,0.,1.).Double().fill(ak.flatten(Jets.btagDeepFlavB))

#2. Jets pt : Untagged and Tagged
JetHist= (
hist.Hist.new.StrCat(["Untagged","btagDeepFlavB"], name="Type")
.Reg(50,0.,500., name="pt", label="$p_t$ (GeV)")
.Double()
)
JetHist.fill(Type="Untagged", pt = ak.flatten(Jets.pt))
JetHist.fill(Type="btagDeepFlavB", pt = ak.flatten(ak4_BJets_med.pt))

#3. DiJets Mass : Untagged and Tagged
DiJetHist= (
hist.Hist.new.StrCat(["Untagged","btagDeepFlavB"], name="Type")
.Reg(50,0.,500., name="mass", label="Mass (GeV)")
.Double()
)
DiJetHist.fill(Type="Untagged", mass = DiJets.mass)
DiJetHist.fill(Type="btagDeepFlavB", mass = DiJets_bb.mass)

#4. MET histogram
metHist = (
hist.Hist.new.Reg(100,0,500).Double()
)
metHist.fill(events.MET.pt)

#Prepare the output
output = {
"Cutflow": self.cutflow ,
"Histograms": {
"Tag" : TagHist ,
"Jetpt" : JetHist ,
"DiJetMass" : DiJetHist ,
"MET": metHist
}
}
return output
def postprocess(self, accumulator):
pass
Loading

0 comments on commit 5f9e3ae

Please sign in to comment.