CAFAna - PetrilloAtWork/sbncode GitHub Wiki
Slice-based and spill-based analysis
CAFMaker
produces one StandardRecord
object per art::Event
, i.e. one per beam spill / readout window.
However, most often you are interested in the properties of neutrino candidates, which are best represented as slices, of which there can be multiple per spill.
CAFAna provides SpillVar
for when you want to fill one entry into your spectrum for each spill that passes certain cuts. It also provides SliceVar
for when you want to fill your spectrum with a property of each slice that passes cuts. These are both, in fact, instances of the _Var
template specialized over different parts of the StandardRecord
structure, so they provide all the same functionality as each other.
Likewise, for selecting spills/slices there are SpillCut
and SliceCut
. Since many slice-based analyses need to also apply some quality cut on the spill, Spectrum
provides several options as constructors:
SpillCut
+SpillVar
--SpectrumLoader
checks each spill (StandardRecord
) against the cut and then evaluates the varSliceCut
+SliceVar
-- in this caseSpectrumLoader
loops through each slice, checks it against the cut, and then evaluates the var for that sliceSpillCut
+SliceCut
+SliceVar
-- in this caseSpectrumLoader
checks eachStandardRecord
against the spill cut before looping through the slices as above
MultiVar
On occasion you may need to fill multiple values into your spectrum per spill or slice. For example filling one entry per track, or one entry per CRT hit. Or perhaps you have some complex requirements that can't be factorized as SpillCut
+SliceCut
. In this case you can use MultiVar
, which behaves like Var but enables returning multiple values per slice. Or SpillMultiVar
which returns multiple values per spill.
Note that if you want to make a selection of a subset of tracks/hits etc that can't be expressed with Cut
s in this case. You must put that logic in your MultiVar
and either fill into the output vector or not as appropriate.
The special-casing of slices, where looping over them and cutting on them is a built-in feature of SpectrumLoader
is a little clunky. Ideally one could have, say, TrackCut
s. This is in the works.
FlatCAFs
ROOT has trouble with nested vectors in data structures. This occurs, for example, where we have a vector of dE/dx values within a vector of showers within a vector of slices. CAFAna's solution to this problem is "flatCAFs". These can be produced using the flatten_caf
executable. FlatCAFs may be used in CAFAna exactly as if they were regular CAFs, no changes to your code required. They don't suffer from the nested vectors problem, and they are often faster to read. It's a win-win!
Demo macros
A set of scripts to get you up and running an analysis with CAF files and the CAFAna framework are contained in the SBNAna/ananue/
directory. Both ICARUS and SBND have the same CAF file structure so you would only need to change your input file, and the variables and cuts to use according to your analysis and detector.
- helper.h It is not strictly necessary for you to have an equivalent file for your analysis, but it is strongly advised to help you keep your code organised. A few binnings and cuts are defined in this file, as well as structures (struct) to simplify the spectra making and plotting.
- make_spectra.C This is the script that you want to run first. Here we define the input CAF file(s) to use, and the spectra that we want to save into a ROOT output file. What you'd want to take note on is how to load a CAF file and define a Spectrum. To run it type
cafe make_spectra.C
from your terminal. You can additionally use ROOT tags such as-b
to Run in batch mode without graphics following thecafe
command, or-q
to Exit after processing command line macro files. I personally usecafe -bq
by default. - plot_spectra.C This script reads spectra from the ROOT file created by make_spectra.C and plots them. You can use your ROOT superpowers to further pimp your plots as much as you want (or have time and patience to). What you mostly want to take out of this script is how to load or open a spectrum and scale it.
Tip
It is good practice to separate your analysis in two steps
- Making the spectra and saving them.
- Plotting the spectra.
This example runs in a couple of minutes because we are only reading from a single file and we use a very simple logic. However, it should not come by surprise if the first step takes at least one hour for a more complex analysis. It would be a pain to run these two processes in a single script to find out that a legend is misplaced or that your plot is not colour-blind friendly.
Data samples
From MCP2020A:
Sample official_MCP2020A_prodoverlay_corsika_cosmics_proton_genie_nu_spill_gsimple-configf-v1_tpc-configf-v1_tpc_reco2_sbnd1
:
/pnfs/sbn/persistent/users/gputnam/MCP2020A-CAF/sbnd-overlay.caf.root
/pnfs/sbn/persistent/users/gputnam/MCP2020A-CAF/sbnd-overlay.flat.root
Processing is still ongoing -- these files will be updated as it happens.