Rivet  1.8.3
IsolationProjection.hh
1 // -*- C++ -*-
2 #ifndef RIVET_IsolationProjection_HH
3 #define RIVET_IsolationProjection_HH
4 
5 #include "Rivet/Event.hh"
6 #include "Rivet/Projection.hh"
7 #include "Rivet/Math/Units.hh"
8 #include "Rivet/Projections/IsolationEstimators.hh"
9 #include <boost/shared_ptr.hpp>
10 
11 namespace Rivet{
12 
13 
16  template <typename PROJ1, typename PROJ2,
17  typename EST = typename isohelper<typename PROJ1::entity_type, typename PROJ2::collection_type>::estimatorhelper>
19  public:
21  IsolationProjection(PROJ1& iso,
22  PROJ2& ctrl,
23  EST* estimator,
24  double ptmin = 0*GeV) :
25  _estimator(estimator),
26  _ptmin(ptmin)
27  {
28  setName("IsolationProjection");
29  addProjection(iso, "ToBeIsolated");
30  addProjection(ctrl, "Control");
31  }
32 
34  const vector<pair<const typename PROJ1::entity_type*, double> >
35  isolatedParticles(double maxiso = numeric_limits<double>::max()) const;
36 
37  virtual const Projection* clone() const {
38  return new IsolationProjection(*this);
39  }
40 
41  protected:
42 
44  virtual void project(const Event& e);
45 
47  virtual int compare(const Projection& p) const;
48 
49 
50  private:
51 
53  boost::shared_ptr<EST> _estimator;
54 
56  //double _coneRadius;
57 
59  double _ptmin;
60 
63  vector<pair<const typename PROJ1::entity_type*, double> > _isovalues;
64  };
65 
66 
67  template<typename PROJ1, typename PROJ2, typename EST>
68  inline const vector<pair<const typename PROJ1::entity_type*, double> > IsolationProjection<PROJ1, PROJ2, EST>
69  ::isolatedParticles(double maxiso) const {
70  vector<pair<const typename PROJ1::entity_type*, double> > out;
71  for (typename vector<pair<const typename PROJ1::entity_type*, double> >::const_iterator i = _isovalues.begin(); i != _isovalues.end(); ++i){
72  if (i->second < maxiso) out.push_back(*i);
73  }
74  return out;
75  }
76 
77 
78  template<typename PROJ1, typename PROJ2, typename EST>
80  Log& log = getLog();
81  _isovalues.clear();
83  const PROJ1& isofs = applyProjection<PROJ1>(e, "ToBeIsolated");
86  const typename PROJ1::collection_type isopart = isofs.entities();
87  const PROJ2& ctrlfs = applyProjection<PROJ2>(e, "Control");
88  const typename PROJ2::collection_type ctrlpart = ctrlfs.entities();
89  for (typename PROJ1::collection_type::const_iterator iiso = isopart.begin(); iiso != isopart.end(); ++iiso){
90  if (iiso->getMomentum().pT() < _ptmin) continue;
91  double isolation = _estimator->estimate(*iiso, ctrlpart);
92  log << Log::DEBUG << "Isolation for particle with momentum " << iiso->getMomentum()
93  << " is " << isolation << endl;
94  _isovalues.push_back(make_pair(&(*iiso), isolation));
95  }
96  }
97 
98  template<typename PROJ1, typename PROJ2, typename EST>
100  const IsolationProjection & other = dynamic_cast<const IsolationProjection &>(p);
101  //first check the final states
102  int isofscmp = mkNamedPCmp(other, "ToBeIsolated");
103  if (isofscmp != EQUIVALENT) return isofscmp;
104  int isoctrlcmp = mkNamedPCmp(other, "Control");
105  if (isoctrlcmp != EQUIVALENT) return isoctrlcmp;
106  // compare the ptmin of the isolated colection
107  int ptmincmp = cmp(_ptmin, other._ptmin);
108  if (ptmincmp != EQUIVALENT) return ptmincmp;
109  // compare the estimators
110  //if (cmp(*(_estimator.get()),*(other._estimator.get())) == EQUIVALENT) cout << "Estimatori uguali!" << endl;
111  return cmp(*(_estimator.get()),*(other._estimator.get()));
112  }
113 
114 }
115 
116 #endif
void setName(const std::string &name)
Used by derived classes to set their name.
Definition: Projection.hh:120
IsolationProjection(PROJ1 &iso, PROJ2 &ctrl, EST *estimator, double ptmin=0 *GeV)
Constructor.
Definition: IsolationProjection.hh:21
const vector< pair< const typename PROJ1::entity_type *, double > > isolatedParticles(double maxiso=numeric_limits< double >::max()) const
Get the isolation values for the isofinalstate.
Definition: IsolationProjection.hh:69
Definition: IsolationProjection.hh:18
Definition: Logging.hh:9
virtual const Projection * clone() const
Clone on the heap.
Definition: IsolationProjection.hh:37
virtual int compare(const Projection &p) const
Compare projections.
Definition: IsolationProjection.hh:99
Definition: Event.hh:22
virtual void project(const Event &e)
Apply the projection to the event.
Definition: IsolationProjection.hh:79
const PROJ & addProjection(const PROJ &proj, const std::string &name)
Definition: ProjectionApplier.hh:113
Base class for all Rivet projections.
Definition: Projection.hh:28
Cmp< T > cmp(const T &t1, const T &t2)
Global helper function for easy creation of Cmp objects.
Definition: Cmp.hh:285