ParticleFilters.h
Go to the documentation of this file.
1 /**
2  * @file ParticleFilters.h
3  * @brief Defines classes to filter particles based on their trajectory.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date March 24, 2016
6  *
7  *
8  */
9 
10 #ifndef LARCOREALG_COREUTILS_PARTICLEFILTERS_H
11 #define LARCOREALG_COREUTILS_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 util {
28 
29  /**
30  * @brief Tag for filters
31  *
32  * A filter of this type acts on trajectory coordinates, and if it ever
33  * returns true, then the particle is safe.
34  */
36 
37 
38  /** **************************************************************************
39  * @brief Use to keep particles with at least part of trajectory in a volume
40  * @author Matt Bass, Gianluca Petrillo
41  *
42  * The class stores a list of pointers to volumes to consider.
43  * If a point specified in the mustKeep() call is within one of the blessed
44  * volumes, the whole track it belongs to must to be kept.
45  *
46  * No condition for prompt rejection is provided.
47  */
49  public:
50 
51  using Point_t = std::array<double, 3>;
52 
53  /// Due to the structure of ROOT geometry, volumes and their transformations
54  /// are not living in the same place; so we need to keep both.
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; ///< ROOT volume
60  TGeoCombiTrans const* trans; ///< volume transformation (has both ways)
61  }; // VolumeInfo_t
62 
63  using AllVolumeInfo_t = std::vector<VolumeInfo_t>;
64 
65  /// @{
66  /// @brief Constructors: read the volumes from the specified list
67  /// @param volumes list of interesting volumes
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  {}
74  /// @}
75 
76  /**
77  * @brief Returns whether a track along the specified point must be kept
78  * @param pos point on the track, a [x,y,z] array in "Geant4 coordinates"
79  * @brief whether a track along the specified point must be kept
80  *
81  * If the return value is true, the track must be kept.
82  * If the return value is false, no decision can be made yet.
83  * If no decision is made after the track is over, the track should be
84  * dropped.
85  */
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; ///< all good volumes
109 
110  }; // PositionInVolumeFilter
111 
112 } // namespace util
113 
114 #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.
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)
bool mustKeep(TLorentzVector const &pos) const
def move(depos, offset)
Definition: depos.py:107
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.