CMS 3D CMS Logo

FWGeometryTableManager.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWGeometryTableManager
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author:
10 // Created: Wed Jan 4 20:31:25 CET 2012
11 //
12 
13 // system include files
14 
15 // user include files
20 
21 #include "TEveUtil.h"
22 #include "TEveVector.h"
23 #include "TGeoShape.h"
24 #include "TGeoMatrix.h"
25 #include "TGeoBBox.h"
26 #include "TPRegexp.h"
27 
29  : FWGeometryTableManagerBase(), m_browser(v), m_filterOff(true) {}
30 
32 
33 const char* FWGeometryTableManager::cellName(const NodeInfo& data) const {
34  if (m_browser->getVolumeMode())
35  return Form("%s [%d]", data.m_node->GetVolume()->GetName(), data.m_node->GetNdaughters());
36  else
37  return Form("%s [%d]", data.m_node->GetName(), data.m_node->GetNdaughters());
38 }
39 
40 //------------------------------------------------------------------------------
41 
42 FWTableCellRendererBase* FWGeometryTableManager::cellRenderer(int iSortedRowNumber, int iCol) const {
44  if (m_row_to_index.empty())
45  return renderer;
46 
47  int unsortedRow = m_row_to_index[iSortedRowNumber];
48  if (unsortedRow < 0)
49  printf("!!!!!!!!!!!!!!!! error %d %d \n", unsortedRow, iSortedRowNumber);
50 
51  // editor state
52  //
53  m_renderer.showEditor(unsortedRow == m_editTransparencyIdx && iCol == kTranspColumn);
54 
55  // selection state
56  //
57  const NodeInfo& data = m_entries[unsortedRow];
58  TGeoNode& gn = *data.m_node;
59  bool isSelected = data.testBit(kHighlighted) || data.testBit(kSelected);
60  // printf("cell render %s \n", data.name());
61  if (data.testBit(kSelected)) {
62  m_highlightContext->SetBackground(0xc86464);
63  } else if (data.testBit(kHighlighted)) {
64  m_highlightContext->SetBackground(0x6464c8);
65  } else if (iCol == kMaterialColumn && data.testBit(kMatches)) {
66  m_highlightContext->SetBackground(0xdddddd);
67  }
68 
69  // set column content
70  //
71  if (iCol == kNameColumn) {
72  renderer->setData(cellName(data), isSelected);
73 
74  renderer->setIsParent(nodeIsParent(data));
75 
77 
78  int level = data.m_level - m_levelOffset;
79  if (nodeIsParent(data))
80  renderer->setIndentation(20 * level);
81  else
83 
84  return renderer;
85  } else {
86  // printf("title %s \n",data.m_node->GetTitle());
87  renderer->setIsParent(false);
88  renderer->setIndentation(0);
89  if (iCol == kColorColumn) {
90  // m_colorBoxRenderer.setData(data.m_node->GetVolume()->GetLineColor(), isSelected);
92  return &m_colorBoxRenderer;
93  } else if (iCol == kTranspColumn) {
94  renderer->setData(Form("%d", 100 - data.m_transparency), isSelected);
95  return renderer;
96  } else if (iCol == kVisSelfColumn) {
97  renderer->setData(getVisibility(data) ? "On" : "-", isSelected);
98  return renderer;
99  } else if (iCol == kVisChildColumn) {
100  renderer->setData(getVisibilityChld(data) ? "On" : "-", isSelected);
101  return renderer;
102  } else if (iCol == kMaterialColumn) {
103  renderer->setData(gn.GetVolume()->GetMaterial()->GetName(), isSelected);
104  return renderer;
105  } else {
106  renderer->setData("ERROR", false);
107  return renderer;
108  }
109  }
110 }
111 
112 //------------------------------------------------------------------------------
113 
115  NodeInfo& parent = m_entries[parent_idx];
116  TGeoNode* parentGeoNode = parent.m_node;
117  int parentLevel = parent.m_level;
118 
119  int nV = parentGeoNode->GetNdaughters();
120  int dOff = 0;
121  for (int n = 0; n != nV; ++n) {
122  NodeInfo& data = m_entries[parent_idx + n + 1 + dOff];
123  data.m_node = parentGeoNode->GetDaughter(n);
124  data.m_level = parentLevel + 1;
125  data.m_parent = parent_idx;
126  data.m_color = data.m_node->GetVolume()->GetLineColor();
127  data.m_transparency = data.m_node->GetVolume()->GetTransparency();
128  if (data.m_level <= m_browser->getAutoExpand())
129  data.setBit(kExpanded);
130 
131  importChildren(parent_idx + n + 1 + dOff);
132  getNNodesTotal(parentGeoNode->GetDaughter(n), dOff);
133  }
134 }
135 
136 //==============================================================================
137 
139  // Used for debug: in a NodeInfo entry look TGeoNode children from parent index and check
140  // if child is found.
141 
142  for (size_t i = 0, e = m_entries.size(); i != e; ++i) {
143  if (m_entries[i].m_level > 0) {
144  TGeoNode* pn = m_entries[m_entries[i].m_parent].m_node;
145  bool ok = false;
146  for (int d = 0; d < pn->GetNdaughters(); ++d) {
147  if (m_entries[i].m_node == pn->GetDaughter(d)) {
148  ok = true;
149  break;
150  }
151  }
152  if (!ok)
153  printf("!!!!!! node %s has false parent %s \n", m_entries[i].name(), pn->GetName());
154  }
155  }
156 }
157 
158 void FWGeometryTableManager::checkChildMatches(TGeoVolume* vol, std::vector<TGeoVolume*>& pstack) {
159  if (m_volumes[vol].m_matches) {
160  for (std::vector<TGeoVolume*>::iterator i = pstack.begin(); i != pstack.end(); ++i) {
161  Match& pm = m_volumes[*i];
162  pm.m_childMatches = true;
163  }
164  }
165 
166  pstack.push_back(vol);
167 
168  int nD = vol->GetNdaughters(); //TMath::Min(m_browser->getMaxDaughters(), vol->GetNdaughters());
169  for (int i = 0; i < nD; ++i)
170  checkChildMatches(vol->GetNode(i)->GetVolume(), pstack);
171 
172  pstack.pop_back();
173 }
174 
175 //------------------------------------------------------------------------------
176 // Callbacks
177 //------------------------------------------------------------------------------
178 namespace {
179  int matchTPME(const char* w, TPMERegexp& regexp) {
180  TString s(w);
181  return regexp.Match(s);
182  }
183 } // namespace
184 
186  std::string filterExp = m_browser->getFilter();
187  m_filterOff = filterExp.empty();
188  printf("update filter %s OFF %d volumes size %d\n", filterExp.c_str(), m_filterOff, (int)m_volumes.size());
189 
190  if (m_filterOff || m_entries.empty())
191  return;
192 
193  // update volume-match entries
194  int numMatched = 0;
195 
196  TPMERegexp regexp(TString(filterExp.c_str()), "o");
197  for (Volumes_i i = m_volumes.begin(); i != m_volumes.end(); ++i) {
198  int res = 0;
199 
201  res = matchTPME(i->first->GetMaterial()->GetName(), regexp);
202  } else if (iType == FWGeometryTableView::kFilterMaterialTitle) {
203  res = matchTPME(i->first->GetMaterial()->GetTitle(), regexp);
204  } else if (iType == FWGeometryTableView::kFilterShapeName) {
205  res = matchTPME(i->first->GetShape()->GetName(), regexp);
206  } else if (iType == FWGeometryTableView::kFilterShapeClassName) {
207  res = matchTPME(i->first->GetShape()->ClassName(), regexp);
208  }
209 
210  i->second.m_matches = (res > 0);
211  i->second.m_childMatches = false;
212  if (res)
213  numMatched++;
214  }
215 
216  printf("update filter [%d] volumes matched\n", numMatched);
217  std::vector<TGeoVolume*> pstack;
218  checkChildMatches(m_entries[0].m_node->GetVolume(), pstack);
219 
220  for (Entries_i ni = m_entries.begin(); ni != m_entries.end(); ++ni) {
221  ni->resetBit(kFilterCached);
223  }
224 }
225 
226 //==============================================================================
227 
228 void FWGeometryTableManager::loadGeometry(TGeoNode* iGeoTopNode, TObjArray* iVolumes) {
229 #ifdef PERFTOOL_GEO_TABLE
230  ProfilerStart("loadGeo");
231 #endif
232 
233  // Prepare data for cell render.
234 
235  // clear entries
236  m_entries.clear();
237  m_row_to_index.clear();
238  m_volumes.clear();
239  m_levelOffset = 0;
240 
241  // set volume table for filters
242  Volumes_t pipi(iVolumes->GetSize());
243  m_volumes.swap(pipi);
244  TIter next(iVolumes);
245  TGeoVolume* v;
246  while ((v = (TGeoVolume*)next()) != nullptr)
247  m_volumes.insert(std::make_pair(v, Match()));
248 
249  if (!m_filterOff)
251 
252  // add top node to init
253 
254  int nTotal = 0;
255  NodeInfo topNodeInfo;
256  topNodeInfo.m_node = iGeoTopNode;
257  topNodeInfo.m_level = 0;
258  topNodeInfo.m_parent = -1;
259  topNodeInfo.m_color = iGeoTopNode->GetVolume()->GetLineColor();
260  topNodeInfo.m_transparency = iGeoTopNode->GetVolume()->GetTransparency();
261  topNodeInfo.setBitVal(kExpanded, m_browser->getAutoExpand());
262  topNodeInfo.setBitVal(kVisNodeSelf, m_browser->drawTopNode());
263 
264  getNNodesTotal(topNodeInfo.m_node, nTotal);
265  m_entries.resize(nTotal + 1);
266  m_entries[0] = topNodeInfo;
267 
268  importChildren(0);
269 
270  // checkHierarchy();
271 
272 #ifdef PERFTOOL_GEO_TABLE
273  ProfilerStop();
274 #endif
275 }
276 
277 //------------------------------------------------------------------------------
278 
279 void FWGeometryTableManager::printMaterials() { std::cerr << "not implemented \n"; }
280 
281 //------------------------------------------------------------------------------
282 
284  m_row_to_index.clear();
285 
286  int i = TMath::Max(0, m_browser->getTopNodeIdx());
287  m_row_to_index.push_back(i);
288 
289  NodeInfo& data = m_entries[i];
290 
291  if (!m_filterOff)
293 
294  if ((m_filterOff && data.testBit(kExpanded) == false) ||
295  (m_filterOff == false && data.testBit(kChildMatches) == false))
296  return;
297 
298  if (m_browser->getVolumeMode())
300  else
302 
303  // printf (" child [%d] FWGeometryTableManagerBase::recalculateVisibility table size %d \n", (int)m_row_to_index.size());
304 }
305 
306 //------------------------------------------------------------------------------
307 
309  TGeoNode* parentNode = m_entries[pIdx].m_node;
310  int nD = parentNode->GetNdaughters();
311  int dOff = 0;
312 
313  // printf("----------- parent %s\n", parentNode->GetName() );
314 
315  std::vector<int> vi;
316  vi.reserve(nD);
317 
318  for (int n = 0; n != nD; ++n) {
319  int idx = pIdx + 1 + n + dOff;
321 
322  bool toAdd = true;
323  for (std::vector<int>::iterator u = vi.begin(); u != vi.end(); ++u) {
324  TGeoVolume* neighbourVolume = parentNode->GetDaughter(*u)->GetVolume();
325  if (neighbourVolume == data.m_node->GetVolume()) {
326  toAdd = false;
327  // printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
328  break;
329  }
330  }
331 
332  if (toAdd) {
333  vi.push_back(n);
334  if (m_filterOff) {
335  // std::cout << data.nameIndent() << std::endl;
336  m_row_to_index.push_back(idx);
337  if (data.testBit(kExpanded))
339  } else {
341  if (data.testBitAny(kMatches | kChildMatches))
342  m_row_to_index.push_back(idx);
343  if (data.testBit(kChildMatches) && data.testBit(kExpanded))
345  }
346  }
347  FWGeometryTableManagerBase::getNNodesTotal(parentNode->GetDaughter(n), dOff);
348  }
349 }
350 
351 //------------------------------------------------------------------------------
352 
354  TGeoNode* parentNode = m_entries[pIdx].m_node;
355  int nD = parentNode->GetNdaughters();
356  int dOff = 0;
357  for (int n = 0; n != nD; ++n) {
358  int idx = pIdx + 1 + n + dOff;
360 
361  if (m_filterOff) {
362  m_row_to_index.push_back(idx);
363  if (data.testBit(kExpanded))
365  } else {
367  if (data.testBitAny(kMatches | kChildMatches))
368  m_row_to_index.push_back(idx);
369  if (data.testBit(kChildMatches) && data.testBit(kExpanded))
371  }
372 
373  FWGeometryTableManagerBase::getNNodesTotal(parentNode->GetDaughter(n), dOff);
374  }
375 }
376 
377 //------------------------------------------------------------------------------
378 
380  if (!data.testBit(kFilterCached)) {
381  bool matches = m_volumes[data.m_node->GetVolume()].m_matches;
382  // if (matches) printf("%s matches filter \n", data.name());
383  data.setBitVal(kMatches, matches);
385 
386  bool childMatches = m_volumes[data.m_node->GetVolume()].m_childMatches;
387  data.setBitVal(kChildMatches, childMatches);
388  data.setBitVal(kExpanded, childMatches);
389  setVisibilityChld(data, childMatches);
390 
391  data.setBit(kFilterCached);
392  // printf("%s matches [%d] childMatches [%d] ................ %d %d \n", data.name(), data.testBit(kMatches), data.testBit(kChildMatches), matches , childMatches);
393  }
394 }
395 
396 //------------------------------------------------------------------------------
397 
399  if (m_browser->getVolumeMode()) {
400  if (data.m_node->GetVolume()->IsVisible() != x) {
402  data.m_node->GetVolume()->SetVisibility(x);
403  }
404  } else {
405  data.setBitVal(kVisNodeSelf, x);
406  }
407 }
408 
409 //------------------------------------------------------------------------------
410 
412  if (m_browser->getVolumeMode()) {
413  if (data.m_node->GetVolume()->IsVisibleDaughters() != x) {
414  TEveGeoManagerHolder gmgr(FWGeometryTableViewManager::getGeoMangeur());
415  data.m_node->GetVolume()->VisibleDaughters(x);
416  }
417  } else {
418  data.setBitVal(kVisNodeChld, x);
419  }
420 }
421 //______________________________________________________________________________
422 
424  TGeoNode* parentNode = m_entries[selectedIdx].m_node;
425  int nD = parentNode->GetNdaughters();
426  int dOff = 0;
427  for (int n = 0; n != nD; ++n) {
428  int idx = selectedIdx + 1 + n + dOff;
430 
431  setVisibility(data, v);
433 
434  FWGeometryTableManager::getNNodesTotal(parentNode->GetDaughter(n), dOff);
435  }
436 }
437 
438 //------------------------------------------------------------------------------
439 
441  if (m_browser->getVolumeMode())
442  return data.m_node->GetVolume()->IsVisible();
443 
444  return data.testBit(kVisNodeSelf);
445 }
446 
448  if (m_browser->getVolumeMode())
449  return data.m_node->GetVolume()->IsVisibleDaughters();
450 
451  return data.testBit(kVisNodeChld);
452 }
453 
454 //------------------------------------------------------------------------------
455 
457  return (data.m_node->GetNdaughters() != 0) && (m_filterOff || data.testBit(kChildMatches));
458 }
459 
460 //------------------------------------------------------------------------------
461 
462 void FWGeometryTableManager::checkRegionOfInterest(double* center, double radius, long algo) {
463  double sqr_r = radius * radius;
464 
465  for (Entries_i ni = m_entries.begin(); ni != m_entries.end(); ++ni)
466  ni->resetBit(kVisNodeChld);
467 
468  int cnt = 0;
469  TEveGeoManagerHolder mangeur(FWGeometryTableViewManager::getGeoMangeur());
470  printf("FWGeometryTableManagerBase::checkRegionOfInterest BEGIN r=%d center= (%.1f, %.1f, %.1f)\n ",
471  (int)radius,
472  center[0],
473  center[1],
474  center[2]);
475  TGeoIterator git(m_entries[0].m_node->GetVolume());
476  Entries_i eit(m_entries.begin());
477  while (git()) {
478  const TGeoMatrix* gm = git.GetCurrentMatrix();
479  const TGeoBBox* bb = static_cast<TGeoBBox*>(eit->m_node->GetVolume()->GetShape());
480  const Double_t* bo = bb->GetOrigin();
481  const Double_t bd[] = {bb->GetDX(), bb->GetDY(), bb->GetDZ()};
482  const Double_t* cc = center;
483 
484  bool visible = false;
485 
486  switch (algo) {
488  const Double_t* t = gm->GetTranslation();
489  TEveVectorD d(cc[0] - (t[0] + bo[0]), cc[1] - (t[1] + bo[1]), cc[2] - (t[2] + bo[2]));
490  Double_t sqr_d = d.Mag2();
491  ;
492  visible = (sqr_d <= sqr_r);
493  break;
494  }
496  assert(gm->IsScale() == false);
497 
498  const Double_t* t = gm->GetTranslation();
499  const Double_t* r = gm->GetRotationMatrix();
500  TEveVectorD d(cc[0] - (t[0] + bo[0]), cc[1] - (t[1] + bo[1]), cc[2] - (t[2] + bo[2]));
501  Double_t sqr_d = 0;
502  for (Int_t i = 0; i < 3; ++i) {
503  Double_t dp = d[0] * r[i] + d[1] * r[i + 3] + d[2] * r[i + 6];
504  if (dp < -bd[i]) {
505  Double_t delta = dp + bd[i];
506  sqr_d += delta * delta;
507  } else if (dp > bd[i]) {
508  Double_t delta = dp - bd[i];
509  sqr_d += delta * delta;
510  }
511  }
512  visible = (sqr_d <= sqr_r);
513  }
514  }
515 
516  if (visible) {
517  eit->setBit(kVisNodeSelf);
518  int pidx = eit->m_parent;
519  while (pidx >= 0) {
520  m_entries[pidx].setBit(kVisNodeChld);
521  pidx = m_entries[pidx].m_parent;
522  ++cnt;
523  }
524  } else {
525  eit->resetBit(kVisNodeSelf);
526  }
527  eit++;
528  }
529 
530  printf("FWGeometryTableManager::checkRegionOfInterest END [%d]\n ", cnt);
531 }
532 
534  for (Entries_i ni = m_entries.begin(); ni != m_entries.end(); ++ni) {
535  ni->setBit(kVisNodeSelf);
536  ni->setBit(kVisNodeChld);
537  }
538  // ni->setMatchRegion(true);
539 }
FWGeometryTableView * m_browser
T w() const
FWGeometryTableManager(FWGeometryTableView *)
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
void checkRegionOfInterest(double *center, double radius, long algo)
std::unordered_map< TGeoVolume *, Match > Volumes_t
void setDaughtersSelfVisibility(int i, bool v) override
assert(be >=bs)
Definition: Electron.h:6
void assertNodeFilterCache(NodeInfo &data)
bool getVisibility(const NodeInfo &nodeInfo) const override
std::string getFilter() const
d
Definition: ztail.py:151
const char * cellName(const NodeInfo &data) const override
virtual void setIndentation(int indentation=0)
static void getNNodesTotal(TGeoNode *geoNode, int &off)
void setData(const std::string &, bool isSelected)
void checkChildMatches(TGeoVolume *v, std::vector< TGeoVolume *> &)
bool nodeIsParent(const NodeInfo &) const override
void loadGeometry(TGeoNode *iGeoTopNode, TObjArray *iVolumes)
bool isSelected(const std::vector< L1HPSPFTauQualityCut > &qualityCuts, const l1t::PFCandidate &pfCand, float_t primaryVertexZ)
FWTableCellRendererBase * cellRenderer(int iSortedRowNumber, int iCol) const override
def Match(required, got)
void setVisibility(NodeInfo &nodeInfo, bool) override
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
Volumes_t::iterator Volumes_i
float x
void importChildren(int parent_idx)
bool getVisibilityChld(const NodeInfo &nodeInfo) const override
void setVisibilityChld(NodeInfo &nodeInfo, bool) override
virtual void showEditor(bool value)