From 7a95a9c3a3c2a8b2ba72091953245a15ff9a360c Mon Sep 17 00:00:00 2001
From: Dave Casper <dcasper@uci.edu>
Date: Mon, 25 Sep 2023 07:38:29 -0700
Subject: [PATCH] Fix overlaps in Veto, magnet covers and Ecal

---
 .../GeoModel/FaserGeoModel/data/geomDB.sql    | 31 +++++++++++++------
 .../VetoGeoModel/src/VetoStation.cxx          |  2 +-
 Simulation/G4Faser/G4FaserAlg/CMakeLists.txt  | 23 ++++++++++----
 .../test/G4FaserAlgConfigNew_Test.py          |  7 ++++-
 .../DipoleGeoModel/src/DipoleFactory.cxx      |  7 +++--
 5 files changed, 51 insertions(+), 19 deletions(-)

diff --git a/DetectorDescription/GeoModel/FaserGeoModel/data/geomDB.sql b/DetectorDescription/GeoModel/FaserGeoModel/data/geomDB.sql
index 046c5462f..d4f489049 100644
--- a/DetectorDescription/GeoModel/FaserGeoModel/data/geomDB.sql
+++ b/DetectorDescription/GeoModel/FaserGeoModel/data/geomDB.sql
@@ -1038,6 +1038,8 @@ INSERT INTO "HVS_TAG2NODE" VALUES (41, "Ecal-TB01", 107857, NULL, 0, 0,    16858
 INSERT INTO "HVS_TAG2NODE" VALUES (410, "EcalTopLevel-00", 100058, NULL, 0, 0, 1599350400000000000, NULL, 22);
 INSERT INTO "HVS_TAG2NODE" VALUES (410, "EcalTopLevel-02", 107797, NULL, 0, 0, 1619222400000000000, NULL, 22);
 INSERT INTO "HVS_TAG2NODE" VALUES (410, "EcalTopLevel-TB00", 107822, NULL, 0, 0, 1627862400000000000, NULL, 22);
+INSERT INTO "HVS_TAG2NODE" VALUES (410, "EcalTopLevel-04", 107886, NULL, 0, 0,   1695600000000000000, NULL, 22);
+INSERT INTO "HVS_TAG2NODE" VALUES (410, "EcalTopLevel-TB01", 107887, NULL, 0, 0, 1695600000000000000, NULL, 22);
 INSERT INTO "HVS_TAG2NODE" VALUES (411, "EcalRowGeneral-00", 100059, NULL, 0, 0, 1599350400000000000, NULL, 22);
 INSERT INTO "HVS_TAG2NODE" VALUES (411, "EcalRowGeneral-TB00", 107830, NULL, 0, 0, 1627862400000000000, NULL, 22);
 INSERT INTO "HVS_TAG2NODE" VALUES (414, "EcalSwitches-00", 100057, NULL, 0, 0, 1593907200000000000, NULL, 22);
@@ -2009,7 +2011,7 @@ INSERT INTO "HVS_TAGCACHE" VALUES ("FASERNU-04", "DipoleSwitches",     "DipoleSw
 INSERT INTO "HVS_TAGCACHE" VALUES ("FASERNU-04", "DipoleWrappingGeneral", "DipoleWrappingGeneral-01",   107885);
 INSERT INTO "HVS_TAGCACHE" VALUES ("FASERNU-04", "Calorimeter",        "Calorimeter-04",          107858);
 INSERT INTO "HVS_TAGCACHE" VALUES ("FASERNU-04", "Ecal",               "Ecal-04",                 107856);
-INSERT INTO "HVS_TAGCACHE" VALUES ("FASERNU-04", "EcalTopLevel",       "EcalTopLevel-02",         107797);
+INSERT INTO "HVS_TAGCACHE" VALUES ("FASERNU-04", "EcalTopLevel",       "EcalTopLevel-04",         107886);
 INSERT INTO "HVS_TAGCACHE" VALUES ("FASERNU-04", "EcalRowGeneral",     "EcalRowGeneral-00",       100059);
 INSERT INTO "HVS_TAGCACHE" VALUES ("FASERNU-04", "EcalSwitches",       "EcalSwitches-01",         107855);
 INSERT INTO "HVS_TAGCACHE" VALUES ("FASERNU-04", "VetoTopLevel",       "VetoTopLevel-02",         107798);
@@ -2087,7 +2089,7 @@ INSERT INTO "HVS_TAGCACHE" VALUES ("FASER-TB01", "DipoleSwitches",     "DipoleSw
 INSERT INTO "HVS_TAGCACHE" VALUES ("FASER-TB01", "DipoleWrappingGeneral", "DipoleWrappingGeneral-01",   107885);
 INSERT INTO "HVS_TAGCACHE" VALUES ("FASER-TB01", "Calorimeter",        "Calorimeter-TB01",        107859);
 INSERT INTO "HVS_TAGCACHE" VALUES ("FASER-TB01", "Ecal",               "Ecal-TB01",               107857);
-INSERT INTO "HVS_TAGCACHE" VALUES ("FASER-TB01", "EcalTopLevel",       "EcalTopLevel-TB00",       107822);
+INSERT INTO "HVS_TAGCACHE" VALUES ("FASER-TB01", "EcalTopLevel",       "EcalTopLevel-TB00",       107887);
 INSERT INTO "HVS_TAGCACHE" VALUES ("FASER-TB01", "EcalRowGeneral",     "EcalRowGeneral-TB00",     107830);
 INSERT INTO "HVS_TAGCACHE" VALUES ("FASER-TB01", "EcalSwitches",       "EcalSwitches-01",         107855);
 INSERT INTO "HVS_TAGCACHE" VALUES ("FASER-TB01", "VetoTopLevel",       "VetoTopLevel-TB00",       107823);
@@ -2856,13 +2858,17 @@ INSERT INTO "PRESHOWERWRAPPINGGENERAL_DATA2TAG" VALUES (107875, 0);
 INSERT INTO "PRESHOWERWRAPPINGGENERAL_DATA2TAG" VALUES (107876, 1);
 --
 --
-INSERT INTO "ECALTOPLEVEL_DATA" VALUES (0, 0.0,   0.0, 3099.2, 0.0, 0.0, 0.0, 321, "Ecal");
-INSERT INTO "ECALTOPLEVEL_DATA" VALUES (1, 0.0, -71.6,    0.0, 0.0, 2.8, 0.0, 321, "BottomRow");
-INSERT INTO "ECALTOPLEVEL_DATA" VALUES (2, 0.0,  49.6,    0.0, 0.0, 2.8, 0.0, 321, "TopRow");
-INSERT INTO "ECALTOPLEVEL_DATA" VALUES (3, 0.0,   0.0, 3098.9, 0.0, 0.0, 0.0, 321, "Ecal");
-INSERT INTO "ECALTOPLEVEL_DATA" VALUES (4, 0.0, -71.6,    0.0, 0.0, 0.0, 0.0, 321, "BottomRow");
-INSERT INTO "ECALTOPLEVEL_DATA" VALUES (5, 0.0,  49.6,    0.0, 0.0, 0.0, 0.0, 321, "TopRow");
-INSERT INTO "ECALTOPLEVEL_DATA" VALUES (6, -17.22, -22.80, 1088.66, -2.8, -2.8, 0.0, 321, "Ecal");
+INSERT INTO "ECALTOPLEVEL_DATA" VALUES (0, 0.0,   0.0, 3099.2, 0.0, 0.0, 0.0, 321, "Ecal"); -- Old TI12
+INSERT INTO "ECALTOPLEVEL_DATA" VALUES (1, 0.0, -71.6,    0.0, 0.0, 2.8, 0.0, 321, "BottomRow"); -- TI12 (with overlap)
+INSERT INTO "ECALTOPLEVEL_DATA" VALUES (2, 0.0,  49.6,    0.0, 0.0, 2.8, 0.0, 321, "TopRow");    -- TI12 (with overlap)
+INSERT INTO "ECALTOPLEVEL_DATA" VALUES (3, 0.0,   0.0, 3098.9, 0.0, 0.0, 0.0, 321, "Ecal"); -- TI12
+INSERT INTO "ECALTOPLEVEL_DATA" VALUES (4, 0.0, -71.6,    0.0, 0.0, 0.0, 0.0, 321, "BottomRow"); -- TB00 (with overlap)
+INSERT INTO "ECALTOPLEVEL_DATA" VALUES (5, 0.0,  49.6,    0.0, 0.0, 0.0, 0.0, 321, "TopRow");    -- TB00 (with overlap)
+INSERT INTO "ECALTOPLEVEL_DATA" VALUES (6, -17.22, -22.80, 1088.66, -2.8, -2.8, 0.0, 321, "Ecal"); -- test beam
+INSERT INTO "ECALTOPLEVEL_DATA" VALUES (7, 0.0, -72.0,    0.0, 0.0, 2.8, 0.0, 321, "BottomRow");   -- TI12 (overlap fixed)
+INSERT INTO "ECALTOPLEVEL_DATA" VALUES (8, 0.0,  50.0,    0.0, 0.0, 2.8, 0.0, 321, "TopRow");      -- TI12 (overlap fixed)
+INSERT INTO "ECALTOPLEVEL_DATA" VALUES (9, 0.0, -72.0,    0.0, 0.0, 0.0, 0.0, 321, "BottomRow");   -- TB01 (overlap fixed)
+INSERT INTO "ECALTOPLEVEL_DATA" VALUES (10, 0.0, 50.0,    0.0, 0.0, 0.0, 0.0, 321, "TopRow");     -- TB01 (overlap fixed)
 INSERT INTO "ECALTOPLEVEL_DATA2TAG" VALUES (100058, 0);
 INSERT INTO "ECALTOPLEVEL_DATA2TAG" VALUES (100058, 1);
 INSERT INTO "ECALTOPLEVEL_DATA2TAG" VALUES (100058, 2);
@@ -2872,6 +2878,13 @@ INSERT INTO "ECALTOPLEVEL_DATA2TAG" VALUES (107797, 3);
 INSERT INTO "ECALTOPLEVEL_DATA2TAG" VALUES (107822, 4);
 INSERT INTO "ECALTOPLEVEL_DATA2TAG" VALUES (107822, 5);
 INSERT INTO "ECALTOPLEVEL_DATA2TAG" VALUES (107822, 6);
+INSERT INTO "ECALTOPLEVEL_DATA2TAG" VALUES (107886, 3);
+INSERT INTO "ECALTOPLEVEL_DATA2TAG" VALUES (107886, 7);
+INSERT INTO "ECALTOPLEVEL_DATA2TAG" VALUES (107886, 8);
+INSERT INTO "ECALTOPLEVEL_DATA2TAG" VALUES (107887, 6);
+INSERT INTO "ECALTOPLEVEL_DATA2TAG" VALUES (107887, 9);
+INSERT INTO "ECALTOPLEVEL_DATA2TAG" VALUES (107887, 10);
+
 --
 --
 INSERT INTO "ECALROWGENERAL_DATA" VALUES (0, 2, 0.0, 2.8);
diff --git a/Scintillator/ScintDetDescr/VetoGeoModel/src/VetoStation.cxx b/Scintillator/ScintDetDescr/VetoGeoModel/src/VetoStation.cxx
index 7c0723d54..05e4a8b0b 100644
--- a/Scintillator/ScintDetDescr/VetoGeoModel/src/VetoStation.cxx
+++ b/Scintillator/ScintDetDescr/VetoGeoModel/src/VetoStation.cxx
@@ -102,7 +102,7 @@ VetoStation::build(VetoIdentifier id)
     id.setPlate(iPlate);
     GeoAlignableTransform* transform = new GeoAlignableTransform(GeoTrf::Translate3D(0.0, 
                                                                                      0.0,
-                                                                                     (plateThickness - activeDepth)/2 + iPlate * m_platePitch));
+                                                                                     plateCenterZ));
     station->add(transform);
     GeoVPhysVol* platePV = m_plate->build(id);
     station->add(platePV);
diff --git a/Simulation/G4Faser/G4FaserAlg/CMakeLists.txt b/Simulation/G4Faser/G4FaserAlg/CMakeLists.txt
index 979897a94..ec2babac5 100644
--- a/Simulation/G4Faser/G4FaserAlg/CMakeLists.txt
+++ b/Simulation/G4Faser/G4FaserAlg/CMakeLists.txt
@@ -31,21 +31,32 @@ atlas_add_test( G4FaserAlgConfig_TestFaser
                 PROPERTIES TIMEOUT 300 
                 PROPERTIES WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
 
-atlas_add_test( G4FaserAlgConfig_TestFaserNu
-                SCRIPT python ${CMAKE_CURRENT_SOURCE_DIR}/test/G4FaserAlgConfigNew_Test.py GeoModel.FaserVersion="'FASERNU-03'" IOVDb.GlobalTag="'OFLCOND-FASER-02'" Output.HITSFileName='faserNu.HITS.pool.root'
+atlas_add_test( G4FaserAlgConfig_TestFaserNu03
+                SCRIPT python ${CMAKE_CURRENT_SOURCE_DIR}/test/G4FaserAlgConfigNew_Test.py GeoModel.FaserVersion="'FASERNU-03'" IOVDb.GlobalTag="'OFLCOND-FASER-02'" Output.HITSFileName='faserNu03.HITS.pool.root'
                 PROPERTIES TIMEOUT 300 
                 PROPERTIES WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
 
-atlas_add_test( G4FaserAlgConfig_TestFaserNu_NewField
-                SCRIPT python ${CMAKE_CURRENT_SOURCE_DIR}/test/G4FaserAlgConfigNew_Test.py GeoModel.FaserVersion="'FASERNU-03'" IOVDb.GlobalTag="'OFLCOND-FASER-03'" Output.HITSFileName='faserNu.HITS.pool.root'
+atlas_add_test( G4FaserAlgConfig_TestFaserNu03_NewField
+                SCRIPT python ${CMAKE_CURRENT_SOURCE_DIR}/test/G4FaserAlgConfigNew_Test.py GeoModel.FaserVersion="'FASERNU-03'" IOVDb.GlobalTag="'OFLCOND-FASER-03'" Output.HITSFileName='faserNu03_NewField.HITS.pool.root'
                 PROPERTIES TIMEOUT 300 
                 PROPERTIES WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
 
-atlas_add_test( G4FaserAlgConfig_TestTestbeam
-                SCRIPT python ${CMAKE_CURRENT_SOURCE_DIR}/test/G4FaserAlgConfigNew_Test.py GeoModel.FaserVersion="'FASER-TB00'" IOVDb.GlobalTag="'OFLCOND-FASER-TB00'" Output.HITSFileName='tb.HITS.pool.root'
+atlas_add_test( G4FaserAlgConfig_TestFaserNu04
+                SCRIPT python ${CMAKE_CURRENT_SOURCE_DIR}/test/G4FaserAlgConfigNew_Test.py GeoModel.FaserVersion="'FASERNU-04'" IOVDb.GlobalTag="'OFLCOND-FASER-03'" Output.HITSFileName='faserNu04.HITS.pool.root'
                 PROPERTIES TIMEOUT 300 
                 PROPERTIES WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
 
+atlas_add_test( G4FaserAlgConfig_TestTestbeam00
+                SCRIPT python ${CMAKE_CURRENT_SOURCE_DIR}/test/G4FaserAlgConfigNew_Test.py GeoModel.FaserVersion="'FASER-TB00'" IOVDb.GlobalTag="'OFLCOND-FASER-TB00'" Output.HITSFileName='tb00.HITS.pool.root'
+                PROPERTIES TIMEOUT 300 
+                PROPERTIES WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
+
+atlas_add_test( G4FaserAlgConfig_TestTestbeam01
+                SCRIPT python ${CMAKE_CURRENT_SOURCE_DIR}/test/G4FaserAlgConfigNew_Test.py GeoModel.FaserVersion="'FASER-TB01'" IOVDb.GlobalTag="'OFLCOND-FASER-TB00'" Output.HITSFileName='tb01.HITS.pool.root'
+                PROPERTIES TIMEOUT 300 
+                PROPERTIES WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
+
+
 # Install files from the package:
 atlas_install_python_modules( python/*.py )
 atlas_install_scripts( test/*.py )
diff --git a/Simulation/G4Faser/G4FaserAlg/test/G4FaserAlgConfigNew_Test.py b/Simulation/G4Faser/G4FaserAlg/test/G4FaserAlgConfigNew_Test.py
index df6abb7ab..fb07e943a 100755
--- a/Simulation/G4Faser/G4FaserAlg/test/G4FaserAlgConfigNew_Test.py
+++ b/Simulation/G4Faser/G4FaserAlg/test/G4FaserAlgConfigNew_Test.py
@@ -48,7 +48,7 @@ if __name__ == '__main__':
     ConfigFlags.addFlag("Sim.Beam.xshift", 0)  # Potential beam shift
     ConfigFlags.addFlag("Sim.Beam.yshift", 0)        
 
-    ConfigFlags.GeoModel.FaserVersion = "FASERNU-03"             # Geometry set-up
+    ConfigFlags.GeoModel.FaserVersion = "FASERNU-04"             # Geometry set-up
     ConfigFlags.IOVDb.GlobalTag = "OFLCOND-FASER-03"             # Conditions set-up
     ConfigFlags.addFlag("Input.InitialTimeStamp", 0)             # To avoid autoconfig 
     ConfigFlags.GeoModel.Align.Dynamic = False
@@ -172,6 +172,11 @@ if __name__ == '__main__':
 
     #cfg.getEventAlgo("OutputStreamHITS").ItemList += ["McEventCollection#BeamTruthEvent_ATLASCoord"]    
 #
+# Uncomment to check volumes for overlap - will cause CTest to fail due to overwriting file
+#
+#    from G4DebuggingTools.G4DebuggingToolsConfigNew import VolumeDebugger
+#    cfg.merge(VolumeDebugger(ConfigFlags, name="G4UA::UserActionSvc", TargetVolume="", Verbose=True))
+#
 # Dump config
 #
     from AthenaConfiguration.ComponentFactory import CompFactory
diff --git a/Tracker/TrackerDetDescr/DipoleGeoModel/src/DipoleFactory.cxx b/Tracker/TrackerDetDescr/DipoleGeoModel/src/DipoleFactory.cxx
index 6129c49cc..ccfda7160 100644
--- a/Tracker/TrackerDetDescr/DipoleGeoModel/src/DipoleFactory.cxx
+++ b/Tracker/TrackerDetDescr/DipoleGeoModel/src/DipoleFactory.cxx
@@ -93,13 +93,16 @@ void DipoleFactory::create(GeoPhysVol *world )
   double upstreamThickness = wrappingParameters->thickness1();
   double downstreamThickness = wrappingParameters->thickness2();
   double wrappingRadius = wrappingParameters->radius();
+  msg(MSG::ALWAYS) << "Upstream wrapping thickness: " << upstreamThickness << "; Downstream wrapping thickness: " << downstreamThickness << endmsg;
+  msg(MSG::ALWAYS) << "Upstream wrapping position: " << -(parameters->longLength() + upstreamThickness)/2 << "; Downstream wrapping position: " << (parameters->longLength() + downstreamThickness)/2 << endmsg;
 
   GeoTrf::Transform3D dipoleTransform = parameters->partTransform("Dipole");
   const GeoTube* shortShape = new GeoTube(parameters->innerRadius(), parameters->outerRadius(), parameters->shortLength()/2);
   GeoLogVol* shortLog = new GeoLogVol("ShortDipole", shortShape, NdFeB);
   const GeoTube* longShape = new GeoTube(parameters->innerRadius(), parameters->outerRadius(), parameters->longLength()/2);
   GeoLogVol* longLog = new GeoLogVol("LongDipole", longShape, NdFeB);
-  const GeoTube* wrappedShape = new GeoTube(parameters->innerRadius(), std::max(parameters->outerRadius(), wrappingRadius), parameters->longLength()/2 + std::max(upstreamThickness, downstreamThickness));
+  // const GeoTube* wrappedShape = new GeoTube(parameters->innerRadius(), std::max(parameters->outerRadius(), wrappingRadius), parameters->longLength()/2 + std::max(upstreamThickness, downstreamThickness));
+  const GeoTube* wrappedShape = new GeoTube(0.0, std::max(parameters->outerRadius(), wrappingRadius), parameters->longLength()/2 + std::max(upstreamThickness, downstreamThickness));
   GeoLogVol* wrappedLog = new GeoLogVol("WrappedLongDipole", wrappedShape, air);
   GeoPhysVol* wrappedPV = new GeoPhysVol(wrappedLog);
   GeoPhysVol* longPV = new GeoPhysVol(longLog);
@@ -113,7 +116,7 @@ void DipoleFactory::create(GeoPhysVol *world )
   const GeoTube* downstreamShape = new GeoTube(0.0, wrappingRadius, downstreamThickness/2);
   GeoLogVol* downstreamLog = new GeoLogVol("DownstreamWrapping", downstreamShape, downstreamMaterial);
   GeoPhysVol* downstreamPV = new GeoPhysVol(downstreamLog);
-  wrappedPV->add(new GeoTransform(GeoTrf::Translate3D(0.0, 0.0, (parameters->longLength() + upstreamThickness)/2)));
+  wrappedPV->add(new GeoTransform(GeoTrf::Translate3D(0.0, 0.0, (parameters->longLength() + downstreamThickness)/2)));
   wrappedPV->add(downstreamPV);
 
   std::vector<std::string> partNames {"UpstreamDipole", "CentralDipole", "DownstreamDipole"};
-- 
GitLab