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