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

add TRACCC algorithm #270

Open
wants to merge 6 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
7 changes: 7 additions & 0 deletions Reconstruction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ add_subdirectory(PFA)
add_subdirectory(SiliconTracking)
add_subdirectory(Tracking)
add_subdirectory(RecGenfitAlg)

find_package(traccc)
if (TRACCC_FOUND)
add_subdirectory(TracccAlg)
else ()
message("traccc library not found.")
endif()
26 changes: 26 additions & 0 deletions Reconstruction/TracccAlg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
gaudi_add_module(TracccAlg
SOURCES src/TracccAlg.cpp
LINK DetInterface
k4FWCore::k4FWCore
Gaudi::GaudiAlgLib Gaudi::GaudiKernel
${LCIO_LIBRARIES}
${DD4hep_COMPONENT_LIBRARIES}
EDM4HEP::edm4hep EDM4HEP::edm4hepDict
${podio_LIBRARIES} podio::podioRootIO
)

target_link_libraries(TracccAlg PUBLIC traccc::wrapper)

if (GenFit_FOUND)
target_link_libraries(TracccAlg PUBLIC GenFit::genfit2)
endif()

target_include_directories(TracccAlg PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>/include
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

install(TARGETS TracccAlg
EXPORT CEPCSWTargets
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
COMPONENT dev)
61 changes: 61 additions & 0 deletions Reconstruction/TracccAlg/options/TracccAlg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python

from Gaudi.Configuration import *
import os
from Configurables import k4DataSvc
dsvc = k4DataSvc("EventDataSvc",
input="CRD-oi-v0j-Sim00.root"
)

from Configurables import PodioInput
podioinput = PodioInput("PodioReader", collections=[
"VXDCollection",
])

##############################################################################
# Geometry Svc
##############################################################################

geometry_option = "CRD_o1_v01/CRD_o1_v01.xml"

if not os.getenv("DETCRDROOT"):
print("Can't find the geometry. Please setup envvar DETCRDROOT." )
sys.exit(-1)

geometry_path = os.path.join(os.getenv("DETCRDROOT"), "compact", geometry_option)
if not os.path.exists(geometry_path):
print("Can't find the compact geometry file: %s"%geometry_path)
sys.exit(-1)

from Configurables import GeomSvc
geosvc = GeomSvc("GeomSvc")
geosvc.compact = geometry_path


##############################################################################
# TracccAlg
##############################################################################

from Configurables import TracccAlg
alg = TracccAlg("TracccAlg")
alg.SimTrackerHitCollection.Path = "VXDCollection"

##############################################################################
# TracccAlg
##############################################################################
# from Configurables import PodioOutput
# out = PodioOutput("out")
# out.filename = "sim_RawTimeSeries.root"
# out.outputCommands = ["keep *"]

# VXDCollection.cellID
# system:5,side:-2,layer:9,module:8,sensor:8,barrelside:-2,x:-10,y:-10

# ApplicationMgr
from Configurables import ApplicationMgr
ApplicationMgr( TopAlg = [podioinput, alg],
EvtSel = 'NONE',
EvtMax = 5000,
ExtSvc = [dsvc, geosvc],
# OutputLevel=DEBUG
)
90 changes: 90 additions & 0 deletions Reconstruction/TracccAlg/src/TracccAlg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// read csv
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <sstream>

// dependence
#include "TracccAlg.h"
#include "edm4hep/SimTrackerHitCollection.h"

// root
#include <TFile.h>
#include <TTree.h>

DECLARE_COMPONENT(TracccAlg)

TracccAlg::TracccAlg(const std::string& name, ISvcLocator* svcLoc)
: GaudiAlgorithm(name, svcLoc)
{
declareProperty("SimTrackerHitCollection", m_hitCol);
}

StatusCode TracccAlg::initialize()
{
info() << "begin initialize TracccAlg" << endmsg;

m_geosvc = service<IGeomSvc>("GeomSvc");
info() << "getDecoder VXDCollection" << endmsg;

m_decoder = m_geosvc->getDecoder("VXDCollection");

if(!m_decoder){
error() << "Failed to get the decoder. " << endmsg;
return StatusCode::FAILURE;
}

std::string detect = "CEPCSW_sim/tml_detector/detectors.csv";
std::string digit = "CEPCSW_sim/tml_detector/double_VXD_config.json";

my_acts->initial(&detect, &digit);

return GaudiAlgorithm::initialize();
}

StatusCode TracccAlg::execute()
{
auto hits = m_hitCol.get();

// system:5,side:-2,layer:9,module:8,sensor:8,barrelside:-2,x:-11,y:-14
for (auto hit: *hits) {
auto cellid = hit.getCellID();
m_layer = m_decoder->get(cellid, "layer");
m_module = m_decoder->get(cellid, "module");
m_barrelside = m_decoder->get(cellid, "barrelside");
m_x = m_decoder->get(cellid, "x");
m_y = m_decoder->get(cellid, "y");
// info() << " x: " << m_x << " y: " << m_y << endmsg;

gid = generate_gid(m_layer, m_module, m_barrelside);
if (m_layer < 2){
m_x += 220;
m_y += 1250;
}
else{
m_x += 440;
m_y += 2500;
}

// geometry_id,hit_id,channel0,channel1,timestamp,value,particle_id
my_cell cell_col = {gid, m_layer, (uint32_t)m_x, (uint32_t)m_y,
0, 0.02, event_num};

cells.push_back(cell_col);
}

if ((event_num % 50) == 49){
int en = event_num / 50;
my_acts->run(&cells, en);
cells.clear();
}

event_num ++;
return StatusCode::SUCCESS;
}

StatusCode TracccAlg::finalize()
{
info() << "finalize TracccAlg" << endmsg;
return GaudiAlgorithm::finalize();
}
61 changes: 61 additions & 0 deletions Reconstruction/TracccAlg/src/TracccAlg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef TRACCCALG_H
#define TRACCCALG_H

#include "k4FWCore/DataHandle.h"
#include "GaudiAlg/GaudiAlgorithm.h"
#include "DD4hep/Detector.h"
#include <DDRec/DetectorData.h>

#include "GaudiKernel/NTuple.h"
#include "DetInterface/IGeomSvc.h"
#include "traccc/wrapper/sycl_wrapper.hpp"

namespace edm4hep {
class SimTrackerHitCollection;
}

namespace dd4hep {
namespace DDSegmentation {
class BitFieldCoder;
}
}

class TracccAlg : public GaudiAlgorithm
{

public :

TracccAlg(const std::string& name, ISvcLocator* svcLoc);

virtual StatusCode initialize();
virtual StatusCode execute();
virtual StatusCode finalize();

private :
DataHandle<edm4hep::SimTrackerHitCollection> m_hitCol{"VXDCollection", Gaudi::DataHandle::Reader, this};
SmartIF<IGeomSvc> m_geosvc;

dd4hep::DDSegmentation::BitFieldCoder *m_decoder;

uint64_t m_layer;
uint64_t m_module;
int m_barrelside;
int m_x;
int m_y;
uint64_t gid;

uint64_t event_num = 0;

std::vector<my_cell> cells{};

traccc_wrapper* my_acts = factory();
};

uint64_t generate_gid(uint64_t layer, uint64_t module, int barrelside) {
uint64_t acts_module = (module + 1) * 2;
if (barrelside == 1) acts_module -= 1;
uint64_t acts_layer = (layer + 1) * 2;
return 0x0300000000000000 | (acts_layer << 36) | (acts_module << 8);
}

#endif // PIXEL_H