27#include <TGeoManager.h>
28#include <TGeoGlobalMagField.h>
55struct TrackAtVtxStruct {
81 throw std::runtime_error(
"cannot load the geometry");
85 if (!TGeoGlobalMagField::Instance()->GetField()) {
86 auto l3Current = ic.
options().
get<
float>(
"l3Current");
87 auto dipoleCurrent = ic.
options().
get<
float>(
"dipoleCurrent");
89 3500.,
"A-A",
"$(O2_ROOT)/share/Common/maps/mfchebKGI_sym.root");
90 TGeoGlobalMagField::Instance()->SetField(field);
91 TGeoGlobalMagField::Instance()->Lock();
101 LOG(info) <<
"initializing track extrapolation to vertex";
103 auto grpFile = ic.
options().
get<std::string>(
"grp-file");
104 if (std::filesystem::exists(grpFile)) {
110 auto stop = [
this]() {
111 LOG(info) <<
"track propagation to vertex duration = " << mElapsedTime.count() <<
" s";
122 auto rofs = pc.
inputs().
get<gsl::span<ROFRecord>>(
"rofs");
123 auto tracks = pc.
inputs().
get<gsl::span<TrackMCH>>(
"tracks");
124 auto vertices = pc.
inputs().
get<gsl::span<math_utils::Point3D<double>>>(
"vertices");
126 if (vertices.size() != rofs.size()) {
127 throw length_error(
"number of vertices different from number of events");
131 mTracksAtVtx.clear();
134 for (
const auto& rof : rofs) {
135 auto tStart = std::chrono::high_resolution_clock::now();
136 nTracksTot += extrapTracksToVertex(tracks.subspan(rof.getFirstIdx(), rof.getNEntries()), vertices[++iVertex]);
137 auto tEnd = std::chrono::high_resolution_clock::now();
138 mElapsedTime += tEnd - tStart;
146 writeTracks(msgOut.data());
156 auto& tracksAtVtx = mTracksAtVtx.emplace_back();
159 for (
const auto& track : tracks) {
162 auto& trackAtVtx = tracksAtVtx.emplace_back();
163 trackAtVtx.mchTrackIdx = ++trackIdx;
166 TrackParam trackParamAtVertex(track.getZ(), track.getParameters());
168 tracksAtVtx.pop_back();
171 trackAtVtx.paramAtVertex.x = trackParamAtVertex.getNonBendingCoor();
172 trackAtVtx.paramAtVertex.y = trackParamAtVertex.getBendingCoor();
173 trackAtVtx.paramAtVertex.z = trackParamAtVertex.getZ();
174 trackAtVtx.paramAtVertex.px = trackParamAtVertex.px();
175 trackAtVtx.paramAtVertex.py = trackParamAtVertex.py();
176 trackAtVtx.paramAtVertex.pz = trackParamAtVertex.pz();
177 trackAtVtx.paramAtVertex.sign = trackParamAtVertex.getCharge();
180 TrackParam trackParamAtDCA(track.getZ(), track.getParameters());
182 tracksAtVtx.pop_back();
185 double dcaX = trackParamAtDCA.getNonBendingCoor() -
vertex.x();
186 double dcaY = trackParamAtDCA.getBendingCoor() -
vertex.y();
187 trackAtVtx.dca = TMath::Sqrt(dcaX * dcaX + dcaY * dcaY);
190 TrackParam trackParamAtRAbs(track.getZ(), track.getParameters());
192 tracksAtVtx.pop_back();
195 double xAbs = trackParamAtRAbs.getNonBendingCoor();
196 double yAbs = trackParamAtRAbs.getBendingCoor();
197 trackAtVtx.rAbs = TMath::Sqrt(xAbs * xAbs + yAbs * yAbs);
200 return tracksAtVtx.size();
204 void writeTracks(
char* bufferPtr)
const
208 for (
const auto& tracksAtVtx : mTracksAtVtx) {
211 int nTracks = tracksAtVtx.size();
212 memcpy(bufferPtr, &nTracks,
sizeof(
int));
213 bufferPtr +=
sizeof(
int);
217 memcpy(bufferPtr, tracksAtVtx.data(), nTracks *
sizeof(TrackAtVtxStruct));
218 bufferPtr += nTracks *
sizeof(TrackAtVtxStruct);
223 std::vector<std::vector<TrackAtVtxStruct>> mTracksAtVtx{};
224 std::chrono::duration<double> mElapsedTime{};
232 Inputs{
InputSpec{
"vertices",
"MCH",
"VERTICES", 0, Lifetime::Timeframe},
233 InputSpec{
"rofs",
"MCH",
"TRACKROFS", 0, Lifetime::Timeframe},
234 InputSpec{
"tracks",
"MCH",
"TRACKS", 0, Lifetime::Timeframe},
235 InputSpec{
"clusters",
"MCH",
"TRACKCLUSTERS", 0, Lifetime::Timeframe}},
236 Outputs{
OutputSpec{{
"tracksatvertex"},
"MCH",
"TRACKSATVERTEX", 0, Lifetime::Timeframe}},
240 {
"l3Current", VariantType::Float, -30000.0f, {
"L3 current"}},
241 {
"dipoleCurrent", VariantType::Float, -6000.0f, {
"Dipole current"}}}};
Definition of the GeometryManager class.
Header of the General Run Parameters object.
Definition of the MagF class.
Definition of the Names Generator class.
Definition of a data processor to extrapolate the tracks to the vertex.
Definition of the MCH track parameters minimal structure.
Definition of the MCH track.
Definition of the MCH track parameters for internal use.
static void loadGeometry(std::string_view geomFilePath="", bool applyMisalignment=false, bool preferAlignedFile=true)
static std::string getGRPFileName(const std::string_view prefix=STANDARDSIMPREFIX)
static int initFieldFromGRP(const o2::parameters::GRPMagField *grp, bool verbose=false)
static MagneticField * createFieldMap(float l3Current=-30000., float diCurrent=-6000., Int_t convention=0, Bool_t uniform=kFALSE, float beamenergy=7000, const Char_t *btype="pp", const std::string path=std::string(gSystem->Getenv("VMCWORKDIR"))+std::string("/Common/maps/mfchebKGI_sym.root"))
T get(const char *key) const
decltype(auto) make(const Output &spec, Args... args)
ServiceRegistryRef services()
ConfigParamRegistry const & options()
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
void init(framework::InitContext &ic)
void initCustom(framework::InitContext &ic)
void initFromGRP(std::string grpFile)
void run(framework::ProcessingContext &pc)
track parameters for internal use
static GRPObject * loadFrom(const std::string &grpFileName="")
Defining PrimaryVertex explicitly as messageable.
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
std::vector< OutputSpec > Outputs
o2::framework::DataProcessorSpec getTrackAtVertexSpec(const char *specName)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
TrackParamStruct paramAtVertex
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"