All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NumuSelection.h
Go to the documentation of this file.
1 #ifndef __sbnanalysis_ana_SBNOsc_NumuSelection__
2 #define __sbnanalysis_ana_SBNOsc_NumuSelection__
3 
4 /**
5  * \file NumuSelection.h
6  *
7  * SBN nue selection.
8  *
9  * Author:
10  */
11 
12 #include <iostream>
13 #include <array>
14 #include <map>
15 
16 #include "canvas/Utilities/InputTag.h"
17 #include "core/SelectionBase.hh"
18 #include "core/Event.hh"
19 
20 #include "Utilities.h"
21 
22 #include "TH1D.h"
23 #include "TDatabasePDG.h"
24 #include "TGraph.h"
25 
26 #include "nusimdata/SimulationBase/MCTruth.h"
28 
29 // take the geobox stuff from uboonecode
30 #include "ubcore/LLBasicTool/GeoAlgo/GeoAABox.h"
31 #include "ubcore/LLBasicTool/GeoAlgo/GeoAlgo.h"
32 #include "TRandom.h"
33 #include "TRandomGen.h"
34 
35 class TH2D;
36 
37 namespace ana {
38  namespace SBNOsc {
39 
40 /**
41  * \class NumuSelection
42  * \brief Electron neutrino event selection
43  */
45 public:
46  /** Constructor. */
47  NumuSelection();
48 
49  /**
50  * Initialization.
51  *
52  * \param config A configuration, as a FHiCL ParameterSet object
53  */
54  void Initialize(fhicl::ParameterSet* config=NULL);
55 
56  /** Finalize and write objects to the output file. */
57  void Finalize();
58 
59  /**
60  * Process one event.
61  *
62  * \param ev A single event, as a gallery::Event
63  * \param Reconstructed interactions
64  * \return True to keep event
65  */
66  bool ProcessEvent(const gallery::Event& ev, const std::vector<event::Interaction> &truth, std::vector<event::RecoInteraction>& reco);
67 
68  /** Additional information used by the selection per neutrino interaction */
69  struct NuMuInteraction {
70  bool t_is_contained; //!< whether the (maybe faked) lepton track is totally contained in the active volume
71  double t_contained_length; //!< the length of the (maybe faked) lepton track contained in the active volume [cm]
72  double t_length; //!< total length of (maybe faked) lepton track [cm]
73  int t_pdgid; //!< PDGID of primary track (muon or pi+)
74  double t_energy_true; //!< True energy of primary track [GeV]
75  double t_energy_smeared; //!< Smeared energy of primary track [GeV]
76  TVector3 t_momentum;
77 
78  // default constructor -- fills with bogus info
79  /*
80  NuMuInteraction():
81  t_is_contained(false),
82  t_contained_length(-1),
83  t_length(-1),
84  t_pdgid(-1)
85  {}*/
86  };
87 
88 protected:
89  /** Configuration parameters */
90  struct Config {
91  bool doFVCut; //!< Whether to apply fiducial volume cut
92  std::vector<geoalgo::AABox> fiducial_volumes; //!< List of FV containers -- set by "fiducial_volumes"
93  std::vector<geoalgo::AABox> active_volumes; //!< List of active volumes
94  double vertexDistanceCut; //!< Value of max distance [cm] between truth and reconstructed vertex. Will not apply cut if value is negative.
95  bool verbose; //!< Whether to print out info associated w/ selection.
96  bool acceptShakyTracks; //!< Whether to calculate length of tracks that don't have all points generated
97  bool trajPointLength; //!< Whether to use trajectory points to calculate length
98  double minLengthContainedTrack; //!< Minimum length [cm] of contained tracks. Will not apply cut if value is negative.
99  double minLengthExitingTrack; //!< Minimum length [cm] of exiting tracks. Will not apply cut if value is negative.
100  double trackVisibleEnergyThreshold; //!< Energy threshold for track to be acounted in visible energy calculation [GeV].
101  double showerEnergyDistortion; //!< Energy distortion of showers for visible energy calculation (%).
102  double trackEnergyDistortion; //!< Energy distortion of tracks for visible energy calculation (%).
103  double leptonEnergyDistortionContained; //<! Energy distortion of lepton (primary track) for visible energy calculation (%).
104  double leptonEnergyDistortionLeavingA; //!< Parameter to be used in the energy distortion of primary lepton for visible energy calculation.
105  // (%) = -A * Log(B * L) where L is the lepton contained length
106  double leptonEnergyDistortionLeavingB; //!< Parameter to be used in the energy distortion of primary lepton for visible energy calculation.
107  // (%) = -A * Log(B * L) where L is the lepton contained length
108  bool cutKMEC; //!< Whether to remove MEC events (useful for studying difference w.r.t. proposal)
109  bool onlyKMEC; //!< Whether to remove all non-MEC events
112  double selectionEfficiency; //!< Signal efficiency weight applied to signal (charged current) events
113  double backgroundRejection; //!< Rejection applied to background (NC) events
114  std::vector<std::string> uniformWeights; //!< Weights taken from "EventWeight" that should be applied to the weight of each event
115  double constantWeight; //!< constant weight to apply uniformly to each event
116  double constantCCWeight; //!< constant weight to apply to each CC event
117  double constantNCWeight; //!< constant weight to apply to each NC event
118  double constantEnergyScale; //!< constant scale to apply to reco_energy calculation
119  };
120 
121  /** Histograms made for output */
122  struct RootHistos {
123  TH1D *h_numu_ccqe; //!< histogram w/ CCQE energy veriable [GeV]
124  TH1D *h_numu_trueE; //!< histogram w/ truth energy variable [GeV]
125  TH1D *h_numu_visibleE; //!< histogram w/ visible energy variable (total muon momentum + kinetic hadron energy) [GeV]
126  TH1D *h_numu_true_v_visibleE; //!< histogram w/ difference of visible and truth energy [GeV]
127  TH1D *h_numu_t_is_contained; //!< histogram w/ whether associated track is contained in AV
128  TH1D *h_numu_contained_L; //!< histogram w/ FV contained length of track in CC event [cm]
129  TH1D *h_numu_t_length; //!< histogram w/ total length of associated track [cm]
130  TH1D *h_numu_t_is_muon; //!< histogram of whether associated track is a muon
131  //TH1D *h_numu_m_energy_true; //!< histogram of truth energy of muon (excludes background pions)
132  //TH1D *h_numu_m_energy_smeared; //!< histogram of smeared energy of muon (excludes background pions)
133  TH2D *h_numu_Vxy; //!< 2D x-y vertex histogram [cm]
134  TH2D *h_numu_Vxz; //!< 2D x-z vertex histogram [cm]
135  TH2D *h_numu_Vyz; //!< 2D y-z vertex histogram [cm]
142  TH1D *h_numu_t_is_muon_sig; //!< histogram of whether associated track is a muon
143  TH1D *h_numu_t_is_muon_bkg; //!< histogram of whether associated track is a muon
144  };
145 
146  // helper struct holding track info -- see NumuInteraction for variable details
147  struct TrackInfo {
148  bool t_is_contained; //!< whether the (maybe faked) lepton track is totally contained in the active volume
149  double t_contained_length; //!< the length of the (maybe faked) lepton track contained in the active volume [cm]
150  double t_length; //!< total length of (maybe faked) lepton track [cm]
151  };
152 
153  static const unsigned nCuts = 5; //!< number of cuts
154 
155  /* Applies FV cut
156  * \param v The neutrino interaction vertex
157  * \return Whether to apply FV cut on neutrino
158  *
159  * */
160  bool passFV(const TVector3 &v) { return !_config.doFVCut ||containedInFV(v); }
161 
162  /** Applies reco-truth vertex matching cut
163  * \param truth_v Truth vertex vector
164  * \param reco_v Reconstructed vertex vector
165  * \return Whether to apply reco-truth vertex matching cut: true == passed cut
166  * */
167  bool passRecoVertex(const TVector3 &truth_v, const TVector3 &reco_v);
168 
169  /** Applies truth length cut
170  * \param length Distance travelled by lepton
171  * \param stop_in_tpc Whether the lepton stopped in the TPC volume
172  * \return Whether to apply length cut: true == passed cut
173  * */
174  bool passMinLength(double length, bool stop_in_tpc);
175 
176  /** Run Selection on a neutrino
177  * \param ev The gallery event.
178  * \param mctruth The mctruth object associated with the currently considered interaction.
179  * \param truth_ind The index into the vector of MCTruth objects in the gallery event from which the "mctruth" object is
180  * \param intInfo The interaction info object associated with this mctruth object.
181  *
182  * \return A list containing whether the interaction passed each cut (ordered in the same way as the "cutNames()")
183  * */
184  std::array<bool, nCuts> Select(const gallery::Event& ev, const simb::MCTruth& mctruth, unsigned truth_ind, const NumuSelection::NuMuInteraction &intInfo);
185 
186  /** Get associated interaction information from monte carlo
187  * \param ev The gallery event.
188  * \param mctruth The mctruth object associated with the currently considered interaction.
189  *
190  * \return NuMuInteraction object containing information from the mctruth object
191  * */
192  NuMuInteraction interactionInfo(const gallery::Event& ev, const simb::MCTruth &mctruth, VisibleEnergyCalculator &calculator);
193 
194  /** Get the interaction info associated with a track. This works right now because
195  * all interaction info comes from the primary track. Might have to re-think structure
196  * going forward.
197  *
198  * \param track The primary track.
199  * \return Interaction info filled in from this track.
200  */
201  TrackInfo trackInfo(const sim::MCTrack &track);
202 
203  /** Helper function -- whether point is contained in fiducial volume list
204  * \param v The point vector.
205  *
206  * \return Whether the point is contained in the configured list of fiducial volumes.
207  * */
208  bool containedInFV(const TVector3 &v);
209 
210  /** Helper function -- whether point is contained in active volume list
211  * \param v The point vector.
212  *
213  * \return Whether the point is contained in the configured list of active volumes.
214  * */
215  bool containedInAV(const TVector3 &v);
216 
217  unsigned _event_counter; //!< Count processed events
218  unsigned _nu_count; //!< Count selected events
219  TGraph *_cut_counts; //!< Keep track of neutrinos per cut
220 
221  /** Names of cuts
222  * \return List of names of cuts (for histogram names)
223  * */
224  static const std::array<std::string, nCuts> cutNames() {
225  return {"MEC", "AV", "Track", "FV", "min_L"};
226  }
227 
228  TRandomMT64 _rand; //!< random number generation
229  Config _config; //!< The config
230 
231  std::vector<NuMuInteraction> *_interactionInfo; //!< Branch holder
232 
233  RootHistos _root_histos[nCuts]; //!< Histos (one group per cut)
234 
235  std::map<std::string, double> _eventCategories;
236 };
237 
238  } // namespace SBNOsc
239 } // namespace ana
240 
241 #endif // __sbnanalysis_ana_SBNOsc_NumuSelection__
242 
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.
Definition: NumuSelection.h:91
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.
double constantEnergyScale
constant scale to apply to reco_energy calculation
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]
double t_length
total length of (maybe faked) lepton track [cm]
bool containedInAV(const TVector3 &v)
double trackVisibleEnergyThreshold
Energy threshold for track to be acounted in visible energy calculation [GeV].
TH1D * h_numu_ccqe
histogram w/ CCQE energy veriable [GeV]
TH2D * h_numu_Vxy
2D x-y vertex histogram [cm]
bool verbose
Whether to print out info associated w/ selection.
Definition: NumuSelection.h:95
TH1D * h_numu_t_is_muon
histogram of whether associated track is a muon
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)
std::vector< geoalgo::AABox > fiducial_volumes
List of FV containers – set by &quot;fiducial_volumes&quot;.
Definition: NumuSelection.h:92
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.
TH1D * h_numu_t_is_muon_sig
histogram of whether associated track is a muon
bool onlyKMEC
Whether to remove all non-MEC events.
double constantNCWeight
constant weight to apply to each NC event
Electron neutrino event selection.
Definition: NumuSelection.h:44
void Initialize(fhicl::ParameterSet *config=NULL)
double t_length
total length of (maybe faked) lepton track [cm]
Definition: NumuSelection.h:72
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+)
Definition: NumuSelection.h:73
double leptonEnergyDistortionLeavingA
Parameter to be used in the energy distortion of primary lepton for visible energy calculation...
double minLengthContainedTrack
Minimum length [cm] of contained tracks. Will not apply cut if value is negative. ...
Definition: NumuSelection.h:98
process_name standard_reco_uboone reco
double t_contained_length
the length of the (maybe faked) lepton track contained in the active volume [cm]
Definition: NumuSelection.h:71
double constantCCWeight
constant weight to apply to each CC event
std::vector< std::string > uniformWeights
Weights taken from &quot;EventWeight&quot; 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)
Base class for event selections.
double minLengthExitingTrack
Minimum length [cm] of exiting tracks. Will not apply cut if value is negative.
Definition: NumuSelection.h:99
TH1D * h_numu_trueE
histogram w/ truth energy variable [GeV]
Class def header for mctrack data container.
double t_energy_smeared
Smeared energy of primary track [GeV].
Definition: NumuSelection.h:75
TH1D * h_numu_true_v_visibleE
histogram w/ difference of visible and truth energy [GeV]
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)
unsigned _event_counter
Count processed events.
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]
bool trajPointLength
Whether to use trajectory points to calculate length.
Definition: NumuSelection.h:97
std::vector< geoalgo::AABox > active_volumes
List of active volumes.
Definition: NumuSelection.h:93
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 selectionEfficiency
Signal efficiency weight applied to signal (charged current) events.
bool t_is_contained
whether the (maybe faked) lepton track is totally contained in the active volume
Definition: NumuSelection.h:70
static const std::array< std::string, nCuts > cutNames()
TH1D * h_numu_t_is_contained
histogram w/ whether associated track is contained in AV
bool acceptShakyTracks
Whether to calculate length of tracks that don&#39;t have all points generated.
Definition: NumuSelection.h:96
double vertexDistanceCut
Value of max distance [cm] between truth and reconstructed vertex. Will not apply cut if value is neg...
Definition: NumuSelection.h:94
double t_energy_true
True energy of primary track [GeV].
Definition: NumuSelection.h:74
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]
bool passMinLength(double length, bool stop_in_tpc)