Fork me on GitHub

source: git/display/DelphesEventDisplay.cc@ 3f51314

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

First incomplete version with summary plots

Most of the functionalities are there, but it is not yet properly
integrated in the GUI.
Known issues:

  • size of the event markers
  • all markers appear the same (missing index?)
  • Property mode set to 100644
File size: 14.7 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 "TRootEmbeddedCanvas.h"
48#include "TClonesArray.h"
49#include "TEveEventManager.h"
50#include "TCanvas.h"
51#include "TH1F.h"
52
53DelphesEventDisplay::DelphesEventDisplay()
54{
55 event_id_ = 0;
56 tkRadius_ = 1.29;
57 totRadius_ = 2.0;
58 tkHalfLength_ = 3.0;
59 muHalfLength_ = 6.0;
60 bz_ = 3.8;
61 chain_ = new TChain("Delphes");
62 treeReader_ = 0;
63 delphesDisplay_ = 0;
64 etaAxis_ = 0;
65 phiAxis_ = 0;
66}
67
68DelphesEventDisplay::~DelphesEventDisplay()
69{
70 delete chain_;
71}
72
73DelphesEventDisplay::DelphesEventDisplay(const char *configFile, const char *inputFile, Delphes3DGeometry& det3D)
74{
75 event_id_ = 0;
76 tkRadius_ = 1.29;
77 totRadius_ = 2.0;
78 tkHalfLength_ = 3.0;
79 bz_ = 3.8;
80 chain_ = new TChain("Delphes");
81 treeReader_ = 0;
82 delphesDisplay_ = 0;
83
84 // initialize the application
85 TEveManager::Create(kTRUE, "IV");
86 fStatusBar_ = gEve->GetBrowser()->GetStatusBar();
87 TGeoManager* geom = gGeoManager;
88
89 // build the detector
90 tkRadius_ = det3D.getTrackerRadius();
91 totRadius_ = det3D.getDetectorRadius();
92 tkHalfLength_ = det3D.getTrackerHalfLength();
93 muHalfLength_ = det3D.getDetectorHalfLength();
94 bz_ = det3D.getBField();
95 etaAxis_ = det3D.getCaloAxes().first;
96 phiAxis_ = det3D.getCaloAxes().second;
97 TGeoVolume* top = det3D.getDetector(false);
98 geom->SetTopVolume(top);
99 TEveElementList *geometry = new TEveElementList("Geometry");
100 TObjArray* nodes = top->GetNodes();
101 TIter itNodes(nodes);
102 TGeoNode* nodeobj;
103 TEveGeoTopNode* node;
104 while((nodeobj = (TGeoNode*)itNodes.Next())) {
105 node = new TEveGeoTopNode(gGeoManager,nodeobj);
106 node->UseNodeTrans();
107 geometry->AddElement(node);
108 }
109
110 // Create chain of root trees
111 chain_->Add(inputFile);
112
113 // Create object of class ExRootTreeReader
114 fStatusBar_->SetText("Opening Delphes data file", 1);
115 treeReader_ = new ExRootTreeReader(chain_);
116
117 // prepare data collections
118 readConfig(configFile, elements_);
119 for(std::vector<DelphesBranchBase*>::iterator element = elements_.begin(); element<elements_.end(); ++element) {
120 DelphesBranchElement<TEveTrackList>* item_v1 = dynamic_cast<DelphesBranchElement<TEveTrackList>*>(*element);
121 DelphesBranchElement<TEveElementList>* item_v2 = dynamic_cast<DelphesBranchElement<TEveElementList>*>(*element);
122 if(item_v1) gEve->AddElement(item_v1->GetContainer());
123 if(item_v2) gEve->AddElement(item_v2->GetContainer());
124 }
125
126 // viewers and scenes
127 delphesDisplay_ = new DelphesDisplay;
128 gEve->AddGlobalElement(geometry);
129 delphesDisplay_->ImportGeomRPhi(geometry);
130 delphesDisplay_->ImportGeomRhoZ(geometry);
131 // find the first calo data and use that to initialize the calo display
132 for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
133 if(TString((*data)->GetType())=="Tower") { // we could also use GetClassName()=="DelphesCaloData"
134 DelphesCaloData* container = dynamic_cast<DelphesBranchElement<DelphesCaloData>*>((*data))->GetContainer();
135 assert(container);
136 TEveCalo3D *calo3d = new TEveCalo3D(container);
137 calo3d->SetBarrelRadius(tkRadius_);
138 calo3d->SetEndCapPos(tkHalfLength_);
139 gEve->AddGlobalElement(calo3d);
140 delphesDisplay_->ImportCaloRPhi(calo3d);
141 delphesDisplay_->ImportCaloRhoZ(calo3d);
142 TEveCaloLego *lego = new TEveCaloLego(container);
143 lego->InitMainTrans();
144 lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());
145 lego->SetAutoRebin(kFALSE);
146 lego->Set2DMode(TEveCaloLego::kValSizeOutline);
147 delphesDisplay_->ImportCaloLego(lego);
148 break;
149 }
150 }
151
152 // the GUI: control panel, summary tab
153 make_gui();
154
155 //ready...
156 fStatusBar_->SetText("Ready.", 1);
157 load_event();
158 plotSummary_->FillSample(treeReader_, event_id_); //TODO later, control it via a GUI button.
159 plotSummary_->FillEvent(); //TODO later move to event loop
160 plotSummary_->Draw();
161 gEve->Redraw3D(kTRUE);
162
163}
164
165// function that parses the config to extract the branches of interest and prepare containers
166void DelphesEventDisplay::readConfig(const char *configFile, std::vector<DelphesBranchBase*>& elements) {
167 ExRootConfReader *confReader = new ExRootConfReader;
168 confReader->ReadFile(configFile);
169 ExRootConfParam branches = confReader->GetParam("TreeWriter::Branch");
170 Int_t nBranches = branches.GetSize()/3;
171 DelphesBranchElement<TEveTrackList>* tlist;
172 DelphesBranchElement<DelphesCaloData>* clist;
173 DelphesBranchElement<TEveElementList>* elist;
174 // first loop with all but tracks
175 for(Int_t b = 0; b<nBranches; ++b) {
176 TString input = branches[b*3].GetString();
177 TString name = branches[b*3+1].GetString();
178 TString className = branches[b*3+2].GetString();
179 if(className=="Tower") {
180 if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
181 clist = new DelphesBranchElement<DelphesCaloData>(name,treeReader_->UseBranch(name),kBlack);
182 clist->GetContainer()->SetEtaBins(etaAxis_);
183 clist->GetContainer()->SetPhiBins(phiAxis_);
184 elements.push_back(clist);
185 } else if(className=="Jet") {
186 if(input.Contains("GenJetFinder")) {
187 elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kCyan);
188 elist->GetContainer()->SetRnrSelf(false);
189 elist->GetContainer()->SetRnrChildren(false);
190 elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
191 elements.push_back(elist);
192 } else {
193 elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kYellow);
194 elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
195 elements.push_back(elist);
196 }
197 } else if(className=="Electron") {
198 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kRed);
199 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
200 elements.push_back(tlist);
201 } else if(className=="Photon") {
202 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kYellow);
203 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
204 elements.push_back(tlist);
205 } else if(className=="Muon") {
206 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kGreen);
207 tlist->SetTrackingVolume(totRadius_, muHalfLength_, bz_);
208 elements.push_back(tlist);
209 } else if(className=="MissingET") {
210 elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kViolet);
211 elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
212 elements.push_back(elist);
213 } else if(className=="GenParticle") {
214 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kCyan);
215 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
216 tlist->GetContainer()->SetRnrSelf(false);
217 tlist->GetContainer()->SetRnrChildren(false);
218 elements.push_back(tlist);
219 } else {
220 continue;
221 }
222 }
223 // second loop for tracks
224 for(Int_t b = 0; b<nBranches; ++b) {
225 TString input = branches[b*3].GetString();
226 TString name = branches[b*3+1].GetString();
227 TString className = branches[b*3+2].GetString();
228 if(className=="Track") {
229 if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
230 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kBlue);
231 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
232 elements.push_back(tlist);
233 }
234 }
235}
236
237void DelphesEventDisplay::load_event()
238{
239 // Load event specified in global event_id_.
240 // The contents of previous event are removed.
241
242 // safety
243 if(event_id_ >= treeReader_->GetEntries() || event_id_<0 ) return;
244
245 // message
246 fStatusBar_->SetText(Form("Loading event %d.", event_id_), 1);
247
248 // clear the previous event
249 gEve->GetViewers()->DeleteAnnotations();
250 for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
251 (*data)->Reset();
252 }
253
254 // Load selected branches with data from specified event
255 treeReader_->ReadEntry(event_id_);
256 for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
257 (*data)->ReadBranch();
258 }
259
260 // update display
261 TEveElement* top = (TEveElement*)gEve->GetCurrentEvent();
262 delphesDisplay_->DestroyEventRPhi();
263 delphesDisplay_->ImportEventRPhi(top);
264 delphesDisplay_->DestroyEventRhoZ();
265 delphesDisplay_->ImportEventRhoZ(top);
266 update_html_summary();
267 //TODO: update plot tab (show current event on top)
268
269 gEve->Redraw3D(kFALSE, kTRUE);
270 fStatusBar_->SetText(Form("Loaded event %d.", event_id_), 1);
271}
272
273void DelphesEventDisplay::update_html_summary()
274{
275 // Update summary of current event.
276
277 TEveElement::List_i i;
278 TEveElement::List_i j;
279 Int_t k;
280 TEveElement *el;
281 DelphesHtmlObjTable *table;
282 TEveEventManager *mgr = gEve ? gEve->GetCurrentEvent() : 0;
283 if (mgr) {
284 htmlSummary_->Clear("D");
285 for (i=mgr->BeginChildren(); i!=mgr->EndChildren(); ++i) {
286 el = ((TEveElement*)(*i));
287 if (el->IsA() == TEvePointSet::Class()) {
288 TEvePointSet *ps = (TEvePointSet *)el;
289 TString ename = ps->GetElementName();
290 TString etitle = ps->GetElementTitle();
291 if (ename.First('\'') != kNPOS)
292 ename.Remove(ename.First('\''));
293 etitle.Remove(0, 2);
294 Int_t nel = atoi(etitle.Data());
295 table = htmlSummary_->AddTable(ename, 0, nel);
296 }
297 else if (el->IsA() == TEveTrackList::Class()) {
298 TEveTrackList *tracks = (TEveTrackList *)el;
299 TString ename = tracks->GetElementName();
300 if (ename.First('\'') != kNPOS)
301 ename.Remove(ename.First('\''));
302 table = htmlSummary_->AddTable(ename.Data(), 5,
303 tracks->NumChildren(), kTRUE, "first");
304 table->SetLabel(0, "Momentum");
305 table->SetLabel(1, "P_t");
306 table->SetLabel(2, "Phi");
307 table->SetLabel(3, "Theta");
308 table->SetLabel(4, "Eta");
309 k=0;
310 for (j=tracks->BeginChildren(); j!=tracks->EndChildren(); ++j) {
311 Float_t p = ((TEveTrack*)(*j))->GetMomentum().Mag();
312 table->SetValue(0, k, p);
313 Float_t pt = ((TEveTrack*)(*j))->GetMomentum().Perp();
314 table->SetValue(1, k, pt);
315 Float_t phi = ((TEveTrack*)(*j))->GetMomentum().Phi();
316 table->SetValue(2, k, phi);
317 Float_t theta = ((TEveTrack*)(*j))->GetMomentum().Theta();
318 table->SetValue(3, k, theta);
319 Float_t eta = theta>0.0005 && theta<3.1413 ? ((TEveTrack*)(*j))->GetMomentum().Eta() : 1e10;
320 table->SetValue(4, k, eta);
321 ++k;
322 }
323 }
324 }
325 htmlSummary_->Build();
326 gHtml_->Clear();
327 gHtml_->ParseText((char*)htmlSummary_->Html().Data());
328 gHtml_->Layout();
329 }
330
331}
332
333/******************************************************************************/
334// GUI
335/******************************************************************************/
336
337void DelphesEventDisplay::make_gui()
338{
339 // Create minimal GUI for event navigation.
340 // TODO: better GUI could be made based on the ch15 of the manual (Writing a GUI)
341
342 // add a tab on the left
343 TEveBrowser* browser = gEve->GetBrowser();
344 browser->StartEmbedding(TRootBrowser::kLeft);
345
346 // set the main title
347 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
348 frmMain->SetWindowName("Delphes Event Display");
349 frmMain->SetCleanup(kDeepCleanup);
350
351 // build the navigation menu
352 TGHorizontalFrame* hf = new TGHorizontalFrame(frmMain);
353 {
354 TString icondir;
355 if(gSystem->Getenv("ROOTSYS"))
356 icondir = Form("%s/icons/", gSystem->Getenv("ROOTSYS"));
357 if(!gSystem->OpenDirectory(icondir))
358 icondir = Form("%s/icons/", (const char*)gSystem->GetFromPipe("root-config --etcdir") );
359 TGPictureButton* b = 0;
360
361 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoBack.gif"));
362 hf->AddFrame(b);
363 b->Connect("Clicked()", "DelphesEventDisplay", this, "Bck()");
364
365 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoForward.gif"));
366 hf->AddFrame(b);
367 b->Connect("Clicked()", "DelphesEventDisplay", this, "Fwd()");
368 }
369 frmMain->AddFrame(hf);
370 frmMain->MapSubwindows();
371 frmMain->Resize();
372 frmMain->MapWindow();
373 browser->StopEmbedding();
374 browser->SetTabTitle("Event Control", 0);
375
376 // the summary tab
377 htmlSummary_ = new DelphesHtmlSummary("Delphes Event Display Summary Table");
378 TEveWindowSlot* slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
379 gHtml_ = new TGHtml(0, 100, 100);
380 TEveWindowFrame *wf = slot->MakeFrame(gHtml_);
381 gHtml_->MapSubwindows();
382 wf->SetElementName("Summary tables");
383
384 // plot tab
385 slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
386 TEveWindowTab* tab = slot->MakeTab();
387 tab->SetElementName("Summary plots");
388 tab->SetShowTitleBar(kFALSE);
389 plotSummary_ = new DelphesPlotSummary(tab);
390 plotSummary_->Init(elements_);
391}
392
Note: See TracBrowser for help on using the repository browser.