LOGO

RestFrames  v1.0.1
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 
50 
51  CombinatoricGroup::~CombinatoricGroup() {}
52 
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 
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 
80  if(!ContainsFrame(frame))
81  return;
82  m_NElementsForFrame.erase(&frame);
83  m_NExclusiveElementsForFrame.erase(&frame);
84  Group::RemoveFrame(frame);
85  }
86 
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 
102  bool& exclusive_N) const {
103  if(!ContainsFrame(frame)) return;
104 
105  N = m_NElementsForFrame[&frame];
106  exclusive_N = m_NExclusiveElementsForFrame[&frame];
107  }
108 
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 
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 
170  int charge){
171  return AddLabFrameFourVector(V, RFCharge(charge));
172  }
173 
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 
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 }
RestFrames::CombinatoricState
Definition: CombinatoricState.hh:43
RestFrames::RFCharge
Definition: RFCharge.hh:40
RestFrames::CombinatoricGroup::Clear
virtual void Clear()
Clears CombinatoricGroup of all connections to other objects.
Definition: CombinatoricGroup.cc:57
ReconstructionFrame.hh
RestFrames::Group::Clear
virtual void Clear()
Clears Group of all connections to other objects.
Definition: Group.cc:62
RestFrames::CombinatoricGroup::GetNElementsForFrame
virtual void GetNElementsForFrame(const RestFrame &frame, int &N, bool &exclusive_N) const
Tells number of elements required for this frame.
Definition: CombinatoricGroup.cc:101
RestFrames::CombinatoricState::Empty
static CombinatoricState & Empty()
Returns empty CombinatoricState.
Definition: CombinatoricState.cc:52
RestFrames::RestFrame::IsRecoFrame
bool IsRecoFrame() const
Is this an ReconstructionFrame ? (yes/no)
Definition: RestFrame.cc:113
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::RFBase::IsEmpty
bool IsEmpty() const
Checks whether this is default (empty) instance of class.
Definition: RFBase.cc:84
RestFrames::State::SetFourVector
virtual void SetFourVector(const TLorentzVector &V)
Sets four-vector of this frame.
Definition: State.cc:161
RestFrames::CombinatoricGroup::GetNElementsInFrame
int GetNElementsInFrame(const RestFrame &frame) const
Returns number of elements in a frame.
Definition: CombinatoricGroup.cc:197
RestFrames::CombinatoricGroup::CombinatoricGroup
CombinatoricGroup()
Empty constructor.
Definition: CombinatoricGroup.cc:49
RestFrames::State::GetFourVector
virtual TLorentzVector GetFourVector() const
Returns four vector of this frame.
Definition: State.cc:165
RestFrames::Group::RemoveFrame
virtual void RemoveFrame(RestFrame &frame)
Removes a frame (RestFrame) from this group.
Definition: Group.cc:117
RestFrames::Group::AddJigsaw
virtual void AddJigsaw(Jigsaw &jigsaw)
Adds a jigsaw (Jigsaw) to current group.
Definition: Group.cc:99
RestFrames::CombinatoricGroup::AddLabFrameFourVector
RFKey AddLabFrameFourVector(const TLorentzVector &V, const RFCharge &charge=RFCharge())
Adds four-vector (TLorentzVector) in the lab frame.
Definition: CombinatoricGroup.cc:154
RestFrames::CombinatoricGroup::GetFrame
RestFrame const & GetFrame(const RFKey &key) const
Returns frame (RestFrame) that contains key
Definition: CombinatoricGroup.cc:180
RestFrames::RFBase::GetKey
RFKey GetKey() const
gets object identification key
Definition: RFBase.cc:100
RestFrames::VisibleState
Definition: VisibleState.hh:39
Jigsaw.hh
RestFrames::Group::GetNFrames
int GetNFrames() const
Returns the number of frames (RestFrame) contained in this group.
Definition: Group.cc:161
RestFrames::CombinatoricState::AddElements
void AddElements(const VisibleStateList &states)
Adds elements to this state.
Definition: CombinatoricState.cc:92
RestFrames::CombinatoricState::ClearElements
void ClearElements()
Clears all elements associated with this state.
Definition: CombinatoricState.cc:83
RestFrames::Group::AddFrame
virtual void AddFrame(RestFrame &frame)
Adds a frame (RestFrame) to this group.
Definition: Group.cc:83
RestFrames::RFBase::GetName
std::string GetName() const
Returns object name.
Definition: RFBase.cc:104
RestFrames::CombinatoricGroup::RemoveFrame
virtual void RemoveFrame(RestFrame &frame)
Removes a frame (RestFrame) from this combinatoric group.
Definition: CombinatoricGroup.cc:79
RestFrames::CombinatoricGroup::AddJigsaw
virtual void AddJigsaw(Jigsaw &jigsaw)
Adds a jigsaw (Jigsaw) to this combinatoric group.
Definition: CombinatoricGroup.cc:109
CombinatoricState.hh
RestFrames::State::GetListFrames
ConstRestFrameList const & GetListFrames() const
Returns list of frames (RestFrame) contained in this state.
Definition: State.cc:102
RestFrames::CombinatoricGroup::Empty
static CombinatoricGroup & Empty()
Returns empty CombinatoricGroup.
Definition: CombinatoricGroup.cc:53
RestFrames::CombinatoricGroup::GetLabFrameFourVector
TLorentzVector GetLabFrameFourVector(const RFKey &key) const
Returns lab frame's four-vector (TLorentzVector) of frame that contains key
Definition: CombinatoricGroup.cc:188
CombinatoricGroup.hh
RestFrames::RestFrame::IsVisibleFrame
bool IsVisibleFrame() const
Is this a VisibleFrame ? (yes/no)
Definition: RestFrame.cc:97
RestFrames::VisibleState::SetCharge
virtual void SetCharge(const RFCharge &charge)
Sets charge of this state.
Definition: VisibleState.cc:90
RestFrames::CombinatoricGroup
Definition: CombinatoricGroup.hh:39
RestFrames::Group::ContainsFrame
bool ContainsFrame(const RestFrame &frame) const
Is frame (RestFrame) contained in this group? (true/false)
Definition: Group.cc:157
RestFrames::Jigsaw
abstract base class for all Jigsaw objects
Definition: Jigsaw.hh:44
RestFrames::Jigsaw::IsCombinatoricJigsaw
bool IsCombinatoricJigsaw() const
Is combinatoric jigsaw? (true/false)
Definition: Jigsaw.cc:96
RestFrames::RFKey
Definition: RFKey.hh:38
RestFrames::RestFrame::Empty
static RestFrame & Empty()
Returns empty RestFrame.
Definition: RestFrame.cc:62
RestFrames::CombinatoricState::GetElement
VisibleState const & GetElement(const RFKey &key) const
Returns element with key in this state.
Definition: CombinatoricState.cc:113
RestFrames::RFBase::AddDependent
void AddDependent(RFBase *dep)
pointer to RFBase object owned by this one
Definition: RFBase.cc:88
RestFrames::CombinatoricGroup::SetNElementsForFrame
virtual void SetNElementsForFrame(const RestFrame &frame, int N, bool exclusive_N=false)
Assigns to frame a required min/max number of elements.
Definition: CombinatoricGroup.cc:87
RestFrames::CombinatoricGroup::AddFrame
virtual void AddFrame(RestFrame &frame)
Adds a frame (RestFrame) to this combinatoric group.
Definition: CombinatoricGroup.cc:65