Skip to content

Instantly share code, notes, and snippets.

@cvson
cvson / pi_calculation_simple_with_root
Created July 1, 2014 05:22
Pi calculation with simple Monte Carlo (ROOT)
//try to make a toy monte carlo
//pi calculation
void pi(){
TCanvas *c1 = new TCanvas("c1","pi",800,800);
gStyle->SetOptStat(0);
gStyle->SetLineWidth(2);
//c1->SetGrid();
gBenchmark->Start("hpi");
gSystem->Unlink("hpianim.gif"); // delete old file
@cvson
cvson / simpleProfitPrediction.C
Last active May 6, 2019 08:12
[ Simple profit prediction] to predict profile #ROOT #lifeapp #tutorials
//try to make a toy monte carlo
//waste calculation
void simpleProfitPrediction(){
gBenchmark->Start("htrang");
TH1 *hprofit = new TH1F("hprofit","hprofit",100,-2000,6000);
Int_t numUnit;
Float_t rentUnit=500;
Float_t monthlyExpense;
Float_t profit;
#!/usr/bin/gnuplot
# Redirect output to file
set terminal postscript enhanced eps color
set output "workforce_male_percent.eps"
set style data histogram
set yrange [0:100]
set key right top title ''
#set title "male workforce percentage"
set style fill solid border -1
Apple 70 55 15 11 7 2
Google 70 61 30 3 2 4
Yahoo 63 50 39 2 4 2
Facebook 69 57 34 4 2 3
#Day Month Mo.Number Day_of_year Draft_No.
1 Jan 1 1 305
2 Jan 1 2 159
3 Jan 1 3 251
4 Jan 1 4 215
5 Jan 1 5 101
6 Jan 1 6 224
7 Jan 1 7 306
8 Jan 1 8 199
9 Jan 1 9 194
#!/usr/local/bin/gnuplot
###################################
# #
# @visionlib.postach.io #
# #
###################################
set term post enh color
set output "draft_lottery.eps"
set xlabel "Draft Number"
set ylabel "Day of year"
//
// randomWalk.C
////////////////////////////////////////////////////
//
// Simple Monte Carlo
//
///////////////////////////////////////////////////
// Created by @visionlib.postach.io
{
const Int_t kIteration = 1000000;
void titleStyle(TH1* h1){
h1->SetTitle("");
h1->GetYaxis()->CenterTitle();
h1->GetXaxis()->CenterTitle();
h1->GetXaxis()->SetLabelSize(h1->GetXaxis()->GetTitleSize()*1.4);
h1->GetYaxis()->SetLabelSize(h1->GetYaxis()->GetTitleSize()*1.4);
h1->GetXaxis()->SetTitleSize(h1->GetXaxis()->GetLabelSize()*1.2);
h1->GetYaxis()->SetTitleSize(h1->GetYaxis()->GetLabelSize()*1.2);
h1->GetYaxis()->SetTitleOffset(0.9);
}
@cvson
cvson / gridWalk.C
Created August 25, 2014 01:57
Solve Random walk problem with Monte Carlo Method
{
TH2F *h = new TH2F("h","h",10,0,9,10,0,9);
TCanvas *c = new TCanvas("c","c");
c->Range(-0.3373713,-2.125,3.036341,9.125);
//new TCanvas;
//gPad->Range(-0.3373713,-2.125,3.036341,9.125);
gStyle->SetOptStat(0);
c->cd();
h->SetTitle("");
@cvson
cvson / AppleScript-chrome-screenshot
Created August 27, 2014 03:47
Automatically screenshot webpage with AppleScript
-- set file name
set fileNames to "webshot-googleAnalytics"
tell application "Google Chrome"
-- open window with secret mode, if with normal mode then use {mode:"normal"}
set aWin to make new window with properties {mode:"normal"}
tell aWin
-- open new tab and set URL
set newTab to make new tab with properties {URL:"https://www.google.com/analytics/web/?et=&authuser=#report/visitors-overview/a38108925w74194420p76615924/"}
tell active tab