All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackCaloSkimmerSelectStoppingTrack_tool.cc
Go to the documentation of this file.
1 // Framework Includes
2 #include "art/Utilities/ToolMacros.h"
3 #include "fhiclcpp/ParameterSet.h"
4 
13 
14 #include "ITCSSelectionTool.h"
15 
16 namespace sbn {
17 
19 public:
20 
21  TrackCaloSkimmerSelectStoppingTrack(const fhicl::ParameterSet &p);
23 
24  bool Select(const TrackInfo &t) override;
25 
26 private:
27  // config
28  double fFVInsetMinX;
29  double fFVInsetMaxX;
30  double fFVInsetMinY;
31  double fFVInsetMaxY;
32  double fFVInsetMinZ;
33  double fFVInsetMaxZ;
34 
37 
41 
42  // Time info grabbed from Detector Properties
43  int fTickMin;
44  int fTickMax;
45 
46  // Geometry info grabbed from Detector Geometry
47  std::vector<std::vector<geo::BoxBoundedGeo>> fTPCVolumes;
48  std::vector<geo::BoxBoundedGeo> fActiveVolumes;
49 
50  // Fiducial space
51  std::vector<geo::BoxBoundedGeo> fFiducialVolumes;
52  // Fiducial time
53  double fFidTickMin;
54  double fFidTickMax;
56 
58 };
59 
62  fFVInsetMinX(p.get<double>("FVInsetMinX")),
63  fFVInsetMaxX(p.get<double>("FVInsetMaxX")),
64  fFVInsetMinY(p.get<double>("FVInsetMinY")),
65  fFVInsetMaxY(p.get<double>("FVInsetMaxY")),
66  fFVInsetMinZ(p.get<double>("FVInsetMinZ")),
67  fFVInsetMaxZ(p.get<double>("FVInsetMaxZ")),
68  fMinTimeTickInset(p.get<double>("MinTimeTickInset")),
69  fMaxTimeTickInset(p.get<double>("MaxTimeTickInset")),
70  fEndMediandQdxCut(p.get<double>("EndMediandQdxCut")),
71  fNumberTimeSamples(p.get<unsigned>("NumberTimeSamples")),
72  fRequireDownwards(p.get<bool>("RequireDownwards", true)),
73  fMediandQdxRRMax(p.get<double>("MediandQdxRRMax", 5.)),
74  fCheckFiducialX(p.get<bool>("CheckFiducialX"))
75 {
76  // Get the fiducial volume info
77  const geo::GeometryCore *geometry = lar::providerFrom<geo::Geometry>();
78 
79  // first the TPC volumes
80  for (auto const &cryo: geometry->IterateCryostats()) {
81  geo::GeometryCore::TPC_iterator iTPC = geometry->begin_TPC(cryo.ID()),
82  tend = geometry->end_TPC(cryo.ID());
83  std::vector<geo::BoxBoundedGeo> this_tpc_volumes;
84  while (iTPC != tend) {
85  geo::TPCGeo const& TPC = *iTPC;
86  this_tpc_volumes.push_back(TPC.ActiveBoundingBox());
87  iTPC++;
88  }
89  fTPCVolumes.push_back(std::move(this_tpc_volumes));
90  }
91 
92  // TODO: make configurable? Is this every not 0?
93  fTickMin = 0;
95 
98 
99  // then combine them into active volumes
100  for (const std::vector<geo::BoxBoundedGeo> &tpcs: fTPCVolumes) {
101  double XMin = std::min_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MinX() < rhs.MinX(); })->MinX();
102  double YMin = std::min_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MinY() < rhs.MinY(); })->MinY();
103  double ZMin = std::min_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MinZ() < rhs.MinZ(); })->MinZ();
104 
105  double XMax = std::max_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MaxX() < rhs.MaxX(); })->MaxX();
106  double YMax = std::max_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MaxY() < rhs.MaxY(); })->MaxY();
107  double ZMax = std::max_element(tpcs.begin(), tpcs.end(), [](auto &lhs, auto &rhs) { return lhs.MaxZ() < rhs.MaxZ(); })->MaxZ();
108 
109  fActiveVolumes.emplace_back(XMin, XMax, YMin, YMax, ZMin, ZMax);
110  }
111 
112  // And take the inset for the fiducial volumes
113  for (const geo::BoxBoundedGeo &AV: fActiveVolumes) {
114  fFiducialVolumes.emplace_back(AV.MinX() + fFVInsetMinX, AV.MaxX() - fFVInsetMaxX,
115  AV.MinY() + fFVInsetMinY, AV.MaxY() - fFVInsetMaxY,
116  AV.MinZ() + fFVInsetMinZ, AV.MaxZ() - fFVInsetMaxZ);
117  }
118 
119 }
120 
122  bool downwards = (t.dir.y < 0.) || !fRequireDownwards;
123 
124  bool end_is_fid = false;
125  for (const geo::BoxBoundedGeo &g: fFiducialVolumes) {
126  geo::Point_t end {t.end.x, t.end.y, t.end.z};
127 
128  bool is_contained = fCheckFiducialX ? g.ContainsPosition(end) : g.ContainsYZ(end.Y(), end.Z());
129 
130  if (is_contained) {
131  end_is_fid = true;
132  break;
133  }
134  }
135 
136  // Collection plane times need to be fiducial
137  bool time_is_fid = \
142 
143  // compute the median dqdx of the last few cm -- using fMediandQdxRRMax
144  std::vector<double> endp_dqdx;
145  for (const sbn::TrackHitInfo &h: t.hits2) {
146  if (h.oncalo && h.rr < fMediandQdxRRMax) endp_dqdx.push_back(h.dqdx);
147  }
148  double med_dqdx = -1;
149  if (endp_dqdx.size()) {
150  unsigned middle = endp_dqdx.size() / 2;
151  std::nth_element(endp_dqdx.begin(), endp_dqdx.begin() + middle, endp_dqdx.end());
152  med_dqdx = endp_dqdx[middle];
153 
154  // for even case
155  if (endp_dqdx.size() % 2 == 0) {
156  unsigned other_middle = middle - 1;
157  std::nth_element(endp_dqdx.begin(), endp_dqdx.begin() + other_middle, endp_dqdx.end());
158  med_dqdx = (med_dqdx + endp_dqdx[other_middle]) / 2.;
159  }
160  }
161 
162  bool valid_med_dqdx = ((med_dqdx > 0.) && (med_dqdx > fEndMediandQdxCut)) || (fEndMediandQdxCut < 0.);
163 
164  return downwards && end_is_fid && time_is_fid && valid_med_dqdx;
165 }
166 
167 DEFINE_ART_CLASS_TOOL(TrackCaloSkimmerSelectStoppingTrack)
168 
169 } // end namespace sbn
float hit_max_time_p2_tpcE
Max hit time of track on plane 2 TPC E.
Utilities related to art service access.
const geo::GeometryCore * geometry
pdgs p
Definition: selectors.fcl:22
Geometry information for a single TPC.
Definition: TPCGeo.h:38
float hit_min_time_p2_tpcE
Min hit time of track on plane 2 TPC E.
geo::BoxBoundedGeo const & ActiveBoundingBox() const
Returns the box of the active volume of this TPC.
Definition: TPCGeo.h:320
return track match has_match and!particle is_contained
Definition: selectors.fcl:108
static constexpr bool
std::vector< std::vector< geo::BoxBoundedGeo > > fTPCVolumes
Vector3D end
End position of track [cm].
BEGIN_PROLOG g
BEGIN_PROLOG TPC
TPC_iterator begin_TPC() const
Returns an iterator pointing to the first TPC in the detector.
float dqdx
Initial computed dq/dx of hit [ADC/cm].
while getopts h
Access the description of detector geometry.
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
Description of geometry of one entire detector.
bool Select(const TrackInfo &t) override
For children to implement: Whether to select a given track.
float rr
Residual range of hit along track [cm].
IteratorBox< cryostat_iterator,&GeometryCore::begin_cryostat,&GeometryCore::end_cryostat > IterateCryostats() const
Enables ranged-for loops on all cryostats of the detector.
float hit_min_time_p2_tpcW
Min hit time of track on plane 2 TPC W.
A base class aware of world box coordinatesAn object describing a simple shape can inherit from this ...
Definition: BoxBoundedGeo.h:33
std::vector< TrackHitInfo > hits2
List of hits on plane 2.
Forward iterator browsing all geometry elements in the detector.
Definition: GeometryCore.h:727
Vector3D dir
Direction of track.
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
bool oncalo
Whether the hit is on the track calorimetry.
float hit_max_time_p2_tpcW
Max hit time of track on plane 2 TPC W.
BEGIN_PROLOG don t mess with this pandoraTrackGausCryoW true
art framework interface to geometry description
TPC_iterator end_TPC() const
Returns an iterator pointing after the last TPC in the detector.