From d8451ab8e350dde49560c1c329e95fb55bfb98f9 Mon Sep 17 00:00:00 2001 From: armin-ilg Date: Mon, 23 Sep 2024 14:11:11 +0200 Subject: [PATCH] Update to IDEA_o1_v03 vertex and ability to specify resolution per layer --- VTXdigi/include/VTXdigitizer.h | 16 ++-- VTXdigi/src/VTXdigitizer.cpp | 50 +++++++----- VTXdigi/test/runVTXdigitizer.py | 130 ++++++++++++++------------------ 3 files changed, 96 insertions(+), 100 deletions(-) diff --git a/VTXdigi/include/VTXdigitizer.h b/VTXdigi/include/VTXdigitizer.h index e0cf0de..84515e5 100644 --- a/VTXdigi/include/VTXdigitizer.h +++ b/VTXdigi/include/VTXdigitizer.h @@ -30,11 +30,13 @@ namespace edm4hep { #include "DDSegmentation/BitFieldCoder.h" +#include + /** @class VTXdigitizer * * Algorithm for creating digitized (meaning 'reconstructed' for now) vertex detector hits (edm4hep::TrackerHit3D) from Geant4 hits (edm4hep::SimTrackerHit). * - * @author Brieuc Francois + * @author Brieuc Francois, Armin Ilg * @date 2023-03 * */ @@ -76,13 +78,13 @@ class VTXdigitizer : public Gaudi::Algorithm { dd4hep::VolumeManager m_volman; // x resolution in um - FloatProperty m_x_resolution{this, "xResolution", 0.1, "Spatial resolution in the x direction [um] (r-phi direction in barrel, z direction in disks)"}; + Gaudi::Property> m_x_resolution{this, "xResolution", {0.1}, "Spatial resolutions in the x direction per layer [um] (r-phi direction in barrel, z direction in disks)"}; // y resolution in um - FloatProperty m_y_resolution{this, "yResolution", 0.1, "Spatial resolution in the y direction [um] (r direction in barrel, r-phi direction in disks)"}; + Gaudi::Property> m_y_resolution{this, "yResolution", {0.1}, "Spatial resolutions in the y direction per layer [um] (r direction in barrel, r-phi direction in disks)"}; // t resolution in ns - FloatProperty m_t_resolution{this, "tResolution", 0.1, "Time resolution [ns]"}; + Gaudi::Property> m_t_resolution{this, "tResolution", {0.1}, "Time resolutions per layer [ns]"}; // Surface manager used to project hits onto sensitive surface with forceHitsOntoSurface argument mutable const dd4hep::rec::SurfaceMap* _map; @@ -94,7 +96,7 @@ class VTXdigitizer : public Gaudi::Algorithm { IRndmGenSvc* m_randSvc; // Gaussian random number generator used for smearing - Rndm::Numbers m_gauss_x; - Rndm::Numbers m_gauss_y; - Rndm::Numbers m_gauss_time; + std::vector m_gauss_x_vec; + std::vector m_gauss_y_vec; + std::vector m_gauss_t_vec; }; diff --git a/VTXdigi/src/VTXdigitizer.cpp b/VTXdigi/src/VTXdigitizer.cpp index 94b04d0..54d382b 100644 --- a/VTXdigi/src/VTXdigitizer.cpp +++ b/VTXdigi/src/VTXdigitizer.cpp @@ -17,17 +17,29 @@ StatusCode VTXdigitizer::initialize() { error() << "Couldn't get RndmGenSvc!" << endmsg; return StatusCode::FAILURE; } - if (m_gauss_x.initialize(m_randSvc, Rndm::Gauss(0., m_x_resolution)).isFailure()) { - error() << "Couldn't initialize RndmGenSvc!" << endmsg; - return StatusCode::FAILURE; + + m_gauss_x_vec.resize(m_x_resolution.size()); + for (size_t i = 0; i < m_x_resolution.size(); ++i) { + if (m_gauss_x_vec[i].initialize(m_randSvc, Rndm::Gauss(0., m_x_resolution[i])).isFailure()) { + error() << "Couldn't initialize RndmGenSvc!" << endmsg; + return StatusCode::FAILURE; + } } - if (m_gauss_y.initialize(m_randSvc, Rndm::Gauss(0., m_y_resolution)).isFailure()) { - error() << "Couldn't initialize RndmGenSvc!" << endmsg; - return StatusCode::FAILURE; + + m_gauss_y_vec.resize(m_y_resolution.size()); + for (size_t i = 0; i < m_y_resolution.size(); ++i) { + if (m_gauss_y_vec[i].initialize(m_randSvc, Rndm::Gauss(0., m_y_resolution[i])).isFailure()) { + error() << "Couldn't initialize RndmGenSvc!" << endmsg; + return StatusCode::FAILURE; + } } - if (m_gauss_time.initialize(m_randSvc, Rndm::Gauss(0., m_t_resolution)).isFailure()) { - error() << "Couldn't initialize RndmGenSvc!" << endmsg; - return StatusCode::FAILURE; + + m_gauss_t_vec.resize(m_t_resolution.size()); + for (size_t i = 0; i < m_t_resolution.size(); ++i) { + if (m_gauss_t_vec[i].initialize(m_randSvc, Rndm::Gauss(0., m_t_resolution[i])).isFailure()) { + error() << "Couldn't initialize RndmGenSvc!" << endmsg; + return StatusCode::FAILURE; + } } // check if readout exists @@ -126,22 +138,20 @@ StatusCode VTXdigitizer::execute(const EventContext&) const { // Smear the hit in the local sensor coordinates double digiHitLocalPosition[3]; - if (m_readoutName == "VTXIBCollection" || - m_readoutName == "VTXOBCollection" || - m_readoutName == "VertexBarrelCollection" || + int iLayer = m_decoder->get(cellID, "layer"); + if (m_readoutName == "VertexBarrelCollection" || m_readoutName == "SiWrBCollection") { // In barrel, the sensor box is along y-z digiHitLocalPosition[0] = simHitLocalPositionVector.x(); - digiHitLocalPosition[1] = simHitLocalPositionVector.y() + m_gauss_x.shoot() * dd4hep::mm; - digiHitLocalPosition[2] = simHitLocalPositionVector.z() + m_gauss_y.shoot() * dd4hep::mm; - } else if (m_readoutName == "VTXDCollection" || - m_readoutName == "VertexEndcapCollection" || + digiHitLocalPosition[1] = simHitLocalPositionVector.y() + m_gauss_x_vec[iLayer].shoot() * dd4hep::mm; + digiHitLocalPosition[2] = simHitLocalPositionVector.z() + m_gauss_y_vec[iLayer].shoot() * dd4hep::mm; + } else if (m_readoutName == "VertexEndcapCollection" || m_readoutName == "SiWrDCollection") { // In the disks, the sensor box is already in x-y - digiHitLocalPosition[0] = simHitLocalPositionVector.x() + m_gauss_x.shoot() * dd4hep::mm; - digiHitLocalPosition[1] = simHitLocalPositionVector.y() + m_gauss_y.shoot() * dd4hep::mm; + digiHitLocalPosition[0] = simHitLocalPositionVector.x() + m_gauss_x_vec[iLayer].shoot() * dd4hep::mm; + digiHitLocalPosition[1] = simHitLocalPositionVector.y() + m_gauss_y_vec[iLayer].shoot() * dd4hep::mm; digiHitLocalPosition[2] = simHitLocalPositionVector.z(); } else { error() - << "VTX readout name (m_readoutName) unknown!" + << "VTX readout name (m_readoutName) unknown or xResolution/yResolution/tResolution not defining all detector layer resolutions!" << endmsg; return StatusCode::FAILURE; } @@ -167,7 +177,7 @@ StatusCode VTXdigitizer::execute(const EventContext&) const { output_digi_hit.setPosition(digiHitGlobalPositionVector); // Apply time smearing - output_digi_hit.setTime(input_sim_hit.getTime() + m_gauss_time.shoot()); + output_digi_hit.setTime(input_sim_hit.getTime() + m_gauss_t_vec[iLayer].shoot()); output_digi_hit.setCellID(cellID); diff --git a/VTXdigi/test/runVTXdigitizer.py b/VTXdigi/test/runVTXdigitizer.py index 943542e..3bf05b4 100644 --- a/VTXdigi/test/runVTXdigitizer.py +++ b/VTXdigi/test/runVTXdigitizer.py @@ -113,28 +113,25 @@ from Configurables import SimG4SaveTrackerHits ### CLD -SimG4SaveTrackerHitsB = SimG4SaveTrackerHits("SimG4SaveTrackerHitsB", readoutName="VertexBarrelCollection") -SimG4SaveTrackerHitsB.SimTrackHits.Path = "VTXB_simTrackerHits" +# SimG4SaveTrackerHitsB = SimG4SaveTrackerHits("SimG4SaveTrackerHitsB", readoutName="VertexBarrelCollection") +# SimG4SaveTrackerHitsB.SimTrackHits.Path = "VTXB_simTrackerHits" -SimG4SaveTrackerHitsE = SimG4SaveTrackerHits("SimG4SaveTrackerHitsE", readoutName="VertexEndcapCollection") -SimG4SaveTrackerHitsE.SimTrackHits.Path = "VTXE_simTrackerHits" +# SimG4SaveTrackerHitsE = SimG4SaveTrackerHits("SimG4SaveTrackerHitsE", readoutName="VertexEndcapCollection") +# SimG4SaveTrackerHitsE.SimTrackHits.Path = "VTXE_simTrackerHits" ### IDEA -SimG4SaveTrackerHitsIB = SimG4SaveTrackerHits("SimG4SaveTrackerHitsIB", readoutName="VTXIBCollection") -SimG4SaveTrackerHitsIB.SimTrackHits.Path = "VTXIB_simTrackerHits" - -SimG4SaveTrackerHitsOB = SimG4SaveTrackerHits("SimG4SaveTrackerHitsOB", readoutName="VTXOBCollection") -SimG4SaveTrackerHitsOB.SimTrackHits.Path = "VTXOB_simTrackerHits" +SimG4SaveTrackerHitsB = SimG4SaveTrackerHits("SimG4SaveTrackerHitsB", readoutName="VertexBarrelCollection") +SimG4SaveTrackerHitsB.SimTrackHits.Path = "VTXB_simTrackerHits" -SimG4SaveTrackerHitsD = SimG4SaveTrackerHits("SimG4SaveTrackerHitsD", readoutName="VTXDCollection") +SimG4SaveTrackerHitsD = SimG4SaveTrackerHits("SimG4SaveTrackerHitsD", readoutName="VertexEndcapCollection") SimG4SaveTrackerHitsD.SimTrackHits.Path = "VTXD_simTrackerHits" -SimG4SaveTrackerHitsSiWrB = SimG4SaveTrackerHits("SimG4SaveTrackerHitsSiWrB", readoutName="SiWrBCollection") -SimG4SaveTrackerHitsSiWrB.SimTrackHits.Path = "SiWrB_simTrackerHits" +# SimG4SaveTrackerHitsSiWrB = SimG4SaveTrackerHits("SimG4SaveTrackerHitsSiWrB", readoutName="SiWrBCollection") +# SimG4SaveTrackerHitsSiWrB.SimTrackHits.Path = "SiWrB_simTrackerHits" -SimG4SaveTrackerHitsSiWrD = SimG4SaveTrackerHits("SimG4SaveTrackerHitsSiWrD", readoutName="SiWrDCollection") -SimG4SaveTrackerHitsSiWrD.SimTrackHits.Path = "SiWrD_simTrackerHits" +# SimG4SaveTrackerHitsSiWrD = SimG4SaveTrackerHits("SimG4SaveTrackerHitsSiWrD", readoutName="SiWrDCollection") +# SimG4SaveTrackerHitsSiWrD.SimTrackHits.Path = "SiWrD_simTrackerHits" from Configurables import SimG4Alg @@ -148,7 +145,7 @@ # IDEA geantsim = SimG4Alg("SimG4Alg", - outputs= [SimG4SaveTrackerHitsIB, SimG4SaveTrackerHitsOB, SimG4SaveTrackerHitsD, + outputs= [SimG4SaveTrackerHitsB, SimG4SaveTrackerHitsD, #SimG4SaveTrackerHitsSiWrB, SimG4SaveTrackerHitsSiWrD, #saveHistTool ], @@ -159,69 +156,56 @@ from Configurables import VTXdigitizer ### For CLD. Not working yet, SimG4 doesn't produce hits in CLD vertex yet -vtxb_digitizer = VTXdigitizer("VTXBdigitizer", +# cld_vtxb_digitizer = VTXdigitizer("VTXBdigitizer", +# inputSimHits = SimG4SaveTrackerHitsB.SimTrackHits.Path, +# outputDigiHits = SimG4SaveTrackerHitsB.SimTrackHits.Path.replace("sim", "digi"), +# outputSimDigiAssociation = SimG4SaveTrackerHitsB.SimTrackHits.Path.replace("simTrackerHits", "simDigiAssociation"), +# detectorName = "Vertex", +# readoutName = "VertexBarrelCollection", +# xResolutions = [vertexBarrelResolution_x, vertexBarrelResolution_x, vertexBarrelResolution_x, vertexBarrelResolution_x, vertexBarrelResolution_x, vertexBarrelResolution_x], +# yResolutions = [vertexBarrelResolution_y, vertexBarrelResolution_y, vertexBarrelResolution_y, vertexBarrelResolution_y, vertexBarrelResolution_y, vertexBarrelResolution_y], +# tResolutions = [vertexBarrelResolution_t, vertexBarrelResolution_t, vertexBarrelResolution_t, vertexBarrelResolution_t, vertexBarrelResolution_t, vertexBarrelResolution_t], +# forceHitsOntoSurface = False, +# OutputLevel = INFO +# ) + +# cld_vtxd_digitizer = VTXdigitizer("VTXDdigitizer", +# inputSimHits = SimG4SaveTrackerHitsE.SimTrackHits.Path, +# outputDigiHits = SimG4SaveTrackerHitsE.SimTrackHits.Path.replace("sim", "digi"), +# outputSimDigiAssociation = SimG4SaveTrackerHitsE.SimTrackHits.Path.replace("simTrackerHits", "simDigiAssociation"), +# detectorName = "Vertex", +# readoutName = "VertexEndcapCollection", +# xResolutions = [vertexEndcapResolution_x, vertexEndcapResolution_x, vertexEndcapResolution_x, vertexEndcapResolution_x, vertexEndcapResolution_x, vertexEndcapResolution_x], +# yResolutions = [vertexEndcapResolution_y, vertexEndcapResolution_y, vertexEndcapResolution_y, vertexEndcapResolution_y, vertexEndcapResolution_y, vertexEndcapResolution_y], +# tResolutions = [vertexEndcapResolution_t, vertexEndcapResolution_t, vertexEndcapResolution_t, vertexEndcapResolution_t, vertexEndcapResolution_t, vertexEndcapResolution_t], +# forceHitsOntoSurface = False, +# OutputLevel = INFO +# ) + + +### For IDEA +idea_vtxb_digitizer = VTXdigitizer("VTXBdigitizer", inputSimHits = SimG4SaveTrackerHitsB.SimTrackHits.Path, outputDigiHits = SimG4SaveTrackerHitsB.SimTrackHits.Path.replace("sim", "digi"), outputSimDigiAssociation = SimG4SaveTrackerHitsB.SimTrackHits.Path.replace("simTrackerHits", "simDigiAssociation"), detectorName = "Vertex", readoutName = "VertexBarrelCollection", - xResolution = vertexBarrelResolution_x, - yResolution = vertexBarrelResolution_y, - tResolution = vertexBarrelResolution_t, - forceHitsOntoSurface = False, - OutputLevel = INFO -) - -vtxe_digitizer = VTXdigitizer("VTXEdigitizer", - inputSimHits = SimG4SaveTrackerHitsE.SimTrackHits.Path, - outputDigiHits = SimG4SaveTrackerHitsE.SimTrackHits.Path.replace("sim", "digi"), - outputSimDigiAssociation = SimG4SaveTrackerHitsE.SimTrackHits.Path.replace("simTrackerHits", "simDigiAssociation"), - detectorName = "Vertex", - readoutName = "VertexEndcapCollection", - xResolution = vertexEndcapResolution_x, - yResolution = vertexEndcapResolution_y, - tResolution = vertexEndcapResolution_t, + xResolution = [innerVertexResolution_x, innerVertexResolution_x, innerVertexResolution_x, outerVertexResolution_x, outerVertexResolution_x], # mm, r-phi direction + yResolution = [innerVertexResolution_y, innerVertexResolution_y, innerVertexResolution_y, outerVertexResolution_y, outerVertexResolution_y], # mm, z direction + tResolution = [innerVertexResolution_t, innerVertexResolution_t, innerVertexResolution_t, outerVertexResolution_t, outerVertexResolution_t], # ns forceHitsOntoSurface = False, OutputLevel = INFO ) - -### For IDEA -vtxib_digitizer = VTXdigitizer("VTXIBdigitizer", - inputSimHits = SimG4SaveTrackerHitsIB.SimTrackHits.Path, - outputDigiHits = SimG4SaveTrackerHitsIB.SimTrackHits.Path.replace("sim", "digi"), - outputSimDigiAssociation = SimG4SaveTrackerHitsIB.SimTrackHits.Path.replace("simTrackerHits", "simDigiAssociation"), - detectorName = "Vertex", - readoutName = "VTXIBCollection", - xResolution = innerVertexResolution_x, # mm, r-phi direction - yResolution = innerVertexResolution_y, # mm, z direction - tResolution = innerVertexResolution_t, - forceHitsOntoSurface = False, - OutputLevel = INFO -) - -vtxob_digitizer = VTXdigitizer("VTXOBdigitizer", - inputSimHits = SimG4SaveTrackerHitsOB.SimTrackHits.Path, - outputDigiHits = SimG4SaveTrackerHitsOB.SimTrackHits.Path.replace("sim", "digi"), - outputSimDigiAssociation = SimG4SaveTrackerHitsOB.SimTrackHits.Path.replace("simTrackerHits", "simDigiAssociation"), - detectorName = "Vertex", - readoutName = "VTXOBCollection", - xResolution = outerVertexResolution_x, # mm, r-phi direction - yResolution = outerVertexResolution_y, # mm, z direction - tResolution = outerVertexResolution_t, # ns - forceHitsOntoSurface = False, - OutputLevel = INFO -) - -vtxd_digitizer = VTXdigitizer("VTXDdigitizer", +idea_vtxd_digitizer = VTXdigitizer("VTXDdigitizer", inputSimHits = SimG4SaveTrackerHitsD.SimTrackHits.Path, outputDigiHits = SimG4SaveTrackerHitsD.SimTrackHits.Path.replace("sim", "digi"), outputSimDigiAssociation = SimG4SaveTrackerHitsD.SimTrackHits.Path.replace("simTrackerHits", "simDigiAssociation"), detectorName = "Vertex", - readoutName = "VTXDCollection", - xResolution = outerVertexResolution_x, # mm, r direction - yResolution = outerVertexResolution_y, # mm, phi direction - tResolution = outerVertexResolution_t, # ns + readoutName = "VertexEndcapCollection", + xResolution = [outerVertexResolution_x, outerVertexResolution_x, outerVertexResolution_x], # mm, r direction + yResolution = [outerVertexResolution_y, outerVertexResolution_y, outerVertexResolution_y], # mm, phi direction + tResolution = [outerVertexResolution_t, outerVertexResolution_t, outerVertexResolution_t], # ns forceHitsOntoSurface = False, OutputLevel = INFO ) @@ -231,9 +215,9 @@ # outputDigiHits = SimG4SaveTrackerHitsSiWrB.SimTrackHits.Path.replace("sim", "digi"), # detectorName = "SiliconWrapper", # readoutName = "SiWrBCollection", -# xResolution = siWrapperResolution_x, # mm, r direction -# yResolution = siWrapperResolution_y, # mm, phi direction -# tResolution = siWrapperResolution_t, # ns +# xResolutions = siWrapperResolution_x, # mm, r direction +# yResolutions = siWrapperResolution_y, # mm, phi direction +# tResolutions = siWrapperResolution_t, # ns # forceHitsOntoSurface = False, # OutputLevel = INFO #) @@ -243,9 +227,9 @@ # outputDigiHits = SimG4SaveTrackerHitsSiWrD.SimTrackHits.Path.replace("sim", "digi"), # detectorName = "SiliconWrapper", # readoutName = "SiWrDCollection", -# xResolution = siWrapperResolution_x, # mm, r direction -# yResolution = siWrapperResolution_y, # mm, phi direction -# tResolution = siWrapperResolution_t, # ns +# xResolutions = siWrapperResolution_x, # mm, r direction +# yResolutions = siWrapperResolution_y, # mm, phi direction +# tResolutions = siWrapperResolution_t, # ns # forceHitsOntoSurface = False, # OutputLevel = INFO #) @@ -281,7 +265,7 @@ # genAlg, # hepmc_converter, # geantsim, -# vtxb_digitizer,vtxe_digitizer, +# cld_vtxb_digitizer, cld_vtxd_digitizer, # out # ], # EvtSel = 'NONE', @@ -296,7 +280,7 @@ genAlg, hepmc_converter, geantsim, - vtxib_digitizer, vtxob_digitizer, vtxd_digitizer, + idea_vtxb_digitizer, idea_vtxd_digitizer, #siwrb_digitizer, siwrd_digitizer, out ],