All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Cuts.cc
Go to the documentation of this file.
1 #include "Cuts.h"
2 #include "../Histograms/Derived.h"
3 #include "../RecoUtils/GeoUtil.h"
4 #include "../TriggerEmulator/PMTTrigger.h"
5 #include "../NumuReco/TrackAlgo.h"
6 
7 namespace ana {
8  namespace SBNOsc {
9 
10 void Cuts::Initialize(const fhicl::ParameterSet &cfg, const geo::GeometryCore *geometry) {
11  fConfig.active_volumes.clear();
12  fConfig.fiducial_volumes.clear();
13 
14  fConfig.UseTrueVertex = cfg.get<bool>("UseTrueVertex", false);
15  fConfig.trackMatchCompletionCut = cfg.get<double>("trackMatchCompletionCut", -1);
17  fConfig.TruthCompletion = cfg.get<float>("TruthCompletion", 0.5);
18  fConfig.TruthMatchDist = cfg.get<float>("TruthMatchDist", 5.);
19 
20  fConfig.MCSTrackLength = cfg.get<float>("MCSTrackLength", 100.);
21  fConfig.TrackLength = cfg.get<float>("TrackLength", 50.);
22 
23  fConfig.CRTHitDist = cfg.get<float>("CRTHitDist", 35.);
24  fConfig.CRTHitTimeRange = cfg.get<std::array<float, 2>>("CRTHitTimeRange", {-0.2, 2.0});
25  fConfig.CRTActivityTimeRange = cfg.get<std::array<float, 2>>("CRTActivityTimeRange", {-0.2, 2.0});
26  fConfig.CRTTrackAngle = cfg.get<float>("CRTTrackAngle", 0.4);
27 
28  fConfig.TruthFlashMatch = cfg.get<bool>("TruthFlashMatch", false);
29  fConfig.FlashMatchScore = cfg.get<float>("FlashMatchScore", 10.);
30 
31  fConfig.PMTTriggerTreshold = cfg.get<int>("PMTTriggerTreshold", 7950);
32  fConfig.PMTNAboveThreshold = cfg.get<unsigned>("PMTNAboveThreshold", 5);
33 
34  fConfig.CRTActivityPEThreshold = cfg.get<float>("CRTActivityPEThreshold", 100.);
35 
36  fConfig.CutOrder = cfg.get<std::vector<std::string>>("CutOrder");
37  fConfig.TruthCutOrder = cfg.get<std::vector<std::string>>("TruthCutOrder");
38 
39  {
40  fhicl::ParameterSet dFV = \
41  cfg.get<fhicl::ParameterSet>("fiducial_volume_inset");
42  double dx = dFV.get<double>("x");
43  double dy = dFV.get<double>("y");
44  double zfront = dFV.get<double>("zfront");
45  double zback = dFV.get<double>("zback");
46  for (const geo::BoxBoundedGeo &geo: fConfig.active_volumes) {
47  fConfig.fiducial_volumes.emplace_back(geo.MinX() + dx, geo.MaxX() - dx, geo.MinY() + dy, geo.MaxY() - dy, geo.MinZ() + zfront, geo.MaxZ() - zback);
48  }
49  }
50 
51  {
52  fhicl::ParameterSet dFV = \
53  cfg.get<fhicl::ParameterSet>("calorimetric_containment_volume_inset");
54  double dx = dFV.get<double>("x");
55  double dy = dFV.get<double>("y");
56  double zfront = dFV.get<double>("zfront");
57  double zback = dFV.get<double>("zback");
58  for (const geo::BoxBoundedGeo &geo: fConfig.active_volumes) {
59  fConfig.calorimetric_containment_volumes.emplace_back(geo.MinX() + dx,
60  geo.MaxX() - dx,
61  geo.MinY() + dy,
62  geo.MaxY() - dy,
63  geo.MinZ() +
64  zfront,
65  geo.MaxZ() -zback);
66  }
67  }
68 
69  {
70  fhicl::ParameterSet dFV = \
71  cfg.get<fhicl::ParameterSet>("cosmic_containment_volume_inset");
72  double ytop = dFV.get<double>("ytop");
73  double ybottom = dFV.get<double>("ybottom");
74  double zfront = dFV.get<double>("zfront");
75  double zback = dFV.get<double>("zback");
76  for (const geo::BoxBoundedGeo &geo: fConfig.active_volumes) {
77  VolYZ contain;
78  contain.Y = {geo.MinY() + ybottom, geo.MaxY() - ytop};
79  contain.Z = {geo.MinZ() + zfront, geo.MaxZ() - zback};
80  fConfig.cosmic_containment_volumes.emplace_back(contain);
81  }
82  }
83 
84 }
85 
86 std::array<bool, Cuts::nTruthCuts> Cuts::ProcessTruthCuts(const numu::RecoEvent &event, const event::Event &core, unsigned truth_vertex_index, bool SequentialCuts) const {
87  std::map<std::string, bool> cuts;
88  cuts["Truth"] = true;
89 
90 
91  cuts["T_fid"] = InFV(core.truth[truth_vertex_index].neutrino.position);
92 
93  cuts["T_trig"] = PassFlashTrigger(event);
94 
95  cuts["T_vqual"] = (fConfig.TruthMatchDist < 0. ||
96  dist2Match(core.truth[truth_vertex_index], event.reco) < fConfig.TruthMatchDist);
97  cuts["T_tqual"] = (fConfig.TruthCompletion < 0. ||
98  trackMatchCompletion(truth_vertex_index, event) > fConfig.TruthCompletion);
99 
100  bool has_reco = false;
101  for (unsigned i = 0; i < event.reco.size(); i++) {
102  const numu::RecoTrack &primary_track = event.tracks.at(event.reco[i].slice.primary_track_index);
103  if (event.reco[i].match.has_match &&
104  event.reco[i].match.mctruth_track_id == truth_vertex_index &&
105  primary_track.match.is_primary) {
106  has_reco = true;
107  break;
108  }
109  }
110  cuts["T_reco"] = has_reco;
111 
112  std::array<bool, Cuts::nTruthCuts> ret;
113  for (unsigned i = 0; i < fConfig.TruthCutOrder.size(); i++) {
114  if (SequentialCuts && i > 0) ret[i] = ret[i-1] && cuts.at(fConfig.TruthCutOrder[i]);
115  else ret[i] = cuts.at(fConfig.TruthCutOrder[i]);
116  }
117  return ret;
118 
119 }
120 
121 bool Cuts::PassFlashTrigger(const numu::RecoEvent &event) const {
123 }
124 
125 std::array<bool, Cuts::nCuts> Cuts::ProcessRecoCuts(const numu::RecoEvent &event,
126  unsigned reco_vertex_index,
127  bool fSequentialCuts) const {
128  std::map<std::string, bool> cuts;
129  cuts["Reco"] = true;
130 
131  cuts["R_trig"] = PassFlashTrigger(event);
132 
133  // require an in-time flash time
134  bool has_intime_flash = false;
135  for (const numu::RecoInteraction &reco: event.reco) {
136  if (reco.slice.flash_match.present && reco.slice.flash_match.time > 0. /*intime*/) {
137  has_intime_flash = true;
138  break;
139  }
140  }
141  cuts["R_flashtime"] = has_intime_flash;
142 
143  // require fiducial
144  if (fConfig.UseTrueVertex) {
145  cuts["R_fid"] = false; // TODO: implement
146  }
147  else {
148  cuts["R_fid"] = InFV(event.reco[reco_vertex_index].position);
149  }
150 
151  const numu::RecoTrack &primary_track = event.tracks.at(event.reco[reco_vertex_index].slice.primary_track_index);
152 
153  // good_mcs = track contain OR (range momentum OR mcs trk length)
154  cuts["R_goodmcs"] = ( ( InCalorimetricContainment(primary_track.start) &&
155  InCalorimetricContainment(primary_track.end) ) ||
156  ( numu::MCSMomentum(primary_track) < 7. /*garbage value*/&&
157  (fConfig.MCSTrackLength <0. ||
158  primary_track.length > fConfig.MCSTrackLength) )
159  );
160 
161  // allow truth-based flash matching or reco based
162  bool time_in_spill = false;
163  if (primary_track.match.has_match) {
164  time_in_spill = TimeInSpill(event.particles.at(primary_track.match.mcparticle_id).start_time);
165  }
166 
167  if (fConfig.TruthFlashMatch) cuts["R_flashmatch"] = time_in_spill;
168  else cuts["R_flashmatch"] = fConfig.FlashMatchScore < 0. || (event.reco[reco_vertex_index].slice.flash_match.present && event.reco[reco_vertex_index].slice.flash_match.score < fConfig.FlashMatchScore);
169 
170  cuts["R_crttrack"] = !HasCRTTrackMatch(primary_track);
171 
172  cuts["R_crthit"] = ( !HasCRTHitMatch(primary_track) ||
173  TimeInSpill(CRTMatchTime(primary_track)) );
174 
175  cuts["R_length"] = fConfig.TrackLength < 0. ||
176  primary_track.length > fConfig.TrackLength;
177 
178  cuts["R_contained"] = ( InCosmicContainment(primary_track.start) &&
179  InCosmicContainment(primary_track.end) );
180 
181 
182  cuts["R_crtactive"] = true; //is_contained;
183  for (const numu::CRTHit &crt_hit: event.in_time_crt_hits) {
184  if ( TimeInSpill(crt_hit.time) &&
185  crt_hit.pes > fConfig.CRTActivityPEThreshold ) {
186  cuts["R_crtactive"] = false;
187  break;
188  }
189  }
190 
191  std::array<bool, Cuts::nCuts> ret;
192  for (unsigned i = 0; i < fConfig.CutOrder.size(); i++) {
193  if (fSequentialCuts && i > 0) ret[i] = ret[i-1] && cuts.at(fConfig.CutOrder[i]);
194  else ret[i] = cuts.at(fConfig.CutOrder[i]);
195  }
196  return ret;
197 }
198 
200  return track.crt_match.track.present &&
201  (fConfig.CRTTrackAngle < 0. ||
203 }
204 
206  return track.crt_match.hit_match.present &&
207  (fConfig.CRTHitDist < 0. ||
209 }
210 
212  if (HasCRTTrackMatch(track)) return track.crt_match.track.time;
213  if (HasCRTHitMatch(track)) return track.crt_match.hit_match.time;
214  return -99999;
215 }
216 
217 bool Cuts::TimeInSpill(float time) const {
218  return time > fConfig.CRTHitTimeRange[0] &&
219  time < fConfig.CRTHitTimeRange[1];
220 }
221 
222 bool Cuts::TimeInCRTActiveSpill(float time) const {
223  return time > fConfig.CRTActivityTimeRange[0] &&
224  time < fConfig.CRTActivityTimeRange[1];
225 }
226 
227 bool Cuts::InFV(const geo::Point_t &v) const {
228  for (auto const& FV: fConfig.fiducial_volumes) {
229  if (FV.ContainsPosition(v)) return true;
230  }
231  return false;
232 }
233 
234 bool Cuts::InFV(const TVector3 &v) const {
235  for (auto const& FV: fConfig.fiducial_volumes) {
236  if (FV.ContainsPosition(v)) return true;
237  }
238  return false;
239 }
240 
241 bool Cuts::InCalorimetricContainment(const TVector3 &v) const {
242  for (auto const& FV: fConfig.calorimetric_containment_volumes) {
243  if (FV.ContainsPosition(v)) return true;
244  }
245  return false;
246 }
247 
248 bool Cuts::InCosmicContainment(const TVector3 &v) const {
249  for (auto const& CV: fConfig.cosmic_containment_volumes) {
250  if (CV.Z[0] < v.Z()
251  && CV.Z[1] > v.Z()
252  && CV.Y[0] < v.Y()
253  && CV.Y[1] > v.Y()) {
254  return true;
255  }
256  }
257  return false;
258 }
259 
260 
261 /*
262 bool Cuts::SelectReco(std::array<bool, Cuts::nCuts> &cuts) {
263  return
264  cuts[0] &&
265  (cuts[1] || !fConfig.requireTrack) &&
266  (cuts[3] || !fConfig.requireMatched) &&
267  (cuts[4] || !fConfig.requireContained);
268 }
269 */
270  }
271 }
bool TimeInSpill(float time) const
Definition: Cuts.cc:217
Track track
CRT Track match.
Definition: CRTMatch.h:30
bool HasCRTHitMatch(const numu::RecoTrack &track) const
Definition: Cuts.cc:205
std::vector< geo::BoxBoundedGeo > ActiveVolumes(const geo::GeometryCore *geometry)
Definition: GeoUtil.cc:3
std::array< bool, nTruthCuts > ProcessTruthCuts(const numu::RecoEvent &event, const event::Event &core, unsigned truth_vertex_index, bool SequentialCuts=true) const
Definition: Cuts.cc:86
std::vector< geo::BoxBoundedGeo > active_volumes
float distance
//!&lt; Distance from projected track to CRT Hit. Nonsense if present is false.
Definition: CRTMatch.h:26
const geo::GeometryCore * geometry
std::vector< geo::BoxBoundedGeo > calorimetric_containment_volumes
CRTMatch crt_match
CRTMatch.
Definition: RecoTrack.h:59
bool present
Whether this CRTMatch has a matching track.
Definition: CRTMatch.h:16
int mcparticle_id
MCParticle ID of the particle this track matches to (same as the ID of the RecoTrack of that particle...
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:88
bool HasCRTTrackMatch(const numu::RecoTrack &track) const
Definition: Cuts.cc:199
std::vector< geo::BoxBoundedGeo > fiducial_volumes
bool InCosmicContainment(const TVector3 &v) const
Definition: Cuts.cc:248
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:91
std::array< bool, nCuts > ProcessRecoCuts(const numu::RecoEvent &event, unsigned reco_vertex_index, bool fSequentialCuts=true) const
Definition: Cuts.cc:125
process_name use argoneut_mc_hitfinder track
std::map< size_t, TrueParticle > particles
Map of indices to True particle information.
Definition: RecoEvent.h:49
process_name opflashCryoW ana
std::vector< CRTHit > in_time_crt_hits
List of crt hits in time with the beam spill.
Definition: RecoEvent.h:51
std::vector< RecoInteraction > reco
List of reconstructed vertices.
Definition: RecoEvent.h:50
process_name standard_reco_uboone reco
TVector3 start
start position of track
Definition: RecoTrack.h:54
FlashMatch flash_match
Result of flash matching algorithm on this slice.
Definition: RecoEvent.h:30
float length
Length of track.
Definition: RecoTrack.h:48
float MCSMomentum(const numu::RecoTrack &track)
Definition: TrackAlgo.cc:20
double MinZ() const
Returns the world z coordinate of the start of the box.
bool present
Whether this CRTMatch has a matching hit.
Definition: CRTMatch.h:25
bool InFV(const TVector3 &v) const
Definition: Cuts.cc:234
std::vector< FlashTriggerPrimitive > flash_trigger_primitives
List of trigger primitives from optical detectors.
Definition: RecoEvent.h:52
float time
CRT Hit time.
Definition: DetInfo.h:13
float CRTMatchTime(const numu::RecoTrack &track) const
Definition: Cuts.cc:211
Description of geometry of one entire detector.
bool PassFlashTrigger(const numu::RecoEvent &event) const
Definition: Cuts.cc:121
bool has_match
Whether a track match exists.
double MaxY() const
Returns the world y coordinate of the end of the box.
float dist2Match(const event::Interaction &truth, const std::vector< numu::RecoInteraction > &candidates)
Definition: Derived.cc:3
The standard event data definition.
Definition: Event.hh:228
bool is_primary
Whether this track was produced as the &quot;primary&quot; process.
TrackTruthMatch match
Truth matching information.
Definition: RecoTrack.h:57
RecoSlice slice
Particle content of the interaction.
Definition: RecoEvent.h:39
A base class aware of world box coordinatesAn object describing a simple shape can inherit from this ...
Definition: BoxBoundedGeo.h:33
double MaxZ() const
Returns the world z coordinate of the end of the box.
float pes
Number of PE&#39;s in hit.
Definition: DetInfo.h:15
float angle
Angle between TPC track and CRT track.
Definition: CRTMatch.h:18
float trackMatchCompletion(unsigned truth_index, const numu::RecoEvent &event)
Definition: Derived.cc:13
bool TimeInCRTActiveSpill(float time) const
Definition: Cuts.cc:222
TVector3 end
end position of track
Definition: RecoTrack.h:55
bool InCalorimetricContainment(const TVector3 &v) const
Definition: Cuts.cc:241
void Initialize(const fhicl::ParameterSet &cfg, const geo::GeometryCore *geometry)
Definition: Cuts.cc:10
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
double MinY() const
Returns the world y coordinate of the start of the box.
HitMatch hit_match
CRT Hit match.
Definition: CRTMatch.h:31
bool HasTrigger(const std::vector< FlashTriggerPrimitive > &primitives, int threshold, unsigned n_above_threshold)
Definition: PMTTrigger.cc:65
std::vector< Interaction > truth
All truth interactions.
Definition: Event.hh:232
float time
Matching time [us] of track. T==0 is set to beam spill start time.
Definition: CRTMatch.h:17