Fork me on GitHub

source: git/display/DelphesEventDisplay.cc@ ad015db

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

Small fixes for the summary plots

The plots are now correct, even if few things can be fixed (errors for
empty plots, and integration with the GUI)

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