GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AgataGeometryTransformer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004-2006 by Olivier Stezowski & Christian Finck *
3  * stezow(AT)ipnl.in2p3.fr, cfinck(AT)ires.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
23 #include <Riostream.h>
24 #include <map>
25 
26 #ifndef Gw_AgataGeometryTransformer
28 #endif
29 
30 #ifndef ROOT_TGeoBBox
31 #include "TGeoBBox.h"
32 #endif
33 
34 #ifndef ROOT_TColor
35 #include "TColor.h"
36 #endif
37 
38 #ifndef ROOT_TGeoCone
39 #include "TGeoCone.h"
40 #endif
41 
42 #ifndef ROOT_TGeoManager
43 #include "TGeoManager.h"
44 #endif
45 
46 #ifndef ROOT_TGeoPcon
47 #include "TGeoPcon.h"
48 #endif
49 
50 #ifndef ROOT_TGeoShape
51 #include "TGeoShape.h"
52 #endif
53 
54 #ifndef ROOT_TGeoTube
55 #include "TGeoTube.h"
56 #endif
57 
58 #ifndef ROOT_TGeoXtru
59 #include "TGeoXtru.h"
60 #endif
61 
62 #ifndef ROOT_TGeoMatrix
63 #include "TGeoMatrix.h"
64 #endif
65 
66 #ifndef ROOT_TList
67 #include "TList.h"
68 #endif
69 
70 #ifndef ROOT_TMath
71 #include "TMath.h"
72 #endif
73 
74 #ifndef ROOT_TObjArray
75 #include "TObjArray.h"
76 #endif
77 
78 #ifndef ROOT_TVector3
79 #include "TVector3.h"
80 #endif
81 
82 #ifndef ROOT_TGeoCompositeShape
83 #include "TGeoCompositeShape.h"
84 #endif
85 
86 
87 using namespace Gw;
88 using namespace std;
89 
90 const Int_t AgataGeometryTransformer::fgkMaxDetectorID = 180;
91 const Int_t AgataGeometryTransformer::fgkMaxDepthID = 6;
92 const Float_t AgataGeometryTransformer::fgkDepth[6] = {0, 8, 21, 36, 54, 72};
93 const Char_t* AgataGeometryTransformer::fgkGeomName = "Agata";
94 const Char_t* AgataGeometryTransformer::fgkGeomTitle = "Geometry for Agata";
95  Char_t AgataGeometryTransformer::fgDefaultTransp = 50;
96 
97 //______________________________________________________________________________
99  : TObject(),
100  fMatrixList(new TObjArray(fgkMaxDetectorID)),
101  fLog("AgataGeometryTransformer")
102 {
103 // Standard constructor
104  fMatrixList->SetOwner(true);
105 }
106 
107 //______________________________________________________________________________
109 {
110 // Destructor
111  delete fMatrixList;
112 }
113 
114 //______________________________________________________________________________
115 Bool_t AgataGeometryTransformer::ReadTransformations(const TString fileName)
116 {
117  fLog.SetProcessMethod("ReadTransformations(const TString )");
118 
119  ifstream in(fileName, ios::in);
120  if (!in) {
121  fLog << error << Form("file %s not found\n", fileName.Data()) << dolog;
122  return false;
123  }
124 
125  Int_t nd, k;
126  Double_t x,y,z;
127 
128  Double_t trans[3];
129  Double_t rot[9];
130  Char_t line[255];
131 
132  while ( !in.eof() ) {
133 
134  in.getline(line,255);
135 
136  if(sscanf(line, "%d %d %lf %lf %lf", &nd, &k, &x, &y, &z) != 5) {
137  fLog << error << "Problem reading translation factors" << dolog;
138  return false;
139  }
140  trans[0] = x; trans[1] = y, trans[2] = z;
141 
142  if (nd > fgkMaxDetectorID) {
143  fLog << error << Form("Id %d too large, max: %d\n", nd, fgkMaxDetectorID) << dolog;
144  return false;
145  }
146 
147  in.getline(line,255);
148  if(sscanf(line, "%d %lf %lf %lf", &k, &x, &y, &z) != 4)
149  {
150  fLog << error << Form("Problem reading 1st rotation factors for id %d\n", nd) << dolog;
151  return false;
152  }
153  rot[0] = x; rot[1] = y; rot[2] = z;
154 
155  in.getline(line,255);
156  if(sscanf(line, "%d %lf %lf %lf", &k, &x, &y, &z) != 4)
157  {
158  fLog << error << Form("Problem reading 2nd rotation factors for id %d\n", nd) << dolog;
159  return false;
160  }
161  rot[3] = x; rot[4] = y; rot[5] = z;
162 
163  in.getline(line,255);
164  if(sscanf(line, "%d %lf %lf %lf", &k, &x, &y, &z) != 4)
165  {
166  fLog << error << Form("Problem reading 3rd rotation factors for id %d\n", nd) << dolog;
167  return false;
168  }
169  rot[6] = x; rot[7] = y; rot[8] = z;
170 
171  // add matrix for the given id
172  if (fMatrixList->At(nd)) {
173  fLog << error << Form("Matrix transformation already exist for id %d\n", nd) << dolog;
174  return false;
175  } else
176  fMatrixList->AddAt( FillTransMatrix(trans, rot), nd );
177  }
178 
179  in.close( );
180 
181  fLog << dolog;
182 
183  return true;
184 }
185 
186 //______________________________________________________________________________
187 TGeoCombiTrans* AgataGeometryTransformer::FillTransMatrix(Double_t* trans, Double_t* rot)
188 {
189 
190  TGeoRotation rotation; rotation.SetMatrix(rot);
191 
192  TGeoTranslation translation;
193  translation.SetTranslation(trans[0], trans[1], trans[2]);
194 
195  return new TGeoCombiTrans(translation, rotation);
196 }
197 
198 
199 //_____________________________________________________________________________
201  Double_t xg, Double_t yg, Double_t zg,
202  Double_t& xl, Double_t& yl, Double_t& zl) const
203 {
204  if (detID < 0 || detID > fgkMaxDetectorID) {
205  fLog.SetProcessMethod("Global2Local()");
206  fLog << error << "Wrong detector id number" << dolog;
207  return ;
208  }
209 
210  TGeoCombiTrans* mat = static_cast<TGeoCombiTrans*> ( fMatrixList->At(detID) );
211  Double_t local[3] = {0., 0., 0.};
212  Double_t global[3] = {xg, yg, zg};
213 
214  mat->MasterToLocal(global, local);
215  xl = local[0];
216  yl = local[1];
217  zl = local[2];
218 
219 }
220 
221 //_____________________________________________________________________________
223  Float_t xg, Float_t yg, Float_t zg,
224  Float_t& xl, Float_t& yl, Float_t& zl) const
225 {
226  if (detID < 0 || detID > fgkMaxDetectorID) {
227  fLog.SetProcessMethod("Global2Local()");
228  fLog << error << "Wrong detector id number" << dolog;
229  return;
230  }
231 
232  TGeoCombiTrans* mat = static_cast<TGeoCombiTrans*> ( fMatrixList->At(detID) );
233  Double_t local[3] = {0., 0., 0.};
234  Double_t global[3] = {xg, yg, zg};
235 
236  mat->MasterToLocal(global, local);
237  xl = local[0];
238  yl = local[1];
239  zl = local[2];
240 
241 }
242 
243 
244 //_____________________________________________________________________________
246  Double_t xl, Double_t yl, Double_t zl,
247  Double_t& xg, Double_t& yg, Double_t& zg) const
248 {
249  if (detID < 0 || detID > fgkMaxDetectorID) {
250  fLog.SetProcessMethod("Local2Global()");
251  fLog << error << "Wrong detector id number" << dolog;
252  return;
253  }
254 
255  TGeoCombiTrans* mat = static_cast<TGeoCombiTrans*> ( fMatrixList->At(detID) );
256  Double_t local[3] = {xl, yl, zl};
257  Double_t global[3] = {0., 0., 0.};
258 
259  mat->LocalToMaster(local, global);
260  xg = global[0];
261  yg = global[1];
262  zg = global[2];
263 
264 }
265 
266 //_____________________________________________________________________________
268  Float_t xl, Float_t yl, Float_t zl,
269  Float_t& xg, Float_t& yg, Float_t& zg) const
270 {
271  if (detID < 0 || detID > fgkMaxDetectorID) {
272  fLog.SetProcessMethod("Local2Global()");
273  fLog << error << "Wrong detector id number" << dolog;
274  return ;
275  }
276 
277  TGeoCombiTrans* mat = static_cast<TGeoCombiTrans*> ( fMatrixList->At(detID) );
278  Double_t local[3] = {xl, yl, zl};
279  Double_t global[3] = {0., 0., 0.};
280 
281  mat->LocalToMaster(local, global);
282  xg = global[0];
283  yg = global[1];
284  zg = global[2];
285 
286 }
287 
288 //_____________________________________________________________________________
290 {
291  Int_t depthId = 0;
292  for (Int_t i = fgkMaxDepthID-1; i >= 0; --i) {
293  if (z > fgkDepth[i]) {
294  depthId = i;
295  break;
296  }
297  }
298  return depthId+1;
299 }
300 
301 //_____________________________________________________________________________
302 Int_t AgataGeometryTransformer::GetSectorId(Double_t x, Double_t y)
303 {
304  // tmp solution
305  Double_t rho = TMath::Sqrt(x*x + y*y);
306  Double_t phi = TMath::ACos(x/rho);
307 
308  Double_t angle = TMath::Pi()/3;
309 
310  Int_t id = Int_t(phi/angle);
311 
312  if (y < 0) {
313  switch (id) {
314  case 0:
315  return id+5;
316  break;
317  case 1:
318  return id+3;
319  break;
320  case 2:
321  return id+1;
322  break;
323  }
324  }
325  return id;
326 }
327 
328 //_____________________________________________________________________________
329 namespace {
330  const Double_t mm = 0.1;
331 
332  struct ASolid
333  {
334  Int_t Which; // Crystal fType defined by an integer
335  Int_t Sides; // Number of faces for this crystal
336 
337  Double_t HoleR; // Coaxial hole with radius HoleR
338  Double_t HoleL; // Hole starts at the depth HoleL
339 
340  Double_t CylR; // Radius of the cylinder that is the base of the shaped crystal
341  Double_t CylL; // Length of the cylinder that is the base of the shaped crystal
342  Double_t CylX; // Additionnal offset
343  Double_t CylY; // Additionnal offset
344  Double_t CylZ; // Additionnal offset
345 
346  Double_t ThickB; // Thickness of the passive area (back)
347  Double_t ThickC; // Thickness of the passive area (coaxial)
348  Double_t CapS; // The crystal-encapsulation spacing is capS
349  Double_t CapT; // The capsule is capT thick
350  Double_t Tolerance; // CapS+CapT+tol
351 
352  Float_t ColX; // RGB color components
353  Float_t ColY; // RGB color components
354  Float_t ColZ; // RGB color components
355 
356  TObjArray *Vertex; // Array of 3D points (TVector3)
357 
358  ASolid() : Which(-1),Sides(0),
359  HoleR(0.0),HoleL(0.0),CylR(0.0),CylL(0.0),CylX(0.0),CylY(0.0),CylZ(0.0),
360  ThickB(0.0),ThickC(0.0),CapS(0.0),CapT(0.0),Tolerance(0.0),
361  ColX(0.0),ColY(0.0),ColZ(0.0) { Vertex = new TObjArray(); Vertex->SetOwner() ; }
362  ~ASolid() { Vertex->Delete(); delete Vertex; }
363 
364  void Print() const;
365  };
366 
367  void ASolid::Print() const
368  {
369  cout << " Crystal Type " << Which << endl;
370  cout << " Sides " << Sides << endl;
371  cout << " Dimensions crystal " << CylL << " " << CylR << endl;
372  cout << " Dimensions hole " << HoleL << " " << HoleR << endl;
373  }
374 
375 } // anonymous namespace for local declarations
376 
377 //_____________________________________________________________________________
378 Int_t AgataGeometryTransformer::BuildAgataCrystals(const char *filename, const char *basecrysname)
379 {
380  if ( gGeoManager == 0x0 )
381  { cout << " BuildAgataCrystals needs an existing gGeoManager ... " << endl; return 0 ; }
382 
383  // try to open the file
384  ifstream infil; infil.open(filename); if ( !infil.is_open() ) return 0 ;
385 
386  cout << " ---> Reading description of crystals from file " << filename << " ..." << endl;
387 
388  // read the file (see AgataDetectorArray::ReadSolidFile())
389  int i1,i2,i3,lline; double x,y,z,X,Y,Z; char line[255];
390 
391  std::vector<ASolid *> pgons; ASolid *pPg = 0x0; int nPgons = 0; // number of crystals defined in the file
392 
393  int opgon = -1;
394  while( infil.good() ) {
395  infil.getline(line,255); lline = strlen(line);
396 
397  if ( lline < 2 ) continue; if ( line[0] == '#' ) continue;
398 
399  // decode the line
400  if(sscanf(line,"%d %d %d %lf %lf %lf %lf %lf %lf", &i1, &i2, &i3, &x, &y, &z, &X, &Y, &Z) != 9) {
401  nPgons++;
402  break;
403  }
404  if(opgon != i1) { // a new crystal is being defined, so init a new ASolid structure
405  nPgons++;
406  opgon = i1;
407  pPg = new ASolid(); pPg->Which = i1; pPg->Sides = i2; pgons.push_back( pPg );
408  }
409  if(i2==0 && i3==0) { // basic shape for the crystal
410  pPg->HoleR = x * mm;
411  pPg->CylR = y * mm;
412  pPg->CylL = z * mm;
413  pPg->CylX = X * mm;
414  pPg->CylY = Y * mm;
415  pPg->CylZ = Z * mm;
416  }
417  else if(i2==0 && i3==1) { // passive and capsule
418  pPg->HoleL = x * mm;
419  pPg->ThickB = y * mm;
420  pPg->ThickC = z * mm;
421  pPg->CapS = X * mm;
422  pPg->CapT = Y * mm;
423  pPg->Tolerance = Z * mm;
424  }
425  else if(i2==0 && i3==2) { // colors
426  pPg->ColX = x;
427  pPg->ColY = y;
428  pPg->ColZ = z;
429  }
430  else { // a new point to define the ploygon
431  pPg->Vertex->AddAt(new TVector3( x * mm, y * mm, z * mm ), i3);
432  pPg->Vertex->AddAt(new TVector3( X * mm, Y * mm, Z * mm ),i3+i2);
433  }
434  } // while good
435  infil.close();
436  cout << " ... " << nPgons << " different crystals have been built " << endl; // end read the file.
437 
438  // now it built the different crystals and add them to the TGeoManager
439  TGeoMaterial *mat;
440  TGeoMedium *med;
441 
442  if ( (mat = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Ge")) == 0x0 )
443  mat = new TGeoMaterial("Ge", 72.59,32,5.32);
444 
445  if ( (med = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Ge")) == 0x0 )
446  med = new TGeoMedium("Ge",1,mat);
447 
448  vector<ASolid*>::iterator itthesolids;
449  for (itthesolids = pgons.begin(); itthesolids!=pgons.end(); itthesolids++) {
450 
451  pPg = *itthesolids; TString cname, pname; // to get the current crystal definition and set names
452 
453  // Base shape for this crystal
454  // Creation of a Pcon with a name based on the crystal number written in the asolid file
455  cname = "BaseShape";
456  cname += pPg->Which;
457  TGeoPcon *baseshape = new TGeoPcon(0.0,360.0,4);
458 
459  baseshape->SetName(cname.Data());
460  baseshape->DefineSection(0,0.0,0.0,pPg->CylR);
461  baseshape->DefineSection(1,0.9990*pPg->HoleL,0.0,pPg->CylR);
462  baseshape->DefineSection(2,pPg->HoleL,pPg->HoleR,pPg->CylR);
463  baseshape->DefineSection(3,pPg->CylL,pPg->HoleR,pPg->CylR);
464 
465  // Method 3 to build the crystal shape
466  Double_t scale = 0.0, xv[12], yv[12];
467  TVector3 *p1, *p2;
468  for (int i = 0; i < pPg->Sides; i++ ) {
469 
470  p1 = (TVector3 *)pPg->Vertex->At(i); p2 = (TVector3 *)pPg->Vertex->At(i+pPg->Sides);
471  xv[i] = p1->x(); yv[i] = p1->y();
472 
473  Double_t s = TMath::Sqrt(p2->x()*p2->x()+p2->y()*p2->y())
474  / TMath::Sqrt(p1->x()*p1->x()+p1->y()*p1->y()) ;
475 
476  if ( s > scale ) scale = s;
477  }
478 
479  // now build the union as a composition shape that is the shaper of the raw crystal
480  pname = "Shaper"; pname += pPg->Which;
481  TGeoXtru *shaper = new TGeoXtru(2); shaper->SetName(pname.Data());
482 
483  shaper->DefinePolygon(pPg->Sides,xv,yv);
484  shaper->DefineSection(0,-0.001,0.0,0.0,1.0);
485  shaper->DefineSection(1,1.001*pPg->CylL,0.0,0.0,scale);
486 
487  // Intersection between the raw crystal and the shaper
488  cname += " * "; cname += "Shaper"; cname += pPg->Which;
489 
490  // methode 2
491  // cname += ":"; cname += "TrShaper"; cname += pPg->Which;
492 
493  pname = basecrysname; pname += pPg->Which;
494  TGeoCompositeShape *crysshape = new TGeoCompositeShape(pname.Data(),cname.Data());
495 
496  // TGeoVolume *thecrys = new TGeoVolume(pname.Data(),arb8,med);
497  // TGeoVolume *thecrys = new TGeoVolume(pname.Data(),shaper,med);
498  TGeoVolume *thecrys = new TGeoVolume(pname.Data(),crysshape,med);
499  // TGeoVolume *thecrys = new TGeoVolume(pname.Data(),baseshape,med);
500  thecrys->SetLineColor(TColor::GetColor(pPg->ColX,pPg->ColY,pPg->ColZ));
501  thecrys->SetTransparency(fgDefaultTransp);
502  } // itthesolids
503 
504  return nPgons;
505 }
506 
507 //_____________________________________________________________________________
508 Int_t AgataGeometryTransformer::BuildAgataClusters(const char *filename, const char *baseclusname, const char *basecrysname)
509 {
510  // crystals are not yet defined so the cluster cannot be built
511  if ( gGeoManager == 0x0 ) {
512  cout << " BuildAgataClusters needs an existing gGeoManager ... " << endl;
513  return 0;
514  }
515 
516  // try to open the file
517  ifstream infil; infil.open(filename); if ( !infil.is_open() ) return 0 ;
518 
519  cout << "\nReading description of clusters from file " << filename << " ..." << endl;
520 
521  Char_t line[256];
522  Int_t lline, i1, i2, i3, oclust, nclust; Double_t ps, th, ph, x, y, z;
523 
524  TString crysname, clusname; TGeoVolume *clu = 0x0, *cris = 0x0;
525 
526  nclust = 0; oclust = -1;
527  while(infil.good()) {
528  infil.getline(line,255); lline = strlen(line);
529  if(lline < 2) continue;
530  if(line[0] == '#') continue;
531  if(sscanf(line,"%d %d %d %lf %lf %lf %lf %lf %lf", &i1, &i2, &i3, &ps, &th, &ph, &x, &y, &z) != 9) {
532  break;
533  }
534  if(oclust != i1) {
535  oclust = i1;
536  nclust++;
537 
538  // a new assembly is created to define the cluster
539  clusname = baseclusname; clusname += oclust; clu = new TGeoVolumeAssembly(clusname.Data());
540  }
541  // look for the corresponding crystal in the list of existing volumes
542  crysname = basecrysname; crysname += i2; cris = gGeoManager->GetVolume(crysname.Data());
543  if ( cris == 0x0 ) {
544  cout << "Cannot build correctly the cluster " << clusname << ", " << crysname << " does not exist " << endl;
545  }
546  else { // add this crystal after transformation to the assembly
547  TGeoHMatrix H; TGeoRotation R; TGeoTranslation T(x*mm,y*mm,z*mm);
548  R.RotateZ(ps);
549  R.RotateY(th);
550  R.RotateZ(ph);
551 
552  H = T * R;
553  TGeoHMatrix *h = new TGeoHMatrix(H); clu->AddNode(cris,i3,h);
554  }
555  }
556  infil.close();
557 
558  cout << nclust << " different cluster(s) have been build " << endl; return nclust;
559 }
560 
561 //_____________________________________________________________________________
562 TGeoVolume* AgataGeometryTransformer::BuildAgataDetector(const char *filename, const char *baseclusname, const char *agataName)
563 {
564  // crystals are not yet defined so the cluster cannot be built
565  if ( gGeoManager == 0x0 ) {
566  cout << " BuildAgata needs an existing gGeoManager ... " << endl;
567  return 0x0;
568  }
569 
570  // try to open the file
571  ifstream infil; infil.open(filename); if ( !infil.is_open() ) return 0x0 ;
572 
573  cout << "\n Reading description of AGATA from file " << filename << " ..." << endl;
574 
575  TString clusname;
576  Char_t line[256];
577  Int_t lline, i1, i2, nclust = 0; Double_t ps, th, ph, x, y, z;
578 
579  TGeoVolume *agata = 0x0;
580  while(infil.good()) {
581  infil.getline(line,255); lline = strlen(line);
582  if(lline < 2) continue;
583  if(line[0] == '#') continue;
584  if(sscanf(line,"%d %d %lf %lf %lf %lf %lf %lf",
585  &i1, &i2, &ps, &th, &ph, &x, &y, &z) != 8) break;
586 
587  clusname = baseclusname; clusname += i2;
588  TGeoVolume *clus = gGeoManager->GetVolume(clusname.Data());
589  if ( clus ) { // this cluster is known
590  TGeoMedium *med;
591  TGeoMaterial *mat;
592  if ( (mat = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Vacuum")) == 0x0 )
593  mat = new TGeoMaterial("Vacuum",0,0,0);
594  if ( (med = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Vacuum")) == 0x0 )
595  med = new TGeoMedium("Vacuum",1,mat);
596 
597  if ( agata == 0x0 )
598  agata = gGeoManager->MakeBox(agataName,med,60,60,60); // volume corresponding to agata
599 
600  TGeoHMatrix H; TGeoRotation R; TGeoTranslation T(x*mm,y*mm,z*mm);
601  R.RotateZ(ps);
602  R.RotateY(th);
603  R.RotateZ(ph);
604 
605  H = T * R;
606  TGeoHMatrix *h = new TGeoHMatrix(H); agata->AddNode(clus,i1,h); nclust++;
607  }
608  }
609  infil.close();
610 
611  cout << nclust << " cluster(s) composed this geometry " << endl; return agata;
612 }
613 
614 //_____________________________________________________________________________
615 TGeoVolume* AgataGeometryTransformer::ImportAgata(const char *asolid, const char *aclust, const char *aeuler,
616  const char *baseclusname, const char *agataName)
617 {
618  if ( gGeoManager == 0x0 ) { // a new Geo Manager is created if needed
619  new TGeoManager(fgkGeomName, fgkGeomTitle);
620  }
621 
622  // try to build the different part of the detector
623  TGeoVolume *agata = 0x0;
624  if ( BuildAgataCrystals(asolid) > 0 ) { // at least one crystal has been build
625  if ( BuildAgataClusters(aclust) > 0 ) { // at least one cluster has been build
626  agata = BuildAgataDetector(aeuler, baseclusname, agataName);
627  }
628  }
629 
630  return agata;
631 }
632 
633 //_____________________________________________________________________________
634 TGeoVolume* AgataGeometryTransformer::BuildAgata(const char* agataPath, const char *asolid, const char *aclust, const char *aeuler,
635  const char *baseclusname, const char *agataName)
636 {
637  if ( gGeoManager == 0x0 ) { // a new Geo Manager is created if needed
638  new TGeoManager(fgkGeomName, fgkGeomTitle);
639  }
640 
641  TString path(agataPath);
642  if (!path.EndsWith("/"))
643  path += "/";
644  TString geoSolid(asolid);
645  TString geoCluster(aclust);
646  TString geoEuler(aeuler);
647 
648  geoSolid.Prepend(path);
649  geoCluster.Prepend(path);
650  geoEuler.Prepend(path);
651 
652  // try to build the different part of the detector
653  TGeoVolume *agata = 0x0;
654  if ( BuildAgataCrystals(geoSolid.Data()) > 0 ) { // at least one crystal has been build
655  if ( BuildAgataClusters(geoCluster.Data()) > 0 ) { // at least one cluster has been build
656  agata = BuildAgataDetector(geoEuler.Data(), baseclusname, agataName);
657  }
658  }
659 
660  return agata;
661 }
662 
663 //_____________________________________________________________________________
664 TGeoVolume* AgataGeometryTransformer::BuildDante(const char* danteConf, const char* basemoduleName, const char *danteName)
665 {
666  std::ifstream in(danteConf); std::string tmp;
667 
668  if ( in.is_open() == false ) {
669  cout << " ---> Problem opening file " << danteConf << " ..." << endl;
670  return 0x0;
671  }
672 
673  cout << " ---> Reading description of Dante from file " << danteConf << " ..." << endl;
674 
675  getline(in,tmp);
676  tmp += " ";
677  TGeoVolume* dante = 0x0;
678  while ( in.good() && !in.eof() ) { // read input stream line by line
679 
680  if ( tmp[0] == '#' ) {
681  getline(in,tmp);
682  continue;
683  } // this line is a comment
684 
685  Float_t dz, rz1, ry, rz2, rx, tx1, tx2,ty1, ty2, ax, bx, cx, ay, by, cy ;
686  Int_t which;
687  std::istringstream decode(tmp);
688 
689  decode >> which;
690 
691  if (which != -1) {
692 
693  decode >> dz >> rz1 >> ry >> rz2 >> rx >> tx1 >> tx2 >> ty1 >> ty2 >> ax >> bx >> cx >> ay >> by >> cy ;
694 
695  dante = AgataGeometryTransformer::AddDanteModule(dz/10., rz1, ry, rz2, rx, basemoduleName, danteName);
696 
697  // add 0x0 character at the end since getline
698  // does not store \n and it may give troubles when decoding
699  }
700  getline(in,tmp);
701  tmp += " ";
702 
703  }
704  in.close();
705 
706 
707  return dante;
708 }
709 
710 //_____________________________________________________________________________
711 TGeoVolume* AgataGeometryTransformer::AddDanteModule(const Float_t dZ, const Float_t rotZ1, const Float_t rotY, const Float_t rotZ2,
712  const Float_t rotX, const char* basemoduleName, const char *danteName)
713 {
714  if ( gGeoManager == 0x0 ) { // a new Geo Manager is created if needed
715  new TGeoManager(fgkGeomName, fgkGeomTitle);
716  }
717 
718  TGeoVolume* dante = gGeoManager->FindVolumeFast(danteName);
719  if ( dante == 0x0 ) {
720  TGeoMedium *med;
721  TGeoMaterial *mat;
722  if ( (mat = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Vacuum")) == 0x0 )
723  mat = new TGeoMaterial("Vacuum",0,0,0);
724  if ( (med = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Vacuum")) == 0x0 )
725  med = new TGeoMedium("Vacuum",1,mat);
726 
727  dante = gGeoManager->MakeBox(danteName,med,60,60,60); // volume corresponding to Dante
728  }
729 
730  // create module
731  TGeoMaterial* matMod;
732  TGeoMedium* medMod;
733 
734  if ( (matMod = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Si")) == 0x0 )
735  matMod = new TGeoMaterial("Si", 28.09, 14, 2.3);
736  if ( (medMod = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Si")) == 0x0 )
737  medMod = new TGeoMedium("Si",2,matMod);
738 
739  TGeoBBox *box = new TGeoBBox(Form("%s_Box",basemoduleName), 2., 3., 0.2);
740 
741  // Apply transfo
742  TGeoRotation rot;
743  TGeoHMatrix transfo;
744  TGeoHMatrix* hm = 0x0;
745  TGeoTranslation trans(0., 0., dZ);
746 
747  rot.RotateZ(rotZ1);
748  rot.RotateY(rotY);
749  rot.RotateZ(rotZ2);
750  rot.RotateX(rotX);
751 
752  transfo = rot * trans;
753  hm = new TGeoHMatrix(transfo);
754 
755  Int_t nbModule = 0;
756 
757  TGeoVolume *danteMod = new TGeoVolume(Form("%s_Dante",basemoduleName),box, medMod);
758  danteMod->SetLineColor(kAzure-5);
759  danteMod->SetTransparency(fgDefaultTransp);
760 
761  TObjArray* list = dante->GetNodes();
762  if (list) {
763  for (Int_t i = 0; i < list->GetEntries(); ++i) {
764  TGeoVolume* vol = (TGeoVolume*)list->At(i);
765  if (vol) {
766  TString name(vol->GetName());
767  if ( name.Contains(Form("%s_Dante",basemoduleName)) )
768  nbModule++;
769  }
770  }
771  }
772 
773  dante->AddNode(danteMod, nbModule, hm);
774  return dante;
775 }
776 
777 //_____________________________________________________________________________
778 TGeoVolume* AgataGeometryTransformer::AddBeamPipe(const Float_t dZ, const Float_t minR, const Float_t maxR, const char *pipeName )
779 {
780  if ( gGeoManager == 0x0 ) { // a new Geo Manager is created if needed
781  new TGeoManager(fgkGeomName, fgkGeomTitle);
782  }
783 
784  // create module
785  TGeoMaterial* matPipe;
786  TGeoMedium* medPipe;
787 
788  if ( (matPipe = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Al")) == 0x0 )
789  matPipe = new TGeoMaterial("Al", 26.98,13,2.7);
790  if ( (medPipe = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Al")) == 0x0 )
791  medPipe = new TGeoMedium("Al", 2, matPipe);
792 
793 
794  TGeoVolume* tube = gGeoManager->MakeTube(pipeName, medPipe, minR, maxR, dZ);
795  tube->SetVisibility(true);
796  tube->SetLineColor(17);
797  tube->SetTransparency(fgDefaultTransp);
798 
799  return tube;
800 }
801 
802 //_____________________________________________________________________________
803 TGeoVolume* AgataGeometryTransformer::AddTarget(const Float_t dx, const Float_t dy, const Float_t dz,
804  const char *targetName, TGeoMaterial* mat)
805 {
806  if ( gGeoManager == 0x0 ) { // a new Geo Manager is created if needed
807  new TGeoManager(fgkGeomName, fgkGeomTitle);
808  }
809 
810  // create module
811  TGeoMaterial* matTarget;
812  TGeoMedium* medTarget;
813 
814  if (mat != 0) {
815  matTarget = mat;
816  medTarget = new TGeoMedium("Medium", 1, matTarget);
817  } else {
818  if ( (matTarget = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Vacuum")) == 0x0 )
819  matTarget = new TGeoMaterial("Vacuum", 0., 0., 0.);
820  if ( (medTarget = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Vacuum")) == 0x0 )
821  medTarget = new TGeoMedium("Vacuum", 1, matTarget);
822  }
823 
824  TGeoVolume* target = gGeoManager->MakeBox(targetName, medTarget, dx, dy, dz);
825  target->SetVisibility(true);
826 
827  return target;
828 }
829 
830 //_____________________________________________________________________________
831 TGeoVolume* AgataGeometryTransformer::AddFloor(Float_t dx, const Float_t dy, const Float_t dz, const char *floorName )
832 {
833  if ( gGeoManager == 0x0 ) { // a new Geo Manager is created if needed
834  new TGeoManager(fgkGeomName, fgkGeomTitle);
835  }
836 
837  // create module
838  TGeoMaterial* matFloor;
839  TGeoMedium* medFloor;
840 
841  if ( (matFloor = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Al")) == 0x0 )
842  matFloor = new TGeoMaterial("Al", 26.98,13,2.7);
843  if ( (medFloor = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Al")) == 0x0 )
844  medFloor = new TGeoMedium("Al", 2, matFloor);
845 
846 
847  TGeoVolume* floor = gGeoManager->MakeBox(floorName, medFloor, dx, dy, dz);
848  floor->SetVisibility(true);
849  floor->SetLineColor(kWhite);
850  floor->SetTransparency(fgDefaultTransp);
851  return floor;
852 }
853 
854 //_____________________________________________________________________________
855 TGeoVolume* AgataGeometryTransformer::AddPrismaMCP(const char *prismaName, Float_t dx, Float_t dy, Float_t dz, Float_t phi, TGeoMaterial* mat)
856 {
857  if ( gGeoManager == 0x0 ) { // a new Geo Manager is created if needed
858  new TGeoManager(fgkGeomName, fgkGeomTitle);
859  }
860 
861  // cmedMWPCeate module
862  TGeoMaterial* matMCP;
863  TGeoMedium* medMCP;
864 
865  if (mat != 0) {
866  matMCP = mat;
867  medMCP = new TGeoMedium("Medium", 1, matMCP);
868  } else {
869  if ( (matMCP = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Vacuum")) == 0x0 )
870  matMCP = new TGeoMaterial("Vacuum", 0., 0., 0.);
871  if ( (medMCP = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Vacuum")) == 0x0 )
872  medMCP = new TGeoMedium("Vacuum", 1, matMCP);
873  }
874 
875 
876  TGeoVolume* mcp = gGeoManager->MakeBox(prismaName,medMCP,dx,dy,dz);
877 
878  TGeoVolume* start = gGeoManager->MakeBox("start", medMCP, dx, dy, dz);
879  start->SetVisibility(true);
880  start->SetLineColor(kBlue);
881  start->SetTransparency(fgDefaultTransp);
882 
883  TGeoRotation rot;
884  rot.RotateY(phi);
885  TGeoHMatrix *hm = new TGeoHMatrix(rot);
886  mcp->AddNode(start, 0, hm);
887 
888 
889  return mcp;
890 }
891 
892 //_____________________________________________________________________________
893 TGeoVolume* AgataGeometryTransformer::AddPrismaDipoleOld(const char *prismaName, Float_t dz, Float_t rmin, Float_t rmax, Float_t phi1, Float_t phi2)
894 {
895  if ( gGeoManager == 0x0 ) { // a new Geo Manager is created if needed
896  new TGeoManager(fgkGeomName, fgkGeomTitle);
897  }
898 
899  TGeoMaterial* matPrismaDipole;
900  TGeoMedium* medPrismaDipole;
901 
902  if ( (matPrismaDipole = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Fe")) == 0x0 )
903  matPrismaDipole = new TGeoMaterial("Fe", 55.9, 26, 7.87);
904  if ( (medPrismaDipole = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Fe")) == 0x0 )
905  medPrismaDipole = new TGeoMedium("Fe", 3, matPrismaDipole);
906 
907  TGeoMedium *med;
908  TGeoMaterial *mat;
909  if ( (mat = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Vacuum")) == 0x0 )
910  mat = new TGeoMaterial("Vacuum",0,0,0);
911  if ( (med = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Vacuum")) == 0x0 )
912  med = new TGeoMedium("Vacuum",1,mat);
913 
914  TGeoRotation rot;
915  rot.RotateX(90);
916  rot.RotateY(65);
917 
918  TGeoHMatrix transfo;
919  TGeoTranslation trans(-(rmax+rmin)/2*(1+(1-TMath::Cos(20.*TMath::DegToRad()))), 0., (rmax+rmin)/2);
920  transfo = trans*rot;
921  TGeoHMatrix *hm = new TGeoHMatrix(transfo);
922 
923  TGeoVolume* dipole = gGeoManager->MakeCons(Form("%s_%s", prismaName,"Dipole"), medPrismaDipole, dz, rmin, rmax, rmin, rmax, phi1, phi2);
924  dipole->SetVisibility(true);
925  dipole->SetLineColor(55);
926  dipole->SetTransparency(fgDefaultTransp);
927 
928  TGeoConeSeg* shape = (TGeoConeSeg*)dipole->GetShape();
929  shape->ComputeBBox();
930  Float_t boxSizeX = shape->GetDX();
931  Float_t boxSizeY = shape->GetDY();
932  Float_t boxSizeZ = shape->GetDZ();
933 
934  TGeoVolume* prisma = gGeoManager->MakeBox(prismaName, med, boxSizeX, boxSizeY, boxSizeZ); // volume corresponding to prisma dipole
935  prisma->AddNode(dipole, 1, hm);
936 
937  return prisma;
938 }
939 
940 
941 //_____________________________________________________________________________
942 TGeoVolume* AgataGeometryTransformer::AddPrismaDipole(const char *prismaName, Float_t dx, Float_t dy, Float_t dz)
943 {
944  if ( gGeoManager == 0x0 ) { // a new Geo Manager is created if needed
945  new TGeoManager(fgkGeomName, fgkGeomTitle);
946  }
947 
948  TGeoMaterial* matPrismaDipole;
949  TGeoMedium* medPrismaDipole;
950 
951  if ( (matPrismaDipole = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Fe")) == 0x0 )
952  matPrismaDipole = new TGeoMaterial("Fe", 55.9, 26, 7.87);
953  if ( (medPrismaDipole = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Fe")) == 0x0 )
954  medPrismaDipole = new TGeoMedium("Fe", 3, matPrismaDipole);
955 
956  TGeoMedium *med;
957  TGeoMaterial *mat;
958  if ( (mat = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Vacuum")) == 0x0 )
959  mat = new TGeoMaterial("Vacuum",0,0,0);
960  if ( (med = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Vacuum")) == 0x0 )
961  med = new TGeoMedium("Vacuum",1,mat);
962 
963  // Dipole entrance
964  TGeoRotation rot1;
965  rot1.RotateY(20);
966 
967  TGeoHMatrix transfo1;
968  transfo1 = rot1;
969  TGeoHMatrix *hm1 = new TGeoHMatrix(transfo1);
970 
971  TGeoVolume* dipoleIn = gGeoManager->MakeBox(Form("%s_%s", prismaName,"Dipole"), medPrismaDipole, dx, dy, dz);
972  dipoleIn->SetVisibility(true);
973  dipoleIn->SetLineColor(kViolet);
974  dipoleIn->SetTransparency(fgDefaultTransp);
975 
976  // Dipole exit
977  TGeoRotation rot2;
978  rot2.RotateY(-60);
979  Float_t posX = 60.;
980  Float_t posZ = 60.*TMath::Tan(60.*TMath::DegToRad());
981  TGeoTranslation trans2(-posX, 0, posZ);
982 
983  TGeoHMatrix transfo2;
984  transfo2 = trans2*rot2;
985  TGeoHMatrix *hm2 = new TGeoHMatrix(transfo2);
986 
987  TGeoVolume* dipoleOut = gGeoManager->MakeBox(Form("%s_%s", prismaName,"Dipole"), medPrismaDipole, dx, dy, dz);
988  dipoleOut->SetVisibility(true);
989  dipoleOut->SetLineColor(kViolet);
990  dipoleOut->SetTransparency(fgDefaultTransp);
991 
992  TGeoVolume* prisma = gGeoManager->MakeBox(prismaName, med, 200, 200, 200); // volume corresponding to prisma dipole
993  prisma->AddNode(dipoleIn, 1, hm1);
994  prisma->AddNode(dipoleOut, 2, hm2);
995 
996  return prisma;
997 }
998 
999 //_____________________________________________________________________________
1000 TGeoVolume* AgataGeometryTransformer::AddPrismaQpole(const char *prismaName, Float_t dz, Float_t rmin, Float_t rmax)
1001 {
1002  if ( gGeoManager == 0x0 ) { // a new Geo Manager is created if needed
1003  new TGeoManager(fgkGeomName, fgkGeomTitle);
1004  }
1005 
1006  TGeoMaterial* matPrismaQpole;
1007  TGeoMedium* medPrismaQpole;
1008 
1009  if ( (matPrismaQpole = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Fe")) == 0x0 )
1010  matPrismaQpole = new TGeoMaterial("Fe", 55.9, 26, 7.87);
1011  if ( (medPrismaQpole = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Fe")) == 0x0 )
1012  medPrismaQpole = new TGeoMedium("Fe", 3, matPrismaQpole);
1013 
1014  TGeoVolume* prisma = gGeoManager->MakeTube(prismaName, medPrismaQpole, rmin, rmax, dz);
1015  prisma->SetVisibility(true);
1016  prisma->SetLineColor(kViolet);
1017  prisma->SetTransparency(fgDefaultTransp);
1018 
1019  return prisma;
1020 }
1021 
1022 //_____________________________________________________________________________
1023 TGeoVolume* AgataGeometryTransformer::AddPrismaMWPC(const char *prismaName, Float_t dzFcIc, Float_t dx, Float_t dy, Float_t dz, TGeoMaterial* mat)
1024 {
1025  if ( gGeoManager == 0x0 ) { // a new Geo Manager is created if needed
1026  new TGeoManager(fgkGeomName, fgkGeomTitle);
1027  }
1028 
1029  // cmedMWPCeate module
1030  TGeoMaterial* matMWPC;
1031  TGeoMedium* medMWPC;
1032 
1033  if (mat != 0) {
1034  matMWPC = mat;
1035  medMWPC = new TGeoMedium("Medium", 1, matMWPC);
1036  } else {
1037  if ( (matMWPC = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Vacuum")) == 0x0 )
1038  matMWPC = new TGeoMaterial("Vacuum", 0., 0., 0.);
1039  if ( (medMWPC = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Vacuum")) == 0x0 )
1040  medMWPC = new TGeoMedium("Vacuum", 1, matMWPC);
1041  }
1042 
1043 
1044  TGeoVolume* mwpc = gGeoManager->MakeBox(prismaName,medMWPC,dx,dy,100);
1045 
1046  TGeoVolume* fc = gGeoManager->MakeBox("FC", medMWPC, dx, 10, 1);
1047  fc->SetVisibility(true);
1048  fc->SetLineColor(kBlue);
1049  fc->SetTransparency(fgDefaultTransp);
1050  mwpc->AddNode(fc,0);
1051 
1052  TGeoVolume* ic = gGeoManager->MakeBox("IC", medMWPC, dx, 10, dz);
1053  ic->SetVisibility(true);
1054  ic->SetLineColor(kBlue);
1055  ic->SetTransparency(fgDefaultTransp);
1056  TGeoTranslation trans1(0., 0., dzFcIc+dz);
1057  TGeoHMatrix *hm1 = new TGeoHMatrix(trans1);
1058  mwpc->AddNode(ic, 1, hm1);
1059 
1060 
1061  return mwpc;
1062 }
1063 
1064 //_____________________________________________________________________________
1065 TGeoVolume* AgataGeometryTransformer::BuildPrisma(const char* prismaConf, Float_t dzMCP, Float_t dzQpole, Float_t dzDipole, Float_t dzDipMWPC,
1066  const char* nameMCP, const char* nameQPole, const char* nameDipole, const char* nameMWPC,
1067  const char* prismaName)
1068 {
1069  if ( gGeoManager == 0x0 ) { // a new Geo Manager is created if needed
1070  new TGeoManager(fgkGeomName, fgkGeomTitle);
1071  }
1072 
1073  TGeoMedium *med;
1074  TGeoMaterial *mat;
1075  if ( (mat = (TGeoMaterial *)gGeoManager->GetListOfMaterials()->FindObject("Vacuum")) == 0x0 )
1076  mat = new TGeoMaterial("Vacuum",0,0,0);
1077  if ( (med = (TGeoMedium *)gGeoManager->GetListOfMedia()->FindObject("Vacuum")) == 0x0 )
1078  med = new TGeoMedium("Vacuum",1,mat);
1079 
1080 
1081  Float_t dzMCPLoc; Float_t dzQpoleLoc; Float_t dzDipoleLoc; Float_t dzDipMWPCLoc;
1082  if ( ReadPrismaConf(dzMCPLoc, dzQpoleLoc, dzDipoleLoc, dzDipMWPCLoc, prismaConf) ) {
1083  dzMCP = dzMCPLoc;
1084  dzQpole = dzQpoleLoc;
1085  dzDipole = dzDipoleLoc;
1086  dzDipMWPC = dzDipMWPCLoc;
1087  cout << " ---> Reading description of Prisma from file " << prismaConf << " ..." << endl;
1088  } else {
1089  cout << " ---> Using default values for Prisma geometry" << " ..." << endl;
1090  }
1091 
1092  // global volume
1093  Float_t dyRot = 30.;
1094  TGeoVolume* prisma = gGeoManager->MakeBox(prismaName,med,450,450,450);
1095 
1096  // MCP
1097  TGeoVolume* mcp = AgataGeometryTransformer::AddPrismaMCP(nameMCP);
1098  TGeoTranslation trans0(0., 0., dzMCP);
1099  TGeoHMatrix *hm0 = new TGeoHMatrix(trans0);
1100 
1101  prisma->AddNode(mcp, 0, hm0);
1102 
1103  // Qpole
1104  TGeoVolume* Qpole = AgataGeometryTransformer::AddPrismaQpole(nameQPole);
1105  TGeoTube* shape = (TGeoTube*)Qpole->GetShape();
1106  shape->ComputeBBox();
1107  Float_t dzQp = shape->GetDZ();
1108  Float_t posZQp = dzQpole + dzQp;
1109 
1110  TGeoTranslation trans1(0., 0., posZQp);
1111  TGeoHMatrix *hm1 = new TGeoHMatrix(trans1);
1112 
1113  prisma->AddNode(Qpole, 1, hm1);
1114 
1115  // Dipole
1116  Float_t posZDip = dzDipole;
1117 
1118  TGeoVolume* dipole = AgataGeometryTransformer::AddPrismaDipole(nameDipole);
1119  TGeoHMatrix transfo2;
1120  TGeoTranslation trans2(0., 0.,posZDip);
1121  transfo2 = trans2;
1122  TGeoHMatrix *hm2 = new TGeoHMatrix(transfo2);
1123  prisma->AddNode(dipole, 2, hm2);
1124 
1125  //MWPC
1126  Float_t posXmwpc = 60 + dzDipMWPC * TMath::Cos(dyRot*TMath::DegToRad());
1127  Float_t posZmwpc = posZDip + 60.*TMath::Sqrt(3.) + dzDipMWPC * TMath::Sin(dyRot*TMath::DegToRad());
1128 
1129  TGeoRotation rot3;
1130  TGeoHMatrix transfo3;
1131  Float_t dphi = dyRot-90;
1132  TGeoTranslation trans3(-posXmwpc, 0, posZmwpc);
1133  rot3.RotateY(dphi);
1134  transfo3 = trans3*rot3;
1135  TGeoHMatrix *hm3 = new TGeoHMatrix(transfo3);
1136  TGeoVolume* mwpc = AgataGeometryTransformer::AddPrismaMWPC(nameMWPC);
1137  prisma->AddNode(mwpc, 3, hm3);
1138 
1139  return prisma;
1140 }
1141 
1142 //_____________________________________________________________________________
1143 Bool_t AgataGeometryTransformer::ReadPrismaConf(Float_t& dzMCP, Float_t& dzQpole, Float_t& dzDipole, Float_t& dzDipMWPC, const char* prismaConf)
1144 {
1145  std::map<TString, float> map;
1146  ifstream in(prismaConf);
1147  if ( !in ) {
1148  return false;
1149  }
1150 
1151  Char_t line[255];
1152  while ( in.getline(line,255) ) {
1153 
1154  TString tmp(line);
1155 
1156  if (tmp[0] == '#') continue;
1157  if (tmp[0] == ' ') continue;
1158  if (tmp.Length() < 5) continue;
1159 
1160  Int_t pos = tmp.First('=');
1161 
1162  TString sValue = tmp(pos+1, tmp.Length()-pos);
1163 
1164  TString sToken = tmp(0, pos-1);
1165 
1166  Float_t value = sValue.Atof();
1167  map[sToken] = value;
1168  }
1169 
1170  std::map<TString, float>::iterator iter;
1171 
1172  iter = map.find(TString("target_mcp_distance"));
1173  dzMCP = iter->second/10.;
1174 
1175  iter = map.find(TString("target_quad_distance"));
1176  dzQpole = iter->second/10.;
1177 
1178  iter = map.find(TString("target_dipole_distance"));
1179  dzDipole = iter->second/10.;
1180 
1181  iter = map.find(TString("dip_fp_dist"));
1182  dzDipMWPC= iter->second/10.;
1183 
1184  return true;
1185 }
1186 
static TGeoVolume * AddPrismaQpole(const char *prismaName="PrismaQpole", Float_t dz=21., Float_t rmin=15., Float_t rmax=15.7)
Add Prisma Qpole.
static TGeoVolume * BuildAgataDetector(const char *filename="aeuler", const char *baseclusname="agataCluster", const char *agataName="Agata")
to build agata from a formatted text-file (aeuler)
LogMessage & error(LogMessage &)
static TGeoVolume * AddTarget(const Float_t dx=0.8, const Float_t dy=0.8, const Float_t dz=0.05, const char *targetName="Target", TGeoMaterial *mat=0x0)
Add beam pipe.
static TGeoVolume * AddPrismaDipole(const char *prismaName="PrismaDipole", Float_t dx=50., Float_t dy=10., Float_t dz=1.)
Add Prisma Dipole.
void Global2Local(Int_t detID, Double_t xg, Double_t yg, Double_t zg, Double_t &xl, Double_t &yl, Double_t &zl) const
Transform point from the global reference frame to the local reference frame of the detection id...
static TGeoVolume * AddDanteModule(const Float_t dz=0., const Float_t rotz1=0., const Float_t roty=0., const Float_t rotz2=0, const Float_t rotx=0., const char *basemoduleName="Module", const char *danteName="Dante")
Add Dante module geometry to the Agata-Geant4 world.
static TGeoVolume * AddPrismaDipoleOld(const char *prismaName="PrismaDipole", Float_t dz=10., Float_t rmin=70., Float_t rmax=170., Float_t phi1=-20, Float_t phi2=65)
Add Prisma Dipole.
static TGeoVolume * BuildPrisma(const char *prismaConf="solver.conf", Float_t dzMCP=25., Float_t dzQpole=54., Float_t dzDipole=160., Float_t dzDipMWPC=328.5, const char *nameMCP="PrismaMCP", const char *nameQPole="PrismaQpole", const char *nameDipole="PrismaDipole", const char *nameMWPC="PrismaMWPC", const char *prismaName="Prisma")
Build Prisma.
static TGeoVolume * AddPrismaMCP(const char *prismaName="PrismaMCP", Float_t dx=10., Float_t dy=10., Float_t dz=1., Float_t phi=135., TGeoMaterial *mat=0x0)
Add MCP.
UInt_t value[MaxValue]
Definition: ReadDaqAlone.C:29
static Bool_t ReadPrismaConf(Float_t &dzMCP, Float_t &dzQpole, Float_t &dzDipole, Float_t &dzDipMWPC, const char *prismaConf="solver.conf")
Read prisma configuration file.
TGeoCombiTrans * FillTransMatrix(Double_t *trans, Double_t *rot)
fill list of matrices
static TGeoVolume * BuildDante(const char *danteConf="Dante.conf", const char *basemoduleName="Module", const char *danteName="Dante")
Build Dante.
static TGeoVolume * AddBeamPipe(const Float_t dZ=18, const Float_t minR=2., const Float_t maxR=2.3, const char *pipeName="Pipe")
Add beam pipe.
Int_t Z[3000]
LogMessage & dolog(LogMessage &)
static TGeoVolume * BuildAgata(const char *agataPath="./", const char *asolid="asolid", const char *aclust="aclust", const char *aeuler="aeuler", const char *baseclusname="agataCluster", const char *agataName="Agata")
For uniformity of names overload ImportAgata method.
Bool_t ReadTransformations(const TString fileName)
read transformations file
ADF::LogMessage & endl(ADF::LogMessage &log)
static TGeoVolume * ImportAgata(const char *asolid="asolid", const char *aclust="aclust", const char *aeuler="aeuler", const char *baseclusname="agataCluster", const char *agataName="Agata")
to import the agata geometry from the Agata world
static int BuildAgataClusters(const char *filename="aclust", const char *baseclusname="agataCluster", const char *basecrysname="gePoly")
to build agata clusters from a formatted text-file (aclust)
Int_t GetSectorId(Double_t x, Double_t y)
Get sector id from (x,y) position.
static int BuildAgataCrystals(const char *filename="asolid", const char *basecrysname="gePoly")
to build agata crytals from a formatted text-file (asolid)
Int_t GetDepthId(Double_t z)
Get sector depth from z position.
virtual void SetProcessMethod(const char *)
To set the current method.
static TGeoVolume * AddFloor(Float_t dx=20, const Float_t dy=0.1, const Float_t dz=25, const char *floorName="Floor")
Add floor.
void Local2Global(Int_t detID, Double_t xl, Double_t yl, Double_t zl, Double_t &xg, Double_t &yg, Double_t &zg) const
Transform point from the local reference frame of the detection id to the global reference frame...
static TGeoVolume * AddPrismaMWPC(const char *prismaName="PrismaMWPC", Float_t dzFcIc=72., Float_t dx=75., Float_t dy=10., Float_t dz=65., TGeoMaterial *mat=0x0)
Add Multi Wire Proportional Chamber (MWPC)