Skip to content

Instantly share code, notes, and snippets.

View ram1123's full-sized avatar
💭
I may be slow to respond.

Ram krishna Sharma ram1123

💭
I may be slow to respond.
View GitHub Profile
@ram1123
ram1123 / ReadYamlFile.md
Last active July 4, 2018 11:10
How to read yaml file

How To Read YAML Files

import yaml

file = open("yamlfile.yml","r")
ymload = yaml.load(file)
file.close()

for sections in ymload:
 print sections
@ram1123
ram1123 / StoreOutputIn_Variable.md
Last active July 4, 2018 11:16
how to store output of a command in a variable using python

(Python) How to store output of command in a variable

import subprocess

command = "ls -ltrh"

output = subprocess.check_output(command, shell=True)
@ram1123
ram1123 / Python_PlottingHelperFunctions.md
Last active January 18, 2018 18:18
Some function collection that helps in plotting

Time check

import ROOT as r
r.gROOT.SetBatch(True)
clock = r.TStopwatch()
clock.Start()
print "Note the running time..."
clock.Stop()
@ram1123
ram1123 / TTreeReader_Macro.md
Last active July 4, 2018 11:15
Root Small Macros

(ROOT) Read Root TTree using TTreeReader and make histogram

#include "TFile.h"
#include "TH1F.h"
#include "TTreeReader.h"
#include "TTreeReaderValue.h"
void TTreeReader_Macro() {
   // Create a histogram for the values we read.
   TH1F *h1 = new TH1F("h1", "ntuple", 100, 0, 2400);
@ram1123
ram1123 / RooFit_ReadHisto_Fit.py
Last active June 7, 2023 04:53
rooFit Scripts
# (RooFit) Read Histogram from root file and fit using RooFit
import ROOT as r
from ROOT import RooErfExpPdf
fin = r.TFile.Open("root://cmseos.fnal.gov//store/user/rasharma/SecondStep/WWTree_2018_01_07_12h02/HaddedFiles/Hadds_for_BkgEstimation/WWTree_WJets.root")
treeIn = fin.Get("otree")
@ram1123
ram1123 / Compare_Histo_Fit.md
Last active July 4, 2018 11:13
Issue: Compare Integral of histogram and equivalent function

(PyROOT) Read Histogram from tree

import ROOT as r

fin = r.TFile.Open("root://cmseos.fnal.gov//store/user/rasharma/SecondStep/WWTree_2018_01_07_12h02/HaddedFiles/Hadds_for_BkgEstimation/WWTree_WJets.root")

treeIn = fin.Get("otree")

c1 = r.TCanvas("c1","c1",800,600)
@ram1123
ram1123 / Integral_RooFit.md
Last active July 4, 2018 11:11
Issue: Compare Integral of histogram and equivalent function

(RooFit) How to get integral of a RooRealVal

import ROOT as r

r.gSystem.Load("PDFs/PdfDiagonalizer_cc.so")
r.gSystem.Load("PDFs/Util_cxx.so")
r.gSystem.Load("PDFs/HWWLVJRooPdfs_cxx.so")

from ROOT import RooErfExpPdf
@ram1123
ram1123 / ReadWorkspace.py
Created December 2, 2020 11:39
RooWorkspaces
from ROOT import *
myfile = TFile('/afs/cern.ch/user/r/rasharma/work/doubleHiggs/flashggFinalFitNew_2017/CMSSW_10_2_13/src/flashggFinalFit/Signal/SingleHiggsOutDir/ttHJetToGG_M125_13TeV_amcatnloFXFX_madspin_pythia8.root')
w = myfile.Get("tagsDumper/cms_hgg_13TeV")
# print the workspace
w.Print();
# get a variable
#mass = w.var("CMS_hgg_mass")
@ram1123
ram1123 / replaceSplit.C
Last active August 3, 2021 20:20
Replace a string, check if sub-string is there in a string or not, Tokenize a string based on delimiter (Works within ROOT environment)
void replaceSplit() {
TString string1 = "GluGluToHHTo2G4Q_node_cHHH1_13TeV_HHWWggTag_1_FNUFEBDown01sigma";
TString ToReplace = "HHWWggTag_1";
TString ReplaceWith = "HHWWggTag_FH_1";
std::cout << "==>\t" << string1 << std::endl;
std::cout << "==>\t" << string1.ReplaceAll(ToReplace, ReplaceWith) << std::endl;
std::cout << "==>\t" << string1.Contains("noda") << std::endl;
std::cout << "==>\t" << string1.Contains("Tag_1") << std::endl;
@ram1123
ram1123 / proxy.sh
Created June 16, 2021 08:23
Set proxy for condor jobs at lxplus
#!/bin/sh
# the argument to this script will be the file created by proxy command, i.e.
# voms-proxy-init --voms cms --valid 168:00
# Created proxy in /tmp/x509up_u48539.
# then the first argument will be x509up_u48539 only.
proxy=${1}
cp /tmp/${proxy} ~/
export X509_USER_PROXY=~/${proxy}