TrackerSourceLinker.cpp 5.5 KB
Newer Older
1
#include "JugTrack/GeometryContainers.hpp"
2
3
4
5
6
7
8

// Gaudi
#include "GaudiAlg/GaudiAlgorithm.h"
#include "GaudiKernel/ToolHandle.h"
#include "GaudiAlg/Transformer.h"
#include "GaudiAlg/GaudiTool.h"
#include "GaudiKernel/RndmGenerators.h"
9
#include "Gaudi/Property.h"
10
11
12
13
14
15
16

#include "JugBase/DataHandle.h"
#include "JugBase/IGeoSvc.h"

#include "DDRec/CellIDPositionConverter.h"
#include "DDRec/SurfaceManager.h"
#include "DDRec/Surface.h"
Whitney Armstrong's avatar
Whitney Armstrong committed
17
18
19
#include "DD4hep/Volumes.h"
#include "DD4hep/DD4hepUnits.h"

20

21
22
23
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Definitions/Units.hpp"
#include "Acts/Definitions/Common.hpp"
24
25
26
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Plugins/DD4hep/DD4hepDetectorElement.hpp"

27
28
29
#include "JugTrack/Index.hpp"
#include "JugTrack/IndexSourceLink.hpp"
#include "JugTrack/Measurement.hpp"
30
31
32
33
34

#include "eicd/TrackerHitCollection.h"

namespace Jug::Reco {

Whitney Armstrong's avatar
Whitney Armstrong committed
35
36
37
38
  /** Source source Linker.
   *
   * \ingroup track
   */
39
40
41
  class TrackerSourceLinker : public GaudiAlgorithm {
  public:
    DataHandle<eic::TrackerHitCollection>    m_inputHitCollection{"inputHitCollection", Gaudi::DataHandle::Reader, this};
42
43
    DataHandle<IndexSourceLinkContainer>     m_outputSourceLinks{"outputSourceLinks", Gaudi::DataHandle::Writer, this};
    DataHandle<MeasurementContainer>          m_outputMeasurements{"outputMeasurements", Gaudi::DataHandle::Writer, this};
44
45
46
47
48
49
50
51
    /// Pointer to the geometry service
    SmartIF<IGeoSvc> m_geoSvc;

  public:
    TrackerSourceLinker(const std::string& name, ISvcLocator* svcLoc)
        : GaudiAlgorithm(name, svcLoc) {
      declareProperty("inputHitCollection", m_inputHitCollection, "");
      declareProperty("outputSourceLinks", m_outputSourceLinks, "");
52
      declareProperty("outputMeasurements", m_outputMeasurements, "");
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
    }

    StatusCode initialize() override {
      if (GaudiAlgorithm::initialize().isFailure())
        return StatusCode::FAILURE;
      m_geoSvc = service("GeoSvc");
      if (!m_geoSvc) {
        error() << "Unable to locate Geometry Service. "
                << "Make sure you have GeoSvc and SimSvc in the right order in the configuration."
                << endmsg;
        return StatusCode::FAILURE;
      }

      return StatusCode::SUCCESS;
    }

    StatusCode execute() override {
      // input collection
      const eic::TrackerHitCollection* hits = m_inputHitCollection.get();
      // Create output collections
73
74
75
76
77
78
      auto sourceLinks = m_outputSourceLinks.createAndPut();
      auto measurements = m_outputMeasurements.createAndPut();
      // IndexMultimap<ActsFatras::Barcode> hitParticlesMap;
      // IndexMultimap<Index> hitSimHitsMap;
      sourceLinks->reserve(hits->size());
      measurements->reserve(hits->size());
79

Whitney Armstrong's avatar
Whitney Armstrong committed
80
      debug() << (*hits).size() << " hits " << endmsg;
81
      int ihit = 0;
82
83
      for(const auto& ahit : *hits) {

84
        Acts::SymMatrix2 cov = Acts::SymMatrix2::Zero();
85
86
        cov(0,0) = ahit.covMatrix().xx*Acts::UnitConstants::mm;//*ahit.xx()*Acts::UnitConstants::mm;
        cov(1,1) = ahit.covMatrix().yy*Acts::UnitConstants::mm;//*ahit.yy()*Acts::UnitConstants::mm;
87

88
89
        auto       vol_ctx = m_geoSvc->cellIDPositionConverter()->findContext(ahit.cellID());
        auto       vol_id  = vol_ctx->identifier;
Chao Peng's avatar
Chao Peng committed
90
91
        const auto is      = m_geoSvc->surfaceMap().find(vol_id);
        if (is == m_geoSvc->surfaceMap().end()) {
Whitney Armstrong's avatar
Whitney Armstrong committed
92
          debug() << " vol_id (" <<  vol_id << ")  not found in m_surfaces." <<endmsg;
93
94
95
          continue;
        }
        const Acts::Surface* surface = is->second;
Whitney Armstrong's avatar
Whitney Armstrong committed
96
        auto surf_center = surface->center(Acts::GeometryContext());
97
        debug() << " surface center : " << surface->center(Acts::GeometryContext()).transpose() << endmsg;
98
        // transform global position into local coordinates
99
        Acts::Vector2 pos(0, 0);
100
        // geometry context contains nothing here
101
        pos = surface->globalToLocal(Acts::GeometryContext(), {ahit.position().x, ahit.position().y, ahit.position().z}, {0, 0, 0}).value();//, pos);
102

103
        Acts::Vector2 loc = Acts::Vector2::Zero();
Whitney Armstrong's avatar
Whitney Armstrong committed
104
        loc[Acts::eBoundLoc0]     = pos[0] ;//+ m_cfg.sigmaLoc0 * stdNormal(rng);
Whitney Armstrong's avatar
Whitney Armstrong committed
105
        loc[Acts::eBoundLoc1]     = pos[1] ;//+ m_cfg.sigmaLoc1 * stdNormal(rng);
Whitney Armstrong's avatar
Whitney Armstrong committed
106
        debug() << "loc : (" << loc[Acts::eBoundLoc0] << ", " << loc[Acts::eBoundLoc1] << ")" << endmsg;
Whitney Armstrong's avatar
Whitney Armstrong committed
107

108
109
110
111
112
113
114
        //local position
        //auto loc = {ahit.x(), ahit.y(), ahit.z()} - vol_ctx->volumePlacement().position()
        //debug() << " hit          : \n" <<  ahit << endmsg;
        //debug() << " cell ID : " << ahit.cellID() << endmsg;
        //debug() << " position : (" <<  ahit.position(0) << ", " <<  ahit.position(1) << ", "<<  ahit.position(2) << ") " << endmsg;
        //debug() << " vol_id       : " <<  vol_id << endmsg;
        //debug() << " placment pos : " << vol_ctx->volumePlacement().position() << endmsg;
115

116
117
118
        // the measurement container is unordered and the index under which the
        // measurement will be stored is known before adding it.
        Index hitIdx = measurements->size();
119
        IndexSourceLink sourceLink(surface->geometryId(), ihit);
120
121
122
123
124
125
        auto meas = Acts::makeMeasurement(sourceLink, loc, cov, Acts::eBoundLoc0, Acts::eBoundLoc1);

        // add to output containers. since the input is already geometry-order,
        // new elements in geometry containers can just be appended at the end.
        sourceLinks->emplace_hint(sourceLinks->end(), std::move(sourceLink));
        measurements->emplace_back(std::move(meas));
126

127
        ihit++;
128
129
130
131
132
133
134
135
136
      }
      return StatusCode::SUCCESS;
    }

   };
  DECLARE_COMPONENT(TrackerSourceLinker)

} // namespace Jug::reco