1 | #include <set>
|
---|
2 | #include <map>
|
---|
3 | #include <utility>
|
---|
4 | #include <vector>
|
---|
5 | #include "TGeoManager.h"
|
---|
6 | #include "TGeoVolume.h"
|
---|
7 | #include "TGeoMedium.h"
|
---|
8 | #include "TGeoNode.h"
|
---|
9 | #include "TGeoCompositeShape.h"
|
---|
10 | #include "TGeoMatrix.h"
|
---|
11 | #include "TGeoTube.h"
|
---|
12 | #include "TGeoCone.h"
|
---|
13 | #include "TGeoArb8.h"
|
---|
14 | //#include "../external/ExRootAnalysis/ExRootConfReader.h"
|
---|
15 | #include "TF2.h"
|
---|
16 | #include "TH1F.h"
|
---|
17 | #include "TMath.h"
|
---|
18 | #include "TSystem.h"
|
---|
19 |
|
---|
20 | using namespace std;
|
---|
21 |
|
---|
22 | // TODO: asymmetric detector
|
---|
23 | // TODO: generalize for FCC-like config: >1 calorimeter & flexibility in module names
|
---|
24 | class Delphes3DGeometry {
|
---|
25 | public:
|
---|
26 | Delphes3DGeometry(TGeoManager *geom = NULL);
|
---|
27 | ~Delphes3DGeometry() {}
|
---|
28 |
|
---|
29 | void readFile(const char* filename);
|
---|
30 |
|
---|
31 | void setContingency(Double_t contingency) { contingency_ = contingency; }
|
---|
32 | void setCaloBarrelThickness(Double_t thickness) { calo_barrel_thickness_ = thickness; }
|
---|
33 | void setCaloEndcapThickness(Double_t thickness) { calo_endcap_thickness_ = thickness; }
|
---|
34 | void setMuonSystemThickness(Double_t thickness) { muonSystem_thickn_ = thickness; }
|
---|
35 |
|
---|
36 | TGeoVolume* getDetector(bool withTowers = true);
|
---|
37 |
|
---|
38 | private:
|
---|
39 | void addTracker(TGeoVolume *top);
|
---|
40 | void addCalorimeters(TGeoVolume *top);
|
---|
41 | void addMuonDets(TGeoVolume *top);
|
---|
42 | void addCaloTowers(TGeoVolume *top);
|
---|
43 |
|
---|
44 | private:
|
---|
45 |
|
---|
46 | TGeoManager *geom_;
|
---|
47 |
|
---|
48 | TGeoMedium *vacuum_;
|
---|
49 | TGeoMedium *tkmed_;
|
---|
50 | TGeoMedium *calomed_;
|
---|
51 | TGeoMedium *mudetmed_;
|
---|
52 |
|
---|
53 | Double_t contingency_;
|
---|
54 | Double_t calo_barrel_thickness_;
|
---|
55 | Double_t calo_endcap_thickness_;
|
---|
56 | Double_t muonSystem_thickn_;
|
---|
57 | Double_t tk_radius_;
|
---|
58 | Double_t tk_length_;
|
---|
59 | Double_t calo_endcap_etamax_;
|
---|
60 | Double_t muonSystem_etamax_;
|
---|
61 | Double_t calo_barrel_innerRadius_;
|
---|
62 | Double_t calo_endcap_etamin_;
|
---|
63 | Double_t calo_endcap_innerRadius1_;
|
---|
64 | Double_t calo_endcap_innerRadius2_;
|
---|
65 | Double_t calo_endcap_outerRadius1_;
|
---|
66 | Double_t calo_endcap_outerRadius2_;
|
---|
67 | Double_t calo_endcap_coneThickness_;
|
---|
68 | Double_t calo_endcap_diskThickness_;
|
---|
69 |
|
---|
70 | set< pair<Double_t, Int_t> > caloBinning_;
|
---|
71 |
|
---|
72 | };
|
---|
73 |
|
---|
74 | Delphes3DGeometry::Delphes3DGeometry(TGeoManager *geom) {
|
---|
75 |
|
---|
76 | //--- the geometry manager
|
---|
77 | geom_ = geom==NULL? gGeoManager : geom;
|
---|
78 |
|
---|
79 | //--- define some materials
|
---|
80 | TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0);
|
---|
81 | TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7); // placeholder
|
---|
82 |
|
---|
83 | //--- define some media
|
---|
84 | TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum);
|
---|
85 | TGeoMedium *Al = new TGeoMedium("Root Material",2, matAl);
|
---|
86 | vacuum_ = Vacuum;
|
---|
87 | tkmed_ = Vacuum; // placeholder
|
---|
88 | calomed_ = Al; // placeholder
|
---|
89 | mudetmed_ = Al; // placeholder
|
---|
90 |
|
---|
91 | // custom parameters
|
---|
92 | contingency_ = 10.;
|
---|
93 | calo_barrel_thickness_ = 50.;
|
---|
94 | calo_endcap_thickness_ = 75.;
|
---|
95 | muonSystem_thickn_ = contingency_;
|
---|
96 |
|
---|
97 | // read these parameters from the Delphes Card (with default values)
|
---|
98 | tk_radius_ = 120.;
|
---|
99 | tk_length_ = 150.;
|
---|
100 | calo_endcap_etamax_ = 2.6;
|
---|
101 | muonSystem_etamax_ = 2.4;
|
---|
102 | }
|
---|
103 |
|
---|
104 | void Delphes3DGeometry::readFile(const char *configFile) {
|
---|
105 |
|
---|
106 | ExRootConfReader *confReader = new ExRootConfReader;
|
---|
107 | confReader->ReadFile(configFile);
|
---|
108 |
|
---|
109 | tk_radius_ = confReader->GetDouble("ParticlePropagator::Radius", 1.0)*100; // tk_radius
|
---|
110 | tk_length_ = confReader->GetDouble("ParticlePropagator::HalfLength", 3.0)*100; // tk_length
|
---|
111 |
|
---|
112 | TString muonEffFormula = confReader->GetString("MuonEfficiency::EfficiencyFormula","abs(eta)<2.0");
|
---|
113 | muonEffFormula.ReplaceAll("pt","x");
|
---|
114 | muonEffFormula.ReplaceAll("eta","y");
|
---|
115 | muonEffFormula.ReplaceAll("phi","0.");
|
---|
116 | TF2* muEffFunction = new TF2("muEff",muonEffFormula,0,1000,-10,10);
|
---|
117 | TH1F etaHisto("eta","eta",100,5.,-5.);
|
---|
118 | Double_t pt,eta;
|
---|
119 | for(int i=0;i<1000;++i) {
|
---|
120 | muEffFunction->GetRandom2(pt,eta);
|
---|
121 | etaHisto.Fill(eta);
|
---|
122 | }
|
---|
123 | Int_t bin = -1;
|
---|
124 | bin = etaHisto.FindFirstBinAbove(0.5);
|
---|
125 | Double_t etamin = (bin>-1) ? etaHisto.GetBinLowEdge(bin) : -10.;
|
---|
126 | bin = etaHisto.FindLastBinAbove(0.5);
|
---|
127 | Double_t etamax = (bin>-1) ? etaHisto.GetBinLowEdge(bin+1) : -10.;
|
---|
128 | muonSystem_etamax_ = TMath::Max(fabs(etamin),fabs(etamax)); // muonSystem_etamax
|
---|
129 | delete muEffFunction;
|
---|
130 |
|
---|
131 | caloBinning_.clear(); // calo binning
|
---|
132 | ExRootConfParam paramEtaBins, paramPhiBins;
|
---|
133 | ExRootConfParam param = confReader->GetParam("Calorimeter::EtaPhiBins");
|
---|
134 | Int_t size = param.GetSize();
|
---|
135 | for(int i = 0; i < size/2; ++i) {
|
---|
136 | paramEtaBins = param[i*2];
|
---|
137 | paramPhiBins = param[i*2+1];
|
---|
138 | assert(paramEtaBins.GetSize()==1);
|
---|
139 | caloBinning_.insert(std::make_pair(paramEtaBins[0].GetDouble(),paramPhiBins.GetSize()-1));
|
---|
140 | }
|
---|
141 |
|
---|
142 | calo_endcap_etamax_ = TMath::Max(fabs(caloBinning_.begin()->first),fabs(caloBinning_.rbegin()->first)); // calo_endcap_etamax_
|
---|
143 |
|
---|
144 | delete confReader;
|
---|
145 |
|
---|
146 | calo_barrel_innerRadius_ = tk_radius_+contingency_;
|
---|
147 | calo_endcap_etamin_ = -log(tk_radius_/(2*tk_length_));
|
---|
148 | calo_endcap_innerRadius1_ = tk_length_*2.*exp(-calo_endcap_etamax_)/(1-exp(-2.*calo_endcap_etamax_));
|
---|
149 | calo_endcap_innerRadius2_ = (tk_length_+calo_endcap_thickness_)*2.*exp(-calo_endcap_etamax_)/(1-exp(-2.*calo_endcap_etamax_));
|
---|
150 | calo_endcap_outerRadius1_ = tk_radius_;
|
---|
151 | calo_endcap_outerRadius2_ = tk_radius_+calo_barrel_thickness_;
|
---|
152 | calo_endcap_coneThickness_ = calo_barrel_thickness_ * (1-exp(-2.*calo_endcap_etamin_)) / (2.*exp(-calo_endcap_etamin_));
|
---|
153 | calo_endcap_diskThickness_ = TMath::Max(0.,calo_endcap_thickness_-calo_endcap_coneThickness_);
|
---|
154 | }
|
---|
155 |
|
---|
156 | TGeoVolume* Delphes3DGeometry::getDetector(bool withTowers) {
|
---|
157 | TGeoVolume *top = geom_->MakeBox("Delphes3DGeometry", vacuum_, 1500, 1500, 2300); // determine the size from what we know about the detector TODO
|
---|
158 | addTracker(top);
|
---|
159 | addCalorimeters(top);
|
---|
160 | addMuonDets(top);
|
---|
161 | if (withTowers) {
|
---|
162 | addCaloTowers(top);
|
---|
163 | }
|
---|
164 | return top;
|
---|
165 | }
|
---|
166 |
|
---|
167 | void Delphes3DGeometry::addTracker(TGeoVolume *top) {
|
---|
168 | // tracker: a cylinder
|
---|
169 | TGeoVolume *tracker = geom_->MakeTube("tracker", tkmed_, 0., tk_radius_, tk_length_);
|
---|
170 | tracker->SetLineColor(kYellow);
|
---|
171 | top->AddNode(tracker,1);
|
---|
172 | }
|
---|
173 |
|
---|
174 | void Delphes3DGeometry::addCalorimeters(TGeoVolume *top) {
|
---|
175 | // calorimeters: tube truncated in eta + cones
|
---|
176 |
|
---|
177 | /*TGeoTube *calo_barrel_cylinder =*/ new TGeoTube("calo_barrel_cylinder",calo_barrel_innerRadius_,tk_radius_+calo_barrel_thickness_+contingency_,tk_length_+calo_barrel_thickness_);
|
---|
178 | /*TGeoCone *calo_endcap_cone =*/ new TGeoCone("calo_endcap_cone",calo_endcap_coneThickness_/2.,calo_endcap_innerRadius1_,calo_endcap_outerRadius1_,calo_endcap_innerRadius2_,calo_endcap_outerRadius2_);
|
---|
179 | /*TGeoTube *calo_endcap_disk =*/ new TGeoTube("calo_endcap_disk",calo_endcap_innerRadius2_,tk_radius_+calo_barrel_thickness_,calo_endcap_diskThickness_/2.);
|
---|
180 | TGeoTranslation *tr1 = new TGeoTranslation("tr1",0., 0., (calo_endcap_coneThickness_+calo_endcap_diskThickness_)/2.);
|
---|
181 | tr1->RegisterYourself();
|
---|
182 | TGeoCompositeShape *calo_endcap_cs = new TGeoCompositeShape("calo_endcap_cs","calo_endcap_cone+calo_endcap_disk:tr1");
|
---|
183 | TGeoTranslation *trc1 = new TGeoTranslation("calo_endcap1_position",0.,0., tk_length_+calo_endcap_coneThickness_/2.);
|
---|
184 | trc1->RegisterYourself();
|
---|
185 | TGeoRotation *negz = new TGeoRotation("negz",0,180,0);
|
---|
186 | TGeoCombiTrans *trc2 = new TGeoCombiTrans("calo_endcap2_position",0.,0.,-(tk_length_+calo_endcap_coneThickness_/2.),negz);
|
---|
187 | trc2->RegisterYourself();
|
---|
188 | TGeoTranslation *trc1c = new TGeoTranslation("calo_endcap1_position_cont",0.,0., tk_length_+calo_endcap_coneThickness_/2.+contingency_);
|
---|
189 | trc1c->RegisterYourself();
|
---|
190 | TGeoCombiTrans *trc2c = new TGeoCombiTrans("calo_endcap2_position_cont",0.,0.,-(tk_length_+calo_endcap_coneThickness_/2.)-contingency_,negz);
|
---|
191 | trc2c->RegisterYourself();
|
---|
192 | TGeoVolume *calo_endcap = new TGeoVolume("calo_endcap",calo_endcap_cs,calomed_);
|
---|
193 | TGeoCompositeShape *calo_barrel_cs = new TGeoCompositeShape("calo_barrel_cs","calo_barrel_cylinder-calo_endcap_cs:calo_endcap1_position-calo_endcap_cs:calo_endcap2_position");
|
---|
194 | TGeoVolume *calo_barrel = new TGeoVolume("calo_barrel",calo_barrel_cs,calomed_);
|
---|
195 | calo_endcap->SetLineColor(kViolet);
|
---|
196 | calo_endcap->SetFillColor(kViolet);
|
---|
197 | calo_barrel->SetLineColor(kRed);
|
---|
198 | top->AddNode(calo_endcap,1,trc1c);
|
---|
199 | top->AddNode(calo_endcap,2,trc2c);
|
---|
200 | top->AddNode(calo_barrel,1);
|
---|
201 | }
|
---|
202 |
|
---|
203 | void Delphes3DGeometry::addMuonDets(TGeoVolume *top) {
|
---|
204 |
|
---|
205 | // muon system: tube + disks
|
---|
206 | Double_t muonSystem_radius = tk_radius_+calo_barrel_thickness_+2*contingency_;
|
---|
207 | Double_t muonSystem_length = tk_length_+TMath::Max(calo_endcap_coneThickness_,calo_endcap_thickness_)+2*contingency_;
|
---|
208 | Double_t muonSystem_rmin = muonSystem_length*2.*exp(-muonSystem_etamax_)/(1-exp(-2.*muonSystem_etamax_));
|
---|
209 | TGeoVolume *muon_barrel = geom_->MakeTube("muon_barrel",mudetmed_,muonSystem_radius,muonSystem_radius+muonSystem_thickn_,muonSystem_length);
|
---|
210 | muon_barrel->SetLineColor(kBlue);
|
---|
211 | top->AddNode(muon_barrel,1);
|
---|
212 | TGeoVolume *muon_endcap = geom_->MakeTube("muon_endcap",mudetmed_,muonSystem_rmin,muonSystem_radius+muonSystem_thickn_,muonSystem_thickn_/2.);
|
---|
213 | muon_endcap->SetLineColor(kBlue);
|
---|
214 | TGeoTranslation *trm1 = new TGeoTranslation("muonEndcap1_position",0.,0.,muonSystem_length);
|
---|
215 | trm1->RegisterYourself();
|
---|
216 | TGeoTranslation *trm2 = new TGeoTranslation("muonEndcap2_position",0.,0.,-muonSystem_length);
|
---|
217 | trm1->RegisterYourself();
|
---|
218 | top->AddNode(muon_endcap,1,trm1);
|
---|
219 | top->AddNode(muon_endcap,1,trm2);
|
---|
220 | }
|
---|
221 |
|
---|
222 | void Delphes3DGeometry::addCaloTowers(TGeoVolume *top) {
|
---|
223 |
|
---|
224 | TGeoVolume* calo_endcap = top->GetNode("calo_endcap_1")->GetVolume();
|
---|
225 | TGeoVolume* calo_barrel = top->GetNode("calo_barrel_1")->GetVolume();
|
---|
226 |
|
---|
227 | // calo towers in the barrel
|
---|
228 | Double_t vertices[16] = {0.,0.,0.,0.,0.,0.,0.,0.}; // summit of the pyramid
|
---|
229 | Double_t R = tk_radius_+calo_barrel_thickness_+2*contingency_; // radius of the muons system = height of the pyramid
|
---|
230 | Int_t nEtaBins = caloBinning_.size();
|
---|
231 | // this rotation is to make the tower point "up"
|
---|
232 | TGeoRotation* initTowerRot = new TGeoRotation("initTowerRot",0.,90.,0.);
|
---|
233 | TGeoCombiTrans* initTower = new TGeoCombiTrans("initTower",0.,-R/2.,0.,initTowerRot);
|
---|
234 | initTower->RegisterYourself();
|
---|
235 | // eta bins... we build one pyramid per eta slice and then translate it nphi times.
|
---|
236 | // phi bins represented by rotations around z
|
---|
237 | Double_t *y = new Double_t[nEtaBins];
|
---|
238 | Double_t *dx = new Double_t[nEtaBins];
|
---|
239 | Int_t *nphi = new Int_t[nEtaBins];
|
---|
240 | Int_t etaslice = 0;
|
---|
241 | std::map<std::pair<int,int>, TGeoRotation*> phirotations;
|
---|
242 | for(set< pair<Double_t, Int_t> >::const_iterator bin=caloBinning_.begin(); bin!=caloBinning_.end();++bin) {
|
---|
243 | if(abs(bin->first)>calo_endcap_etamin_) continue; // only in the barrel
|
---|
244 | nphi[etaslice] = bin->second;
|
---|
245 | y[etaslice] = 0.5*R*(1-exp(-2*bin->first))/exp(-bin->first);
|
---|
246 | Double_t phiRotationAngle = 360./nphi[etaslice];
|
---|
247 | dx[etaslice] = R*tan(TMath::Pi()*phiRotationAngle/360.);
|
---|
248 | for(int phislice=0;phislice<nphi[etaslice];++phislice) {
|
---|
249 | phirotations[make_pair(etaslice,phislice)] = new TGeoRotation(Form("phi%d_%d",etaslice,phislice),phiRotationAngle*phislice,0.,0.);
|
---|
250 | phirotations[make_pair(etaslice,phislice)]->RegisterYourself();
|
---|
251 | }
|
---|
252 | ++etaslice;
|
---|
253 | }
|
---|
254 | nEtaBins = ++etaslice;
|
---|
255 | for(int i=0;i<nEtaBins-1;++i) { // loop on the eta slices
|
---|
256 | vertices[8] = -dx[i]; vertices[9] = y[i];
|
---|
257 | vertices[10] = -dx[i]; vertices[11] = y[i+1];
|
---|
258 | vertices[12] = dx[i]; vertices[13] = y[i+1];
|
---|
259 | vertices[14] = dx[i]; vertices[15] = y[i];
|
---|
260 | /*TGeoArb8 *tower =*/ new TGeoArb8(Form("tower%d",i),R/2., vertices); // tower in the proper eta slice, at phi=0
|
---|
261 | // intersection between the tower and the calo_barrel
|
---|
262 | TGeoCompositeShape *finaltower_cs = new TGeoCompositeShape(Form("ftower%d_cs",i),Form("tower%d:initTower*calo_barrel_cs",i));
|
---|
263 | TGeoVolume *finaltower = new TGeoVolume(Form("ftower%d",i),finaltower_cs,calomed_);
|
---|
264 | finaltower->SetLineColor(kRed);
|
---|
265 | for(int j=0;j<nphi[i];++j) { // loop on the phi slices
|
---|
266 | calo_barrel->AddNode(finaltower,j,phirotations[make_pair(i,j)]);
|
---|
267 | }
|
---|
268 | }
|
---|
269 | delete[] y;
|
---|
270 | delete[] dx;
|
---|
271 | delete[] nphi;
|
---|
272 | //the towers in the forward region
|
---|
273 | R = tk_length_+calo_endcap_thickness_+3*contingency_; // Z of the muons system = height of the pyramid
|
---|
274 | nEtaBins = caloBinning_.size();
|
---|
275 | // translation to bring the origin of the tower to (0,0,0)
|
---|
276 | TGeoTranslation* towerdz = new TGeoTranslation("towerdz",0.,0.,R/2.-(tk_length_+calo_endcap_coneThickness_/2.));
|
---|
277 | towerdz->RegisterYourself();
|
---|
278 | // eta bins... we build one pyramid per eta slice and then translate it nphi times.
|
---|
279 | Double_t *r = new Double_t[nEtaBins];
|
---|
280 | nphi = new Int_t[nEtaBins];
|
---|
281 | etaslice = 0;
|
---|
282 | phirotations.clear();
|
---|
283 | for(set< pair<Double_t, Int_t> >::const_iterator bin=caloBinning_.begin(); bin!=caloBinning_.end();++bin) {
|
---|
284 | if(bin->first<calo_endcap_etamin_) continue; // only in the + endcap
|
---|
285 | r[etaslice] = R*2*exp(-bin->first)/(1-exp(-2*bin->first));
|
---|
286 | nphi[etaslice] = bin->second;
|
---|
287 | Double_t phiRotationAngle = 360./nphi[etaslice];
|
---|
288 | for(int phislice=0;phislice<nphi[etaslice];++phislice) {
|
---|
289 | phirotations[make_pair(etaslice,phislice)] = new TGeoRotation(Form("forward_phi%d_%d",etaslice,phislice),phiRotationAngle*phislice,0.,0.);
|
---|
290 | phirotations[make_pair(etaslice,phislice)]->RegisterYourself();
|
---|
291 | }
|
---|
292 | ++etaslice;
|
---|
293 | }
|
---|
294 | nEtaBins = etaslice;
|
---|
295 | for(int i=0;i<nEtaBins;++i) { // loop on the eta slices
|
---|
296 | vertices[8] = -r[i+1]*sin(TMath::Pi()/20.); vertices[9] = r[i+1]*cos(TMath::Pi()/20.);
|
---|
297 | vertices[10] = -r[i]*sin(TMath::Pi()/20.); vertices[11] = r[i]*cos(TMath::Pi()/20.);
|
---|
298 | vertices[12] = r[i]*sin(TMath::Pi()/20.); vertices[13] = r[i]*cos(TMath::Pi()/20.);
|
---|
299 | vertices[14] = r[i+1]*sin(TMath::Pi()/20.); vertices[15] = r[i+1]*cos(TMath::Pi()/20.);
|
---|
300 | /*TGeoArb8 *fwdtower =*/ new TGeoArb8(Form("fwdtower%d",i),R/2., vertices); // tower in the proper eta slice, at phi=0
|
---|
301 | // intersection between the tower and the calo_endcap
|
---|
302 | TGeoCompositeShape *finalfwdtower_cs = new TGeoCompositeShape(Form("ffwdtower%d_cs",i),Form("fwdtower%d:towerdz*calo_endcap_cs",i));
|
---|
303 | TGeoVolume *finalfwdtower = new TGeoVolume(Form("ffwdtower%d",i),finalfwdtower_cs,calomed_);
|
---|
304 | finalfwdtower->SetLineColor(kViolet);
|
---|
305 | for(int j=0;j<nphi[i];++j) { // loop on the phi slices
|
---|
306 | calo_endcap->AddNode(finalfwdtower,j,phirotations[make_pair(i,j)]);
|
---|
307 | }
|
---|
308 | }
|
---|
309 | delete[] r;
|
---|
310 | delete[] nphi;
|
---|
311 | }
|
---|
312 |
|
---|
313 | void geometry(const char* filename = "delphes_card_CMS.tcl")
|
---|
314 | {
|
---|
315 | gSystem->Load("libGeom");
|
---|
316 | gSystem->Load("../libDelphes");
|
---|
317 | TGeoManager *geom = new TGeoManager("delphes", "Delphes geometry");
|
---|
318 |
|
---|
319 | // make the top container volume -> designed to contain a "big" detector (ATLAS)
|
---|
320 | TGeoVolume *top = geom->MakeBox("TOP", 0, 1500, 1500, 2300);
|
---|
321 | geom->SetTopVolume(top);
|
---|
322 |
|
---|
323 | // build the detector
|
---|
324 | Delphes3DGeometry det3D;
|
---|
325 | det3D.readFile(filename);
|
---|
326 | top->AddNode(det3D.getDetector(true),1);
|
---|
327 |
|
---|
328 | // draw it
|
---|
329 | geom->CloseGeometry();
|
---|
330 | top->Draw();
|
---|
331 | }
|
---|
332 |
|
---|