Skip to content

Instantly share code, notes, and snippets.

View grigolet's full-sized avatar

Gianluca Rigoletti grigolet

View GitHub Profile
@grigolet
grigolet / signals.txt
Last active September 30, 2022 14:34
Some raw signals
8273
8269
8268
8266
8270
8270
8266
8267
8274
8265
@grigolet
grigolet / double_row_example.dsv
Last active January 30, 2022 11:38
Unconventional file formats that can be parsed into pandas dataframes
head1 head2 head3
head4 head5
idx1 idx2 idx3
1.1 1.2 1.3
1.4 1.5
2.1 2.2 2.3
2.4 2.5
3.1 3.2 3.3
3.4 3.5
"""Utility function to extract data from webdcs
into a csv file. Requires python3.6+, pandas, pyROOT
installed.
The main function doing the work is webdcs_to_csv() that
takes the path to the .zip file of the webdcs and returns
a pandas dataframe.
The dataframe can then be saved as a csv by simply alling
"""
@grigolet
grigolet / multiuser.py
Created September 10, 2021 21:33
Lona snippets that I found useful for myself
"""Run the script and open multiple sessions. Each connected users should
see the same list of random numbers generated by the "Add random number" button.
Useful for understanding view.iter_objects() and server.state
"""
from lona import LonaApp, LonaView
import lona.html as h
import random
@grigolet
grigolet / xpubxsub.py
Created April 11, 2021 15:43
PUB and SUB with XPUB, XSUB sockets in pyzmq using a zmq proxy
"""An example of PUB/SUB with a XPUB/XSUB connected by a proxy.
Inspired from https://stackoverflow.com/questions/14590122/how-to-implement-proxy-broker-for-xpub-xsub-messaging-in-zmq
and https://gist.github.com/minrk/4667957."""
import zmq
from threading import Thread
import random
import time
@grigolet
grigolet / fit.py
Created February 13, 2021 09:39
Fitting data distributed to a gaussian with ODR
"""Fits gaussian to a data distribution.
It uses scipy.stats to generate sample data and
scipy.odr to fit data with a gaussian function.
The output is a `scipy.odr.Output` object
"""
import scipy.stats as s
@grigolet
grigolet / rootlike.mplstyle
Last active July 21, 2020 12:11
My matplotlib rc for ROOT like plots
#### MATPLOTLIBRC FORMAT
## Personal comments
## 1. I installed GNU-Freefont to emulate the style used by ROOT
## 2. The only thing I really couldn't personalize here is the alignment of the labels. I saw lot
## of ROOT plots having xlabel on the right and ylabels on the top. This can be done
## manually on each plot by calling plt.ylabel('', ha='right', y=1.0) or
## plt.xlabel('', ha='right', x=1.0)
## This is a sample matplotlib configuration file - you can find a copy
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
/*
plotter.c
Giulio Candreva (giulio.candreva@cern.ch)
------------------------------
the purpose is to plot the data from the summary files, generated by the script WIP.c
the script is divided in various functions:
- split(string s, char delim, vector <string> *elements)
Takes a string s, splits it in chunks using the 'delim' char as divider.
The chunks are put in the *elements vector
@grigolet
grigolet / functions.cpp
Created July 12, 2018 12:51
Utility functions for bronkhorst flowplot
#include <string>
#include <vector>
#include <sstream>
#include <fstream>
/**
* Simple function that given the path of a text files returns the last line as a string.
* Answer taken from here http://www.cplusplus.com/forum/general/108679/#msg591060
*/
std::string get_last_line(std::string filename)