ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ML2AcceleratorConstruction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ML2AcceleratorConstruction.cc
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 
43 
46 #include "G4ios.hh"
47 #include "G4SystemOfUnits.hh"
48 
49 using namespace std;
50 
52 {
53  acceleratorConstructionMessenger = new CML2AcceleratorConstructionMessenger(this);
54  idCurrentRotationX = 0;
55 }
56 
58 {
59  delete acceleratorConstructionMessenger;
60 }
62 
64 {
65  if (instance == 0)
66  {
68  }
69  return instance;
70 }
71 
73 {
74  accelerator -> reset();
75 }
76 
78 {
79 // switch between different accelerators according to the main macro selection (actually only one accelerator is available)
80  G4cout << "I'm building " << AcceleratorName << " accelerator" << G4endl;
81  bool bAccExists = false;
82  if (AcceleratorName == "acc1")
83  {
84  accelerator = CML2Acc1::GetInstance();
85  bAccExists = true;
86  }
87  else if (AcceleratorName == "acc2")
88  {
89  accelerator = CML2Acc2::GetInstance();
90  bAccExists = true;
91  }
92  else if (AcceleratorName == "accSaturn")
93  {
94  accelerator = CML2AccSaturn::GetInstance();
95  bAccExists = true;
96  }
97 
98  if (bAccExists && AcceleratorMacFileName!="")
99  {
100  // read the messenger data related to the selected accelerator
102  G4String command = "/control/execute ";
103  UI->ApplyCommand(command+AcceleratorMacFileName);
104  }
105 
106  if (rotationsX.size() < 1)
107  {
108  addAcceleratorRotationsX(0.);
109  }
110 
111  return bAccExists;
112 }
114 {
115  // a call to select the right accelerator
116  bOnlyVisio = bOV;
117  if (design())
118  {
119 // G4cout << "*** debug *** AcceleratorConstruction::Construct" << G4endl;
120  acceleratorConstructionMessenger->SetReferenceWorld(bOnlyVisio);
121  // create the accelerator-world box
122  G4Material *Vacuum = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
123  G4ThreeVector halfSize;
124  initialCentre.set(0.*mm, 0.*mm, -isoCentre);
125  halfSize.set(600.*mm, 600.*mm, 600.*mm);
126  G4Box *accWorldB = new G4Box("accWorldG", halfSize.getX(), halfSize.getY(), halfSize.getZ());
127  G4LogicalVolume *accWorldLV = new G4LogicalVolume(accWorldB, Vacuum, "accWorldL", 0, 0, 0);
128  G4VisAttributes* simpleAlSVisAtt = new G4VisAttributes(G4Colour::White());
129  simpleAlSVisAtt -> SetVisibility(false);
130  accWorldLV -> SetVisAttributes(simpleAlSVisAtt);
131 
132  PVAccWorld= new G4PVPlacement(0, initialCentre, "acceleratorBox", accWorldLV, PVWorld, false, 0);
133 
134  // create the actual accelerator
135  accelerator -> Construct(PVAccWorld, isoCentre);
136  Z_Value_PhaseSpaceBeforeJaws = accelerator -> getBeforeJaws_Z_PhaseSpacePosition();
137  accelerator -> writeInfo();
138 
139  }
140  else
141  {
142  return false;
143  }
144  return true;
145 }
146 
148 {
149  if (!bOnlyVisio)
150  {
151  G4cout << "Actual rotation: " << idCurrentRotationX << "/" << rotationsX.size() << " " << G4endl;
152  }
153  G4cout << "Accelerator angle: " << currentRotationX/deg << " [deg]" << G4endl;
154 }
155 
157 {
158  G4RotationMatrix *rmInv=new G4RotationMatrix();
159  if (idCurrentRotationX <(int) rotationsX.size())
160  {
161  currentRotationX = rotationsX[idCurrentRotationX];
162  rmInv = rotateAccelerator(currentRotationX);
163  idCurrentRotationX++;
164  }
165  else
166  {
167  rmInv = 0;
168  }
169  return rmInv;
170 }
172 {
173  currentRotationX = angleX;
175  G4ThreeVector NewCentre;
177  G4RotationMatrix *rmInv = new G4RotationMatrix();
178  PVAccWorld->SetTranslation(initialCentre);
179  PVAccWorld->SetRotation(rm);
180  if (bRotate90Y)
181  {
182  rm->rotateY(90.*deg);
183  }
184  rm->rotateX(-angleX);
185  PVAccWorld->SetRotation(rm);
186  *rmInv=CLHEP::inverseOf(*rm);
187  NewCentre=*rmInv*initialCentre;
188  PVAccWorld->SetTranslation(NewCentre);
191  return rmInv;
192 }
194 {
195  char cR[5];
196  G4int cRI=(G4int)((currentRotationX/deg)+.5);
197  sprintf(cR,"%d",cRI);
198  G4String rotationName=G4String(cR);
199  if (bRotate90Y)
200  {rotationName="_Ro90Y"+rotationName;}
201  else
202  {rotationName="_Ro"+rotationName;}
203  return rotationName;
204 }