GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
MainWindow.cpp
1 #include "TEveBrowser.h"
2 #include "TEveScene.h"
3 #include "TEveTrans.h"
4 #include "TGeoBBox.h"
5 #include "TGeoNode.h"
6 #include "TSystem.h"
7 
8 #include "utils/GGSSmartLog.h"
9 
10 #include "application/Application.h"
11 #include "application/gui/MainWindow.h"
12 
13 const int MainWindow::_defWidth = 1280;
14 const int MainWindow::_defHeight = 800;
15 const Option_t *MainWindow::_defOpt = "IV";
16 
17 MainWindow::MainWindow(UInt_t w, UInt_t h) : TEveManager(w, h, kTRUE, _defOpt) {
18 
19  _firstLoad = true;
20 
21  gEve = this;
22  GetMainWindow()->SetWindowName("GGSLeonard");
23 
24  _DEBUGPointSet = new TEvePointSet("DEBUG Volume position");
25  _DEBUGPointSet->SetMainColor(kRed);
26 
27  _MCTruthList = new TEveElementList("MC Truth");
28  _MCTruthShortInfo = new TGLAnnotation(GetDefaultGLViewer(), "", 0.01, 0.99);
29  _MCTruthShortInfo->SetTextSize(0.03);
30 
31  AddElement(_MCTruthList);
32 
33  AddElement(_DEBUGPointSet);
34 
35  AddControlTab();
36 }
37 
38 void MainWindow::CreateMaps() {
39  static const std::string routineName("MainWindow::CreateMaps");
40 
41  EDApplication *thisApp = (EDApplication *)gApplication;
42 
43  for (TString _det : thisApp->GetFileManager()->GetDetList()) {
44  COUT(DEBUG) << "Det is " << _det << ENDL;
45 
46  if (_DetectorHitMap.find(_det.Data()) == _DetectorHitMap.end()) {
47  COUT(DEBUG) << " DetectorHit not found, creating one... " << ENDL;
48  DetectorHit *_dhit = new DetectorHit(_det.Data());
49  _dhit->SetDisplayType(DetectorHit::kColorCodedHit);
50  _DetectorHitMap.insert(std::make_pair(_det.Data(), std::move(_dhit)));
51  AddElement(_DetectorHitMap[_det.Data()]->GetTEveElementList());
52  } else {
53  COUT(DEBUG) << " DetectorHit already there, passing on... " << ENDL;
54  }
55  }
56 
57  GenerateHashTable(thisApp->GetGeoManager()->GetEveGeoTopNode());
58 
59  for (TString _det : thisApp->GetFileManager()->GetDetList()) {
60  auto thisTEveGeoShapeMapPtr = _DetectorHitMap.find(_det.Data())->second->GetTEveGeoShapeMap();
61  COUT(DEBUG) << "map for detector " << _det << " has " << thisTEveGeoShapeMapPtr->size() << " entries "
62  << thisTEveGeoShapeMapPtr << ENDL;
63  }
64 
65  AddHitControls();
66  AddHitOptions();
67  gEve->GetBrowser()->SetTab(0, 1);
68 }
69 
70 void MainWindow::GenerateHashTable(TEveGeoNode *node) {
71  static const std::string routineName("MainWindow::GenerateHashTable");
72 
73  static std::vector<std::string> pathLevels;
74  static int level = 0;
75 
76  std::pair<UOMIterator, bool> mapResult;
77  std::string nodeName = node->GetElementName();
78  pathLevels.push_back(nodeName);
79  std::string path = "", dpath = "";
80  for (size_t il = 0; il < pathLevels.size(); il++)
81  path.append(pathLevels[il] + "/");
82  for (size_t il = 0; il < pathLevels.size(); il++)
83  dpath.append(pathLevels[il] + ".");
84  path.pop_back();
85  dpath.pop_back();
86 
87  EDApplication *thisApp = (EDApplication *)gApplication;
88 
89  std::unordered_map<std::string, TEveGeoShape *> *theMap;
90  bool foundMap = false;
91  for (TString _det : thisApp->GetFileManager()->GetDetList()) {
92  std::string volName = node->GetNode()->GetVolume()->GetName();
93  // Extract detector name from old-style sensitive volume name (XXXXH#E).
94  if (volName.size() == 7 && volName[4] == 'H' && (volName[5] == '1' || volName[5] == '2' || volName[5] == '4') &&
95  volName[6] == 'E')
96  volName = volName.substr(0, 4);
97  if (volName == _det.Data()) {
98  auto _dhitIter = _DetectorHitMap.find(_det.Data());
99  if (_dhitIter == _DetectorHitMap.end()) {
100  COUT(DEBUG) << "Could not find map for detector " << _det << ENDL;
101  continue;
102  }
103  theMap = _dhitIter->second->GetTEveGeoShapeMap();
104  foundMap = true;
105  break;
106  } // pray that this works...
107  }
108 
109  if (!foundMap) {
110  theMap = &_TEveGeoShapeMap_World;
111  }
112 
113  if (!gGeoManager->cd(path.data())) {
114  COUT(WARNING) << "Node " << path << " not found" << ENDL;
115  return;
116  }
117 
118  TString lvlString = "";
119  for (int is = 0; is < level; is++)
120  lvlString += "-";
121 
122  _TEveGeoNodeMap.insert(std::make_pair(dpath, node));
123  // COUT(DEBUG) << lvlString << " Inserted node " << dpath << " with value " << node << " (" <<
124  // node->GetNode()->GetVolume()->GetName() << ")"<< ENDL;
125 
126  TEveGeoShape *shape = new TEveGeoShape(nodeName.data(), path.data());
127  shape->RefMainTrans().SetFrom(*gGeoManager->GetCurrentMatrix());
128  shape->SetShape((TGeoShape *)gGeoManager->GetCurrentVolume()->GetShape()->Clone());
129 
130  mapResult = (*theMap).insert(make_pair(dpath, shape));
131  if (mapResult.second == false) {
132  COUT(DEBUG) << lvlString << " Could not insert node " << dpath << " with value " << shape << " into map " << theMap
133  << ENDL;
134  } else {
135  // COUT(DEBUG) << lvlString << " Inserted node " << dpath << " with value " << shape << " into map " << theMap <<
136  // ENDL;
137  }
138 
139  if (node->NumChildren() > 0) {
140  TEveElementList::List_i iter;
141  for (iter = node->BeginChildren(); iter != node->EndChildren(); iter++) {
142  level++;
143  GenerateHashTable((TEveGeoNode *)*iter);
144  level--;
145  }
146  }
147 
148  pathLevels.pop_back();
149 }
150 
151 void MainWindow::MakeTransparentScene(int transp) {
152  static const std::string routineName("MainWindow::MakeTransparentScene");
153 
154  COUT(DEBUG) << "Setting scene transparency to " << transp << ENDL;
155 
156  UOMIterator iter;
157  TEveGeoNode *node;
158  for (std::pair<std::string, TEveGeoNode *> element : _TEveGeoNodeMap) {
159  node = element.second;
160  node->SetMainTransparency(transp);
161  }
162 
163  GetGlobalScene()->Changed();
164  GetGlobalScene()->Repaint();
165 }
166 
167 void MainWindow::LoadEvent() {
168  static const std::string routineName("MainWindow::LoadEvent");
169 
170  EDApplication *thisApp = (EDApplication *)gApplication;
171 
172  _MCTruthList->RemoveElements();
173 
174  if (_firstLoad) {
175  gStyle->SetPalette(kRainBow);
176  COUT(DEBUG) << gStyle->GetNumberOfColors() << ENDL;
177  COUT(DEBUG) << gStyle->GetColorPalette(0) << ENDL;
178 
179  MakeTransparentScene(95);
180  _firstLoad = false;
181  }
182 
183  _DEBUGPointSet->Reset();
184 
185  SetMCTruth(thisApp->GetFileManager()->GetMCTruthReader());
186 
187  for (TString _det : thisApp->GetFileManager()->GetDetList()) {
188  _DetectorHitMap[_det.Data()]->GetTEveElementList()->RemoveElements();
189  SetDetectorHits(_det, thisApp->GetFileManager()->GetHitsReader());
190  }
191 
192  gEve->FullRedraw3D();
193 }
194 
195 void MainWindow::SetEventNumber(UInt_t evt) {
196  static const std::string routineName("MainWindow::SetEventNumber");
197 
198  EDApplication *thisApp = (EDApplication *)gApplication;
199 
200  _evField->SetIntNumber(evt);
201  _evFileText->ChangeText(Form(" of %i", (int)thisApp->GetFileManager()->GetEntries()));
202  _evNumbersFrame->Layout();
203  _progressBar->SetPosition(evt);
204 }
205 
206 void MainWindow::UpdateFileEntries() {
207  EDApplication *thisApp = (EDApplication *)gApplication;
208 
209  _progressBar->SetRange(0, (int)thisApp->GetFileManager()->GetEntries());
210 }
211 
212 void MainWindow::SetFileName(TString filename) { _fileField->SetText(filename.Data(), kFALSE); }
213 
214 void MainWindow::SetDisplayDetector(TString det, Bool_t s) {
215  static const std::string routineName("MainWindow::SetDisplayDetector");
216 
217  COUT(DEBUG) << "Called with det=" << det << ENDL;
218  _DetectorHitMap[det.Data()]->GetTEveElementList()->SetRnrState(s);
219  FullRedraw3D();
220 }
221 
222 void MainWindow::SetDetectorHitType(TString det, DetectorHit::hitType type) {
223  _DetectorHitMap[det.Data()]->SetDisplayType(type);
224 
225  LoadEvent();
226 }
227 
228 void MainWindow::SetDetectorHitThreshold(TString det, Float_t thr) {
229  _DetectorHitMap[det.Data()]->SetThreshold(thr);
230 
231  LoadEvent();
232 }
233 
234 void MainWindow::SetDetectorHitColor(TString det, Color_t col) {
235  _DetectorHitMap[det.Data()]->SetColor(col);
236 
237  LoadEvent();
238 }
239 
240 void MainWindow::SetDisplayPartHits(Bool_t s) {
241  _MCPartHitList->SetRnrState(s);
242  FullRedraw3D();
243 }
#define ENDL
Definition: GGSSmartLog.h:105
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:76
Long64_t GetEntries()
The total number of events.