Fork me on GitHub

source: git/display/DelphesEventDisplay.cc@ 53b78e8

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

New signal to show the progress of plot processing

Progress is now shown in the status bar when generating std plots.

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