LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ParticleFilters.h
Go to the documentation of this file.
1 
10 #ifndef LARCOREALG_COREUTILS_PARTICLEFILTERS_H
11 #define LARCOREALG_COREUTILS_PARTICLEFILTERS_H
12 
13 // LArSoft libraries
14 
15 // ROOT libraries
16 #include "TGeoMatrix.h" // TGeoCombiTrans
17 #include "TGeoVolume.h"
18 #include "TLorentzVector.h"
19 #include "TVector3.h"
20 
21 // C/C++ standard libraries
22 #include <array>
23 #include <utility> // std::move()
24 #include <vector>
25 
26 namespace util {
27 
35 
47  public:
48  using Point_t = std::array<double, 3>;
49 
52  struct VolumeInfo_t {
53  VolumeInfo_t(TGeoVolume const* new_vol, TGeoCombiTrans const* new_trans)
54  : vol(new_vol), trans(new_trans)
55  {}
56 
57  TGeoVolume const* vol;
58  TGeoCombiTrans const* trans;
59  }; // VolumeInfo_t
60 
61  using AllVolumeInfo_t = std::vector<VolumeInfo_t>;
62 
66  PositionInVolumeFilter(std::vector<VolumeInfo_t> const& volumes) : volumeInfo(volumes) {}
67  PositionInVolumeFilter(std::vector<VolumeInfo_t>&& volumes) : volumeInfo(std::move(volumes)) {}
69 
80  bool mustKeep(Point_t const& pos) const
81  {
82  // if no volume is specified, it means we don't filter
83  if (volumeInfo.empty()) return true;
84  double local[3];
85  for (auto const& info : volumeInfo) {
86  // transform the point to relative to the volume
87  info.trans->MasterToLocal(pos.data(), local);
88  // containment check
89  if (info.vol->Contains(local)) return true;
90  } // for volumes
91  return false;
92  } // mustKeep()
93 
94  bool mustKeep(TVector3 const& pos) const
95  {
96  return mustKeep(Point_t{{pos.X(), pos.Y(), pos.Z()}});
97  }
98 
99  bool mustKeep(TLorentzVector const& pos) const
100  {
101  return mustKeep(Point_t{{pos.X(), pos.Y(), pos.Z()}});
102  }
103 
104  protected:
105  std::vector<VolumeInfo_t> volumeInfo;
106 
107  }; // PositionInVolumeFilter
108 
109 } // namespace util
110 
111 #endif // LARCOREALG_COREUTILS_PARTICLEFILTERS_H
bool mustKeep(Point_t const &pos) const
Returns whether a track along the specified point must be kept.
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:26
std::vector< VolumeInfo_t > volumeInfo
all good volumes
std::array< double, 3 > Point_t
std::vector< VolumeInfo_t > AllVolumeInfo_t
TGeoVolume const * vol
ROOT volume.
STL namespace.
PositionInVolumeFilter(std::vector< VolumeInfo_t > &&volumes)
Constructors: read the volumes from the specified list.
bool mustKeep(TLorentzVector const &pos) const
TGeoCombiTrans const * trans
volume transformation (has both ways)
bool mustKeep(TVector3 const &pos) const
VolumeInfo_t(TGeoVolume const *new_vol, TGeoCombiTrans const *new_trans)
PositionInVolumeFilter(std::vector< VolumeInfo_t > const &volumes)
Constructors: read the volumes from the specified list.
Use to keep particles with at least part of trajectory in a volume.