LOGO

RestFrames  v1.0.1
RestFrames HEP Event Analysis Software Library
LabRecoFrame.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/Jigsaw.hh"
33 #include "RestFrames/Group.hh"
35 
36 namespace RestFrames {
37 
39  // LabRecoFrame class
41  LabRecoFrame::LabRecoFrame(const std::string& sname,
42  const std::string& stitle)
43  : LabFrame<ReconstructionFrame>(sname, stitle) {}
44 
46 
47  LabRecoFrame::~LabRecoFrame(){
48  Clear();
49  }
50 
52  m_TreeGroups.Clear();
53  m_TreeJigsaws.Clear();
54  m_TreeStates.Clear();
56  }
57 
59  m_TreeStates += state;
60  }
61 
62  void LabRecoFrame::AddTreeStates(const VisibleStateList& states) const {
63  m_TreeStates += states;
64  }
65 
66  void LabRecoFrame::RemoveTreeState(const VisibleState& state) const {
67  m_TreeStates -= state;
68  }
69 
71  m_TreeStates -= states;
72  }
73 
75  return m_TreeStates;
76  }
77 
79  m_Log << LogVerbose << "Initializing this tree for analysis..." << LogEnd;
80 
81  if(!IsSoundBody()){
82  UnSoundBody(RF_FUNCTION);
83  return SetMind(false);
84  }
85 
86  if(!InitializeTreeGroups()){
87  m_Log << LogWarning;
88  m_Log << "Unable to intialize Groups for analysis" << LogEnd;
89  return SetMind(false);
90  }
91 
92  if(!InitializeTreeStates()){
93  m_Log << LogWarning;
94  m_Log << "Unable to intialize States for analysis" << LogEnd;
95  return SetMind(false);
96  }
97 
98  if(!InitializeTreeJigsaws()){
99  m_Log << LogWarning;
100  m_Log << "Unable to intialize Jigsaws for analysis" << LogEnd;
101  return SetMind(false);
102  }
103 
105  m_Log << LogWarning;
106  m_Log << "Unable to recursively initialize tree for analysis";
107  m_Log << LogEnd;
108  return SetMind(false);
109  }
110 
111  m_Log << LogVerbose << "...Done initializing tree for analysis" << LogEnd;
112  return SetMind(true);
113  }
114 
115  bool LabRecoFrame::InitializeTreeGroups(){
116  m_Log << LogVerbose << "Initializing Groups for analysis..." << LogEnd;
117 
118  m_TreeGroups.Clear();
119  m_TreeGroups += GetListGroups();
120 
121  int Ngroup = m_TreeGroups.GetN();
122  for(int i = 0; i < Ngroup; i++){
123  if(!m_TreeGroups[i].InitializeAnalysis()){
124  m_Log << LogWarning;
125  m_Log << "Unable to initialize analysis for Group ";
126  m_Log << Log(m_TreeGroups[i]) << LogEnd;
127  return false;
128  }
129  }
130  m_Log << LogVerbose << "...Done initializing Groups for analysis" << LogEnd;
131  return true;
132  }
133 
134  bool LabRecoFrame::InitializeTreeStates(){
135  m_Log << LogVerbose << "Initializing States for analysis..." << LogEnd;
136 
137  m_TreeStates.Clear();
138  int Ng = m_TreeGroups.GetN();
139 
140  RFList<ReconstructionFrame> frames = GetListVisibleFrames();
141  int Nf = frames.GetN();
142  for(int f = 0; f < Nf; f++){
143  bool has_group = false;
144  for(int g = 0; g < Ng; g++){
145  if(m_TreeGroups[g].ContainsFrame(frames[f])){
146  has_group = true;
147  break;
148  }
149  }
150  if(!has_group) {
151  VisibleState& state = GetNewVisibleState();
152  state.AddFrame(frames[f]);
153  state.SetCharge(frames[f].GetCharge());
154  m_TreeStates += state;
155  }
156  }
157 
158  frames = GetListInvisibleFrames();
159  Nf = frames.GetN();
160  for(int f = 0; f < Nf; f++){
161  bool has_group = false;
162  for(int g = 0; g < Ng; g++){
163  if(m_TreeGroups[g].ContainsFrame(frames[f])){
164  has_group = true;
165  break;
166  }
167  }
168  if(!has_group){
169  m_Log << LogWarning;
170  m_Log << "Found InvisibleRecoFrame without an assigned group: " << std::endl;
171  m_Log << Log(frames[f]) << LogEnd;
172  return false;
173  }
174  }
175  m_Log << LogVerbose << "...Done initializing States" << LogEnd;
176  return true;
177  }
178 
179  bool LabRecoFrame::InitializeTreeJigsaws(){
180  m_Log << LogVerbose << "Initializing Jigsaws for analysis..." << LogEnd;
181 
182  m_TreeJigsaws.Clear();
183 
184  int Ng = m_TreeGroups.GetN();
185 
186  // Initialize Dependancy States in Jigsaws
187  for(int g = 0; g < Ng; g++){
188  JigsawList jigsaws = m_TreeGroups[g].GetListJigsaws();
189  int Nj = jigsaws.GetN();
190  for(int j = 0; j < Nj; j++)
191  if(!jigsaws[j].InitializeAnalysis()){
192  m_Log << LogWarning;
193  m_Log << "Unable to initialize Jigsaw for analysis:" << std::endl;
194  m_Log << Log(jigsaws[j]) << LogEnd;
195  return false;
196  }
197  }
198  // Initialize Dependancy Jigsaw lists inside jigsaws
199  for(int g = 0; g < Ng; g++){
200  JigsawList jigsaws = m_TreeGroups[g].GetListJigsaws();
201  int Nj = jigsaws.GetN();
202  for(int j = 0; j < Nj; j++){
203  Jigsaw& jigsaw = jigsaws[j];
204  if(!jigsaw.InitializeDependancyJigsaws()){
205  m_Log << LogWarning;
206  m_Log << "Unable to initialize dependancy Jigsaw list for Jigsaw:" << std::endl;
207  m_Log << Log(jigsaw) << LogEnd;
208  return false;
209  }
210  m_TreeJigsaws.Add(jigsaw);
211  }
212  }
213  // Initialize Jigsaw execution list
214  JigsawList exec_jigsaws;
215  JigsawList todo_jigsaws;
216  int Nj = m_TreeJigsaws.GetN();
217  for(int j = 0; j < Nj; j++){
218  if(!m_TreeJigsaws[j].InitializeJigsawExecutionList(exec_jigsaws, todo_jigsaws)){
219  m_TreeJigsaws.Clear();
220  m_Log << LogWarning;
221  m_Log << "Unable to initialize Jigsaw execution list in Jigsaw:" << std::endl;
222  m_Log << Log(m_TreeJigsaws[j]) << LogEnd;
223  return false;
224  }
225  }
226  m_TreeJigsaws.Clear();
227  m_TreeJigsaws += todo_jigsaws;
228 
229  m_Log << LogVerbose << "...Done initializing Jigsaws" << LogEnd;
230  return true;
231  }
232 
234  SetSpirit(false);
235  if(!IsSoundMind()){
236  UnSoundMind(RF_FUNCTION);
237  return SetMind(false);
238  }
239 
240  int Ng = m_TreeGroups.GetN();
241  for(int i = 0; i < Ng; i++)
242  if(!m_TreeGroups[i].ClearEvent())
243  return SetMind(false);
244 
245  if(!ClearEventRecursive())
246  return SetMind(false);
247 
248  return SetMind(true);
249  }
250 
252  if(!IsSoundMind()){
253  UnSoundMind(RF_FUNCTION);
254  return SetSpirit(false);
255  }
256 
257  int Ns = m_TreeStates.GetN();
258  for(int i = 0; i < Ns; i++){
259  m_TreeStates[i].SetLabFrameFourVector();
260  }
261 
262  int Ng = m_TreeGroups.GetN();
263  for(int i = 0; i < Ng; i++){
264  if(!m_TreeGroups[i].AnalyzeEvent()){
265  m_Log << LogWarning;
266  m_Log << "Unable to analyze event for Group: ";
267  m_Log << Log(m_TreeGroups[i]) << LogEnd;
268  return SetSpirit(false);
269  }
270  }
271  int Nj = m_TreeJigsaws.GetN();
272  for(int i = 0; i < Nj; i++){
273  if(!m_TreeJigsaws[i].AnalyzeEvent()){
274  m_Log << LogWarning;
275  m_Log << "Unable to analyze event for Jigsaw: ";
276  m_Log << Log(m_TreeJigsaws[i]) << LogEnd;
277  return SetSpirit(false);
278  }
279  }
280  if(!AnalyzeEventRecursive()){
281  m_Log << LogWarning;
282  m_Log << "Unable to recursively analyze event" << LogEnd;
283  return SetSpirit(false);
284  }
285  return SetSpirit(true);
286  }
287 
288  VisibleState& LabRecoFrame::GetNewVisibleState(){
289  if(m_TreeStates.GetN() < m_InitStates.GetN())
290  return m_InitStates[m_TreeStates.GetN()];
291  char strn[10];
292  sprintf(strn,"%d",m_TreeStates.GetN()+1);
293  std::string name = GetName()+"_"+std::string(strn);
294  VisibleState* statePtr = new VisibleState(name, name);
295  AddDependent(statePtr);
296  m_InitStates.Add(*statePtr);
297  return *statePtr;
298  }
299 
300 }
RestFrames::ReconstructionFrame::AnalyzeEventRecursive
bool AnalyzeEventRecursive()
Recursively analyze event in this frame and its children.
Definition: ReconstructionFrame.cc:300
RestFrames::ReconstructionFrame::ClearEventRecursive
bool ClearEventRecursive()
Recursively clear event information from this frame and its children.
Definition: ReconstructionFrame.cc:245
RestFrames::LabRecoFrame::ClearEvent
virtual bool ClearEvent()
Clears event.
Definition: LabRecoFrame.cc:233
RestFrames::RestFrame::GetListInvisibleFrames
virtual RestFrameList GetListInvisibleFrames() const
Returns a list of InvisibleFrame s inheriting from this.
Definition: RestFrame.cc:348
RestFrames::LabRecoFrame::RemoveTreeState
void RemoveTreeState(const VisibleState &state) const
Removes a state from "VisibleStateList" of this frame.
Definition: LabRecoFrame.cc:66
RestFrames::LabRecoFrame::AddTreeStates
void AddTreeStates(const VisibleStateList &states) const
Adds states to "VisibleStateList" of this frame.
Definition: LabRecoFrame.cc:62
VisibleRecoFrame.hh
RestFrames::ReconstructionFrame::InitializeAnalysisRecursive
bool InitializeAnalysisRecursive()
Recursively initialize this frame and its children for analysis.
Definition: ReconstructionFrame.cc:218
RestFrames::LabRecoFrame::LabRecoFrame
LabRecoFrame()
Empty constructor.
Definition: LabRecoFrame.cc:45
RestFrames::RFList< VisibleState >
RestFrames::VisibleState
Definition: VisibleState.hh:39
Jigsaw.hh
RestFrames::RFBase::GetName
std::string GetName() const
Returns object name.
Definition: RFBase.cc:104
RestFrames::LabRecoFrame::RemoveTreeStates
void RemoveTreeStates(const VisibleStateList &states) const
Removes states from "VisibleStateList" of this frame.
Definition: LabRecoFrame.cc:70
RestFrames::LabRecoFrame::Clear
virtual void Clear()
Clears LabRecoFrame from all connections to other objects.
Definition: LabRecoFrame.cc:51
RestFrames::RestFrame::GetCharge
virtual RFCharge GetCharge() const
Returns the charge of this frame.
Definition: RestFrame.cc:427
RestFrames::RestFrame::GetListVisibleFrames
virtual RestFrameList GetListVisibleFrames() const
Returns a list of VisibleFrame s inheriting from this.
Definition: RestFrame.cc:344
RestFrames::LabRecoFrame::InitializeAnalysis
virtual bool InitializeAnalysis()
Initialize analysis capability of a tree to reconstruct events.
Definition: LabRecoFrame.cc:78
VisibleState.hh
RestFrames::ReconstructionFrame::GetListGroups
GroupList GetListGroups() const
Returns a list of groups (GroupList) of this class.
Definition: ReconstructionFrame.cc:149
RestFrames::LabRecoFrame::AnalyzeEvent
virtual bool AnalyzeEvent()
Analyzes event.
Definition: LabRecoFrame.cc:251
RestFrames::LabFrame
Definition: LabFrame.hh:41
RestFrames::LabRecoFrame::AddTreeState
void AddTreeState(VisibleState &state) const
Adds a state to "VisibleStateList" of this frame.
Definition: LabRecoFrame.cc:58
RestFrames::RFBase::AddDependent
void AddDependent(RFBase *dep)
pointer to RFBase object owned by this one
Definition: RFBase.cc:88
RestFrames::ReconstructionFrame
Definition: ReconstructionFrame.hh:41
Group.hh
RestFrames::LabRecoFrame::GetTreeStates
VisibleStateList const & GetTreeStates() const
Returns list of visible states of this frame.
Definition: LabRecoFrame.cc:74
LabRecoFrame.hh
RestFrames::ReconstructionFrame::Clear
virtual void Clear()
Clears ReconstructionFrame of all connections to other objects.
Definition: ReconstructionFrame.cc:56