Fork me on GitHub

source: git/display/DelphesEventDisplay.cc@ 4fd37d4

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

Code reorganization

Moved the methods that read branches to the correponding BranchElements.

  • Property mode set to 100644
File size: 11.3 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 "TClonesArray.h"
48
49DelphesEventDisplay::DelphesEventDisplay()
50{
51 event_id_ = 0;
52 tkRadius_ = 1.29;
53 totRadius_ = 2.0;
54 tkHalfLength_ = 3.0;
55 muHalfLength_ = 6.0;
56 bz_ = 3.8;
57 chain_ = new TChain("Delphes");
58 treeReader_ = 0;
59 delphesDisplay_ = 0;
60 etaAxis_ = 0;
61 phiAxis_ = 0;
62}
63
64DelphesEventDisplay::~DelphesEventDisplay()
65{
66 delete chain_;
67}
68
69DelphesEventDisplay::DelphesEventDisplay(const char *configFile, const char *inputFile, Delphes3DGeometry& det3D)
70{
71 event_id_ = 0;
72 tkRadius_ = 1.29;
73 totRadius_ = 2.0;
74 tkHalfLength_ = 3.0;
75 bz_ = 3.8;
76 chain_ = new TChain("Delphes");
77 treeReader_ = 0;
78 delphesDisplay_ = 0;
79
80 // initialize the application
81 TEveManager::Create(kTRUE, "IV");
82 TGeoManager* geom = gGeoManager;
83
84 // build the detector
85 tkRadius_ = det3D.getTrackerRadius();
86 totRadius_ = det3D.getDetectorRadius();
87 tkHalfLength_ = det3D.getTrackerHalfLength();
88 muHalfLength_ = det3D.getDetectorHalfLength();
89 bz_ = det3D.getBField();
90 etaAxis_ = det3D.getCaloAxes().first;
91 phiAxis_ = det3D.getCaloAxes().second;
92 TGeoVolume* top = det3D.getDetector(false);
93 geom->SetTopVolume(top);
94 TEveElementList *geometry = new TEveElementList("Geometry");
95 TObjArray* nodes = top->GetNodes();
96 TIter itNodes(nodes);
97 TGeoNode* nodeobj;
98 TEveGeoTopNode* node;
99 while((nodeobj = (TGeoNode*)itNodes.Next())) {
100 node = new TEveGeoTopNode(gGeoManager,nodeobj);
101 node->UseNodeTrans();
102 geometry->AddElement(node);
103 }
104
105 // Create chain of root trees
106 chain_->Add(inputFile);
107
108 // Create object of class ExRootTreeReader
109 printf("*** Opening Delphes data file ***\n");
110 treeReader_ = new ExRootTreeReader(chain_);
111
112 // prepare data collections
113 readConfig(configFile, elements_);
114 for(std::vector<DelphesBranchBase*>::iterator element = elements_.begin(); element<elements_.end(); ++element) {
115 DelphesBranchElement<TEveTrackList>* item_v1 = dynamic_cast<DelphesBranchElement<TEveTrackList>*>(*element);
116 DelphesBranchElement<TEveElementList>* item_v2 = dynamic_cast<DelphesBranchElement<TEveElementList>*>(*element);
117 if(item_v1) gEve->AddElement(item_v1->GetContainer());
118 if(item_v2) gEve->AddElement(item_v2->GetContainer());
119 }
120
121 // viewers and scenes
122 delphesDisplay_ = new DelphesDisplay;
123 gEve->AddGlobalElement(geometry);
124 delphesDisplay_->ImportGeomRPhi(geometry);
125 delphesDisplay_->ImportGeomRhoZ(geometry);
126 // find the first calo data and use that to initialize the calo display
127 for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
128 if(TString((*data)->GetType())=="Tower") { // we could also use GetClassName()=="DelphesCaloData"
129 DelphesCaloData* container = dynamic_cast<DelphesBranchElement<DelphesCaloData>*>((*data))->GetContainer();
130 assert(container);
131 TEveCalo3D *calo3d = new TEveCalo3D(container);
132 calo3d->SetBarrelRadius(tkRadius_);
133 calo3d->SetEndCapPos(tkHalfLength_);
134 gEve->AddGlobalElement(calo3d);
135 delphesDisplay_->ImportCaloRPhi(calo3d);
136 delphesDisplay_->ImportCaloRhoZ(calo3d);
137 TEveCaloLego *lego = new TEveCaloLego(container);
138 lego->InitMainTrans();
139 lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());
140 lego->SetAutoRebin(kFALSE);
141 lego->Set2DMode(TEveCaloLego::kValSizeOutline);
142 delphesDisplay_->ImportCaloLego(lego);
143 break;
144 }
145 }
146
147 make_gui();
148 load_event();
149 gEve->Redraw3D(kTRUE);
150
151}
152
153// function that parses the config to extract the branches of interest and prepare containers
154void DelphesEventDisplay::readConfig(const char *configFile, std::vector<DelphesBranchBase*>& elements) {
155 ExRootConfReader *confReader = new ExRootConfReader;
156 confReader->ReadFile(configFile);
157 ExRootConfParam branches = confReader->GetParam("TreeWriter::Branch");
158 Int_t nBranches = branches.GetSize()/3;
159 DelphesBranchElement<TEveTrackList>* tlist;
160 DelphesBranchElement<DelphesCaloData>* clist;
161 DelphesBranchElement<TEveElementList>* elist;
162 // first loop with all but tracks
163 for(Int_t b = 0; b<nBranches; ++b) {
164 TString input = branches[b*3].GetString();
165 TString name = branches[b*3+1].GetString();
166 TString className = branches[b*3+2].GetString();
167 if(className=="Tower") {
168 if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
169 clist = new DelphesBranchElement<DelphesCaloData>(name,treeReader_->UseBranch(name),kBlack);
170 clist->GetContainer()->SetEtaBins(etaAxis_);
171 clist->GetContainer()->SetPhiBins(phiAxis_);
172 elements.push_back(clist);
173 } else if(className=="Jet") {
174 if(input.Contains("GenJetFinder")) {
175 elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kCyan);
176 elist->GetContainer()->SetRnrSelf(false);
177 elist->GetContainer()->SetRnrChildren(false);
178 elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
179 elements.push_back(elist);
180 } else {
181 elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kYellow);
182 elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
183 elements.push_back(elist);
184 }
185 } else if(className=="Electron") {
186 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kRed);
187 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
188 elements.push_back(tlist);
189 } else if(className=="Photon") {
190 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kYellow);
191 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
192 elements.push_back(tlist);
193 } else if(className=="Muon") {
194 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kGreen);
195 tlist->SetTrackingVolume(totRadius_, muHalfLength_, bz_);
196 elements.push_back(tlist);
197 } else if(className=="MissingET") {
198 elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kViolet);
199 elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
200 elements.push_back(elist);
201 } else if(className=="GenParticle") {
202 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kCyan);
203 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
204 tlist->GetContainer()->SetRnrSelf(false);
205 tlist->GetContainer()->SetRnrChildren(false);
206 elements.push_back(tlist);
207 } else {
208 continue;
209 }
210 }
211 // second loop for tracks
212 for(Int_t b = 0; b<nBranches; ++b) {
213 TString input = branches[b*3].GetString();
214 TString name = branches[b*3+1].GetString();
215 TString className = branches[b*3+2].GetString();
216 if(className=="Track") {
217 if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
218 tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kBlue);
219 tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
220 elements.push_back(tlist);
221 }
222 }
223}
224
225void DelphesEventDisplay::load_event()
226{
227 // Load event specified in global event_id_.
228 // The contents of previous event are removed.
229
230 // safety
231 if(event_id_ >= treeReader_->GetEntries() || event_id_<0 ) return;
232
233 //TODO move this to the status bar ???
234 printf("Loading event %d.\n", event_id_);
235
236 // clear the previous event
237 gEve->GetViewers()->DeleteAnnotations();
238 for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
239 (*data)->Reset();
240 }
241
242 // Load selected branches with data from specified event
243 treeReader_->ReadEntry(event_id_);
244 for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
245 (*data)->ReadBranch();
246 }
247
248 // update display
249 TEveElement* top = (TEveElement*)gEve->GetCurrentEvent();
250 delphesDisplay_->DestroyEventRPhi();
251 delphesDisplay_->ImportEventRPhi(top);
252 delphesDisplay_->DestroyEventRhoZ();
253 delphesDisplay_->ImportEventRhoZ(top);
254 //update_html_summary();
255
256 gEve->Redraw3D(kFALSE, kTRUE);
257}
258
259/******************************************************************************/
260// GUI
261/******************************************************************************/
262
263void DelphesEventDisplay::make_gui()
264{
265 // Create minimal GUI for event navigation.
266 // TODO: better GUI could be made based on the ch15 of the manual (Writing a GUI)
267
268 // add a tab on the left
269 TEveBrowser* browser = gEve->GetBrowser();
270 browser->StartEmbedding(TRootBrowser::kLeft);
271
272 // set the main title
273 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
274 frmMain->SetWindowName("Delphes Event Display");
275 frmMain->SetCleanup(kDeepCleanup);
276
277 // build the navigation menu
278 TGHorizontalFrame* hf = new TGHorizontalFrame(frmMain);
279 {
280 TString icondir;
281 if(gSystem->Getenv("ROOTSYS"))
282 icondir = Form("%s/icons/", gSystem->Getenv("ROOTSYS"));
283 if(!gSystem->OpenDirectory(icondir))
284 icondir = Form("%s/icons/", (const char*)gSystem->GetFromPipe("root-config --etcdir") );
285 TGPictureButton* b = 0;
286
287 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoBack.gif"));
288 hf->AddFrame(b);
289 b->Connect("Clicked()", "DelphesEventDisplay", this, "Bck()");
290
291 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoForward.gif"));
292 hf->AddFrame(b);
293 b->Connect("Clicked()", "DelphesEventDisplay", this, "Fwd()");
294 }
295 frmMain->AddFrame(hf);
296 frmMain->MapSubwindows();
297 frmMain->Resize();
298 frmMain->MapWindow();
299 browser->StopEmbedding();
300 browser->SetTabTitle("Event Control", 0);
301}
302
Note: See TracBrowser for help on using the repository browser.