5 #include "fhiclcpp/ParameterSet.h"
10 #include "gallery/ValidHandle.h"
11 #include "canvas/Utilities/InputTag.h"
12 #include "canvas/Persistency/Common/FindMany.h"
14 #include "nusimdata/SimulationBase/MCTruth.h"
15 #include "nusimdata/SimulationBase/MCNeutrino.h"
16 #include "nusimdata/SimulationBase/MCTruth.h"
17 #include "nusimdata/SimulationBase/MCNeutrino.h"
61 double aaBoxesMin(
const std::vector<geoalgo::AABox> &boxes,
unsigned dim) {
62 return std::min_element(boxes.begin(), boxes.end(), [dim](
auto &lhs,
auto &rhs) {
return lhs.Min()[dim] < rhs.Min()[dim]; })->
Min()[dim];
65 double aaBoxesMax(
const std::vector<geoalgo::AABox> &boxes,
unsigned dim) {
66 return std::max_element(boxes.begin(), boxes.end(), [dim](
auto &lhs,
auto &rhs) {
return lhs.Max()[dim] < rhs.Max()[dim]; })->
Max()[dim];
71 double xmin = select_volume.
Min()[0] + 5.;
72 double ymin = select_volume.
Min()[1] + 5.;
73 double zmin = select_volume.
Min()[2] + 5.;
75 double xmax = select_volume.
Max()[0] - 5.;
76 double ymax = select_volume.
Max()[1] - 5.;
77 double zmax = select_volume.
Max()[2] - 5.;
85 fhicl::ParameterSet pconfig = config->get<fhicl::ParameterSet>(
"NumuSelection");
88 std::vector<fhicl::ParameterSet> AVs = \
89 pconfig.get<std::vector<fhicl::ParameterSet> >(
"active_volumes");
90 for (
auto const& AV : AVs) {
91 double xmin = AV.get<
double>(
"xmin");
92 double ymin = AV.get<
double>(
"ymin");
93 double zmin = AV.get<
double>(
"zmin");
94 double xmax = AV.get<
double>(
"xmax");
95 double ymax = AV.get<
double>(
"ymax");
96 double zmax = AV.get<
double>(
"zmax");
100 std::vector<fhicl::ParameterSet> FVs = \
101 pconfig.get<std::vector<fhicl::ParameterSet> >(
"fiducial_volumes");
102 for (
auto const& FV : FVs) {
103 double xmin = FV.get<
double>(
"xmin");
104 double ymin = FV.get<
double>(
"ymin");
105 double zmin = FV.get<
double>(
"zmin");
106 double xmax = FV.get<
double>(
"xmax");
107 double ymax = FV.get<
double>(
"ymax");
108 double zmax = FV.get<
double>(
"zmax");
144 for (
unsigned i = 0; i <
nCuts; i++) {
195 for (
unsigned i = 0; i <
nCuts; i++) {
223 std::cout <<
"Category: " << it->first <<
" " << it->second << std::endl;
232 <<
"(" <<
_nu_count <<
" neutrinos selected)"
240 auto const& mctruths = \
241 *ev.getValidHandle<std::vector<simb::MCTruth> >(
fTruthTag);
243 auto const& mctracks = \
244 *ev.getValidHandle<std::vector<sim::MCTrack> >(
fMCTrackTag);
245 auto const& mcshowers = \
246 *ev.getValidHandle<std::vector<sim::MCShower> >(
fMCShowerTag);
252 for (
unsigned i = 0; i < mctruths.size(); i++) {
253 auto const &mctruth = mctruths[i];
258 if (!pass_kMEC)
continue;
260 weight *= interaction.
weights.at(key)[0];
262 if (
containedInAV(mctruth.GetNeutrino().Nu().Position().Vect())) {
263 bool iscc = mctruth.GetNeutrino().CCNC() == 0;
264 unsigned n_pions = 0;
265 for (
auto const &mctrack: mctracks) {
266 if (
isFromNuVertex(mctruth, mctrack) &&
abs(mctrack.PdgCode()) == 211 && mctrack.Process() ==
"primary") {
285 int mode = mctruth.GetNeutrino().Mode();
298 bool selected =
false;
299 for (
size_t i=0; i<mctruths.size(); i++) {
300 auto const& mctruth = mctruths.at(i);
302 const simb::MCNeutrino&
nu = mctruth.GetNeutrino();
335 weight *= interaction.
weights.at(key)[0];
365 reco_interaction.
weight = weight;
368 std::array<bool, NumuSelection::nCuts> selection =
Select(ev, mctruth, i, intInfo);
371 bool pass_selection = std::find(selection.begin(), selection.end(),
false) == selection.end();
372 if (pass_selection) {
374 reco.push_back(reco_interaction);
383 for (
size_t select_i=0; select_i < selection.size(); select_i++) {
384 if (selection[select_i]) {
423 double contained_length = 0;
429 bool contained_in_AV = track.size() > 0;
437 int active_volume_index = -1;
442 active_volume_index = i;
447 std::vector<geoalgo::AABox> volumes;
448 if (active_volume_index >= 0) {
452 for (
int i = 1; i < track.size(); i++) {
454 if (contained_in_AV) contained_in_AV =
containedInAV(pos.Vect());
457 contained_length +=
containedLength(track[i].Position().Vect(), pos.Vect(), volumes);
458 length += (track[i].Position().Vect() - pos.Vect()).Mag();
460 pos = track[i].Position();
467 int active_volume_index = -1;
472 active_volume_index = i;
475 if (active_volume_index >= 0) {
478 if (volume.
Contain(pos_point)) {
480 TLorentzVector this_pos = pos;
481 for (; i < track.size(); i++) {
482 this_pos = track[i].Position();
485 contained_in_AV =
false;
490 length = (pos.Vect() - this_pos.Vect()).Mag();
491 std::vector<geoalgo::AABox> volumes {volume};
492 contained_length =
containedLength(pos.Vect(), this_pos.Vect(), volumes);
494 else contained_in_AV =
false;
496 else contained_in_AV =
false;
526 auto const& mctrack_list = \
527 *ev.getValidHandle<std::vector<sim::MCTrack> >(
fMCTrackTag);
528 auto const& mcshower_list = \
529 *ev.getValidHandle<std::vector<sim::MCShower> >(
fMCShowerTag);
534 std::cout <<
"MODE: " << mctruth.GetNeutrino().Mode() << std::endl;
535 std::cout <<
"CC: " << mctruth.GetNeutrino().CCNC() << std::endl;
537 for (
auto const &mct: mctrack_list) {
539 std::cout <<
"PDG: " << mct.PdgCode() << std::endl;
541 std::cout <<
"Energy: " << mct.Start().E() << std::endl;
542 std::cout <<
"Kinetic: " << mct.Start().E() -
PDGMass(mct.PdgCode()) << std::endl;
543 std::cout <<
"Length: " << (mct.Start().Position().Vect() - mct.End().Position().Vect()).Mag() << std::endl;
544 std::cout <<
"Process: " << mct.Process() << std::endl;
547 for (
auto const &mcs: mcshower_list) {
549 std::cout <<
"PDG: " << mcs.PdgCode() << std::endl;
551 std::cout <<
"Energy: " << mcs.Start().E() << std::endl;
552 std::cout <<
"Kinetic: " << mcs.Start().E() -
PDGMass(mcs.PdgCode()) << std::endl;
553 std::cout <<
"Length: " << (mcs.Start().Position().Vect() - mcs.End().Position().Vect()).Mag() << std::endl;
554 std::cout <<
"Process: " << mcs.Process() << std::endl;
559 auto const& mcparticle_list = \
560 *ev.getValidHandle<std::vector<simb::MCParticle>>(
fMCParticleTag);
567 for (
int i = 0; i < mctrack_list.size(); i++) {
568 if (
isFromNuVertex(mctruth, mctrack_list[i]) &&
abs(mctrack_list[i].PdgCode()) == 13 && mctrack_list[i].Process() ==
"primary") {
569 if (track_ind == -1 || mctrack_list[track_ind].Start().E() < mctrack_list[i].Start().E()) {
576 if (track_ind == -1) {
577 double track_contained_length = -1;
578 for (
int i = 0; i < mctrack_list.size(); i++) {
579 if (
isFromNuVertex(mctruth, mctrack_list[i]) &&
abs(mctrack_list[i].PdgCode()) == 211 && mctrack_list[i].Process() ==
"primary") {
580 if (track_ind == -1 || mctrack_list[track_ind].Start().E() < mctrack_list[i].Start().E()) {
593 if (track_ind == -1) {
613 double truth_energy = (mctrack_list[track_ind].Start().E()) / 1000.;
614 TVector3 momentum = mctrack_list[track_ind].Start().Momentum().Vect();
619 std::array<bool, NumuSelection::nCuts>
NumuSelection::Select(
const gallery::Event& ev,
const simb::MCTruth& mctruth,
622 const simb::MCNeutrino&
nu = mctruth.GetNeutrino();
625 bool pass_valid_track = intInfo.
t_pdgid != -1;
628 bool pass_FV =
passFV(nu.Nu().Position().Vect());
634 bool pass_reco_vertex =
true;
637 truth_v[0] = nu.Nu().Vx();
638 truth_v[1] = nu.Nu().Vy();
639 truth_v[2] = nu.Nu().Vz();
642 auto const pfp_handle = ev.getValidHandle<std::vector<recob::PFParticle>>(
"pandoraNu");
643 art::FindMany<recob::Vertex> fvtx(pfp_handle, ev,
"pandoraNu");
645 std::vector<const recob::Vertex*> vertices = fvtx.at(truth_ind);
647 auto vertex = vertices[0]->position();
650 pass_reco_vertex =
passRecoVertex(nu.Nu().Position().Vect(), reco_v);
656 std::cout <<
"CCNC: " << nu.CCNC() <<
" MODE: " << nu.Mode() <<
" PDG: " << nu.Nu().PdgCode() << std::endl;
658 std::cout <<
"pass Valid Track: " << pass_valid_track << std::endl;
659 std::cout <<
"Pos: " << nu.Nu().Vx() <<
" " << nu.Nu().Vy() <<
" " << nu.Nu().Vz() << std::endl;
660 std::cout <<
"pass FV: " << pass_FV << std::endl;
661 std::cout <<
"pass Reco: " << pass_reco_vertex << std::endl;
663 std::cout <<
"pass Length: " << pass_min_length << std::endl;
667 bool pass_AV =
false;
670 if (AV.Contain(interaction)) pass_AV =
true;
679 pass_kMEC = pass_kMEC && pass_Mode && pass_CCNC;
682 return {pass_kMEC, pass_AV && pass_kMEC, pass_valid_track && pass_kMEC && pass_AV, pass_valid_track && pass_kMEC && pass_FV, pass_valid_track && pass_kMEC && pass_FV && pass_min_length};
688 if (AV.Contain(p))
return true;
696 if (FV.Contain(p))
return true;
711 return pass_stopped && pass_exiting;
TH1D * h_numu_t_is_muon_bkg
histogram of whether associated track is a muon
std::vector< NuMuInteraction > * _interactionInfo
Branch holder.
bool doFVCut
Whether to apply fiducial volume cut.
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
double showerEnergyDistortion
Energy distortion of showers for visible energy calculation (%).
TrackInfo trackInfo(const sim::MCTrack &track)
TGraph * _cut_counts
Keep track of neutrinos per cut.
int lepton_index
Index of lepton in the mctrack object.
double constantEnergyScale
constant scale to apply to reco_energy calculation
double track_energy_distortion
Distortion of energies of tracks (%).
double visibleEnergyProposal(TRandom &rand, const simb::MCTruth &mctruth, const std::vector< sim::MCTrack > &mctrack_list, const VisibleEnergyCalculator &calculator)
TH1D * h_numu_contained_L
histogram w/ FV contained length of track in CC event [cm]
TH1D * h_numu_t_length
histogram w/ total length of associated track [cm]
TVector3 momentum
Three-momentum.
double t_length
total length of (maybe faked) lepton track [cm]
bool containedInAV(const TVector3 &v)
double lepton_energy_distortion_leaving_A
Parameter in function to calculate primary lepton energy resolution.
double trackVisibleEnergyThreshold
Energy threshold for track to be acounted in visible energy calculation [GeV].
art::InputTag fTruthTag
art tag for MCTruth information
FinalStateParticle lepton
The primary final state lepton.
TH1D * h_numu_ccqe
histogram w/ CCQE energy veriable [GeV]
TH2D * h_numu_Vxy
2D x-y vertex histogram [cm]
bool isFromNuVertex(const simb::MCTruth &mc, const simb::MCParticle &mcp, float distance)
bool verbose
Whether to print out info associated w/ selection.
TTree * fTree
The output ROOT tree.
Representation of a 3D rectangular box which sides are aligned w/ coordinate axis. A representation of an Axis-Aligned-Boundary-Box, a simple & popular representation of 3D boundary box for collision detection. The concept was taken from the reference, Real-Time-Collision-Detection (RTCD), and in particular Ch. 4.2 (page 77): .
TH1D * h_numu_t_is_muon
histogram of whether associated track is a muon
TFile * fOutputFile
The output ROOT file.
Neutrino neutrino
The neutrino.
double backgroundRejection
Rejection applied to background (NC) events.
bool cutKMEC
Whether to remove MEC events (useful for studying difference w.r.t. proposal)
bool passFV(const TVector3 &v)
double lepton_energy_distortion_contained
Distortion of energies of primary lepton whose tracks are contained within the TPC (%)...
std::vector< geoalgo::AABox > fiducial_volumes
List of FV containers – set by "fiducial_volumes".
process_name use argoneut_mc_hitfinder track
bool passRecoVertex(const TVector3 &truth_v, const TVector3 &reco_v)
process_name opflashCryoW ana
Config _config
The config.
bool iscc
CC (true) or NC/interference (false)
const MCStep & End() const
TH1D * h_numu_t_is_muon_sig
histogram of whether associated track is a muon
bool onlyKMEC
Whether to remove all non-MEC events.
const Point_t & Min() const
Minimum point getter.
double constantNCWeight
constant weight to apply to each NC event
Electron neutrino event selection.
void Initialize(fhicl::ParameterSet *config=NULL)
double t_length
total length of (maybe faked) lepton track [cm]
std::map< std::string, double > _eventCategories
double leptonEnergyDistortionLeavingB
Parameter to be used in the energy distortion of primary lepton for visible energy calculation...
int t_pdgid
PDGID of primary track (muon or pi+)
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
double leptonEnergyDistortionLeavingA
Parameter to be used in the energy distortion of primary lepton for visible energy calculation...
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
double minLengthContainedTrack
Minimum length [cm] of contained tracks. Will not apply cut if value is negative. ...
double lepton_energy_distortion_leaving_B
Parameter in function to calculate primary lepton energy resolution.
double leptonEnergyDistortionContained
Contains truth level information and additional fields for selection-defined reconstruction informati...
float reco_energy
Reconstructed neutrino energy [GeV].
double aaBoxesMin(const std::vector< geoalgo::AABox > &boxes, unsigned dim)
process_name standard_reco_uboone reco
bool Contain(const Point_t &pt) const
Test if a point is contained within the box.
double t_contained_length
the length of the (maybe faked) lepton track contained in the active volume [cm]
double smearLeptonEnergy(TRandom &rand, const sim::MCTrack &mct, const VisibleEnergyCalculator &calculator)
double constantCCWeight
constant weight to apply to each CC event
float weight
Selection-defined event weight.
std::vector< std::string > uniformWeights
Weights taken from "EventWeight" that should be applied to the weight of each event.
TRandomMT64 _rand
random number generation
bool ProcessEvent(const gallery::Event &ev, const std::vector< event::Interaction > &truth, std::vector< event::RecoInteraction > &reco)
std::array< bool, nCuts > Select(const gallery::Event &ev, const simb::MCTruth &mctruth, unsigned truth_ind, const NumuSelection::NuMuInteraction &intInfo)
#define DECLARE_SBN_PROCESSOR(classname)
art::InputTag fMCShowerTag
art tag for MCShower
double minLengthExitingTrack
Minimum length [cm] of exiting tracks. Will not apply cut if value is negative.
TH1D * h_numu_trueE
histogram w/ truth energy variable [GeV]
double track_threshold
Energy threshold of track energy counted in calculation [GeV].
TH1D * h_numu_true_v_visibleE
histogram w/ difference of visible and truth energy [GeV]
Provides recob::Track data product.
unsigned _nu_count
Count selected events.
double constantWeight
constant weight to apply uniformly to each event
RootHistos _root_histos[nCuts]
Histos (one group per cut)
double aaBoxesMax(const std::vector< geoalgo::AABox > &boxes, unsigned dim)
unsigned _event_counter
Count processed events.
double shower_energy_distortion
Distortion of energies of showers (%).
TH1D * h_numu_visibleE
histogram w/ visible energy variable (total muon momentum + kinetic hadron energy) [GeV] ...
TH2D * h_numu_Vxz
2D x-z vertex histogram [cm]
double ECCQE(const TVector3 &l_momentum, double l_energy, double energy_distortion, double angle_distortion)
bool trajPointLength
Whether to use trajectory points to calculate length.
std::vector< geoalgo::AABox > active_volumes
List of active volumes.
double containedLength(const TVector3 &v0, const TVector3 &v1, const std::vector< geoalgo::AABox > &boxes)
float energy
Neutrino energy (GeV)
double t_contained_length
the length of the (maybe faked) lepton track contained in the active volume [cm]
double trackEnergyDistortion
Energy distortion of tracks for visible energy calculation (%).
double lepton_contained_length
Length of section of primary lepton's track that is contained within the TPC.
const Point_t & Max() const
Maximum point getter.
art::InputTag fMCParticleTag
art tag for MCParticle
geoalgo::AABox shaveVolume(const geoalgo::AABox &select_volume, double delta)
int lepton_pdgid
PDGID of lepton in the interaction. Used to add.
const MCStep & Start() const
bool t_is_contained
whether the (maybe faked) lepton track is totally contained in the active volume
double selectionEfficiency
Signal efficiency weight applied to signal (charged current) events.
static const std::array< std::string, nCuts > cutNames()
TH1D * h_numu_t_is_contained
histogram w/ whether associated track is contained in AV
const TLorentzVector & Position() const
bool acceptShakyTracks
Whether to calculate length of tracks that don't have all points generated.
double vertexDistanceCut
Value of max distance [cm] between truth and reconstructed vertex. Will not apply cut if value is neg...
art::InputTag fMCTrackTag
art tag for MCTrack
bool t_is_contained
whether the (maybe faked) lepton track is totally contained in the active volume
bool containedInFV(const TVector3 &v)
NuMuInteraction interactionInfo(const gallery::Event &ev, const simb::MCTruth &mctruth, VisibleEnergyCalculator &calculator)
static const unsigned nCuts
number of cuts
TH2D * h_numu_Vyz
2D y-z vertex histogram [cm]
All truth information associated with one neutrino interaction.
BEGIN_PROLOG could also be cout
bool lepton_contained
True if primary lepton's track is contained within TPC.
std::map< std::string, std::vector< float > > weights
bool passMinLength(double length, bool stop_in_tpc)