| File: | beast/ph1sustr/geometry/src/Ph1sustrCreator.cc |
| Warning: | line 539, column 32 Potential leak of memory pointed to by 'l_bgobeamb' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /************************************************************************** | |||
| 2 | * basf2 (Belle II Analysis Software Framework) * | |||
| 3 | * Author: The Belle II Collaboration * | |||
| 4 | * * | |||
| 5 | * See git log for contributors and copyright holders. * | |||
| 6 | * This file is licensed under LGPL-3.0, see LICENSE.md. * | |||
| 7 | **************************************************************************/ | |||
| 8 | ||||
| 9 | #include <beast/ph1sustr/geometry/Ph1sustrCreator.h> | |||
| 10 | #include <beast/ph1sustr/simulation/SensitiveDetector.h> | |||
| 11 | ||||
| 12 | #include <geometry/Materials.h> | |||
| 13 | #include <geometry/CreatorFactory.h> | |||
| 14 | #include <framework/gearbox/GearDir.h> | |||
| 15 | #include <framework/logging/Logger.h> | |||
| 16 | ||||
| 17 | #include <cmath> | |||
| 18 | ||||
| 19 | #include <G4LogicalVolume.hh> | |||
| 20 | #include <G4PVPlacement.hh> | |||
| 21 | ||||
| 22 | //Shapes | |||
| 23 | #include <G4Box.hh> | |||
| 24 | #include "G4UnionSolid.hh" | |||
| 25 | #include "G4SubtractionSolid.hh" | |||
| 26 | ||||
| 27 | //Visualization | |||
| 28 | #include "G4Colour.hh" | |||
| 29 | #include <G4VisAttributes.hh> | |||
| 30 | ||||
| 31 | using namespace std; | |||
| 32 | ||||
| 33 | namespace Belle2 { | |||
| 34 | ||||
| 35 | /** Namespace to encapsulate code needed for simulation and reconstrucion of the PH1SUSTR detector */ | |||
| 36 | namespace ph1sustr { | |||
| 37 | ||||
| 38 | // Register the creator | |||
| 39 | /** Creator creates the phase 1 support structure geometry */ | |||
| 40 | geometry::CreatorFactory<Ph1sustrCreator> Ph1sustrFactory("PH1SUSTRCreator"); | |||
| 41 | ||||
| 42 | Ph1sustrCreator::Ph1sustrCreator(): m_sensitive(0) | |||
| 43 | { | |||
| 44 | //m_sensitive = new SensitiveDetector(); | |||
| 45 | } | |||
| 46 | ||||
| 47 | Ph1sustrCreator::~Ph1sustrCreator() | |||
| 48 | { | |||
| 49 | if (m_sensitive) delete m_sensitive; | |||
| 50 | } | |||
| 51 | ||||
| 52 | void Ph1sustrCreator::create(const GearDir& content, G4LogicalVolume& topVolume, geometry::GeometryTypes /* type */) | |||
| 53 | { | |||
| 54 | ||||
| 55 | m_sensitive = new SensitiveDetector(); | |||
| 56 | ||||
| 57 | //lets get the stepsize parameter with a default value of 5 µm | |||
| 58 | //double stepSize = content.getLength("stepSize", 5 * CLHEP::um); | |||
| 59 | ||||
| 60 | ||||
| 61 | //no get the array. Notice that the default framework unit is cm, so the | |||
| 62 | //values will be automatically converted | |||
| 63 | vector<double> bar = content.getArray("bar"); | |||
| 64 | B2INFO("Contents of bar: ")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2:: LogConfig::c_Info, 0, "beast")) { { LogVariableStream varStream ; varStream << "Contents of bar: "; Belle2::LogSystem:: Instance().sendMessage(Belle2::LogMessage(Belle2::LogConfig:: c_Info, std::move(varStream), "beast", __PRETTY_FUNCTION__, "beast/ph1sustr/geometry/src/Ph1sustrCreator.cc" , 64, 0)); }; } } while(false); | |||
| ||||
| 65 | for (double value : bar) { | |||
| 66 | B2INFO("value: " << value)do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2:: LogConfig::c_Info, 0, "beast")) { { LogVariableStream varStream ; varStream << "value: " << value; Belle2::LogSystem ::Instance().sendMessage(Belle2::LogMessage(Belle2::LogConfig ::c_Info, std::move(varStream), "beast", __PRETTY_FUNCTION__, "beast/ph1sustr/geometry/src/Ph1sustrCreator.cc", 66, 0)); } ; } } while(false); | |||
| 67 | } | |||
| 68 | /*double x_tpcbeamR = 0; | |||
| 69 | double y_tpcbeamR = 0; | |||
| 70 | double z_tpcbeamR = 0; | |||
| 71 | double x_tpcbeamL = 0; | |||
| 72 | double y_tpcbeamL = 0; | |||
| 73 | double z_tpcbeamL = 0; | |||
| 74 | double x_tpcbeamT = 0; | |||
| 75 | double y_tpcbeamT = 0; | |||
| 76 | double z_tpcbeamT = 0; | |||
| 77 | double x_tpcbeamB = 0; | |||
| 78 | double y_tpcbeamB = 0; | |||
| 79 | double z_tpcbeamB = 0;*/ | |||
| 80 | //Lets loop over all the Active nodes | |||
| 81 | for (const GearDir& activeParams : content.getNodes("Active")) { | |||
| 82 | ||||
| 83 | //plate positions | |||
| 84 | double x_tpcbeamR = activeParams.getLength("x_tpcbeamR") * CLHEP::cm; | |||
| 85 | double y_tpcbeamR = activeParams.getLength("y_tpcbeamR") * CLHEP::cm; | |||
| 86 | double z_tpcbeamR = activeParams.getLength("z_tpcbeamR") * CLHEP::cm; | |||
| 87 | double x_tpcbeamL = activeParams.getLength("x_tpcbeamL") * CLHEP::cm; | |||
| 88 | double y_tpcbeamL = activeParams.getLength("y_tpcbeamL") * CLHEP::cm; | |||
| 89 | double z_tpcbeamL = activeParams.getLength("z_tpcbeamL") * CLHEP::cm; | |||
| 90 | double x_tpcbeamT = activeParams.getLength("x_tpcbeamT") * CLHEP::cm; | |||
| 91 | double y_tpcbeamT = activeParams.getLength("y_tpcbeamT") * CLHEP::cm; | |||
| 92 | double z_tpcbeamT = activeParams.getLength("z_tpcbeamT") * CLHEP::cm; | |||
| 93 | double x_tpcbeamB = activeParams.getLength("x_tpcbeamB") * CLHEP::cm; | |||
| 94 | double y_tpcbeamB = activeParams.getLength("y_tpcbeamB") * CLHEP::cm; | |||
| 95 | double z_tpcbeamB = activeParams.getLength("z_tpcbeamB") * CLHEP::cm; | |||
| 96 | ||||
| 97 | //TPC vertical: 4x @ 1614/ea | |||
| 98 | //TPC horizontal + BGO base: 8x @ 1583/ea | |||
| 99 | //TPC railroad: 8x @ 2200/ea | |||
| 100 | //BGO vertical: 4x @ 928/ea | |||
| 101 | //BGO horizontal: 4x @ 318/ea | |||
| 102 | //G4double dz_20V2100bgov = 843.72 / 2.*CLHEP::mm; | |||
| 103 | //G4double dz_20V2100bgoh = 280.00 / 2.*CLHEP::mm; | |||
| 104 | ||||
| 105 | //Beam supporting the TPC-Tube-plate | |||
| 106 | //define tpc beam and plate dimensions | |||
| 107 | double betpcbeam = 190.8 / 2. * CLHEP::mm; | |||
| 108 | G4double dx_tpcbeam = 2.54 * 1.63 / 2.*CLHEP::cm; | |||
| 109 | G4double dy_tpcbeam = 2.54 * 1.63 / 2.*CLHEP::cm; | |||
| 110 | G4double dz_tpcbeam = 2200. / 2.*CLHEP::mm; | |||
| 111 | G4double dw_tpcbeam = 2.54 * 0.25 / 2.*CLHEP::cm; | |||
| 112 | //G4double dx_plate = 2.54 * 0.35 / 2.*CLHEP::cm; | |||
| 113 | ||||
| 114 | //G4double dx_plate_short = 0.4765 * CLHEP::cm; | |||
| 115 | G4double dx_plate_short = 0.5 / 2. * CLHEP::cm; | |||
| 116 | G4double dy_plate_short = 27.47788 / 2.*CLHEP::cm; | |||
| 117 | G4double dz_plate_short = 40. / 2.*CLHEP::cm; | |||
| 118 | ||||
| 119 | G4double dx_plate = 0.5 / 2. * CLHEP::cm; | |||
| 120 | G4double dy_plate = 32. / 2.*CLHEP::cm; | |||
| 121 | G4double dz_plate = 50. / 2.*CLHEP::cm; | |||
| 122 | ||||
| 123 | //Right from e^-~--~beam | |||
| 124 | //create plate volume | |||
| 125 | G4VSolid* s_plate = new G4Box("s_plate", dx_plate, dy_plate, dz_plate); | |||
| 126 | G4VSolid* s_plate_short = new G4Box("s_plate_short", dx_plate_short, dy_plate_short, dz_plate_short); | |||
| 127 | ||||
| 128 | //place plate volume | |||
| 129 | G4LogicalVolume* l_plate = new G4LogicalVolume(s_plate, geometry::Materials::get("Al"), "l_plate", 0, 0); | |||
| 130 | G4LogicalVolume* l_plate_short = new G4LogicalVolume(s_plate_short, geometry::Materials::get("Al"), "l_plate_short", 0, 0); | |||
| 131 | G4VisAttributes* white = new G4VisAttributes(G4Colour(1, 1, 1)); | |||
| 132 | white->SetForceAuxEdgeVisible(true); | |||
| 133 | l_plate->SetVisAttributes(white); | |||
| 134 | l_plate_short->SetVisAttributes(white); | |||
| 135 | ||||
| 136 | G4VSolid* s_tpcbeam_a = new G4Box("s_tpcbeam_a", dx_tpcbeam, dy_tpcbeam, dz_tpcbeam); | |||
| 137 | G4VSolid* s_tpcbeam_b = new G4Box("s_tpcbeam_b", dx_tpcbeam - 2.*dw_tpcbeam, dy_tpcbeam - dw_tpcbeam, dz_tpcbeam); | |||
| 138 | G4VSolid* s_tpcbeampos = new G4SubtractionSolid("s_tpcbeampos", s_tpcbeam_a, s_tpcbeam_b, 0, G4ThreeVector(0, dw_tpcbeam, 0)); | |||
| 139 | G4VSolid* s_tpcbeamneg = new G4SubtractionSolid("s_tpcbeamneg", s_tpcbeam_a, s_tpcbeam_b, 0, G4ThreeVector(0, -dw_tpcbeam, 0)); | |||
| 140 | G4VSolid* s_tpcbeam = new G4UnionSolid("s_tpcbeam", s_tpcbeampos, s_tpcbeamneg, 0, G4ThreeVector(0, -2.*dy_tpcbeam, 0)); | |||
| 141 | ||||
| 142 | //create tpc beam volumes | |||
| 143 | G4LogicalVolume* l_tpcbeam = new G4LogicalVolume(s_tpcbeam, geometry::Materials::get("FG_Epoxy"), "l_tpcbeam", 0, 0); | |||
| 144 | ||||
| 145 | //place plate volume | |||
| 146 | G4ThreeVector PH1SUSTRpos = G4ThreeVector( | |||
| 147 | x_tpcbeamR, | |||
| 148 | y_tpcbeamR, | |||
| 149 | z_tpcbeamR | |||
| 150 | ); | |||
| 151 | new G4PVPlacement(0, PH1SUSTRpos, l_plate, "p_plateR", &topVolume, false, 1); | |||
| 152 | ||||
| 153 | //offsets hori | |||
| 154 | //G4double offset_h = /*110.*CLHEP::cm*/dz_tpcbeam + /*80.*CLHEP::cm*/ dz_plate - 2. * dz_tpcbeam; | |||
| 155 | G4double offset_h = /*110.*CLHEP::cm*/dz_tpcbeam + 80.*CLHEP::cm - 2. * dz_tpcbeam; | |||
| 156 | ||||
| 157 | //place 1st tpc beam volume | |||
| 158 | /*PH1SUSTRpos = G4ThreeVector( | |||
| 159 | x_tpcbeamR + dx_plate + dx_tpcbeam, | |||
| 160 | y_tpcbeamR + betpcbeam + 2. * dy_tpcbeam, | |||
| 161 | -offset_h / 2. | |||
| 162 | ); | |||
| 163 | new G4PVPlacement(0, PH1SUSTRpos, l_tpcbeam, "p_tpcbeam", &topVolume, false, 1);*/ | |||
| 164 | G4Transform3D TransForm = G4Translate3D(x_tpcbeamR + dx_plate + dx_tpcbeam, | |||
| 165 | y_tpcbeamR + betpcbeam + 2. * dy_tpcbeam, | |||
| 166 | -offset_h / 2.) * G4RotateZ3D(90.*CLHEP::deg); | |||
| 167 | new G4PVPlacement(TransForm, l_tpcbeam, "p_tpcbeamR1", &topVolume, false, 1); | |||
| 168 | ||||
| 169 | //place 2nd tpc beam volume | |||
| 170 | /*PH1SUSTRpos = G4ThreeVector( | |||
| 171 | x_tpcbeamR + dx_plate + dx_tpcbeam, | |||
| 172 | y_tpcbeamR - betpcbeam - 2. * dy_tpcbeam, | |||
| 173 | -offset_h / 2. | |||
| 174 | ); | |||
| 175 | new G4PVPlacement(0, PH1SUSTRpos, l_tpcbeam, "p_tpcbeam", &topVolume, false, 1);*/ | |||
| 176 | TransForm = G4Translate3D(x_tpcbeamR + dx_plate + dx_tpcbeam, | |||
| 177 | y_tpcbeamR - betpcbeam - 2. * dy_tpcbeam, | |||
| 178 | -offset_h / 2.) * G4RotateZ3D(90.*CLHEP::deg); | |||
| 179 | new G4PVPlacement(TransForm, l_tpcbeam, "p_tpcbeamR2", &topVolume, false, 1); | |||
| 180 | ||||
| 181 | //Left from e^-~--~beam | |||
| 182 | //place plate volume | |||
| 183 | PH1SUSTRpos = G4ThreeVector( | |||
| 184 | x_tpcbeamL, | |||
| 185 | y_tpcbeamL, | |||
| 186 | z_tpcbeamL | |||
| 187 | ); | |||
| 188 | new G4PVPlacement(0, PH1SUSTRpos, l_plate, "p_plateL", &topVolume, false, 1); | |||
| 189 | ||||
| 190 | //place 1st tpc beam volume | |||
| 191 | /*PH1SUSTRpos = G4ThreeVector( | |||
| 192 | x_tpcbeamL - dx_plate - dx_tpcbeam, | |||
| 193 | y_tpcbeamL + betpcbeam + 2. * dy_tpcbeam, | |||
| 194 | -offset_h / 2. | |||
| 195 | ); | |||
| 196 | new G4PVPlacement(0, PH1SUSTRpos, l_tpcbeam, "p_tpcbeam", &topVolume, false, 1);*/ | |||
| 197 | TransForm = G4Translate3D(x_tpcbeamL - dx_plate - 3. * dx_tpcbeam, | |||
| 198 | y_tpcbeamL + betpcbeam + 2. * dy_tpcbeam, | |||
| 199 | -offset_h / 2.) * G4RotateZ3D(90.*CLHEP::deg); | |||
| 200 | new G4PVPlacement(TransForm, l_tpcbeam, "p_tpcbeamL1", &topVolume, false, 1); | |||
| 201 | ||||
| 202 | //place 2nd tpc beam volume | |||
| 203 | /*PH1SUSTRpos = G4ThreeVector( | |||
| 204 | x_tpcbeamL - dx_plate - dx_tpcbeam, | |||
| 205 | y_tpcbeamL - betpcbeam - 2. * dy_tpcbeam, | |||
| 206 | -offset_h / 2. | |||
| 207 | ); | |||
| 208 | new G4PVPlacement(0, PH1SUSTRpos, l_tpcbeam, "p_tpcbeam", &topVolume, false, 1);*/ | |||
| 209 | TransForm = G4Translate3D(x_tpcbeamL - dx_plate - 3. * dx_tpcbeam, | |||
| 210 | y_tpcbeamL - betpcbeam - 2. * dy_tpcbeam, | |||
| 211 | -offset_h / 2.) * G4RotateZ3D(90.*CLHEP::deg); | |||
| 212 | new G4PVPlacement(TransForm, l_tpcbeam, "p_tpcbeamL2", &topVolume, false, 1); | |||
| 213 | ||||
| 214 | //Bottom | |||
| 215 | G4RotationMatrix* rotXx = new G4RotationMatrix(); | |||
| 216 | double Angle = 90. * CLHEP::deg; | |||
| 217 | rotXx->rotateZ(Angle); | |||
| 218 | //place bottom plate | |||
| 219 | PH1SUSTRpos = G4ThreeVector( | |||
| 220 | x_tpcbeamB, | |||
| 221 | y_tpcbeamB, | |||
| 222 | z_tpcbeamB | |||
| 223 | ); | |||
| 224 | new G4PVPlacement(rotXx, PH1SUSTRpos, l_plate_short, "p_plateB", &topVolume, false, 1); | |||
| 225 | ||||
| 226 | //place 1st tpc beam volume | |||
| 227 | /*PH1SUSTRpos = G4ThreeVector( | |||
| 228 | x_tpcbeamB + betpcbeam + 2. * dx_tpcbeam, | |||
| 229 | y_tpcbeamB - dx_plate - dy_tpcbeam, | |||
| 230 | -offset_h / 2. | |||
| 231 | ); | |||
| 232 | new G4PVPlacement(rotXx, PH1SUSTRpos, l_tpcbeam, "p_tpcbeam", &topVolume, false, 1);*/ | |||
| 233 | TransForm = G4Translate3D(x_tpcbeamB + betpcbeam + 1.5 * dx_tpcbeam, | |||
| 234 | y_tpcbeamB - dx_plate - 1.5 * dy_tpcbeam, | |||
| 235 | -offset_h / 2.) /* G4RotateZ3D(90.*CLHEP::deg)*/; | |||
| 236 | new G4PVPlacement(TransForm, l_tpcbeam, "p_tpcbeamB1", &topVolume, false, 1); | |||
| 237 | ||||
| 238 | //place 2nd tpc beam volume | |||
| 239 | /*PH1SUSTRpos = G4ThreeVector( | |||
| 240 | x_tpcbeamB - betpcbeam - 2. * dx_tpcbeam, | |||
| 241 | y_tpcbeamB - dx_plate - dy_tpcbeam, | |||
| 242 | -offset_h / 2. | |||
| 243 | ); | |||
| 244 | new G4PVPlacement(rotXx, PH1SUSTRpos, l_tpcbeam, "p_tpcbeam", &topVolume, false, 1);*/ | |||
| 245 | TransForm = G4Translate3D(x_tpcbeamB - betpcbeam - 1.5 * dx_tpcbeam, | |||
| 246 | y_tpcbeamB - dx_plate - 1.5 * dy_tpcbeam, | |||
| 247 | -offset_h / 2.) /* G4RotateZ3D(90.*CLHEP::deg)*/; | |||
| 248 | new G4PVPlacement(TransForm, l_tpcbeam, "p_tpcbeamB2", &topVolume, false, 1); | |||
| 249 | ||||
| 250 | //Top | |||
| 251 | //rotXx = new G4RotationMatrix(); | |||
| 252 | //rotXx->rotateZ( 90. ); | |||
| 253 | //place top plate | |||
| 254 | PH1SUSTRpos = G4ThreeVector( | |||
| 255 | x_tpcbeamT, | |||
| 256 | y_tpcbeamT, | |||
| 257 | z_tpcbeamT | |||
| 258 | ); | |||
| 259 | new G4PVPlacement(rotXx, PH1SUSTRpos, l_plate, "p_plateT", &topVolume, false, 1); | |||
| 260 | ||||
| 261 | //place 1st tpc beam volume | |||
| 262 | /*PH1SUSTRpos = G4ThreeVector( | |||
| 263 | x_tpcbeamT + betpcbeam + 2. * dx_tpcbeam, | |||
| 264 | y_tpcbeamT + dx_plate + dy_tpcbeam, | |||
| 265 | -offset_h / 2. | |||
| 266 | ); | |||
| 267 | new G4PVPlacement(rotXx, PH1SUSTRpos, l_tpcbeam, "p_tpcbeam", &topVolume, false, 1);*/ | |||
| 268 | TransForm = G4Translate3D(x_tpcbeamT + betpcbeam + 1.5 * dx_tpcbeam, | |||
| 269 | y_tpcbeamT + dx_plate + 3. * dy_tpcbeam, | |||
| 270 | -offset_h / 2.) /* G4RotateZ3D(90.*CLHEP::deg)*/; | |||
| 271 | new G4PVPlacement(TransForm, l_tpcbeam, "p_tpcbeamT1", &topVolume, false, 1); | |||
| 272 | ||||
| 273 | //place 2nd tpc beam volume | |||
| 274 | /*PH1SUSTRpos = G4ThreeVector( | |||
| 275 | x_tpcbeamT - betpcbeam - 2. * dx_tpcbeam, | |||
| 276 | y_tpcbeamT + dx_plate + dy_tpcbeam, | |||
| 277 | -offset_h / 2. | |||
| 278 | ); | |||
| 279 | new G4PVPlacement(rotXx, PH1SUSTRpos, l_tpcbeam, "p_tpcbeam", &topVolume, false, 1);*/ | |||
| 280 | TransForm = G4Translate3D(x_tpcbeamT - betpcbeam - 1.5 * dx_tpcbeam, | |||
| 281 | y_tpcbeamT + dx_plate + 3 * dy_tpcbeam, | |||
| 282 | -offset_h / 2.) /* G4RotateZ3D(90.*CLHEP::deg)*/; | |||
| 283 | new G4PVPlacement(TransForm, l_tpcbeam, "p_tpcbeamT2", &topVolume, false, 1); | |||
| 284 | ||||
| 285 | //vertical beams | |||
| 286 | //G4double dz_tpcbeamv = 1537.37 / 2.*CLHEP::mm; | |||
| 287 | G4double dz_tpcbeamv = 1583. / 2.*CLHEP::mm; | |||
| 288 | G4VSolid* s_tpcbeamv_a = new G4Box("s_tpcbeamv_a", dx_tpcbeam, dy_tpcbeam, dz_tpcbeamv); | |||
| 289 | G4VSolid* s_tpcbeamv_b = new G4Box("s_tpcbeamv_b", dx_tpcbeam - 2.*dw_tpcbeam, dy_tpcbeam - dw_tpcbeam, dz_tpcbeamv); | |||
| 290 | G4VSolid* s_tpcbeamvpos = new G4SubtractionSolid("s_tpcbeamvpos", s_tpcbeamv_a, s_tpcbeamv_b, 0, G4ThreeVector(0, dw_tpcbeam, 0)); | |||
| 291 | G4VSolid* s_tpcbeamvneg = new G4SubtractionSolid("s_tpcbeamvneg", s_tpcbeamv_a, s_tpcbeamv_b, 0, G4ThreeVector(0, -dw_tpcbeam, 0)); | |||
| 292 | G4VSolid* s_tpcbeamv = new G4UnionSolid("s_tpcbeamv", s_tpcbeamvpos, s_tpcbeamvneg, 0, G4ThreeVector(0, -2.*dy_tpcbeam, 0)); | |||
| 293 | G4LogicalVolume* l_tpcbeamv = new G4LogicalVolume(s_tpcbeamv, geometry::Materials::get("FG_Epoxy"), "l_tpcbeamv", 0, 0); | |||
| 294 | ||||
| 295 | //offset verti | |||
| 296 | //G4double offset_v = fabs(76.*CLHEP::cm - 2. * dz_tpcbeamv) / 2.; | |||
| 297 | G4double offset_v = fabs(110.*CLHEP::cm - 2. * dz_tpcbeamv) / 2.; | |||
| 298 | ||||
| 299 | //place 1st vertical TPC beam | |||
| 300 | G4RotationMatrix* rotX = new G4RotationMatrix(); | |||
| 301 | rotX->rotateX(90.*CLHEP::deg); | |||
| 302 | PH1SUSTRpos = G4ThreeVector( | |||
| 303 | x_tpcbeamL - dx_plate - 3 * dx_tpcbeam - 2.*dx_tpcbeam, | |||
| 304 | offset_v / 2., | |||
| 305 | -800.*CLHEP::mm | |||
| 306 | ); | |||
| 307 | new G4PVPlacement(rotX, PH1SUSTRpos, l_tpcbeamv, "p_tpcbeamv1", &topVolume, false, 0); | |||
| 308 | //place 2nd vertical TPC beam | |||
| 309 | PH1SUSTRpos = G4ThreeVector( | |||
| 310 | x_tpcbeamR + dx_plate + 3.*dx_tpcbeam + 2.*dx_tpcbeam, | |||
| 311 | offset_v / 2., | |||
| 312 | -800.*CLHEP::mm | |||
| 313 | ); | |||
| 314 | new G4PVPlacement(rotX, PH1SUSTRpos, l_tpcbeamv, "p_tpcbeamv2", &topVolume, false, 0); | |||
| 315 | //place 3rd vertical TPC beam | |||
| 316 | PH1SUSTRpos = G4ThreeVector( | |||
| 317 | x_tpcbeamL - dx_plate - 3.*dx_tpcbeam - 2.*dx_tpcbeam, | |||
| 318 | offset_v / 2., | |||
| 319 | 1100.*CLHEP::mm | |||
| 320 | ); | |||
| 321 | new G4PVPlacement(rotX, PH1SUSTRpos, l_tpcbeamv, "p_tpcbeamv3", &topVolume, false, 0); | |||
| 322 | //place 4th vertical TPC beam | |||
| 323 | PH1SUSTRpos = G4ThreeVector( | |||
| 324 | x_tpcbeamR + dx_plate + 3.*dx_tpcbeam + 2.*dx_tpcbeam, | |||
| 325 | offset_v / 2., | |||
| 326 | 1100.*CLHEP::mm | |||
| 327 | ); | |||
| 328 | new G4PVPlacement(rotX, PH1SUSTRpos, l_tpcbeamv, "p_tpcbeamv4", &topVolume, false, 0); | |||
| 329 | ||||
| 330 | //horizontal beams | |||
| 331 | //G4double dz_tpcbeamh = 1792. / 2.*CLHEP::mm; | |||
| 332 | G4double dz_tpcbeamh = 1614. / 2.*CLHEP::mm; | |||
| 333 | G4VSolid* s_tpcbeamh_a = new G4Box("s_tpcbeamh_a", dx_tpcbeam, dy_tpcbeam, dz_tpcbeamh); | |||
| 334 | G4VSolid* s_tpcbeamh_b = new G4Box("s_tpcbeamh_b", dx_tpcbeam - 2.*dw_tpcbeam, dy_tpcbeam - dw_tpcbeam, dz_tpcbeamh); | |||
| 335 | G4VSolid* s_tpcbeamhpos = new G4SubtractionSolid("s_tpcbeamhpos", s_tpcbeamh_a, s_tpcbeamh_b, 0, G4ThreeVector(0, dw_tpcbeam, 0)); | |||
| 336 | G4VSolid* s_tpcbeamhneg = new G4SubtractionSolid("s_tpcbeanhneg", s_tpcbeamh_a, s_tpcbeamh_b, 0, G4ThreeVector(0, -dw_tpcbeam, 0)); | |||
| 337 | G4VSolid* s_tpcbeamh = new G4UnionSolid("s_tpcbeamh", s_tpcbeamhpos, s_tpcbeamhneg, 0, G4ThreeVector(0, -2.*dy_tpcbeam, 0)); | |||
| 338 | ||||
| 339 | G4LogicalVolume* l_tpcbeamh = new G4LogicalVolume(s_tpcbeamh, geometry::Materials::get("FG_Epoxy"), "l_tpcbeamh", 0, 0); | |||
| 340 | ||||
| 341 | //place 1st horizontal TPC beam | |||
| 342 | G4RotationMatrix* rotY = new G4RotationMatrix(); | |||
| 343 | rotY->rotateY(90.*CLHEP::deg); | |||
| 344 | PH1SUSTRpos = G4ThreeVector( | |||
| 345 | 0 * CLHEP::mm, | |||
| 346 | y_tpcbeamB - dx_plate - 4. * dy_tpcbeam - 2. * dy_tpcbeam, | |||
| 347 | 1100.*CLHEP::mm - 2. * dy_tpcbeam | |||
| 348 | ); | |||
| 349 | new G4PVPlacement(rotY, PH1SUSTRpos, l_tpcbeamh, "p_tpcbeamh1", &topVolume, false, 0); | |||
| 350 | ||||
| 351 | //place 2nd horizontal TPC beam | |||
| 352 | PH1SUSTRpos = G4ThreeVector( | |||
| 353 | 0 * CLHEP::mm, | |||
| 354 | y_tpcbeamT + dx_plate + 5. * dy_tpcbeam + 2. * dy_tpcbeam, | |||
| 355 | 1100.*CLHEP::mm - 2. * dy_tpcbeam | |||
| 356 | ); | |||
| 357 | new G4PVPlacement(rotY, PH1SUSTRpos, l_tpcbeamh, "p_tpcbeamh2", &topVolume, false, 0); | |||
| 358 | ||||
| 359 | //place 3rd horizontal TPC beam | |||
| 360 | PH1SUSTRpos = G4ThreeVector( | |||
| 361 | 0 * CLHEP::mm, | |||
| 362 | y_tpcbeamB - dx_plate - 4. * dy_tpcbeam - 2. * dy_tpcbeam, | |||
| 363 | -800.*CLHEP::mm + 4. * dy_tpcbeam | |||
| 364 | ); | |||
| 365 | new G4PVPlacement(rotY, PH1SUSTRpos, l_tpcbeamh, "p_tpcbeamh3", &topVolume, false, 0); | |||
| 366 | ||||
| 367 | //place 4th horizontal TPC beam | |||
| 368 | PH1SUSTRpos = G4ThreeVector( | |||
| 369 | 0 * CLHEP::mm, | |||
| 370 | y_tpcbeamT + dx_plate + 5. * dy_tpcbeam + 2. * dy_tpcbeam, | |||
| 371 | -800.*CLHEP::mm + 4. * dy_tpcbeam | |||
| 372 | ); | |||
| 373 | new G4PVPlacement(rotY, PH1SUSTRpos, l_tpcbeamh, "p_tpcbeamh4", &topVolume, false, 0); | |||
| 374 | ||||
| 375 | G4VisAttributes* brown = new G4VisAttributes(G4Colour(.5, .5, 0)); | |||
| 376 | brown->SetForceAuxEdgeVisible(true); | |||
| 377 | l_tpcbeam->SetVisAttributes(brown); | |||
| 378 | l_tpcbeamv->SetVisAttributes(brown); | |||
| 379 | l_tpcbeamh->SetVisAttributes(brown); | |||
| 380 | ||||
| 381 | //CsI box beams | |||
| 382 | G4double dz_csibeamh = activeParams.getLength("lcsiBeamh") * CLHEP::cm / 2.; | |||
| 383 | G4VSolid* s_csibeamh_a = new G4Box("s_csibeamh_a", dx_tpcbeam, dy_tpcbeam, dz_csibeamh); | |||
| 384 | G4VSolid* s_csibeamh_b = new G4Box("s_csibeamh_b", dx_tpcbeam - 2.*dw_tpcbeam, dy_tpcbeam - dw_tpcbeam, dz_csibeamh); | |||
| 385 | G4VSolid* s_csibeamhpos = new G4SubtractionSolid("s_csibeamhpos", s_csibeamh_a, s_csibeamh_b, 0, G4ThreeVector(0, dw_tpcbeam, 0)); | |||
| 386 | G4VSolid* s_csibeamhneg = new G4SubtractionSolid("s_csibeamhneg", s_csibeamh_a, s_csibeamh_b, 0, G4ThreeVector(0, -dw_tpcbeam, 0)); | |||
| 387 | //G4VSolid* s_csibeamhpos = new G4SubtractionSolid("s_csibeamhpos", s_csibeamh_a, s_csibeamh_b, 0, G4ThreeVector(dw_tpcbeam, 0, 0)); | |||
| 388 | //G4VSolid* s_csibeamhneg = new G4SubtractionSolid("s_csibeamhneg", s_csibeamh_a, s_csibeamh_b, 0, G4ThreeVector(-dw_tpcbeam, 0, 0)); | |||
| 389 | G4VSolid* s_csibeamh = new G4UnionSolid("s_csibeamh", s_csibeamhpos, s_csibeamhneg, 0, G4ThreeVector(0, -2.*dy_tpcbeam, 0)); | |||
| 390 | G4LogicalVolume* l_csibeamh = new G4LogicalVolume(s_csibeamh, geometry::Materials::get("FG_Epoxy"), "l_csibeamh", 0, 0); | |||
| 391 | ||||
| 392 | double x_offset = activeParams.getLength("x_offset") * CLHEP::cm; | |||
| 393 | double y_offset = activeParams.getLength("y_offset") * CLHEP::cm; | |||
| 394 | ||||
| 395 | std::vector<double> xcsiBeamh = activeParams.getArray("xcsiBeamh", {0}); | |||
| 396 | std::vector<double> ycsiBeamh = activeParams.getArray("ycsiBeamh", {0}); | |||
| 397 | std::vector<double> zcsiBeamh = activeParams.getArray("zcsiBeamh", {0}); | |||
| 398 | for (unsigned int i = 0; i < xcsiBeamh.size(); ++i) { | |||
| 399 | xcsiBeamh[i] = xcsiBeamh[i] - x_offset; | |||
| 400 | ycsiBeamh[i] = ycsiBeamh[i] - y_offset; | |||
| 401 | G4Transform3D transform = G4Translate3D(xcsiBeamh[i], ycsiBeamh[i] - dy_tpcbeam, | |||
| 402 | zcsiBeamh[i] + 2. * dy_tpcbeam) * G4RotateY3D(90.*CLHEP::deg) * G4RotateZ3D(90.*CLHEP::deg); | |||
| 403 | new G4PVPlacement(transform, l_csibeamh, TString::Format("p_csibeamh1_%d", i).Data(), &topVolume, false, 1); | |||
| 404 | transform = G4Translate3D(xcsiBeamh[i], ycsiBeamh[i] + dy_tpcbeam, | |||
| 405 | zcsiBeamh[i] + 2. * dy_tpcbeam) * G4RotateY3D(90.*CLHEP::deg) * G4RotateZ3D(90.*CLHEP::deg); | |||
| 406 | new G4PVPlacement(transform, l_csibeamh, TString::Format("p_csibeamh2_%d", i).Data(), &topVolume, false, 1); | |||
| 407 | } | |||
| 408 | ||||
| 409 | G4double dz_csibeamvF = activeParams.getLength("lcsiBeamvF") * CLHEP::cm / 2.; | |||
| 410 | G4VSolid* s_csibeamvF_a = new G4Box("s_csibeamvF_a", dx_tpcbeam, dy_tpcbeam, dz_csibeamvF); | |||
| 411 | G4VSolid* s_csibeamvF_b = new G4Box("s_csibeamvF_b", dx_tpcbeam - 2.*dw_tpcbeam, dy_tpcbeam - dw_tpcbeam, dz_csibeamvF); | |||
| 412 | G4VSolid* s_csibeamvFpos = new G4SubtractionSolid("s_csibeamvFpos", s_csibeamvF_a, s_csibeamvF_b, 0, G4ThreeVector(0, dw_tpcbeam, | |||
| 413 | 0)); | |||
| 414 | G4VSolid* s_csibeamvFneg = new G4SubtractionSolid("s_csibeamvFneg", s_csibeamvF_a, s_csibeamvF_b, 0, G4ThreeVector(0, -dw_tpcbeam, | |||
| 415 | 0)); | |||
| 416 | G4VSolid* s_csibeamvF = new G4UnionSolid("s_csibeamvF", s_csibeamvFpos, s_csibeamvFneg, 0, G4ThreeVector(0, -2.*dy_tpcbeam, 0)); | |||
| 417 | G4LogicalVolume* l_csibeamvF = new G4LogicalVolume(s_csibeamvF, geometry::Materials::get("FG_Epoxy"), "l_csibeamvF", 0, 0); | |||
| 418 | ||||
| 419 | std::vector<double> xcsiBeamvF = | |||
| 420 | activeParams.getArray("xcsiBeamvF", {0}); | |||
| 421 | std::vector<double> ycsiBeamvF = | |||
| 422 | activeParams.getArray("ycsiBeamvF", {0}); | |||
| 423 | std::vector<double> zcsiBeamvF = | |||
| 424 | activeParams.getArray("zcsiBeamvF", {0}); | |||
| 425 | for (unsigned int i = 0; i < xcsiBeamvF.size(); ++i) { | |||
| 426 | xcsiBeamvF[i] = xcsiBeamvF[i] - x_offset; | |||
| 427 | ycsiBeamvF[i] = ycsiBeamvF[i] - y_offset; | |||
| 428 | PH1SUSTRpos = G4ThreeVector(xcsiBeamvF[i], ycsiBeamvF[i], zcsiBeamvF[i]); | |||
| 429 | new G4PVPlacement(rotX, PH1SUSTRpos, l_csibeamvF, TString::Format("p_csibeamvF_%d", i).Data(), &topVolume, false, 0); | |||
| 430 | } | |||
| 431 | ||||
| 432 | G4double dz_csibeamvB = activeParams.getLength("lcsiBeamvB") * CLHEP::cm / 2.; | |||
| 433 | G4VSolid* s_csibeamvB_a = new G4Box("s_csibeamvB_a", dx_tpcbeam, dy_tpcbeam, dz_csibeamvB); | |||
| 434 | G4VSolid* s_csibeamvB_b = new G4Box("s_csibeamvB_b", dx_tpcbeam - 2.*dw_tpcbeam, dy_tpcbeam - dw_tpcbeam, dz_csibeamvB); | |||
| 435 | G4VSolid* s_csibeamvBpos = new G4SubtractionSolid("s_csibeamvBpos", s_csibeamvB_a, s_csibeamvB_b, 0, G4ThreeVector(0, dw_tpcbeam, | |||
| 436 | 0)); | |||
| 437 | G4VSolid* s_csibeamvBneg = new G4SubtractionSolid("s_csibeamvBneg", s_csibeamvB_a, s_csibeamvB_b, 0, G4ThreeVector(0, -dw_tpcbeam, | |||
| 438 | 0)); | |||
| 439 | G4VSolid* s_csibeamvB = new G4UnionSolid("s_csibeamvB", s_csibeamvBpos, s_csibeamvBneg, 0, G4ThreeVector(0, -2.*dy_tpcbeam, 0)); | |||
| 440 | G4LogicalVolume* l_csibeamvB = new G4LogicalVolume(s_csibeamvB, geometry::Materials::get("FG_Epoxy"), "l_csibeamvB", 0, 0); | |||
| 441 | ||||
| 442 | std::vector<double> xcsiBeamvB = | |||
| 443 | activeParams.getArray("xcsiBeamvB", {0}); | |||
| 444 | std::vector<double> ycsiBeamvB = | |||
| 445 | activeParams.getArray("ycsiBeamvB", {0}); | |||
| 446 | std::vector<double> zcsiBeamvB = | |||
| 447 | activeParams.getArray("zcsiBeamvB", {0}); | |||
| 448 | for (unsigned int i = 0; i < xcsiBeamvB.size(); ++i) { | |||
| 449 | xcsiBeamvB[i] = xcsiBeamvB[i] - x_offset; | |||
| 450 | ycsiBeamvB[i] = ycsiBeamvB[i] - y_offset; | |||
| 451 | PH1SUSTRpos = G4ThreeVector(xcsiBeamvB[i], ycsiBeamvB[i], zcsiBeamvB[i]); | |||
| 452 | new G4PVPlacement(rotX, PH1SUSTRpos, l_csibeamvB, TString::Format("p_csibeamvB_%d", i).Data(), &topVolume, false, 0); | |||
| 453 | } | |||
| 454 | ||||
| 455 | G4double dz_base = activeParams.getLength("lBase") * CLHEP::cm / 2.; | |||
| 456 | G4VSolid* s_base_a = new G4Box("s_base_a", dx_tpcbeam, dy_tpcbeam, dz_base); | |||
| 457 | G4VSolid* s_base_b = new G4Box("s_base_b", dx_tpcbeam - 2.*dw_tpcbeam, dy_tpcbeam - dw_tpcbeam, dz_base); | |||
| 458 | G4VSolid* s_base = new G4SubtractionSolid("s_base", s_base_a, s_base_b, 0, G4ThreeVector(0, dw_tpcbeam, 0)); | |||
| 459 | G4LogicalVolume* l_base = new G4LogicalVolume(s_base, geometry::Materials::get("FG_Epoxy"), "l_base", 0, 0); | |||
| 460 | ||||
| 461 | std::vector<double> xBase = activeParams.getArray("xBase", {0}); | |||
| 462 | std::vector<double> yBase = activeParams.getArray("yBase", {0}); | |||
| 463 | std::vector<double> zBase = activeParams.getArray("zBase", {0}); | |||
| 464 | for (unsigned int i = 0; i < xBase.size(); ++i) { | |||
| 465 | xBase[i] = xBase[i] - x_offset; | |||
| 466 | yBase[i] = yBase[i] - y_offset; | |||
| 467 | PH1SUSTRpos = G4ThreeVector(xBase[i], yBase[i], zBase[i]); | |||
| 468 | new G4PVPlacement(0, PH1SUSTRpos, l_base, TString::Format("p_base_%d", i).Data(), &topVolume, false, 0); | |||
| 469 | } | |||
| 470 | ||||
| 471 | G4double dz_bgobeamv = activeParams.getLength("lbgoBeamv") * CLHEP::cm / 2.; | |||
| 472 | G4VSolid* s_bgobeamv_a = new G4Box("s_bgobeamv_a", dx_tpcbeam, dy_tpcbeam, dz_bgobeamv); | |||
| 473 | G4VSolid* s_bgobeamv_b = new G4Box("s_bgobeamv_b", dx_tpcbeam - 2.*dw_tpcbeam, dy_tpcbeam - dw_tpcbeam, dz_bgobeamv); | |||
| 474 | G4VSolid* s_bgobeamvpos = new G4SubtractionSolid("s_bgobeamvpos", s_bgobeamv_a, s_bgobeamv_b, 0, G4ThreeVector(0, dw_tpcbeam, 0)); | |||
| 475 | G4VSolid* s_bgobeamvneg = new G4SubtractionSolid("s_bgobeamvneg", s_bgobeamv_a, s_bgobeamv_b, 0, G4ThreeVector(0, -dw_tpcbeam, 0)); | |||
| 476 | G4VSolid* s_bgobeamv = new G4UnionSolid("s_bgobeamv", s_bgobeamvpos, s_bgobeamvneg, 0, G4ThreeVector(0, -2.*dy_tpcbeam, 0)); | |||
| 477 | G4LogicalVolume* l_bgobeamv = new G4LogicalVolume(s_bgobeamv, geometry::Materials::get("FG_Epoxy"), "l_bgobeamv", 0, 0); | |||
| 478 | ||||
| 479 | std::vector<double> xbgoBeamv = activeParams.getArray("xbgoBeamv", {0}); | |||
| 480 | std::vector<double> ybgoBeamv = activeParams.getArray("ybgoBeamv", {0}); | |||
| 481 | std::vector<double> zbgoBeamv = activeParams.getArray("zbgoBeamv", {0}); | |||
| 482 | for (unsigned int i = 0; i < xbgoBeamv.size(); ++i) { | |||
| 483 | ybgoBeamv[i] = ybgoBeamv[i] - y_offset; | |||
| 484 | PH1SUSTRpos = G4ThreeVector(xbgoBeamv[i], ybgoBeamv[i], zbgoBeamv[i]); | |||
| 485 | new G4PVPlacement(rotX, PH1SUSTRpos, l_bgobeamv, TString::Format("p_bgobeamv_%d", i).Data(), &topVolume, false, 0); | |||
| 486 | } | |||
| 487 | ||||
| 488 | G4double dz_bgobeamh = activeParams.getLength("lbgoBeamh") * CLHEP::cm / 2.; | |||
| 489 | G4VSolid* s_bgobeamh_a = new G4Box("s_bgobeamh_a", dx_tpcbeam, dy_tpcbeam, dz_bgobeamh); | |||
| 490 | G4VSolid* s_bgobeamh_b = new G4Box("s_bgobeamh_b", dx_tpcbeam - 2.*dw_tpcbeam, dy_tpcbeam - dw_tpcbeam, dz_bgobeamh); | |||
| 491 | G4VSolid* s_bgobeamhpos = new G4SubtractionSolid("s_bgobeamhpos", s_bgobeamh_a, s_bgobeamh_b, 0, G4ThreeVector(0, dw_tpcbeam, 0)); | |||
| 492 | G4VSolid* s_bgobeamhneg = new G4SubtractionSolid("s_bgobeamhneg", s_bgobeamh_a, s_bgobeamh_b, 0, G4ThreeVector(0, -dw_tpcbeam, 0)); | |||
| 493 | G4VSolid* s_bgobeamh = new G4UnionSolid("s_bgobeamh", s_bgobeamhpos, s_bgobeamhneg, 0, G4ThreeVector(0, -2.*dy_tpcbeam, 0)); | |||
| 494 | G4LogicalVolume* l_bgobeamh = new G4LogicalVolume(s_bgobeamh, geometry::Materials::get("FG_Epoxy"), "l_bgobeamh", 0, 0); | |||
| 495 | ||||
| 496 | std::vector<double> xbgoBeamh = activeParams.getArray("xbgoBeamh", {0}); | |||
| 497 | std::vector<double> ybgoBeamh = activeParams.getArray("ybgoBeamh", {0}); | |||
| 498 | std::vector<double> zbgoBeamh = activeParams.getArray("zbgoBeamh", {0}); | |||
| 499 | for (unsigned int i = 0; i < xbgoBeamh.size(); ++i) { | |||
| 500 | ybgoBeamh[i] = ybgoBeamh[i] - y_offset; | |||
| 501 | G4Transform3D transform = G4Translate3D(xbgoBeamh[i], ybgoBeamh[i], | |||
| 502 | zbgoBeamh[i] + 2. * dy_tpcbeam) * G4RotateY3D(90.*CLHEP::deg) * G4RotateZ3D(90.*CLHEP::deg); | |||
| 503 | new G4PVPlacement(transform, l_bgobeamh, TString::Format("p_bgobeamh_%d", i).Data(), &topVolume, false, 0); | |||
| 504 | } | |||
| 505 | ||||
| 506 | G4double dz_bgobeamt = activeParams.getLength("lbgoBeamt") * CLHEP::cm / 2.; | |||
| 507 | G4VSolid* s_bgobeamt_a = new G4Box("s_bgobeamt_a", dx_tpcbeam, dy_tpcbeam, dz_bgobeamt); | |||
| 508 | G4VSolid* s_bgobeamt_b = new G4Box("s_bgobeamt_b", dx_tpcbeam - 2.*dw_tpcbeam, dy_tpcbeam - dw_tpcbeam, dz_bgobeamt); | |||
| 509 | G4VSolid* s_bgobeamt = new G4SubtractionSolid("s_bgobeamt", s_bgobeamt_a, s_bgobeamt_b, 0, G4ThreeVector(0, dw_tpcbeam, 0)); | |||
| 510 | G4LogicalVolume* l_bgobeamt = new G4LogicalVolume(s_bgobeamt, geometry::Materials::get("FG_Epoxy"), "l_bgobeamt", 0, 0); | |||
| 511 | ||||
| 512 | std::vector<double> xbgoBeamt = activeParams.getArray("xbgoBeamt", {0}); | |||
| 513 | std::vector<double> ybgoBeamt = activeParams.getArray("ybgoBeamt", {0}); | |||
| 514 | std::vector<double> zbgoBeamt = activeParams.getArray("zbgoBeamt", {0}); | |||
| 515 | for (unsigned int i = 0; i < xbgoBeamt.size(); ++i) { | |||
| 516 | ybgoBeamt[i] = ybgoBeamt[i] - y_offset; | |||
| 517 | PH1SUSTRpos = G4ThreeVector(xbgoBeamt[i], ybgoBeamt[i], zbgoBeamt[i]); | |||
| 518 | new G4PVPlacement(0, PH1SUSTRpos, l_bgobeamt, TString::Format("p_bgobeamt_%d", i).Data(), &topVolume, false, 0); | |||
| 519 | } | |||
| 520 | ||||
| 521 | G4double dz_bgobeamb = activeParams.getLength("lbgoBeamb") * CLHEP::cm / 2.; | |||
| 522 | G4VSolid* s_bgobeamb_a = new G4Box("s_bgobeamb_a", dx_tpcbeam, dy_tpcbeam, dz_bgobeamb); | |||
| 523 | G4VSolid* s_bgobeamb_b = new G4Box("s_bgobeamb_b", dx_tpcbeam - 2.*dw_tpcbeam, dy_tpcbeam - dw_tpcbeam, dz_bgobeamb); | |||
| 524 | G4VSolid* s_bgobeambpos = new G4SubtractionSolid("s_bgobeambpos", s_bgobeamb_a, s_bgobeamb_b, 0, G4ThreeVector(0, dw_tpcbeam, 0)); | |||
| 525 | G4VSolid* s_bgobeambneg = new G4SubtractionSolid("s_bgobeambneg", s_bgobeamb_a, s_bgobeamb_b, 0, G4ThreeVector(0, -dw_tpcbeam, 0)); | |||
| 526 | G4VSolid* s_bgobeamb = new G4UnionSolid("s_bgobeamb", s_bgobeambpos, s_bgobeambneg, 0, G4ThreeVector(0, -2.*dy_tpcbeam, 0)); | |||
| 527 | G4LogicalVolume* l_bgobeamb = new G4LogicalVolume(s_bgobeamb, geometry::Materials::get("FG_Epoxy"), "l_bgobeamb", 0, 0); | |||
| 528 | std::vector<double> xbgoBeamb = activeParams.getArray("xbgoBeamb", {0}); | |||
| 529 | std::vector<double> ybgoBeamb = activeParams.getArray("ybgoBeamb", {0}); | |||
| 530 | std::vector<double> zbgoBeamb = activeParams.getArray("zbgoBeamb", {0}); | |||
| 531 | for (unsigned int i = 0; i < xbgoBeamb.size(); ++i) { | |||
| 532 | xbgoBeamb[i] = xbgoBeamb[i] - x_offset; | |||
| 533 | ybgoBeamb[i] = ybgoBeamb[i] - y_offset; | |||
| 534 | G4Transform3D transform = G4Translate3D(xbgoBeamb[i], ybgoBeamb[i], | |||
| 535 | zbgoBeamb[i] + 2. * dy_tpcbeam) * G4RotateY3D(90.*CLHEP::deg) * G4RotateZ3D(90.*CLHEP::deg); | |||
| 536 | new G4PVPlacement(transform, l_bgobeamb, TString::Format("p_bgobeamb_%d", i).Data(), &topVolume, false, 1); | |||
| 537 | } | |||
| 538 | ||||
| 539 | G4double dz_tpcbeamb = activeParams.getLength("ltpcBeamb") * CLHEP::cm / 2.; | |||
| ||||
| 540 | G4VSolid* s_tpcbeamb_a = new G4Box("s_tpcbeamb_a", dx_tpcbeam, dy_tpcbeam, dz_tpcbeamb); | |||
| 541 | G4VSolid* s_tpcbeamb_b = new G4Box("s_tpcbeamb_b", dx_tpcbeam - 2.*dw_tpcbeam, dy_tpcbeam - dw_tpcbeam, dz_tpcbeamb); | |||
| 542 | G4VSolid* s_tpcbeambpos = new G4SubtractionSolid("s_tpcbeambpos", s_tpcbeamb_a, s_tpcbeamb_b, 0, G4ThreeVector(0, dw_tpcbeam, 0)); | |||
| 543 | G4VSolid* s_tpcbeambneg = new G4SubtractionSolid("s_tpcbeambneg", s_tpcbeamb_a, s_tpcbeamb_b, 0, G4ThreeVector(0, -dw_tpcbeam, 0)); | |||
| 544 | G4VSolid* s_tpcbeamb = new G4UnionSolid("s_tpcbeamb", s_tpcbeambpos, s_tpcbeambneg, 0, G4ThreeVector(0, -2.*dy_tpcbeam, 0)); | |||
| 545 | G4LogicalVolume* l_tpcbeamb = new G4LogicalVolume(s_tpcbeamb, geometry::Materials::get("FG_Epoxy"), "l_tpcbeamb", 0, 0); | |||
| 546 | std::vector<double> xtpcBeamb = activeParams.getArray("xtpcBeamb", {0}); | |||
| 547 | std::vector<double> ytpcBeamb = activeParams.getArray("ytpcBeamb", {0}); | |||
| 548 | std::vector<double> ztpcBeamb = activeParams.getArray("ztpcBeamb", {0}); | |||
| 549 | for (unsigned int i = 0; i < xtpcBeamb.size(); ++i) { | |||
| 550 | xtpcBeamb[i] = xtpcBeamb[i] - x_offset; | |||
| 551 | ytpcBeamb[i] = ytpcBeamb[i] - y_offset; | |||
| 552 | G4Transform3D transform = | |||
| 553 | G4Translate3D(xtpcBeamb[i], ytpcBeamb[i], ztpcBeamb[i] + 2. * dy_tpcbeam) * | |||
| 554 | G4RotateY3D(90.*CLHEP::deg) * G4RotateZ3D(90.*CLHEP::deg); | |||
| 555 | new G4PVPlacement(transform, l_tpcbeamb, TString::Format("p_tpcbeamb_%d", i).Data(), &topVolume, false, 1); | |||
| 556 | } | |||
| 557 | ||||
| 558 | G4double dz_fangsbeamhf = activeParams.getLength("lfangsBeamhf") * CLHEP::cm / 2.; | |||
| 559 | G4VSolid* s_fangsbeamhf_a = new G4Box("s_fangsbeamhf_a", dx_tpcbeam, dy_tpcbeam, dz_fangsbeamhf); | |||
| 560 | G4VSolid* s_fangsbeamhf_b = new G4Box("s_fangsbeamhf_b", dx_tpcbeam - 2.*dw_tpcbeam, dy_tpcbeam - dw_tpcbeam, dz_fangsbeamhf); | |||
| 561 | G4VSolid* s_fangsbeamhf = new G4SubtractionSolid("s_fangsbeamhf", s_fangsbeamhf_a, s_fangsbeamhf_b, 0, G4ThreeVector(0, dw_tpcbeam, | |||
| 562 | 0)); | |||
| 563 | G4LogicalVolume* l_fangsbeamhf = new G4LogicalVolume(s_fangsbeamhf, geometry::Materials::get("FG_Epoxy"), "l_fangsbeamhf", 0, 0); | |||
| 564 | double xfangsbeamhf = activeParams.getLength("xfangsBeamhf") * CLHEP::cm; | |||
| 565 | double yfangsbeamhf = activeParams.getLength("yfangsBeamhf") * CLHEP::cm; | |||
| 566 | double zfangsbeamhf = activeParams.getLength("zfangsBeamhf") * CLHEP::cm; | |||
| 567 | PH1SUSTRpos = G4ThreeVector(xfangsbeamhf, yfangsbeamhf, zfangsbeamhf); | |||
| 568 | new G4PVPlacement(rotY, PH1SUSTRpos, l_fangsbeamhf, "p_fangsbeamhf", &topVolume, false, 0); | |||
| 569 | ||||
| 570 | G4double dz_fangsbeamhb = activeParams.getLength("lfangsBeamhb") * CLHEP::cm / 2.; | |||
| 571 | G4VSolid* s_fangsbeamhb_a = new G4Box("s_fangsbeamhb_a", dx_tpcbeam, dy_tpcbeam, dz_fangsbeamhb); | |||
| 572 | G4VSolid* s_fangsbeamhb_b = new G4Box("s_fangsbeamhb_b", dx_tpcbeam - 2.*dw_tpcbeam, dy_tpcbeam - dw_tpcbeam, dz_fangsbeamhb); | |||
| 573 | G4VSolid* s_fangsbeamhbpos = new G4SubtractionSolid("s_fangsbeamhbpos", s_fangsbeamhb_a, s_fangsbeamhb_b, 0, G4ThreeVector(0, | |||
| 574 | dw_tpcbeam, 0)); | |||
| 575 | G4VSolid* s_fangsbeamhbneg = new G4SubtractionSolid("s_fangsbeamhbneg", s_fangsbeamhb_a, s_fangsbeamhb_b, 0, G4ThreeVector(0, | |||
| 576 | -dw_tpcbeam, 0)); | |||
| 577 | G4VSolid* s_fangsbeamhb = new G4UnionSolid("s_fangsbeamhb", s_fangsbeamhbpos, s_fangsbeamhbneg, 0, G4ThreeVector(0, -2.*dy_tpcbeam, | |||
| 578 | 0)); | |||
| 579 | G4LogicalVolume* l_fangsbeamhb = new G4LogicalVolume(s_fangsbeamhb, geometry::Materials::get("FG_Epoxy"), "l_fangsbeamhb", 0, 0); | |||
| 580 | double xfangsbeamhb = activeParams.getLength("xfangsBeamhb") * CLHEP::cm; | |||
| 581 | double yfangsbeamhb = activeParams.getLength("yfangsBeamhb") * CLHEP::cm; | |||
| 582 | double zfangsbeamhb = activeParams.getLength("zfangsBeamhb") * CLHEP::cm; | |||
| 583 | TransForm = G4Translate3D(xfangsbeamhb, yfangsbeamhb, zfangsbeamhb) /* G4RotateX3D(90.*CLHEP::deg)*/ * G4RotateY3D(90.*CLHEP::deg); | |||
| 584 | new G4PVPlacement(TransForm, l_fangsbeamhb, "p_fangsbeamhb", &topVolume, false, 1); | |||
| 585 | } | |||
| 586 | } | |||
| 587 | } // ph1sustr namespace | |||
| 588 | } // Belle2 namespace |
| 1 | // Components for manipulating sequences of characters -*- C++ -*- |
| 2 | |
| 3 | // Copyright (C) 1997-2025 Free Software Foundation, Inc. |
| 4 | // |
| 5 | // This file is part of the GNU ISO C++ Library. This library is free |
| 6 | // software; you can redistribute it and/or modify it under the |
| 7 | // terms of the GNU General Public License as published by the |
| 8 | // Free Software Foundation; either version 3, or (at your option) |
| 9 | // any later version. |
| 10 | |
| 11 | // This library is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU General Public License for more details. |
| 15 | |
| 16 | // Under Section 7 of GPL version 3, you are granted additional |
| 17 | // permissions described in the GCC Runtime Library Exception, version |
| 18 | // 3.1, as published by the Free Software Foundation. |
| 19 | |
| 20 | // You should have received a copy of the GNU General Public License and |
| 21 | // a copy of the GCC Runtime Library Exception along with this program; |
| 22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 23 | // <http://www.gnu.org/licenses/>. |
| 24 | |
| 25 | /** @file bits/basic_string.h |
| 26 | * This is an internal header file, included by other library headers. |
| 27 | * Do not attempt to use it directly. @headername{string} |
| 28 | */ |
| 29 | |
| 30 | // |
| 31 | // ISO C++ 14882: 21 Strings library |
| 32 | // |
| 33 | |
| 34 | #ifndef _BASIC_STRING_H1 |
| 35 | #define _BASIC_STRING_H1 1 |
| 36 | |
| 37 | #ifdef _GLIBCXX_SYSHDR |
| 38 | #pragma GCC system_header |
| 39 | #endif |
| 40 | |
| 41 | #include <ext/alloc_traits.h> |
| 42 | #include <debug/debug.h> |
| 43 | |
| 44 | #if __cplusplus202002L >= 201103L |
| 45 | #include <initializer_list> |
| 46 | #endif |
| 47 | |
| 48 | #include <bits/version.h> |
| 49 | |
| 50 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 51 | # include <string_view> |
| 52 | #endif |
| 53 | |
| 54 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 55 | # include <bits/ranges_algobase.h> // ranges::copy |
| 56 | # include <bits/ranges_util.h> // ranges::subrange |
| 57 | #endif |
| 58 | |
| 59 | #if __cplusplus202002L > 202302L |
| 60 | # include <charconv> |
| 61 | #endif |
| 62 | |
| 63 | |
| 64 | #if ! _GLIBCXX_USE_CXX11_ABI1 |
| 65 | # include "cow_string.h" |
| 66 | #else |
| 67 | |
| 68 | namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default"))) |
| 69 | { |
| 70 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 71 | _GLIBCXX_BEGIN_NAMESPACE_CXX11namespace __cxx11 { |
| 72 | |
| 73 | /** |
| 74 | * @class basic_string basic_string.h <string> |
| 75 | * @brief Managing sequences of characters and character-like objects. |
| 76 | * |
| 77 | * @ingroup strings |
| 78 | * @ingroup sequences |
| 79 | * @headerfile string |
| 80 | * @since C++98 |
| 81 | * |
| 82 | * @tparam _CharT Type of character |
| 83 | * @tparam _Traits Traits for character type, defaults to |
| 84 | * char_traits<_CharT>. |
| 85 | * @tparam _Alloc Allocator type, defaults to allocator<_CharT>. |
| 86 | * |
| 87 | * Meets the requirements of a <a href="tables.html#65">container</a>, a |
| 88 | * <a href="tables.html#66">reversible container</a>, and a |
| 89 | * <a href="tables.html#67">sequence</a>. Of the |
| 90 | * <a href="tables.html#68">optional sequence requirements</a>, only |
| 91 | * @c push_back, @c at, and @c %array access are supported. |
| 92 | */ |
| 93 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 94 | class basic_string |
| 95 | { |
| 96 | #if __cplusplus202002L >= 202002L |
| 97 | static_assert(is_trivially_copyable_v<_CharT> |
| 98 | && is_trivially_default_constructible_v<_CharT> |
| 99 | && is_standard_layout_v<_CharT>); |
| 100 | static_assert(is_same_v<_CharT, typename _Traits::char_type>); |
| 101 | static_assert(is_same_v<_CharT, typename _Alloc::value_type>); |
| 102 | using _Char_alloc_type = _Alloc; |
| 103 | #else |
| 104 | typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template |
| 105 | rebind<_CharT>::other _Char_alloc_type; |
| 106 | #endif |
| 107 | |
| 108 | typedef __gnu_cxx::__alloc_traits<_Char_alloc_type> _Alloc_traits; |
| 109 | |
| 110 | // Types: |
| 111 | public: |
| 112 | typedef _Traits traits_type; |
| 113 | typedef typename _Traits::char_type value_type; |
| 114 | typedef _Char_alloc_type allocator_type; |
| 115 | typedef typename _Alloc_traits::size_type size_type; |
| 116 | typedef typename _Alloc_traits::difference_type difference_type; |
| 117 | typedef typename _Alloc_traits::reference reference; |
| 118 | typedef typename _Alloc_traits::const_reference const_reference; |
| 119 | typedef typename _Alloc_traits::pointer pointer; |
| 120 | typedef typename _Alloc_traits::const_pointer const_pointer; |
| 121 | typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator; |
| 122 | typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string> |
| 123 | const_iterator; |
| 124 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 125 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 126 | |
| 127 | /// Value returned by various member functions when they fail. |
| 128 | static const size_type npos = static_cast<size_type>(-1); |
| 129 | |
| 130 | protected: |
| 131 | // type used for positions in insert, erase etc. |
| 132 | #if __cplusplus202002L < 201103L |
| 133 | typedef iterator __const_iterator; |
| 134 | #else |
| 135 | typedef const_iterator __const_iterator; |
| 136 | #endif |
| 137 | |
| 138 | private: |
| 139 | static _GLIBCXX20_CONSTEXPRconstexpr pointer |
| 140 | _S_allocate(_Char_alloc_type& __a, size_type __n) |
| 141 | { |
| 142 | pointer __p = _Alloc_traits::allocate(__a, __n); |
| 143 | #if __glibcxx_constexpr_string201907L >= 201907L |
| 144 | // std::char_traits begins the lifetime of characters, |
| 145 | // but custom traits might not, so do it here. |
| 146 | if constexpr (!is_same_v<_Traits, char_traits<_CharT>>) |
| 147 | if (std::__is_constant_evaluated()) |
| 148 | // Begin the lifetime of characters in allocated storage. |
| 149 | for (size_type __i = 0; __i < __n; ++__i) |
| 150 | std::construct_at(__builtin_addressof(__p[__i])); |
| 151 | #endif |
| 152 | return __p; |
| 153 | } |
| 154 | |
| 155 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 156 | // A helper type for avoiding boiler-plate. |
| 157 | typedef basic_string_view<_CharT, _Traits> __sv_type; |
| 158 | |
| 159 | template<typename _Tp, typename _Res> |
| 160 | using _If_sv = enable_if_t< |
| 161 | __and_<is_convertible<const _Tp&, __sv_type>, |
| 162 | __not_<is_convertible<const _Tp*, const basic_string*>>, |
| 163 | __not_<is_convertible<const _Tp&, const _CharT*>>>::value, |
| 164 | _Res>; |
| 165 | |
| 166 | // Allows an implicit conversion to __sv_type. |
| 167 | _GLIBCXX20_CONSTEXPRconstexpr |
| 168 | static __sv_type |
| 169 | _S_to_string_view(__sv_type __svt) noexcept |
| 170 | { return __svt; } |
| 171 | |
| 172 | // Wraps a string_view by explicit conversion and thus |
| 173 | // allows to add an internal constructor that does not |
| 174 | // participate in overload resolution when a string_view |
| 175 | // is provided. |
| 176 | struct __sv_wrapper |
| 177 | { |
| 178 | _GLIBCXX20_CONSTEXPRconstexpr explicit |
| 179 | __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { } |
| 180 | |
| 181 | __sv_type _M_sv; |
| 182 | }; |
| 183 | |
| 184 | /** |
| 185 | * @brief Only internally used: Construct string from a string view |
| 186 | * wrapper. |
| 187 | * @param __svw string view wrapper. |
| 188 | * @param __a Allocator to use. |
| 189 | */ |
| 190 | _GLIBCXX20_CONSTEXPRconstexpr |
| 191 | explicit |
| 192 | basic_string(__sv_wrapper __svw, const _Alloc& __a) |
| 193 | : basic_string(__svw._M_sv.data(), __svw._M_sv.size(), __a) { } |
| 194 | #endif |
| 195 | |
| 196 | // Use empty-base optimization: http://www.cantrip.org/emptyopt.html |
| 197 | struct _Alloc_hider : allocator_type // TODO check __is_final |
| 198 | { |
| 199 | #if __cplusplus202002L < 201103L |
| 200 | _Alloc_hider(pointer __dat, const _Alloc& __a = _Alloc()) |
| 201 | : allocator_type(__a), _M_p(__dat) { } |
| 202 | #else |
| 203 | _GLIBCXX20_CONSTEXPRconstexpr |
| 204 | _Alloc_hider(pointer __dat, const _Alloc& __a) |
| 205 | : allocator_type(__a), _M_p(__dat) { } |
| 206 | |
| 207 | _GLIBCXX20_CONSTEXPRconstexpr |
| 208 | _Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc()) |
| 209 | : allocator_type(std::move(__a)), _M_p(__dat) { } |
| 210 | #endif |
| 211 | |
| 212 | pointer _M_p; // The actual data. |
| 213 | }; |
| 214 | |
| 215 | _Alloc_hider _M_dataplus; |
| 216 | size_type _M_string_length; |
| 217 | |
| 218 | enum { _S_local_capacity = 15 / sizeof(_CharT) }; |
| 219 | |
| 220 | union |
| 221 | { |
| 222 | _CharT _M_local_buf[_S_local_capacity + 1]; |
| 223 | size_type _M_allocated_capacity; |
| 224 | }; |
| 225 | |
| 226 | _GLIBCXX20_CONSTEXPRconstexpr |
| 227 | void |
| 228 | _M_data(pointer __p) |
| 229 | { _M_dataplus._M_p = __p; } |
| 230 | |
| 231 | _GLIBCXX20_CONSTEXPRconstexpr |
| 232 | void |
| 233 | _M_length(size_type __length) |
| 234 | { _M_string_length = __length; } |
| 235 | |
| 236 | _GLIBCXX20_CONSTEXPRconstexpr |
| 237 | pointer |
| 238 | _M_data() const |
| 239 | { return _M_dataplus._M_p; } |
| 240 | |
| 241 | _GLIBCXX20_CONSTEXPRconstexpr |
| 242 | pointer |
| 243 | _M_local_data() |
| 244 | { |
| 245 | #if __cplusplus202002L >= 201103L |
| 246 | return std::pointer_traits<pointer>::pointer_to(*_M_local_buf); |
| 247 | #else |
| 248 | return pointer(_M_local_buf); |
| 249 | #endif |
| 250 | } |
| 251 | |
| 252 | _GLIBCXX20_CONSTEXPRconstexpr |
| 253 | const_pointer |
| 254 | _M_local_data() const |
| 255 | { |
| 256 | #if __cplusplus202002L >= 201103L |
| 257 | return std::pointer_traits<const_pointer>::pointer_to(*_M_local_buf); |
| 258 | #else |
| 259 | return const_pointer(_M_local_buf); |
| 260 | #endif |
| 261 | } |
| 262 | |
| 263 | _GLIBCXX20_CONSTEXPRconstexpr |
| 264 | void |
| 265 | _M_capacity(size_type __capacity) |
| 266 | { _M_allocated_capacity = __capacity; } |
| 267 | |
| 268 | _GLIBCXX20_CONSTEXPRconstexpr |
| 269 | void |
| 270 | _M_set_length(size_type __n) |
| 271 | { |
| 272 | _M_length(__n); |
| 273 | traits_type::assign(_M_data()[__n], _CharT()); |
| 274 | } |
| 275 | |
| 276 | _GLIBCXX20_CONSTEXPRconstexpr |
| 277 | bool |
| 278 | _M_is_local() const |
| 279 | { |
| 280 | if (_M_data() == _M_local_data()) |
| 281 | { |
| 282 | if (_M_string_length > _S_local_capacity) |
| 283 | __builtin_unreachable(); |
| 284 | return true; |
| 285 | } |
| 286 | return false; |
| 287 | } |
| 288 | |
| 289 | // Create & Destroy |
| 290 | _GLIBCXX20_CONSTEXPRconstexpr |
| 291 | pointer |
| 292 | _M_create(size_type&, size_type); |
| 293 | |
| 294 | _GLIBCXX20_CONSTEXPRconstexpr |
| 295 | void |
| 296 | _M_dispose() |
| 297 | { |
| 298 | if (!_M_is_local()) |
| 299 | _M_destroy(_M_allocated_capacity); |
| 300 | } |
| 301 | |
| 302 | _GLIBCXX20_CONSTEXPRconstexpr |
| 303 | void |
| 304 | _M_destroy(size_type __size) throw() |
| 305 | { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); } |
| 306 | |
| 307 | #if __cplusplus202002L < 201103L || defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS |
| 308 | // _M_construct_aux is used to implement the 21.3.1 para 15 which |
| 309 | // requires special behaviour if _InIterator is an integral type |
| 310 | template<typename _InIterator> |
| 311 | void |
| 312 | _M_construct_aux(_InIterator __beg, _InIterator __end, |
| 313 | std::__false_type) |
| 314 | { |
| 315 | typedef typename iterator_traits<_InIterator>::iterator_category _Tag; |
| 316 | _M_construct(__beg, __end, _Tag()); |
| 317 | } |
| 318 | |
| 319 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 320 | // 438. Ambiguity in the "do the right thing" clause |
| 321 | template<typename _Integer> |
| 322 | void |
| 323 | _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type) |
| 324 | { _M_construct_aux_2(static_cast<size_type>(__beg), __end); } |
| 325 | |
| 326 | void |
| 327 | _M_construct_aux_2(size_type __req, _CharT __c) |
| 328 | { _M_construct(__req, __c); } |
| 329 | #endif |
| 330 | |
| 331 | // For Input Iterators, used in istreambuf_iterators, etc. |
| 332 | template<typename _InIterator> |
| 333 | _GLIBCXX20_CONSTEXPRconstexpr |
| 334 | void |
| 335 | _M_construct(_InIterator __beg, _InIterator __end, |
| 336 | std::input_iterator_tag); |
| 337 | |
| 338 | // For forward_iterators up to random_access_iterators, used for |
| 339 | // string::iterator, _CharT*, etc. |
| 340 | template<typename _FwdIterator> |
| 341 | _GLIBCXX20_CONSTEXPRconstexpr |
| 342 | void |
| 343 | _M_construct(_FwdIterator __beg, _FwdIterator __end, |
| 344 | std::forward_iterator_tag); |
| 345 | |
| 346 | _GLIBCXX20_CONSTEXPRconstexpr |
| 347 | void |
| 348 | _M_construct(size_type __req, _CharT __c); |
| 349 | |
| 350 | // Construct using block of memory of known size. |
| 351 | // If _Terminated is true assume that source is already 0 terminated. |
| 352 | template<bool _Terminated> |
| 353 | _GLIBCXX20_CONSTEXPRconstexpr |
| 354 | void |
| 355 | _M_construct(const _CharT *__c, size_type __n); |
| 356 | |
| 357 | _GLIBCXX20_CONSTEXPRconstexpr |
| 358 | allocator_type& |
| 359 | _M_get_allocator() |
| 360 | { return _M_dataplus; } |
| 361 | |
| 362 | _GLIBCXX20_CONSTEXPRconstexpr |
| 363 | const allocator_type& |
| 364 | _M_get_allocator() const |
| 365 | { return _M_dataplus; } |
| 366 | |
| 367 | // Ensure that _M_local_buf is the active member of the union. |
| 368 | __attribute__((__always_inline__)) |
| 369 | _GLIBCXX14_CONSTEXPRconstexpr |
| 370 | void |
| 371 | _M_init_local_buf() _GLIBCXX_NOEXCEPTnoexcept |
| 372 | { |
| 373 | #if __glibcxx_is_constant_evaluated201811L |
| 374 | if (std::is_constant_evaluated()) |
| 375 | for (size_type __i = 0; __i <= _S_local_capacity; ++__i) |
| 376 | _M_local_buf[__i] = _CharT(); |
| 377 | #endif |
| 378 | } |
| 379 | |
| 380 | __attribute__((__always_inline__)) |
| 381 | _GLIBCXX14_CONSTEXPRconstexpr |
| 382 | pointer |
| 383 | _M_use_local_data() _GLIBCXX_NOEXCEPTnoexcept |
| 384 | { |
| 385 | #if __cpp_lib_is_constant_evaluated201811L |
| 386 | _M_init_local_buf(); |
| 387 | #endif |
| 388 | return _M_local_data(); |
| 389 | } |
| 390 | |
| 391 | private: |
| 392 | |
| 393 | #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST |
| 394 | // The explicit instantiations in misc-inst.cc require this due to |
| 395 | // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64063 |
| 396 | template<typename _Tp, bool _Requires = |
| 397 | !__are_same<_Tp, _CharT*>::__value |
| 398 | && !__are_same<_Tp, const _CharT*>::__value |
| 399 | && !__are_same<_Tp, iterator>::__value |
| 400 | && !__are_same<_Tp, const_iterator>::__value> |
| 401 | struct __enable_if_not_native_iterator |
| 402 | { typedef basic_string& __type; }; |
| 403 | template<typename _Tp> |
| 404 | struct __enable_if_not_native_iterator<_Tp, false> { }; |
| 405 | #endif |
| 406 | |
| 407 | _GLIBCXX20_CONSTEXPRconstexpr |
| 408 | size_type |
| 409 | _M_check(size_type __pos, const char* __s) const |
| 410 | { |
| 411 | if (__pos > this->size()) |
| 412 | __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "("%s: __pos (which is %zu) > " "this->size() (which is %zu)" ) |
| 413 | "this->size() (which is %zu)")("%s: __pos (which is %zu) > " "this->size() (which is %zu)" ), |
| 414 | __s, __pos, this->size()); |
| 415 | return __pos; |
| 416 | } |
| 417 | |
| 418 | _GLIBCXX20_CONSTEXPRconstexpr |
| 419 | void |
| 420 | _M_check_length(size_type __n1, size_type __n2, const char* __s) const |
| 421 | { |
| 422 | if (this->max_size() - (this->size() - __n1) < __n2) |
| 423 | __throw_length_error(__N(__s)(__s)); |
| 424 | } |
| 425 | |
| 426 | |
| 427 | // NB: _M_limit doesn't check for a bad __pos value. |
| 428 | _GLIBCXX20_CONSTEXPRconstexpr |
| 429 | size_type |
| 430 | _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPTnoexcept |
| 431 | { |
| 432 | const bool __testoff = __off < this->size() - __pos; |
| 433 | return __testoff ? __off : this->size() - __pos; |
| 434 | } |
| 435 | |
| 436 | // True if _Rep and source do not overlap. |
| 437 | bool |
| 438 | _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPTnoexcept |
| 439 | { |
| 440 | return (less<const _CharT*>()(__s, _M_data()) |
| 441 | || less<const _CharT*>()(_M_data() + this->size(), __s)); |
| 442 | } |
| 443 | |
| 444 | // When __n = 1 way faster than the general multichar |
| 445 | // traits_type::copy/move/assign. |
| 446 | _GLIBCXX20_CONSTEXPRconstexpr |
| 447 | static void |
| 448 | _S_copy(_CharT* __d, const _CharT* __s, size_type __n) |
| 449 | { |
| 450 | if (__n == 1) |
| 451 | traits_type::assign(*__d, *__s); |
| 452 | else |
| 453 | traits_type::copy(__d, __s, __n); |
| 454 | } |
| 455 | |
| 456 | _GLIBCXX20_CONSTEXPRconstexpr |
| 457 | static void |
| 458 | _S_move(_CharT* __d, const _CharT* __s, size_type __n) |
| 459 | { |
| 460 | if (__n == 1) |
| 461 | traits_type::assign(*__d, *__s); |
| 462 | else |
| 463 | traits_type::move(__d, __s, __n); |
| 464 | } |
| 465 | |
| 466 | _GLIBCXX20_CONSTEXPRconstexpr |
| 467 | static void |
| 468 | _S_assign(_CharT* __d, size_type __n, _CharT __c) |
| 469 | { |
| 470 | if (__n == 1) |
| 471 | traits_type::assign(*__d, __c); |
| 472 | else |
| 473 | traits_type::assign(__d, __n, __c); |
| 474 | } |
| 475 | |
| 476 | #pragma GCC diagnostic push |
| 477 | #pragma GCC diagnostic ignored "-Wc++17-extensions" |
| 478 | // _S_copy_chars is a separate template to permit specialization |
| 479 | // to optimize for the common case of pointers as iterators. |
| 480 | template<class _Iterator> |
| 481 | _GLIBCXX20_CONSTEXPRconstexpr |
| 482 | static void |
| 483 | _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) |
| 484 | { |
| 485 | #if __cplusplus202002L >= 201103L |
| 486 | using _IterBase = decltype(std::__niter_base(__k1)); |
| 487 | if constexpr (__or_<is_same<_IterBase, _CharT*>, |
| 488 | is_same<_IterBase, const _CharT*>>::value) |
| 489 | _S_copy(__p, std::__niter_base(__k1), __k2 - __k1); |
| 490 | #if __cpp_lib_concepts202002L |
| 491 | else if constexpr (requires { |
| 492 | requires contiguous_iterator<_Iterator>; |
| 493 | { std::to_address(__k1) } |
| 494 | -> convertible_to<const _CharT*>; |
| 495 | }) |
| 496 | { |
| 497 | const auto __d = __k2 - __k1; |
| 498 | (void) (__k1 + __d); // See P3349R1 |
| 499 | _S_copy(__p, std::to_address(__k1), static_cast<size_type>(__d)); |
| 500 | } |
| 501 | #endif |
| 502 | else |
| 503 | #endif |
| 504 | for (; __k1 != __k2; ++__k1, (void)++__p) |
| 505 | traits_type::assign(*__p, static_cast<_CharT>(*__k1)); |
| 506 | } |
| 507 | #pragma GCC diagnostic pop |
| 508 | |
| 509 | #if __cplusplus202002L < 201103L || defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS |
| 510 | static void |
| 511 | _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) |
| 512 | { _S_copy_chars(__p, __k1.base(), __k2.base()); } |
| 513 | |
| 514 | static void |
| 515 | _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2) |
| 516 | { _S_copy_chars(__p, __k1.base(), __k2.base()); } |
| 517 | |
| 518 | static void |
| 519 | _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) |
| 520 | { _S_copy(__p, __k1, __k2 - __k1); } |
| 521 | |
| 522 | static void |
| 523 | _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) |
| 524 | { _S_copy(__p, __k1, __k2 - __k1); } |
| 525 | #endif |
| 526 | |
| 527 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 528 | // pre: __n == ranges::distance(__rg). __p+[0,__n) is a valid range. |
| 529 | template<typename _Rg> |
| 530 | static constexpr void |
| 531 | _S_copy_range(pointer __p, _Rg&& __rg, size_type __n) |
| 532 | { |
| 533 | if constexpr (requires { |
| 534 | requires ranges::contiguous_range<_Rg>; |
| 535 | { ranges::data(std::forward<_Rg>(__rg)) } |
| 536 | -> convertible_to<const _CharT*>; |
| 537 | }) |
| 538 | _S_copy(__p, ranges::data(std::forward<_Rg>(__rg)), __n); |
| 539 | else |
| 540 | { |
| 541 | auto __first = ranges::begin(__rg); |
| 542 | const auto __last = ranges::end(__rg); |
| 543 | for (; __first != __last; ++__first) |
| 544 | traits_type::assign(*__p++, static_cast<_CharT>(*__first)); |
| 545 | } |
| 546 | } |
| 547 | #endif |
| 548 | |
| 549 | _GLIBCXX20_CONSTEXPRconstexpr |
| 550 | static int |
| 551 | _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPTnoexcept |
| 552 | { |
| 553 | const difference_type __d = difference_type(__n1 - __n2); |
| 554 | |
| 555 | if (__d > __gnu_cxx::__numeric_traits<int>::__max) |
| 556 | return __gnu_cxx::__numeric_traits<int>::__max; |
| 557 | else if (__d < __gnu_cxx::__numeric_traits<int>::__min) |
| 558 | return __gnu_cxx::__numeric_traits<int>::__min; |
| 559 | else |
| 560 | return int(__d); |
| 561 | } |
| 562 | |
| 563 | _GLIBCXX20_CONSTEXPRconstexpr |
| 564 | void |
| 565 | _M_assign(const basic_string&); |
| 566 | |
| 567 | _GLIBCXX20_CONSTEXPRconstexpr |
| 568 | void |
| 569 | _M_mutate(size_type __pos, size_type __len1, const _CharT* __s, |
| 570 | size_type __len2); |
| 571 | |
| 572 | _GLIBCXX20_CONSTEXPRconstexpr |
| 573 | void |
| 574 | _M_erase(size_type __pos, size_type __n); |
| 575 | |
| 576 | public: |
| 577 | // Construct/copy/destroy: |
| 578 | // NB: We overload ctors in some cases instead of using default |
| 579 | // arguments, per 17.4.4.4 para. 2 item 2. |
| 580 | |
| 581 | /** |
| 582 | * @brief Default constructor creates an empty string. |
| 583 | */ |
| 584 | _GLIBCXX20_CONSTEXPRconstexpr |
| 585 | basic_string() |
| 586 | _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value)noexcept(is_nothrow_default_constructible<_Alloc>::value ) |
| 587 | #if __cpp_concepts202002 && __glibcxx_type_trait_variable_templates201510L |
| 588 | requires is_default_constructible_v<_Alloc> |
| 589 | #endif |
| 590 | : _M_dataplus(_M_local_data()) |
| 591 | { |
| 592 | _M_init_local_buf(); |
| 593 | _M_set_length(0); |
| 594 | } |
| 595 | |
| 596 | /** |
| 597 | * @brief Construct an empty string using allocator @a a. |
| 598 | */ |
| 599 | _GLIBCXX20_CONSTEXPRconstexpr |
| 600 | explicit |
| 601 | basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPTnoexcept |
| 602 | : _M_dataplus(_M_local_data(), __a) |
| 603 | { |
| 604 | _M_init_local_buf(); |
| 605 | _M_set_length(0); |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * @brief Construct string with copy of value of @a __str. |
| 610 | * @param __str Source string. |
| 611 | */ |
| 612 | _GLIBCXX20_CONSTEXPRconstexpr |
| 613 | basic_string(const basic_string& __str) |
| 614 | : _M_dataplus(_M_local_data(), |
| 615 | _Alloc_traits::_S_select_on_copy(__str._M_get_allocator())) |
| 616 | { |
| 617 | _M_construct<true>(__str._M_data(), __str.length()); |
| 618 | } |
| 619 | |
| 620 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 621 | // 2583. no way to supply an allocator for basic_string(str, pos) |
| 622 | /** |
| 623 | * @brief Construct string as copy of a substring. |
| 624 | * @param __str Source string. |
| 625 | * @param __pos Index of first character to copy from. |
| 626 | * @param __a Allocator to use. |
| 627 | */ |
| 628 | _GLIBCXX20_CONSTEXPRconstexpr |
| 629 | basic_string(const basic_string& __str, size_type __pos, |
| 630 | const _Alloc& __a = _Alloc()) |
| 631 | : _M_dataplus(_M_local_data(), __a) |
| 632 | { |
| 633 | const _CharT* __start = __str._M_data() |
| 634 | + __str._M_check(__pos, "basic_string::basic_string"); |
| 635 | _M_construct(__start, __start + __str._M_limit(__pos, npos), |
| 636 | std::forward_iterator_tag()); |
| 637 | } |
| 638 | |
| 639 | /** |
| 640 | * @brief Construct string as copy of a substring. |
| 641 | * @param __str Source string. |
| 642 | * @param __pos Index of first character to copy from. |
| 643 | * @param __n Number of characters to copy. |
| 644 | */ |
| 645 | _GLIBCXX20_CONSTEXPRconstexpr |
| 646 | basic_string(const basic_string& __str, size_type __pos, |
| 647 | size_type __n) |
| 648 | : _M_dataplus(_M_local_data()) |
| 649 | { |
| 650 | const _CharT* __start = __str._M_data() |
| 651 | + __str._M_check(__pos, "basic_string::basic_string"); |
| 652 | _M_construct(__start, __start + __str._M_limit(__pos, __n), |
| 653 | std::forward_iterator_tag()); |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * @brief Construct string as copy of a substring. |
| 658 | * @param __str Source string. |
| 659 | * @param __pos Index of first character to copy from. |
| 660 | * @param __n Number of characters to copy. |
| 661 | * @param __a Allocator to use. |
| 662 | */ |
| 663 | _GLIBCXX20_CONSTEXPRconstexpr |
| 664 | basic_string(const basic_string& __str, size_type __pos, |
| 665 | size_type __n, const _Alloc& __a) |
| 666 | : _M_dataplus(_M_local_data(), __a) |
| 667 | { |
| 668 | const _CharT* __start |
| 669 | = __str._M_data() + __str._M_check(__pos, "string::string"); |
| 670 | _M_construct(__start, __start + __str._M_limit(__pos, __n), |
| 671 | std::forward_iterator_tag()); |
| 672 | } |
| 673 | |
| 674 | /** |
| 675 | * @brief Construct string initialized by a character %array. |
| 676 | * @param __s Source character %array. |
| 677 | * @param __n Number of characters to copy. |
| 678 | * @param __a Allocator to use (default is default allocator). |
| 679 | * |
| 680 | * NB: @a __s must have at least @a __n characters, '\\0' |
| 681 | * has no special meaning. |
| 682 | */ |
| 683 | _GLIBCXX20_CONSTEXPRconstexpr |
| 684 | basic_string(const _CharT* __s, size_type __n, |
| 685 | const _Alloc& __a = _Alloc()) |
| 686 | : _M_dataplus(_M_local_data(), __a) |
| 687 | { |
| 688 | // NB: Not required, but considered best practice. |
| 689 | if (__s == 0 && __n > 0) |
| 690 | std::__throw_logic_error(__N("basic_string: "("basic_string: " "construction from null is not valid") |
| 691 | "construction from null is not valid")("basic_string: " "construction from null is not valid")); |
| 692 | _M_construct(__s, __s + __n, std::forward_iterator_tag()); |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * @brief Construct string as copy of a C string. |
| 697 | * @param __s Source C string. |
| 698 | * @param __a Allocator to use (default is default allocator). |
| 699 | */ |
| 700 | #if __cpp_deduction_guides201703L && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS |
| 701 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 702 | // 3076. basic_string CTAD ambiguity |
| 703 | template<typename = _RequireAllocator<_Alloc>> |
| 704 | #endif |
| 705 | _GLIBCXX20_CONSTEXPRconstexpr |
| 706 | basic_string(const _CharT* __s, const _Alloc& __a = |