EmLikeHits_module.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // EmLikeHits class
4 //
5 // robert.sulej@cern.ch
6 //
7 // This module produces new hit container with hadron/muon-like hits subtracted. The
8 // goal is to provide EM cascade-like hits as input to clustering algorithms that
9 // expect EM showers not tracks.
10 //
11 // Module needs reconstructed and tagged tracks on its input. For the moment tagging
12 // is encoded in the track ID - TO BE CHANGED TO A SIMPLE DATA PRODUCT ASSIGNED TO
13 // TRACK.
14 //
15 // Also hits unmatched to any track are checked if they are not very close to any of
16 // hadron/muon tracks. The distance is calculated in 2D projection, using track
17 // trajectory points. As soon as pma::Tracks are able to produce assiciated data
18 // product with node description the distance will use NODES INSTEAD OF TRAJECTORY
19 // POINTS since many trajectory points may belong to single linear segment.
20 //
21 ///////////////////////////////////////////////////////////////////////////////////////
22 
23 
31 #include "fhiclcpp/ParameterSet.h"
33 
34 // LArSoft includes
44 
45 namespace dune {
46 
47 class EmLikeHits : public art::EDProducer {
48 
49 public:
50 
51  explicit EmLikeHits(fhicl::ParameterSet const & p);
52 
53  EmLikeHits(EmLikeHits const &) = delete;
54 
55  EmLikeHits(EmLikeHits &&) = delete;
56 
57  EmLikeHits & operator = (EmLikeHits const &) = delete;
58 
59  EmLikeHits & operator = (EmLikeHits &&) = delete;
60 
61  void reconfigure(fhicl::ParameterSet const& p);
62 
63  void produce(art::Event & e) override;
64 
65 private:
66 
69  const std::vector<recob::Track>& tracks,
70  const art::FindManyP< recob::Hit >& fbp);
71 
73  detinfo::DetectorPropertiesData const& detProp,
75  const std::vector<recob::Track>& tracks,
76  const art::FindManyP< recob::Hit >& fbp);
77 
78  bool isCloseToTrack(
79  TVector2 p, const recob::Track& trk,
80  unsigned int view,
81  unsigned int tpc,
82  unsigned int cryo);
83 
84  static double getDist2(
85  const TVector2& psrc,
86  const TVector2& p0,
87  const TVector2& p1);
88 
89 // ******************** parameters **********************
90 
93 
94 };
95 // ------------------------------------------------------
96 
98 {
99  this->reconfigure(p);
100  produces< std::vector<recob::Hit> >();
101 }
102 // ------------------------------------------------------
103 
105 {
106  fHitModuleLabel = pset.get< std::string >("HitModuleLabel");
107  fTrk3DModuleLabel = pset.get< std::string >("Trk3DModuleLabel");
108 }
109 // ------------------------------------------------------
110 
112  std::vector< art::Ptr<recob::Hit> >& hitlist,
113  const std::vector<recob::Track>& tracks,
114  const art::FindManyP< recob::Hit >& fbp)
115 {
116  for (size_t t = 0; t < tracks.size(); t++)
117  if (!(tracks[t].ID() & 0x10000))
118  {
119  std::vector< art::Ptr<recob::Hit> > v = fbp.at(t);
120  mf::LogVerbatim("EmLikeHits") << " track-like trajectory: " << v.size() << std::endl;
121  size_t ih = 0;
122  while (ih < hitlist.size())
123  {
124  bool found = false;
125  for (size_t it = 0; it < v.size(); it++)
126  if (v[it].key() == hitlist[ih].key())
127  {
128  found = true; break;
129  }
130  if (found) hitlist.erase(hitlist.begin() + ih);
131  else ih++;
132  }
133  }
134 }
135 // ------------------------------------------------------
136 
138  unsigned int view, unsigned int tpc, unsigned int cryo)
139 {
141  double wirePitch = geom->TPC(tpc, cryo).Plane(view).WirePitch();
142 
143  //double driftPitch = detProp.GetXTicksCoefficient(tpc, cryo);
144 
145  double max_d2_d = 0.3 * 0.3;
146  double max_d2_w = (wirePitch + 0.1) * (wirePitch + 0.1);
147 
148  bool isClose = false;
149  for (size_t i = 0; i < trk.NumberTrajectoryPoints() - 1; ++i)
150  {
151  TVector2 p0 = pma::GetVectorProjectionToPlane(trk.LocationAtPoint<TVector3>(i), view, tpc, cryo);
152  TVector2 p1 = pma::GetVectorProjectionToPlane(trk.LocationAtPoint<TVector3>(i + 1), view, tpc, cryo);
153  double d2 = getDist2(p, p0, p1);
154 
155  double dpx = fabs(p0.X() - p1.X());
156  double dpy = fabs(p0.Y() - p1.Y());
157 
158  if (((dpx > 0.5 * dpy) && (d2 < max_d2_d)) || (d2 < max_d2_w))
159  {
160  isClose = true; break;
161  }
162  }
163  return isClose;
164 }
165 // ------------------------------------------------------
166 
168  detinfo::DetectorPropertiesData const& detProp,
169  std::vector< art::Ptr<recob::Hit> >& hitlist,
170  const std::vector<recob::Track>& tracks,
171  const art::FindManyP< recob::Hit >& fbp)
172 {
173  size_t ih = 0;
174  while (ih < hitlist.size())
175  {
176  bool unmatched = true, close = false;;
177  for (size_t t = 0; t < tracks.size(); t++)
178  {
179  std::vector< art::Ptr<recob::Hit> > v = fbp.at(t);
180  for (size_t it = 0; it < v.size(); it++)
181  if (v[it].key() == hitlist[ih].key())
182  {
183  unmatched = false; break;
184  }
185  if (!unmatched) break;
186  }
187  if (unmatched)
188  {
189  unsigned int plane = hitlist[ih]->WireID().Plane;
190  unsigned int tpc = hitlist[ih]->WireID().TPC;
191  unsigned int cryo = hitlist[ih]->WireID().Cryostat;
192 
193  TVector2 hcm = pma::WireDriftToCm(detProp,
194  hitlist[ih]->WireID().Wire, hitlist[ih]->PeakTime(), plane, tpc, cryo);
195 
196  for (size_t t = 0; t < tracks.size(); t++)
197  if (!(tracks[t].ID() & 0x10000) &&
198  isCloseToTrack(hcm, tracks[t], plane, tpc, cryo))
199  {
200  close = true; break;
201  }
202  }
203  if (close) hitlist.erase(hitlist.begin() + ih);
204  else ih++;
205  }
206 }
207 // ------------------------------------------------------
208 
210 {
211  std::unique_ptr< std::vector< recob::Hit > > not_track_hits(new std::vector< recob::Hit >);
212 
213  std::vector< art::Ptr<recob::Hit> > hitlist;
214  auto hitListHandle = evt.getHandle< std::vector<recob::Hit> >(fHitModuleLabel);
215  auto trkListHandle = evt.getHandle< std::vector<recob::Track> >(fTrk3DModuleLabel);
216 
217  if (hitListHandle && trkListHandle)
218  {
219  art::FindManyP< recob::Hit > fbp(trkListHandle, evt, fTrk3DModuleLabel);
220 
221  art::fill_ptr_vector(hitlist, hitListHandle);
222  mf::LogVerbatim("EmLikeHits") << "all hits: " << hitlist.size() << std::endl;
223 
224  removeHitsAssignedToTracks(hitlist, *trkListHandle, fbp);
225  auto const detProp =
227  removeUnmatchedHitsCloseToTracks(detProp, hitlist, *trkListHandle, fbp);
228 
229  for (auto const& hit : hitlist) not_track_hits->push_back(recob::Hit(*hit));
230  mf::LogVerbatim("EmLikeHits") << "remaining not track-like hits: " << not_track_hits->size() << std::endl;
231  }
232  evt.put(std::move(not_track_hits));
233 }
234 // ------------------------------------------------------
235 
236 double EmLikeHits::getDist2(const TVector2& psrc, const TVector2& p0, const TVector2& p1)
237 {
238  TVector2 v0(psrc); v0 -= p0;
239  TVector2 v1(p1); v1 -= p0;
240 
241  TVector2 v2(psrc); v2 -= p1;
242  TVector2 v3(v1); v3 *= -1.0;
243 
244  double v0Norm2 = v0.Mod2();
245  double v1Norm2 = v1.Mod2();
246 
247  double eps = 1.0E-7; // 0.001mm
248  if (v1Norm2 > eps)
249  {
250  double mag01 = sqrt(v0Norm2 * v1Norm2);
251  double cosine01 = 0.0;
252  if (mag01 != 0.0) cosine01 = v0 * v1 / mag01;
253 
254  double v2Norm2 = v2.Mod2();
255  double mag23 = sqrt(v2Norm2 * v3.Mod2());
256  double cosine23 = 0.0;
257  if (mag23 != 0.0) cosine23 = v2 * v3 / mag23;
258 
259  double result = 0.0;
260  if ((cosine01 > 0.0) && (cosine23 > 0.0))
261  {
262  result = (1.0 - cosine01 * cosine01) * v0Norm2;
263  }
264  else
265  {
266  if (cosine01 <= 0.0) result = v0Norm2;
267  else result = v2Norm2;
268  }
269 
270  if (result >= 0.0) return result;
271  else return 0.0;
272  }
273  else
274  {
275  v1 = p0; v1 += p1; v1 *= 0.5;
276  return pma::Dist2(v1, psrc);
277  }
278 }
279 // ------------------------------------------------------
280 
282 
283 } // namespace dune
void produce(art::Event &e) override
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
void removeUnmatchedHitsCloseToTracks(detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit > > &hitlist, const std::vector< recob::Track > &tracks, const art::FindManyP< recob::Hit > &fbp)
static QCString result
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:37
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
unsigned int ID
Point_t const & LocationAtPoint(size_t i) const
Definition: Track.h:126
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
std::string fHitModuleLabel
struct vector vector
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:102
TVector2 WireDriftToCm(detinfo::DetectorPropertiesData const &detProp, unsigned int wire, float drift, unsigned int plane, unsigned int tpc, unsigned int cryo)
Definition: Utilities.cxx:294
EmLikeHits(fhicl::ParameterSet const &p)
std::string fTrk3DModuleLabel
static double getDist2(const TVector2 &psrc, const TVector2 &p0, const TVector2 &p1)
art framework interface to geometry description
int close(int)
Closes the file descriptor fd.
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
def key(type, name=None)
Definition: graph.py:13
def move(depos, offset)
Definition: depos.py:107
T get(std::string const &key) const
Definition: ParameterSet.h:271
void removeHitsAssignedToTracks(std::vector< art::Ptr< recob::Hit > > &hitlist, const std::vector< recob::Track > &tracks, const art::FindManyP< recob::Hit > &fbp)
p
Definition: test.py:223
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
TVector2 GetVectorProjectionToPlane(const TVector3 &v, unsigned int plane, unsigned int tpc, unsigned int cryo)
Definition: Utilities.cxx:281
Detector simulation of raw signals on wires.
Encapsulate the geometry of a wire.
Definition: tracks.py:1
Implementation of the Projection Matching Algorithm.
Declaration of signal hit object.
Encapsulate the construction of a single detector plane.
Provides recob::Track data product.
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
EmLikeHits & operator=(EmLikeHits const &)=delete
PlaneGeo const & Plane(geo::View_t view) const
Return the plane in the tpc with View_t view.
Definition: TPCGeo.cxx:263
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
TCEvent evt
Definition: DataStructs.cxx:7
void reconfigure(fhicl::ParameterSet const &p)
bool isCloseToTrack(TVector2 p, const recob::Track &trk, unsigned int view, unsigned int tpc, unsigned int cryo)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
double WirePitch() const
Return the wire pitch (in centimeters). It is assumed constant.
Definition: PlaneGeo.h:411
QTextStream & endl(QTextStream &s)
Encapsulate the construction of a single detector plane.