Skip to content

Commit

Permalink
CreateCaloCellPositions transition to edm4hep
Browse files Browse the repository at this point in the history
  • Loading branch information
BrieucF authored and vvolkl committed Apr 14, 2021
1 parent c105446 commit 52c0d52
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
#include "DD4hep/Detector.h"

// EDM
#include "datamodel/CaloHitCollection.h"
#include "datamodel/PositionedCaloHitCollection.h"
#include "datamodel/PositionedTrackHitCollection.h"
#include "datamodel/TrackHitCollection.h"
#include "edm4hep/CalorimeterHitCollection.h"

DECLARE_COMPONENT(CreateCaloCellPositionsFCCee)

Expand Down Expand Up @@ -45,7 +42,8 @@ StatusCode CreateCaloCellPositionsFCCee::execute() {
auto edmPositionedHitCollection = m_positionedHits.createAndPut();

for (const auto& hit : *hits) {
dd4hep::DDSegmentation::CellID cellId = hit.core().cellId;
auto positionedHit = hit.clone();
dd4hep::DDSegmentation::CellID cellId = positionedHit.getCellID();
// identify calo system
auto systemId = m_decoder->get(cellId, "system");
dd4hep::Position posCell;
Expand All @@ -65,15 +63,16 @@ StatusCode CreateCaloCellPositionsFCCee::execute() {
else if (systemId == 11) // HFWD system id
posCell = m_cellPositionsHFwdTool->xyzPosition(cellId);

auto edmPos = fcc::Point();
auto edmPos = edm4hep::Vector3f();
edmPos.x = posCell.x() / dd4hep::mm;
edmPos.y = posCell.y() / dd4hep::mm;
edmPos.z = posCell.z() / dd4hep::mm;

auto positionedHit = edmPositionedHitCollection->create(edmPos, hit.core());
positionedHit.setPosition(edmPos);
edmPositionedHitCollection->push_back(positionedHit);

// Debug information about cell position
debug() << "Cell energy (GeV) : " << hit.core().energy << "\tcellID " << hit.core().cellId << endmsg;
debug() << "Cell energy (GeV) : " << positionedHit.getEnergy() << "\tcellID " << positionedHit.getCellID() << endmsg;
debug() << "Position of cell (mm) : \t" << posCell.x() / dd4hep::mm << "\t" << posCell.y() / dd4hep::mm << "\t"
<< posCell.z() / dd4hep::mm << endmsg;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
#include "GaudiAlg/GaudiAlgorithm.h"
#include "GaudiKernel/ToolHandle.h"

#include "datamodel/CaloHit.h"
#include "datamodel/CaloHitCollection.h"
#include "datamodel/PositionedCaloHit.h"
#include "datamodel/PositionedCaloHitCollection.h"
#include "edm4hep/CalorimeterHit.h"
#include "edm4hep/CalorimeterHitCollection.h"

class IGeoSvc;

Expand Down Expand Up @@ -61,9 +59,9 @@ class CreateCaloCellPositionsFCCee : public GaudiAlgorithm {
/// Decoder for system ID
dd4hep::DDSegmentation::BitFieldCoder* m_decoder = new dd4hep::DDSegmentation::BitFieldCoder("system:4");
/// Input collection
DataHandle<fcc::CaloHitCollection> m_hits{"hits/hits", Gaudi::DataHandle::Reader, this};
DataHandle<edm4hep::CalorimeterHitCollection> m_hits{"hits/hits", Gaudi::DataHandle::Reader, this};
/// Output collection
DataHandle<fcc::PositionedCaloHitCollection> m_positionedHits{"hits/positionedHits", Gaudi::DataHandle::Writer, this};
DataHandle<edm4hep::CalorimeterHitCollection> m_positionedHits{"hits/positionedHits", Gaudi::DataHandle::Writer, this};
};

#endif /* DETCOMPONENTS_CREATECELLPOSITIONSFCCEE_H */
15 changes: 7 additions & 8 deletions RecFCChhCalorimeter/src/components/CreateCaloCellPositions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
#include "DD4hep/Detector.h"

// EDM
#include "datamodel/CaloHitCollection.h"
#include "datamodel/PositionedCaloHitCollection.h"
#include "datamodel/PositionedTrackHitCollection.h"
#include "datamodel/TrackHitCollection.h"
#include "edm4hep/CalorimeterHitCollection.h"

DECLARE_COMPONENT(CreateCaloCellPositions)

Expand Down Expand Up @@ -45,7 +42,8 @@ StatusCode CreateCaloCellPositions::execute() {
auto edmPositionedHitCollection = m_positionedHits.createAndPut();

for (const auto& hit : *hits) {
dd4hep::DDSegmentation::CellID cellId = hit.core().cellId;
auto positionedHit = hit.clone();
dd4hep::DDSegmentation::CellID cellId = positionedHit.getCellID();
// identify calo system
auto systemId = m_decoder->get(cellId, "system");
dd4hep::Position posCell;
Expand All @@ -65,15 +63,16 @@ StatusCode CreateCaloCellPositions::execute() {
else if (systemId == 11) // HFWD system id
posCell = m_cellPositionsHFwdTool->xyzPosition(cellId);

auto edmPos = fcc::Point();
auto edmPos = edm4hep::Vector3f();
edmPos.x = posCell.x() / dd4hep::mm;
edmPos.y = posCell.y() / dd4hep::mm;
edmPos.z = posCell.z() / dd4hep::mm;

auto positionedHit = edmPositionedHitCollection->create(edmPos, hit.core());
positionedHit.setPosition(edmPos);
edmPositionedHitCollection->push_back(positionedHit);

// Debug information about cell position
debug() << "Cell energy (GeV) : " << hit.core().energy << "\tcellID " << hit.core().cellId << endmsg;
debug() << "Cell energy (GeV) : " << positionedHit.getEnergy() << "\tcellID " << positionedHit.getCellID() << endmsg;
debug() << "Position of cell (mm) : \t" << posCell.x() / dd4hep::mm << "\t" << posCell.y() / dd4hep::mm << "\t"
<< posCell.z() / dd4hep::mm << endmsg;
}
Expand Down
10 changes: 4 additions & 6 deletions RecFCChhCalorimeter/src/components/CreateCaloCellPositions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
#include "GaudiAlg/GaudiAlgorithm.h"
#include "GaudiKernel/ToolHandle.h"

#include "datamodel/CaloHit.h"
#include "datamodel/CaloHitCollection.h"
#include "datamodel/PositionedCaloHit.h"
#include "datamodel/PositionedCaloHitCollection.h"
#include "edm4hep/CalorimeterHit.h"
#include "edm4hep/CalorimeterHitCollection.h"

class IGeoSvc;

Expand Down Expand Up @@ -61,9 +59,9 @@ class CreateCaloCellPositions : public GaudiAlgorithm {
/// Decoder for system ID
dd4hep::DDSegmentation::BitFieldCoder* m_decoder = new dd4hep::DDSegmentation::BitFieldCoder("system:4");
/// Input collection
DataHandle<fcc::CaloHitCollection> m_hits{"hits/hits", Gaudi::DataHandle::Reader, this};
DataHandle<edm4hep::CalorimeterHitCollection> m_hits{"hits/hits", Gaudi::DataHandle::Reader, this};
/// Output collection
DataHandle<fcc::PositionedCaloHitCollection> m_positionedHits{"hits/positionedHits", Gaudi::DataHandle::Writer, this};
DataHandle<edm4hep::CalorimeterHitCollection> m_positionedHits{"hits/positionedHits", Gaudi::DataHandle::Writer, this};
};

#endif /* DETCOMPONENTS_CREATECELLPOSITIONS_H */

0 comments on commit 52c0d52

Please sign in to comment.