FairRoot/PandaRoot
createSTT_150.C
Go to the documentation of this file.
1 // *******************************************************************************
2 // NEW (!!!) MACRO TO PRODUCE THE GEOMETRY ASCII FILE
3 // *******************************************************************************
4 // This macro reproduces the file straws_skewed_blocks_35cm_pipe.geo (rev 13273)
5 // apart from line 26 (starting and ending phi angles of the tube segment
6 // representing the outer support cylinder).
7 // The phi values in the geo file (2.713409, 177.286591) were obtained with
8 // outerDiam = 84.4 cm. By running this macro line 26 becomes 2.785918, 177.214082
9 // *******************************************************************************
10 // if you want to reduce the tube length:
11 // - change tubeLength
12 // - change sttCenterZ
13 // - length and number of the short skewed straws is changed automatically
14 // *******************************************************************************
15 
16 #include <iostream>
17 #include <iomanip>
18 #include <fstream>
19 #include <math.h>
20 #include <string>
21 #include <sstream>
22 #include <vector>
23 
24 using namespace std;
25 
26 static int counter1;
27 static int counter2;
28 static int counter3;
29 static int counter4;
30 static int counter5;
31 static int counter6;
32 
33 //--------------------------------------------geometry definitions
34 #define outerDiam 82.2000
35 #define innerDiam 31.8000
36 #define tubeInnerDiam 1.0000
37 #define tubeOuterDiam 1.0060
38 #define tubeSeperation 1.0100
39 #define wireDiam 0.0020
40 #define tubeLength 150.0000
41 
42 #define safety 0.2000
43 
44 #define sttCenterX 0.
45 #define sttCenterY 0.
46 // tubeLength/2 - 40
47 #define sttCenterZ 35.
48 
49 #define innerCoverThickness 0.1000 // cm
50 #define outerCoverThickness 0.1000 // cm
51 
52 #define panelthickness 0.1000
53 #define pipeDiam 4.0000
54 #define noSupport 0
55 
56 #define skewangle 3.
57 
58 #define pi 3.141592653589793238512808959406186204433
59 
60 #define cave "cave"
61 #define sttassembly "stt01assembly"
62 #define innerCylinder "stt01innerCylinder"
63 #define outerCylinder "stt01outerCylinder"
64 #define panel1 "stt01box#1"
65 #define panel2 "stt01box#2"
66 #define panel3 "stt01box#3"
67 #define panel4 "stt01box#4"
68 
69 // materials
70 #define air "air"
71 #define AlBe "STTsupport"
72 #define mylar "mylar"
73 #define HeMixture "STTmix9010_2bar"
74 #define W "tungsten"
75 
76 static int tubeteller;
77 static int axialtubeteller;
78 static int skewedtubeteller;
80 static double maximumradius = 0;
81 static double minimumradius = 100000;
82 
83 // fuctions to write part of the declaration
84 void writename(char const *name, bool support = false, bool leftside = false)
85 {
86  if(support && leftside) cout << name << "#1" << endl;
87  else if(support && !leftside) cout << name << "#2" << endl;
88  else cout << name << endl;
89  counter1++;
90 }
91 
92 void writemother(char const *name, bool original = true, bool support = false)
93 {
94  cout << name << endl;
95  if (original && !support)
96  cout << "TUBE" << endl;
97  if(original && support)
98  cout << "TUBS" << endl;
99  counter2++;
100 }
101 
102 void writecylsupport(char const *name, bool firstone)
103 {
104  cout << name << endl;
105  if (firstone)
106  cout << "TUBS" << endl;
107  counter2++;
108 }
109 
110 void writemedium(char *name)
111 {
112  cout << name << endl;
113  counter3++;
114 }
115 
116 void writetube(double inner, double outer, double length)
117 {
118  cout << 0. << " " << 0. << " " << -1. * length * 10. << endl;
119  cout << inner * 10. << " " << outer * 10. << endl;
120  cout << 0. << " " << 0. << " " << length * 10. << endl;
121  counter4++;
122 }
123 
124 void writehalftube(double inner, double outer, double length)
125 {
126  cout << 0. << " " << 0. << " " << -1. * length * 10. << endl;
127  cout << inner * 10. << " " << outer * 10. << endl;
128  cout << 0. << " " << 0. << " " << length * 10. << endl;
129  cout << atan((pipeDiam/2.)/outer) * (180. / pi) << " " << 180. - atan((pipeDiam/2.)/outer) * (180. / pi) << endl;
130  counter4++;
131 }
132 
133 void writepanel(char const *name, bool firstone, double xthick, double ythick, double length, int side)
134 {
135  xthick *= 10.;
136  ythick *= 10.;
137  length *= 10.;
138 
139  if(firstone) {
140  cout << name << endl;
141  cout << sttassembly << endl;
142  cout << "BOX" << endl;
143  cout << AlBe << endl;
144  cout << xthick/2. << " " << -ythick/2. << " " << -length / 2. << endl;
145  cout << xthick/2. << " " << ythick/2. << " " << -length / 2. << endl;
146  cout << -xthick/2. << " " << ythick/2. << " " << -length / 2. << endl;
147  cout << -xthick/2. << " " << -ythick/2. << " " << -length / 2. << endl;
148  cout << xthick/2. << " " << -ythick/2. << " " << length / 2. << endl;
149  cout << xthick/2. << " " << ythick/2. << " " << length / 2. << endl;
150  cout << -xthick/2. << " " << ythick/2. << " " << length / 2. << endl;
151  cout << -xthick/2. << " " << -ythick/2. << " " << length / 2. << endl;
152  }
153  else {
154  cout << name << endl;
155  cout << sttassembly << endl;
156  }
157 
158 }
159 
160 
161 void writetrans(double x, double y, double z)
162 {
163  cout << x * 10. << " " << y * 10. << " " << z * 10. << endl;
164  counter5++;
165 }
166 
167 void writerot(double x00, double x01, double x02, double x10, double x11, double x12, double x20, double x21, double x22)
168 {
169  cout << x00 << " " << x01 << " " << x02 << " "
170  << x10 << " " << x11 << " " << x12 << " "
171  << x20 << " " << x21 << " " << x22 << endl;
172  cout << "//----------------------------------------------------------" << endl;
173  counter6++;
174 }
175 
176 // write the declaration of a complete straw
177 bool putStraw(double posX, double posY, double posZ)
178 {
179 
180  // CHECK PIPE
181  if(posX > -(pipeDiam/2. + panelthickness) && posX < (pipeDiam/2. + panelthickness)) return false;
182 
183  // check if the straws fit wihin the inner and outer diameter specified
184  if (
185  (sqrt(posX * posX + posY * posY) < ((outerDiam / 2.) - outerCoverThickness - (tubeOuterDiam / 2.))) &&
186  (sqrt(posX * posX + posY * posY) > ((innerDiam / 2.) + innerCoverThickness + (tubeOuterDiam / 2.)))
187  )
188  {
189  // convert int to string
190  stringstream
191  conv;
192 
193  string
194  tubetellerStr;
195 
196  conv << tubeteller + 1;
197  conv >> tubetellerStr;
198 
199  string
200  nameItube = "stt01tube#" + tubetellerStr,
201  nameIgas = "stt01gas#" + tubetellerStr,
202  nameIwire = "stt01wire#" + tubetellerStr;
203 
204  // keep track of minimum and maximum extend of the straw package
205  if (sqrt(posX * posX + posY * posY) - (tubeOuterDiam / 2.) < minimumradius)
206  {
207  minimumradius = sqrt(posX * posX + posY * posY) - (tubeOuterDiam / 2.);
208  }
209  if (sqrt(posX * posX + posY * posY) + (tubeOuterDiam / 2.) > maximumradius)
210  {
211  maximumradius = sqrt(posX * posX + posY * posY) + (tubeOuterDiam / 2.);
212  }
213 
214  // place the tube
215  if (tubeteller == 0)
216  {
217  // original tube
218 
219  // Mylar tubes
220  writename(nameItube.c_str());
223  writetube(0, tubeOuterDiam / 2., tubeLength / 2.);
224  writetrans(posX, posY, posZ);
225  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
226 
227  // Gas filling
228  writename(nameIgas.c_str());
229  writemother(nameItube.c_str());
231  writetube(0., tubeInnerDiam / 2., tubeLength / 2.);
232  writetrans(0., 0., 0.);
233  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
234 
235  // Anode wire
236  writename(nameIwire.c_str());
237  writemother(nameIgas.c_str());
238  writemedium(W);
239  writetube(0., wireDiam / 2., tubeLength / 2.);
240  writetrans(0., 0., 0.);
241  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
242  }
243  else
244  {
245  // copy
246  writename(nameItube.c_str());
247  writemother(sttassembly, false);
248  writetrans(posX, posY, posZ);
249  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
250  }
251  tubeteller++;
252  axialtubeteller++;
253  }
254  else
255  {
256  return false;
257  }
258 
259  return true;
260 }
261 
262 // write the rotation matrix for a right skewed straw
263 void plotrotright(double x, double y, double z)
264 {
265  double
266  newskewangle = skewangle * -1.;
267 
268  cout << 1 + (1 - cos(newskewangle * (pi / 180.))) * (x * x - 1) << " "
269  << -z * sin(newskewangle * (pi / 180.)) + (1 - cos(newskewangle * (pi / 180.))) * x * y << " "
270  << y * sin(newskewangle * (pi / 180.)) + (1 - cos(newskewangle * (pi / 180.))) * x * z << " "
271 
272  << z * sin(newskewangle * (pi / 180.)) + (1 - cos(newskewangle * (pi / 180.))) * x * y << " "
273  << 1 + (1 - cos(newskewangle * (pi / 180.))) * (y * y - 1) << " "
274  << -x * sin(newskewangle * (pi / 180.)) + (1 - cos(newskewangle * (pi / 180.))) * y * z << " "
275 
276  << -y * sin(newskewangle * (pi / 180.)) + (1 - cos(newskewangle * (pi / 180.))) * x * z << " "
277  << x * sin(newskewangle * (pi / 180.)) + (1 - cos(newskewangle * (pi / 180.))) * y * z << " "
278  << 1 + (1 - cos(newskewangle * (pi / 180.))) * (z * z - 1) << endl;
279  cout << "//----------------------------------------------------------" << endl;
280  counter6++;
281 }
282 
283 // write the rotation matrix for a left skewed straw
284 void plotrotleft(double x, double y, double z)
285 {
286  cout << 1 + (1 - cos(skewangle * (pi / 180.))) * (x * x - 1) << " "
287  << -z * sin(skewangle * (pi / 180.)) + (1 - cos(skewangle * (pi / 180.))) * x * y << " "
288  << y * sin(skewangle * (pi / 180.)) + (1 - cos(skewangle * (pi / 180.))) * x * z << " "
289 
290  << z * sin(skewangle * (pi / 180.)) + (1 - cos(skewangle * (pi / 180.))) * x * y << " "
291  << 1 + (1 - cos(skewangle * (pi / 180.))) * (y * y - 1) << " "
292  << -x * sin(skewangle * (pi / 180.)) + (1 - cos(skewangle * (pi / 180.))) * y * z << " "
293 
294  << -y * sin(skewangle * (pi / 180.)) + (1 - cos(skewangle * (pi / 180.))) * x * z << " "
295  << x * sin(skewangle * (pi / 180.)) + (1 - cos(skewangle * (pi / 180.))) * y * z << " "
296  << 1 + (1 - cos(skewangle * (pi / 180.))) * (z * z - 1) << endl;
297  cout << "//----------------------------------------------------------" << endl;
298  counter6++;
299 }
300 
301 bool putStrawRotatedShortLeft(double posX, double posY, double posZ, double xvector, double yvector, double zvector, double length)
302 {
303 
304  double extr1 = posX + (length/2.) * sin(skewangle);
305  double extr2 = posX - (length/2.) * sin(skewangle);
306 
307  if (length > 0.)
308  {
309  // convert int to string
310  stringstream
311  conv;
312 
313  string
314  tubetellerStr;
315 
316  conv << tubeteller + 1;
317  conv >> tubetellerStr;
318 
319  string
320  nameItube = "stt01tube" + tubetellerStr,
321  nameIgas = "stt01gas" + tubetellerStr,
322  nameIwire = "stt01wire" + tubetellerStr;
323 
324  // N.B. we don't use copies here since the short straws are all different in length
325 
326  // Mylar tubes
327  writename(nameItube.c_str());
330  writetube(0, tubeOuterDiam / 2., length / 2.);
331  writetrans(posX, posY, posZ);
332  plotrotleft(xvector, yvector, zvector);
333 
334  // gas filling
335  writename(nameIgas.c_str());
336  writemother(nameItube.c_str());
338  writetube(0., tubeInnerDiam / 2., length / 2.);
339  writetrans(0., 0., 0.);
340  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
341 
342  // anode wires
343  writename(nameIwire.c_str());
344  writemother(nameIgas.c_str());
345  writemedium(W);
346  writetube(0., wireDiam / 2., length / 2.);
347  writetrans(0., 0., 0.);
348  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
349 
350  tubeteller++;
352 
353 
354  return true;
355  }
356 }
357 
358 bool putStrawRotatedShortRight(double posX, double posY, double posZ, double xvector, double yvector, double zvector, double length)
359 {
360  double extr1 = posX + (length/2.) * sin(skewangle);
361  double extr2 = posX - (length/2.) * sin(skewangle);
362 
363  if (length > 0.)
364  {
365 
366 
367 
368  // convert int to string
369  stringstream
370  conv;
371 
372  string
373  tubetellerStr;
374 
375  conv << tubeteller + 1;
376  conv >> tubetellerStr;
377 
378  string
379  nameItube = "stt01tube" + tubetellerStr,
380  nameIgas = "stt01gas" + tubetellerStr,
381  nameIwire = "stt01wire" + tubetellerStr;
382 
383  // N.B. don;t use copies here since all short straws have different length
384 
385  // Mylar tubes
386  writename(nameItube.c_str());
389  writetube(0, tubeOuterDiam / 2., length / 2.);
390  writetrans(posX, posY, posZ);
391  plotrotright(xvector, yvector, zvector);
392 
393  // gas filling
394  writename(nameIgas.c_str());
395  writemother(nameItube.c_str());
397  writetube(0., tubeInnerDiam / 2., length / 2.);
398  writetrans(0., 0., 0.);
399  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
400 
401  // anode wire
402  writename(nameIwire.c_str());
403  writemother(nameIgas.c_str());
404  writemedium(W);
405  writetube(0., wireDiam / 2., length / 2.);
406  writetrans(0., 0., 0.);
407  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
408 
409  tubeteller++;
411 
412  return true;
413  }
414 }
415 
416 bool putStrawRotatedLeft(double posX, double posY, double posZ, double xvector, double yvector, double zvector, double length)
417 {
418  double extr1 = posX + (length/2.) * sin(skewangle);
419  double extr2 = posX - (length/2.) * sin(skewangle);
420 
421 
422  // convert int to string
423  stringstream
424  conv;
425 
426  string
427  tubetellerStr;
428 
429  conv << tubeteller + 1;
430  conv >> tubetellerStr;
431 
432  string
433  nameItube = "stt01tube#" + tubetellerStr,
434  nameIgas = "stt01gas#" + tubetellerStr,
435  nameIwire = "stt01wire#" + tubetellerStr;
436 
437  if (tubeteller == 0)
438  {
439  // original straw
440  // Mylar tubes
441  writename(nameItube.c_str());
444  writetube(0, tubeOuterDiam / 2., length / 2.);
445  writetrans(posX, posY, posZ);
446  plotrotleft(xvector, yvector, zvector);
447 
448  // Gas filling
449  writename(nameIgas.c_str());
450  writemother(nameItube.c_str());
452  writetube(0., tubeInnerDiam / 2., length / 2.);
453  writetrans(0., 0., 0.);
454  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
455 
456  // Anode wire
457  writename(nameIwire.c_str());
458  writemother(nameIgas.c_str());
459  writemedium(W);
460  writetube(0., wireDiam / 2., length / 2.);
461  writetrans(0., 0., 0.);
462  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
463  }
464  else
465  {
466  // copy volume
467 
468  writename(nameItube.c_str());
469  writemother(sttassembly, false);
470  writetrans(posX, posY, posZ);
471  plotrotleft(xvector, yvector, zvector);
472  }
473 
474  tubeteller++;
476 
477  return true;
478 }
479 
480 bool putStrawRotatedRight(double posX, double posY, double posZ, double xvector, double yvector, double zvector, double length)
481 {
482 
483 
484  double extr1 = posX + (length/2.) * sin(skewangle);
485  double extr2 = posX - (length/2.) * sin(skewangle);
486 
487 
488  // convert int to string
489  stringstream
490  conv;
491 
492  string
493  tubetellerStr;
494 
495  conv << tubeteller + 1;
496  conv >> tubetellerStr;
497 
498  string
499  nameItube = "stt01tube#" + tubetellerStr,
500  nameIgas = "stt01gas#" + tubetellerStr,
501  nameIwire = "stt01wire#" + tubetellerStr;
502 
503  if (tubeteller == 0)
504  {
505  // original volume
506 
507  // Mylar tubes
508  writename(nameItube.c_str());
511  writetube(0, tubeOuterDiam / 2., length / 2.);
512  writetrans(posX, posY, posZ);
513  plotrotright(xvector, yvector, zvector);
514 
515  // gas filling
516  writename(nameIgas.c_str());
517  writemother(nameItube.c_str());
519  writetube(0., tubeInnerDiam / 2., length / 2.);
520  writetrans(0., 0., 0.);
521  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
522 
523  // anode wire
524  writename(nameIwire.c_str());
525  writemother(nameIgas.c_str());
526  writemedium(W);
527  writetube(0., wireDiam / 2., length / 2.);
528  writetrans(0., 0., 0.);
529  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
530  }
531  else
532  {
533  // copy volume
534  writename(nameItube.c_str());
535  writemother(sttassembly, false);
536  writetrans(posX, posY, posZ);
537  plotrotright(xvector, yvector, zvector);
538  }
539 
540  tubeteller++;
542 
543  return true;
544 }
545 
546 
547 
548 void placeSingleLayerStraightExact(double ringteller)
549 {
550  double
551  radius = tubeSeperation / 2.;
552 
553  // place a straight double layer
554  double
555  xpos = 0.,
556  ypos = ((ringteller) * 2 * radius),
557  zpos = 0.;
558 
559  // 6 loops, one for each side of the hexagon
560  // 1 / \ 4
561  // 2 | | 5
562  // 3 \ / 6
563  for(int i = 0; i < ringteller; i++)
564  {
565  xpos -= sqrt(3.) * radius;
566  ypos -= radius;
567  putStraw(xpos, ypos, zpos);
568  }
569  for(int i = 0; i < ringteller; i++)
570  {
571  ypos -= 2 * radius;
572  putStraw(xpos, ypos, zpos);
573  }
574  for(int i = 0; i < ringteller; i++)
575  {
576  xpos += sqrt(3.) * radius;
577  ypos -= radius;
578  putStraw(xpos, ypos, zpos);
579  }
580  for(int i = 0; i < ringteller; i++)
581  {
582  xpos += sqrt(3.) * radius;
583  ypos += radius;
584  putStraw(xpos, ypos, zpos);
585  }
586  for(int i = 0; i < ringteller; i++)
587  {
588  ypos += 2 * radius;
589  putStraw(xpos, ypos, zpos);
590  }
591  for(int i = 0; i < ringteller; i++)
592  {
593  xpos -= sqrt(3.) * radius;
594  ypos += radius;
595  putStraw(xpos, ypos, zpos);
596  }
597 }
598 
599 void placeSingleLayerSkewedRight(double ringposition)
600 {
601  // see void placeSingleLayerSkewedLeft(double ringposition)
602 
603  double radius = tubeSeperation / 2.;
604 
605  double
606  newskewangle = skewangle * -1.;
607 
608  double
609  newradius = radius / cos((newskewangle / 180.) * pi);
610 
611  double
612  xpos = 0.,
613  ypos = ringposition / cos((30. / 180.) * pi),
614  zpos = 0.,
615  tmpxpos,
616  tmpypos,
617  vectorx,
618  vectory,
619  vectorz;
620 
621  double
622  availableSpace = 2. * ringposition * tan((30. / 180.) * pi);
623 
624  int
625  possibleStraws = int((availableSpace - fabs(tubeLength * sin((newskewangle / 180.) * pi))) / (newradius * 2)),
626  extraStraws = -1 * possibleStraws + int(availableSpace / (newradius * 2));
627 
628  double
629  extraspace = (availableSpace - (possibleStraws + extraStraws) * (newradius * 2)) / 2.;
630 
631  cerr << "extra space: " << extraspace * 2 << endl;
632 
633  double
634  skewanglerad = (newskewangle / 180.) * pi,
635  sixtyrad = (60. / 180.) * pi,
636  translationToLeft = - 0.5 * tubeLength * tan(skewanglerad);
637 
638 
639  vector<double>
640  lengthsShort;
641 
642  double
643  xpos2 = xpos - availableSpace * sin((60. / 180.) * pi),
644  ypos2 = ypos - availableSpace * cos((60. / 180.) * pi),
645  tmpxpos2 = xpos2,
646  tmpypos2 = ypos2 - extraspace - newradius,
647  limit = ypos2 - availableSpace + newradius + safety;
648 
649  for(int i = 0; i < possibleStraws; i++)
650  {
651  tmpypos2 -= 2 * newradius;
652  }
653 
654  for (int i = 0; i < extraStraws; i++)
655  {
656  double
657  lengthShort = (tmpypos2 - limit) / sin(newskewangle * (pi / 180.));
658 
659  if (lengthShort > tubeLength)
660  lengthShort = tubeLength;
661 
662  // cerr << "length: " << lengthShort << endl;
663  lengthsShort.push_back(fabs(lengthShort));
664 
665  tmpypos2 -= 2 * newradius;
666  }
667 
668 
669  double
670  additionalShift = fabs(tubeLength * sin((newskewangle / 180.) * pi));
671 
672  // =================================================
673  // planes intersecting pipe ========================
674  // pipe
675  double pipespace = (panelthickness + pipeDiam/2.) * 1./(sqrt(3)/2.);
676 
677  // the available space for a layer at the radius ringposition
678  double
679  availableSpacePipe = 2. * ringposition * tan((30. / 180.) * pi) - pipespace;
680 
681  // the number of skewed full-length straws that fit in the available space
682  int
683  possibleStrawsPipe = int((availableSpacePipe - fabs(tubeLength * sin((skewangle / 180.) * pi))) / (newradius * 2));
684 
685  // the number of short straws that fit on either side of the pack of full-length straws
686  int
687  extraStrawsPipe = -1 * possibleStrawsPipe + int(availableSpacePipe / (newradius * 2));
688  // the amount of space that is left in the layer when considering the sum of all
689  // full length and short straws together
690  double
691  extraspacePipe = (availableSpacePipe - (possibleStrawsPipe + extraStrawsPipe) * (newradius * 2)) / 2.;
692 
693  // cerr << "layer with pipe " << possibleStraws << " " << extraStraws << endl;
694 
695  // calculate the lenghts of the different short straws in this layer
696  vector<double>
697  lengthsShortPipe;
698 
699  double
700  // start at the right edge of the layer
701  xpos2Pipe = xpos - availableSpacePipe * sin((60. / 180.) * pi),
702  ypos2Pipe = ypos - availableSpacePipe * cos((60. / 180.) * pi),
703  // shift to the center of the rightmost straw
704  tmpxpos2Pipe = xpos2Pipe,
705  tmpypos2Pipe = ypos2Pipe - extraspacePipe - newradius,
706  // the limit on the left side of the plane beyond which no center of the short straws may be
707  limitPipe = ypos2Pipe - availableSpacePipe + newradius + safety;
708 
709 
710  // shift to the center of of the leftmost full-length straw
711  for(int i = 0; i < possibleStrawsPipe; i++)
712  {
713  tmpypos2Pipe -= 2 * newradius;
714  }
715 
716  // calculate the maximum allowable length for this short straw and shift to the next
717  for (int i = 0; i < extraStrawsPipe; i++)
718  {
719  double
720  lengthShort = (tmpypos2Pipe - limitPipe) / sin(skewangle * (pi / 180.));
721 
722  if (lengthShort > tubeLength)
723  lengthShort = tubeLength;
724  lengthsShortPipe.push_back(lengthShort);
725  tmpypos2Pipe -= 2 * newradius;
726  }
727  // =================================================
728 
729  // plane 1
730  vectorx = -cos((60. / 180.) * pi);
731  vectory = sin((60. / 180.) * pi);
732  vectorz = 0;
733  tmpxpos = xpos - (extraspacePipe + newradius + pipespace) * sin((60. / 180.) * pi);
734  tmpypos = ypos - (extraspacePipe + newradius + pipespace) * cos((60. / 180.) * pi);
735 
736  for(int i = 0; i < possibleStrawsPipe; i++)
737  {
738 
739  putStrawRotatedRight(tmpxpos + (translationToLeft - additionalShift) * sin(sixtyrad),
740  tmpypos + (translationToLeft - additionalShift) * cos(sixtyrad),
741  zpos, vectorx, vectory, vectorz, tubeLength);
742 
743  tmpxpos -= 2 * newradius * sin((60. / 180.) * pi);
744  tmpypos -= 2 * newradius * cos((60. / 180.) * pi);
745  }
746 
747  for (int i = 0; i < extraStrawsPipe; i++)
748  {
749  double
750  lengthShort = lengthsShortPipe[i];
751 
752  double
753  translationToFrontPar = ((tubeLength - lengthShort) / 2.) * cos(skewanglerad),
754  translationToFrontPer = ((tubeLength - lengthShort) / 2.) * sin(skewanglerad),
755  switchSides = 2 * newradius * (possibleStrawsPipe + 1 + (2 * i)) * cos(skewanglerad);
756 
757  putStrawRotatedShortRight(tmpxpos + (translationToLeft - additionalShift - translationToFrontPer) * sin(sixtyrad),
758  tmpypos + (translationToLeft - additionalShift - translationToFrontPer) * cos(sixtyrad),
759  zpos - translationToFrontPar,
760  vectorx, vectory, vectorz, lengthShort);
761 
762  putStrawRotatedShortRight(tmpxpos + (translationToLeft - additionalShift + translationToFrontPer + switchSides) * sin(sixtyrad),
763  tmpypos + (translationToLeft - additionalShift + translationToFrontPer + switchSides) * cos(sixtyrad),
764  zpos + translationToFrontPar,
765  vectorx, vectory, vectorz, lengthShort);
766 
767 
768  tmpxpos -= 2 * newradius * sin((60. / 180.) * pi);
769  tmpypos -= 2 * newradius * cos((60. / 180.) * pi);
770  }
771 
772 
773  // plane 2
774  vectorx = -1.;
775  vectory = 0.;
776  vectorz = 0.;
777  xpos -= availableSpace * sin((60. / 180.) * pi);
778  ypos -= availableSpace * cos((60. / 180.) * pi);
779  tmpxpos = xpos;
780  tmpypos = ypos - extraspace - newradius;
781 
782  for(int i = 0; i < possibleStraws; i++)
783  {
784  putStrawRotatedRight(tmpxpos, tmpypos - additionalShift + translationToLeft, zpos, vectorx, vectory, vectorz, tubeLength);
785  tmpypos -= 2 * newradius;
786  }
787 
788  for (int i = 0; i < extraStraws; i++)
789  {
790  double
791  lengthShort = lengthsShort[i];
792 
793  double
794  translationToFrontPar = ((tubeLength - lengthShort) / 2.) * cos(skewanglerad),
795  translationToFrontPer = ((tubeLength - lengthShort) / 2.) * sin(skewanglerad),
796  switchSides = 2 * newradius * (possibleStraws + 1 + (2 * i)) * cos(skewanglerad);
797 
798  putStrawRotatedShortRight(tmpxpos,
799  tmpypos - additionalShift + (translationToLeft - translationToFrontPer),
800  zpos - translationToFrontPar,
801  vectorx, vectory, vectorz, lengthShort);
802 
803  putStrawRotatedShortRight(tmpxpos,
804  tmpypos - additionalShift + (translationToLeft + translationToFrontPer + switchSides),
805  zpos + translationToFrontPar,
806  vectorx, vectory, vectorz, lengthShort);
807 
808  tmpypos -= 2 * newradius;
809  }
810 
811  // plane 3
812  vectorx = -1 * cos((60. / 180.) * pi);
813  vectory = -1 * sin((60. / 180.) * pi);
814  vectorz = 0;
815  ypos -= availableSpace;
816  tmpxpos = xpos + (extraspacePipe + newradius) * sin((60. / 180.) * pi);
817  tmpypos = ypos - (extraspacePipe + newradius) * cos((60. / 180.) * pi);
818 
819  for(int i = 0; i < possibleStrawsPipe; i++)
820  {
821 
822  putStrawRotatedRight(tmpxpos - (translationToLeft - additionalShift) * sin(sixtyrad),
823  tmpypos + (translationToLeft - additionalShift) * cos(sixtyrad),
824  zpos, vectorx, vectory, vectorz, tubeLength);
825 
826  tmpxpos += 2 * newradius * sin((60. / 180.) * pi);
827  tmpypos -= 2 * newradius * cos((60. / 180.) * pi);
828  }
829 
830  for (int i = 0; i < extraStrawsPipe; i++)
831  {
832  double
833  lengthShort = lengthsShortPipe[i];
834 
835  double
836  translationToFrontPar = ((tubeLength - lengthShort) / 2.) * cos(skewanglerad),
837  translationToFrontPer = ((tubeLength - lengthShort) / 2.) * sin(skewanglerad),
838  switchSides = 2 * newradius * (possibleStrawsPipe + 1 + (2 * i)) * cos(skewanglerad);
839 
840  putStrawRotatedShortRight(tmpxpos - (translationToLeft - translationToFrontPer - additionalShift) * sin(sixtyrad),
841  tmpypos + (translationToLeft - translationToFrontPer - additionalShift) * cos(sixtyrad),
842  zpos - translationToFrontPar,
843  vectorx, vectory, vectorz, lengthShort);
844 
845  putStrawRotatedShortRight(tmpxpos - (translationToLeft + translationToFrontPer - additionalShift + switchSides) * sin(sixtyrad),
846  tmpypos + (translationToLeft + translationToFrontPer - additionalShift + switchSides) * cos(sixtyrad),
847  zpos + translationToFrontPar,
848  vectorx, vectory, vectorz, lengthShort);
849 
850  tmpxpos += 2 * newradius * sin((60. / 180.) * pi);
851  tmpypos -= 2 * newradius * cos((60. / 180.) * pi);
852  }
853 
854  // plane 4
855  vectorx = 1 * cos((60. / 180.) * pi);
856  vectory = -1 * sin((60. / 180.) * pi);
857  vectorz = 0;
858  xpos += availableSpace * sin((60. / 180.) * pi);
859  ypos -= availableSpace * cos((60. / 180.) * pi);
860  tmpxpos = xpos + (extraspacePipe + newradius + pipespace) * sin((60. / 180.) * pi);
861  tmpypos = ypos + (extraspacePipe + newradius + pipespace) * cos((60. / 180.) * pi);
862 
863  for(int i = 0; i < possibleStrawsPipe; i++)
864  {
865 
866  putStrawRotatedRight(tmpxpos - (translationToLeft - additionalShift) * sin(sixtyrad),
867  tmpypos - (translationToLeft - additionalShift) * cos(sixtyrad),
868  zpos, vectorx, vectory, vectorz, tubeLength);
869 
870  tmpxpos += 2 * newradius * sin((60. / 180.) * pi);
871  tmpypos += 2 * newradius * cos((60. / 180.) * pi);
872  }
873 
874  for (int i = 0; i < extraStrawsPipe; i++)
875  {
876  double
877  lengthShort = lengthsShortPipe[i];
878 
879  double
880  translationToFrontPar = ((tubeLength - lengthShort) / 2.) * cos(skewanglerad),
881  translationToFrontPer = ((tubeLength - lengthShort) / 2.) * sin(skewanglerad),
882  switchSides = 2 * newradius * (possibleStrawsPipe + 1 + (2 * i)) * cos(skewanglerad);
883 
884  putStrawRotatedShortRight(tmpxpos - (translationToLeft - additionalShift - translationToFrontPer) * sin(sixtyrad),
885  tmpypos - (translationToLeft - additionalShift - translationToFrontPer) * cos(sixtyrad),
886  zpos - translationToFrontPar,
887  vectorx, vectory, vectorz, lengthShort);
888 
889  putStrawRotatedShortRight(tmpxpos - (translationToLeft - additionalShift + translationToFrontPer + switchSides) * sin(sixtyrad),
890  tmpypos - (translationToLeft - additionalShift + translationToFrontPer + switchSides) * cos(sixtyrad),
891  zpos + translationToFrontPar,
892  vectorx, vectory, vectorz, lengthShort);
893 
894  tmpxpos += 2 * newradius * sin((60. / 180.) * pi);
895  tmpypos += 2 * newradius * cos((60. / 180.) * pi);
896  }
897 
898  // plane 5
899  vectorx = 1.;
900  vectory = 0.;
901  vectorz = 0.;
902  xpos += availableSpace * sin((60. / 180.) * pi);
903  ypos += availableSpace * cos((60. / 180.) * pi);
904  tmpxpos = xpos;
905  tmpypos = ypos + extraspace + newradius;
906 
907  for(int i = 0; i < possibleStraws; i++)
908  {
909  putStrawRotatedRight(tmpxpos, tmpypos - (translationToLeft - additionalShift), zpos, vectorx, vectory, vectorz, tubeLength);
910  tmpypos += 2 * newradius;
911  }
912 
913  for (int i = 0; i < extraStraws; i++)
914  {
915  double
916  lengthShort = lengthsShort[i];
917 
918  double
919  translationToFrontPar = ((tubeLength - lengthShort) / 2.) * cos(skewanglerad),
920  translationToFrontPer = ((tubeLength - lengthShort) / 2.) * sin(skewanglerad),
921  switchSides = 2 * newradius * (possibleStraws + 1 + (2 * i)) * cos(skewanglerad);
922 
923  putStrawRotatedShortRight(tmpxpos, tmpypos - (translationToLeft - additionalShift - translationToFrontPer),
924  zpos - translationToFrontPar,
925  vectorx, vectory, vectorz, lengthShort);
926 
927  putStrawRotatedShortRight(tmpxpos, tmpypos - (translationToLeft - additionalShift + translationToFrontPer + switchSides),
928  zpos + translationToFrontPar,
929  vectorx, vectory, vectorz, lengthShort);
930 
931  tmpypos += 2 * newradius;
932  }
933 
934  // plane 6
935  vectorx = cos((60. / 180.) * pi);
936  vectory = sin((60. / 180.) * pi);
937  vectorz = 0;
938  ypos += availableSpace;
939  tmpxpos = xpos - (extraspacePipe + newradius) * sin((60. / 180.) * pi);
940  tmpypos = ypos + (extraspacePipe + newradius) * cos((60. / 180.) * pi);
941 
942  for(int i = 0; i < possibleStrawsPipe; i++)
943  {
944 
945  putStrawRotatedRight(tmpxpos + (translationToLeft - additionalShift) * sin(sixtyrad),
946  tmpypos - (translationToLeft - additionalShift) * cos(sixtyrad),
947  zpos, vectorx, vectory, vectorz, tubeLength);
948 
949  tmpxpos -= 2 * newradius * sin((60. / 180.) * pi);
950  tmpypos += 2 * newradius * cos((60. / 180.) * pi);
951  }
952 
953  for (int i = 0; i < extraStrawsPipe; i++)
954  {
955  double
956  lengthShort = lengthsShortPipe[i];
957 
958  double
959  translationToFrontPar = ((tubeLength - lengthShort) / 2.) * cos(skewanglerad),
960  translationToFrontPer = ((tubeLength - lengthShort) / 2.) * sin(skewanglerad),
961  switchSides = 2 * newradius * (possibleStrawsPipe + 1 + (2 * i)) * cos(skewanglerad);
962 
963  putStrawRotatedShortRight(tmpxpos + (translationToLeft - additionalShift - translationToFrontPer) * sin(sixtyrad),
964  tmpypos - (translationToLeft - additionalShift - translationToFrontPer) * cos(sixtyrad),
965  zpos - translationToFrontPar,
966  vectorx, vectory, vectorz, lengthShort);
967 
968  putStrawRotatedShortRight(tmpxpos + (translationToLeft - additionalShift + translationToFrontPer + switchSides) * sin(sixtyrad),
969  tmpypos - (translationToLeft - additionalShift + translationToFrontPer + switchSides) * cos(sixtyrad),
970  zpos + translationToFrontPar,
971  vectorx, vectory, vectorz, lengthShort);
972 
973  tmpxpos -= 2 * newradius * sin((60. / 180.) * pi);
974  tmpypos += 2 * newradius * cos((60. / 180.) * pi);
975  }
976 
977 }
978 
979 
980 
981 
982 void placeSingleLayerSkewedLeft(double ringposition)
983 {
984  // calculation of some general properties of the layer layout
985  // see layerfront.ps and layertop.ps if description is not clear
986 
987  // skewed straws become ellipses in the x-y projection
988  // the short ellipse radius is still the straw radius, the
989  // long ellipse radius (within the straw plane) is given by:
990 
991  double
992  radius = tubeSeperation / 2.;
993 
994  double
995  newradius = radius / cos((skewangle / 180.) * pi);
996 
997 
998  double
999  xpos = 0.,
1000  ypos = ringposition / cos((30. / 180.) * pi),
1001  zpos = 0.,
1002  tmpxpos,
1003  tmpypos,
1004  vectorx,
1005  vectory,
1006  vectorz;
1007 
1008 
1009  // the available space for a layer at the radius ringposition
1010  double
1011  availableSpace = 2. * ringposition * tan((30. / 180.) * pi);
1012 
1013  // the number of skewed full-length straws that fit in the available space
1014  int
1015  possibleStraws = int((availableSpace - tubeLength * sin((skewangle / 180.) * pi)) / (newradius * 2));
1016 
1017  // the number of short straws that fit on either side of the pack of full-length straws
1018  int
1019  extraStraws = int(availableSpace / (newradius * 2)) - possibleStraws;
1020 
1021  // the amount of space that is left in the layer when considering the sum of all
1022  // full length and short straws together
1023  double
1024  extraspace = (availableSpace - (possibleStraws + extraStraws) * (newradius * 2)) / 2.;
1025 
1026  // cerr << possibleStraws << " " << extraStraws << endl;
1027 
1028  double
1029  skewanglerad = (skewangle / 180.) * pi,
1030  sixtyrad = (60. / 180.) * pi,
1031  // translation between the front end of the straw and the center
1032  translationToLeft = - 0.5 * tubeLength * tan(skewanglerad);
1033 
1034  // calculate the lenghts of the different short straws in this layer
1035  vector<double>
1036  lengthsShort;
1037 
1038  double
1039  // start at the right edge of the layer
1040  xpos2 = xpos - availableSpace * sin((60. / 180.) * pi),
1041  ypos2 = ypos - availableSpace * cos((60. / 180.) * pi),
1042  // shift to the center of the rightmost straw
1043  tmpxpos2 = xpos2,
1044  tmpypos2 = ypos2 - extraspace - newradius,
1045  // the limit on the left side of the plane beyond which no center of the short straws may be
1046  limit = ypos2 - availableSpace + newradius + safety;
1047 
1048  // cerr << "xpos2/ypos2 " << xpos2 << " " << ypos2 << endl;
1049  // cerr << "tmpxpos2/tmpypos2 " << tmpxpos2 << " " << tmpypos2 << endl;
1050 
1051 
1052  // shift to the center of of the leftmost full-length straw
1053  for(int i = 0; i < possibleStraws; i++)
1054  {
1055  tmpypos2 -= 2 * newradius;
1056  }
1057 
1058  // calculate the maximum allowable length for this short straw and shift to the next
1059  for (int i = 0; i < extraStraws; i++)
1060  {
1061  double
1062  lengthShort = (tmpypos2 - limit) / sin(skewangle * (pi / 180.));
1063 
1064  if (lengthShort > tubeLength)
1065  lengthShort = tubeLength;
1066 
1067  // cerr << "length: " << lengthShort << endl;
1068  lengthsShort.push_back(lengthShort);
1069 
1070  tmpypos2 -= 2 * newradius;
1071  }
1072  // =================================================
1073  // planes intersecting pipe ========================
1074  // pipe
1075  double pipespace = (panelthickness + pipeDiam/2.) * 1./(sqrt(3)/2.);
1076 
1077  // the available space for a layer at the radius ringposition
1078  double
1079  availableSpacePipe = 2. * ringposition * tan((30. / 180.) * pi) - pipespace;
1080 
1081  // the number of skewed full-length straws that fit in the available space
1082  int
1083  possibleStrawsPipe = int((availableSpacePipe - tubeLength * sin((skewangle / 180.) * pi)) / (newradius * 2));
1084 
1085  // the number of short straws that fit on either side of the pack of full-length straws
1086  int
1087  extraStrawsPipe = int(availableSpacePipe / (newradius * 2)) - possibleStrawsPipe;
1088 
1089  // the amount of space that is left in the layer when considering the sum of all
1090  // full length and short straws together
1091  double
1092  extraspacePipe = (availableSpacePipe - (possibleStrawsPipe + extraStrawsPipe) * (newradius * 2)) / 2.;
1093 
1094  // cerr << "layer with pipe " << possibleStraws << " " << extraStraws << endl;
1095 
1096  // calculate the lenghts of the different short straws in this layer
1097  vector<double>
1098  lengthsShortPipe;
1099 
1100  double
1101  // start at the right edge of the layer
1102  xpos2Pipe = xpos - availableSpacePipe * sin((60. / 180.) * pi),
1103  ypos2Pipe = ypos - availableSpacePipe * cos((60. / 180.) * pi),
1104  // shift to the center of the rightmost straw
1105  tmpxpos2Pipe = xpos2Pipe,
1106  tmpypos2Pipe = ypos2Pipe - extraspacePipe - newradius,
1107  // the limit on the left side of the plane beyond which no center of the short straws may be
1108  limitPipe = ypos2Pipe - availableSpacePipe + newradius + safety;
1109 
1110  // shift to the center of of the leftmost full-length straw
1111  for(int i = 0; i < possibleStrawsPipe; i++)
1112  {
1113  tmpypos2Pipe -= 2 * newradius;
1114  }
1115 
1116  // calculate the maximum allowable length for this short straw and shift to the next
1117  for (int i = 0; i < extraStrawsPipe; i++)
1118  {
1119  double
1120  lengthShort = (tmpypos2Pipe - limitPipe) / sin(skewangle * (pi / 180.));
1121 
1122  if (lengthShort > tubeLength)
1123  lengthShort = tubeLength;
1124 
1125  lengthsShortPipe.push_back(lengthShort);
1126 
1127  tmpypos2Pipe -= 2 * newradius;
1128  }
1129  // =================================================
1130  // plane 1
1131  // place full straws:
1132  vectorx = -cos((60. / 180.) * pi);
1133  vectory = sin((60. / 180.) * pi);
1134  vectorz = 0;
1135  tmpxpos = xpos - (extraspacePipe + newradius + pipespace) * sin((60. / 180.) * pi);
1136  tmpypos = ypos - (extraspacePipe + newradius + pipespace) * cos((60. / 180.) * pi);
1137 
1138  for(int i = 0; i < possibleStrawsPipe; i++)
1139  {
1140  // place a straw
1141  putStrawRotatedLeft(tmpxpos + translationToLeft * sin(sixtyrad),
1142  tmpypos + translationToLeft * cos(sixtyrad),
1143  zpos, vectorx, vectory, vectorz, tubeLength);
1144 
1145  tmpxpos -= 2 * newradius * sin((60. / 180.) * pi);
1146  tmpypos -= 2 * newradius * cos((60. / 180.) * pi);
1147  }
1148 
1149  for (int i = 0; i < extraStrawsPipe; i++)
1150  {
1151  double
1152  lengthShort = lengthsShortPipe[i];
1153 
1154  double
1155  translationToFrontPar = ((tubeLength - lengthShort) / 2.) * cos(skewanglerad),
1156  translationToFrontPer = ((tubeLength - lengthShort) / 2.) * sin(skewanglerad),
1157  // translation to the other side of the straw layer
1158  switchSides = 2 * newradius * (possibleStrawsPipe + 1 + (2 * i)) * cos(skewanglerad);
1159 
1160 
1161  putStrawRotatedShortLeft(tmpxpos + (translationToLeft + translationToFrontPer) * sin(sixtyrad),
1162  tmpypos + (translationToLeft + translationToFrontPer) * cos(sixtyrad),
1163  zpos + translationToFrontPar,
1164  vectorx, vectory, vectorz, lengthShort);
1165 
1166  putStrawRotatedShortLeft(tmpxpos + (translationToLeft - translationToFrontPer + switchSides) * sin(sixtyrad),
1167  tmpypos + (translationToLeft - translationToFrontPer + switchSides) * cos(sixtyrad),
1168  zpos - translationToFrontPar,
1169  vectorx, vectory, vectorz, lengthShort);
1170 
1171 
1172  tmpxpos -= 2 * newradius * sin((60. / 180.) * pi);
1173  tmpypos -= 2 * newradius * cos((60. / 180.) * pi);
1174  }
1175 
1176  // plane 2
1177  vectorx = -1.;
1178  vectory = 0.;
1179  vectorz = 0.;
1180  xpos -= availableSpace * sin((60. / 180.) * pi);
1181  ypos -= availableSpace * cos((60. / 180.) * pi);
1182  tmpxpos = xpos;
1183  tmpypos = ypos - extraspace - newradius;
1184 
1185  for(int i = 0; i < possibleStraws; i++)
1186  {
1187  putStrawRotatedLeft(tmpxpos, tmpypos + translationToLeft, zpos, vectorx, vectory, vectorz, tubeLength);
1188  tmpypos -= 2 * newradius;
1189  }
1190 
1191  for (int i = 0; i < extraStraws; i++)
1192  {
1193  double
1194  lengthShort = lengthsShort[i];
1195 
1196  double
1197  translationToFrontPar = ((tubeLength - lengthShort) / 2.) * cos(skewanglerad),
1198  translationToFrontPer = ((tubeLength - lengthShort) / 2.) * sin(skewanglerad),
1199  switchSides = 2 * newradius * (possibleStraws + 1 + (2 * i)) * cos(skewanglerad);
1200 
1201  putStrawRotatedShortLeft(tmpxpos,
1202  tmpypos + (translationToLeft + translationToFrontPer),
1203  zpos + translationToFrontPar,
1204  vectorx, vectory, vectorz, lengthShort);
1205 
1206  putStrawRotatedShortLeft(tmpxpos,
1207  tmpypos + (translationToLeft - translationToFrontPer + switchSides),
1208  zpos - translationToFrontPar,
1209  vectorx, vectory, vectorz, lengthShort);
1210 
1211  tmpypos -= 2 * newradius;
1212  }
1213 
1214  // plane 3
1215  vectorx = -1 * cos((60. / 180.) * pi);
1216  vectory = -1 * sin((60. / 180.) * pi);
1217  vectorz = 0;
1218  ypos -= availableSpace;
1219  tmpxpos = xpos + (extraspacePipe + newradius) * sin((60. / 180.) * pi);
1220  tmpypos = ypos - (extraspacePipe + newradius) * cos((60. / 180.) * pi);
1221 
1222  for(int i = 0; i < possibleStrawsPipe; i++)
1223  {
1224 
1225  putStrawRotatedLeft(tmpxpos - translationToLeft * sin(sixtyrad),
1226  tmpypos + translationToLeft * cos(sixtyrad),
1227  zpos, vectorx, vectory, vectorz, tubeLength);
1228 
1229  tmpxpos += 2 * newradius * sin((60. / 180.) * pi);
1230  tmpypos -= 2 * newradius * cos((60. / 180.) * pi);
1231  }
1232 
1233  for (int i = 0; i < extraStrawsPipe; i++)
1234  {
1235  double
1236  lengthShort = lengthsShortPipe[i];
1237 
1238  double
1239  translationToFrontPar = ((tubeLength - lengthShort) / 2.) * cos(skewanglerad),
1240  translationToFrontPer = ((tubeLength - lengthShort) / 2.) * sin(skewanglerad),
1241  switchSides = 2 * newradius * (possibleStrawsPipe + 1 + (2 * i)) * cos(skewanglerad);
1242 
1243  putStrawRotatedShortLeft(tmpxpos - (translationToLeft + translationToFrontPer) * sin(sixtyrad),
1244  tmpypos + (translationToLeft + translationToFrontPer) * cos(sixtyrad),
1245  zpos + translationToFrontPar,
1246  vectorx, vectory, vectorz, lengthShort);
1247 
1248  putStrawRotatedShortLeft(tmpxpos - (translationToLeft - translationToFrontPer + switchSides) * sin(sixtyrad),
1249  tmpypos + (translationToLeft - translationToFrontPer + switchSides) * cos(sixtyrad),
1250  zpos - translationToFrontPar,
1251  vectorx, vectory, vectorz, lengthShort);
1252 
1253  tmpxpos += 2 * newradius * sin((60. / 180.) * pi);
1254  tmpypos -= 2 * newradius * cos((60. / 180.) * pi);
1255  }
1256 
1257  // plane 4
1258  vectorx = 1 * cos((60. / 180.) * pi);
1259  vectory = -1 * sin((60. / 180.) * pi);
1260  vectorz = 0;
1261  xpos += availableSpace * sin((60. / 180.) * pi);
1262  ypos -= availableSpace * cos((60. / 180.) * pi);
1263  tmpxpos = xpos + (extraspacePipe + newradius + pipespace) * sin((60. / 180.) * pi);
1264  tmpypos = ypos + (extraspacePipe + newradius + pipespace) * cos((60. / 180.) * pi);
1265 
1266  for(int i = 0; i < possibleStrawsPipe; i++)
1267  {
1268 
1269  putStrawRotatedLeft(tmpxpos - translationToLeft * sin(sixtyrad),
1270  tmpypos - translationToLeft * cos(sixtyrad),
1271  zpos, vectorx, vectory, vectorz, tubeLength);
1272 
1273  tmpxpos += 2 * newradius * sin((60. / 180.) * pi);
1274  tmpypos += 2 * newradius * cos((60. / 180.) * pi);
1275  }
1276 
1277  for (int i = 0; i < extraStrawsPipe; i++)
1278  {
1279  double
1280  lengthShort = lengthsShortPipe[i];
1281 
1282  double
1283  translationToFrontPar = ((tubeLength - lengthShort) / 2.) * cos(skewanglerad),
1284  translationToFrontPer = ((tubeLength - lengthShort) / 2.) * sin(skewanglerad),
1285  switchSides = 2 * newradius * (possibleStrawsPipe + 1 + (2 * i)) * cos(skewanglerad);
1286 
1287 
1288  putStrawRotatedShortLeft(tmpxpos - (translationToLeft + translationToFrontPer) * sin(sixtyrad),
1289  tmpypos - (translationToLeft + translationToFrontPer) * cos(sixtyrad),
1290  zpos + translationToFrontPar,
1291  vectorx, vectory, vectorz, lengthShort);
1292 
1293  putStrawRotatedShortLeft(tmpxpos - (translationToLeft - translationToFrontPer + switchSides) * sin(sixtyrad),
1294  tmpypos - (translationToLeft - translationToFrontPer + switchSides) * cos(sixtyrad),
1295  zpos - translationToFrontPar,
1296  vectorx, vectory, vectorz, lengthShort);
1297 
1298  tmpxpos += 2 * newradius * sin((60. / 180.) * pi);
1299  tmpypos += 2 * newradius * cos((60. / 180.) * pi);
1300  }
1301 
1302  // plane 5
1303  vectorx = 1.;
1304  vectory = 0.;
1305  vectorz = 0.;
1306  xpos += availableSpace * sin((60. / 180.) * pi);
1307  ypos += availableSpace * cos((60. / 180.) * pi);
1308  tmpxpos = xpos;
1309  tmpypos = ypos + extraspace + newradius;
1310 
1311  for(int i = 0; i < possibleStraws; i++)
1312  {
1313 
1314  putStrawRotatedLeft(tmpxpos, tmpypos - translationToLeft, zpos, vectorx, vectory, vectorz, tubeLength);
1315 
1316  tmpypos += 2 * newradius;
1317  }
1318 
1319  for (int i = 0; i < extraStraws; i++)
1320  {
1321  double
1322  lengthShort = lengthsShort[i];
1323 
1324  double
1325  translationToFrontPar = ((tubeLength - lengthShort) / 2.) * cos(skewanglerad),
1326  translationToFrontPer = ((tubeLength - lengthShort) / 2.) * sin(skewanglerad),
1327  switchSides = 2 * newradius * (possibleStraws + 1 + (2 * i)) * cos(skewanglerad);
1328 
1329  putStrawRotatedShortLeft(tmpxpos,
1330  tmpypos - (translationToLeft + translationToFrontPer),
1331  zpos + translationToFrontPar,
1332  vectorx, vectory, vectorz, lengthShort);
1333 
1334  putStrawRotatedShortLeft(tmpxpos,
1335  tmpypos - (translationToLeft - translationToFrontPer + switchSides),
1336  zpos - translationToFrontPar,
1337  vectorx, vectory, vectorz, lengthShort);
1338 
1339  tmpypos += 2 * newradius;
1340  }
1341 
1342  // plane 6
1343  vectorx = cos((60. / 180.) * pi);
1344  vectory = sin((60. / 180.) * pi);
1345  vectorz = 0;
1346  ypos += availableSpace;
1347  tmpxpos = xpos - (extraspacePipe + newradius) * sin((60. / 180.) * pi);
1348  tmpypos = ypos + (extraspacePipe + newradius) * cos((60. / 180.) * pi);
1349 
1350  for(int i = 0; i < possibleStrawsPipe; i++)
1351  {
1352 
1353  putStrawRotatedLeft(tmpxpos + translationToLeft * sin(sixtyrad),
1354  tmpypos - translationToLeft * cos(sixtyrad),
1355  zpos, vectorx, vectory, vectorz, tubeLength);
1356 
1357  tmpxpos -= 2 * newradius * sin((60. / 180.) * pi);
1358  tmpypos += 2 * newradius * cos((60. / 180.) * pi);
1359  }
1360 
1361  for (int i = 0; i < extraStrawsPipe; i++)
1362  {
1363  double
1364  lengthShort = lengthsShortPipe[i];
1365 
1366  double
1367  translationToFrontPar = ((tubeLength - lengthShort) / 2.) * cos(skewanglerad),
1368  translationToFrontPer = ((tubeLength - lengthShort) / 2.) * sin(skewanglerad),
1369  switchSides = 2 * newradius * (possibleStrawsPipe + 1 + (2 * i)) * cos(skewanglerad);
1370 
1371  putStrawRotatedShortLeft(tmpxpos + (translationToLeft + translationToFrontPer) * sin(sixtyrad),
1372  tmpypos - (translationToLeft + translationToFrontPer) * cos(sixtyrad),
1373  zpos + translationToFrontPar,
1374  vectorx, vectory, vectorz, lengthShort);
1375 
1376  putStrawRotatedShortLeft(tmpxpos + (translationToLeft - translationToFrontPer + switchSides) * sin(sixtyrad),
1377  tmpypos - (translationToLeft - translationToFrontPer + switchSides) * cos(sixtyrad),
1378  zpos - translationToFrontPar,
1379  vectorx, vectory, vectorz, lengthShort);
1380 
1381  tmpxpos -= 2 * newradius * sin((60. / 180.) * pi);
1382  tmpypos += 2 * newradius * cos((60. / 180.) * pi);
1383  }
1384 }
1385 
1386 
1387 void makeDoubleLayerStraightExact(double &startRadius)
1388 {
1389  // close packed straight layers are only possible at specific positions
1390  // these are indicated by the integer ringteller. ringteller = 0 would be
1391  // a single straw at the origin. ringteller = 1 would be the first layer of
1392  // 6 straws closepacked around that single straw. And so on ...
1393 
1394  // look for the first ring number which is completely outside the startradius
1395  // given:
1396  double
1397  radius = tubeSeperation / 2.;
1398 
1399  int
1400  ringteller = 0;
1401 
1402  while (ringteller * sqrt(3.) * radius - radius <= startRadius)
1403  {
1404  ringteller++;
1405  }
1406  cerr << "startRadius " << startRadius << endl;
1407  // move the startRadius to the next double layer
1408  startRadius = (ringteller + 1) * sqrt(3.) * radius;
1409 
1410  // place the first layer of this double layer
1411  cerr << "positioning ring at: " << ringteller * sqrt(3.) * radius << endl;
1412  placeSingleLayerStraightExact(ringteller);
1413  // place the second layer
1414  cerr << "positioning ring at: " << (ringteller + 1) * sqrt(3.) * radius << endl;
1415  placeSingleLayerStraightExact(ringteller + 1);
1416 
1417  cerr << "ringteller " << ringteller << endl;
1418 }
1419 
1420 void makeSingleLayerStraightExact(double &startRadius)
1421 {
1422  // see comments at makeDoubleLayerStraightExact()
1423 
1424  double
1425  radius = tubeSeperation / 2.;
1426 
1427  int
1428  ringteller = 0;
1429 
1430  while (ringteller * sqrt(3.) * radius - radius + innerCoverThickness <= startRadius) // CHECK
1431  {
1432  ringteller++;
1433  }
1434 
1435  startRadius = (ringteller + 1) * sqrt(3.) * radius;
1436 
1437  cerr << "positioning ring at: " << ringteller * sqrt(3.) * radius << endl;
1438  placeSingleLayerStraightExact(ringteller);
1439  cerr << "ringteller " << ringteller << " radius " << radius << endl;
1440 
1441 }
1442 
1443 void makeDoubleLayerSkewedRight(double startRadius)
1444 {
1445  // see comments at makeDoubleLayerSkewedLeft()
1446  placeSingleLayerSkewedRight(startRadius);
1447  placeSingleLayerSkewedRight(startRadius + sqrt(3.) * (tubeSeperation / 2.));
1448 }
1449 
1450 void makeDoubleLayerSkewedLeft(double startRadius)
1451 {
1452  // place first skewed left layer at the specified radius
1453  placeSingleLayerSkewedLeft(startRadius);
1454 
1455  // the straw separation is the separation between the centers of two straws next to each other within one layer.
1456  // Close packing then dictates that separation between the layers is sqrt(3) * (separation / 2)
1457  placeSingleLayerSkewedLeft(startRadius + sqrt(3.) * (tubeSeperation / 2.));
1458 }
1459 
1460 int main()
1461 {
1462  // reset counters for the numbers of straws
1463  counter1 = 0;
1464  counter2 = 0;
1465  counter3 = 0;
1466  counter4 = 0;
1467  counter5 = 0;
1468  counter6 = 0;
1469  tubeteller = 0;
1470  axialtubeteller = 0;
1471  skewedtubeteller = 0;
1472 
1473  cout << setiosflags(ios::fixed) << setprecision(6);
1474 
1475  //------------------------------------------------------ volumes
1476 
1478  // //
1479  // STT Support: //
1480  // //
1482 
1483  if(!noSupport)
1484  {
1485  // container for all tubes!
1486  // for X > 0
1487  cout << sttassembly << endl;
1488  cout << cave << endl;
1489  cout << "ASSEMBLY" << endl;
1490  cout << air << endl;
1491  counter4++;
1492  writetrans(0., 0., sttCenterZ);
1493  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
1494 
1495  // cylinder inner x > 0
1496  writename(innerCylinder, 1, 1);
1498  // writemother(sttassembly, 1, 1);
1499  writemedium(AlBe);
1501  writetrans(0., 0., 0.);
1502  writerot(0., 1., 0., -1., 0., 0., 0., 0., 1.);
1503  // writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
1504 
1505  // cylinder outer x > 0
1506  writename(outerCylinder, 1, 1);
1508  // writemother(sttassembly, 1, 1);
1509  writemedium(AlBe);
1511  writetrans(0., 0., 0.);
1512  writerot(0., 1., 0., -1., 0., 0., 0., 0., 1.);
1513  // writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
1514 
1515  // cylinder inner x < 0
1516  writename(innerCylinder, 1, 0);
1517  writecylsupport(sttassembly, false);
1518  // writemother(sttassembly, 1, 1);
1519  // writemedium(AlBe);
1520  // writehalftube((innerDiam / 2.), (innerDiam / 2.) + innerCoverThickness, tubeLength / 2.);
1521  writetrans(0., 0., 0.);
1522  writerot(0., -1., 0., 1., 0., 0., 0., 0., 1.);
1523  // writerot(1., 0., 0., 0., -1., 0., 0., 0., 1.);
1524 
1525  // cylinder outer x < 0
1526  writename(outerCylinder, 1, 0);
1527  writecylsupport(sttassembly, false);
1528  // writemother(sttassembly, 1, 1);
1529  // writemedium(AlBe);
1530  // writehalftube((outerDiam / 2.) - outerCoverThickness, (outerDiam / 2.), tubeLength / 2.);
1531  writetrans(0., 0., 0.);
1532  writerot(0., -1., 0., 1., 0., 0., 0., 0., 1.);
1533  // writerot(1., 0., 0., 0., -1., 0., 0., 0., 1.);
1534 
1535  // around the pipe CHECK why (pipeDiam/2.) "-" panelthickness/2?? -----------------
1536  // panel up x > 0
1538  writetrans((pipeDiam/2.) - panelthickness/2., (outerDiam/2. + innerDiam/2.)/2., 0.);
1539  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
1540  // panel up x < 0
1542  writetrans(-((pipeDiam/2.) - panelthickness), (outerDiam/2. + innerDiam/2.)/2., 0.);
1543  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
1544  // panel down x > 0
1545  writepanel(panel3, false, panelthickness, (outerDiam/2. - innerDiam/2.), tubeLength, 1);
1546  writetrans((pipeDiam/2.) - panelthickness, -(outerDiam/2. + innerDiam/2.)/2., 0.);
1547  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
1548  // panel down x < 0
1549  writepanel(panel4, false, panelthickness, (outerDiam/2. - innerDiam/2.), tubeLength, 2);
1550  writetrans(-((pipeDiam/2.) - panelthickness), -(outerDiam/2. + innerDiam/2.)/2., 0.);
1551  writerot(1., 0., 0., 0., 1., 0., 0., 0., 1.);
1552 
1553  }
1554 
1556  // //
1557  // Layers Geometry and //
1558  // Placement of the logical tubes : //
1559  // //
1561 
1562  double
1563  startRadius = innerCoverThickness + innerDiam / 2.; // CHECK added CoverThickness // CHECK
1564 
1565  bool
1566  wintzdesign = true;
1567 
1568  if (wintzdesign)
1569  {
1570 
1571  // NEW ONE!
1572  // 4 double layers of straight straws
1573  makeDoubleLayerStraightExact(startRadius);
1574  makeDoubleLayerStraightExact(startRadius);
1575  makeDoubleLayerStraightExact(startRadius);
1576  makeDoubleLayerStraightExact(startRadius);
1577 
1578  cerr << "start radius before skewed " << startRadius << endl;
1579  // startRadius = (ringteller + 1) * sqrt(3.) * radius;
1580 
1581  makeDoubleLayerSkewedLeft((26 * sqrt(3.) + 2) * (tubeSeperation / 2.));
1582  makeDoubleLayerSkewedRight((27 * sqrt(3.) + 4) * (tubeSeperation / 2.) + 0.244);
1583  makeDoubleLayerSkewedLeft((28 * sqrt(3.) + 6) * (tubeSeperation / 2.) + 2*0.244);
1584  makeDoubleLayerSkewedRight((29 * sqrt(3.) + 8) * (tubeSeperation / 2.) + 3*0.244);
1585 
1586 
1587  cerr << "start radius after " << startRadius << endl;
1588  startRadius += 10 * tubeSeperation * sqrt(3.) /2.;
1589 
1590  cerr << "start radius " << startRadius << endl;
1591 
1592  // then two double layers of straight straws
1593  makeDoubleLayerStraightExact(startRadius);
1594  makeDoubleLayerStraightExact(startRadius);
1595 
1596  }
1597  else
1598  {
1599  makeDoubleLayerStraightExact(startRadius);
1600  startRadius += tubeSeperation;
1601  makeDoubleLayerSkewedLeft(startRadius);
1602  startRadius += tubeSeperation + sqrt(3.) * (tubeSeperation / 2.);
1603  makeDoubleLayerSkewedRight(startRadius);
1604  startRadius += (tubeSeperation / 2.) + sqrt(3.) * (tubeSeperation / 2.);
1605  makeDoubleLayerStraightExact(startRadius);
1606  startRadius += tubeSeperation;
1607  makeDoubleLayerSkewedLeft(startRadius);
1608  startRadius += tubeSeperation + sqrt(3.) * (tubeSeperation / 2.);
1609  makeDoubleLayerSkewedRight(startRadius);
1610  startRadius += (tubeSeperation / 2.) + sqrt(3.) * (tubeSeperation / 2.);
1611  makeDoubleLayerStraightExact(startRadius);
1612  startRadius += tubeSeperation;
1613  makeDoubleLayerSkewedLeft(startRadius);
1614  startRadius += tubeSeperation + sqrt(3.) * (tubeSeperation / 2.);
1615  makeDoubleLayerSkewedRight(startRadius);
1616  startRadius += (tubeSeperation / 2.) + sqrt(3.) * (tubeSeperation / 2.);
1617  makeDoubleLayerStraightExact(startRadius);
1618  }
1619 
1620  // fill the rest of the volume with straight straws
1621  // straws outside the outerDiam will not be placed
1622  bool
1623  fillup = true;
1624 
1625  if (fillup)
1626  {
1627  makeDoubleLayerStraightExact(startRadius);
1628  makeDoubleLayerStraightExact(startRadius);
1629  makeDoubleLayerStraightExact(startRadius);
1630  makeDoubleLayerStraightExact(startRadius);
1631  makeDoubleLayerStraightExact(startRadius);
1632  makeDoubleLayerStraightExact(startRadius);
1633  makeDoubleLayerStraightExact(startRadius);
1634  makeDoubleLayerStraightExact(startRadius);
1635  makeDoubleLayerStraightExact(startRadius);
1636  makeDoubleLayerStraightExact(startRadius);
1637  }
1638 
1639  // output of all counters
1640  cerr << "tubes: " << tubeteller << endl;
1641  cerr << "axial tubes: " << axialtubeteller << endl;
1642  cerr << "skewed tubes full length: " << skewedtubeteller << endl;
1643  cerr << "skewed tubes short: " << shortskewedtubeteller << endl;
1644  cerr << "minimum radius: " << minimumradius << endl;
1645  cerr << "maximum radius: " << maximumradius << endl;
1646 
1647  return 0;
1648 }
1649 
1650 
1651 
static int counter6
Definition: createSTT_150.C:31
int main(int argc, char **argv)
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
bool putStraw(double posX, double posY, double posZ)
Definition: createSTT.C:171
#define cave
Definition: createSTT_150.C:60
#define AlBe
Definition: createSTT_150.C:71
static int counter1
Definition: createSTT_150.C:26
Int_t i
Definition: run_full.C:25
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
#define wireDiam
Definition: createSTT_150.C:39
friend F32vec4 sin(const F32vec4 &a)
Definition: P4_F32vec4.h:111
bool putStrawRotatedShortLeft(double posX, double posY, double posZ, double xvector, double yvector, double zvector, double length)
Definition: createSTT.C:295
#define sttassembly
Definition: createSTT_150.C:61
#define pi
Definition: createSTT.C:60
#define air
Definition: createSTT_150.C:70
#define safety
Definition: createSTT_150.C:42
#define panel2
Definition: createSTT_150.C:65
#define panel1
Definition: createSTT_150.C:64
void writetrans(double x, double y, double z)
Definition: createSTT.C:155
void makeDoubleLayerStraightExact(double &startRadius)
Definition: createSTT.C:1397
static int tubeteller
Definition: createSTT_150.C:76
#define noSupport
Definition: createSTT_150.C:54
void writerot(double x00, double x01, double x02, double x10, double x11, double x12, double x20, double x21, double x22)
Definition: createSTT.C:161
void writename(char const *name, bool support=false, bool leftside=false)
Definition: createSTT.C:86
#define innerCylinder
Definition: createSTT_150.C:62
static int counter5
Definition: createSTT_150.C:30
#define panel3
Definition: createSTT_150.C:66
#define tubeLength
Definition: createSTT_150.C:40
void writemedium(char *name)
Definition: createSTT.C:104
#define innerCoverThickness
Definition: createSTT_150.C:49
bool putStrawRotatedRight(double posX, double posY, double posZ, double xvector, double yvector, double zvector, double length)
Definition: createSTT.C:474
bool putStrawRotatedShortRight(double posX, double posY, double posZ, double xvector, double yvector, double zvector, double length)
Definition: createSTT.C:352
#define tubeInnerDiam
Definition: createSTT_150.C:36
const Double_t zpos
#define tubeOuterDiam
Definition: createSTT_150.C:37
void plotrotright(double x, double y, double z)
Definition: createSTT.C:257
void makeSingleLayerStraightExact(double &startRadius)
Definition: createSTT.C:1430
static double minimumradius
Definition: createSTT_150.C:81
#define pipeDiam
Definition: createSTT_150.C:53
#define skewangle
Definition: createSTT_150.C:56
void placeSingleLayerStraightExact(double ringteller)
Definition: createSTT.C:542
Double_t z
#define outerDiam
Definition: createSTT_150.C:34
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
void makeDoubleLayerSkewedRight(double startRadius)
Definition: createSTT.C:1453
#define outerCylinder
Definition: createSTT_150.C:63
void placeSingleLayerSkewedRight(double ringposition)
Definition: createSTT.C:593
#define tubeSeperation
Definition: createSTT_150.C:38
bool putStrawRotatedLeft(double posX, double posY, double posZ, double xvector, double yvector, double zvector, double length)
Definition: createSTT.C:410
static int counter2
Definition: createSTT_150.C:27
void writecylsupport(char const *name, bool firstone)
TString name
#define panel4
Definition: createSTT_150.C:67
void writehalftube(double inner, double outer, double length)
Definition: createSTT.C:118
void placeSingleLayerSkewedLeft(double ringposition)
Definition: createSTT.C:984
#define mylar
Definition: createSTT_150.C:72
#define sttCenterZ
Definition: createSTT_150.C:47
void makeDoubleLayerSkewedLeft(double startRadius)
Definition: createSTT.C:1460
Double_t x
#define outerCoverThickness
Definition: createSTT_150.C:50
static int axialtubeteller
Definition: createSTT_150.C:77
static int counter3
Definition: createSTT_150.C:28
static double maximumradius
Definition: createSTT_150.C:80
void writetube(double inner, double outer, double length)
Definition: createSTT.C:110
void plotrotleft(double x, double y, double z)
Definition: createSTT.C:278
#define panelthickness
Definition: createSTT_150.C:52
#define W
Definition: createSTT_150.C:74
void writepanel(char const *name, bool firstone, double xthick, double ythick, double length, int side)
Definition: createSTT.C:127
Double_t y
static int shortskewedtubeteller
Definition: createSTT_150.C:79
static int counter4
Definition: createSTT_150.C:29
double limit
Definition: dedx_bands.C:18
static int skewedtubeteller
Definition: createSTT_150.C:78
#define HeMixture
Definition: createSTT_150.C:73
#define innerDiam
Definition: createSTT_150.C:35
void writemother(char const *name, bool original=true, bool support=false)
Definition: createSTT.C:94