TEventChangeManager.cxx
Go to the documentation of this file.
3 #include "TGUIManager.hxx"
4 #include "TEventDisplay.hxx"
5 #include "TEventManager.hxx"
6 #include "TRecurseGeoManager.hxx"
7 
8 #include "TG4Event.h"
9 
10 #include <TQObject.h>
11 #include <TGButton.h>
12 #include <TGeoManager.h>
13 #include <TGeoNode.h>
14 #include <TGeoVolume.h>
15 #include <TEveGeoShape.h>
16 #include <TEveGeoNode.h>
17 #include <TEveManager.h>
18 
19 #include <iostream>
20 
22 
23 namespace {
24 
25  /// This takes a geometry id and "clones" it into the Eve display.
26  TEveGeoShape* GeometryClone(TGeoVolume* currVolume) {
27 
28  TGeoShape* currShape = currVolume->GetShape();
29  TEveGeoShape *fakeShape = new TEveGeoShape(currShape->GetName());
30 
31  TGeoMatrix* currMat = gGeoManager->GetCurrentMatrix();
32  TGeoMatrix* mat = currMat->MakeClone();
33  fakeShape->SetTransMatrix(*mat);
34 
35  // Clone the shape so that it can be displayed. This has to play some
36  // fancy footsie to get the gGeoManager memory management right. It
37  // first saves the current manager, then gets an internal geometry
38  // manager used by TEveGeoShape, and then resets the old manager once
39  // the shape is created.
40  TGeoManager* saveGeom = gGeoManager;
41  gGeoManager = fakeShape->GetGeoMangeur();
42  TGeoShape* clonedShape
43  = dynamic_cast<TGeoShape*> (currShape->Clone("fakeShape"));
44  fakeShape->SetShape(clonedShape);
45  gGeoManager = saveGeom;
46 
47  return fakeShape;
48  }
49 
50  struct PickVolumes: TRecurseGeoManager {
51  std::vector<std::string> fVolumesToShow;
52  TEveElementList* fEveList;
53  PickVolumes(TEveElementList* eveList) : fEveList(eveList) {}
54  bool Action(int) {
55  if (!fEveList) return true;
56  TGeoNode* node = gGeoManager->GetCurrentNode();
57  std::string name(node->GetName());
58  for (std::vector<std::string>::iterator v = fVolumesToShow.begin();
59  v != fVolumesToShow.end(); ++v) {
60  if (name.find(*v) == std::string::npos) continue;
61  std::cout << "Show volume " << node->GetName() << std::endl;
62  TEveGeoShape *shape = GeometryClone(node->GetVolume());
63  shape->SetMainColor(node->GetVolume()->GetLineColor());
64  shape->SetMainTransparency(90);
65  fEveList->AddElement(shape);
66  break;
67  }
68  return true;
69  }
70  };
71 }
72 
73 TTree* EDep::gEDepSimTree = NULL;
76 
78  TGButton* button = EDep::TEventDisplay::Get().GUI().GetNextEventButton();
79  if (button) {
80  button->Connect("Clicked()",
81  "EDep::TEventChangeManager",
82  this,
83  "ChangeEvent(=1)");
84  }
85 
87  if (button) {
88  button->Connect("Clicked()",
89  "EDep::TEventChangeManager",
90  this,
91  "ChangeEvent(=0)");
92  }
93 
95  if (button) {
96  button->Connect("Clicked()",
97  "EDep::TEventChangeManager",
98  this,
99  "ChangeEvent(=-1)");
100  }
101 
102  ClearVolumesToShow();
103 }
104 
106 
108  if (!source) {
109  std::cout << "Invalid event source" << std::endl;
110  return;
111  }
112  fEventSource = source;
113  gEDepSimTree = (TTree*) fEventSource->Get("EDepSimEvents");
114  if (!gEDepSimTree) {
115  std::cout << "Missing the event tree" << std::endl;
116  return;
117  }
118  gEDepSimTree->SetBranchAddress("Event",&gEDepSimEvent);
121 
122  fEventSource->Get("EDepSimGeometry");
123 
124  if (GetShowGeometry() && !fVolumesToShow.empty()) {
125  TEveElementList* simple = new TEveElementList("simplifiedGeometry");
126  PickVolumes visitor(simple);
127  visitor.fVolumesToShow.clear();
128  visitor.fVolumesToShow.reserve(fVolumesToShow.size());
129  std::copy(fVolumesToShow.begin(), fVolumesToShow.end(),
130  std::back_inserter(visitor.fVolumesToShow));
131  visitor.Apply();
132  gEve->AddGlobalElement(simple);
133  }
134 
135  NewEvent();
136  UpdateEvent();
137 }
138 
141  fNewEventHandlers.push_back(handler);
142 }
143 
146  fUpdateHandlers.push_back(handler);
147 }
148 
150  std::cout << "Change Event by " << change << " entries" << std::endl;
151  if (!GetEventSource()) {
152  std::cout << "Event source is not available" << std::endl;
153  UpdateEvent();
154  return;
155  }
156 
157  gEDepSimEntryNumber += change;
158  if (gEDepSimEntryNumber >= gEDepSimTree->GetEntries()) {
159  gEDepSimEntryNumber = gEDepSimTree->GetEntries() - 1;
160  }
162 
163  if (change != 0) NewEvent();
164 
165  UpdateEvent();
166 }
167 
169  std::cout << "New Event" << std::endl;
170 
172 
173  // Run through all of the handlers.
174  for (Handlers::iterator h = fNewEventHandlers.begin();
175  h != fNewEventHandlers.end(); ++h) {
176  (*h)->Apply();
177  }
178 
179 }
180 
182 
183  if (!gEDepSimEvent) {
184  std::cout << "Invalid event" << std::endl;;
185  return;
186  }
187 
188  // Run through all of the handlers.
189  for (Handlers::iterator h = fUpdateHandlers.begin();
190  h != fUpdateHandlers.end(); ++h) {
191  (*h)->Apply();
192  }
193 
194  // Make sure EVE is up to date.
195  gEve->Redraw3D(kTRUE);
196 }
static QCString name
Definition: declinfo.cpp:673
intermediate_table::iterator iterator
EDep::TGUIManager & GUI()
Return a reference to the gui manager.
std::string string
Definition: nybbler.cc:12
void SetEventSource(TFile *source)
void AddNewEventHandler(EDep::TVEventChangeHandler *handler)
int find(char c, int index=0, bool cs=TRUE) const
Definition: qcstring.cpp:41
TGButton * GetNextEventButton()
Get the next event button widget.
Definition: TGUIManager.hxx:37
TTree * gEDepSimTree
The tree containing the event.
static TEventDisplay & Get(void)
TGButton * GetPrevEventButton()
Get the previous event button widget.
Definition: TGUIManager.hxx:43
int gEDepSimEntryNumber
TG4Event * gEDepSimEvent
The event being displayed.
ClassImp(EDep::TEventChangeManager) namespace
T copy(T const &v)
static msg_handler handler
Definition: qglobal.cpp:234
virtual bool Action(int depth)
TGButton * GetDrawEventButton()
Get the redraw current event button widget.
Definition: TGUIManager.hxx:40
QTextStream & endl(QTextStream &s)
void AddUpdateHandler(EDep::TVEventChangeHandler *handler)