Fork me on GitHub

source: git/display/DelphesEventDisplay.cc@ 6301e02

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 6301e02 was 6301e02, checked in by Christophe Delaere <christophe.delaere@…>, 10 years ago

Better GUI

Improved the event navigation widget + batch operations

  • Property mode set to 100644
File size: 16.1 KB
Line 
1/*
2 * Delphes: a framework for fast simulation of a generic collider experiment
3 * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <cassert>
20#include <iostream>
21#include <utility>
22#include <algorithm>
23#include "TGeoManager.h"
24#include "TGeoVolume.h"
25#include "external/ExRootAnalysis/ExRootConfReader.h"
26#include "external/ExRootAnalysis/ExRootTreeReader.h"
27#include "display/DelphesCaloData.h"
28#include "display/DelphesBranchElement.h"
29#include "display/Delphes3DGeometry.h"
30#include "display/DelphesEventDisplay.h"
31#include "classes/DelphesClasses.h"
32#include "TEveElement.h"
33#include "TEveJetCone.h"
34#include "TEveTrack.h"
35#include "TEveTrackPropagator.h"
36#include "TEveCalo.h"
37#include "TEveManager.h"
38#include "TEveGeoNode.h"
39#include "TEveTrans.h"
40#include "TEveViewer.h"
41#include "TEveBrowser.h"
42#include "TEveArrow.h"
43#include "TMath.h"
44#include "TSystem.h"
45#include "TRootBrowser.h"
46#include "TGButton.h"
47#include "TGTextEntry.h"
48#include "TGProgressBar.h"
49#include "TGNumberEntry.h"
50#include "TRootEmbeddedCanvas.h"
51#include "TClonesArray.h"
52#include "TEveEventManager.h"
53#include "TCanvas.h"
54#include "TH1F.h"
55
56DelphesEventDisplay::DelphesEventDisplay()
57{
58 event_id_ = 0;
59 tkRadius_ = 1.29;
60 totRadius_ = 2.0;
61 tkHalfLength_ = 3.0;
62 muHalfLength_ = 6.0;
63 bz_ = 3.8;
64 chain_ = new TChain("Delphes");
65 treeReader_ = 0;
66 delphesDisplay_ = 0;
67 etaAxis_ = 0;
68 phiAxis_ = 0;
69}
70
71DelphesEventDisplay::~DelphesEventDisplay()
72{
73 delete chain_;
74}
75
76DelphesEventDisplay::DelphesEventDisplay(const char *configFile, const char *inputFile, Delphes3DGeometry& det3D)
77{
78 event_id_ = 0;
79 tkRadius_ = 1.29;
80 totRadius_ = 2.0;
81 tkHalfLength_ = 3.0;
82 bz_ = 3.8;
83 chain_ = new TChain("Delphes");
84 treeReader_ = 0;
85 delphesDisplay_ = 0;
86
87 // initialize the application
88 TEveManager::Create(kTRUE, "IV");
89 fStatusBar_ = gEve->GetBrowser()->GetStatusBar();
90 TGeoManager* geom = gGeoManager;
91
92 // build the detector
93 tkRadius_ = det3D.getTrackerRadius();
94 totRadius_ = det3D.getDetectorRadius();
95 tkHalfLength_ = det3D.getTrackerHalfLength();
96 muHalfLength_ = det3D.getDetectorHalfLength();
97 bz_ = det3D.getBField();
98 etaAxis_ = det3D.getCaloAxes().first;
99 phiAxis_ = det3D.getCaloAxes().second;
100 TGeoVolume* top = det3D.getDetector(false);
101 geom->SetTopVolume(top);
102 TEveElementList *geometry = new TEveElementList("Geometry");
103 TObjArray* nodes = top->GetNodes();
104 TIter itNodes(nodes);
105 TGeoNode* nodeobj;
106 TEveGeoTopNode* node;
107 while((nodeobj = (TGeoNode*)itNodes.Next())) {
108 node = new TEveGeoTopNode(gGeoManager,nodeobj);
109 node->UseNodeTrans();
110 geometry->AddElement(node);
111 }
112
113 // Create chain of root trees
114 chain_->Add(inputFile);
115
116 // Create object of class ExRootTreeReader
117 fStatusBar_->SetText("Opening Delphes data file", 1);
118 gSystem->ProcessEvents();
119 treeReader_ = new ExRootTreeReader(chain_);
120
121 // prepare data collections
122 readConfig(configFile, elements_);
123 for(std::vector<DelphesBranchBase*>::iterator element = elements_.begin(); element<elements_.end(); ++element) {
124 DelphesBranchElement<TEveTrackList>* item_v1 = dynamic_cast<DelphesBranchElement<TEveTrackList>*>(*element);
125 DelphesBranchElement<TEveElementList>* item_v2 = dynamic_cast<DelphesBranchElement<TEveElementList>*>(*element);
126 if(item_v1) gEve->AddElement(item_v1->GetContainer());
127 if(item_v2) gEve->AddElement(item_v2->GetContainer());
128 }
129
130 // viewers and scenes
131 delphesDisplay_ = new DelphesDisplay;
132 gEve->AddGlobalElement(geometry);
133 delphesDisplay_->ImportGeomRPhi(geometry);
134 delphesDisplay_->ImportGeomRhoZ(geometry);
135 // find the first calo data and use that to initialize the calo display
136 for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
137 if(TString((*data)->GetType())=="Tower") { // we could also use GetClassName()=="DelphesCaloData"
138 DelphesCaloData* container = dynamic_cast<DelphesBranchElement<DelphesCaloData>*>((*data))->GetContainer();
139 assert(container);
140 TEveCalo3D *calo3d = new TEveCalo3D(container);
141 calo3d->SetBarrelRadius(tkRadius_);
142 calo3d->SetEndCapPos(tkHalfLength_);
143 gEve->AddGlobalElement(calo3d);
144 delphesDisplay_->ImportCaloRPhi(calo3d);
145 delphesDisplay_->ImportCaloRhoZ(calo3d);
146 TEveCaloLego *lego = new TEveCaloLego(container);
147 lego->InitMainTrans();
148 lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());
149 lego->SetAutoRebin(kFALSE);
150 lego->Set2DMode(TEveCaloLego::kValSizeOutline);
151 delphesDisplay_->ImportCaloLego(lego);
152 break;
153 }
154 }
155
156 // the GUI: control panel, summary tab
157 make_gui();
158
159 //ready...
160 fStatusBar_->SetText("Ready.", 1);
161 gSystem->ProcessEvents();
162 load_event();
163 gEve->Redraw3D(kTRUE);
164
165}
166
167// function that parses the config to extract the branches of interest and prepare containers
168void DelphesEventDisplay::readConfig(const char *configFile, std::vector<DelphesBranchBase*>& elements) {
169 ExRootConfReader *confReader = new ExRootConfReader;
170 confReader->ReadFile(configFile);
171 ExRootConfParam branches = confReader->GetParam("TreeWriter::Branch");
172 Int_t nBranches = branches.GetSize()/3;
173 DelphesBranchElement<TEveTrackList>* tlist;
174 DelphesBranchElement<DelphesCaloData>* clist;
175 DelphesBranchElement<TEveElementList>* elist;
176 // first loop with all but tracks
177 for(Int_t b = 0; b<nBranches; ++b) {
178 TString input = branches[b*3].GetString();
179 TString name = branches[b*3+1].GetString();
180 TString className = branches[b*3+2].GetString();
181 if(className=="Tower") {
182 if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
183 clist = new DelphesBranchElement<DelphesCaloData>(name,treeReader_->UseBranch(name),kBlack);
184 clist->GetContainer()->SetEtaBins(etaAxis_);
185 clist->GetContainer()->SetPhiBins(phiAxis_);
186 elements.push_back(clist);
187 } else if(className=="Jet") {
188 if(input.Contains("GenJetFinder")) {
189 elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kCyan);
190 elist->GetContainer()->SetRnrSelf(false);
191 elist->GetContainer()->SetRnrChildren(false);
192 elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
193 elements.push_back(elist);
194 } else {
195 elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kYellow);
196 elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
197 elements.push_back(elist);
198 }
199 } else if(className=="Electron") {
200 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kRed);
201 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
202 elements.push_back(tlist);
203 } else if(className=="Photon") {
204 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kYellow);
205 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
206 elements.push_back(tlist);
207 } else if(className=="Muon") {
208 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kGreen);
209 tlist->SetTrackingVolume(totRadius_, muHalfLength_, bz_);
210 elements.push_back(tlist);
211 } else if(className=="MissingET") {
212 elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kViolet);
213 elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
214 elements.push_back(elist);
215 } else if(className=="GenParticle") {
216 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kCyan);
217 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
218 tlist->GetContainer()->SetRnrSelf(false);
219 tlist->GetContainer()->SetRnrChildren(false);
220 elements.push_back(tlist);
221 } else {
222 continue;
223 }
224 }
225 // second loop for tracks
226 for(Int_t b = 0; b<nBranches; ++b) {
227 TString input = branches[b*3].GetString();
228 TString name = branches[b*3+1].GetString();
229 TString className = branches[b*3+2].GetString();
230 if(className=="Track") {
231 if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
232 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kBlue);
233 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
234 elements.push_back(tlist);
235 }
236 }
237}
238
239void DelphesEventDisplay::load_event()
240{
241 // Load event specified in global event_id_.
242 // The contents of previous event are removed.
243
244 // safety
245 if(event_id_ >= treeReader_->GetEntries() || event_id_<0 ) return;
246
247 // message
248 fStatusBar_->SetText(Form("Loading event %d.", event_id_), 1);
249 gSystem->ProcessEvents();
250
251 // clear the previous event
252 gEve->GetViewers()->DeleteAnnotations();
253 for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
254 (*data)->Reset();
255 }
256
257 // Load selected branches with data from specified event
258 treeReader_->ReadEntry(event_id_);
259 for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
260 (*data)->ReadBranch();
261 }
262
263 // update display
264 TEveElement* top = (TEveElement*)gEve->GetCurrentEvent();
265 delphesDisplay_->DestroyEventRPhi();
266 delphesDisplay_->ImportEventRPhi(top);
267 delphesDisplay_->DestroyEventRhoZ();
268 delphesDisplay_->ImportEventRhoZ(top);
269 update_html_summary();
270 plotSummary_->FillEvent();
271 plotSummary_->Draw();
272
273 gEve->Redraw3D(kFALSE, kTRUE);
274 fStatusBar_->SetText(Form("Loaded event %d.", event_id_), 1);
275 gSystem->ProcessEvents();
276}
277
278void DelphesEventDisplay::update_html_summary()
279{
280 // Update summary of current event.
281
282 TEveElement::List_i i;
283 TEveElement::List_i j;
284 Int_t k;
285 TEveElement *el;
286 DelphesHtmlObjTable *table;
287 TEveEventManager *mgr = gEve ? gEve->GetCurrentEvent() : 0;
288 if (mgr) {
289 htmlSummary_->Clear("D");
290 for (i=mgr->BeginChildren(); i!=mgr->EndChildren(); ++i) {
291 el = ((TEveElement*)(*i));
292 if (el->IsA() == TEvePointSet::Class()) {
293 TEvePointSet *ps = (TEvePointSet *)el;
294 TString ename = ps->GetElementName();
295 TString etitle = ps->GetElementTitle();
296 if (ename.First('\'') != kNPOS)
297 ename.Remove(ename.First('\''));
298 etitle.Remove(0, 2);
299 Int_t nel = atoi(etitle.Data());
300 table = htmlSummary_->AddTable(ename, 0, nel);
301 }
302 else if (el->IsA() == TEveTrackList::Class()) {
303 TEveTrackList *tracks = (TEveTrackList *)el;
304 TString ename = tracks->GetElementName();
305 if (ename.First('\'') != kNPOS)
306 ename.Remove(ename.First('\''));
307 table = htmlSummary_->AddTable(ename.Data(), 5,
308 tracks->NumChildren(), kTRUE, "first");
309 table->SetLabel(0, "Momentum");
310 table->SetLabel(1, "P_t");
311 table->SetLabel(2, "Phi");
312 table->SetLabel(3, "Theta");
313 table->SetLabel(4, "Eta");
314 k=0;
315 for (j=tracks->BeginChildren(); j!=tracks->EndChildren(); ++j) {
316 Float_t p = ((TEveTrack*)(*j))->GetMomentum().Mag();
317 table->SetValue(0, k, p);
318 Float_t pt = ((TEveTrack*)(*j))->GetMomentum().Perp();
319 table->SetValue(1, k, pt);
320 Float_t phi = ((TEveTrack*)(*j))->GetMomentum().Phi();
321 table->SetValue(2, k, phi);
322 Float_t theta = ((TEveTrack*)(*j))->GetMomentum().Theta();
323 table->SetValue(3, k, theta);
324 Float_t eta = theta>0.0005 && theta<3.1413 ? ((TEveTrack*)(*j))->GetMomentum().Eta() : 1e10;
325 table->SetValue(4, k, eta);
326 ++k;
327 }
328 }
329 }
330 htmlSummary_->Build();
331 gHtml_->Clear();
332 gHtml_->ParseText((char*)htmlSummary_->Html().Data());
333 gHtml_->Layout();
334 }
335
336}
337
338/******************************************************************************/
339// GUI
340/******************************************************************************/
341
342void DelphesEventDisplay::make_gui()
343{
344 // Create minimal GUI for event navigation.
345
346 // add a tab on the left
347 TEveBrowser* browser = gEve->GetBrowser();
348 browser->SetWindowName("Delphes Event Display");
349 browser->StartEmbedding(TRootBrowser::kLeft);
350
351 // set the main title
352 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
353 frmMain->SetWindowName("Delphes Event Display");
354 frmMain->SetCleanup(kDeepCleanup);
355
356 // build the navigation menu
357 TString icondir;
358 if(gSystem->Getenv("ROOTSYS"))
359 icondir = Form("%s/icons/", gSystem->Getenv("ROOTSYS"));
360 if(!gSystem->OpenDirectory(icondir))
361 icondir = Form("%s/icons/", (const char*)gSystem->GetFromPipe("root-config --etcdir") );
362 TGGroupFrame* vf = new TGGroupFrame(frmMain,"Event navigation",kVerticalFrame | kFitWidth );
363 {
364 TGHorizontalFrame* hf = new TGHorizontalFrame(frmMain);
365 {
366 TGPictureButton* b = 0;
367
368 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoBack.gif"));
369 hf->AddFrame(b, new TGLayoutHints(kLHintsLeft | kLHintsCenterY , 10, 2, 10, 10));
370 b->Connect("Clicked()", "DelphesEventDisplay", this, "Bck()");
371
372 numberEntry_ = new TGNumberEntry(hf,0,9,-1,TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, treeReader_->GetEntries());
373 hf->AddFrame(numberEntry_, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY , 2, 0, 10, 10));
374 numberEntry_->Connect("ValueSet(Long_t)", "DelphesEventDisplay", this, "GoTo(Long_t)");
375
376 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoForward.gif"));
377 hf->AddFrame(b, new TGLayoutHints(kLHintsRight | kLHintsCenterY , 2, 10, 10, 10));
378 b->Connect("Clicked()", "DelphesEventDisplay", this, "Fwd()");
379
380 }
381 vf->AddFrame(hf, new TGLayoutHints(kLHintsExpandX , 2, 2, 2, 2));
382
383 progress_ = new TGHProgressBar(frmMain, TGProgressBar::kFancy, 100);
384 progress_->SetMax( treeReader_->GetEntries());
385 progress_->ShowPosition(kTRUE, kFALSE, "Event %.0f");
386 progress_->SetBarColor("green");
387 vf->AddFrame(progress_, new TGLayoutHints(kLHintsExpandX, 10, 10, 5, 5));
388 }
389 frmMain->AddFrame(vf, new TGLayoutHints(kLHintsExpandX , 5, 5, 5, 5));
390 vf = new TGGroupFrame(frmMain,"Batch operations",kVerticalFrame | kFitWidth );
391 {
392 TGTextButton *b = new TGTextButton(vf, "Initialize Summary Plots");
393 vf->AddFrame(b, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY | kLHintsExpandX, 10, 10, 10, 10));
394 b->Connect("Clicked()", "DelphesEventDisplay", this, "InitSummaryPlots()");
395 }
396 frmMain->AddFrame(vf, new TGLayoutHints(kLHintsExpandX , 5, 5, 5, 5));
397
398 frmMain->MapSubwindows();
399 frmMain->Resize();
400 frmMain->MapWindow();
401 browser->StopEmbedding();
402 browser->SetTabTitle("Event Control", 0);
403
404 // the summary tab
405 htmlSummary_ = new DelphesHtmlSummary("Delphes Event Display Summary Table");
406 TEveWindowSlot* slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
407 gHtml_ = new TGHtml(0, 100, 100);
408 TEveWindowFrame *wf = slot->MakeFrame(gHtml_);
409 gHtml_->MapSubwindows();
410 wf->SetElementName("Summary tables");
411
412 // plot tab
413 slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
414 TEveWindowTab* tab = slot->MakeTab();
415 tab->SetElementName("Summary plots");
416 tab->SetShowTitleBar(kFALSE);
417 plotSummary_ = new DelphesPlotSummary(tab);
418 plotSummary_->Init(elements_);
419}
420
Note: See TracBrowser for help on using the repository browser.