|
1 | 1 | package org.jlab.detector.geant4.v2.MPGD.trapezoid; |
2 | 2 |
|
| 3 | +import eu.mihosoft.vrl.v3d.Vector3d; |
3 | 4 | import org.jlab.detector.calib.utils.DatabaseConstantProvider; |
4 | 5 |
|
5 | 6 | import java.util.LinkedHashMap; |
@@ -70,6 +71,17 @@ public class MPGDTrapezoidConstants { |
70 | 71 | public static final double YENLARGEMENT = 0.15; // cm |
71 | 72 | public static final double ZENLARGEMENT = 0.02; // cm |
72 | 73 |
|
| 74 | + |
| 75 | + |
| 76 | + public static record SectorDimensions( |
| 77 | + double halfThickness, |
| 78 | + double halfHeight, |
| 79 | + double halfLargeBase, |
| 80 | + double halfSmallBase, |
| 81 | + double tiltRad |
| 82 | + ) { |
| 83 | + } |
| 84 | + |
73 | 85 | // ------------------------------------------------------------------------ |
74 | 86 | // Material description: (layer, component) -> parameters |
75 | 87 | // ------------------------------------------------------------------------ |
@@ -221,4 +233,148 @@ public synchronized void getConstants(DatabaseConstantProvider cp) { |
221 | 233 | .put(component, info); |
222 | 234 | } |
223 | 235 | } |
| 236 | + |
| 237 | + // ------------------------------------------------------------------------ |
| 238 | + // Sector geometry helpers |
| 239 | + // ------------------------------------------------------------------------ |
| 240 | + /** |
| 241 | + * Computes the total thickness (mm) of a sector by summing the thickness of |
| 242 | + * all material volumes. |
| 243 | + * |
| 244 | + * @return |
| 245 | + */ |
| 246 | + public double getSectorThickness() { |
| 247 | + return detectorStructure.values() |
| 248 | + .stream() |
| 249 | + .flatMap(componentMap -> componentMap.values().stream()) |
| 250 | + .mapToDouble(info -> info.thickness) |
| 251 | + .sum(); |
| 252 | + } |
| 253 | + |
| 254 | + /** |
| 255 | + * |
| 256 | + * @param region |
| 257 | + * @return |
| 258 | + */ |
| 259 | + public SectorDimensions getSectorActiveVolumeDimensions(int region) { |
| 260 | + |
| 261 | + double baseDistance = this.TGTDET + region * this.DZ; |
| 262 | + |
| 263 | + double sectorHeight = baseDistance |
| 264 | + * (Math.tan(Math.toRadians(this.THMAX - this.THTILT)) |
| 265 | + + Math.tan(Math.toRadians(this.THTILT - this.THMIN))); |
| 266 | + |
| 267 | + double halfThickness = this.getSectorThickness() / 2.0; |
| 268 | + double halfHeight = sectorHeight / 2.0; |
| 269 | + |
| 270 | + // Distance from target to the bottom base along the tilted axis |
| 271 | + double W2TGT = (this.TGTDET + region * this.DZ) |
| 272 | + / Math.cos(Math.toRadians(this.THTILT - this.THMIN)); |
| 273 | + |
| 274 | + double YMIN = W2TGT * Math.sin(Math.toRadians(this.THMIN)); // distance from beamline (Y) |
| 275 | + double h = sectorHeight * Math.cos(Math.toRadians(this.THTILT)); |
| 276 | + double halfSmallBase = 0.5 * (YMIN * Math.tan(Math.toRadians(this.THOPEN) / 2)); |
| 277 | + |
| 278 | + double halfLargeBase = halfSmallBase + sectorHeight * Math.tan(Math.toRadians(this.THOPEN / 2.0)); |
| 279 | + |
| 280 | + double tiltRad = Math.toRadians(this.THTILT); |
| 281 | + |
| 282 | + double twidth_Check = 2 * halfLargeBase * Math.sin(Math.toRadians(this.THOPEN)); |
| 283 | + |
| 284 | + if (MPGDTrapezoidConstants.VERBOSE) { |
| 285 | + System.out.printf("this.TWIDT=%.3f vs %.3f", this.TWIDTH, twidth_Check); |
| 286 | + |
| 287 | + System.out.printf("YMIN=%.3f", YMIN); |
| 288 | + |
| 289 | + System.out.printf( |
| 290 | + "SectorDimensionsPhysical [%s] region=%d : height=%.3f | halfT=%.3f halfH=%.3f " |
| 291 | + + "halfLarge=%.3f halfSmall=%.3f tilt(deg)=%.3f%n", |
| 292 | + this.detectorName, region, sectorHeight, |
| 293 | + halfThickness, halfHeight, |
| 294 | + halfLargeBase, halfSmallBase, |
| 295 | + this.THTILT |
| 296 | + ); |
| 297 | + } |
| 298 | + |
| 299 | + return new SectorDimensions(halfThickness, halfHeight, halfLargeBase, halfSmallBase, tiltRad); |
| 300 | + } |
| 301 | + |
| 302 | + /** |
| 303 | + * |
| 304 | + * @param region |
| 305 | + * @return |
| 306 | + */ |
| 307 | + public SectorDimensions getSectorContainerDimensions(int region) { |
| 308 | + |
| 309 | + SectorDimensions phys = getSectorActiveVolumeDimensions(region); |
| 310 | + |
| 311 | + double halfThickness = phys.halfThickness() + MPGDTrapezoidConstants.ZENLARGEMENT; |
| 312 | + double halfHeight = phys.halfHeight() + MPGDTrapezoidConstants.YENLARGEMENT; |
| 313 | + double halfLargeBase = phys.halfLargeBase() + MPGDTrapezoidConstants.XENLARGEMENT; |
| 314 | + double halfSmallBase = phys.halfSmallBase() + MPGDTrapezoidConstants.XENLARGEMENT; |
| 315 | + |
| 316 | + return new SectorDimensions(halfThickness, halfHeight, halfLargeBase, halfSmallBase, phys.tiltRad()); |
| 317 | + } |
| 318 | + |
| 319 | + /** |
| 320 | + * Computes the sector height (longitudinal extension in the RZ plane) for a |
| 321 | + * given region. |
| 322 | + * |
| 323 | + * @param region |
| 324 | + * @return |
| 325 | + */ |
| 326 | + public double getSectorHeight(int region) { |
| 327 | + |
| 328 | + double baseDistance = this.TGTDET + region * this.DZ; |
| 329 | + |
| 330 | + double sectorHeight = baseDistance |
| 331 | + * (Math.tan(Math.toRadians(this.THMAX - this.THTILT)) |
| 332 | + + Math.tan(Math.toRadians(this.THTILT - this.THMIN))); |
| 333 | + |
| 334 | + if (MPGDTrapezoidConstants.VERBOSE) { |
| 335 | + System.out.printf( |
| 336 | + "SectorHeight [%s] region=%d : baseDistance=%.3f THMIN=%.3f THMAX=%.3f THTILT=%.3f -> height=%.3f%n", |
| 337 | + this.detectorName, |
| 338 | + region, |
| 339 | + baseDistance, |
| 340 | + this.THMIN, this.THMAX, this.THTILT, |
| 341 | + sectorHeight |
| 342 | + ); |
| 343 | + } |
| 344 | + |
| 345 | + return sectorHeight; |
| 346 | + } |
| 347 | + |
| 348 | + /** |
| 349 | + * Computes the barycenter coordinates of a given sector/region in the |
| 350 | + * CLAS12 coordinate system. |
| 351 | + * |
| 352 | + * @param isector |
| 353 | + * @param iregion |
| 354 | + * @return |
| 355 | + */ |
| 356 | + public Vector3d getCenterCoordinate(int isector, int iregion) { |
| 357 | + |
| 358 | + Vector3d vCenter = new Vector3d(0, 0, 0); |
| 359 | + |
| 360 | + // Distance from target to the bottom base along the tilted axis |
| 361 | + double W2TGT = (this.TGTDET + iregion * this.DZ) |
| 362 | + / Math.cos(Math.toRadians(this.THTILT - this.THMIN)); |
| 363 | + |
| 364 | + double YMIN = W2TGT * Math.sin(Math.toRadians(this.THMIN)); // distance from beamline (Y) |
| 365 | + double ZMIN = W2TGT * Math.cos(Math.toRadians(this.THMIN)); // Z of the bottom base |
| 366 | + |
| 367 | + SectorDimensions dimCont = this.getSectorContainerDimensions(iregion); |
| 368 | + double sectorHeight = 2 * dimCont.halfHeight(); |
| 369 | + |
| 370 | + vCenter.x = 0.0; |
| 371 | + vCenter.y = (sectorHeight / 2.0) * Math.cos(Math.toRadians(this.THTILT)) + YMIN; |
| 372 | + vCenter.z = -(sectorHeight / 2.0) * Math.sin(Math.toRadians(this.THTILT)) + ZMIN; |
| 373 | + |
| 374 | + // Rotate to the correct sector around Z (assumes 6 sectors, 60° apart) |
| 375 | + vCenter.rotateZ(-Math.toRadians(90.0 - isector * 60.0)); |
| 376 | + |
| 377 | + return vCenter; |
| 378 | + } |
| 379 | + |
224 | 380 | } |
0 commit comments