LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
ParticleFilters.h
Go to the documentation of this file.
1 
10 #ifndef LARSIM_LARG4_PARTICLEFILTERS_H
11 #define LARSIM_LARG4_PARTICLEFILTERS_H
12 
13 // LArSoft libraries
14 
15 // ROOT libraries
16 #include "TGeoVolume.h"
17 #include "TGeoMatrix.h" // TGeoCombiTrans
18 #include "TLorentzVector.h"
19 #include "TVector3.h"
20 
21 // C/C++ standard libraries
22 #include <array>
23 #include <vector>
24 #include <utility> // std::move()
25 
26 
27 namespace larg4 {
28 
36 
37 
49  public:
50 
51  using Point_t = std::array<double, 3>;
52 
55  struct VolumeInfo_t {
56  VolumeInfo_t(TGeoVolume const* new_vol, TGeoCombiTrans const* new_trans)
57  : vol(new_vol), trans(new_trans) {}
58 
59  TGeoVolume const* vol;
60  TGeoCombiTrans const* trans;
61  }; // VolumeInfo_t
62 
63  using AllVolumeInfo_t = std::vector<VolumeInfo_t>;
64 
68  PositionInVolumeFilter(std::vector<VolumeInfo_t> const& volumes)
69  : volumeInfo(volumes)
70  {}
71  PositionInVolumeFilter(std::vector<VolumeInfo_t>&& volumes)
72  : volumeInfo(std::move(volumes))
73  {}
75 
86  bool mustKeep(Point_t const& pos) const
87  {
88  // if no volume is specified, it means we don't filter
89  if (volumeInfo.empty()) return true;
90  double local[3];
91  for(auto const& info: volumeInfo) {
92  // transform the point to relative to the volume
93  info.trans->MasterToLocal(pos.data(), local);
94  // containment check
95  if (info.vol->Contains(local)) return true;
96  } // for volumes
97  return false;
98  } // mustKeep()
99 
100  bool mustKeep(TVector3 const& pos) const
101  { return mustKeep(Point_t{{ pos.X(), pos.Y(), pos.Z() }}); }
102 
103  bool mustKeep(TLorentzVector const& pos) const
104  { return mustKeep(Point_t{{ pos.X(), pos.Y(), pos.Z() }}); }
105 
106 
107  protected:
108  std::vector<VolumeInfo_t> volumeInfo;
109 
110  }; // PositionInVolumeFilter
111 
112 } // namespace larg4
113 
114 #endif // LARSIM_LARG4_PARTICLEFILTERS_H
bool mustKeep(TVector3 const &pos) const
std::vector< VolumeInfo_t > AllVolumeInfo_t
bool mustKeep(TLorentzVector const &pos) const
std::vector< VolumeInfo_t > volumeInfo
all good volumes
Geant4 interface.
TGeoCombiTrans const * trans
volume transformation (has both ways)
STL namespace.
VolumeInfo_t(TGeoVolume const *new_vol, TGeoCombiTrans const *new_trans)
TGeoVolume const * vol
ROOT volume.
std::array< double, 3 > Point_t
bool mustKeep(Point_t const &pos) const
Returns whether a track along the specified point must be kept.
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.
PositionInVolumeFilter(std::vector< VolumeInfo_t > &&volumes)
Constructors: read the volumes from the specified list.