Fork me on GitHub

source: git/examples/geometry.C@ 7513718

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

Almost integrated geometry and event display

In terms of functionalities, we should be close. But this has to be
debugged. Then, other features will have to be developed.

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