Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,62 +1,39 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.jlab.detector.geant4.v2;

import eu.mihosoft.vrl.v3d.Vector3d;
import java.util.List;
import java.util.ArrayList;
import org.jlab.detector.volume.Geant4Basic;
import org.jlab.detector.volume.G4Trd;
import org.jlab.detector.volume.G4Box;
import java.util.ArrayList;
import java.util.List;
import org.jlab.detector.base.DetectorType;
import org.jlab.detector.base.GeometryFactory;
import org.jlab.detector.units.SystemOfUnits.Length;

import static org.jlab.detector.units.SystemOfUnits.Length;
import org.jlab.detector.volume.G4World;
import org.jlab.geom.base.ConstantProvider;
import org.jlab.geom.prim.Plane3D;
import org.jlab.geom.prim.Trap3D;
import org.jlab.geometry.prim.Line3d;
import static org.jlab.detector.units.SystemOfUnits.Length;

/**
*
* @author Ethan Cline
*/
public final class MUCALGeant4Factory extends Geant4Factory {




public MUCALGeant4Factory(ConstantProvider provider) {
motherVolume = new G4World("ddvcs_ecal");


for (int sector = 1; sector <= 2; sector++) {
List<G4Trd> layerVolume = createPanel(provider, sector, 1);
for (G4Trd crystal : layerVolume) {
crystal.setMother(motherVolume);
}
// layerVolume.setMother(motherVolume);
List<G4Trd> layerVolume = createPanel(provider, sector, 1);
for (G4Trd crystal : layerVolume) {
crystal.setMother(motherVolume);
}
// layerVolume.setMother(motherVolume);
}
properties.put("email", "ewcline@mit.edu");
properties.put("author", "cline");
properties.put("date", "3/23/26");
}

private List<G4Trd> createPanel(ConstantProvider cp, int sector, int layer) {


List<G4Trd> crystals = this.createLayer(cp, layer);

return crystals;
return this.createLayer(cp, layer);
}
private List<G4Trd> createLayer(ConstantProvider cp, int layer) {


private List<G4Trd> createLayer(ConstantProvider cp, int layer) {

double Dat25deg = 596.*Length.mm; // distance of the upstream face from the target at 25 deg
double ThetaU = Math.toRadians(25); // deg
double ThetaMin = Math.toRadians(7); // deg
Expand All @@ -69,19 +46,19 @@ private List<G4Trd> createLayer(ConstantProvider cp, int layer) {
double microgap = 0.5*Length.mm;
double Cwidth = (CwidthU+CwidthD)/2. + microgap;
int nCrystal = 2*((int)(CrmaxU / Cwidth)+100);// add 100 to get full coverage

double centerX, centerY, x12, x22, y12, y22, rad1, rad2, rad3, rad4, rxy;
double centerZ, thetaX, thetaY, radius, posX, posY, posZ, dx1, dx2, dz;
String vname;
List<G4Trd> crystalVolumes = new ArrayList<>();

for(int iX = 0; iX < nCrystal; iX++)
{
for(int iY = 0; iY < nCrystal; iY++)
{
{
for(int iY = 0; iY < nCrystal; iY++)
{
centerX = - nCrystal/2.*Cwidth + (double)iX*Cwidth + 0.5*Cwidth;
centerY = - nCrystal/2.*Cwidth + (double)iY*Cwidth + 0.5*Cwidth;

x12 = (centerX - 0.5*Cwidth)*(centerX - 0.5*Cwidth);
x22 = (centerX + 0.5*Cwidth)*(centerX + 0.5*Cwidth);
y12 = (centerY - 0.5*Cwidth)*(centerY - 0.5*Cwidth);
Expand All @@ -91,67 +68,64 @@ private List<G4Trd> createLayer(ConstantProvider cp, int layer) {
rad2 = Math.sqrt(x22 + y22);
rad3 = Math.sqrt(x12 + y22);
rad4 = Math.sqrt(x22 + y12);
if(rad1 > CrminU + microgap && rad1 < CrmaxU - microgap &&
rad2 > CrminU + microgap && rad2 < CrmaxU - microgap &&
rad3 > CrminU + microgap && rad3 < CrmaxU - microgap &&
rad4 > CrminU + microgap && rad4 < CrmaxU - microgap
)
{

rxy = Math.sqrt(centerX*centerX + centerY*centerY);
centerZ = (Dat25deg+Clength/2.)/Math.cos(ThetaU) - rxy*Math.sin(ThetaU);
thetaX = -Math.atan(centerX/centerZ);
thetaY = Math.atan(centerY/centerZ);
radius = Math.sqrt(rxy*rxy + centerZ*centerZ);
posX = centerX;
posY = centerY;
posZ = centerZ;
vname = String.format("sci_S%d_L%d_C%d", iX + 1, iY + 1, nCrystal);
dx1 = CwidthU/2.0;
dx2 = CwidthD/2.0;
dz = Clength/2.0;
G4Trd crvolume = new G4Trd("mucal_" + iX + "_" + iY, dx1, dx2, dx1, dx2, dz);
crvolume.makeSensitive();
crvolume.rotate("zyx",0, thetaX, thetaY);
crvolume.translate(posX, posY, posZ);
crystalVolumes.add(crvolume);
}

if(rad1 > CrminU + microgap && rad1 < CrmaxU - microgap &&
rad2 > CrminU + microgap && rad2 < CrmaxU - microgap &&
rad3 > CrminU + microgap && rad3 < CrmaxU - microgap &&
rad4 > CrminU + microgap && rad4 < CrmaxU - microgap
)
{
rxy = Math.sqrt(centerX*centerX + centerY*centerY);
centerZ = (Dat25deg+Clength/2.)/Math.cos(ThetaU) - rxy*Math.sin(ThetaU);
thetaX = -Math.atan(centerX/centerZ);
thetaY = Math.atan(centerY/centerZ);
radius = Math.sqrt(rxy*rxy + centerZ*centerZ);
posX = centerX;
posY = centerY;
posZ = centerZ;
vname = String.format("sci_S%d_L%d_C%d", iX + 1, iY + 1, nCrystal);
dx1 = CwidthU/2.0;
dx2 = CwidthD/2.0;
dz = Clength/2.0;
G4Trd crvolume = new G4Trd("mucal_" + iX + "_" + iY, dx1, dx2, dx1, dx2, dz);
crvolume.makeSensitive();
crvolume.rotate("zyx",0, thetaX, thetaY);
crvolume.translate(posX, posY, posZ);
crystalVolumes.add(crvolume);
}

}
}

return crystalVolumes;
}

public G4Trd getComponent(int sector, int layer, int crystal) {
int ivolume = (sector - 1) * 3 + layer - 1;

if (sector >= 1 && sector <= 6
&& layer >= 1 && layer <= 3) {

&& layer >= 1 && layer <= 3) {
List<Geant4Basic> panel = motherVolume.getChildren().get(ivolume).getChildren();
int ncrystals = panel.size();

if (crystal >= 1 && crystal <= ncrystals) {
return (G4Trd) panel.get(crystal - 1);
}
}

System.err.println("ERROR!!!");
System.err.println("Component: sector: " + sector + ", layer: " + layer + ", crystal: " + crystal + " doesn't exist");
throw new IndexOutOfBoundsException();
}


public G4World getMother() {
return motherVolume;
}


public static void main(String[] args) {
ConstantProvider cp = null;//GeometryFactory.getConstants(DetectorType.MUCAL);
MUCALGeant4Factory factory = new MUCALGeant4Factory(cp);

factory.getAllVolumes().forEach(volume -> {
System.out.println(volume.gemcString());
});
Expand Down
Loading