Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MUONDigi] Adding a digitizer of IDEA Muon system. #24

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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)

Expand Down
80 changes: 80 additions & 0 deletions MUONdigi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${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)
21 changes: 21 additions & 0 deletions MUONdigi/dataFormatExtension/muonSystemHit.yaml
Original file line number Diff line number Diff line change
@@ -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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using MCRecoTrackerAssociation https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L634 ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be used for linking between digi and sim? I fount it relates between reco and sim..
On another hand I'd like to see if there is an association also to store the validation data (e.g: simDigipPositionDifference)

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

107 changes: 107 additions & 0 deletions MUONdigi/include/MUONsimpleDigitizer.h
Original file line number Diff line number Diff line change
@@ -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<edm4hep::SimTrackerHitCollection> m_input_sim_hits{"inputSimHits", Gaudi::DataHandle::Reader, this};
// Output digitized tracker hit collection name
DataHandle<edm4hep::TrackerHit3DCollection> m_output_digi_hits{"outputDigiHits", Gaudi::DataHandle::Writer, this};
// Output association between digitized and simulated hit collections name
DataHandle<extension::MCRecoMuonSystemDigiAssociationCollection> m_output_sim_digi_association{"outputSimDigiAssociation", Gaudi::DataHandle::Writer, this};

// Detector readout name
Gaudi::Property<std::string> m_readoutName{this, "readoutName", "MuonSystemCollection", "Name of the detector readout"};
// Pointer to the geometry service
ServiceHandle<IGeoSvc> 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we need 3 numbers here. Since you do the smearing in local coordinates (as it should), 2 numbers should be sufficient no? OR at least we should put ine by default to 0, otherwise we really smear in the 3 dimensions.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a flag, set to false by default, to produce these collections? See e.g. https://github.com/key4hep/k4RecTracker/blob/master/DCHdigi/include/DCHsimpleDigitizerExtendedEdm.h#L78 (the branch will unfortunately still be there I am afraid)

DataHandle<podio::UserDataCollection<double>> m_simDigiDifferenceX{"simDigiDifferenceX", Gaudi::DataHandle::Writer, this}; // mm
DataHandle<podio::UserDataCollection<double>> m_simDigiDifferenceY{"simDigiDifferenceY", Gaudi::DataHandle::Writer, this}; // mm
DataHandle<podio::UserDataCollection<double>> m_simDigiDifferenceZ{"simDigiDifferenceZ", Gaudi::DataHandle::Writer, this}; // mm

// Random Number Service
IRndmGenSvc* m_randSvc;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmcarcell let us know if a consensus was reached on which random number generator we should use

// 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;
};
Loading
Loading