LOGO

RestFrames  v1.0.1
RestFrames HEP Event Analysis Software Library
ReconstructionFrame.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/Group.hh"
35 
36 namespace RestFrames {
37 
39  // ReconstructionFrame class methods
41  ReconstructionFrame::ReconstructionFrame(const std::string& sname,
42  const std::string& stitle)
43  : RestFrame(sname, stitle)
44  {
45  m_Ana = kRecoFrame;
46  m_GroupPtr = nullptr;
47  }
48 
50  : RestFrame() {}
51 
52  ReconstructionFrame::~ReconstructionFrame(){
53  Clear();
54  }
55 
57  SetGroup();
58  m_ChildStates.clear();
60  }
61 
63  return VisibleRecoFrame::Empty();
64  }
65 
67  if(!frame) return;
68  if(!frame.IsRecoFrame()) return;
70  }
71 
73  SetBody(false);
74  bool contains = m_ChildFrames.Contains(frame);
75  m_ChildBoosts.erase(&frame);
76  m_ChildStates.erase(&frame);
77  m_ChildFrames.Remove(frame);
78  if(contains)
79  frame.SetParentFrame();
80  }
81 
83  SetBody(false);
84  while(GetNChildren() > 0)
85  RemoveChildFrame(m_ChildFrames[0]);
86  m_ChildFrames.Clear();
87  m_ChildBoosts.clear();
88  m_ChildStates.clear();
89  }
90 
92  if(!frame) return;
93  if(!frame.IsRecoFrame()) return;
95  }
96 
98  const RestFrame& frame = RestFrame::GetParentFrame();
99  if(!frame.IsEmpty())
100  return static_cast<const ReconstructionFrame&>(frame);
101  else
103  }
104 
107  if(!frame.IsEmpty())
108  return static_cast<ReconstructionFrame&>(frame);
109  else
111  }
112 
113  StateList const& ReconstructionFrame::GetChildStates(int i) const {
114  return GetChildStates(GetChildFrame(i));
115  }
116 
117  StateList const& ReconstructionFrame::GetChildStates(const RestFrame& child) const {
118  if(m_ChildStates.count(&child) <= 0)
119  return State::EmptyList();
120 
121  return m_ChildStates[&child];
122  }
123 
125  if(IsEmpty()) return;
126 
127  SetMind(false);
128 
129  if(m_GroupPtr){
130  if(*m_GroupPtr != group){
131  Group* groupPtr = m_GroupPtr;
132  m_GroupPtr = nullptr;
133  groupPtr->RemoveFrame(*this);
134  }
135  }
136  if(!group)
137  m_GroupPtr = nullptr;
138  else
139  m_GroupPtr = &group;
140  }
141 
143  if(m_GroupPtr)
144  return *m_GroupPtr;
145  else
146  return Group::Empty();
147  }
148 
150  GroupList groups;
151  FillListGroupsRecursive(groups);
152  return groups;
153  }
154 
155  void ReconstructionFrame::FillListGroupsRecursive(GroupList& groups) const {
156  if(m_GroupPtr) groups.Add(*m_GroupPtr);
157  int Nchild = GetNChildren();
158  for(int i = 0; i < Nchild; i++)
159  GetChildFrame(i).FillListGroupsRecursive(groups);
160  }
161 
162  bool ReconstructionFrame::InitializeVisibleStates(){
163  m_ChildStates.clear();
164  if(!GetLabFrame())
165  return false;
166 
167  const VisibleStateList& states =
168  static_cast<const LabRecoFrame&>(GetLabFrame()).GetTreeStates();
169 
170  int Nchild = GetNChildren();
171  for(int i = 0; i < Nchild; i++){
172  RestFrame& child = GetChildFrame(i);
173  m_ChildStates[&child] = StateList();
174  RFList<ReconstructionFrame> frames = child.GetListVisibleFrames();
175  int Nf = frames.GetN();
176  for(int f = 0; f < Nf; f++)
177  if(!frames[f].GetGroup())
178  if(!m_ChildStates[&child].Add(StateList(states).GetFrame(frames[f]))){
179  m_Log << LogWarning;
180  m_Log << "Unable to associate State with Group-less Frame:";
181  m_Log << Log(frames[f]) << LogEnd;
182  return false;
183  }
184  }
185  return true;
186  }
187 
188  bool ReconstructionFrame::InitializeGroupStates(){
189  GroupList groups = GetListGroups();
190  int Ngroup = groups.GetN();
191  int Nchild = GetNChildren();
192 
193  for(int c = 0; c < Nchild; c++){
194  RestFrameList frames =
197  int Nframe = frames.GetN();
198  for(int f = 0; f < Nframe; f++){
199  for(int g = 0; g < Ngroup; g++){
200  if(groups[g].ContainsFrame(frames[f])){
201  State& state = groups[g].GetChildState(frames[f]);
202  if(!state){
203  m_Log << LogWarning;
204  m_Log << "Unable to get State associated with Group Frame: " << std::endl;
205  m_Log << " Frame:" << Log(frames[f]);
206  m_Log << " Group:" << Log(groups[g]) << LogEnd;
207  return false;
208  }
209  m_ChildStates[&GetChildFrame(c)].Add(state);
210  break;
211  }
212  }
213  }
214  }
215  return true;
216  }
217 
219  if(!IsSoundBody()){
220  UnSoundBody(RF_FUNCTION);
221  return SetMind(false);
222  }
223 
224  if(!InitializeVisibleStates())
225  return SetMind(false);
226  if(!InitializeGroupStates())
227  return SetMind(false);
228 
229  int Nchild = GetNChildren();
230  for(int i = 0; i < Nchild; i++)
232  m_Log << LogWarning;
233  m_Log << "Unable to recursively initialize analysis for frame:";
234  m_Log << Log(GetChildFrame(i)) << LogEnd;
235  return SetMind(false);
236  }
237 
238  return SetMind(true);
239  }
240 
241  bool ReconstructionFrame::ResetRecoFrame(){
242  return true;
243  }
244 
246  if(!IsSoundMind()){
247  UnSoundMind(RF_FUNCTION);
248  return false;
249  }
250 
251  if(!ResetRecoFrame())
252  return false;
253 
254  int Nf = GetNChildren();
255  for(int i = 0; i < Nf; i++)
257  return false;
258 
259  return true;
260  }
261 
262  bool ReconstructionFrame::ReconstructFrame(){
263  if(!IsSoundMind()){
264  UnSoundMind(RF_FUNCTION);
265  return SetSpirit(false);
266  }
267 
268  TLorentzVector Ptot(0,0,0,0);
269 
270  int Nchild = GetNChildren();
271  for(int i = 0; i < Nchild; i++){
273 
274  TLorentzVector P = m_ChildStates[&child].GetFourVector();
275  // P.SetVectM(P.Vect(), std::max(0.,P.M()));
276 
277  bool terminal = child.IsVisibleFrame() || child.IsInvisibleFrame();
278  if(terminal || P.M() <= 1e-5){
279  SetChildBoostVector(child, m_Empty3Vector);
280  P.SetVectM(P.Vect(), std::max(0.,P.M()));
281  child.SetFourVector(P, *this);
282  } else {
283  SetChildBoostVector(child, P.BoostVector());
284  P.SetVectM(P.Vect(), std::max(0.,P.M()));
285  child.SetFourVector(P, *this);
286  }
287 
288  Ptot += P;
289 
290  if(child.IsVisibleFrame())
291  static_cast<VisibleRecoFrame&>(child).
292  SetCharge(m_ChildStates[&child].GetCharge());
293  }
294 
295  if(IsLabFrame()) SetFourVector(Ptot,*this);
296 
297  return SetSpirit(true);
298  }
299 
301  if(!IsSoundMind()){
302  UnSoundMind(RF_FUNCTION);
303  return SetSpirit(false);
304  }
305  if(!ReconstructFrame()){
306  m_Log << LogWarning;
307  m_Log << "Unable to reconstruct event for this frame.";
308  m_Log << LogEnd;
309  return SetSpirit(false);
310  }
311 
312  int Nchild = GetNChildren();
313  for(int i = 0; i < Nchild; i++){
315  TVector3 boost = GetChildBoostVector(child);
316 
317  bool terminal = child.IsVisibleFrame() || child.IsInvisibleFrame();
318  if(!terminal){
319  boost *= -1.;
320  if(boost.Mag() < 1.)
321  m_ChildStates[&child].Boost(boost);
322  }
323 
324  if(!child.AnalyzeEventRecursive())
325  return SetSpirit(false);
326 
327  if(!terminal){
328  boost *= -1.;
329  if(boost.Mag() < 1.)
330  m_ChildStates[&child].Boost(boost);
331  }
332  }
333 
334  return SetSpirit(true);
335  }
336 
337 }
RestFrames::ReconstructionFrame::AnalyzeEventRecursive
bool AnalyzeEventRecursive()
Recursively analyze event in this frame and its children.
Definition: ReconstructionFrame.cc:300
RestFrames::RestFrame::GetLabFrame
virtual RestFrame const & GetLabFrame() const
Returns the LabFrame that this frame inherits from.
Definition: RestFrame.cc:256
RestFrames::RestFrame::SetParentFrame
virtual void SetParentFrame(RestFrame &frame=RestFrame::Empty())
Sets the parent frame for this frame.
Definition: RestFrame.cc:181
RestFrames::RestFrame::GetChildFrame
virtual RestFrame & GetChildFrame(int i=0) const
Get the RestFrame of the i th child.
Definition: RestFrame.cc:235
RestFrames::ReconstructionFrame::ClearEventRecursive
bool ClearEventRecursive()
Recursively clear event information from this frame and its children.
Definition: ReconstructionFrame.cc:245
RestFrames::RestFrame::GetListInvisibleFrames
virtual RestFrameList GetListInvisibleFrames() const
Returns a list of InvisibleFrame s inheriting from this.
Definition: RestFrame.cc:348
RestFrames::State::EmptyList
static StateList const & EmptyList()
Returns empty StateList.
Definition: State.cc:72
RestFrames::ReconstructionFrame::GetParentFrame
virtual ReconstructionFrame const & GetParentFrame() const
Returns the parent of this frame.
Definition: ReconstructionFrame.cc:97
VisibleRecoFrame.hh
ReconstructionFrame.hh
RestFrames::Group::Empty
static Group & Empty()
Returns empty Group.
Definition: Group.cc:58
RestFrames::ReconstructionFrame::InitializeAnalysisRecursive
bool InitializeAnalysisRecursive()
Recursively initialize this frame and its children for analysis.
Definition: ReconstructionFrame.cc:218
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::RestFrame::AddChildFrame
virtual void AddChildFrame(RestFrame &frame)
Adds a child RestFrame to this frame.
Definition: RestFrame.cc:198
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::ReconstructionFrame::SetParentFrame
virtual void SetParentFrame(RestFrame &frame=RestFrame::Empty())
Set the parent frame for this frame.
Definition: ReconstructionFrame.cc:91
RestFrames::RFList< State >
RestFrames::Group::RemoveFrame
virtual void RemoveFrame(RestFrame &frame)
Removes a frame (RestFrame) from this group.
Definition: Group.cc:117
RestFrames::ReconstructionFrame::AddChildFrame
virtual void AddChildFrame(RestFrame &frame)
Add a child RestFrame to this frame.
Definition: ReconstructionFrame.cc:66
RestFrames::RestFrame::GetNChildren
int GetNChildren() const
Returns the number of child frames inheriting from this one.
Definition: RestFrame.cc:231
RestFrames::ReconstructionFrame::ReconstructionFrame
ReconstructionFrame()
Empty constructor.
Definition: ReconstructionFrame.cc:49
RestFrames::RestFrame::GetParentFrame
virtual RestFrame const & GetParentFrame() const
Returns the parent of this frame.
Definition: RestFrame.cc:245
RestFrames::RestFrame::IsInvisibleFrame
bool IsInvisibleFrame() const
Is this an InvisibleFrame ? (yes/no)
Definition: RestFrame.cc:101
RestFrames::ReconstructionFrame::GetChildFrame
virtual ReconstructionFrame & GetChildFrame(int i=0) const
Get the frame of the i th child.
Definition: ReconstructionFrame.cc:105
RestFrames::RestFrame::GetCharge
virtual RFCharge GetCharge() const
Returns the charge of this frame.
Definition: RestFrame.cc:427
RestFrames::ReconstructionFrame::RemoveChildFrame
virtual void RemoveChildFrame(RestFrame &frame)
Remove a child of this frame.
Definition: ReconstructionFrame.cc:72
RestFrames::RestFrame::Clear
virtual void Clear()
Clears RestFrame of all connections to other objects.
Definition: RestFrame.cc:57
RestFrames::RestFrame::GetListVisibleFrames
virtual RestFrameList GetListVisibleFrames() const
Returns a list of VisibleFrame s inheriting from this.
Definition: RestFrame.cc:344
VisibleState.hh
RestFrames::ReconstructionFrame::SetGroup
virtual void SetGroup(Group &group=Group::Empty())
Sets group of this frame.
Definition: ReconstructionFrame.cc:124
RestFrames::RestFrame::IsVisibleFrame
bool IsVisibleFrame() const
Is this a VisibleFrame ? (yes/no)
Definition: RestFrame.cc:97
RestFrames::RestFrame::RestFrame
RestFrame()
Empty constructor.
Definition: RestFrame.cc:39
RestFrames::ReconstructionFrame::GetListGroups
GroupList GetListGroups() const
Returns a list of groups (GroupList) of this class.
Definition: ReconstructionFrame.cc:149
RestFrames::VisibleRecoFrame::Empty
static VisibleRecoFrame & Empty()
Returns empty VisibleRecoFrame.
Definition: VisibleRecoFrame.cc:48
RestFrames::RestFrame::IsLabFrame
bool IsLabFrame() const
Is this a LabFrame ? (yes/no)
Definition: RestFrame.cc:109
RestFrames::ReconstructionFrame::Empty
static ReconstructionFrame & Empty()
Returns empty ReconstructionFrame.
Definition: ReconstructionFrame.cc:62
RestFrames::ReconstructionFrame::GetGroup
Group & GetGroup() const
Returns group of this class.
Definition: ReconstructionFrame.cc:142
RestFrames::ReconstructionFrame::RemoveChildFrames
void RemoveChildFrames()
Remove all the children of this frame.
Definition: ReconstructionFrame.cc:82
RestFrames::ReconstructionFrame
Definition: ReconstructionFrame.hh:41
Group.hh
LabRecoFrame.hh
RestFrames::ReconstructionFrame::Clear
virtual void Clear()
Clears ReconstructionFrame of all connections to other objects.
Definition: ReconstructionFrame.cc:56