CMS 3D CMS Logo

FWOverlapTableManager.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWOverlapTableManager
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author:
10 // Created: Wed Jan 4 20:31:32 CET 2012
11 //
12 
13 // system include files
14 
15 // user include files
21 
22 #include "TEveQuadSet.h"
23 #include "TGeoVolume.h"
24 #include "TGeoMatrix.h"
25 #include "TGeoShape.h"
26 #include "TGeoBBox.h"
27 #include "TGeoMatrix.h"
28 #include "TEveUtil.h"
29 #include "TObjString.h"
30 #include "TGeoNode.h"
31 #include "TGeoOverlap.h"
32 #include "TGeoManager.h"
33 #include "TPolyMarker3D.h"
34 
35 #include "TStopwatch.h"
36 #include "TTimer.h"
37 #include "TGeoPainter.h"
38 #include "TPRegexp.h"
39 
41 
43 
44 std::vector<std::string> FWOverlapTableManager::getTitles() const {
45  std::vector<std::string> returnValue;
46  returnValue.reserve(numberOfColumns());
47 
48  returnValue.push_back("Name");
49  returnValue.push_back("Color");
50  returnValue.push_back("Opcty");
51  returnValue.push_back("RnrSelf");
52  returnValue.push_back("RnrChildren");
53  returnValue.push_back("Overlap");
54  returnValue.push_back("RnrMarker");
55  return returnValue;
56 }
57 
58 //---------------------------------------------------------------------------------
59 void FWOverlapTableManager::importOverlaps(std::string iPath, double iPrecision) {
60  m_entries.clear();
61  m_mapNodeOverlaps.clear();
62  m_browser->getMarker()->Reset(TEveQuadSet::kQT_FreeQuad, kFALSE, 32);
63 
64  TEveGeoManagerHolder mangeur(FWGeometryTableViewManager::getGeoMangeur());
65  // gGeoManager->cd();
66  NodeInfo topNodeInfo;
67  topNodeInfo.m_node = gGeoManager->GetTopNode();
68  topNodeInfo.m_level = 0;
69  topNodeInfo.m_color = gGeoManager->GetTopNode()->GetVolume()->GetLineColor();
70  topNodeInfo.m_transparency = gGeoManager->GetTopNode()->GetVolume()->GetTransparency();
71  topNodeInfo.m_parent = -1;
72  topNodeInfo.resetBit(kVisNodeSelf);
73 
74  m_entries.resize(gGeoManager->GetNNodes());
75  m_entries[0] = topNodeInfo;
76 
77  m_entries.resize(gGeoManager->GetNNodes());
78 
79  TGeoVolume* topVol = topNodeInfo.m_node->GetVolume();
80  Int_t icheck = 0;
81  Int_t ncheck = 0;
82  TStopwatch* timer;
83  Int_t i;
84  bool checkingOverlaps = false;
85  TGeoManager* geom = topVol->GetGeoManager();
86  ncheck = topNodeInfo.m_node->CountDaughters(kFALSE);
87  timer = new TStopwatch();
88  geom->ClearOverlaps();
89  geom->SetCheckingOverlaps(kTRUE);
90 
91  int oldS = 0;
92  timer->Start();
93  geom->GetGeomPainter()->OpProgress(topVol->GetName(), icheck, ncheck, timer, kFALSE);
94  // topVol->CheckOverlaps(iPrecision);
95  icheck++;
96  TGeoIterator git(topVol);
97  Entries_i eit = m_entries.begin();
98  /*
99  if (gGeoManager->GetListOfOverlaps()->GetEntriesFast()) {
100  int newCnt = gGeoManager->GetListOfOverlaps()->GetEntriesFast();
101  for (int i=0; i<newCnt; ++i) {
102  addOverlapEntry((TGeoOverlap*)gGeoManager->GetListOfOverlaps()->At(i), new TGeoHMatrix(*geom->GetCurrentMatrix()), topNode, next);
103  }
104  oldS= newCnt;
105  }*/
106  eit++;
107  TGeoNode* node;
108  icheck = 1;
109 
110  int topNodeIdx = m_browser->getTopNodeIdx();
111 
112  while ((node = git())) {
113  if (!eit->testBit(kOverlap))
114  eit->resetBit(kVisNodeSelf);
115  eit->m_node = node;
116  eit->m_color = node->GetVolume()->GetLineColor();
117  eit->m_transparency = node->GetVolume()->GetTransparency();
118  eit->m_level = git.GetLevel();
119  eit->m_parent = icheck;
120 
121  if ((topNodeIdx) == icheck || !topNodeIdx) {
122  // printf("start to check overlaps on topNodeIdx %s \n", eit->name());
123  checkingOverlaps = true;
124  } else if (checkingOverlaps && (eit->m_level <= m_entries[m_browser->getTopNodeIdx()].m_level)) {
125  checkingOverlaps = false;
126  }
127  // parent index
128  Entries_i pit = eit;
129  do {
130  --pit;
131  --(eit->m_parent);
132  if (pit->m_level < eit->m_level)
133  break;
134  } while (pit != m_entries.begin());
135 
136  // overlap bits
137  if (checkingOverlaps) {
138  if (!node->GetVolume()->IsSelected()) {
139  geom->GetGeomPainter()->OpProgress(node->GetVolume()->GetName(), icheck + 1, ncheck, timer, kFALSE);
140  node->GetVolume()->SelectVolume(kFALSE);
141 
142  node->GetVolume()->CheckOverlaps(iPrecision);
143 
144  if (oldS != gGeoManager->GetListOfOverlaps()->GetEntriesFast()) {
145  // printf("mother %s overlaps \n", node->GetName());
146 
147  eit->setBit(kOverlapChild);
148  eit->setBit(kVisNodeChld);
149  eit->setBit(kVisMarker);
150 
151  TGeoHMatrix* motherm = new TGeoHMatrix(*geom->GetCurrentMatrix());
152  {
153  TGeoNode* ni = topNodeInfo.m_node;
154  for (Int_t i = 1; i <= git.GetLevel(); i++) {
155  ni = ni->GetDaughter(git.GetIndex(i));
156  motherm->Multiply(ni->GetMatrix());
157  }
158  }
159 
160  int newCnt = gGeoManager->GetListOfOverlaps()->GetEntriesFast();
161 
162  for (int i = oldS; i < newCnt; ++i) {
163  // printf("add %p %p \n", (void*)node->GetVolume(), (void*)m_entries[icheck].m_node->GetVolume());
164  addOverlapEntry((TGeoOverlap*)gGeoManager->GetListOfOverlaps()->At(i), i, icheck, motherm);
165  }
166 
167  oldS = newCnt;
168  }
169  }
170  }
171  eit++;
172  icheck++;
173  }
174 
175  m_browser->getMarker()->RefitPlex();
176 
177  topVol->SelectVolume(kTRUE);
178  geom->SetCheckingOverlaps(kFALSE);
179  // geom->SortOverlaps();
180  TObjArray* overlaps = geom->GetListOfOverlaps();
181  Int_t novlps = overlaps->GetEntriesFast();
182  TNamed* obj;
183  for (i = 0; i < novlps; i++) {
184  obj = (TNamed*)overlaps->At(i);
185  obj->SetName(Form("ov%05d", i));
186  }
187  geom->GetGeomPainter()->OpProgress("Check overlaps:", icheck, ncheck, timer, kTRUE);
188  Info("CheckOverlaps", "Number of illegal overlaps/extrusions : %d\n", novlps);
189  delete timer;
190 }
191 
192 //______________________________________________________________________________
193 
194 void FWOverlapTableManager::addOverlapEntry(TGeoOverlap* ovl, int ovlIdx, Int_t parentIdx, TGeoHMatrix* motherm) {
195  // printf("add %s \n", ovl->GetTitle());
196  // get doughter indices of overlaps
197  /*
198  TPMERegexp re(" ", "o");
199  re.Split(TString(ovl->GetTitle()));
200  printf("add title %s \n", ovl->GetTitle());
201  */
202  int pcnt = parentIdx + 1;
203  int dOff = 0;
204  TGeoNode* mothern = m_entries[parentIdx].m_node;
205 
206  QuadId* quid = new QuadId(ovl, parentIdx);
207 
208  for (int i = 0; i < mothern->GetNdaughters(); ++i) {
209  TGeoNode* n = mothern->GetDaughter(i);
210 
211  int cnt = pcnt + i + dOff;
212 
213  if (ovl->IsOverlap()) {
214  if (n->GetVolume() == ovl->GetFirstVolume() && (*(ovl->GetFirstMatrix()) == *(n->GetMatrix()))) {
215  // std::string x = re[0].Data();
216  //if (x.find(n->GetName()) == std::string::npos) printf("ERROT \n");
217 
218  m_entries[cnt].setBit(kOverlap);
219  m_entries[cnt].setBit(kVisNodeSelf);
220  m_mapNodeOverlaps.insert(std::pair<int, int>(cnt, ovlIdx));
221  int nno;
222  n->GetOverlaps(nno);
223  nno |= BIT(1);
224  n->SetOverlaps(nullptr, nno);
225  quid->m_nodes.push_back(cnt);
226  }
227  }
228 
229  if (n->GetVolume() == ovl->GetSecondVolume() && (*(ovl->GetSecondMatrix()) == *(n->GetMatrix()))) {
230  //printf("-----------------------------------------------\n");
231  // std::string x = re[2].Data();
232  // if (x.find(n->GetName()) == std::string::npos) printf("ERROT \n");
233 
234  m_entries[cnt].setBit(kOverlap);
235  m_entries[cnt].setBit(kVisNodeSelf);
236 
237  m_mapNodeOverlaps.insert(std::pair<int, int>(cnt, ovlIdx));
238  int nno;
239  n->GetOverlaps(nno);
240  nno |= (ovl->IsOverlap() ? BIT(1) : BIT(2));
241  n->SetOverlaps(nullptr, nno);
242 
243  quid->m_nodes.push_back(cnt);
244  }
245 
247  }
248 
249  TPolyMarker3D* pm = ovl->GetPolyMarker();
250  for (int j = 0; j < pm->GetN(); ++j) {
251  double pl[3];
252  double pg[3];
253  pm->GetPoint(j, pl[0], pl[1], pl[2]);
254  motherm->LocalToMaster(pl, pg);
255 
256  float dx = TMath::Abs(ovl->GetOverlap());
257  if (dx > 1e5) {
258  fwLog(fwlog::kInfo) << Form("WARNING [%s], overlap size = %.1f \n", ovl->GetTitle(), dx);
259  dx = 10;
260  }
261  float dy = dx, dz = 0;
262  float fp[3];
263  fp[0] = pg[0];
264  fp[1] = pg[1];
265  fp[2] = pg[2];
266  float bb[12] = {fp[0] + dx,
267  fp[1] - dy,
268  fp[2] - dz,
269  fp[0] + dx,
270  fp[1] + dy,
271  fp[2] + dz,
272  fp[0] - dx,
273  fp[1] + dy,
274  fp[2] + dz,
275  fp[0] - dx,
276  fp[1] - dy,
277  fp[2] - dz};
278  m_browser->getMarker()->AddQuad(&bb[0]);
279  m_browser->getMarker()->QuadId(quid);
280  }
281 
282  int aIdx = parentIdx;
283  int aLev = m_entries[aIdx].m_level;
284  int topNodeIdx = m_browser->getTopNodeIdx();
285 
286  while (aIdx > topNodeIdx) {
287  aIdx--;
288  if (m_entries[aIdx].m_level < aLev) {
289  m_entries[aIdx].setBit(kOverlapChild);
290  m_entries[aIdx].setBit(kVisNodeChld);
291  // printf("stamp %s \n", m_entries[aIdx].name());
292  aLev--;
293  }
294  }
295 }
296 
297 //_____________________________________________________________________________
298 
300  // printf("overlap recalcuate vis \n");
301  m_row_to_index.clear();
302  int i = m_browser->getTopNodeIdx();
303  m_row_to_index.push_back(i);
304 
305  if (m_entries[i].testBit(kExpanded))
307 }
308 
310  TGeoNode* parentNode = m_entries[pIdx].m_node;
311  int nD = parentNode->GetNdaughters();
312  int dOff = 0;
313  for (int n = 0; n != nD; ++n) {
314  int idx = pIdx + 1 + n + dOff;
316 
317  if (m_browser->listAllNodes() || data.testBitAny(kOverlap | kOverlapChild))
318  m_row_to_index.push_back(idx);
319 
320  if ((m_browser->listAllNodes() || data.testBit(kOverlapChild)) && data.testBit(kExpanded))
322 
323  FWGeometryTableManagerBase::getNNodesTotal(parentNode->GetDaughter(n), dOff);
324  }
325 }
326 
327 //______________________________________________________________________________
328 
330  return m_browser->listAllNodes() ? data.m_node->GetNdaughters() : data.testBit(kOverlapChild);
331 }
332 
334  TEveGeoManagerHolder gmgr(FWGeometryTableViewManager::getGeoMangeur());
335  std::pair<std::multimap<int, int>::const_iterator, std::multimap<int, int>::const_iterator> ppp;
336  ppp = m_mapNodeOverlaps.equal_range(idx);
337  for (std::multimap<int, int>::const_iterator it2 = ppp.first; it2 != ppp.second; ++it2) {
338  const TGeoOverlap* ovl = (const TGeoOverlap*)gGeoManager->GetListOfOverlaps()->At((*it2).second);
339  if (ovl)
340  ovl->Print();
341  }
342 }
343 
344 void FWOverlapTableManager::getOverlapTitles(int idx, TString& txt) const {
345  TEveGeoManagerHolder gmgr(FWGeometryTableViewManager::getGeoMangeur());
346  std::pair<std::multimap<int, int>::const_iterator, std::multimap<int, int>::const_iterator> ppp;
347  ppp = m_mapNodeOverlaps.equal_range(idx);
348  for (std::multimap<int, int>::const_iterator it2 = ppp.first; it2 != ppp.second; ++it2) {
349  const TGeoOverlap* ovl = (const TGeoOverlap*)gGeoManager->GetListOfOverlaps()->At((*it2).second);
350  {
351  txt += "\n";
352 
353  if (ovl) {
354  txt += Form("%s: %g, ", ovl->IsOverlap() ? "Ovl" : "Extr", ovl->GetOverlap());
355  txt += ovl->GetTitle();
356  }
357  }
358  }
359 }
360 //______________________________________________________________________________
361 /*
362  const char* FWOverlapTableManager::cellName(const NodeInfo& data) const
363  {
364  if (data.m_parent == -1)
365  {
366  int ne = 0;
367  int no = 0;
368  TGeoOverlap* ovl;
369  TEveGeoManagerHolder gmgr( FWGeometryTableViewManager::getGeoMangeur());
370  TIter next_ovl(gGeoManager->GetListOfOverlaps());
371  while((ovl = (TGeoOverlap*)next_ovl()))
372  ovl->IsOverlap() ? no++ : ne++;
373 
374  return Form("%s Ovl[%d] Ext[%d]", data.m_node->GetName(), no, ne);
375  }
376  else
377  {
378  return data.name();
379  }
380  }*/
381 
382 //______________________________________________________________________________
383 
384 FWTableCellRendererBase* FWOverlapTableManager::cellRenderer(int iSortedRowNumber, int iCol) const {
385  if (m_row_to_index.empty())
386  return &m_renderer;
387 
388  int unsortedRow = m_row_to_index[iSortedRowNumber];
389 
390  if (unsortedRow < 0)
391  printf("!!!!!!!!!!!!!!!! error %d %d \n", unsortedRow, iSortedRowNumber);
392 
393  // editor state
394  //
395  m_renderer.showEditor(unsortedRow == m_editTransparencyIdx && iCol == 2);
396 
397  // selection state
398  //
399  const NodeInfo& data = m_entries[unsortedRow];
400 
401  bool isSelected = data.testBit(kHighlighted) || data.testBit(kSelected);
402  if (m_browser->listAllNodes())
403  isSelected = isSelected || data.testBit(kOverlap);
404 
405  if (data.testBit(kSelected)) {
406  m_highlightContext->SetBackground(0xc86464);
407  } else if (data.testBit(kHighlighted)) {
408  m_highlightContext->SetBackground(0x6464c8);
409  } else if (m_browser->listAllNodes() && data.testBit(kOverlap)) {
410  m_highlightContext->SetBackground(0xdddddd);
411  }
412 
413  // set column content
414  //
415  if (iCol == 0) {
416  if (unsortedRow == m_browser->getTopNodeIdx()) {
417  int no = 0, ne = 0;
418  TEveGeoManagerHolder gmgr(FWGeometryTableViewManager::getGeoMangeur());
419  TIter next_ovl(gGeoManager->GetListOfOverlaps());
420  const TGeoOverlap* ovl;
421  while ((ovl = (TGeoOverlap*)next_ovl()))
422  ovl->IsOverlap() ? no++ : ne++;
423 
424  m_renderer.setData(Form("%s Ovl[%d] Ext[%d]", data.m_node->GetName(), no, ne), isSelected);
425  } else {
427  }
429 
431 
432  int level = data.m_level - m_levelOffset;
433  if (nodeIsParent(data))
435  else
437  } else {
438  m_renderer.setIsParent(false);
440 
441  if (iCol == 5) {
442  if (data.testBit(kOverlap)) {
443  std::string x;
444  std::pair<std::multimap<int, int>::const_iterator, std::multimap<int, int>::const_iterator> ppp;
445  ppp = m_mapNodeOverlaps.equal_range(unsortedRow);
446 
447  TEveGeoManagerHolder gmgr(FWGeometryTableViewManager::getGeoMangeur());
448 
449  for (std::multimap<int, int>::const_iterator it2 = ppp.first; it2 != ppp.second; ++it2) {
450  const TGeoOverlap* ovl = (const TGeoOverlap*)gGeoManager->GetListOfOverlaps()->At((*it2).second);
451  if (ovl)
452  x += Form("%s: %g ", ovl->IsOverlap() ? "Ovl" : "Extr", ovl->GetOverlap());
453  else
454  x += "err";
455  }
457  } else {
459  }
460  }
461  if (iCol == 1) {
463  return &m_colorBoxRenderer;
464  } else if (iCol == 2) {
465  m_renderer.setData(Form("%d", 100 - data.m_transparency), isSelected);
466  } else if (iCol == 3) {
467  m_renderer.setData(data.testBit(kVisNodeSelf) ? "On" : "-", isSelected);
468 
469  } else if (iCol == 4) {
470  m_renderer.setData(data.testBit(kVisNodeChld) ? "On" : "-", isSelected);
471 
472  } else if (iCol == 6) {
473  std::cerr << "This shoud not happen! \n";
474  }
475  }
476  return &m_renderer;
477 }
478 
479 //______________________________________________________________________________
480 
482  int dOff = 0;
483  TGeoNode* parentNode = m_entries[selectedIdx].m_node;
484  int nD = parentNode->GetNdaughters();
485  for (int n = 0; n != nD; ++n) {
486  int idx = selectedIdx + 1 + n + dOff;
488 
491 
492  FWGeometryTableManagerBase::getNNodesTotal(parentNode->GetDaughter(n), dOff);
493  }
494 }
std::vector< std::string > getTitles() const override
returns the title names for each column
std::multimap< int, int > m_mapNodeOverlaps
void setDaughtersSelfVisibility(int i, bool v) override
bool nodeIsParent(const NodeInfo &) const override
void getOverlapTitles(int, TString &) const
FWEveDigitSetScalableMarker * getMarker()
void addOverlapEntry(TGeoOverlap *, int, int, TGeoHMatrix *)
virtual void recalculateVisibilityNodeRec(int)
FWTableCellRendererBase * cellRenderer(int iSortedRowNumber, int iCol) const override
FWOverlapTableManager(FWOverlapTableView *)
virtual void setIndentation(int indentation=0)
static void getNNodesTotal(TGeoNode *geoNode, int &off)
int numberOfColumns() const override
Number of columns in the table.
void setData(const std::string &, bool isSelected)
void recalculateVisibility() override
#define fwLog(_level_)
Definition: fwLog.h:45
bool isSelected(const std::vector< L1HPSPFTauQualityCut > &qualityCuts, const l1t::PFCandidate &pfCand, float_t primaryVertexZ)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
void importOverlaps(std::string path, double precision)
FWOverlapTableView * m_browser
virtual void showEditor(bool value)