LOGO

RestFrames  v1.0.1
RestFrames HEP Event Analysis Software Library
InvisibleJigsaw.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 
32 #include "RestFrames/RestFrame.hh"
33 
34 namespace RestFrames {
35 
37  // InvisibleJigsaw class
39 
40  InvisibleJigsaw::InvisibleJigsaw(const std::string& sname,
41  const std::string& stitle,
42  int Ninvisible, int Nvisible) :
43  Jigsaw(sname, stitle, Ninvisible, 2*Nvisible),
44  m_Ninv(Ninvisible), m_Nvis(Nvisible)
45  {
46  m_Type = kInvisibleJigsaw;
47  m_InvMassDependancy = false;
48  for(int i = 0; i < m_Ninv; i++){
49  m_ChildStates += GetNewChildState();
50  }
51  }
52 
54  : Jigsaw(), m_Ninv(0), m_Nvis(0) {}
55 
56  InvisibleJigsaw::~InvisibleJigsaw() {}
57 
59  Jigsaw::Clear();
60  }
61 
63  return SetMassInvJigsaw::Empty();
64  }
65 
67  if(!group) return;
68  if(!group.IsInvisibleGroup()) return;
69  Jigsaw::SetGroup(group);
70  }
71 
73  if(!Jigsaw::GetGroup())
74  return InvisibleGroup::Empty();
75  else
76  return static_cast<InvisibleGroup&>(Jigsaw::GetGroup());
77  }
78 
79  void InvisibleJigsaw::SetParentState(State& state){
80  if(!state) return;
81  if(!state.IsInvisibleState()) return;
82  Jigsaw::SetParentState(state);
83  }
84 
85  InvisibleState const& InvisibleJigsaw::GetParentState() const {
86  if(!Jigsaw::GetParentState())
87  return InvisibleState::Empty();
88  else
89  return static_cast<const InvisibleState&>(Jigsaw::GetParentState());
90  }
91 
92  InvisibleState& InvisibleJigsaw::GetChildState(int i) const{
93  if(!Jigsaw::GetChildState(i))
94  return InvisibleState::Empty();
95  else
96  return static_cast<InvisibleState&>(Jigsaw::GetChildState(i));
97  }
98 
99  void InvisibleJigsaw::AddVisibleFrame(const RestFrame& frame, int i){
100  if(!frame) return;
101  if(i < 0 || i >= m_Nvis) return;
102 
103  ConstRestFrameList frames = frame.GetListVisibleFrames();
104  int N = frames.GetN();
105  for(int f = 0; f < N; f++)
106  AddDependancyFrame(frames[f], i);
107  }
108 
110  int N = frames.GetN();
111  for(int f = 0; f < N; f++)
112  AddVisibleFrame(frames[f], i);
113  }
114 
115  void InvisibleJigsaw::AddMassFrame(const RestFrame& frame, int i){
116  if(!frame) return;
117  if(i < 0 || i >= m_Nvis) return;
118 
119  ConstRestFrameList frames = frame.GetListVisibleFrames();
120  int N = frames.GetN();
121  for(int f = 0; f < N; f++)
122  AddDependancyFrame(frames[f], m_Nvis + i);
123  }
124 
126  int N = frames.GetN();
127  for(int f = 0; f < N; f++)
128  AddMassFrame(frames[f], i);
129  }
130 
132  if(!frame) return;
133  if(i < 0 || i >= m_Ninv) return;
134 
136  int N = frames.GetN();
137  for(int f = 0; f < N; f++)
138  AddChildFrame(frames[f], i);
139  }
140 
142  int N = frames.GetN();
143  for(int f = 0; f < N; f++)
144  AddInvisibleFrame(frames[f], i);
145  }
146 
147  InvisibleState& InvisibleJigsaw::GetNewChildState(){
148  char strn[10];
149  sprintf(strn,"%d",GetNChildren());
150  std::string name = GetName()+"_"+std::string(strn);
151  InvisibleState* statePtr = new InvisibleState(name, name);
152  AddDependent(statePtr);
153  return *statePtr;
154  }
155 
157  if(!IsSoundMind()) return 0.;
158 
159  int N = GetNChildren();
160  double M = 0.;
161  for(int i = 0; i < N; i++)
162  M += std::max(0., GetChildState(i).GetMinimumMass());
163  return M;
164  }
165 
166  bool InvisibleJigsaw::InitializeAnalysis(){
167  if(!IsSoundMind())
168  return SetMind(false);
169 
170  for(int v = 0; v < m_Nvis; v++)
171  if(GetDependancyFrames(m_Nvis + v).GetN() == 0)
173 
174  SetMind(true);
175  return Jigsaw::InitializeAnalysis();
176  }
177 
178  void InvisibleJigsaw::FillInvisibleMassJigsawDependancies(JigsawList& jigsaws) const {
179  if(m_InvMassDependancy){
180  for(int i = m_Nvis; i < 2*m_Nvis; i++){
181  int M = GetDependancyStates(i).GetN();
182  for(int j = 0; j < M; j++){
183  GetDependancyStates(i)[j].GetParentJigsaw().
184  FillJigsawDependancies(jigsaws);
185  }
186  }
187  }
188  for(int i = 0; i < m_Ninv; i++)
189  static_cast<const InvisibleJigsaw&>(GetChildState(i).GetChildJigsaw()).
190  FillInvisibleMassJigsawDependancies(jigsaws);
191  }
192 
193  bool InvisibleJigsaw::InitializeDependancyJigsaws(){
194  if(!IsSoundMind()) return false;
195 
196  m_DependancyJigsaws.Clear();
197 
198  JigsawList jigsaws;
199  FillJigsawDependancies(jigsaws);
200  jigsaws -= *this;
201  m_DependancyJigsaws += jigsaws;
202 
203  jigsaws.Clear();
204  FillInvisibleMassJigsawDependancies(jigsaws);
205  jigsaws -= *this;
206  m_DependancyJigsaws += jigsaws;
207 
208  // Remove dependancies from dependants
209  JigsawList group_jigsaws;
210  FillGroupJigsawDependants(group_jigsaws);
211  group_jigsaws -= *this;
212  m_DependancyJigsaws -= group_jigsaws;
213 
214  return true;
215  }
216 
217  bool InvisibleJigsaw::InitializeJigsawExecutionList(JigsawList& exec_jigsaws, JigsawList& todo_jigsaws){
218  if(!IsSoundMind()) return false;
219  if(exec_jigsaws.Contains(*this)) return true;
220 
221  JigsawList group_jigsaws;
222  group_jigsaws.Clear();
223  FillGroupJigsawDependancies(group_jigsaws);
224  group_jigsaws -= *this;
225 
226  int Ngroup = group_jigsaws.GetN();
227  for(int i = Ngroup-1; i >= 0; i--){
228  Jigsaw& jigsaw = group_jigsaws[i];
229  if(!exec_jigsaws.Contains(jigsaw))
230  if(!jigsaw.InitializeJigsawExecutionList(exec_jigsaws, todo_jigsaws))
231  return SetMind(false);
232  m_DependancyJigsaws -= jigsaw;
233  }
234  // Satisfy dependancy jigsaws
235  while(m_DependancyJigsaws.GetN() > 0){
236  Jigsaw& jigsaw = m_DependancyJigsaws[m_DependancyJigsaws.GetN()-1];
237  if(exec_jigsaws.Contains(jigsaw)){
238  m_DependancyJigsaws -= jigsaw;
239  continue;
240  }
241  if(!jigsaw.InitializeJigsawExecutionList(exec_jigsaws, todo_jigsaws))
242  return SetMind(false);
243  m_DependancyJigsaws -= jigsaw;
244  }
245 
246  if(!exec_jigsaws.Contains(*this)){
247  exec_jigsaws += *this;
248  todo_jigsaws += *this;
249  }
250  return true;
251  }
252 
253  bool InvisibleJigsaw::IsSoundBody() const {
254  if(RFBase::IsSoundBody())
255  return true;
256 
257  if(!Jigsaw::IsSoundBody())
258  return SetBody(false);
259 
260  for(int i = 0; i < m_Nvis; i++){
261  if(GetDependancyFrames(i).GetN() <= 0){
262  m_Log << LogWarning;
263  m_Log << "Empty collection of visible frames: " << i;
264  m_Log << LogEnd;
265  return SetBody(false);
266  }
267  }
268 
269  return SetBody(true);
270  }
271 
272 }
RestFrames::InvisibleJigsaw::AddInvisibleFrame
void AddInvisibleFrame(const RestFrame &frame, int i=0)
Adds an InvisibleFrame to current jigsaw.
Definition: InvisibleJigsaw.cc:131
InvisibleJigsaw.hh
RestFrames::InvisibleJigsaw::Empty
static InvisibleJigsaw & Empty()
Returns empty InvisibleJigsaw.
Definition: InvisibleJigsaw.cc:62
RestFrames::RestFrame::GetListInvisibleFrames
virtual RestFrameList GetListInvisibleFrames() const
Returns a list of InvisibleFrame s inheriting from this.
Definition: RestFrame.cc:348
RestFrames::InvisibleJigsaw::SetGroup
void SetGroup(Group &group=Group::Empty())
Sets group (Group) to current jigsaw.
Definition: InvisibleJigsaw.cc:66
RestFrames::Jigsaw::SetGroup
virtual void SetGroup(Group &group=Group::Empty())
Sets group (Group) to current jigsaw.
Definition: Jigsaw.cc:109
RestFrames::Jigsaw::GetGroup
virtual Group & GetGroup() const
Returns group (Group) associated with this jigsaw.
Definition: Jigsaw.cc:130
RestFrames::Jigsaw::Jigsaw
Jigsaw()
Empty constructor.
Definition: Jigsaw.cc:61
RestFrames::InvisibleJigsaw::AddMassFrame
void AddMassFrame(const RestFrame &frame, int i=0)
Adds a visible frame to current jigsaw.
Definition: InvisibleJigsaw.cc:115
RestFrames::InvisibleJigsaw::GetGroup
InvisibleGroup & GetGroup() const
Returns group (Group) associated with this jigsaw.
Definition: InvisibleJigsaw.cc:72
RestFrames::Jigsaw::GetDependancyFrames
virtual ConstRestFrameList const & GetDependancyFrames(int i) const
Returns list of frames in which this jigsaw depends on.
Definition: Jigsaw.cc:214
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< const RestFrame >
RestFrames::Jigsaw::Clear
virtual void Clear()
Clears Jigsaw of all connections to other objects.
Definition: Jigsaw.cc:74
SetMassInvJigsaw.hh
RestFrames::InvisibleJigsaw::AddVisibleFrame
void AddVisibleFrame(const RestFrame &frame, int i=0)
Adds a VisibleFrame to current jigsaw.
Definition: InvisibleJigsaw.cc:99
RestFrames::RFBase::GetName
std::string GetName() const
Returns object name.
Definition: RFBase.cc:104
RestFrames::InvisibleJigsaw::AddVisibleFrames
void AddVisibleFrames(const ConstRestFrameList &frames, int i=0)
Adds a list of visible frames to current jigsaw.
Definition: InvisibleJigsaw.cc:109
RestFrames::RestFrame::GetListVisibleFrames
virtual RestFrameList GetListVisibleFrames() const
Returns a list of VisibleFrame s inheriting from this.
Definition: RestFrame.cc:344
RestFrames::InvisibleJigsaw::AddInvisibleFrames
void AddInvisibleFrames(const ConstRestFrameList &frames, int i=0)
Adds a list of invisible frames to current jigsaw.
Definition: InvisibleJigsaw.cc:141
RestFrames::InvisibleJigsaw::Clear
virtual void Clear()
Clears InvisibleJigsaw of all connections to other objects
Definition: InvisibleJigsaw.cc:58
RestFrames::State::IsInvisibleState
bool IsInvisibleState() const
Is this an InvisibleState? (true/false)
Definition: State.cc:87
RestFrames::InvisibleJigsaw::AddMassFrames
void AddMassFrames(const ConstRestFrameList &frames, int i=0)
Adds a list visible frames to current jigsaw.
Definition: InvisibleJigsaw.cc:125
RestFrames::Jigsaw
abstract base class for all Jigsaw objects
Definition: Jigsaw.hh:44
RestFrames::InvisibleJigsaw::GetMinimumMass
virtual double GetMinimumMass() const
Returns minimum Lorentz invariant mass.
Definition: InvisibleJigsaw.cc:156
RestFrames::InvisibleJigsaw
Definition: InvisibleJigsaw.hh:39
RestFrames::State
Abstract base class for all State objects.
Definition: State.hh:47
RestFrames::RFBase::AddDependent
void AddDependent(RFBase *dep)
pointer to RFBase object owned by this one
Definition: RFBase.cc:88
RestFrames::InvisibleGroup::Empty
static InvisibleGroup & Empty()
Returns empty InvisibleGroup.
Definition: InvisibleGroup.cc:53
RestFrames::InvisibleState
Definition: InvisibleState.hh:40
RestFrames::InvisibleJigsaw::InvisibleJigsaw
InvisibleJigsaw()
Empty constructor.
Definition: InvisibleJigsaw.cc:53
RestFrames::InvisibleGroup
Definition: InvisibleGroup.hh:40
RestFrames::Group::IsInvisibleGroup
bool IsInvisibleGroup() const
Is this an InvisibleGroup? (true/false)
Definition: Group.cc:75
RestFrame.hh
RestFrames::SetMassInvJigsaw::Empty
static SetMassInvJigsaw & Empty()
Returns empty SetMassInvJigsaw.
Definition: SetMassInvJigsaw.cc:49