YAP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Filters.h
Go to the documentation of this file.
1 /* YAP - Yet another PWA toolkit
2  Copyright 2015, Technische Universitaet Muenchen,
3  Authors: Daniel Greenwald, Johannes Rauch
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
20 
21 #ifndef yap__Filters_h
22 #define yap__Filters_h
23 
24 #include "fwd/Filters.h"
25 
26 #include "fwd/DecayChannel.h"
27 #include "fwd/DecayingParticle.h"
28 #include "fwd/DecayTree.h"
29 #include "fwd/FinalStateParticle.h"
30 #include "fwd/FreeAmplitude.h"
31 #include "fwd/MassShape.h"
32 #include "fwd/MassShapeWithNominalMass.h"
33 #include "fwd/Particle.h"
34 #include "fwd/Resonance.h"
35 #include "fwd/SpinAmplitude.h"
36 
37 #include "Exceptions.h"
38 
39 #include <algorithm>
40 #include <memory>
41 #include <set>
42 
43 namespace yap {
44 
47 
50 template <typename container>
51 typename container::value_type lone_elt(container& C)
52 {
53  if (C.size() != 1)
54  throw yap::exceptions::Exception("Container size not 1 (" + std::to_string(C.size()) + ")", "lone_elt");
55  return *C.begin();
56 }
57 
60 template <typename container>
61 typename container::value_type lone_elt(container&& C)
62 {
63  if (C.size() != 1)
64  throw yap::exceptions::Exception("Container size not 1 (" + std::to_string(C.size()) + ")", "lone_elt");
65  return *C.begin();
66 }
67 
71 template <typename T, typename Last, typename ... UnaryPredicates>
72 std::set<std::shared_ptr<T> > filter(const std::set<std::shared_ptr<T> >& S, Last p, UnaryPredicates ... P)
73 {
74  auto s = filter<T, UnaryPredicates...>(S, P...);
75  for (auto it = s.begin(); it != s.end(); ) {
76  if (p(**it))
77  ++it;
78  else
79  it = s.erase(it);
80  }
81  return s;
82 }
83 
84 // does nothing, needed to terminate above variadic template
85 template <typename T>
86 const std::set<std::shared_ptr<T> >& filter(const std::set<std::shared_ptr<T> >& S)
87 { return S; }
88 
93  virtual const bool operator()(const DecayTree& dt) const = 0;
94 };
95 
99  using filter_decay_tree::operator();
100 
102  virtual const bool operator()(const DecayTree& dt) const override;
103 
105  virtual const bool operator()(const FreeAmplitude& fa) const = 0;
106 };
107 
111  using filter_free_amplitude::operator();
112 
114  virtual const bool operator()(const FreeAmplitude& fa) const override;
115 
117  virtual const bool operator()(const DecayChannel& dc) const = 0;
118 };
119 
123  using filter_free_amplitude::operator();
124 
126  virtual const bool operator()(const FreeAmplitude& fa) const override;
127 
129  virtual const bool operator()(const SpinAmplitude& dc) const = 0;
130 };
131 
136  virtual const bool operator()(const Particle& p) const = 0;
137 };
138 
142  using filter_particle::operator();
143 
145  virtual const bool operator()(const Particle& p) const override;
146 
148  virtual const bool operator()(const DecayingParticle& dp) const = 0;
149 };
150 
154  using filter_decaying_particle::operator();
155 
157  virtual const bool operator()(const DecayingParticle& dp) const override;
158 
160  virtual const bool operator()(const Resonance& dp) const = 0;
161 };
162 
166  using filter_resonance::operator();
167 
169  virtual const bool operator()(const Resonance& dp) const override;
170 
172  virtual const bool operator()(const MassShape& dp) const = 0;
173 
174 };
175 
179 template <class F, typename T>
180 const bool by_ptr(const F& f, const std::shared_ptr<T>& ptr)
181 { return ptr and f(*ptr); }
182 
186 template <class F, typename T>
187 const bool by_ptr(const F& f, const T* ptr)
188 { return ptr and f(*ptr); }
189 
193 {
194 public:
199 
200  using filter_decay_channel::operator();
201  using filter_decaying_particle::operator();
202 
204  const bool operator()(const FreeAmplitude& fa) const override;
205 
207  const bool operator()(const DecayChannel& dc) const override
208  { return operator()(&dc); }
209 
211  const bool operator()(const std::shared_ptr<DecayChannel> dc) const
212  { return operator()(dc.get()); }
213 
215  const bool operator()(const DecayChannel* dc) const
216  { return dc == DecayChannel_; }
217 
219  const bool operator()(const DecayingParticle& dp) const override;
220 
221 private:
224 };
225 
229 {
230 public:
235 
236  using filter_spin_amplitude::operator();
237 
239  const bool operator()(const FreeAmplitude& fa) const override;
240 
242  const bool operator()(const SpinAmplitude& sa) const override
243  { return operator()(&sa); }
244 
246  const bool operator()(const std::shared_ptr<SpinAmplitude>& sa) const
247  { return operator()(sa.get()); }
248 
250  const bool operator()(const SpinAmplitude* sa) const
251  { return sa == SpinAmplitude_; }
252 
253 private:
256 };
257 
261 {
262 public:
263 
266  to(const ParticleVector& daughters)
268  {
269  if (std::any_of(Daughters_.begin(), Daughters_.end(), std::logical_not<ParticleVector::value_type>()))
270  throw exceptions::Exception("nullptr daughter provided", "to::to");
271  }
272 
274  template <typename ... Others>
275  to(std::shared_ptr<Particle> A, Others ... others)
277  {
278  Daughters_ = {A, others...};
279  if (std::any_of(Daughters_.begin(), Daughters_.end(), std::logical_not<ParticleVector::value_type>()))
280  throw exceptions::Exception("nullptr daughter provided", "to::to");
281  }
282 
283  using filter_decay_channel::operator();
284  using filter_decaying_particle::operator();
285 
287  virtual const bool operator()(const DecayChannel& dc) const override;
288 
290  virtual const bool operator()(const DecayingParticle& dp) const override;
291 
292 protected:
293 
295  ParticleVector Daughters_;
296 
297 };
298 
301 class exactly_to : public to
302 {
303 public:
306  exactly_to(const ParticleVector& daughters) : to(daughters) {}
307 
309  template <typename ... Others>
310  exactly_to(const ParticleVector::value_type& A, Others ... others)
311  : to(A, others...) {}
312 
313  using to::operator();
314 
316  virtual const bool operator()(const DecayChannel& dc) const override;
317 };
318 
322 {
323 public:
324 
326  l_equals(unsigned l) : filter_spin_amplitude(), L_(l) {}
327 
328  using filter_spin_amplitude::operator();
329 
331  virtual const bool operator()(const SpinAmplitude& sa) const override;
332 
333 private:
334 
336  unsigned L_;
337 
338 };
339 
343 {
344 public:
345 
347  m_equals(int two_m) : filter_free_amplitude(), TwoM_(two_m) {}
348 
349  using filter_free_amplitude::operator();
350 
352  virtual const bool operator()(const FreeAmplitude& fa) const override;
353 
354 private:
355 
357  int TwoM_;
358 
359 };
360 
363 class is_named
364 {
365 public:
367  is_named(std::string name) : Name_(name) {}
368 
370  template <typename T>
371  const bool operator()(const T& t) const
372  { return t.name() == Name_; }
373 
374 private:
376  std::string Name_;
377 };
378 
382 {
383 public:
387 
388  using filter_decaying_particle::operator();
389  using filter_decay_tree::operator();
390 
392  const bool operator()(const DecayTree& dt) const
393  { return operator()(&dt); }
394 
396  const bool operator()(const std::shared_ptr<DecayTree>& dt) const
397  { return operator()(dt.get()); }
398 
400  const bool operator()(const DecayTree* dt) const
401  { return dt == DecayTree_; }
402 
404  const bool operator()(const DecayingParticle& dp) const;
405 
406 private:
409 };
410 
414 {
415 public:
419 
420  using filter_decaying_particle::operator();
421  using filter_free_amplitude::operator();
422 
424  const bool operator()(const DecayTree& dt) const override;
425 
427  const bool operator()(const DecayingParticle& dp) const override;
428 
430  const bool operator()(const FreeAmplitude& fa) const override
431  { return operator()(&fa); }
432 
434  const bool operator()(const std::shared_ptr<FreeAmplitude>& fa) const
435  { return operator()(fa.get()); }
436 
438  const bool operator()(const FreeAmplitude* fa) const
439  { return fa == FreeAmplitude_; }
440 
441 private:
444 };
445 
449 {
450 public:
454 
456  from(const std::shared_ptr<DecayingParticle>& dp)
458 
459  using filter_decay_channel::operator();
460  using filter_particle::operator();
461 
463  const bool operator()(const DecayTree& dt) const override
464  { return has_decay_tree(&dt)(*DecayingParticle_); }
465 
467  const bool operator()(const FreeAmplitude& fa) const override
468  { return has_free_amplitude(&fa)(*DecayingParticle_); }
469 
471  const bool operator()(const DecayChannel& dc) const override
472  { return has_decay_channel(&dc)(*DecayingParticle_); }
473 
475  const bool operator()(const Particle& p) const override;
476 
477 private:
480 };
481 
482 
488 {
489 public:
492 
493  using filter_mass_shape::operator();
494 
496  virtual const bool operator()(const Particle& p) const override;
497 
499  const bool operator()(const FinalStateParticle& p) const
500  { return true; }
501 
503  virtual const bool operator()(const MassShape& m) const override;
504 
506  const bool operator()(const MassShapeWithNominalMass& m) const
507  { return true; }
508 
509 };
510 
512 // end of defgroup filters
513 
514 }
515 
516 #endif
virtual const bool operator()(const Particle &p) const override
Particle functor.
Definition: Filters.cxx:142
Stores complex free amplitude for the particular decay of a particle.
Definition: FreeAmplitude.h:48
const bool by_ptr(const F &f, const std::shared_ptr< T > &ptr)
Definition: Filters.h:180
const bool operator()(const DecayTree &dt) const
DecayTree functor.
Definition: Filters.h:392
exactly_to(const ParticleVector::value_type &A, Others...others)
constructor (variadic)
Definition: Filters.h:310
to(const ParticleVector &daughters)
Definition: Filters.h:266
has_spin_amplitude(const SpinAmplitude *sa)
Definition: Filters.h:233
virtual const bool operator()(const FreeAmplitude &fa) const override
FreeAmplitude functor.
Definition: Filters.cxx:105
container::value_type lone_elt(container &C)
Definition: Filter.h:39
const SpinAmplitude * SpinAmplitude_
SpinAmplitude pointer to check equality to.
Definition: Filters.h:255
const FreeAmplitude * FreeAmplitude_
FreeAmplitude to look for.
Definition: Filters.h:443
const bool operator()(const DecayChannel &dc) const override
DecayChannel functor.
Definition: Filters.h:207
virtual const bool operator()(const SpinAmplitude &sa) const override
SpinAmplitude functor.
Definition: Filters.cxx:99
from(const std::shared_ptr< DecayingParticle > &dp)
Constructor.
Definition: Filters.h:456
to(std::shared_ptr< Particle > A, Others...others)
constructor (variadic)
Definition: Filters.h:275
ParticleVector Daughters_
Particle content to check equality to.
Definition: Filters.h:295
const bool operator()(const FreeAmplitude &fa) const override
FreeAmplitude functor.
Definition: Filters.h:430
int TwoM_
spin projection to check equality to
Definition: Filters.h:357
virtual const bool operator()(const FreeAmplitude &fa) const override
FreeAmplitude functor.
Definition: Filters.cxx:24
Functor object for filtering by parent particle.
Definition: Filters.h:448
const bool operator()(const DecayChannel &dc) const override
DecayChannel functor.
Definition: Filters.h:471
Functor class for filtering by particle content.
Definition: Filters.h:260
helper base class for filtering Resonance's
Definition: Filters.h:153
Functor class for checking whether objects have a particular free amplitude.
Definition: Filters.h:413
helper base class for functor classes that can filter DecayChannel's
Definition: Filters.h:110
Class holding vectors of fixed and free amplitudes that define a decay tree.
Definition: DecayTree.h:49
Functor class for checking if DecayingParticle has specified DecayTree.
Definition: Filters.h:381
helper base class for filtering DecayingParticle's
Definition: Filters.h:141
const bool operator()(const SpinAmplitude *sa) const
SpinAmplitude* functor.
Definition: Filters.h:250
Functor class for filtering by exact particle content.
Definition: Filters.h:301
exactly_to(const ParticleVector &daughters)
Definition: Filters.h:306
has_free_amplitude(const FreeAmplitude *fa)
constructor
Definition: Filters.h:417
const bool operator()(const std::shared_ptr< SpinAmplitude > &sa) const
shared_ptr<SpinAmplitude> functor
Definition: Filters.h:246
virtual const bool operator()(const FreeAmplitude &fa) const override
FreeAmplitude functor.
Definition: Filters.cxx:30
const bool operator()(const DecayTree *dt) const
DecayTree* functor.
Definition: Filters.h:400
const bool operator()(const DecayTree &dt) const override
DecayTree functor.
Definition: Filters.h:463
has_decay_tree(const DecayTree *dt)
constructor
Definition: Filters.h:385
const bool operator()(const SpinAmplitude &sa) const override
SpinAmplitude functor.
Definition: Filters.h:242
const DecayTree * DecayTree_
DecayTree pointer to search for.
Definition: Filters.h:408
unsigned L_
orbital angular momentum to check equality to
Definition: Filters.h:336
const bool operator()(const T &t) const
functor
Definition: Filters.h:371
virtual const bool operator()(const DecayTree &dt) const =0
DecayTree functor.
has_decay_channel(const DecayChannel *dc)
Definition: Filters.h:197
Base class for handling YAP exceptions.
Definition: Exceptions.h:39
const bool operator()(const FreeAmplitude *fa) const
FreeAmplitude* functor.
Definition: Filters.h:438
Class representing a final-state particle.
Definition: FinalStateParticle.h:43
Functor class for filtering by spin amplitude.
Definition: Filters.h:228
helper base class for filtering Particle's
Definition: Filters.h:134
const bool operator()(const DecayTree &dt) const override
DecayTree functor.
Definition: Filters.cxx:120
const bool operator()(const FreeAmplitude &fa) const override
FreeAmplitude functor.
Definition: Filters.cxx:72
Class for MassShape that gets its nominal mass from its owning resonance.
Definition: MassShapeWithNominalMass.h:39
Functor object for filtering by spin projection.
Definition: Filters.h:342
Functor object for filtering by orbital angular momentum.
Definition: Filters.h:321
const bool operator()(const FreeAmplitude &fa) const override
FreeAmplitude functor.
Definition: Filters.cxx:60
const bool operator()(const DecayChannel *dc) const
DecayChannel* functor.
Definition: Filters.h:215
virtual const bool operator()(const Particle &p) const override
Particle functor.
Definition: Filters.cxx:36
virtual const bool operator()(const DecayTree &dt) const override
DecayTree functor.
Definition: Filters.cxx:18
const DecayChannel * DecayChannel_
DecayChannel pointer to check equality to.
Definition: Filters.h:223
helper base class for filtering MassShape's
Definition: Filters.h:165
virtual const bool operator()(const Resonance &dp) const override
Resonance functor.
Definition: Filters.cxx:52
virtual const bool operator()(const DecayChannel &dc) const override
DecayChannel functor.
Definition: Filters.cxx:93
Functor class for filtering by decay channel.
Definition: Filters.h:192
is_named(std::string name)
constructor
Definition: Filters.h:367
Functors return true if particle is a final state particle or if a mass shape can be found that inher...
Definition: Filters.h:487
const DecayingParticle * DecayingParticle_
DecayingParticle to check for.
Definition: Filters.h:479
std::set< std::shared_ptr< T > > filter(const std::set< std::shared_ptr< T > > &S, Last p, UnaryPredicates...P)
Definition: Filter.h:60
std::string to_string(const CachedValue::Status &S)
streaming operator for CachedValue::Status
Definition: CachedValue.cxx:27
const bool operator()(const std::shared_ptr< DecayTree > &dt) const
shared_ptr<DecayTree> functor
Definition: Filters.h:396
l_equals(unsigned l)
constructor
Definition: Filters.h:326
const bool operator()(const FreeAmplitude &fa) const override
FreeAmplitude functor.
Definition: Filters.h:467
virtual const bool operator()(const DecayChannel &dc) const override
DecayChannel functor.
Definition: Filters.cxx:78
const bool operator()(const std::shared_ptr< FreeAmplitude > &fa) const
shared_ptr<FreeAmplitude> functor
Definition: Filters.h:434
Definition: DecayingParticle.h:51
Class for a particle that will decay and has a mass shape.
Definition: Resonance.h:47
Abstract Particle base class.
Definition: Particle.h:47
virtual const bool operator()(const Particle &p) const =0
Particle functor.
m_equals(int two_m)
constructor
Definition: Filters.h:347
helper base class for functor classes that can filter SpinAmplitude's
Definition: Filters.h:122
Functor class for filtering objects that have a #name() function.
Definition: Filters.h:363
Abstract base class for all mass shapes.
Definition: MassShape.h:46
helper base class for functor classes that can filter DecayTree's
Definition: Filters.h:91
const bool operator()(const std::shared_ptr< DecayChannel > dc) const
shared_ptr<DecayChannel> functor
Definition: Filters.h:211
has_mass()
constructor
Definition: Filters.h:491
virtual const bool operator()(const DecayingParticle &dp) const override
DecayingParticle functor.
Definition: Filters.cxx:44
std::string Name_
name to check equality to
Definition: Filters.h:376
Class implementing a decay channel.
Definition: DecayChannel.h:40
from(const DecayingParticle &dp)
Constructor.
Definition: Filters.h:452
const bool operator()(const FinalStateParticle &p) const
FinalStateParticle functor.
Definition: Filters.h:499
Abstract base class implementing a spin amplitude.
Definition: SpinAmplitude.h:46
const bool operator()(const MassShapeWithNominalMass &m) const
MassShapeWithNominalMass functor.
Definition: Filters.h:506
helper base class for functor classes that can filter FreeAmplitude's
Definition: Filters.h:98