Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ML2AcceleratorConstruction.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // The code was written by :
27 // ^Claudio Andenna claudio.andenna@ispesl.it, claudio.andenna@iss.infn.it
28 // *Barbara Caccia barbara.caccia@iss.it
29 // with the support of Pablo Cirrone (LNS, INFN Catania Italy)
30 // with the contribute of Alessandro Occhigrossi*
31 //
32 // ^INAIL DIPIA - ex ISPESL and INFN Roma, gruppo collegato Sanità, Italy
33 // *Istituto Superiore di Sanità and INFN Roma, gruppo collegato Sanità, Italy
34 // Viale Regina Elena 299, 00161 Roma (Italy)
35 // tel (39) 06 49902246
36 // fax (39) 06 49387075
37 //
38 // more information:
39 // http://g4advancedexamples.lngs.infn.it/Examples/medical-linac
40 //
41 //*******************************************************//
42 
45 #include "G4SystemOfUnits.hh"
46 
48 {
49  acceleratorConstructionMessenger=new CML2AcceleratorConstructionMessenger(this);
50  idCurrentRotationX=0;
51 }
52 
54 {
55  if (AcceleratorName=="acc1")
56  {delete accelerator1;}
57 
58  delete PVAccWorld;
59  delete acceleratorConstructionMessenger;
60 }
61 CML2AcceleratorConstruction* CML2AcceleratorConstruction::instance = 0;
62 
64 {
65  if (instance == 0)
66  {
67  instance = new CML2AcceleratorConstruction();
68  }
69  return instance;
70 }
71 
73 {
74  if (AcceleratorName=="acc1")
75  {
76  accelerator1->reset();
77  }
78 
79 }
80 
81 bool CML2AcceleratorConstruction::design(void)
82 {
83 // switch between different accelerators according to the main macro selection (actually only one accelerator is available)
84  std::cout << "I'm building "<< AcceleratorName<<" accelerator"<< G4endl;
85  bool bAccExists=false;
86  if (AcceleratorName=="acc1")
87  {accelerator1=CML2Acc1::GetInstance();bAccExists=true;}
88 
89  if (bAccExists && AcceleratorMacFileName!="")
90  {
91  // read the messenger data related to the accelerator selected
93  G4String command = "/control/execute ";
94  UI->ApplyCommand(command+AcceleratorMacFileName);
95  }
96 
97  if (rotationsX.size()<1)
99 
100  return bAccExists;
101 }
103 {
104 // a call to select the right accelerator
105  bOnlyVisio=bOV;
106  if (design())
107  {
108  acceleratorConstructionMessenger->SetReferenceWorld(bOnlyVisio);
109  // create the accelerator-world box
110  G4Material *Vacuum=G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
111  G4ThreeVector halfSize;
112  initialCentre.set(0.*mm, 0.*mm, -isoCentre);
113  halfSize.set(600.*mm, 600.*mm, 600.*mm);
114  G4Box *accWorldB = new G4Box("accWorldG", halfSize.getX(), halfSize.getY(), halfSize.getZ());
115  G4LogicalVolume *accWorldLV = new G4LogicalVolume(accWorldB, Vacuum, "accWorldL", 0, 0, 0);
116  G4VisAttributes* simpleAlSVisAtt= new G4VisAttributes(G4Colour::White());
117  simpleAlSVisAtt->SetVisibility(false);
118 // simpleAlSVisAtt->SetForceWireframe(false);
119  accWorldLV->SetVisAttributes(simpleAlSVisAtt);
120 
121  PVAccWorld= new G4PVPlacement(0, initialCentre, "acceleratorBox", accWorldLV, PVWorld, false, 0);
122 
123  // create the actual accelerator
124  if (AcceleratorName=="acc1")
125  {
126  accelerator1->Construct(PVAccWorld, isoCentre);
127  Z_Value_PhaseSpaceBeforeJaws=accelerator1->getBeforeJaws_Z_PhaseSpacePosition();
128  accelerator1->writeInfo();
129  }
130  }
131  else
132  {
133  return false;
134  }
135  return true;
136 }
137 
139 {
140  if (!bOnlyVisio)
141  {std::cout <<"Actual rotation: "<<idCurrentRotationX<<"/"<<rotationsX.size() <<" "<< G4endl;}
142  std::cout <<"Accelerator angle: "<< currentRotationX/deg << " [deg]"<< G4endl;
143 }
144 
146 {
147  G4RotationMatrix *rmInv=new G4RotationMatrix();
148  if (idCurrentRotationX <(int) rotationsX.size())
149  {
150  currentRotationX=rotationsX[idCurrentRotationX];
151  rmInv=rotateAccelerator(currentRotationX);
152  idCurrentRotationX++;
153  }
154  else
155  {rmInv=0;}
156  return rmInv;
157 }
159 {
160  currentRotationX=angleX;
162  G4ThreeVector NewCentre;
164  G4RotationMatrix *rmInv=new G4RotationMatrix();
165  PVAccWorld->SetTranslation(initialCentre);
166  PVAccWorld->SetRotation(rm);
167  if (bRotate90Y) {rm->rotateY(90.*deg);}
168  rm->rotateX(-angleX);
169  PVAccWorld->SetRotation(rm);
170  *rmInv=CLHEP::inverseOf(*rm);
171  NewCentre=*rmInv*initialCentre;
172  PVAccWorld->SetTranslation(NewCentre);
175  return rmInv;
176 }
178 {
179  char cR[5];
180  G4int cRI=(G4int)((currentRotationX/deg)+.5);
181  sprintf(cR,"%d",cRI);
182  G4String rotationName=G4String(cR);
183  if (bRotate90Y)
184  {rotationName="_Ro90Y"+rotationName;}
185  else
186  {rotationName="_Ro"+rotationName;}
187  return rotationName;
188 }