LOGO

RestFrames  v1.0.1
RestFrames HEP Event Analysis Software Library
RFList.cc
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 #include "RestFrames/RFList.hh"
34 #include "RestFrames/Jigsaw.hh"
35 #include "RestFrames/Group.hh"
41 
42 namespace RestFrames {
43 
44  using std::vector;
45 
46  template <class T, class Derived>
47  void RFListBase<T,Derived>::Clear(){
48  m_Objs.clear();
49  }
50 
51  template <class T, class Derived>
52  T& RFListBase<T,Derived>::Get(const RFKey& key) const{
53  int N = GetN();
54  for(int i = 0; i < N; i++)
55  if(m_Objs[i]->IsSame(key)) return *m_Objs[i];
56 
57  return T::Empty();
58  }
59 
60  template <class T, class Derived>
61  T& RFListBase<T,Derived>::Get(int i) const {
62  if(i < 0 || i >= GetN()) return T::Empty();
63  return *m_Objs[i];
64  }
65 
66  template <class T, class Derived>
67  bool RFListBase<T,Derived>::Add(T& obj){
68  if(!obj) return false;
69  int N = GetN();
70  for(int i = 0; i < N; i++)
71  if(m_Objs[i]->IsSame(obj)) return false;
72  m_Objs.push_back(&obj);
73  return true;
74  }
75 
76  template <class T, class Derived>
77  int RFListBase<T,Derived>::Remove(const T& obj){
78  int N = GetN();
79  for(int i = 0; i < N; i++){
80  if(m_Objs[i]->IsSame(obj)){
81  m_Objs.erase(m_Objs.begin()+i);
82  return i;
83  }
84  }
85  return -1;
86  }
87 
88  template <class T, class Derived>
89  int RFListBase<T,Derived>::GetIndex(const RFKey& key) const {
90  int N = GetN();
91  for(int i = 0; i < N; i++){
92  if(m_Objs[i]->IsSame(key)) return i;
93  }
94  return -1;
95  }
96 
97  template <class T, class Derived>
98  int RFListBase<T,Derived>::GetIndex(const T& obj) const {
99  int N = GetN();
100  for(int i = 0; i < N; i++){
101  if(m_Objs[i]->IsSame(obj)) return i;
102  }
103  return -1;
104  }
105 
106  template <class T, class Derived>
107  T& RFListBase<T,Derived>::operator[](int i) const {
108  return Get(i);
109  }
110 
111  template <class T, class Derived>
112  bool RFListBase<T,Derived>::operator==(const T& obj) const {
113  if(GetN() != 1) return false;
114  return obj == *m_Objs[0];
115  }
116 
117  template <class T, class Derived>
118  bool RFListBase<T,Derived>::operator!=(const T& obj) const {
119  if(GetN() != 1) return true;
120  return !(obj == *m_Objs[0]);
121  }
122 
123  template <class T, class Derived>
124  Derived RFListBase<T,Derived>::operator+(T& obj) const {
125  Derived list;
126  list.Add((Derived&)*this);
127  list.Add(obj);
128  return list;
129  }
130 
131  template <class T, class Derived>
132  Derived RFListBase<T,Derived>::operator-(const T& obj) const {
133  Derived list;
134  list.Add((Derived&)*this);
135  list.Remove(obj);
136  return list;
137  }
138 
139  // template <class T, class Derived>
140  // Derived RFListBase<T,Derived>::operator-(const Derived& objs) const {
141  // Derived list;
142  // list.Add((Derived&)*this);
143  // list.Remove(objs);
144  // return list;
145  // }
146 
147  template <class T, class Derived>
148  Derived& RFListBase<T,Derived>::operator+=(T& obj){
149  Add(obj);
150  return (Derived&)*this;
151  }
152 
153  // template <class T, class Derived>
154  // Derived& RFListBase<T,Derived>::operator+=(const Derived& objs){
155  // Add(objs);
156  // return (Derived&)*this;
157  // }
158 
159  template <class T, class Derived>
160  Derived& RFListBase<T,Derived>::operator-=(const T& obj){
161  Remove(obj);
162  return (Derived&)*this;
163  }
164 
165  // RestFrame methods
166  double RFList<RestFrame>::GetMass() const {
167  int N = m_Objs.size();
168  TLorentzVector V(0.,0.,0.,0.);
169  for(int i = 0; i < N; i++)
170  V += m_Objs[i]->GetFourVector();
171  return V.M();
172  }
173 
174  TLorentzVector RFList<RestFrame>::GetFourVector() const {
175  return GetFourVector(RestFrame::Empty());
176  }
177 
178  TLorentzVector RFList<RestFrame>::GetFourVector(const RestFrame& frame) const {
179  int N = m_Objs.size();
180  TLorentzVector V(0.,0.,0.,0.);
181  for(int i = 0; i < N; i++)
182  V += m_Objs[i]->GetFourVector(frame);
183  return V;
184  }
185 
186  TLorentzVector RFList<RestFrame>::GetVisibleFourVector() const {
187  return GetVisibleFourVector(RestFrame::Empty());
188  }
189 
190  TLorentzVector RFList<RestFrame>::GetVisibleFourVector(const RestFrame& frame) const {
191  int N = m_Objs.size();
192  TLorentzVector V(0.,0.,0.,0.);
193  for(int i = 0; i < N; i++)
194  V += m_Objs[i]->GetVisibleFourVector(frame);
195  return V;
196  }
197 
198  TLorentzVector RFList<RestFrame>::GetInvisibleFourVector() const {
199  return GetInvisibleFourVector(RestFrame::Empty());
200  }
201 
202  TLorentzVector RFList<RestFrame>::GetInvisibleFourVector(const RestFrame& frame) const {
203  int N = m_Objs.size();
204  TLorentzVector V(0.,0.,0.,0.);
205  for(int i = 0; i < N; i++)
206  V += m_Objs[i]->GetInvisibleFourVector(frame);
207  return V;
208  }
209 
210  double RFList<RestFrame>::GetEnergy(const RestFrame& frame) const {
211  int N = m_Objs.size();
212  TLorentzVector V(0.,0.,0.,0.);
213  for(int i = 0; i < N; i++)
214  V += m_Objs[i]->GetFourVector(frame);
215  return V.E();
216  }
217 
218  double RFList<RestFrame>::GetMomentum(const RestFrame& frame) const {
219  int N = m_Objs.size();
220  TLorentzVector V(0.,0.,0.,0.);
221  for(int i = 0; i < N; i++)
222  V += m_Objs[i]->GetFourVector(frame);
223  return V.P();
224  }
225 
226  RFCharge RFList<RestFrame>::GetCharge() const {
227  RFCharge charge;
228  int N = GetN();
229  for(int i = 0; i < N; i++)
230  charge += m_Objs[i]->GetCharge();
231 
232  return charge;
233  }
234 
235  // State methods
236  State& RFList<State>::GetFrame(const RestFrame& frame) const {
237  int N = GetN();
238  for(int i = 0; i < N; i++)
239  if(m_Objs[i]->IsFrame(frame)) return *m_Objs[i];
240 
241  return State::Empty();
242  }
243 
244  TLorentzVector RFList<State>::GetFourVector() const {
245  TLorentzVector V(0.,0.,0.,0.);
246  int N = GetN();
247  for(int i = 0; i < N; i++)
248  V += m_Objs[i]->GetFourVector();
249 
250  return V;
251  }
252 
253  RFCharge RFList<State>::GetCharge() const {
254  RFCharge charge;
255  int N = GetN();
256  for(int i = 0; i < N; i++)
257  charge += m_Objs[i]->GetCharge();
258 
259  return charge;
260  }
261 
262  void RFList<State>::Boost(const TVector3& B) const {
263  int N = GetN();
264  for(int i = 0; i < N; i++){
265  m_Objs[i]->Boost(B);
266  }
267  }
268 
269  template class RFList<RFBase>;
270  template class RFList<RestFrame>;
271  template class RFList<const RestFrame>;
272  template class RFList<ReconstructionFrame>;
273  template class RFList<GeneratorFrame>;
274  template class RFList<VisibleRecoFrame>;
275  template class RFList<DecayRecoFrame>;
276  template class RFList<ResonanceGenFrame>;
277  template class RFList<Jigsaw>;
278  template class RFList<const Jigsaw>;
279  template class RFList<Group>;
280  template class RFList<const Group>;
281  template class RFList<State>;
282  template class RFList<VisibleState>;
283  template class RFList<InvisibleState>;
284  template class RFList<CombinatoricState>;
285  template class RFList<HistPlotVar>;
286  template class RFList<HistPlotCategory>;
287  template class RFList<const HistPlotCategory>;
288 
289  template class RFListBase<RFBase,RFList<RFBase> >;
290  template class RFListBase<RestFrame,RFList<RestFrame> >;
291  template class RFListBase<const RestFrame,RFList<const RestFrame> >;
292  template class RFListBase<ReconstructionFrame,RFList<ReconstructionFrame> >;
293  template class RFListBase<GeneratorFrame,RFList<GeneratorFrame> >;
294  template class RFListBase<VisibleRecoFrame,RFList<VisibleRecoFrame> >;
295  template class RFListBase<DecayRecoFrame,RFList<DecayRecoFrame> >;
296  template class RFListBase<ResonanceGenFrame,RFList<ResonanceGenFrame> >;
297  template class RFListBase<Jigsaw,RFList<Jigsaw> >;
298  template class RFListBase<const Jigsaw,RFList<const Jigsaw> >;
299  template class RFListBase<Group,RFList<Group> >;
300  template class RFListBase<const Group,RFList<const Group> >;
301  template class RFListBase<State,RFList<State> >;
302  template class RFListBase<VisibleState,RFList<VisibleState> >;
303  template class RFListBase<InvisibleState,RFList<InvisibleState> >;
304  template class RFListBase<CombinatoricState,RFList<CombinatoricState> >;
305  template class RFListBase<HistPlotVar,RFList<HistPlotVar> >;
306  template class RFListBase<HistPlotCategory,RFList<HistPlotCategory> >;
307  template class RFListBase<const HistPlotCategory,RFList<const HistPlotCategory> >;
308 
309 }