create_target_CD2.C

Ivan Muzalevsky, 04/03/2018 05:02 PM

Download (3.84 KB)

 
1
#include <iomanip>
2
#include <iostream>
3
#include "TGeoManager.h"
4
#include "TMath.h"
5

    
6
void create_target_CD2() {
7

    
8
  // Create a zero rotation
9
  TGeoRotation *fZeroRotation = new TGeoRotation();
10
  fZeroRotation->RotateX(0.);
11
  fZeroRotation->RotateY(0.);
12
  fZeroRotation->RotateZ(0.);
13
  
14
  TGeoManager*   gGeoMan = NULL;
15

    
16
  // -------   Load media from media file   -----------------------------------
17
  FairGeoLoader*    geoLoad = new FairGeoLoader("TGeo","FairGeoLoader");
18
  FairGeoInterface* geoFace = geoLoad->getGeoInterface();
19
  TString geoPath = gSystem->Getenv("VMCWORKDIR");
20
  TString medFile = geoPath + "/geometry/media.geo";
21
  geoFace->setMediaFile(medFile);
22
  geoFace->readMedia();
23
  gGeoMan = gGeoManager;
24
  // --------------------------------------------------------------------------
25

    
26
  // -------   Geometry file name (output)   ----------------------------------
27
  TString geoFileName = geoPath + "/geometry/target_CD2_geo.root";
28
  // --------------------------------------------------------------------------
29
  
30
  // -----------------   Get and create the required media    -----------------
31
  FairGeoMedia* geoMedia = geoFace->getMedia();
32
  FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
33

    
34
  FairGeoMedium* mAlumin = geoMedia->getMedium("aluminium");
35
  if ( ! mAlumin ) Fatal("Main", "FairMedium Steel not found");
36
  geoBuild->createMedium(mAlumin);
37
  TGeoMedium* pAlumin = gGeoMan->GetMedium("aluminium");
38
  if ( ! pAlumin ) Fatal("Main", "Medium aluminium not found");
39
  
40
  FairGeoMedium* poli = geoMedia->getMedium("CD2_CH2");
41
  if ( ! poli ) Fatal("Main", "FairMedium CD2_CH2 not found");
42
  geoBuild->createMedium(poli);
43
  TGeoMedium* pPoli = gGeoMan->GetMedium("CD2_CH2");
44
  if ( ! pPoli ) Fatal("Main", "Medium CD2_CH2 not found");
45
  // --------------------------------------------------------------------------
46
  
47
  //------------------------- VOLUMES -----------------------------------------
48
  
49
  // --------------   Create geometry and top volume  -------------------------
50
  gGeoMan = (TGeoManager*)gROOT->FindObject("FAIRGeom");
51
  gGeoMan->SetName("DETgeom");
52
  TGeoVolume* top = new TGeoVolumeAssembly("TOP");
53
  gGeoMan->SetTopVolume(top);
54
  TGeoVolume* target = new TGeoVolumeAssembly("target");
55
  // --------------------------------------------------------------------------
56
  // frame of aluminium
57
  Double_t box_X,box_Y,box_Z; // box of steel
58

    
59
  box_X = 6.; //cm
60
  box_Y = 6.; //cm
61
  box_Z = 0.1; //cm
62
  
63
  box_X /= 2.;
64
  box_Y /= 2.;
65
  box_Z /= 2.;
66
  // --------------------------------------------------------------------------
67
  TGeoBBox box1 = TGeoBBox("box1", box_X, box_Y, box_Z);
68
  TGeoBBox box2 = TGeoBBox("box2", box_X - 1./2., box_Y - 1./2., box_Z);
69

    
70
  TGeoCompositeShape *frame = new TGeoCompositeShape("frame", "box1 - box2");
71
  TGeoVolume* frameAL = new TGeoVolume("frameAL", frame, pAlumin);
72
  // --------------------------------------------------------------------------
73

    
74
  TGeoVolume *boxCD = gGeoManager->MakeBox("boxCD", pPoli, box_X, box_Y, 1e-3);
75

    
76
  // --------------------------------------------------------------------------
77
  Double_t trans_X, trans_Y, trans_Z;
78
  trans_Z = 0.05 + 1e-3;
79
  // --------------------------------------------------------------------------
80
  target->AddNode(frameAL, 0, new TGeoCombiTrans(0.,0.,trans_Z, fZeroRotation));
81
  target->AddNode(frameAL, 0, new TGeoCombiTrans(0.,0.,-trans_Z, fZeroRotation));
82
  target->AddNode(boxCD, 0, new TGeoCombiTrans(0.,0.,0., fZeroRotation));
83
  top->AddNode(target,0,new TGeoCombiTrans(.0,.0,.0, fZeroRotation));
84
  // --------------------------------------------------------------------------
85
  gGeoMan->CloseGeometry();
86
  //gGeoMan->CheckOverlaps(0.001);
87
  gGeoMan->CheckGeometryFull();
88
  gGeoMan->PrintOverlaps();
89
  gGeoMan->Test();
90

    
91
  TFile* geoFile = new TFile(geoFileName, "RECREATE");
92
  top->Write();
93
  geoFile->Close();
94
  // --------------------------------------------------------------------------
95
} 
96