Skip to content

Commit 57de464

Browse files
fixing issue with urwell protype dimensions not being set before creation of geant4 volumes (#1122)
1 parent 06e3e4d commit 57de464

File tree

7 files changed

+202
-194
lines changed

7 files changed

+202
-194
lines changed

common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/MPGD/MUVT/MUVTStripFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ public final class MUVTStripFactory extends MPGDTrapezoidStripFactory {
2424

2525
/**
2626
* Build using an already-configured DatabaseConstantProvider.
27+
* @param cp
2728
*/
28-
public MUVTStripFactory(DatabaseConstantProvider cp, String variation) {
29+
public MUVTStripFactory(DatabaseConstantProvider cp) {
2930
super(new MUVTConstants(cp));
3031

3132

common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/MPGD/URWT/URWTConstants.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,53 @@
88
*/
99
public final class URWTConstants extends MPGDTrapezoidConstants {
1010

11-
private URWTConstants() {
11+
private final String variation;
12+
13+
private URWTConstants(String variation) {
1214
super(
1315
"/test/urwt/", // CCDB base path
1416
"urwt_global", // global table name
1517
"urwt_material", // material table name
1618
"urwt" // detector nams
1719
);
20+
this.variation = variation;
1821
}
1922

2023
public URWTConstants(int run, String variation) {
21-
this();
24+
this(variation);
2225
DatabaseConstantProvider cp = new DatabaseConstantProvider(run, variation);
2326
this.load(cp);
2427
cp.disconnect();
2528
}
2629

27-
public URWTConstants(DatabaseConstantProvider cp) {
28-
this();
30+
public URWTConstants(DatabaseConstantProvider cp, String variation) {
31+
this(variation);
2932
this.load(cp);
3033
}
34+
35+
/**
36+
*
37+
* @param region
38+
* @return
39+
*/
40+
@Override
41+
public SectorDimensions getSectorActiveVolumeDimensions(int region) {
42+
43+
if (variation != null && variation.toLowerCase().contains("proto")) {
44+
45+
double halfThickness = this.getSectorThickness() / 2.0;
46+
double tiltRad = Math.toRadians(THTILT);
47+
48+
// da vertici (mm)
49+
double halfLargeBase = 72.71785;
50+
double halfSmallBase = 50.44350;
51+
double halfHeight = 24.74554;
52+
53+
return new SectorDimensions(halfThickness, halfHeight, halfLargeBase, halfSmallBase, tiltRad);
54+
}
55+
56+
return super.getSectorActiveVolumeDimensions(region);
57+
}
58+
3159

3260
}

common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/MPGD/URWT/URWTGeant4Factory.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,13 @@
1515
*/
1616
public final class URWTGeant4Factory extends MPGDTrapezoidGeant4Factory {
1717

18-
private final String variation;
1918

2019
public URWTGeant4Factory(DatabaseConstantProvider cp, String variation) {
21-
super(new URWTConstants(cp));
22-
this.variation = variation;
20+
super(new URWTConstants(cp, variation));
2321
}
2422

2523
public URWTGeant4Factory(int run, String variation) {
2624
super(new URWTConstants(run, variation));
27-
this.variation = variation;
28-
}
29-
30-
/**
31-
*
32-
* @param region
33-
* @return
34-
*/
35-
@Override
36-
public SectorDimensions getSectorActiveVolumeDimensions(int region) {
37-
38-
if (variation != null && variation.toLowerCase().contains("proto")) {
39-
40-
double halfThickness = this.getSectorThickness() / 2.0;
41-
double tiltRad = Math.toRadians(C.THTILT);
42-
43-
// da vertici (mm)
44-
double halfLargeBase = 72.71785;
45-
double halfSmallBase = 50.44350;
46-
double halfHeight = 24.74554;
47-
48-
return new SectorDimensions(halfThickness, halfHeight, halfLargeBase, halfSmallBase, tiltRad);
49-
}
50-
51-
return super.getSectorActiveVolumeDimensions(region);
5225
}
5326

5427
/**

common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/MPGD/URWT/URWTStripFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ public final class URWTStripFactory extends MPGDTrapezoidStripFactory {
2525
/**
2626
* Build using an already-configured DatabaseConstantProvider.
2727
* @param cp
28+
* @param variation
2829
*/
29-
public URWTStripFactory(DatabaseConstantProvider cp) {
30-
super(new URWTConstants(cp));
30+
public URWTStripFactory(DatabaseConstantProvider cp, String variation) {
31+
super(new URWTConstants(cp, variation));
3132

3233
for (Geant4Basic v : geo.getAllVolumes()) {
3334
if (v.getName() != null) {

common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/MPGD/trapezoid/MPGDTrapezoidConstants.java

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jlab.detector.geant4.v2.MPGD.trapezoid;
22

3+
import eu.mihosoft.vrl.v3d.Vector3d;
34
import org.jlab.detector.calib.utils.DatabaseConstantProvider;
45

56
import java.util.LinkedHashMap;
@@ -70,6 +71,17 @@ public class MPGDTrapezoidConstants {
7071
public static final double YENLARGEMENT = 0.15; // cm
7172
public static final double ZENLARGEMENT = 0.02; // cm
7273

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+
7385
// ------------------------------------------------------------------------
7486
// Material description: (layer, component) -> parameters
7587
// ------------------------------------------------------------------------
@@ -221,4 +233,148 @@ public synchronized void getConstants(DatabaseConstantProvider cp) {
221233
.put(component, info);
222234
}
223235
}
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+
224380
}

0 commit comments

Comments
 (0)