NtupleTutorial: Difference between revisions
m (Beginning to fill in tutorial) |
|||
Line 7: | Line 7: | ||
Note that much of the work we'll do is related to learning how to work with [root][https://root.cern.ch/], a common plotting/fitting program used across many experiments in particle physics. There are many root tutorials out there that you might find useful before, during, or after going through this tutorial. | Note that much of the work we'll do is related to learning how to work with [root][https://root.cern.ch/], a common plotting/fitting program used across many experiments in particle physics. There are many root tutorials out there that you might find useful before, during, or after going through this tutorial. | ||
==Become Familiar with the | ==Setting up your ROOT environment and accessing the Ntuple== | ||
Before we begin looking at the Ntuple, please enter into your mu2e offline directory and make sure the mu2e base release is set up ("source setup.sh" and then "setup mu2e"). There are two Ntuples created for you to explore during this tutorial. One includes signal and background events, while the other just has signal event information. We will focus on the latter. | |||
The files are located at | |||
/cvmfs/mu2e.opensciencegrid.org/DataFiles/tutorials/trkana_signalAndBkg.root | |||
/cvmfs/mu2e.opensciencegrid.org/DataFiles/tutorials/trkana_signal.root | |||
It is easiest if you copy the root files into your own offline directory using the cp command. | |||
==Become Familiar with the Ntuple== | |||
To open the ntuple file type: root -l trkana_signal.root (the -l is optional but stops the root logo from popping up when you open root). This opens the ROOT environment and allows you to navigate through the Ntuple. There are two ways to see the structure of the Ntuple: using a TBrowser and using the ROOT command line. | |||
To set the Ntuple as your starting file, type: TFile *f1 = new TFile("trkana_signal.root"); | |||
Then to see the first folder, type: f1->ls(); | |||
You should see this on your terminal screen: | |||
TFile** trkana_signal_forENE.root | |||
TFile* trkana_signal_forENE.root | |||
KEY: TDirectoryFile TrkAna;1 TrkAna (TrackAnalysis) folder | |||
===Browse with the TBrowser=== | ===Browse with the TBrowser=== | ||
Once ROOT is open, type in "New TBrowser". Now you can look at the file structure! At the top of the left panel should be the trkana_signal.root file. From there you can click on TrkAna folder and the trkana subfolder (called a Tree). Now you have a list of 12 branches in your tree visible to you! | |||
Here is the general info a few of the branches contain: | |||
evtinfo: event level info | |||
dem: results of downstream e minus fit | |||
uem: results of upstream e minus fit | |||
dmm: results of downstream mu minus fit | |||
demc: calorimeter info for downstream e minus | |||
demmc: MC info for downstream e minus | |||
demmcgen: MC generator info for downstream e minus (i.e. the particle that was created) | |||
demmcent: MC info for downstream e minus at entrance to tracker | |||
demmcmid: MC info for downstream e minus at middle of tracker | |||
demmcxit: MC info for downstream e minus at exit of tracker | |||
Remember this Ntuple is filled with information from the tracker that follows a particle's path through the detector. Thus it contains information from the fits for downtstream and upstream moving electrons in the straw tracker, information from the calorimeter (located behind the straw tracker), and the Monte Carlo (MC) information which can be thought of as our "truth" information. The MC shows us how well our tracking information accurately reconstructs the simulated event data. | |||
==Explore a Single Branch == | |||
Click on the dem branch. Here you have 34 different leaves! Have you noticed the Tree, Branch, Leaf structure of the ntuple yet? This cute naming convention makes it easy to understand the hierarchical structure of the Ntuple. These leaves are histograms that contain various information about the downsream electron fit. We will look at just a few of them, but feel free to explore more on your own. | |||
Click on the status leaf. There are 2 peaks, one at 0 and one at -1000. A value of >0 is a success, and you can see that about 333/593 entries were a success! You can move the legend box by clicking and dragging on it. Placing your mouse at the top of the bin at 0 will give you the bin contents on the bottom right hand side of the screen. | |||
The next leaf is the pdg, or particle id number. A pdg value of 11 is an electron. | |||
Then we have nhits: the number of hits on the track. If no track is found, we have 0 hits, but the sucessful tracks range from 15-82 hits. | |||
The nactive leaf shows the number of hits used in the fit. The histogram looks similar to the nhits histogram but is not quite the same. You can see the mean value decreased from 21.88 to 21.44. | |||
The t0 leaf has the time of the track. Our live window for data taking is between 400 and 1700ns. The next leaf t0err is just the error on the t0 values. We only have a finite resolution in timing with the detector. | |||
==Working with ROOT in the command line== | |||
When we are looking at the plots in the leaves, we are seeing the cumulative data for all events. What if we wanted to just see the information for one specific event? To get this you need to type in the terminal ROOT browser:; | |||
root [0] TFile *f1 = new TFile("trkana_signal.root"); (to establish the Ntuple as your starting point) | |||
root [1] TTree *t = (TTree*)f1->Get("TrkAna/trkana"); (to get the trkana tree from the TrkAna folder in the ntuple) | |||
root [2] t->Show(10) (to get the information for event 10) | |||
Now you should see a lot of information printed out that starts with: | |||
eventid = 13 | |||
runid = 4001 | |||
subrunid = 0 | |||
evtwt = 1 | |||
beamwt = 1 | |||
genwt = 1 | |||
nprotons = -1 | |||
nsh = 63 | |||
nesel = 59 | |||
nrsel = 61 | |||
... | |||
Now that you know how to browse the Ntuple, let's start making plots! | |||
===Build a simple analysis structure=== | ===Build a simple analysis structure=== | ||
==Making plots== | ==Making plots== | ||
===Interactively=== | ===Interactively=== | ||
===With a macro=== | ===With a macro=== |
Revision as of 17:53, 5 July 2018
Introduction
When you want to perform a physics analysis, you need a way to access and manipulate the data. For Mu2e, this could include evaluating the performance of the tracking chamber or calorimeter or cosmic ray veto detector. You might want to look at "raw" information from the detector, like voltages or waveforms, or you might want higher-level quantities, where hits from the tracking detector have been combined into tracks or energy deposits in the calorimeter have been clustered into total particle energy. Whatever you need to do, you need a way to organize the information that you need.
At its most basic, you can think of an ntuple as a database. It has a variables defined that are filled with information. There are many different formats your ntuple can take, depending on what information you want to access. In this tutorial we will work with a basic tracking ntuple. We will learn how to discover what information the ntuple contains and how to access and display that information. Hopefully what you learn here will translate to other ntuples that you face in the future.
Note that much of the work we'll do is related to learning how to work with [root][1], a common plotting/fitting program used across many experiments in particle physics. There are many root tutorials out there that you might find useful before, during, or after going through this tutorial.
Setting up your ROOT environment and accessing the Ntuple
Before we begin looking at the Ntuple, please enter into your mu2e offline directory and make sure the mu2e base release is set up ("source setup.sh" and then "setup mu2e"). There are two Ntuples created for you to explore during this tutorial. One includes signal and background events, while the other just has signal event information. We will focus on the latter.
The files are located at /cvmfs/mu2e.opensciencegrid.org/DataFiles/tutorials/trkana_signalAndBkg.root /cvmfs/mu2e.opensciencegrid.org/DataFiles/tutorials/trkana_signal.root
It is easiest if you copy the root files into your own offline directory using the cp command.
Become Familiar with the Ntuple
To open the ntuple file type: root -l trkana_signal.root (the -l is optional but stops the root logo from popping up when you open root). This opens the ROOT environment and allows you to navigate through the Ntuple. There are two ways to see the structure of the Ntuple: using a TBrowser and using the ROOT command line.
To set the Ntuple as your starting file, type: TFile *f1 = new TFile("trkana_signal.root");
Then to see the first folder, type: f1->ls();
You should see this on your terminal screen:
TFile** trkana_signal_forENE.root
TFile* trkana_signal_forENE.root KEY: TDirectoryFile TrkAna;1 TrkAna (TrackAnalysis) folder
Browse with the TBrowser
Once ROOT is open, type in "New TBrowser". Now you can look at the file structure! At the top of the left panel should be the trkana_signal.root file. From there you can click on TrkAna folder and the trkana subfolder (called a Tree). Now you have a list of 12 branches in your tree visible to you!
Here is the general info a few of the branches contain: evtinfo: event level info dem: results of downstream e minus fit uem: results of upstream e minus fit dmm: results of downstream mu minus fit demc: calorimeter info for downstream e minus demmc: MC info for downstream e minus demmcgen: MC generator info for downstream e minus (i.e. the particle that was created) demmcent: MC info for downstream e minus at entrance to tracker demmcmid: MC info for downstream e minus at middle of tracker demmcxit: MC info for downstream e minus at exit of tracker
Remember this Ntuple is filled with information from the tracker that follows a particle's path through the detector. Thus it contains information from the fits for downtstream and upstream moving electrons in the straw tracker, information from the calorimeter (located behind the straw tracker), and the Monte Carlo (MC) information which can be thought of as our "truth" information. The MC shows us how well our tracking information accurately reconstructs the simulated event data.
Explore a Single Branch
Click on the dem branch. Here you have 34 different leaves! Have you noticed the Tree, Branch, Leaf structure of the ntuple yet? This cute naming convention makes it easy to understand the hierarchical structure of the Ntuple. These leaves are histograms that contain various information about the downsream electron fit. We will look at just a few of them, but feel free to explore more on your own.
Click on the status leaf. There are 2 peaks, one at 0 and one at -1000. A value of >0 is a success, and you can see that about 333/593 entries were a success! You can move the legend box by clicking and dragging on it. Placing your mouse at the top of the bin at 0 will give you the bin contents on the bottom right hand side of the screen.
The next leaf is the pdg, or particle id number. A pdg value of 11 is an electron. Then we have nhits: the number of hits on the track. If no track is found, we have 0 hits, but the sucessful tracks range from 15-82 hits.
The nactive leaf shows the number of hits used in the fit. The histogram looks similar to the nhits histogram but is not quite the same. You can see the mean value decreased from 21.88 to 21.44.
The t0 leaf has the time of the track. Our live window for data taking is between 400 and 1700ns. The next leaf t0err is just the error on the t0 values. We only have a finite resolution in timing with the detector.
Working with ROOT in the command line
When we are looking at the plots in the leaves, we are seeing the cumulative data for all events. What if we wanted to just see the information for one specific event? To get this you need to type in the terminal ROOT browser:;
root [0] TFile *f1 = new TFile("trkana_signal.root"); (to establish the Ntuple as your starting point)
root [1] TTree *t = (TTree*)f1->Get("TrkAna/trkana"); (to get the trkana tree from the TrkAna folder in the ntuple)
root [2] t->Show(10) (to get the information for event 10)
Now you should see a lot of information printed out that starts with:
eventid = 13 runid = 4001 subrunid = 0 evtwt = 1 beamwt = 1 genwt = 1 nprotons = -1 nsh = 63 nesel = 59 nrsel = 61
...
Now that you know how to browse the Ntuple, let's start making plots!