LOGO

RestFrames  v1.0.0
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 
45  LabRecoFrame::LabRecoFrame() : LabFrame<ReconstructionFrame>() {}
46 
47  LabRecoFrame::~LabRecoFrame(){
48  Clear();
49  }
50 
52  m_TreeGroups.Clear();
53  m_TreeJigsaws.Clear();
54  m_TreeStates.Clear();
56  }
57 
58  void LabRecoFrame::AddTreeState(VisibleState& state) const {
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 
70  void LabRecoFrame::RemoveTreeStates(const VisibleStateList& states) const {
71  m_TreeStates -= states;
72  }
73 
74  VisibleStateList const& LabRecoFrame::GetTreeStates() const {
75  return m_TreeStates;
76  }
77 
78  bool LabRecoFrame::InitializeAnalysis(){
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 
104  if(!InitializeAnalysisRecursive()){
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  int Nj = m_TreeJigsaws.GetN();
216  for(int j = 0; j < Nj; j++){
217  if(!m_TreeJigsaws[j].InitializeJigsawExecutionList(exec_jigsaws)){
218  m_TreeJigsaws.Clear();
219  m_Log << LogWarning;
220  m_Log << "Unable to initialize Jigsaw execution list in Jigsaw:" << std::endl;
221  m_Log << Log(m_TreeJigsaws[j]) << LogEnd;
222  return false;
223  }
224  }
225  m_TreeJigsaws.Clear();
226  m_TreeJigsaws += exec_jigsaws;
227 
228  m_Log << LogVerbose << "...Done initializing Jigsaws" << LogEnd;
229  return true;
230  }
231 
232  bool LabRecoFrame::ClearEvent(){
233  SetSpirit(false);
234  if(!IsSoundMind()){
235  UnSoundMind(RF_FUNCTION);
236  return SetMind(false);
237  }
238 
239  int Ng = m_TreeGroups.GetN();
240  for(int i = 0; i < Ng; i++)
241  if(!m_TreeGroups[i].ClearEvent())
242  return SetMind(false);
243 
244  if(!ClearEventRecursive())
245  return SetMind(false);
246 
247  return SetMind(true);
248  }
249 
250  bool LabRecoFrame::AnalyzeEvent(){
251  if(!IsSoundMind()){
252  UnSoundMind(RF_FUNCTION);
253  return SetSpirit(false);
254  }
255 
256  int Ns = m_TreeStates.GetN();
257  for(int i = 0; i < Ns; i++){
258  m_TreeStates[i].SetLabFrameFourVector();
259  }
260 
261  int Ng = m_TreeGroups.GetN();
262  for(int i = 0; i < Ng; i++){
263  if(!m_TreeGroups[i].AnalyzeEvent()){
264  m_Log << LogWarning;
265  m_Log << "Unable to analyze event for Group: ";
266  m_Log << Log(m_TreeGroups[i]) << LogEnd;
267  return SetSpirit(false);
268  }
269  }
270  int Nj = m_TreeJigsaws.GetN();
271  for(int i = 0; i < Nj; i++){
272  if(!m_TreeJigsaws[i].AnalyzeEvent()){
273  m_Log << LogWarning;
274  m_Log << "Unable to analyze event for Jigsaw: ";
275  m_Log << Log(m_TreeJigsaws[i]) << LogEnd;
276  return SetSpirit(false);
277  }
278  }
279  if(!AnalyzeEventRecursive()){
280  m_Log << LogWarning;
281  m_Log << "Unable to recursively analyze event" << LogEnd;
282  return SetSpirit(false);
283  }
284  return SetSpirit(true);
285  }
286 
287  VisibleState& LabRecoFrame::GetNewVisibleState(){
288  if(m_TreeStates.GetN() < m_InitStates.GetN())
289  return m_InitStates[m_TreeStates.GetN()];
290  char strn[10];
291  sprintf(strn,"%d",m_TreeStates.GetN()+1);
292  std::string name = GetName()+"_"+std::string(strn);
293  VisibleState* statePtr = new VisibleState(name, name);
294  AddDependent(statePtr);
295  m_InitStates.Add(*statePtr);
296  return *statePtr;
297  }
298 
299 }
virtual void Clear()
Clears ReconstructionFrame of all connections to other objects.
virtual void Clear()
Clears ReconstructionFrame of all connections to other objects.
Definition: LabRecoFrame.cc:51