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(theDetector_->getECAL());
37 manager_->AddElement(theDetector_->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 textBoxClustersCollName_ =
80 new TGTextEntry(commandFrameEcalClusterBranch, new TGTextBuffer(100));
81 commandFrameEcalClusterBranch->AddFrame(textBoxClustersCollName_,
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 textBoxSimThresh_ =
92 new TGTextEntry(commandFrameSimThresh, new TGTextBuffer(100));
93 commandFrameSimThresh->AddFrame(textBoxSimThresh_,
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 textBoxEcalRecHitsCollName_ =
104 new TGTextEntry(commandFrameEcalHitBranch, new TGTextBuffer(100));
105 commandFrameEcalHitBranch->AddFrame(textBoxEcalRecHitsCollName_,
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 textBoxHcalRecHitsCollName_ =
116 new TGTextEntry(commandFrameHcalHitBranch, new TGTextBuffer(100));
117 commandFrameHcalHitBranch->AddFrame(textBoxHcalRecHitsCollName_,
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 textBoxTrackerHitsCollName_ =
128 new TGTextEntry(commandFrameTrackerHitsBranch, new TGTextBuffer(100));
129 commandFrameTrackerHitsBranch->AddFrame(textBoxTrackerHitsCollName_,
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 textBoxEcalScorePlaneBranch_ =
140 new TGTextEntry(commandFrameEcalScorePlaneBranch, new TGTextBuffer(100));
141 commandFrameEcalScorePlaneBranch->AddFrame(textBoxEcalScorePlaneBranch_,
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
206 if (the_file_->nextEvent(false)) {
207 manager_->GetCurrentEvent()->DestroyElements();
209
210 if (verbose_) {
211 std::cout << "[ Display ] : Loading new event "
212 << "... " << std::endl;
213 }
214
215 // draw<std::vector<ldmx::EcalHit>>(ecalRecHitsCollName_);
216 // draw<std::vector<ldmx::HcalHit>>(hcalRecHitsCollName_);
217 // draw<std::vector<ldmx::EcalCluster>>(clustersCollName_);
218 draw<std::vector<ldmx::SimTrackerHit>>(trackerHitsCollName_);
219 draw<std::vector<ldmx::SimTrackerHit>>(ecalSimParticlesCollName_);
220 draw<std::vector<ldmx::SimCalorimeterHit>>("EcalSimHits");
221 draw<std::vector<ldmx::SimCalorimeterHit>>("HcalSimHits");
222 draw<std::map<int, ldmx::SimParticle>>("SimParticles");
223
224 if (verbose_)
225 std::cout << "[ Display ] : Done loading event objects into EVE objects."
226 << std::endl;
227
228 manager_->AddElement(objects_.getSimObjects());
229 manager_->AddElement(objects_.getRecObjects());
230 manager_->Redraw3D(kFALSE);
231
232 if (verbose_) std::cout << "[ Display ] : Done redrawing." << std::endl;
233
234 } else {
235 std::cout << "[ Display ] : Already at last event in file." << std::endl;
236 return;
237 }
238}
239
241 ecalRecHitsCollName_ = getText(textBoxEcalRecHitsCollName_);
242}
243
245 hcalRecHitsCollName_ = getText(textBoxHcalRecHitsCollName_);
246}
247
249 trackerHitsCollName_ = getText(textBoxTrackerHitsCollName_);
250}
251
253 clustersCollName_ = getText(textBoxClustersCollName_);
254}
255
257 ecalSimParticlesCollName_ = getText(textBoxEcalScorePlaneBranch_);
258}
259
261 double thresh = atof(textBoxSimThresh_->GetText());
262 if (thresh == 0 && std::string(textBoxSimThresh_->GetText()) != "0") {
263 std::cout << "[ Display ] : Invalid sim energy threshold entered: \""
264 << textBoxSimThresh_->GetText() << "\"" << std::endl;
265 return false;
266 } else if (verbose_) {
267 std::cout << "[ Display ] : Setting SimParticle energy threshold to "
268 << thresh << std::endl;
269 }
270
271 objects_.SetSimThresh(thresh);
272
273 manager_->RegisterRedraw3D();
274 manager_->FullRedraw3D(kFALSE, kTRUE);
275
276 return true;
277}
278
281
282 manager_->RegisterRedraw3D();
283 manager_->FullRedraw3D(kFALSE, kTRUE);
284}
285
286} // 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
std::string clustersCollName_
name of ecal clusters collection in event tree
Definition Display.h:153
std::string ecalSimParticlesCollName_
name of ecal sim particles collection in
Definition Display.h:161
Display(TEveManager *manager, bool verbose)
Constructor Builds window frame and and control panel.
Definition Display.cxx:13
std::string ecalRecHitsCollName_
name of ecalRecHits collection in event tree
Definition Display.h:155
Objects objects_
drawing methods for event objects
Definition Display.h:167
framework::Event the_event_
Event bus for reading from input file.
Definition Display.h:147
bool SetFile(const TString file)
Opens input file and attempts to obtain the necessary information from it.
Definition Display.cxx:182
void ColorClusters()
Colors cluster objects and redraws.
Definition Display.cxx:279
bool SetSimThresh()
Sets threshold energy from a SimParticle to be drawn from text box.
Definition Display.cxx:260
void NextEvent()
Goes forward one event unless the current event number equals the maximum event number.
Definition Display.cxx:205
std::string trackerHitsCollName_
name of recoil hitss collection in event tree
Definition Display.h:159
std::string getText(TGTextEntry *box) const
Get the text from the input text box.
Definition Display.h:121
void GetECALRecHitsCollInput()
Gets ecalRecHits collection name from text box.
Definition Display.cxx:240
void GetHCALRecHitsCollInput()
Gets hcalRecHits collection name from text box.
Definition Display.cxx:244
EveDetectorGeometry * theDetector_
drawing methods for the detector geometry
Definition Display.h:164
void GetEcalSimParticlesCollInput()
Gets ECAL Sim Particles Branch name from text box.
Definition Display.cxx:256
void GetTrackerHitsCollInput()
Gets trackerHits collection name from text box.
Definition Display.cxx:248
std::string hcalRecHitsCollName_
name of hcalRecHits collection in event tree
Definition Display.h:157
void GetClustersCollInput()
Gets clusters collection name from text box.
Definition Display.cxx:252
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.
void ColorClusters()
Colors ecal clusters according to colors_.
Definition Objects.cxx:32
TEveElement * getRecObjects()
Get the objects from the reconstruction level Eve Element Used to attach these Eve Elements to the Ev...
Definition Objects.h:118
void SetSimThresh(double simThresh)
Sets the energy threshold for a sim particle to be drawn.
Definition Objects.cxx:13
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
void Initialize()
Defines new Eve Element Lists for the event objects.
Definition Objects.cxx:7
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
void addParameter(const std::string &name, const T &value)
Add a parameter to the parameter list.
Definition Parameters.h:55
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