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