Coder Social home page Coder Social logo

bethel-physics / particlediscoverylab Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 7.0 26.85 MB

MATLAB-based projects using CMS Open Data

Home Page: https://bethel-physics.github.io/ParticleDiscoveryLab/

MATLAB 0.93% Python 48.13% Jupyter Notebook 50.60% M 0.35%

particlediscoverylab's Introduction

Binder

Particle Discovery lab (for students!)

The particle discovery lab uses CMS dimuon data from 2012 published via the CERN Open Data Portal. We have developed an undergraduate intermediate-level lab exercise to complement the many high school-level exercises available via the Open Data Portal. Solutions and student code are available in both MATLAB and Python, but do not require ROOT or Open Data Virtual Machines for students or instructors.

The goal of this exercise is for students to reconstruct decays of unknown particle X (initial state) to 2 muons (final state). They will use histograms to display their calculated mass for particle X, and learn about fitting and subtracting background contributions from data. Uncertainty propagation concepts are included through each step of the analysis. After isolating the signal distribution they will determine which particle they have discovered and compare their observed properties (mass and width) to the known properties.

J/psi

Visualize the data

To help introduce this exerience, there are event displays available from the DoubleMuParked dataset that we are studying. The ISpy Event Display is a web-based tool to study events interactively, so students could do this quickly on their laptops. To get to our dataset:

  • Click on the "folder" icon in the upper left corner
  • Select "Open files from the web"
  • Single-click on "Run2012B/"
  • Scroll down and single-click on "DoubleMuParked_0.ig"
  • Click on any of the individual events that appear in the right-hand column
  • Click "Load" Click and drag to rotate the image around! The yellow cylinder represents a detector element for scale, and the red boxes show which muon detector elements were hit by the 2 muons in each event. More detector or physics elements can be showed by making selections in the left-hand menu

ISpy event display

MATLAB (MatlabAnalysis folder)

Software setup: MATLAB should be installed on whatever computers students will use for the exercise. The "curve-fitting toolbox" is the only package used beyond the basic MATLAB install. This package might be part of your MATLAB license, or trials are available for 30 days. https://www.mathworks.com/products/matlab.html

Understanding the workspace

The workspace stored in DoubleMuParked_100k.mat contains the energy and 3-momentum for "muon 1" and "muon 2". When you load the workspace you'll see 4 variables: arrays of size (2 x nEvents) for E, px, py, and pz. The default unit for these numerical values is the GeV.

Values for "muon 1" are stored in the first index, and values for "muon 2" are stored in the second index. Energies can be accessed like this:

i = 294;   # Let's look at event number 294
E_muon1 = E(i,1);  # MATLAB counts indices from 1, not 0!
E_muon2 = E(i,2);

To start from the 100k event workspace

Students can start by opening MuonAnalysis_student.mlx with MATLAB. This contains the instruction of how to set their file path and load the workspace.

To reprocess the data and make a new input workspace

  • NanoAOD2Arrays.py can be run (python -u NanoAOD2Arrays.py) to produce a text file with as many events as you want -- up to the ~61M stored in the NanoAOD ROOT file. See the comments in that file for accessing the NanoAOD file either via the web or by downloading a local file. You will need the ROOT program installed, either directly or by setting up the Open Data Software.
  • txtFileReader.m can be run in MATLAB to create a workspace from the text file. The variables will appear in the Workspace panel to the right -- you can see the size/shape of each array and double-click on a variable to see its contents.
  • In MATLAB, click on the Workspace panel and type CTRL-s. Save a .mat file and post it for your students to download.

Python (PythonAnalysis folder)

Binder: You can run these Jupyter notebooks on the web! https://mybinder.org/v2/gh/bethel-physics/ParticleDiscoveryLab/HEAD

Non-binder software setup: If not using Binder, Python should be installed on whatever computers students will use for the exercise. My experience is using Cygwin on Windows, which provides a unix-based terminal in which python can be run. There are many other methods -- if your students' computational courses use Python via a certain program, I recommend following that protocol. Contact me ([email protected]) to brainstorm python solutions if needed.

Install these packages for python:

If you fork this github repository to make it your own, you can create your own Binder link. Go to mybinder.org and enter the link to your own github repository, such as: https://github.com//ParticleDiscoveryLab.

Understanding the workspace

The data is stored in DoubleMuParked_100k.pkl as a "list of lists". Each item in the list contains 8 numerical values in this order: E1, E2, px1, px2, py1, py2, pz1, pz2 (where "1" refers to "muon 1" and "2" refers to "muon 2") The default unit for these numerical values is the GeV.

Energies for each muon can be accessed like this:

data = pickle.load(open('DoubleMuParked_100k.pkl','rb'))
i = 294;   # Let's look at event number 294
E_muon1 = data[i][0];  # Python counts indices from 0, different from MATLAB
E_muon2 = data[i][1];

To start from the 100k event workspace

Students can start directly from MuonAnalysis_student.py, which is already set to import packages and load the pickle file. The simplest method is to click on the Binder link and navigate to MuonAnalysis_student.ipynb. Or, using python locally:

$ cd /path/to/files/they/downloaded/
$ vi MuonAnalysis_student.py  # or their favorite text editor

To use jupyter outside of Binder, students should launch a notebook, wait for the web browser to launch (or paste the link), and then click on the MuonAnalysis_student.ipynb file.

$ cd /path/to/files/they/downloaded/
$ jupyter notebook
[I 10:53:47.697 NotebookApp] Serving notebooks from local directory: /home/...somepath.../MatlabOpenData
[I 10:53:47.697 NotebookApp] 0 active kernels 
[I 10:53:47.697 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=lonnnnnggggstringofrandomletters
[I 10:53:47.697 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 10:53:47.697 NotebookApp] 
    
    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=lonnnggggggstringofrandomletters

To reprocess the data and make a new input workspace

  • NanoAOD2Arrays.py can be run to produce a new pickle file with as many events as you want -- up to the ~61M stored in the NanoAOD ROOT file. See the comments in that file for accessing the NanoAOD file either via the web or by downloading a local file. You will need the ROOT program installed, either directly or by setting up the Open Data Software.
  • Execute python -u NanoAOD2Arrays.py and provide students with the new pickle file.

particlediscoverylab's People

Contributors

sissonj avatar jmhogan avatar kalinjohnson avatar riggmar avatar escharnick avatar

Stargazers

 avatar Jason Ho avatar

Watchers

James Cloos avatar  avatar Kalin Johnson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.