Fork me on GitHub

source: git/display/DelphesEventDisplay.cc@ 2695ae1

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 2695ae1 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
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 plotSummary_->FillSample(treeReader_, event_id_); //TODO later, control it via a GUI button.
158 load_event();
159 gEve->Redraw3D(kTRUE);
160
161}
162
163// function that parses the config to extract the branches of interest and prepare containers
164void DelphesEventDisplay::readConfig(const char *configFile, std::vector<DelphesBranchBase*>& elements) {
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;
172 // first loop with all but tracks
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();
177 if(className=="Tower") {
178 if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
179 clist = new DelphesBranchElement<DelphesCaloData>(name,treeReader_->UseBranch(name),kBlack);
180 clist->GetContainer()->SetEtaBins(etaAxis_);
181 clist->GetContainer()->SetPhiBins(phiAxis_);
182 elements.push_back(clist);
183 } else if(className=="Jet") {
184 if(input.Contains("GenJetFinder")) {
185 elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kCyan);
186 elist->GetContainer()->SetRnrSelf(false);
187 elist->GetContainer()->SetRnrChildren(false);
188 elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
189 elements.push_back(elist);
190 } else {
191 elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kYellow);
192 elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
193 elements.push_back(elist);
194 }
195 } else if(className=="Electron") {
196 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kRed);
197 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
198 elements.push_back(tlist);
199 } else if(className=="Photon") {
200 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kYellow);
201 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
202 elements.push_back(tlist);
203 } else if(className=="Muon") {
204 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kGreen);
205 tlist->SetTrackingVolume(totRadius_, muHalfLength_, bz_);
206 elements.push_back(tlist);
207 } else if(className=="MissingET") {
208 elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kViolet);
209 elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
210 elements.push_back(elist);
211 } else if(className=="GenParticle") {
212 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kCyan);
213 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
214 tlist->GetContainer()->SetRnrSelf(false);
215 tlist->GetContainer()->SetRnrChildren(false);
216 elements.push_back(tlist);
217 } else {
218 continue;
219 }
220 }
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
228 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kBlue);
229 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
230 elements.push_back(tlist);
231 }
232 }
233}
234
235void DelphesEventDisplay::load_event()
236{
237 // Load event specified in global event_id_.
238 // The contents of previous event are removed.
239
240 // safety
241 if(event_id_ >= treeReader_->GetEntries() || event_id_<0 ) return;
242
243 // message
244 fStatusBar_->SetText(Form("Loading event %d.", event_id_), 1);
245
246 // clear the previous event
247 gEve->GetViewers()->DeleteAnnotations();
248 for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
249 (*data)->Reset();
250 }
251
252 // Load selected branches with data from specified event
253 treeReader_->ReadEntry(event_id_);
254 for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
255 (*data)->ReadBranch();
256 }
257
258 // update display
259 TEveElement* top = (TEveElement*)gEve->GetCurrentEvent();
260 delphesDisplay_->DestroyEventRPhi();
261 delphesDisplay_->ImportEventRPhi(top);
262 delphesDisplay_->DestroyEventRhoZ();
263 delphesDisplay_->ImportEventRhoZ(top);
264 update_html_summary();
265 plotSummary_->FillEvent();
266 plotSummary_->Draw();
267
268 gEve->Redraw3D(kFALSE, kTRUE);
269 fStatusBar_->SetText(Form("Loaded event %d.", event_id_), 1);
270}
271
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
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);
362 b->Connect("Clicked()", "DelphesEventDisplay", this, "Bck()");
363
364 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoForward.gif"));
365 hf->AddFrame(b);
366 b->Connect("Clicked()", "DelphesEventDisplay", this, "Fwd()");
367 }
368 frmMain->AddFrame(hf);
369 frmMain->MapSubwindows();
370 frmMain->Resize();
371 frmMain->MapWindow();
372 browser->StopEmbedding();
373 browser->SetTabTitle("Event Control", 0);
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();
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_);
390}
391
Note: See TracBrowser for help on using the repository browser.