Fork me on GitHub

source: git/display/DelphesEventDisplay.cc@ caa953a

ImprovedOutputFile Timing dual_readout llp
Last change on this file since caa953a was f53a4d2, checked in by Pavel Demin <pavel.demin@…>, 9 years ago

adapt EventDisplay to ROOT 6.04

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