Fork me on GitHub

source: git/examples/geometry.C@ 493aa9b

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

First working version

Many features are still missing, but that version provides the minimal
features in EventDisplay and in addition: event control and transluscent
geometry.

  • Property mode set to 100644
File size: 37.2 KB
Line 
1#include <set>
2#include <map>
3#include <utility>
4#include <vector>
5#include <algorithm>
6#include <sstream>
7#include "TGeoManager.h"
8#include "TGeoVolume.h"
9#include "TGeoMedium.h"
10#include "TGeoNode.h"
11#include "TGeoCompositeShape.h"
12#include "TGeoMatrix.h"
13#include "TGeoTube.h"
14#include "TGeoCone.h"
15#include "TGeoArb8.h"
16//#include "external/ExRootAnalysis/ExRootConfReader.h"
17//#include "external/ExRootAnalysis/ExRootTreeReader.h"
18//#include "display/DelphesCaloData.h"
19//#include "display/DelphesDisplay.h"
20//#include "classes/DelphesClasses.h"
21#include "TF2.h"
22#include "TH1F.h"
23#include "TChain.h"
24#include "TEveElement.h"
25#include "TEveJetCone.h"
26#include "TEveTrack.h"
27#include "TEveTrackPropagator.h"
28#include "TEveCalo.h"
29#include "TMath.h"
30#include "TSystem.h"
31#include "TEveManager.h"
32#include "TEveGeoNode.h"
33#include "TEveTrans.h"
34#include "TEveViewer.h"
35#include "TEveBrowser.h"
36#include "TRootBrowser.h"
37#include "TGLViewer.h"
38#include "TGButton.h"
39#include "TCollection.h"
40#include "TClonesArray.h"
41#include "TGLClip.h"
42
43/*
44 * alice_esd.C : GUI complete
45 * assembly.C: sauvegarde as shape-extract -> implement in the geometry class (read/write)
46 * histobrowser.C: intégration d'histogrammes dans le display (on pourrait avoir Pt, eta, phi pour les principales collections)
47 * also from alice_esd: summary html table
48 *
49 */
50using namespace std;
51
52// Forward declarations.
53class Delphes3DGeometry;
54class ExRootTreeReader;
55class DelphesCaloData;
56class DelphesDisplay;
57void make_gui();
58void load_event();
59void delphes_read();
60
61// Configuration and global variables.
62Int_t event_id = 0; // Current event id.
63Double_t gRadius = 1.29;
64Double_t gHalfLength = 3.0;
65Double_t gBz = 3.8;
66
67TAxis *gEtaAxis = 0;
68TAxis *gPhiAxis = 0;
69
70TChain gChain("Delphes");
71
72ExRootTreeReader *gTreeReader = 0;
73
74TClonesArray *gBranchTower = 0;
75TClonesArray *gBranchTrack = 0;
76TClonesArray *gBranchJet = 0;
77
78DelphesCaloData *gCaloData = 0;
79TEveElementList *gJetList = 0;
80TEveTrackList *gTrackList = 0;
81
82DelphesDisplay *gDelphesDisplay = 0;
83
84/******************************************************************************/
85// Construction of the geometry
86/******************************************************************************/
87
88// TODO: asymmetric detector
89
90class Delphes3DGeometry {
91 public:
92 Delphes3DGeometry(TGeoManager *geom = NULL);
93 ~Delphes3DGeometry() {}
94
95 void readFile(const char* filename, const char* ParticlePropagator="ParticlePropagator",
96 const char* TrackingEfficiency="ChargedHadronTrackingEfficiency",
97 const char* MuonEfficiency="MuonEfficiency",
98 const char* Calorimeters="Calorimeter");
99
100 void loadFromFile(const char* filename, const char* name="DelphesGeometry");
101 void save(const char* filename, const char* name="DelphesGeometry");
102
103 void setContingency(Double_t contingency) { contingency_ = contingency; }
104 void setCaloBarrelThickness(Double_t thickness) { calo_barrel_thickness_ = thickness; }
105 void setCaloEndcapThickness(Double_t thickness) { calo_endcap_thickness_ = thickness; }
106 void setMuonSystemThickness(Double_t thickness) { muonSystem_thickn_ = thickness; }
107
108 TGeoVolume* getDetector(bool withTowers = true);
109
110 Double_t getTrackerRadius() const { return tk_radius_; }
111 Double_t getTrackerHalfLength() const { return tk_length_; }
112 Double_t getBField() const { return tk_Bz_; }
113 std::pair<TAxis*, TAxis*> getCaloAxes() { return std::make_pair(etaAxis_,phiAxis_); }
114
115 private:
116 std::pair<Double_t, Double_t> addTracker(TGeoVolume *top);
117 std::pair<Double_t, Double_t> addCalorimeter(TGeoVolume *top, const char* name, Double_t innerBarrelRadius, Double_t innerBarrelLength, set< pair<Double_t, Int_t> >& caloBinning);
118 std::pair<Double_t, Double_t> addMuonDets(TGeoVolume *top, const char* name, Double_t innerBarrelRadius, Double_t innerBarrelLength);
119 void addCaloTowers(TGeoVolume *top, const char* name, Double_t innerBarrelRadius, Double_t innerBarrelLength, set< pair<Double_t, Int_t> >& caloBinning);
120
121 private:
122
123 TGeoManager *geom_;
124
125 TGeoMedium *vacuum_;
126 TGeoMedium *tkmed_;
127 TGeoMedium *calomed_;
128 TGeoMedium *mudetmed_;
129
130 TAxis* etaAxis_;
131 TAxis* phiAxis_;
132
133 Double_t contingency_;
134 Double_t calo_barrel_thickness_;
135 Double_t calo_endcap_thickness_;
136 Double_t muonSystem_thickn_;
137 Double_t tk_radius_;
138 Double_t tk_length_;
139 Double_t tk_etamax_;
140 Double_t tk_Bz_;
141
142 std::vector<std::string> calorimeters_;
143 std::vector<std::string> muondets_;
144
145 std::map<std::string, Double_t> muonSystem_etamax_;
146 std::map<std::string, set< pair<Double_t, Int_t> > > caloBinning_;
147
148};
149
150Delphes3DGeometry::Delphes3DGeometry(TGeoManager *geom) {
151
152 //--- the geometry manager
153 geom_ = geom==NULL? gGeoManager : geom;
154 //gGeoManager->DefaultColors();
155
156 //--- define some materials
157 TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0);
158 TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7); // placeholder
159 matVacuum->SetTransparency(85); //TODO: tune
160 matAl->SetTransparency(85); //TODO: tune
161
162 //--- define some media
163 TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum);
164 TGeoMedium *Al = new TGeoMedium("Root Material",2, matAl);
165 vacuum_ = Vacuum;
166 tkmed_ = Vacuum; // placeholder
167 calomed_ = Al; // placeholder
168 mudetmed_ = Al; // placeholder
169
170 // custom parameters
171 contingency_ = 10.;
172 calo_barrel_thickness_ = 50.;
173 calo_endcap_thickness_ = 75.;
174 muonSystem_thickn_ = 10.;
175
176 // read these parameters from the Delphes Card (with default values)
177 etaAxis_ = NULL;
178 phiAxis_ = NULL;
179 tk_radius_ = 120.;
180 tk_length_ = 150.;
181 tk_etamax_ = 3.0;
182 tk_Bz_ = 1.;
183}
184
185void Delphes3DGeometry::readFile(const char *configFile,
186 const char* ParticlePropagator, const char* TrackingEfficiency,
187 const char* MuonEfficiency, const char* Calorimeters) {
188
189 ExRootConfReader *confReader = new ExRootConfReader;
190 confReader->ReadFile(configFile);
191
192 tk_radius_ = confReader->GetDouble(Form("%s::Radius",ParticlePropagator), 1.0)*100.; // tk_radius
193 tk_length_ = confReader->GetDouble(Form("%s::HalfLength",ParticlePropagator), 3.0)*100.; // tk_length
194 tk_Bz_ = confReader->GetDouble("ParticlePropagator::Bz", 0.0); // tk_Bz
195
196 {
197 TString tkEffFormula = confReader->GetString(Form("%s::EfficiencyFormula",TrackingEfficiency),"abs(eta)<3.0");
198 tkEffFormula.ReplaceAll("pt","x");
199 tkEffFormula.ReplaceAll("eta","y");
200 tkEffFormula.ReplaceAll("phi","0.");
201 TF2* tkEffFunction = new TF2("tkEff",tkEffFormula,0,1000,-10,10);
202 TH1F etaHisto("eta","eta",100,5.,-5.);
203 Double_t pt,eta;
204 for(int i=0;i<1000;++i) {
205 tkEffFunction->GetRandom2(pt,eta);
206 etaHisto.Fill(eta);
207 }
208 Int_t bin = -1;
209 bin = etaHisto.FindFirstBinAbove(0.5);
210 Double_t etamin = (bin>-1) ? etaHisto.GetBinLowEdge(bin) : -10.;
211 bin = etaHisto.FindLastBinAbove(0.5);
212 Double_t etamax = (bin>-1) ? etaHisto.GetBinLowEdge(bin+1) : -10.;
213 tk_etamax_ = TMath::Max(fabs(etamin),fabs(etamax)); // tk_etamax
214 delete tkEffFunction;
215 }
216
217 {
218 muondets_.push_back("muons");
219 TString muonEffFormula = confReader->GetString(Form("%s::EfficiencyFormula",MuonEfficiency),"abs(eta)<2.0");
220 muonEffFormula.ReplaceAll("pt","x");
221 muonEffFormula.ReplaceAll("eta","y");
222 muonEffFormula.ReplaceAll("phi","0.");
223 TF2* muEffFunction = new TF2("muEff",muonEffFormula,0,1000,-10,10);
224 TH1F etaHisto("eta2","eta2",100,5.,-5.);
225 Double_t pt,eta;
226 for(int i=0;i<1000;++i) {
227 muEffFunction->GetRandom2(pt,eta);
228 etaHisto.Fill(eta);
229 }
230 Int_t bin = -1;
231 bin = etaHisto.FindFirstBinAbove(0.5);
232 Double_t etamin = (bin>-1) ? etaHisto.GetBinLowEdge(bin) : -10.;
233 bin = etaHisto.FindLastBinAbove(0.5);
234 Double_t etamax = (bin>-1) ? etaHisto.GetBinLowEdge(bin+1) : -10.;
235 muonSystem_etamax_["muons"] = TMath::Max(fabs(etamin),fabs(etamax)); // muonSystem_etamax
236 delete muEffFunction;
237 }
238
239 std::string s(Calorimeters);
240 std::replace( s.begin(), s.end(), ',', ' ' );
241 std::istringstream stream( s );
242 std::string word;
243 while (stream >> word) calorimeters_.push_back(word);
244
245 caloBinning_.clear(); // calo binning
246 for(std::vector<std::string>::const_iterator calo=calorimeters_.begin();calo!=calorimeters_.end(); ++calo) {
247 set< pair<Double_t, Int_t> > caloBinning;
248 ExRootConfParam paramEtaBins, paramPhiBins;
249 ExRootConfParam param = confReader->GetParam(Form("%s::EtaPhiBins",calo->c_str()));
250 Int_t size = param.GetSize();
251 for(int i = 0; i < size/2; ++i) {
252 paramEtaBins = param[i*2];
253 paramPhiBins = param[i*2+1];
254 assert(paramEtaBins.GetSize()==1);
255 caloBinning.insert(std::make_pair(paramEtaBins[0].GetDouble(),paramPhiBins.GetSize()-1));
256 }
257 caloBinning_[*calo] = caloBinning;
258 }
259
260 set< pair<Double_t, Int_t> > caloBinning = caloBinning_[*calorimeters_.begin()];
261 Double_t *etaBins = new Double_t[caloBinning.size()]; // note that this is the eta binning of the first calo
262 unsigned int ii = 0;
263 for(set< pair<Double_t, Int_t> >::const_iterator itEtaSet = caloBinning.begin(); itEtaSet != caloBinning.end(); ++itEtaSet) {
264 etaBins[ii++] = itEtaSet->first;
265 }
266 etaAxis_ = new TAxis(caloBinning.size() - 1, etaBins);
267 phiAxis_ = new TAxis(72, -TMath::Pi(), TMath::Pi()); // note that this is fixed while #phibins could vary, also with eta, which doesn't seem possible in ROOT
268
269 delete confReader;
270
271}
272
273TGeoVolume* Delphes3DGeometry::getDetector(bool withTowers) {
274 // compute the envelope
275 Double_t system_radius = tk_radius_+calo_barrel_thickness_+3*contingency_;
276 Double_t system_length = tk_length_+contingency_+(contingency_+calo_endcap_thickness_)*calorimeters_.size()+contingency_;
277 // the detector volume
278 TGeoVolume *top = geom_->MakeBox("Delphes3DGeometry", vacuum_, system_radius, system_radius, system_length);
279 // build the detector
280 std::pair<Double_t, Double_t> limits = addTracker(top);
281 Double_t radius = limits.first;
282 Double_t length = limits.second;
283 for(std::vector<std::string>::const_iterator calo = calorimeters_.begin(); calo != calorimeters_.end(); ++calo) {
284 limits = addCalorimeter(top,calo->c_str(),radius,length,caloBinning_[*calo]);
285 if (withTowers) {
286 addCaloTowers(top,calo->c_str(),radius,length,caloBinning_[*calo]);
287 }
288 radius = limits.first;
289 length = limits.second;
290 }
291 for(std::vector<std::string>::const_iterator muon = muondets_.begin(); muon != muondets_.end(); ++muon) {
292 limits = addMuonDets(top, muon->c_str(), radius, length);
293 radius = limits.first;
294 length = limits.second;
295 }
296 // return the result
297 return top;
298}
299
300std::pair<Double_t, Double_t> Delphes3DGeometry::addTracker(TGeoVolume *top) {
301 // tracker: a cylinder with two cones substracted
302 new TGeoCone("forwardTkAcceptance",(tk_length_/2.+0.05),0.,tk_radius_,(tk_length_)*2.*exp(-tk_etamax_)/(1-exp(-2.*tk_etamax_)),tk_radius_);
303 TGeoTranslation *tr1 = new TGeoTranslation("tkacc1",0., 0., tk_length_/2.);
304 tr1->RegisterYourself();
305 TGeoRotation *negz = new TGeoRotation("tknegz",0,180,0);
306 negz->RegisterYourself();
307 TGeoCombiTrans *tr2 = new TGeoCombiTrans("tkacc2",0.,0.,-tk_length_/2.,negz);
308 tr2->RegisterYourself();
309 TGeoCompositeShape* tracker_cs = new TGeoCompositeShape("tracker_cs","forwardTkAcceptance:tkacc1+forwardTkAcceptance:tkacc2");
310 TGeoVolume *tracker = new TGeoVolume("tracker",tracker_cs,tkmed_);
311 tracker->SetLineColor(kYellow);
312 top->AddNode(tracker,1);
313 return std::make_pair(tk_radius_,tk_length_);
314}
315
316std::pair<Double_t, Double_t> Delphes3DGeometry::addCalorimeter(TGeoVolume *top, const char* name,
317 Double_t innerBarrelRadius, Double_t innerBarrelLength, set< pair<Double_t, Int_t> >& caloBinning) {
318 // parameters derived from the inputs
319 Double_t calo_endcap_etamax = TMath::Max(fabs(caloBinning.begin()->first),fabs(caloBinning.rbegin()->first));
320 Double_t calo_barrel_innerRadius = innerBarrelRadius+contingency_;
321 Double_t calo_barrel_length = innerBarrelLength + calo_barrel_thickness_;
322 Double_t calo_endcap_etamin = -log(innerBarrelRadius/(2*innerBarrelLength));
323 Double_t calo_endcap_innerRadius1 = innerBarrelLength*2.*exp(-calo_endcap_etamax)/(1-exp(-2.*calo_endcap_etamax));
324 Double_t calo_endcap_innerRadius2 = (innerBarrelLength+calo_endcap_thickness_)*2.*exp(-calo_endcap_etamax)/(1-exp(-2.*calo_endcap_etamax));
325 Double_t calo_endcap_outerRadius1 = innerBarrelRadius;
326 Double_t calo_endcap_outerRadius2 = innerBarrelRadius+calo_barrel_thickness_;
327 Double_t calo_endcap_coneThickness = TMath::Min(calo_barrel_thickness_ * (1-exp(-2.*calo_endcap_etamin)) / (2.*exp(-calo_endcap_etamin)), calo_endcap_thickness_);
328 Double_t calo_endcap_diskThickness = TMath::Max(0.,calo_endcap_thickness_-calo_endcap_coneThickness);
329
330 // calorimeters: tube truncated in eta + cones
331 new TGeoTube(Form("%s_barrel_cylinder",name),calo_barrel_innerRadius,calo_barrel_innerRadius+calo_barrel_thickness_,calo_barrel_length);
332 new TGeoCone(Form("%s_endcap_cone",name),calo_endcap_coneThickness/2.,calo_endcap_innerRadius1,calo_endcap_outerRadius1,calo_endcap_innerRadius2,calo_endcap_outerRadius2);
333 new TGeoTube(Form("%s_endcap_disk",name),calo_endcap_innerRadius2,tk_radius_+calo_barrel_thickness_,calo_endcap_diskThickness/2.);
334 TGeoTranslation *tr1 = new TGeoTranslation(Form("%s_tr1",name),0., 0., (calo_endcap_coneThickness+calo_endcap_diskThickness)/2.);
335 tr1->RegisterYourself();
336 TGeoCompositeShape *calo_endcap_cs = new TGeoCompositeShape(Form("%s_endcap_cs",name),Form("%s_endcap_cone+%s_endcap_disk:%s_tr1",name,name,name));
337 TGeoTranslation *trc1 = new TGeoTranslation(Form("%s_endcap1_position",name),0.,0., innerBarrelLength+calo_endcap_coneThickness/2.);
338 trc1->RegisterYourself();
339 TGeoRotation *negz = new TGeoRotation(Form("%s_negz",name),0,180,0);
340 TGeoCombiTrans *trc2 = new TGeoCombiTrans(Form("%s_endcap2_position",name),0.,0.,-(innerBarrelLength+calo_endcap_coneThickness/2.),negz);
341 trc2->RegisterYourself();
342 TGeoTranslation *trc1c = new TGeoTranslation(Form("%s_endcap1_position_cont",name),0.,0., innerBarrelLength+calo_endcap_coneThickness/2.+contingency_);
343 trc1c->RegisterYourself();
344 TGeoCombiTrans *trc2c = new TGeoCombiTrans(Form("%s_endcap2_position_cont",name),0.,0.,-(innerBarrelLength+calo_endcap_coneThickness/2.)-contingency_,negz);
345 trc2c->RegisterYourself();
346 TGeoVolume *calo_endcap = new TGeoVolume(Form("%s_endcap",name),calo_endcap_cs,calomed_);
347 TGeoCompositeShape *calo_barrel_cs = new TGeoCompositeShape(Form("%s_barrel_cs",name),
348 Form("%s_barrel_cylinder-%s_endcap_cs:%s_endcap1_position-%s_endcap_cs:%s_endcap2_position",name,name,name,name,name));
349 TGeoVolume *calo_barrel = new TGeoVolume(Form("%s_barrel",name),calo_barrel_cs,calomed_);
350 calo_endcap->SetLineColor(kViolet);
351 calo_endcap->SetFillColor(kViolet);
352 calo_barrel->SetLineColor(kRed);
353 top->AddNode(calo_endcap,1,trc1c);
354 top->AddNode(calo_endcap,2,trc2c);
355 top->AddNode(calo_barrel,1);
356 return std::make_pair(calo_barrel_innerRadius+calo_barrel_thickness_,innerBarrelLength+calo_endcap_thickness_+contingency_);
357}
358
359std::pair<Double_t, Double_t> Delphes3DGeometry::addMuonDets(TGeoVolume *top, const char* name, Double_t innerBarrelRadius, Double_t innerBarrelLength) {
360 // muon system: tube + disks
361 Double_t muonSystem_radius = innerBarrelRadius + contingency_;
362 Double_t muonSystem_length = innerBarrelLength + contingency_;
363 Double_t muonSystem_rmin = muonSystem_length*2.*exp(-muonSystem_etamax_[name])/(1-exp(-2.*muonSystem_etamax_[name]));
364 TGeoVolume *muon_barrel = geom_->MakeTube(Form("%s_barrel",name),mudetmed_,muonSystem_radius,muonSystem_radius+muonSystem_thickn_,muonSystem_length);
365 muon_barrel->SetLineColor(kBlue);
366 top->AddNode(muon_barrel,1);
367 TGeoVolume *muon_endcap = geom_->MakeTube(Form("%s_endcap",name),mudetmed_,muonSystem_rmin,muonSystem_radius+muonSystem_thickn_,muonSystem_thickn_/2.);
368 muon_endcap->SetLineColor(kBlue);
369 TGeoTranslation *trm1 = new TGeoTranslation(Form("%sEndcap1_position",name),0.,0.,muonSystem_length);
370 trm1->RegisterYourself();
371 TGeoTranslation *trm2 = new TGeoTranslation(Form("%sEndcap2_position",name),0.,0.,-muonSystem_length);
372 trm1->RegisterYourself();
373 top->AddNode(muon_endcap,1,trm1);
374 top->AddNode(muon_endcap,2,trm2);
375 return std::make_pair(muonSystem_radius,muonSystem_length);
376}
377
378void Delphes3DGeometry::addCaloTowers(TGeoVolume *top, const char* name,
379 Double_t innerBarrelRadius, Double_t innerBarrelLength, set< pair<Double_t, Int_t> >& caloBinning) {
380
381 TGeoVolume* calo_endcap = top->GetNode(Form("%s_endcap_1",name))->GetVolume();
382 TGeoVolume* calo_barrel = top->GetNode(Form("%s_barrel_1",name))->GetVolume();
383 Double_t calo_endcap_etamin = -log(innerBarrelRadius/(2*innerBarrelLength));
384 Double_t calo_endcap_coneThickness = TMath::Min(calo_barrel_thickness_ * (1-exp(-2.*calo_endcap_etamin)) / (2.*exp(-calo_endcap_etamin)), calo_endcap_thickness_);
385
386 // calo towers in the barrel
387 Double_t vertices[16] = {0.,0.,0.,0.,0.,0.,0.,0.}; // summit of the pyramid
388 Double_t R = tk_radius_ + contingency_+(contingency_+calo_barrel_thickness_)*calorimeters_.size(); // radius of the muons system = height of the pyramid
389 Int_t nEtaBins = caloBinning.size();
390 // this rotation is to make the tower point "up"
391 TGeoRotation* initTowerRot = new TGeoRotation(Form("%s_initTowerRot",name),0.,90.,0.);
392 TGeoCombiTrans* initTower = new TGeoCombiTrans(Form("%s_initTower",name),0.,-R/2.,0.,initTowerRot);
393 initTower->RegisterYourself();
394 // eta bins... we build one pyramid per eta slice and then translate it nphi times.
395 // phi bins represented by rotations around z
396 Double_t *y = new Double_t[nEtaBins];
397 Double_t *dx = new Double_t[nEtaBins];
398 Int_t *nphi = new Int_t[nEtaBins];
399 Int_t etaslice = 0;
400 std::map<std::pair<int,int>, TGeoRotation*> phirotations;
401 for(set< pair<Double_t, Int_t> >::const_iterator bin=caloBinning.begin(); bin!=caloBinning.end();++bin) {
402 if(abs(bin->first)>calo_endcap_etamin) continue; // only in the barrel
403 nphi[etaslice] = bin->second;
404 y[etaslice] = 0.5*R*(1-exp(-2*bin->first))/exp(-bin->first);
405 Double_t phiRotationAngle = 360./nphi[etaslice];
406 dx[etaslice] = R*tan(TMath::Pi()*phiRotationAngle/360.);
407 for(int phislice=0;phislice<nphi[etaslice];++phislice) {
408 phirotations[make_pair(etaslice,phislice)] = new TGeoRotation(Form("%s_phi%d_%d",name,etaslice,phislice),phiRotationAngle*phislice,0.,0.);
409 phirotations[make_pair(etaslice,phislice)]->RegisterYourself();
410 }
411 ++etaslice;
412 }
413 nEtaBins = etaslice;
414 for(int i=0;i<nEtaBins-1;++i) { // loop on the eta slices
415 vertices[8] = -dx[i]; vertices[9] = y[i];
416 vertices[10] = -dx[i]; vertices[11] = y[i+1];
417 vertices[12] = dx[i]; vertices[13] = y[i+1];
418 vertices[14] = dx[i]; vertices[15] = y[i];
419 new TGeoArb8(Form("%s_tower%d",name,i),R/2., vertices); // tower in the proper eta slice, at phi=0
420 // intersection between the tower and the calo_barrel
421 TGeoCompositeShape *finaltower_cs = new TGeoCompositeShape(Form("%s_ftower%d_cs",name,i),Form("%s_tower%d:%s_initTower*%s_barrel_cs",name,i,name,name));
422 TGeoVolume *finaltower = new TGeoVolume(Form("%s_ftower%d",name,i),finaltower_cs,calomed_);
423 finaltower->SetLineColor(kRed);
424 for(int j=0;j<nphi[i];++j) { // loop on the phi slices
425 calo_barrel->AddNode(finaltower,j,phirotations[make_pair(i,j)]);
426 }
427 }
428 delete[] y;
429 delete[] dx;
430 delete[] nphi;
431 //the towers in the forward region
432 R = tk_length_+contingency_+(contingency_+calo_endcap_thickness_)*calorimeters_.size(); // Z of the muons system = height of the pyramid
433 nEtaBins = caloBinning.size();
434 // translation to bring the origin of the tower to (0,0,0) (well, not really as the endcap is not yet in place)
435 TGeoTranslation* towerdz = new TGeoTranslation(Form("%s_towerdz",name),0.,0.,R/2.-(innerBarrelLength+calo_endcap_coneThickness/2.));
436 towerdz->RegisterYourself();
437 // eta bins... we build one pyramid per eta slice and then translate it nphi times.
438 Double_t *r = new Double_t[nEtaBins];
439 nphi = new Int_t[nEtaBins];
440 etaslice = 0;
441 phirotations.clear();
442 for(set< pair<Double_t, Int_t> >::const_iterator bin=caloBinning.begin(); bin!=caloBinning.end();++bin) {
443 if(bin->first<calo_endcap_etamin) continue; // only in the + endcap
444 r[etaslice] = R*2*exp(-bin->first)/(1-exp(-2*bin->first));
445 nphi[etaslice] = bin->second;
446 Double_t phiRotationAngle = 360./nphi[etaslice];
447 for(int phislice=0;phislice<nphi[etaslice];++phislice) {
448 phirotations[make_pair(etaslice,phislice)] = new TGeoRotation(Form("%s_forward_phi%d_%d",name,etaslice,phislice),phiRotationAngle*phislice,0.,0.);
449 phirotations[make_pair(etaslice,phislice)]->RegisterYourself();
450 }
451 ++etaslice;
452 }
453 nEtaBins = etaslice;
454 for(int i=0;i<nEtaBins-1;++i) { // loop on the eta slices
455 vertices[8] = -r[i+1]*sin(TMath::Pi()/nphi[i]); vertices[9] = r[i+1]*cos(TMath::Pi()/nphi[i]);
456 vertices[10] = -r[i]*sin(TMath::Pi()/nphi[i]); vertices[11] = r[i]*cos(TMath::Pi()/nphi[i]);
457 vertices[12] = r[i]*sin(TMath::Pi()/nphi[i]); vertices[13] = r[i]*cos(TMath::Pi()/nphi[i]);
458 vertices[14] = r[i+1]*sin(TMath::Pi()/nphi[i]); vertices[15] = r[i+1]*cos(TMath::Pi()/nphi[i]);
459 new TGeoArb8(Form("%sfwdtower%d",name,i),R/2., vertices); // tower in the proper eta slice, at phi=0
460 // intersection between the tower and the calo_endcap
461 TGeoCompositeShape *finalfwdtower_cs = new TGeoCompositeShape(Form("%sffwdtower%d_cs",name,i),Form("%sfwdtower%d:%s_towerdz*%s_endcap_cs",name,i,name,name));
462 TGeoVolume *finalfwdtower = new TGeoVolume(Form("%sffwdtower%d",name,i),finalfwdtower_cs,calomed_);
463 finalfwdtower->SetLineColor(kViolet);
464 for(int j=0;j<nphi[i];++j) { // loop on the phi slices
465 calo_endcap->AddNode(finalfwdtower,j,phirotations[make_pair(i,j)]);
466 }
467 }
468 delete[] r;
469 delete[] nphi;
470}
471
472/******************************************************************************/
473// Initialization and steering functions
474/******************************************************************************/
475
476void delphes_event_display(const char *configFile, const char *inputFile)
477{
478 // to be the main function...
479
480 // initialize the application
481 gSystem->Load("../libDelphesDisplay");
482 TGeoManager *geom = new TGeoManager("delphes", "Delphes geometry");
483 TEveManager::Create(kTRUE, "IV");
484
485 // build the detector
486 Delphes3DGeometry det3D;
487 //det3D.readFile(configFile,ParticlePropagator, TrackingEfficiency, MuonEfficiency, Calorimeters);
488 det3D.readFile(configFile);//TODO fix this
489 //top->AddNode(det3D.getDetector(true),1);
490 gRadius = det3D.getTrackerRadius();
491 gHalfLength = det3D.getTrackerHalfLength();
492 gBz = det3D.getBField();
493 gEtaAxis = det3D.getCaloAxes().first;
494 gPhiAxis = det3D.getCaloAxes().second;
495
496
497/*
498 // make the top container volume -> designed to contain a "big" detector (ATLAS)
499 TGeoVolume *top = geom->MakeBox("TOP", 0, 1500, 1500, 2300);
500 geom->SetTopVolume(top);
501
502 // build the detector
503 top->AddNode(det3D.getDetector(true),1);
504 geom->CloseGeometry();
505
506 gGeoManager->DefaultColors();
507
508 TGeoVolume* top = gGeoManager->GetTopVolume()->FindNode("Delphes3DGeometry_1")->GetVolume();
509
510 TEveGeoTopNode* trk = new TEveGeoTopNode(gGeoManager, top->FindNode("tracker_1"));
511 trk->SetVisLevel(6);
512 gEve->AddGlobalElement(trk);
513
514 TEveGeoTopNode* calo = new TEveGeoTopNode(gGeoManager, top->FindNode("Calorimeter_barrel_1"));
515 calo->SetVisLevel(3);
516 gEve->AddGlobalElement(calo);
517 calo = new TEveGeoTopNode(gGeoManager, top->FindNode("Calorimeter_endcap_1"));
518 calo->SetVisLevel(3);
519 calo->UseNodeTrans();
520 gEve->AddGlobalElement(calo);
521 calo = new TEveGeoTopNode(gGeoManager, top->FindNode("Calorimeter_endcap_2"));
522 calo->SetVisLevel(3);
523 calo->UseNodeTrans();
524 gEve->AddGlobalElement(calo);
525
526 TEveGeoTopNode* muon = new TEveGeoTopNode(gGeoManager, top->FindNode("muons_barrel_1"));
527 muon->SetVisLevel(4);
528 gEve->AddGlobalElement(muon);
529 muon = new TEveGeoTopNode(gGeoManager, top->FindNode("muons_endcap_1"));
530 muon->SetVisLevel(4);
531 muon->UseNodeTrans();
532 gEve->AddGlobalElement(muon);
533 muon = new TEveGeoTopNode(gGeoManager, top->FindNode("muons_endcap_2"));
534 muon->SetVisLevel(4);
535 muon->UseNodeTrans();
536 gEve->AddGlobalElement(muon);
537
538*/
539
540
541 //TGeoVolume* top = gGeoManager->GetTopVolume()->FindNode("Delphes3DGeometry_1")->GetVolume();
542 //TGeoVolume* top = det3D.getDetector(true);
543 TGeoVolume* top = det3D.getDetector(false); //TODO: can this be set in the GUI?
544 geom->SetTopVolume(top);
545 TEveElementList *geometry = new TEveElementList("Geometry");
546 TEveGeoTopNode* trk = new TEveGeoTopNode(gGeoManager, top->FindNode("tracker_1"));
547 trk->SetVisLevel(6);
548 geometry->AddElement(trk);
549 TEveGeoTopNode* calo = new TEveGeoTopNode(gGeoManager, top->FindNode("Calorimeter_barrel_1"));
550 calo->SetVisLevel(3);
551 geometry->AddElement(calo);
552 calo = new TEveGeoTopNode(gGeoManager, top->FindNode("Calorimeter_endcap_1"));
553 calo->SetVisLevel(3);
554 calo->UseNodeTrans();
555 geometry->AddElement(calo);
556 calo = new TEveGeoTopNode(gGeoManager, top->FindNode("Calorimeter_endcap_2"));
557 calo->SetVisLevel(3);
558 calo->UseNodeTrans();
559 geometry->AddElement(calo);
560 TEveGeoTopNode* muon = new TEveGeoTopNode(gGeoManager, top->FindNode("muons_barrel_1"));
561 muon->SetVisLevel(4);
562 geometry->AddElement(muon);
563 muon = new TEveGeoTopNode(gGeoManager, top->FindNode("muons_endcap_1"));
564 muon->SetVisLevel(4);
565 muon->UseNodeTrans();
566 geometry->AddElement(muon);
567 muon = new TEveGeoTopNode(gGeoManager, top->FindNode("muons_endcap_2"));
568 muon->SetVisLevel(4);
569 muon->UseNodeTrans();
570 geometry->AddElement(muon);
571 //gGeoManager->DefaultColors();
572
573 // Create chain of root trees
574 gChain.Add(inputFile);
575
576 // Create object of class ExRootTreeReader
577 printf("*** Opening Delphes data file ***\n");
578 gTreeReader = new ExRootTreeReader(&gChain);
579
580 // Get pointers to branches
581 gBranchTower = gTreeReader->UseBranch("Tower");
582 gBranchTrack = gTreeReader->UseBranch("Track");
583 gBranchJet = gTreeReader->UseBranch("Jet");
584
585//TODO make it configurable, for more objects (or can we guess from the config?)
586// idea: for pf objects, we could use the TEveCompound to show track + cluster ??? (nice display but little meaning)
587// for MET and SHT, show an arrow (tooltip = title)
588// for electrons and muons, create additional track collections
589// for photons, use TEveStraightLineSet
590
591/*
592 add Branch Calorimeter/eflowTracks EFlowTrack Track
593 add Branch Calorimeter/eflowPhotons EFlowPhoton Tower
594 add Branch Calorimeter/eflowNeutralHadrons EFlowNeutralHadron Tower
595
596 add Branch GenJetFinder/jets GenJet Jet
597
598 add Branch UniqueObjectFinder/jets Jet Jet
599
600 add Branch UniqueObjectFinder/electrons Electron Electron
601 add Branch UniqueObjectFinder/photons Photon Photon
602 add Branch UniqueObjectFinder/muons Muon Muon
603
604 add Branch MissingET/momentum MissingET MissingET
605 add Branch ScalarHT/energy ScalarHT ScalarHT
606*/
607
608 // data
609 gCaloData = new DelphesCaloData(2);
610 gCaloData->RefSliceInfo(0).Setup("ECAL", 0.1, kRed);
611 gCaloData->RefSliceInfo(1).Setup("HCAL", 0.1, kBlue);
612 gCaloData->SetEtaBins(gEtaAxis);
613 gCaloData->SetPhiBins(gPhiAxis);
614 gCaloData->IncDenyDestroy();
615
616 gJetList = new TEveElementList("Jets");
617 gEve->AddElement(gJetList);
618
619 gTrackList = new TEveTrackList("Tracks");
620 gTrackList->SetMainColor(kBlue);
621 gTrackList->SetMarkerColor(kRed);
622 gTrackList->SetMarkerStyle(kCircle);
623 gTrackList->SetMarkerSize(0.5);
624 gEve->AddElement(gTrackList);
625
626 TEveTrackPropagator *trkProp = gTrackList->GetPropagator();
627 trkProp->SetMagField(0.0, 0.0, -gBz);
628 trkProp->SetMaxR(gRadius);
629 trkProp->SetMaxZ(gHalfLength);
630
631 // viewers and scenes
632
633 TEveCalo3D *calo3d = new TEveCalo3D(gCaloData);
634 calo3d->SetBarrelRadius(gRadius);
635 calo3d->SetEndCapPos(gHalfLength);
636
637 //gStyle->SetPalette(1, 0);
638 TEveCaloLego *lego = new TEveCaloLego(gCaloData);
639 lego->InitMainTrans();
640 lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());
641 lego->SetAutoRebin(kFALSE);
642 lego->Set2DMode(TEveCaloLego::kValSizeOutline);
643
644 gDelphesDisplay = new DelphesDisplay;
645 gEve->AddGlobalElement(geometry);
646 gEve->AddGlobalElement(calo3d);
647 gDelphesDisplay->ImportGeomRPhi(geometry);
648 gDelphesDisplay->ImportCaloRPhi(calo3d);
649 gDelphesDisplay->ImportGeomRhoZ(geometry);
650 gDelphesDisplay->ImportCaloRhoZ(calo3d);
651 gDelphesDisplay->ImportCaloLego(lego);
652 gEve->Redraw3D(kTRUE);
653
654}
655
656//______________________________________________________________________________
657void load_event()
658{
659 // Load event specified in global event_id.
660 // The contents of previous event are removed.
661
662 printf("Loading event %d.\n", event_id);
663
664 gEve->GetViewers()->DeleteAnnotations();
665
666 if(gCaloData) gCaloData->ClearTowers();
667 if(gJetList) gJetList->DestroyElements();
668 if(gTrackList) gTrackList->DestroyElements();
669
670 delphes_read();
671
672 TEveElement* top = (TEveElement*)gEve->GetCurrentEvent();
673 gDelphesDisplay->DestroyEventRPhi();
674 gDelphesDisplay->ImportEventRPhi(top);
675 gDelphesDisplay->DestroyEventRhoZ();
676 gDelphesDisplay->ImportEventRhoZ(top);
677
678 //update_html_summary();
679
680 gEve->Redraw3D(kFALSE, kTRUE);
681}
682
683void delphes_read()
684{
685
686 TIter itTower(gBranchTower);
687 TIter itTrack(gBranchTrack);
688 TIter itJet(gBranchJet);
689
690 Tower *tower;
691 Track *track;
692 Jet *jet;
693
694 TEveJetCone *eveJetCone;
695 TEveTrack *eveTrack;
696
697 Int_t counter;
698
699 TEveTrackPropagator *trkProp = gTrackList->GetPropagator();
700 if(event_id >= gTreeReader->GetEntries()) return;
701
702 // Load selected branches with data from specified event
703 gTreeReader->ReadEntry(event_id);
704 // Loop over all towers
705 itTower.Reset();
706 while((tower = (Tower *) itTower.Next()))
707 {
708 gCaloData->AddTower(tower->Edges[0], tower->Edges[1], tower->Edges[2], tower->Edges[3]);
709 gCaloData->FillSlice(0, tower->Eem);
710 gCaloData->FillSlice(1, tower->Ehad);
711 }
712 gCaloData->DataChanged();
713 // Loop over all tracks
714 itTrack.Reset();
715 counter = 0;
716 while((track = (Track *) itTrack.Next()))
717 {
718 TParticle pb(track->PID, 1, 0, 0, 0, 0,
719 track->P4().Px(), track->P4().Py(),
720 track->P4().Pz(), track->P4().E(),
721 track->X, track->Y, track->Z, 0.0);
722
723 eveTrack = new TEveTrack(&pb, counter, trkProp);
724 eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
725 eveTrack->SetStdTitle();
726 eveTrack->SetAttLineAttMarker(gTrackList);
727
728 switch(TMath::Abs(track->PID))
729 {
730 case 11:
731 eveTrack->SetLineColor(kRed);
732 break;
733 case 13:
734 eveTrack->SetLineColor(kGreen);
735 break;
736 default:
737 eveTrack->SetLineColor(kBlue);
738 }
739 gTrackList->AddElement(eveTrack);
740 eveTrack->MakeTrack();
741 }
742 // Loop over all jets
743 itJet.Reset();
744 counter = 0;
745 while((jet = (Jet *) itJet.Next()))
746 {
747 eveJetCone = new TEveJetCone();
748 eveJetCone->SetName(Form("jet [%d]", counter++));
749 eveJetCone->SetMainTransparency(60);
750 eveJetCone->SetLineColor(kYellow);
751 eveJetCone->SetCylinder(gRadius - 10, gHalfLength - 10);
752 eveJetCone->SetPickable(kTRUE);
753 eveJetCone->AddEllipticCone(jet->Eta, jet->Phi, jet->DeltaEta, jet->DeltaPhi);
754 gJetList->AddElement(eveJetCone);
755 }
756}
757
758
759/******************************************************************************/
760// GUI
761/******************************************************************************/
762
763//______________________________________________________________________________
764//
765// EvNavHandler class is needed to connect GUI signals.
766
767class EvNavHandler
768{
769public:
770 void Fwd()
771 {
772 if (event_id < gTreeReader->GetEntries() - 1) {
773 ++event_id;
774 load_event();
775 } else {
776 printf("Already at last event.\n");
777 }
778 }
779 void Bck()
780 {
781 if (event_id > 0) {
782 --event_id;
783 load_event();
784 } else {
785 printf("Already at first event.\n");
786 }
787 }
788};
789
790//______________________________________________________________________________
791void make_gui()
792{
793 // Create minimal GUI for event navigation.
794 // TODO: better GUI could be made based on the ch15 of the manual (Writing a GUI)
795
796 // add a tab on the left
797 TEveBrowser* browser = gEve->GetBrowser();
798 browser->StartEmbedding(TRootBrowser::kLeft);
799
800 // set the main title
801 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
802 frmMain->SetWindowName("Delphes Event Display");
803 frmMain->SetCleanup(kDeepCleanup);
804
805 // build the navigation menu
806 TGHorizontalFrame* hf = new TGHorizontalFrame(frmMain);
807 {
808 TString icondir;
809 if(gSystem->Getenv("ROOTSYS"))
810 icondir = Form("%s/icons/", gSystem->Getenv("ROOTSYS"));
811 if(!gSystem->OpenDirectory(icondir))
812 icondir = Form("%s/icons/", (const char*)gSystem->GetFromPipe("root-config --etcdir") );
813 TGPictureButton* b = 0;
814 EvNavHandler *fh = new EvNavHandler;
815
816 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoBack.gif"));
817 hf->AddFrame(b);
818 b->Connect("Clicked()", "EvNavHandler", fh, "Bck()");
819
820 b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoForward.gif"));
821 hf->AddFrame(b);
822 b->Connect("Clicked()", "EvNavHandler", fh, "Fwd()");
823 }
824 frmMain->AddFrame(hf);
825 frmMain->MapSubwindows();
826 frmMain->Resize();
827 frmMain->MapWindow();
828 browser->StopEmbedding();
829 browser->SetTabTitle("Event Control", 0);
830}
831
832/******************************************************************************/
833// MAIN
834/******************************************************************************/
835
836void geometry(const char* filename = "delphes_card_CMS.tcl", const char* ParticlePropagator="ParticlePropagator",
837 const char* TrackingEfficiency="ChargedHadronTrackingEfficiency",
838 const char* MuonEfficiency="MuonEfficiency",
839 const char* Calorimeters="Calorimeter")
840{
841
842
843 gSystem->Load("libGeom");
844 gSystem->Load("../libDelphes");
845
846 delphes_event_display("delphes_card_CMS.tcl", "../delphes_output.root"); //TODO propagate parameters
847 make_gui();
848 load_event();
849 gEve->Redraw3D(kTRUE); // Reset camera after the first event has been shown.
850
851 // EClipType not exported to CINT (see TGLUtil.h):
852 // 0 - no clip, 1 - clip plane, 2 - clip box
853 TGLViewer *v = gEve->GetDefaultGLViewer();
854 Double_t plane[4] = { 0., 1., 0., 0. };
855 //v->GetClipSet()->SetClipState(1,plane);
856 //v->GetClipSet()->SetClipType(1);
857 //v->ColorSet().Background().SetColor(kMagenta+4);
858 //v->SetGuideState(TGLUtil::kAxesEdge, kTRUE, kFALSE, 0);
859 v->RefreshPadEditor(v);
860 v->CurrentCamera().RotateRad(-1.2, 0.5);
861 v->DoDraw();
862
863/*
864 TGeoManager *geom = new TGeoManager("delphes", "Delphes geometry");
865
866 // make the top container volume -> designed to contain a "big" detector (ATLAS)
867 TGeoVolume *top = geom->MakeBox("TOP", 0, 1500, 1500, 2300);
868 geom->SetTopVolume(top);
869
870 // build the detector
871 Delphes3DGeometry det3D;
872 det3D.readFile(filename,ParticlePropagator, TrackingEfficiency, MuonEfficiency, Calorimeters);
873 top->AddNode(det3D.getDetector(true),1);
874
875 // draw it
876 geom->CloseGeometry();
877 //top->Draw();
878 //TFile* file = new TFile("DelpheGeom.root","RECREATE");
879 //top->Write("DelphesGeometry");
880 //file->Close();
881
882 TEveManager::Create(kTRUE, "IV");
883
884
885 //TFile::SetCacheFileDir(".");
886 //gGeoManager = gEve->GetGeometry("DelpheGeom.root");
887 gGeoManager->DefaultColors();
888
889 TGeoVolume* top = gGeoManager->GetTopVolume()->FindNode("Delphes3DGeometry_1")->GetVolume();
890
891 TEveGeoTopNode* trk = new TEveGeoTopNode(gGeoManager, top->FindNode("tracker_1"));
892 trk->SetVisLevel(6);
893 gEve->AddGlobalElement(trk);
894
895 TEveGeoTopNode* calo = new TEveGeoTopNode(gGeoManager, top->FindNode("Calorimeter_barrel_1"));
896 calo->SetVisLevel(3);
897 gEve->AddGlobalElement(calo);
898 calo = new TEveGeoTopNode(gGeoManager, top->FindNode("Calorimeter_endcap_1"));
899 calo->SetVisLevel(3);
900 calo->UseNodeTrans();
901 gEve->AddGlobalElement(calo);
902 calo = new TEveGeoTopNode(gGeoManager, top->FindNode("Calorimeter_endcap_2"));
903 calo->SetVisLevel(3);
904 calo->UseNodeTrans();
905 gEve->AddGlobalElement(calo);
906
907 TEveGeoTopNode* muon = new TEveGeoTopNode(gGeoManager, top->FindNode("muons_barrel_1"));
908 muon->SetVisLevel(4);
909 gEve->AddGlobalElement(muon);
910 muon = new TEveGeoTopNode(gGeoManager, top->FindNode("muons_endcap_1"));
911 muon->SetVisLevel(4);
912 muon->UseNodeTrans();
913 gEve->AddGlobalElement(muon);
914 muon = new TEveGeoTopNode(gGeoManager, top->FindNode("muons_endcap_2"));
915 muon->SetVisLevel(4);
916 muon->UseNodeTrans();
917 gEve->AddGlobalElement(muon);
918
919 gEve->FullRedraw3D(kTRUE);
920
921 // EClipType not exported to CINT (see TGLUtil.h):
922 // 0 - no clip, 1 - clip plane, 2 - clip box
923 TGLViewer *v = gEve->GetDefaultGLViewer();
924 v->GetClipSet()->SetClipType(1);
925 v->ColorSet().Background().SetColor(kMagenta+4);
926 v->SetGuideState(TGLUtil::kAxesEdge, kTRUE, kFALSE, 0);
927 v->RefreshPadEditor(v);
928
929 v->CurrentCamera().RotateRad(-1.2, 0.5);
930 v->DoDraw();
931*/
932}
933
Note: See TracBrowser for help on using the repository browser.