Fork me on GitHub

source: git/examples/geometry.C@ e0c1ff0

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

Mostly in place but crashing

Just debugged the obvious typos and other things. It compiles.
Still, crash at runtime in TGeoManager::SetTopVolume(TGeoVolume*)

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