LOGO

RestFrames  v1.0.0
RestFrames HEP Event Analysis Software Library
CombinatoricGroup.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 
33 #include "RestFrames/Jigsaw.hh"
34 
35 namespace RestFrames {
36 
38  // CombinatoricGroup class
39  // a combinatoric collection of particles
41 
42  CombinatoricGroup::CombinatoricGroup(const std::string& sname,
43  const std::string& stitle) :
44  Group(sname, stitle)
45  {
46  m_Type = kCombinatoricGroup;
47  }
48 
49  CombinatoricGroup::CombinatoricGroup() : Group() {}
50 
51  CombinatoricGroup::~CombinatoricGroup() {}
52 
53  CombinatoricGroup& CombinatoricGroup::Empty(){
54  return CombinatoricGroup::m_Empty;
55  }
56 
58  m_Elements.Clear();
59  m_NElementsForFrame.clear();
60  m_NExclusiveElementsForFrame.clear();
61  m_InitStates.Clear();
62  Group::Clear();
63  }
64 
65  void CombinatoricGroup::AddFrame(RestFrame& frame){
66  if(!frame) return;
67  if(!frame.IsVisibleFrame()) return;
68  if(!frame.IsRecoFrame()) return;
69 
70  int N = GetNFrames();
71  Group::AddFrame(frame);
72  if(GetNFrames() == N)
73  return;
74 
75  m_NElementsForFrame[&frame] = 0;
76  m_NExclusiveElementsForFrame[&frame] = true;
77  }
78 
79  void CombinatoricGroup::RemoveFrame(RestFrame& frame){
80  if(!ContainsFrame(frame))
81  return;
82  m_NElementsForFrame.erase(&frame);
83  m_NExclusiveElementsForFrame.erase(&frame);
84  Group::RemoveFrame(frame);
85  }
86 
87  void CombinatoricGroup::SetNElementsForFrame(const RestFrame& frame,
88  int N, bool exclusive_N){
89  if(!ContainsFrame(frame)){
90  N = 0;
91  exclusive_N = true;
92  return;
93  }
94 
95  SetMind(false);
96 
97  m_NElementsForFrame[&frame] = std::max(0, N);
98  m_NExclusiveElementsForFrame[&frame] = exclusive_N;
99  }
100 
101  void CombinatoricGroup::GetNElementsForFrame(const RestFrame& frame, int& N,
102  bool& exclusive_N) const {
103  if(!ContainsFrame(frame)) return;
104 
105  N = m_NElementsForFrame[&frame];
106  exclusive_N = m_NExclusiveElementsForFrame[&frame];
107  }
108 
109  void CombinatoricGroup::AddJigsaw(Jigsaw& jigsaw){
110  if(!jigsaw) return;
111  if(!jigsaw.IsCombinatoricJigsaw()) return;
112  Group::AddJigsaw(jigsaw);
113  }
114 
115  CombinatoricState& CombinatoricGroup::InitializeParentState(){
116  std::string name = GetName()+"_parent";
117  CombinatoricState* statePtr = new CombinatoricState(name, name);
118  AddDependent(statePtr);
119  return *statePtr;
120  }
121 
122  CombinatoricState& CombinatoricGroup::GetParentState() const {
123  if(m_GroupStatePtr)
124  return static_cast<CombinatoricState&>(*m_GroupStatePtr);
125  else
126  return CombinatoricState::Empty();
127  }
128 
129  CombinatoricState& CombinatoricGroup::GetChildState(int i) const {
130  if(!Group::GetChildState(i))
131  return CombinatoricState::Empty();
132  else
133  return static_cast<CombinatoricState&>(Group::GetChildState(i));
134  }
135 
136  // Event analysis functions
137  bool CombinatoricGroup::ClearEvent(){
138  m_Elements.Clear();
139  return true;
140  }
141 
142  bool CombinatoricGroup::AnalyzeEvent(){
143  if(!IsSoundMind()){
144  UnSoundMind(RF_FUNCTION);
145  return SetSpirit(false);
146  }
147 
148  GetParentState().ClearElements();
149  GetParentState().AddElements(m_Elements);
150 
151  return SetSpirit(true);
152  }
153 
154  RFKey CombinatoricGroup::AddLabFrameFourVector(const TLorentzVector& V,
155  const RFCharge& charge){
156  if(IsEmpty()) return RFKey(-1);
157 
158  TLorentzVector P = V;
159  if(P.M() < 0.) P.SetVectM(V.Vect(),0.);
160 
161  VisibleState& state = GetNewElement();
162  state.SetFourVector(P);
163  state.SetCharge(charge);
164  m_Elements.Add(state);
165 
166  return state.GetKey();
167  }
168 
169  RFKey CombinatoricGroup::AddLabFrameFourVector(const TLorentzVector& V,
170  int charge){
171  return AddLabFrameFourVector(V, RFCharge(charge));
172  }
173 
174  RFKey CombinatoricGroup::AddLabFrameFourVector(const TLorentzVector& V,
175  int charge_num,
176  int charge_den){
177  return AddLabFrameFourVector(V, RFCharge(charge_num,charge_den));
178  }
179 
180  RestFrame const& CombinatoricGroup::GetFrame(const RFKey& key) const {
181  int N = GetNChildStates();
182  for(int i = N-1; i >= 0; i--)
183  if(GetChildState(i).ContainsElement(key))
184  return GetChildState(i).GetListFrames()[0];
185  return RestFrame::Empty();
186  }
187 
188  TLorentzVector CombinatoricGroup::GetLabFrameFourVector(const RFKey& key) const {
189  TLorentzVector P(0.,0.,0.,0.);
190  int N = GetNChildStates();
191  for(int i = N-1; i >= 0; i--)
192  if(GetChildState(i).ContainsElement(key))
193  return GetChildState(i).GetElement(key).GetFourVector();
194  return TLorentzVector(0.,0.,0.,0.);
195  }
196 
197  int CombinatoricGroup::GetNElementsInFrame(const RestFrame& frame) const {
198  if(!ContainsFrame(frame)) return -1;
199  return static_cast<CombinatoricState&>(Group::GetChildState(frame)).GetNElements();
200  }
201 
202  VisibleState& CombinatoricGroup::GetNewElement(){
203  if(m_Elements.GetN() < m_InitStates.GetN())
204  return m_InitStates[m_Elements.GetN()];
205  char strn[10];
206  sprintf(strn,"%d",m_Elements.GetN()+1);
207  std::string name = GetName()+"_"+std::string(strn);
208  VisibleState* statePtr = new VisibleState(name,name);
209  AddDependent(statePtr);
210  m_InitStates.Add(*statePtr);
211  return *statePtr;
212  }
213 
214  CombinatoricGroup CombinatoricGroup::m_Empty;
215 
216 }
std::string GetName() const
Returns object name.
Definition: RFBase.cc:104
virtual void Clear()
Clears Group of all connections to other objects.
bool IsEmpty() const
Checks whether this is default (empty) instance of class.
Definition: RFBase.cc:84
void AddDependent(RFBase *dep)
pointer to RFBase object owned by this one
Definition: RFBase.cc:88
virtual void Clear()
Clears Group of all connections to other objects.
Definition: Group.cc:62
abstract base class for all Frame objects