LDMX Software
Display.cxx
Go to the documentation of this file.
1
8
10
11namespace eventdisplay {
12
13Display::Display(TEveManager* manager, bool verbose)
14 : TGMainFrame(gClient->GetRoot(), 320, 320), verbose_(verbose) {
15 /****************************************************************************
16 * GUI Set Up
17 ***************************************************************************/
18
19 SetWindowName("LDMX Event Display");
20
21 manager_ = manager;
22 TGLViewer* viewer = manager_->GetDefaultGLViewer();
23 viewer->UseLightColorSet();
24
25 if (verbose_) {
26 std::cout << "[ Display ] : Drawing detector geometry... " << std::flush;
27 }
28
29 // when the first TGeoShape (a TGeoTube) is drawn, ROOT creates a default
30 // geometry for this drawing and
31 // prints an Info statement to std-out. Currently, I can't figure out how to
32 // turn this behavior off.
34
35 manager_->AddEvent(new TEveEventManager("LDMX Detector", ""));
36 manager_->AddElement(the_detector_->getECAL());
37 manager_->AddElement(the_detector_->getHCAL());
39 manager_->AddEvent(new TEveEventManager("LDMX Event", ""));
40
41 if (verbose_) {
42 std::cout << "done" << std::endl;
43 std::cout << "[ Display ] : Constructing and linking buttons... "
44 << std::flush;
45 }
46
47 TGVerticalFrame* contents = new TGVerticalFrame(this, 1000, 1200);
48 TGHorizontalFrame* commandFrameNextEvent =
49 new TGHorizontalFrame(contents, 100, 0);
50 TGHorizontalFrame* commandFrameColorClusters =
51 new TGHorizontalFrame(contents, 100, 0);
52 TGHorizontalFrame* commandFrameEcalClusterBranch =
53 new TGHorizontalFrame(contents, 100, 0);
54 TGHorizontalFrame* commandFrameSimThresh =
55 new TGHorizontalFrame(contents, 100, 0);
56 TGHorizontalFrame* commandFrameEcalHitBranch =
57 new TGHorizontalFrame(contents, 100, 0);
58 TGHorizontalFrame* commandFrameHcalHitBranch =
59 new TGHorizontalFrame(contents, 100, 0);
60 TGHorizontalFrame* commandFrameTrackerHitsBranch =
61 new TGHorizontalFrame(contents, 100, 0);
62 TGHorizontalFrame* commandFrameEcalScorePlaneBranch =
63 new TGHorizontalFrame(contents, 100, 0);
64
65 TGButton* buttonColor =
66 new TGTextButton(commandFrameColorClusters, "Color Clusters");
67 commandFrameColorClusters->AddFrame(buttonColor,
68 new TGLayoutHints(kLHintsExpandX));
69 buttonColor->Connect("Pressed()", "eventdisplay::Display", this,
70 "ColorClusters()");
71
72 TGButton* buttonNext =
73 new TGTextButton(commandFrameNextEvent, "Next Event >>>");
74 commandFrameNextEvent->AddFrame(buttonNext,
75 new TGLayoutHints(kLHintsExpandX));
76 buttonNext->Connect("Pressed()", "eventdisplay::Display", this,
77 "NextEvent()");
78
79 text_box_clusters_coll_name_ =
80 new TGTextEntry(commandFrameEcalClusterBranch, new TGTextBuffer(100));
81 commandFrameEcalClusterBranch->AddFrame(text_box_clusters_coll_name_,
82 new TGLayoutHints(kLHintsExpandX));
83
84 TGButton* buttonClusterName =
85 new TGTextButton(commandFrameEcalClusterBranch, "Set Clusters Branch");
86 commandFrameEcalClusterBranch->AddFrame(buttonClusterName,
87 new TGLayoutHints(kLHintsExpandX));
88 buttonClusterName->Connect("Pressed()", "eventdisplay::Display", this,
89 "GetClustersCollInput()");
90
91 text_box_sim_thresh_ =
92 new TGTextEntry(commandFrameSimThresh, new TGTextBuffer(100));
93 commandFrameSimThresh->AddFrame(text_box_sim_thresh_,
94 new TGLayoutHints(kLHintsExpandX));
95
96 TGButton* buttonDrawThresh =
97 new TGTextButton(commandFrameSimThresh, "Sim P [MeV] Threshold");
98 commandFrameSimThresh->AddFrame(buttonDrawThresh,
99 new TGLayoutHints(kLHintsExpandX));
100 buttonDrawThresh->Connect("Pressed()", "eventdisplay::Display", this,
101 "SetSimThresh()");
102
103 text_box_ecal_rec_hits_coll_name_ =
104 new TGTextEntry(commandFrameEcalHitBranch, new TGTextBuffer(100));
105 commandFrameEcalHitBranch->AddFrame(text_box_ecal_rec_hits_coll_name_,
106 new TGLayoutHints(kLHintsExpandX));
107
108 TGButton* buttonSetECALBranch =
109 new TGTextButton(commandFrameEcalHitBranch, "Set ECAL RecHits Branch");
110 commandFrameEcalHitBranch->AddFrame(buttonSetECALBranch,
111 new TGLayoutHints(kLHintsExpandX));
112 buttonSetECALBranch->Connect("Pressed()", "eventdisplay::Display", this,
113 "GetECALRecHitsCollInput()");
114
115 text_box_hcal_rec_hits_coll_name_ =
116 new TGTextEntry(commandFrameHcalHitBranch, new TGTextBuffer(100));
117 commandFrameHcalHitBranch->AddFrame(text_box_hcal_rec_hits_coll_name_,
118 new TGLayoutHints(kLHintsExpandX));
119
120 TGButton* buttonSetHCALBranch =
121 new TGTextButton(commandFrameHcalHitBranch, "Set HCAL RecHits Branch");
122 commandFrameHcalHitBranch->AddFrame(buttonSetHCALBranch,
123 new TGLayoutHints(kLHintsExpandX));
124 buttonSetHCALBranch->Connect("Pressed()", "eventdisplay::Display", this,
125 "GetHCALRecHitsCollInput()");
126
127 text_box_tracker_hits_coll_name_ =
128 new TGTextEntry(commandFrameTrackerHitsBranch, new TGTextBuffer(100));
129 commandFrameTrackerHitsBranch->AddFrame(text_box_tracker_hits_coll_name_,
130 new TGLayoutHints(kLHintsExpandX));
131
132 TGButton* buttonSetRecoilBranch =
133 new TGTextButton(commandFrameTrackerHitsBranch, "Set Recoil Sims Branch");
134 commandFrameTrackerHitsBranch->AddFrame(buttonSetRecoilBranch,
135 new TGLayoutHints(kLHintsExpandX));
136 buttonSetRecoilBranch->Connect("Pressed()", "eventdisplay::Display", this,
137 "GetTrackerHitsCollInput()");
138
139 text_box_ecal_score_plane_branch_ =
140 new TGTextEntry(commandFrameEcalScorePlaneBranch, new TGTextBuffer(100));
141 commandFrameEcalScorePlaneBranch->AddFrame(text_box_ecal_score_plane_branch_,
142 new TGLayoutHints(kLHintsExpandX));
143
144 TGButton* buttonSetSimParticlesBranch =
145 new TGTextButton(commandFrameEcalScorePlaneBranch, "Set Ecal SP Branch");
146 commandFrameEcalScorePlaneBranch->AddFrame(buttonSetSimParticlesBranch,
147 new TGLayoutHints(kLHintsExpandX));
148 buttonSetSimParticlesBranch->Connect("Pressed()", "eventdisplay::Display",
149 this, "GetEcalSimParticlesCollInput()");
150
151 // Order from top to bottom here
152 contents->AddFrame(commandFrameEcalHitBranch,
153 new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
154 contents->AddFrame(commandFrameHcalHitBranch,
155 new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
156 contents->AddFrame(commandFrameTrackerHitsBranch,
157 new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
158 contents->AddFrame(commandFrameEcalScorePlaneBranch,
159 new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
160 contents->AddFrame(commandFrameEcalClusterBranch,
161 new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
162 contents->AddFrame(commandFrameNextEvent,
163 new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
164 contents->AddFrame(commandFrameColorClusters,
165 new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
166 contents->AddFrame(commandFrameSimThresh,
167 new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
168
169 AddFrame(contents, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
170
171 MapSubwindows();
172 Resize(GetDefaultSize());
173 MapWindow();
174
175 manager_->FullRedraw3D(kTRUE);
176
177 if (verbose_) {
178 std::cout << "done" << std::endl;
179 }
180}
181
182bool Display::SetFile(const TString file) {
183 try {
185 file_config.addParameter("tree_name", std::string("LDMX_Events"));
186 the_file_ =
187 std::make_unique<framework::EventFile>(file_config, file.Data());
188 the_file_->setupEvent(&the_event_);
189 if (verbose_) {
190 std::cout << "[ Display ] : Input root file opened successfully."
191 << std::endl;
192 }
193 } catch (const framework::exception::Exception& e) {
194 std::cerr << "[ Display ] : Input root file cannot be opened." << std::endl;
195 std::cerr << "[" << e.name() << "] : " << e.message() << "\n"
196 << " at " << e.module() << ":" << e.line() << " in "
197 << e.function() << "\nStack trace: " << std::endl
198 << e.stackTrace();
199 return false;
200 }
201
202 return true;
203}
204
205void Display::NextEvent() {
206 if (the_file_->nextEvent(false)) {
207 manager_->GetCurrentEvent()->DestroyElements();
208 objects_.Initialize();
209
210 if (verbose_) {
211 std::cout << "[ Display ] : Loading new event " << "... " << std::endl;
212 }
213
214 // draw<std::vector<ldmx::EcalHit>>(ecal_rec_hits_coll_name_);
215 // draw<std::vector<ldmx::HcalHit>>(hcal_rec_hits_coll_name_);
216 // draw<std::vector<ldmx::EcalCluster>>(clusters_coll_name_);
222
223 if (verbose_)
224 std::cout << "[ Display ] : Done loading event objects into EVE objects."
225 << std::endl;
226
227 manager_->AddElement(objects_.getSimObjects());
228 manager_->AddElement(objects_.getRecObjects());
229 manager_->Redraw3D(kFALSE);
230
231 if (verbose_) std::cout << "[ Display ] : Done redrawing." << std::endl;
232
233 } else {
234 std::cout << "[ Display ] : Already at last event in file." << std::endl;
235 return;
236 }
237}
238
239void Display::GetECALRecHitsCollInput() {
240 ecal_rec_hits_coll_name_ = getText(text_box_ecal_rec_hits_coll_name_);
241}
242
243void Display::GetHCALRecHitsCollInput() {
244 hcal_rec_hits_coll_name_ = getText(text_box_hcal_rec_hits_coll_name_);
245}
246
247void Display::GetTrackerHitsCollInput() {
248 tracker_hits_coll_name_ = getText(text_box_tracker_hits_coll_name_);
249}
250
251void Display::GetClustersCollInput() {
252 clusters_coll_name_ = getText(text_box_clusters_coll_name_);
253}
254
255void Display::GetEcalSimParticlesCollInput() {
256 ecal_sim_particles_coll_name_ = getText(text_box_ecal_score_plane_branch_);
257}
258
259bool Display::SetSimThresh() {
260 double thresh = atof(text_box_sim_thresh_->GetText());
261 if (thresh == 0 && std::string(text_box_sim_thresh_->GetText()) != "0") {
262 std::cout << "[ Display ] : Invalid sim energy threshold entered: \""
263 << text_box_sim_thresh_->GetText() << "\"" << std::endl;
264 return false;
265 } else if (verbose_) {
266 std::cout << "[ Display ] : Setting SimParticle energy threshold to "
267 << thresh << std::endl;
268 }
269
270 objects_.SetSimThresh(thresh);
271
272 manager_->RegisterRedraw3D();
273 manager_->FullRedraw3D(kFALSE, kTRUE);
274
275 return true;
276}
277
278void Display::ColorClusters() {
279 objects_.ColorClusters();
280
281 manager_->RegisterRedraw3D();
282 manager_->FullRedraw3D(kFALSE, kTRUE);
283}
284
285} // namespace eventdisplay
TEveManager * manager_
event display manager
Definition Display.h:177
std::unique_ptr< framework::EventFile > the_file_
Handle to input file we will be reading.
Definition Display.h:150
Display(TEveManager *manager, bool verbose)
Constructor Builds window frame and and control panel.
Definition Display.cxx:13
std::string clusters_coll_name_
name of ecal clusters collection in event tree
Definition Display.h:153
Objects objects_
drawing methods for event objects
Definition Display.h:167
std::string hcal_rec_hits_coll_name_
name of hcalRecHits collection in event tree
Definition Display.h:157
framework::Event the_event_
Event bus for reading from input file.
Definition Display.h:147
void draw(const std::string &name)
Templated draw method.
Definition Display.h:127
std::string getText(TGTextEntry *box) const
Get the text from the input text box.
Definition Display.h:121
EveDetectorGeometry * the_detector_
drawing methods for the detector geometry
Definition Display.h:164
std::string tracker_hits_coll_name_
name of recoil hitss collection in event tree
Definition Display.h:159
std::string ecal_rec_hits_coll_name_
name of ecalRecHits collection in event tree
Definition Display.h:155
std::string ecal_sim_particles_coll_name_
name of ecal sim particles collection in
Definition Display.h:161
Class that constructs the detector components for the event display.
TEveElement * getHCAL()
Access HCAL Eve Element.
TEveElement * getECAL()
Access ECAL Eve Element.
TEveElement * getRecoilTracker()
Access Recoil Tracker Eve Element.
TEveElement * getRecObjects()
Get the objects from the reconstruction level Eve Element Used to attach these Eve Elements to the Ev...
Definition Objects.h:118
TEveElement * getSimObjects()
Get the objects from the sim level Eve Element Used to attach these Eve Elements to the Eve Manager.
Definition Objects.h:112
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
Standard base exception class with some useful output information.
Definition Exception.h:20
const std::string & function() const
Get the function name where the exception occurred.
Definition Exception.h:74
int line() const
Get the source line number where the exception occurred.
Definition Exception.h:80
const std::string & message() const
Get the message of the exception.
Definition Exception.h:62
const std::string & name() const
Get the name of the exception.
Definition Exception.h:56
const std::string & stackTrace() const
Get the full stack trace.
Definition Exception.h:91
const std::string & module() const
Get the source filename where the exception occurred.
Definition Exception.h:68