diff --git a/CMakeLists.txt b/CMakeLists.txt index 716cb5c..81c2d2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ endfunction() add_subdirectory(DCHdigi) add_subdirectory(ARCdigi) add_subdirectory(VTXdigi) +add_subdirectory(MUONdigi) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) add_subdirectory(Tracking) diff --git a/MUONdigi/CMakeLists.txt b/MUONdigi/CMakeLists.txt new file mode 100644 index 0000000..5a56ae1 --- /dev/null +++ b/MUONdigi/CMakeLists.txt @@ -0,0 +1,80 @@ +set(PackageName MUONdigi) + +project(${PackageName}) + +# Build the extension data model and link it against the upstream model +PODIO_GENERATE_DATAMODEL(muon_extension dataFormatExtension/muonSystemHit.yaml ext_headers ext_sources + UPSTREAM_EDM edm4hep:${EDM4HEP_DATA_DIR}/edm4hep.yaml + IO_BACKEND_HANDLERS ${PODIO_IO_HANDLERS} + OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR}) +PODIO_ADD_DATAMODEL_CORE_LIB(muon_extension "${ext_headers}" "${ext_sources}" + OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR}) +target_link_libraries(muon_extension PUBLIC EDM4HEP::edm4hep) +PODIO_ADD_ROOT_IO_DICT(muon_extensionDict muon_extension "${ext_headers}" src/selection.xml + OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR}) +#PODIO_ADD_SIO_IO_BLOCKS(muon_extension "${ext_headers}" "${ext_sources}") +add_library(muon_extension::muon_extensionDict ALIAS muon_extensionDict) +list(APPEND EXTENSION_INSTALL_LIBS muon_extension muon_extensionDict) +install(TARGETS ${EXTENSION_INSTALL_LIBS} + EXPORT ${PROJECT_NAME}Targets + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib + PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/muon_extension" + COMPONENT dev) + +install(FILES + "${PROJECT_BINARY_DIR}/muon_extensionDictDict.rootmap" + DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT dev) + +install(FILES + dataFormatExtension/muonSystemHit.yaml + DESTINATION "${CMAKE_INSTALL_DATADIR}/muon_extension" COMPONENT dev) + +install(FILES + "${PROJECT_BINARY_DIR}/libmuon_extensionDict_rdict.pcm" + DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT dev) + +file(GLOB sources + ${PROJECT_SOURCE_DIR}/src/*.cpp +) + +file(GLOB headers + ${PROJECT_SOURCE_DIR}/include/*.h +) + +gaudi_add_module(${PackageName} + SOURCES ${sources} + LINK + Gaudi::GaudiAlgLib + Gaudi::GaudiKernel + EDM4HEP::edm4hep + muon_extensionDict + k4FWCore::k4FWCore + DD4hep::DDRec +) + +target_include_directories(${PackageName} PUBLIC + $ + $ + ${CMAKE_INSTALL_PREFIX}/muon_extension +) + +set_target_properties(MUONdigi PROPERTIES PUBLIC_HEADER "${headers}") + +file(GLOB scripts + ${PROJECT_SOURCE_DIR}/test/*.py +) + +file(COPY ${scripts} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test) + +install(TARGETS MUONdigi + EXPORT ${CMAKE_PROJECT_NAME}Targets + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib + PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/@{CMAKE_PROJECT_NAME}" COMPONENT dev +) + +install(FILES ${scripts} DESTINATION test) + +SET(test_name "test_MUONsimpleDigitizer") +ADD_TEST(NAME t_${test_name} COMMAND k4run test/runMUONsimpleDigitizer.py) \ No newline at end of file diff --git a/MUONdigi/dataFormatExtension/muonSystemHit.yaml b/MUONdigi/dataFormatExtension/muonSystemHit.yaml new file mode 100644 index 0000000..8ed466d --- /dev/null +++ b/MUONdigi/dataFormatExtension/muonSystemHit.yaml @@ -0,0 +1,21 @@ +--- +schema_version: 1 +options: + # should getters / setters be prefixed with get / set? + getSyntax: True + # should POD members be exposed with getters/setters in classes that have them as members? + exposePODMembers: False + includeSubfolder: True + +datatypes: + + extension::MCRecoMuonSystemDigiAssociation: + Description: "Association between a Digi hits and the corresponding simulated hit for the muon system" + Author: "B. Francois, CERN; Mahmoud Ali, INFN-Bo" + Members: + - float weight // weight of this association + - edm4hep::Vector3d positionDifference // the difference between simHit and DigiHit positions. + OneToOneRelations: + - edm4hep::TrackerHit3D digi // reference to the digitized hit + - edm4hep::SimTrackerHit sim // reference to the simulated hit + \ No newline at end of file diff --git a/MUONdigi/include/MUONsimpleDigitizer.h b/MUONdigi/include/MUONsimpleDigitizer.h new file mode 100644 index 0000000..9e1c2a6 --- /dev/null +++ b/MUONdigi/include/MUONsimpleDigitizer.h @@ -0,0 +1,107 @@ +#pragma once + +// GAUDI +#include "Gaudi/Property.h" +#include "GaudiAlg/GaudiAlgorithm.h" +#include "GaudiKernel/IRndmGenSvc.h" +#include "GaudiKernel/RndmGenerators.h" + +// K4FWCORE & podio +#include "k4FWCore/DataHandle.h" +#include "k4Interface/IGeoSvc.h" +#include "podio/UserDataCollection.h" +#include "edm4hep/Vector3d.h" + +// EDM4HEP +#include "edm4hep/SimTrackerHitCollection.h" +#include "edm4hep/TrackCollection.h" +#if __has_include("edm4hep/TrackerHit3DCollection.h") +#include "edm4hep/TrackerHit3DCollection.h" +#else +#include "edm4hep/TrackerHitCollection.h" + +namespace edm4hep { + using TrackerHit3DCollection = edm4hep::TrackerHitCollection; +} // namespace edm4hep +#endif + +#include "extension/MCRecoMuonSystemDigiAssociationCollection.h" + +// DD4HEP +#include "DD4hep/Detector.h" // for dd4hep::VolumeManager +#include "DDRec/Vector3D.h" +#include "DDRec/SurfaceManager.h" +#include "DDSegmentation/BitFieldCoder.h" + +/** @class MUONsimpleDigitizer + * + * Algorithm for creating digitized Muon system hits (still based on edm4hep::TrackerHit3D) from edm4hep::SimTrackerHit. + * You have to specify the expected resolution in z and in xy. + * + * @author Mahmoud Ali + * @date 2023-09 + * + */ + +class MUONsimpleDigitizer : public GaudiAlgorithm { +public: + explicit MUONsimpleDigitizer(const std::string&, ISvcLocator*); + virtual ~MUONsimpleDigitizer(); + /** Initialize. + * @return status code + */ + virtual StatusCode initialize() final; + /** Execute. + * @return status code + */ + virtual StatusCode execute() final; + /** Finalize. + * @return status code + */ + virtual StatusCode finalize() final; + +private: + // Input sim tracker hit collection name + DataHandle m_input_sim_hits{"inputSimHits", Gaudi::DataHandle::Reader, this}; + // Output digitized tracker hit collection name + DataHandle m_output_digi_hits{"outputDigiHits", Gaudi::DataHandle::Writer, this}; + // Output association between digitized and simulated hit collections name + DataHandle m_output_sim_digi_association{"outputSimDigiAssociation", Gaudi::DataHandle::Writer, this}; + + // Detector readout name + Gaudi::Property m_readoutName{this, "readoutName", "MuonSystemCollection", "Name of the detector readout"}; + // Pointer to the geometry service + ServiceHandle m_geoSvc; + // Decoder for the cellID + dd4hep::DDSegmentation::BitFieldCoder* m_decoder; + // Volume manager to get the physical cell sensitive volume + dd4hep::VolumeManager m_volman; + + // x position resolution in mm + FloatProperty m_x_resolution{this, "xResolution", 1.0, + "Spatial resolution in the x direction [mm]"}; + // y resolution in mm + FloatProperty m_y_resolution{this, "yResolution", 1.0, "Spatial resolution in the y direction [mm]"}; + + // z resolution in mm + FloatProperty m_z_resolution{this, "zResolution", 1.0, "Spatial resolution in the z direction [mm]"}; + + // Detector efficiency + FloatProperty m_efficiency{this, "efficiency", 0.95, "Detector efficiency"}; + + // Declaration of validation distribution + DataHandle> m_simDigiDifferenceX{"simDigiDifferenceX", Gaudi::DataHandle::Writer, this}; // mm + DataHandle> m_simDigiDifferenceY{"simDigiDifferenceY", Gaudi::DataHandle::Writer, this}; // mm + DataHandle> m_simDigiDifferenceZ{"simDigiDifferenceZ", Gaudi::DataHandle::Writer, this}; // mm + + // Random Number Service + IRndmGenSvc* m_randSvc; + // Gaussian random number generator used for the smearing of the x position + Rndm::Numbers m_gauss_x; + // Gaussian random number generator used for the smearing of the y position + Rndm::Numbers m_gauss_y; + // Gaussian random number generator used for the smearing of the z position + Rndm::Numbers m_gauss_z; + // Flat random number generator used for efficiency + Rndm::Numbers m_flat; +}; \ No newline at end of file diff --git a/MUONdigi/src/MUONsimpleDigitizer.cpp b/MUONdigi/src/MUONsimpleDigitizer.cpp new file mode 100644 index 0000000..4f0f131 --- /dev/null +++ b/MUONdigi/src/MUONsimpleDigitizer.cpp @@ -0,0 +1,183 @@ +#include "MUONsimpleDigitizer.h" + +// DD4hep +#include "DD4hep/Detector.h" +#include "DDRec/Vector3D.h" +#include "podio/UserDataCollection.h" +#include "edm4hep/Vector3d.h" + +#include "extension/MCRecoMuonSystemDigiAssociationCollection.h" +// ROOT +//#include "Math/Cylindrical3D.h" + +DECLARE_COMPONENT(MUONsimpleDigitizer) + +MUONsimpleDigitizer::MUONsimpleDigitizer(const std::string& aName, ISvcLocator* aSvcLoc) + : GaudiAlgorithm(aName, aSvcLoc), m_geoSvc("GeoSvc", "MUONsimpleDigitizer") { + declareProperty("inputSimHits", m_input_sim_hits, "Input sim tracker hit collection name"); + declareProperty("outputDigiHits", m_output_digi_hits, "Output digitized tracker hit collection name"); + declareProperty("outputSimDigiAssociation", m_output_sim_digi_association, "Output name for the association between digitized and simulated hit collections"); + declareProperty("efficiency", m_efficiency, "Efficiency of the detector"); +} + +MUONsimpleDigitizer::~MUONsimpleDigitizer() {} + +StatusCode MUONsimpleDigitizer::initialize() { + // Initialize random services + if (service("RndmGenSvc", m_randSvc).isFailure()) { + 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; + } + if (m_gauss_y.initialize(m_randSvc, Rndm::Gauss(0., m_y_resolution)).isFailure()) { + error() << "Couldn't initialize RndmGenSvc!" << endmsg; + return StatusCode::FAILURE; + } + if (m_gauss_z.initialize(m_randSvc, Rndm::Gauss(0., m_z_resolution)).isFailure()) { + error() << "Couldn't initialize RndmGenSvc!" << endmsg; + return StatusCode::FAILURE; + } + if (m_flat.initialize(m_randSvc, Rndm::Flat(0., 1.)).isFailure()) { + error() << "Couldn't initialize RndmGenSvc!" << endmsg; + return StatusCode::FAILURE; + } + + // check if readout exists + if (m_geoSvc->getDetector()->readouts().find(m_readoutName) == m_geoSvc->getDetector()->readouts().end()) { + error() << "Readout <<" << m_readoutName << ">> does not exist." << endmsg; + return StatusCode::FAILURE; + } + // set the cellID decoder + m_decoder = m_geoSvc->getDetector()->readout(m_readoutName).idSpec().decoder(); + // retrieve the volume manager + m_volman = m_geoSvc->getDetector()->volumeManager(); + + return StatusCode::SUCCESS; +} + +StatusCode MUONsimpleDigitizer::execute() { + // Get the input collection with Geant4 hits + const edm4hep::SimTrackerHitCollection* input_sim_hits = m_input_sim_hits.get(); + debug() << "Input Sim Hit collection size: " << input_sim_hits->size() << endmsg; + + // Digitize the sim hits + edm4hep::TrackerHit3DCollection* output_digi_hits = m_output_digi_hits.createAndPut(); + + // Prepare a collection for the association between digitized and simulated hit, setting weights to 1 + extension::MCRecoMuonSystemDigiAssociationCollection* digi_sim_associations = m_output_sim_digi_association.createAndPut(); + + // Prepare collections for the validation distributions + auto simDigiDifferenceX = m_simDigiDifferenceX.createAndPut(); + auto simDigiDifferenceY = m_simDigiDifferenceY.createAndPut(); + auto simDigiDifferenceZ = m_simDigiDifferenceZ.createAndPut(); + + for (const auto& input_sim_hit : *input_sim_hits) { + // Apply efficiency + if (m_flat.shoot() > m_efficiency) { + continue; // Skip this hit + } + + auto output_digi_hit = output_digi_hits->create(); + // smear the hit position: + // retrieve the cell detElement + dd4hep::DDSegmentation::CellID cellID = input_sim_hit.getCellID(); + debug() << "Digitisation of " << m_readoutName << ", cellID: " << cellID << endmsg; + // auto cellDetElement = m_volman.lookupDetElement(cellID); + + const auto& stripsTransformMatrix = m_volman.lookupVolumePlacement(cellID).matrix(); + + // Retrieve global position in mm and apply unit transformation (translation matrix is stored in cm) + double simHitGlobalPosition[3] = {input_sim_hit.getPosition().x * dd4hep::mm, + input_sim_hit.getPosition().y * dd4hep::mm, + input_sim_hit.getPosition().z * dd4hep::mm}; + dd4hep::rec::Vector3D simHitGlobalPositionVector(simHitGlobalPosition[0], simHitGlobalPosition[1], + simHitGlobalPosition[2]); + double simHitLocalPosition[3] = {0, 0, 0}; + + // get the simHit coordinate in cm in the strips reference frame + stripsTransformMatrix.MasterToLocal(simHitGlobalPosition, simHitLocalPosition); + debug() << "Cell ID string: " << m_decoder->valueString(cellID) << endmsg; + ; + debug() << "Global simHit x " << simHitGlobalPosition[0] << " --> Local simHit x " << simHitLocalPosition[0] + << " in cm" << endmsg; + debug() << "Global simHit y " << simHitGlobalPosition[1] << " --> Local simHit y " << simHitLocalPosition[1] + << " in cm" << endmsg; + debug() << "Global simHit z " << simHitGlobalPosition[2] << " --> Local simHit z " << simHitLocalPosition[2] + << " in cm" << endmsg; + // build a vector to easily apply smearing of distance to the strips + dd4hep::rec::Vector3D simHitLocalPositionVector(simHitLocalPosition[0], simHitLocalPosition[1], + simHitLocalPosition[2]); + // smear xy position + double smearedX = simHitLocalPositionVector.x() + m_gauss_x.shoot() * dd4hep::mm; + double smearedY = simHitLocalPositionVector.y() + m_gauss_y.shoot() * dd4hep::mm; + // smear the z position + double smearedZ = simHitLocalPositionVector.z() + m_gauss_z.shoot() * dd4hep::mm; + + double digiHitLocalPosition[3] = {smearedX, smearedY, smearedZ}; + + // build the local position vector of the smeared hit. + // dd4hep::rec::Vector3D digiHitLocalPositionVector(smearedX, smearedY, smearedZ); + debug() << "Local simHit x: " << simHitLocalPositionVector.x() + << " Local digiHit x: " << smearedX << " in cm" << endmsg; + debug() << "Local simHit y: " << simHitLocalPositionVector.y() + << " Local digiHit y: " << smearedY << " in cm" << endmsg; + debug() << "Local simHit z: " << simHitLocalPositionVector.z() + << " Local digiHit z: " << smearedZ << " in cm" << endmsg; + + // go back to the global frame + double digiHitGlobalPosition[3] = {0, 0, 0}; + stripsTransformMatrix.LocalToMaster(digiHitLocalPosition, digiHitGlobalPosition); + // go back to mm + edm4hep::Vector3d digiHitGlobalPositionVector(digiHitGlobalPosition[0] / dd4hep::mm, + digiHitGlobalPosition[1] / dd4hep::mm, + digiHitGlobalPosition[2] / dd4hep::mm); + output_digi_hit.setPosition(digiHitGlobalPositionVector); + output_digi_hit.setCellID(cellID); + + // create the association between digitized and simulated hit + auto digi_sim_association = digi_sim_associations->create(); + digi_sim_association.setDigi(output_digi_hit); + digi_sim_association.setSim(input_sim_hit); + + // Validating if the digitization; Calculate the position difference in global coordinates + double dx = (digiHitGlobalPosition[0] - simHitGlobalPosition[0]) / dd4hep::mm; + double dy = (digiHitGlobalPosition[1] - simHitGlobalPosition[1]) / dd4hep::mm; + double dz = (digiHitGlobalPosition[2] - simHitGlobalPosition[2]) / dd4hep::mm; + + edm4hep::Vector3d simDigiHitsPositionsDifference(dx / dd4hep::mm, + dy / dd4hep::mm, + dz / dd4hep::mm); + simDigiDifferenceX->push_back(dx); + simDigiDifferenceY->push_back(dy); + simDigiDifferenceZ->push_back(dz); + //digi_sim_association.setPositionDifference(simDigiHitsPositionsDifference); + } + debug() << "Output Digi Hit collection size: " << output_digi_hits->size() << endmsg; + return StatusCode::SUCCESS; +/* + // Validating if the digitization is working + for (const auto& association : *digi_sim_associations) { + const auto simHit = association.getSim(); + const auto digiHit = association.getDigi(); + + const auto simPosition = simHit.getPosition(); + const auto digiPosition = digiHit.getPosition(); + + double dx = digiPosition.x - simPosition.x; + double dy = digiPosition.y - simPosition.y; + double dz = digiPosition.z - simPosition.z; + + edm4hep::Vector3d simDigiHitsPositionsDifference(dx / dd4hep::mm, + dy / dd4hep::mm, + dz / dd4hep::mm); + association.setPositionDifference(simDigiHitsPositionsDifference); + + debug() << "Hit position Difference for cellID " << simHit.getCellID() << ": dx = " << dx << " mm, dy = " << dy << " mm, dz = " << dz << " mm" << endmsg; + } +*/ +} + +StatusCode MUONsimpleDigitizer::finalize() { return StatusCode::SUCCESS; } \ No newline at end of file diff --git a/MUONdigi/test/runMUONsimpleDigitizer.py b/MUONdigi/test/runMUONsimpleDigitizer.py new file mode 100644 index 0000000..4b33c8a --- /dev/null +++ b/MUONdigi/test/runMUONsimpleDigitizer.py @@ -0,0 +1,152 @@ +import os + +from Gaudi.Configuration import * + +from Configurables import FCCDataSvc +podioevent = FCCDataSvc("EventDataSvc") + +from GaudiKernel.SystemOfUnits import MeV, GeV, tesla +################## Particle gun setup +momentum = 5 # in GeV +thetaMin = 0 # degrees +thetaMax = 180 # degrees +pdgCode = 13 # 11 electron, 13 muon, 22 photon, 111 pi0, 211 pi+ +magneticField = True +_pi = 3.14159 + +from Configurables import GenAlg +genAlg = GenAlg() +from Configurables import MomentumRangeParticleGun +pgun = MomentumRangeParticleGun("ParticleGun_Electron") +pgun.PdgCodes = [pdgCode] +pgun.MomentumMin = momentum * GeV +pgun.MomentumMax = momentum * GeV +pgun.PhiMin = 0 +pgun.PhiMax = 2 * _pi +pgun.ThetaMin = thetaMin * _pi / 180. +pgun.ThetaMax = thetaMax * _pi / 180. +genAlg.SignalProvider = pgun + +genAlg.hepmc.Path = "hepmc" + +from Configurables import HepMCToEDMConverter +hepmc_converter = HepMCToEDMConverter() +hepmc_converter.hepmc.Path="hepmc" +genParticlesOutputName = "genParticles" +hepmc_converter.GenParticles.Path = genParticlesOutputName +hepmc_converter.hepmcStatusList = [] + +################## Simulation setup +# Detector geometry +from Configurables import GeoSvc +geoservice = GeoSvc("GeoSvc") +# if FCC_DETECTORS is empty, this should use relative path to working directory +path_to_detector = os.environ.get("K4GEO", "") +print(path_to_detector) +detectors_to_use=[ + # 'Detector/DetFCCeeIDEA/compact/IDEA_o1_v01/FCCee_DectMaster_v02.xml' + '/afs/cern.ch/work/m/maali/public/k4geo/FCCee/IDEA/compact/IDEA_o1_v03/IDEA_o1_v03.xml' + # '/afs/cern.ch/work/m/maali/public/FCCDetectors/Detector/DetFCCeeIDEA/compact/IDEA_o1_v01/FCCee_DectMaster_v02.xml' + ] +# prefix all xmls with path_to_detector +geoservice.detectors = [os.path.join(path_to_detector, _det) for _det in detectors_to_use] +geoservice.OutputLevel = INFO + +# Geant4 service +# Configures the Geant simulation: geometry, physics list and user actions + +from Configurables import SimG4FullSimActions, SimG4Alg, SimG4PrimariesFromEdmTool, SimG4SaveParticleHistory +actions = SimG4FullSimActions() +# Uncomment if history from Geant4 decays is needed (e.g. to get the photons from pi0) and set actions=actions in SimG4Svc + uncomment saveHistTool in SimG4Alg +#actions.enableHistory=True +#actions.energyCut = 0.2 * GeV +#saveHistTool = SimG4SaveParticleHistory("saveHistory") + + +# Magnetic field +from Configurables import SimG4ConstantMagneticFieldTool +field = SimG4ConstantMagneticFieldTool("SimG4ConstantMagneticFieldTool", FieldComponentZ = -2 * tesla, FieldOn = magneticField, IntegratorStepper = "ClassicalRK4") + +from Configurables import SimG4Svc +geantservice = SimG4Svc("SimG4Svc", detector = 'SimG4DD4hepDetector', physicslist = "SimG4FtfpBert", actions = actions, magneticField = field) + +# Fixed seed to have reproducible results, change it for each job if you split one production into several jobs +# Mind that if you leave Gaudi handle random seed and some job start within the same second (very likely) you will have duplicates +geantservice.randomNumbersFromGaudi = False +geantservice.seedValue = 4242 + +# Range cut +geantservice.g4PreInitCommands += ["/run/setCut 0.1 mm"] + +# Geant4 algorithm +# Translates EDM to G4Event, passes the event to G4, writes out outputs via tools +# and a tool that saves the calorimeter hits + +# next, create the G4 algorithm, giving the list of names of tools ("XX/YY") +from Configurables import SimG4PrimariesFromEdmTool +particle_converter = SimG4PrimariesFromEdmTool("EdmConverter") +particle_converter.GenParticles.Path = genParticlesOutputName + +from Configurables import SimG4SaveTrackerHits +SimG4SaveMuonHits = SimG4SaveTrackerHits("SimG4SaveMuonHits", readoutName="MuonSystemCollection") +SimG4SaveMuonHits.SimTrackHits.Path = "Muon_SimHits" + +from Configurables import SimG4Alg +geantsim = SimG4Alg("SimG4Alg", + outputs= [SimG4SaveMuonHits], + eventProvider=particle_converter, + OutputLevel=INFO) + +# Digitize tracker hits +from Configurables import MUONsimpleDigitizer +muon_digitizer = MUONsimpleDigitizer("MUONsimpleDigitizer", + inputSimHits = SimG4SaveMuonHits.SimTrackHits.Path, + outputDigiHits = SimG4SaveMuonHits.SimTrackHits.Path.replace("Sim", "Digi"), + outputSimDigiAssociation = "MS_simDigiAssociation", + readoutName = "MuonSystemCollection", + xResolution = 0.4, # mm + yResolution = 0.4, # mm + zResolution = 0.4, # mm + efficiency = 0.95, # efficiency of the detector (mRWELL chamber) + OutputLevel=DEBUG +) + +################ Output +from Configurables import PodioOutput +out = PodioOutput("out", + OutputLevel=INFO) +out.outputCommands = ["keep *"] + +import uuid +out.filename = "output_MuonSystemDigi"+"_pMin_"+str(momentum)+"_GeV"+"_pdgId_"+str(pdgCode)+".root" + +#CPU information +from Configurables import AuditorSvc, ChronoAuditor +chra = ChronoAuditor() +audsvc = AuditorSvc() +audsvc.Auditors = [chra] +genAlg.AuditExecute = True +hepmc_converter.AuditExecute = True +geantsim.AuditExecute = True +muon_digitizer.AuditExecute = True +out.AuditExecute = True + +from Configurables import EventCounter +event_counter = EventCounter('event_counter') +event_counter.Frequency = 1 + +from Configurables import ApplicationMgr +ApplicationMgr( + TopAlg = [ + event_counter, + genAlg, + hepmc_converter, + geantsim, + muon_digitizer, + out + ], + EvtSel = 'NONE', + EvtMax = 10000, + ExtSvc = [geoservice, podioevent, geantservice, audsvc], + StopOnSignal = True, +) \ No newline at end of file