Skip to content

Commit

Permalink
Making tracking work
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Nov 18, 2024
1 parent 4428f06 commit 3f80948
Show file tree
Hide file tree
Showing 14 changed files with 235 additions and 404 deletions.
11 changes: 4 additions & 7 deletions source/tdis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ add_executable(tdis
tracking/ActsGeometryService.cc
tracking/ActsGeometryService.h
tracking/ReconstructedHitFactory.h

tracking/BuildTelescopeDetector.cpp
tracking/BuildTelescopeDetector.hpp
tracking/TelescopeDetector.cpp
tracking/TelescopeDetector.hpp
tracking/TelescopeDetectorElement.cpp
tracking/TelescopeDetectorElement.hpp
tracking/BuildMtpcDetector.cpp
tracking/BuildMtpcDetector.hpp
tracking/MtpcDetectorElement.cpp
tracking/MtpcDetectorElement.hpp
# tracking/CKFTrackingFunction.cc
# tracking/DD4hepBField.h
# /tracking/DD4hepBField.cc
Expand Down
20 changes: 9 additions & 11 deletions source/tdis/io/PodioWriteProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,9 @@
* repeated exceptions and potential crashes.
*/

#include <JANA/JApplication.h>
#include <JANA/JEvent.h>
#include <JANA/JEventProcessor.h>
#include <podio/podioVersion.h>
#include <podio/ROOTWriter.h>
#include <spdlog/logger.h>
#include <memory>
#include <mutex>
#include <set>
#include <string>
#include <vector>


#include <JANA/JApplication.h>
#include <JANA/JLogger.h>
#include <JANA/Services/JParameterManager.h>
#include <JANA/Utils/JTypeInfo.h>
Expand All @@ -57,11 +47,18 @@
#include <podio/Frame.h>
#include <podio/ROOTWriter.h>
#include <podio/podioVersion.h>
#include <spdlog/logger.h>

#include <chrono>
#include <exception>
#include <memory>
#include <mutex>
#include <set>
#include <string>
#include <thread>
#include <vector>

#include "podio_model/TrackerHit.h"
#include "services/LogService.hpp"

namespace tdis::io {
Expand Down Expand Up @@ -142,6 +139,7 @@ inline void PodioWriteProcessor::Init() {

inline void PodioWriteProcessor::Process(const std::shared_ptr<const JEvent>& event) {
std::lock_guard<std::mutex> lock(m_mutex);
auto hits = event->GetCollection<edm4eic::TrackerHit>("TrackerHit");

m_log->info("PodioWriteProcessor::Process() All event collections:");
auto event_collections = event->GetAllCollectionNames();
Expand Down
7 changes: 6 additions & 1 deletion source/tdis/tdis_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <JANA/JApplication.h>
#include <JANA/Services/JParameterManager.h>
#include <JANA/Components/JOmniFactoryGeneratorT.h>

#include <utility>

Expand Down Expand Up @@ -114,9 +115,13 @@ int main(int argc, char* argv[]) {
app.ProvideService(std::make_shared<tdis::services::LogService>(&app));
app.ProvideService(std::make_shared<tdis::tracking::ActsGeometryService>());

auto reco_hit_generator = new JOmniFactoryGeneratorT<tdis::tracking::ReconstructedHitFactory>();
reco_hit_generator->AddWiring("TrackerHitGenerator", {"DigitizedMtpcMcHit"}, {"TrackerHit"});
app.Add(reco_hit_generator);

app.Add(new JEventSourceGeneratorT<tdis::io::DigitizedDataEventSource>);
app.Add(new tdis::io::PodioWriteProcessor(&app));
app.Add(new JFactoryGeneratorT<tdis::tracking::ReconstructedHitFactory>("TrackerHit"));

// app.Add(new JEventProcessorPodio);
// app.Add(new JFactoryGeneratorT<ExampleClusterFactory>());
// app.Add(new JFactoryGeneratorT<ExampleMultifactory>());
Expand Down
15 changes: 7 additions & 8 deletions source/tdis/tracking/ActsGeometryService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
#include <string>
#include <string_view>

#include "BuildTelescopeDetector.hpp"
#include "TelescopeDetector.hpp"
#include "BuildMtpcDetector.hpp"
#include "services/LogService.hpp"

// Formatter for Eigen matrices
Expand Down Expand Up @@ -369,19 +368,19 @@ void tdis::tracking::ActsGeometryService::Init() {


/// Return the telescope detector
gGeometry =
ActsExamples::Telescope::buildDetector(
gGeometry = tdis::tracking::buildDetector(
nominalContext, // gctx is the detector element dependent geometry context
detectorStore, // detectorStore is the store for the detector element
m_plane_positions, // positions are the positions of different layers in the longitudinal direction
detectorStore, // detectorStore is the store for the detector element
m_plane_positions, // positions are the positions of different layers in the longitudinal direction
stereos, // stereoAngles are the stereo angles of different layers, which are rotation angles around the longitudinal (normal) direction
offsets, // is the offset (u, v) of the layers in the transverse plane
bounds, // bounds is the surface bound values, i.e. halfX and halfY if plane surface, and minR and maxR if disc surface
bounds, // bounds is the surface bound values, minR and maxR
thickness, // thickness is the material thickness of each layer
ActsExamples::Telescope::TelescopeSurfaceType::Disc, // surfaceType is the detector surface type
Acts::BinningValue::binZ);




// Visualize ACTS geometry
const Acts::TrackingVolume& tgVolume = *(gGeometry->highestTrackingVolume());

Expand Down
6 changes: 3 additions & 3 deletions source/tdis/tracking/ActsGeometryService.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <memory>
#include <mutex>

#include "TelescopeDetectorElement.hpp"
#include "MtpcDetectorElement.hpp"
#include "services/LogService.hpp"

namespace tdis::tracking {
Expand Down Expand Up @@ -60,9 +60,9 @@ namespace tdis::tracking {

Acts::GeometryContext m_geometry_context = Acts::GeometryContext();

ActsExamples::Telescope::TelescopeDetectorElement::ContextType nominalContext;
tdis::tracking::MtpcDetectorElement::ContextType nominalContext;

std::vector<std::shared_ptr<ActsExamples::Telescope::TelescopeDetectorElement>>
std::vector<std::shared_ptr<tdis::tracking::MtpcDetectorElement>>
detectorStore;

std::shared_ptr<const Acts::TrackingGeometry> gGeometry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "BuildTelescopeDetector.hpp"
#include <algorithm>
#include <cstddef>
#include <utility>

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Definitions/Units.hpp"
Expand All @@ -28,17 +30,22 @@
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceArray.hpp"
#include "Acts/Utilities/Logger.hpp"

#include <algorithm>
#include <cstddef>
#include <utility>
#include "BuildMtpcDetector.hpp"

std::unique_ptr<const Acts::TrackingGeometry>
ActsExamples::Telescope::buildDetector(const typename ActsExamples::Telescope::TelescopeDetectorElement::ContextType &gctx, std::vector<std::shared_ptr<ActsExamples::Telescope::TelescopeDetectorElement> > &detectorStore, const std::vector<double> &positions, const std::vector<double> &stereoAngles, const std::array<double, 2> &offsets, const std::array<double, 2> &bounds, double thickness, ActsExamples::Telescope::TelescopeSurfaceType surfaceType, Acts::BinningValue binValue) {
tdis::tracking::buildDetector(
const typename tdis::tracking::MtpcDetectorElement::ContextType &gctx,
std::vector<std::shared_ptr<tdis::tracking::MtpcDetectorElement> > &detectorStore,
const std::vector<double> &positions,
const std::vector<double> &stereoAngles,
const std::array<double, 2> &offsets,
const std::array<double, 2> &bounds,
double thickness,
Acts::BinningValue binValue)
{
using namespace Acts::UnitLiterals;

// The rectangle bounds for plane surface
const auto pBounds = std::make_shared<const Acts::RectangleBounds>(bounds[0], bounds[1]);

// The radial bounds for disc surface
const auto rBounds = std::make_shared<const Acts::RadialBounds>(bounds[0], bounds[1]);

Expand Down Expand Up @@ -76,24 +83,20 @@ ActsExamples::Telescope::buildDetector(const typename ActsExamples::Telescope::T
trafo *= Acts::AngleAxis3(stereo, Acts::Vector3::UnitZ());

// Create the detector element
std::shared_ptr<TelescopeDetectorElement> detElement = nullptr;
if (surfaceType == TelescopeSurfaceType::Plane) {
detElement = std::make_shared<TelescopeDetectorElement>(std::make_shared<const Acts::Transform3>(trafo), pBounds, 1._um, surfaceMaterial);
} else {
detElement = std::make_shared<TelescopeDetectorElement>(std::make_shared<const Acts::Transform3>(trafo), rBounds, 1._um, surfaceMaterial);
}
std::shared_ptr<MtpcDetectorElement> detElement = nullptr;

detElement = std::make_shared<MtpcDetectorElement>(std::make_shared<const Acts::Transform3>(trafo), rBounds, 1._um, i, surfaceMaterial);

// Get the surface
auto surface = detElement->surface().getSharedPtr();

// Add the detector element to the detector store
detectorStore.push_back(std::move(detElement));
// Construct the surface array (one surface contained)
std::unique_ptr<Acts::SurfaceArray> surArray(new Acts::SurfaceArray(surface));
// Construct the layer
if (surfaceType == TelescopeSurfaceType::Plane) {
layers[i] = Acts::PlaneLayer::create(trafo, pBounds, std::move(surArray), thickness);
} else {
layers[i] = Acts::DiscLayer::create(trafo, rBounds, std::move(surArray), thickness);
}
layers[i] = Acts::DiscLayer::create(trafo, rBounds, std::move(surArray), thickness);

// Associate the layer to the surface
auto mutableSurface = const_cast<Acts::Surface *>(surface.get());
mutableSurface->associateLayer(*layers[i]);
Expand All @@ -107,11 +110,7 @@ ActsExamples::Telescope::buildDetector(const typename ActsExamples::Telescope::T
// or cylinder with discs
auto length = positions.back() - positions.front();
std::shared_ptr<Acts::VolumeBounds> boundsVol = nullptr;
if (surfaceType == TelescopeSurfaceType::Plane) {
boundsVol = std::make_shared<Acts::CuboidVolumeBounds>(bounds[0] + 5._mm, bounds[1] + 5._mm, length + 10._mm);
} else {
boundsVol = std::make_shared<Acts::CylinderVolumeBounds>(std::max(bounds[0] - 5.0_mm, 0.), bounds[1] + 5._mm, length + 10._mm);
}
boundsVol = std::make_shared<Acts::CylinderVolumeBounds>(std::max(bounds[0] - 5.0_mm, 0.), bounds[1] + 5._mm, length + 10._mm);

Acts::LayerArrayCreator::Config lacConfig;
Acts::LayerArrayCreator layArrCreator(lacConfig, Acts::getDefaultLogger("LayerArrayCreator", Acts::Logging::INFO));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,20 @@

#pragma once

#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Utilities/BinUtility.hpp"
#include "Acts/Utilities/BinningType.hpp"
#include "TelescopeDetectorElement.hpp"

#include <array>
#include <memory>
#include <vector>

#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Utilities/BinUtility.hpp"
#include "Acts/Utilities/BinningType.hpp"
#include "MtpcDetectorElement.hpp"

namespace Acts {
class TrackingGeometry;
} // namespace Acts

namespace ActsExamples::Telescope {

/// The telescope detector surface type
enum class TelescopeSurfaceType {
Plane = 0,
Disc = 1,
};
namespace tdis::tracking {

/// Global method to build the telescope tracking geometry
///
Expand All @@ -39,19 +33,19 @@ enum class TelescopeSurfaceType {
/// rotation angles around the longitudinal (normal)
/// direction
/// @param offsets is the offset (u, v) of the layers in the transverse plane
/// @param bounds is the surface bound values, i.e. halfX and halfY if plane
/// surface, and minR and maxR if disc surface
/// @param bounds is the surface bound values, i.e. minR and maxR
/// @param thickness is the material thickness of each layer
/// @param surfaceType is the detector surface type

/// @param binValue indicates which axis the detector surface normals are
/// parallel to
std::unique_ptr<const Acts::TrackingGeometry> buildDetector(
const typename TelescopeDetectorElement::ContextType& gctx,
std::vector<std::shared_ptr<TelescopeDetectorElement>>& detectorStore,
const typename MtpcDetectorElement::ContextType& gctx,
std::vector<std::shared_ptr<MtpcDetectorElement>>& detectorStore,
const std::vector<double>& positions,
const std::vector<double>& stereoAngles,
const std::array<double, 2>& offsets, const std::array<double, 2>& bounds,
double thickness, TelescopeSurfaceType surfaceType,
const std::array<double, 2>& offsets,
const std::array<double, 2>& bounds,
double thickness,
Acts::BinningValue binValue = Acts::BinningValue::binZ);

} // namespace ActsExamples::Telescope
27 changes: 27 additions & 0 deletions source/tdis/tracking/MtpcDetectorElement.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// This file is part of the Acts project.
//
// Copyright (C) 2020-2021 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Surfaces/DiscSurface.hpp"
#include "Acts/Surfaces/PlaneSurface.hpp"
#include "MtpcDetectorElement.hpp"


tdis::tracking::MtpcDetectorElement::MtpcDetectorElement(
std::shared_ptr<const Acts::Transform3> transform,
std::shared_ptr<const Acts::DiscBounds> dBounds,
double thickness,
int gem_plane_id,
std::shared_ptr<const Acts::ISurfaceMaterial> material)
: Acts::DetectorElementBase(),
m_elementTransform(std::move(transform)),
m_elementSurface(Acts::Surface::makeShared<Acts::DiscSurface>(dBounds, *this)),
m_elementThickness(thickness),
m_gem_plane_id(gem_plane_id),
m_elementDiscBounds(std::move(dBounds)) {
m_elementSurface->assignSurfaceMaterial(std::move(material));
}
Loading

0 comments on commit 3f80948

Please sign in to comment.