LOGO

RestFrames  v1.0.1
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-2019, 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 
42  template <class T>
43  class RFList;
44 
46  // RFListBase class
48  template <class T, class Derived>
49  class RFListBase {
50  public:
51  RFListBase() {}
52 
53  virtual ~RFListBase() {}
54 
55  void Clear();
56 
57  bool Add(T& obj);
58 
59  template <class U>
60  bool Add(const RFList<U>& objs){
61  int N = objs.GetN();
62  double ret = true;
63  for(int i = 0; i < N; i++)
64  if(!Add((T&)objs[i])) ret = false;
65  return ret;
66  }
67 
68  int Remove(const T& obj);
69 
70  template <class U>
71  void Remove(const RFList<U>& objs){
72  int N = objs.GetN();
73  for(int i = 0; i < N; i++)
74  Remove(objs[i]);
75  }
76 
77  int GetN() const { return m_Objs.size(); }
78 
79  T& Get(int i) const;
80 
81  T& Get(const RFKey& key) const;
82 
83  int GetIndex(const RFKey& key) const;
84 
85  int GetIndex(const T& obj) const;
86 
87  template <class U>
88  bool Contains(const U& obj) const{
89  int N = GetN();
90  for(int i = 0; i < N; i++)
91  if(*m_Objs[i] == obj) return true;
92  return false;
93  }
94 
95  template <class U>
96  bool Contains(const RFList<U>& objs) const {
97  int N = objs.GetN();
98  for(int i = 0; i < N; i++)
99  if(!Contains(objs[i]))
100  return false;
101  return true;
102  }
103 
104  template <class U>
105  bool IsSame(const RFList<U>& objs) const {
106  return Union(objs).GetN() == Intersection(objs).GetN();
107  }
108 
109  template <class U>
110  Derived Union(const RFList<U>& objs) const {
111  Derived objs_this = static_cast<const Derived&>(*this);
112  objs_this.Add(objs);
113  return objs_this;
114  }
115 
116  template <class U>
117  Derived Intersection(const RFList<U>& objs) const {
118  Derived inter;
119  int N = objs.GetN();
120  for(int i = 0; i < N; i++)
121  if(Contains(objs[i])) inter.Add(objs[i]);
122  return inter;
123  }
124 
125  template <class U>
126  Derived Complement(const RFList<U>& objs) const {
127  Derived comp = static_cast<Derived&>(*this);
128  int N = objs.GetN();
129  for(int i = 0; i < N; i++)
130  if(comp.Contains(objs.Get(i)))
131  comp.Remove(objs.Get(i));
132  return comp;
133  }
134 
135  Derived& operator = (T& obj){
136  Clear();
137  Add(obj);
138  return static_cast<Derived&>(*this);
139  }
140 
141  template <class U>
142  Derived& operator = (const RFList<U>& objs){
143  Clear();
144  Add(objs);
145  return static_cast<Derived&>(*this);
146  }
147 
148  T& operator [] (int i) const;
149 
150  T& operator [] (const RFKey& key) const;
151 
152  bool operator == (const T& obj) const;
153 
154  template <class U>
155  bool operator == (const RFList<U>& objs) const {
156  return IsSame(objs);
157  }
158 
159  bool operator != (const T& obj) const;
160 
161  template <class U>
162  bool operator != (const RFList<U>& objs) const {
163  return !IsSame(objs);
164  }
165 
166  Derived operator + (T& obj) const;
167 
168  template <class U>
169  Derived operator + (const RFList<U>& objs) const {
170  Derived list = static_cast<const Derived&>(*this);
171  list.Add(objs);
172  return list;
173  }
174 
175  Derived operator - (const T& obj) const;
176 
177  template <class U>
178  Derived operator - (const RFList<U>& objs) const;
179 
180  Derived& operator += (T& obj);
181 
182  template <class U>
183  Derived& operator += (const RFList<U>& objs){
184  Add(objs);
185  return static_cast<Derived&>(*this);
186  }
187 
188  Derived& operator -= (const T& obj);
189 
190  template <class U>
191  Derived& operator -= (const RFList<U>& objs){
192  Remove(objs);
193  return static_cast<Derived&>(*this);
194  }
195 
196  protected:
197  std::vector<T*> m_Objs;
198 
199  };
200 
202  // RFList class
204  template <class T>
205  class RFList : public RestFrames::RFListBase<T,RFList<T> > {
206  public:
207  RFList() : RFListBase<T,RFList<T> >() { }
208 
209  template <class U>
210  RFList(const RFList<U>& objs) : RFListBase<T,RFList<T> >() {
211  RFListBase<T,RFList<T> >::Add(objs);
212  }
213 
214  virtual ~RFList() { }
215  };
216 
217  class RFCharge;
218  class RestFrame;
219  class State;
220 
221  template <>
222  class RFList<RestFrames::State>
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 <>
241  class RFList<RestFrames::RestFrame>
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  class RFDataVar;
273  class RFPDF;
274 
289 
290  typedef std::vector<RestFrames::RFList<RestFrame> > RestFrameListList;
291  typedef std::vector<RestFrames::RFList<State> > StateListList;
292 
293 }
294 
295 #endif
RestFrames::RFListBase
Definition: RFList.hh:49
RestFrames::RFCharge
Definition: RFCharge.hh:40
RestFrames::HistPlotCategory
Definition: HistPlotCategory.hh:40
RestFrames::RestFrame
abstract base class for all Frame objects
Definition: RestFrame.hh:45
RestFrames::Group
abstract base class for all Group objects
Definition: Group.hh:46
RestFrames::RFList
Definition: RFList.hh:43
RestFrames::RFBase
Base class for all RestFrame package objects.
Definition: RFBase.hh:53
RestFrames::VisibleState
Definition: VisibleState.hh:39
RestFrames::Jigsaw
abstract base class for all Jigsaw objects
Definition: Jigsaw.hh:44
RestFrames::State
Abstract base class for all State objects.
Definition: State.hh:47
RestFrames::RFKey
Definition: RFKey.hh:38
RestFrames::HistPlotVar
Definition: HistPlotVar.hh:40