LOGO

RestFrames  v1.0.0
RestFrames HEP Event Analysis Software Library
RFList.hh
Go to the documentation of this file.
1 // RestFrames: particle physics event analysis library
3 // --------------------------------------------------------------------
4 // Copyright (c) 2014-2016, Christopher Rogan
14 // This file is part of RestFrames.
15 //
16 // RestFrames is free software; you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation; either version 2 of the License, or
19 // (at your option) any later version.
20 //
21 // RestFrames is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with RestFrames. If not, see <http://www.gnu.org/licenses/>.
29 
30 #ifndef RFList_HH
31 #define RFList_HH
32 
33 #include <vector>
34 
35 class TLorentzVector;
36 class TVector3;
37 
38 namespace RestFrames {
39 
40  class RFKey;
41  class RFCharge;
42 
43  class RestFrame;
44  class State;
45 
46  template <class T>
47  class RFList;
48 
50  // RFListBase class
52  template <class T, class Derived>
53  class RFListBase {
54  public:
55  RFListBase() {}
56 
57  virtual ~RFListBase() {}
58 
59  void Clear();
60 
61  bool Add(T& obj);
62 
63  template <class U>
64  bool Add(const RFList<U>& objs){
65  int N = objs.GetN();
66  double ret = true;
67  for(int i = 0; i < N; i++)
68  if(!Add((T&)objs[i])) ret = false;
69  return ret;
70  }
71 
72  int Remove(const T& obj);
73 
74  template <class U>
75  void Remove(const RFList<U>& objs){
76  int N = objs.GetN();
77  for(int i = 0; i < N; i++)
78  Remove(objs[i]);
79  }
80 
81  int GetN() const { return m_Objs.size(); }
82 
83  T& Get(int i) const;
84 
85  T& Get(const RFKey& key) const;
86 
87  int GetIndex(const RFKey& key) const;
88 
89  int GetIndex(const T& obj) const;
90 
91  template <class U>
92  bool Contains(const U& obj) const{
93  int N = GetN();
94  for(int i = 0; i < N; i++)
95  if(*m_Objs[i] == obj) return true;
96  return false;
97  }
98 
99  template <class U>
100  bool Contains(const RFList<U>& objs) const {
101  int N = objs.GetN();
102  for(int i = 0; i < N; i++)
103  if(!Contains(objs[i]))
104  return false;
105  return true;
106  }
107 
108  template <class U>
109  bool IsSame(const RFList<U>& objs) const {
110  return Union(objs).GetN() == Intersection(objs).GetN();
111  }
112 
113  template <class U>
114  Derived Union(const RFList<U>& objs) const {
115  Derived objs_this = static_cast<const Derived&>(*this);
116  objs_this.Add(objs);
117  return objs_this;
118  }
119 
120  template <class U>
121  Derived Intersection(const RFList<U>& objs) const {
122  Derived inter;
123  int N = objs.GetN();
124  for(int i = 0; i < N; i++)
125  if(Contains(objs[i])) inter.Add(objs[i]);
126  return inter;
127  }
128 
129  template <class U>
130  Derived Complement(const RFList<U>& objs) const {
131  Derived comp = static_cast<Derived&>(*this);
132  int N = objs.GetN();
133  for(int i = 0; i < N; i++)
134  if(comp.Contains(objs.Get(i)))
135  comp.Remove(objs.Get(i));
136  return comp;
137  }
138 
139  Derived& operator = (T& obj){
140  Clear();
141  Add(obj);
142  return static_cast<Derived&>(*this);
143  }
144 
145  template <class U>
146  Derived& operator = (const RFList<U>& objs){
147  Clear();
148  Add(objs);
149  return static_cast<Derived&>(*this);
150  }
151 
152  T& operator [] (int i) const;
153 
154  T& operator [] (const RFKey& key) const;
155 
156  bool operator == (const T& obj) const;
157 
158  template <class U>
159  bool operator == (const RFList<U>& objs) const {
160  return IsSame(objs);
161  }
162 
163  bool operator != (const T& obj) const;
164 
165  template <class U>
166  bool operator != (const RFList<U>& objs) const {
167  return !IsSame(objs);
168  }
169 
170  Derived operator + (T& obj) const;
171 
172  template <class U>
173  Derived operator + (const RFList<U>& objs) const {
174  Derived list = static_cast<const Derived&>(*this);
175  list.Add(objs);
176  return list;
177  }
178 
179  Derived operator - (const T& obj) const;
180 
181  template <class U>
182  Derived operator-(const RFList<U>& objs) const;
183 
184  Derived& operator += (T& obj);
185 
186  template <class U>
187  Derived& operator += (const RFList<U>& objs){
188  Add(objs);
189  return static_cast<Derived&>(*this);
190  }
191 
192  Derived& operator -= (const T& obj);
193 
194  template <class U>
195  Derived& operator -= (const RFList<U>& objs){
196  Remove(objs);
197  return static_cast<Derived&>(*this);
198  }
199 
200  protected:
201  std::vector<T*> m_Objs;
202 
203  };
204 
206  // RFList class
208  template <class T>
209  class RFList : public RestFrames::RFListBase<T,RFList<T> > {
210  public:
211  RFList() : RFListBase<T,RFList<T> >() { }
212 
213  template <class U>
214  RFList(const RFList<U>& objs) : RFListBase<T,RFList<T> >() {
215  RFListBase<T,RFList<T> >::Add(objs);
216  }
217 
218  virtual ~RFList(){ }
219  };
220 
221  template <>
223  : public RFListBase<State,RFList<RestFrames::State> > {
224  public:
226 
227  template <class U>
228  RFList(const RFList<U>& objs) : RFListBase<State,RFList<State> >() {
229  Add(objs);
230  }
231 
232  virtual ~RFList(){ }
233 
234  State& GetFrame(const RestFrame& frame) const;
235  TLorentzVector GetFourVector() const;
236  RFCharge GetCharge() const;
237  void Boost(const TVector3& B) const;
238  };
239 
240  template <>
242  : public RFListBase<RestFrame,RFList<RestFrames::RestFrame> > {
243  public:
245 
246  template <class U>
248  Add(objs);
249  }
250 
251  virtual ~RFList(){ }
252 
253  double GetMass() const;
254 
255  TLorentzVector GetFourVector() const;
256  TLorentzVector GetFourVector(const RestFrame& frame) const;
257  TLorentzVector GetVisibleFourVector() const;
258  TLorentzVector GetVisibleFourVector(const RestFrame& frame) const;
259  TLorentzVector GetInvisibleFourVector() const;
260  TLorentzVector GetInvisibleFourVector(const RestFrame& frame) const;
261  double GetEnergy(const RestFrame& frame) const;
262  double GetMomentum(const RestFrame& frame) const;
263  RFCharge GetCharge() const;
264  };
265 
266  class RFBase;
267  class Jigsaw;
268  class Group;
269  class VisibleState;
270  class HistPlotVar;
271  class HistPlotCategory;
272 
284 
285  typedef std::vector<RestFrames::RFList<RestFrame> > RestFrameListList;
286  typedef std::vector<RestFrames::RFList<State> > StateListList;
287 
288 }
289 
290 #endif
abstract base class for all Jigsaw objects
Definition: Jigsaw.hh:44
Base class for all RestFrame package objects.
Definition: RFBase.hh:53
abstract base class for all Group objects
Definition: Group.hh:46
abstract base class for all Frame objects
abstract base class for all State objects
Definition: State.hh:44