# SNB analysis code
## Historical code
* Based on `larsoft v08_30_01` with qualifier `e17:prof` or `e17:debug`;
* Original code are found under `/dune/app/users/ajroeth/larsoft_work/srcs/`, which contains two packages: `dunetpc` and `larsim`;
* feature branches named as `feature/dingpf_SNB_analysis` has been created for both of these repos:
* `mrb g dunetpc; cd dunetpc; git checkout feature/dingpf_SNB_analysis`
* `mrb g larsim; cd larsim; git remote set-url origin git@github.com:dingp/larsim.git; git checkout feature/dingpf_SNB_analysis`
* If you do not have write access to the repo, change the git URI to the https version.
**A README file written by AJ Roeth**
```bash
README for AJ's code for pointing resolution project
Fcls for sample production:
Stages: Gen/G4, detsim, reco
/dune/app/users/ajroeth/larsoft_work/srcs/dunetpc/dune/EventGenerator/prodnuescatter_dunefd_wbkg.fcl
This is the fcl I use for the gen/G4 stage for ES events. It adds
radiological backgrounds, turns on light simulation, sets NNu to 260
(corresponds to 10 kpc SN), and points it to the SN nue rate file in
Dan's directory. This is Dan's ES generator module, so talk to him if
there's a bug.
/dune/app/users/ajroeth/larsoft_work/srcs/larsim/larsim/EventGenerator/MARLEY/prodmarley_wbkg.fcl
This is the fcl I use for the gen/G4 stage for CC events. It turns on
light simulation, sets the energy spectrum of the nue flux to the GVKM
model flux (you need to have the file gvkm_flux.root somewhere it can
find it -- add its directory to your $FW_SEARCH_PATH. See the CC xml
for how to make it work on the grid), and shows you how to specify a
direction (by default, the nu direction will be (0,0,1)). This is Steven
Gardiner's CC generator module, so talk to him if there's a bug.
/dune/app/users/ajroeth/larsoft_work/srcs/dunetpc/fcl/dunefd/detsim/standard_detsim_dune10kt_1x2x6_bestop.fcl
This is the fcl I use for the detsim stage. I added lines to the std
detsim given to me by Alex that make it use the most up-to-date and
optimistic photon detector simulation.
/dune/app/users/ajroeth/larsoft_work/srcs/dunetpc/fcl/dunefd/reco/standard_reco_dune10kt_1x2x6_opslicer.fcl
This is the fcl I use for the reco stage. I added opslicer to the reco
chain and took out emtrkmichelid.
/dune/app/users/ajroeth/larsoft_work/srcs/dunetpc/dune/PointResTree/pointrestree.fcl
/dune/app/users/ajroeth/larsoft_work/srcs/dunetpc/dune/PointResTree/pointrestree_marley.fcl
These are the fcls I use to run my analysis module PointResTree. More
in the "code for analysis" section below.
XMLs for sample production:
/dune/app/users/ajroeth/larsoft_work/SN_noise/SN_ES_wbkg_noise.xml
This xml file is used to submit ES simulation jobs to the grid using
project.py.
/dune/app/users/ajroeth/larsoft_work/SN_noise/SN_CC_wbkg_noise.xml
This xml file is used to submit CC simulation jobs to the grid using
project.py.
Note the line:
<maxfluxfilemb>0</maxfluxfilemb>
That's needed with Marley or else it fails with an unhelpful error.
Also note the line:
<jobsub> -f /pnfs/dune/resilient/users/ajroeth/gvkm_flux.root </jobsub>
It copies the flux file to the grid.
Also note the line:
<initsource>/pnfs/dune/persistent/users/gardiner/add_to_fw_search_path.sh</initsource>
It runs a script that puts the flux file location in the search path so
Marley can find it. I think Steven will fix this so this will be
unnecessary in the future.
Code for analysis (pointing resolution):
/dune/app/users/ajroeth/larsoft_work/srcs/dunetpc/dune/PointResTree/PointResTree_module.cc
This is the module I run on the output of the reco stage. It finds the
longest reco'ed track, optionally checks how often that is the true
primary electron track (you can uncomment that section), do "daughter
flipping" on the longest track, do energy reconstruction with drift
correction, and save the necessary info for finding the SN direction
and pointing resolution to a tree in an output root file with a TTree
(no art events).
Note on the fcl files for that module:
pointrestree.fcl has "largeant" as the simulation label by default,
which works for samples made with the NuE generator, but there is also
pointrestree_marley.fcl, which has the simulation label set to "marley"
for use with samples made with Marley.
/dune/app/users/ajroeth/larsoft_work/job/scripts/make_PDFs_PRT_wbkg_noise_sample.C
/dune/app/users/ajroeth/larsoft_work/job/scripts/make_PDFs_PRT.C
This is the Root macro I run on the output of PointResTree to make the
PDFs. There are a couple versions I made for different samples. The
energy bins are mostly 2 MeV wide, but the highest energy bin (with ">=
<some energy>") needs to start at an energy low enough that no PDFs end
up with a bin with 0.
/dune/app/users/ajroeth/larsoft_work/job/scripts/find_full_PR/find_full_point_res.C
This is the Root macro I run on the output of PointResTree, with the PDF
file given as an input. It reconstructs the SN direction for each SN, and
saves the angles between the true SN direction and reco'ed SN direction
in a text file (this is the input to get_SN_pointres.C and
plot_SN_pointres.C). I run it as a compiled macro because it's faster
that way.
/dune/app/users/ajroeth/larsoft_work/job/scripts/get_SN_pointres.C
This is the root macro I run on the output of find_full_point_res.C to
get the pointing resolution. It takes that module's output text file as
input (one of the arguments needs to be the name of that file). You also
specify how many bins in the histogram. You want to increase the bin
number high enough that the bin width is no longer affecting the
pointing resolution, so increase the number of bins until you're getting
the same answer.
/dune/app/users/ajroeth/larsoft_work/job/scripts/plot_SN_pointres.C
This is the root macro I run on the output of find_full_point_res.C to
plot the distribution of angles. It takes that module's output text file as
input (one of the arguments needs to be the name of that file). You also
specify how many bins are in the full histogram, but keep in mind it only
draws a certain range.
```
## Create working directory and build the code
My working directory is under `/dune/app/users/dingpf/snb/larsoft_mydev`.
A useful reference to the commands used below can be found here in the [dunetpc tutorial](https://cdcvs.fnal.gov/redmine/projects/dunetpc/wiki/_Tutorial_).
```shell=
# Setting up UPS products area and larsoft
source /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh
setup larsoft v08_30_01 -q e17:prof
# Creating workding directory
mkdir larsoft_mydev
cd larsoft_mydev
mrb newDev
# Setting up working directory for use, this is to be sourced everytime after new login
source localProducts_larsoft_v08_30_01_e17_prof/setup
# Checking out dunetpc and the feature branch in use
cd srcs
mrb g dunetpc
cd dunetpc
git checkout feature/dingpf_SNB_analysis
cd ..
# Checking out larsim and the feature branch in use
mrb g larsim
cd larsim
git remote set-url origin git@github.com:dingp/larsim.git
# OR: git remote set-url origin https://github.com/dingp/larsim.git
git checkout feature/dingpf_SNB_analysis
cd ..
# Building the packages
cd $MRB_BUILDDIR
mrbsetenv
mrb i -j4
# setup to use the newly built code
mrbslp
```
In the future, when no new packages are added to `srcs`, simply do the following:
```shell=
mrbsetenv
mrb i -j4
mrbslp
```
Upon new login, do
```shell=
source /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh
cd larsoft_mydev
source localProducts_larsoft_v08_30_01_e17_prof/setup
mrbslp
```
## Modules and FHiCL files related to the analysis
### `PointRes`
This module does the following things:
1. taking 10kt MC files as input;
2. loops over tracks, find closet and longest track to true electron;
3. doing daughter flipping on longest tracks;
4. fit on tracks to get SN direction.
```json=
process_name: PointRes
services:
{
TFileService: { fileName: "PointRes.root" }
TimeTracker: {}
message: @local::standard_info
Geometry: @local::dune10kt_workspace_geo
ExptGeoHelperInterface: @local::dune_geometry_helper
LArG4Parameters: @local::dunefd_largeantparameters
@table::dunefd_simulation_services
source:
{
module_type: RootInput
maxEvents: -1
}
outputs:{}
physics:
{
analyzers:
{
PointRes:
{
module_type: "PointRes"
SimulationLabel: "largeant"
DetSimLabel: "daq"
HitsModuleLabel: "hitfd"
HitsModuleLabel2: "gaushit"
TrackModuleLabel: "pmtracktc"
CalorimetryAlg: @local::dune10kt_calorimetryalgmc
OpFlashLabel: "opflash"
}
}
analysis: [ PointRes ]
end_paths: [ analysis ]
}
```
### `PointResTree` (Primary analysis module)
Similar to `PointRes`, but focuses on filling a TTree with variables needed by fitting the SN direction.
```cpp=
// Make tree and branches
tr = tfs->make<TTree>("tr", "tr");
tr->Branch("nu_x",&nu_x,"nu_x/D");
tr->Branch("nu_y",&nu_y,"nu_y/D");
tr->Branch("nu_z",&nu_z,"nu_z/D");
tr->Branch("nu_true_en",&nu_true_en,"nu_true_en/D");
tr->Branch("elec_x",&elec_x,"elec_x/D");
tr->Branch("elec_y",&elec_y,"elec_y/D");
tr->Branch("elec_z",&elec_z,"elec_z/D");
tr->Branch("elec_reco_en_noDC",&elec_reco_en_noDC,"elec_reco_en_noDC/D");
tr->Branch("elec_reco_en_DC",&elec_reco_en_DC,"elec_reco_en_DC/D");
tr->Branch("elec_true_en",&elec_true_en,"elec_true_en/D");
tr->Branch("max_flash_time",&max_flash_time,"max_flash_time/D");
tr->Branch("trk_charge_U",&trk_charge_U,"trk_charge_U/D");
tr->Branch("trk_charge_V",&trk_charge_V,"trk_charge_V/D");
tr->Branch("trk_charge_Z",&trk_charge_Z,"trk_charge_Z/D");
//tr->Branch("",&,"/");
```
## Data/MC and analysis files
### Data/MC files
Two types of MC files using event generator: marly and largeant.
(Marly is the primary one as it does better job to simulate low-energy neutrino-nucleus interactions at ~10MeV and below.)
- Localtion:
- Size:
- Analysis modules:
- job FHiCLs:
- job submission files: `project.py xml`
### Analysis files (ROOT ntuples)
- Location:
- Size:
- Analysis modules:
- Plotting macros:
- job FHiCLs:
- job submission files:
## Useful references:
1. [AJ's presentation](https://indico.fnal.gov/event/21445/contributions/62593/attachments/39229/47521/Point_Res_DUNE_Meeting_2019_09_AJRoeth.pdf)
1. [Supernova Neutrino Burst Detection with the Deep
Underground Neutrino Experiment](https://arxiv.org/abs/2008.06647)
2. [DUNE FarDet TDR](https://arxiv.org/abs/2002.03005)
3. [Simulating low-energy neutrino interactions with MARLEY](https://arxiv.org/abs/2101.11867)
4. [LArSoft event generation and detector simulation](https://indico.fnal.gov/event/9928/sessions/12915/attachments/75522/90585/larsoft-class-event-gen-and-sim.present.pdf)
5. [MARLEY github repo](https://github.com/MARLEY-MC/marley)
6. [MARLEY user guide](http://www.marleygen.org/index.html)
7. [Understanding supernova electron neutrino detection with MARLEY](https://indico.slac.stanford.edu/event/140/contributions/205/attachments/224/336/gardiner-pins-2019.pdf)