Skip to content

Commit

Permalink
Technical changes to support further mkFit development.
Browse files Browse the repository at this point in the history
There are no significant physics changes.

Several changes only affect mkFit in standalone mode.

Main goals:

- Make it easier to express vectorized code.

- Be able to do simple propagations, parameters only, no errors.

- Explore more precise hit preselection in each layer (see
  MkFinder.selectHitIndicesV2()).

- Make it easier to export low-level algorithm / tracking state for
  further analysis directly in ROOT format.

- Allow further development of Phase2 mkFit tracking, together with
  the new propagate-to-plane functionality (in another PR).

Add half_length member to ModuleInfo, fill it in MkFitGeometryESProducer.cc

Extend HitInfo with half-strip-length, add qbar (the other of r/z variables), Store fast-access arrays as std::vector<HitInfo>.

Move propToR/Z() can/maxReachRadius() from Track to TrackBase.

Implement LayerOfHits::reset() to make sure containers are empty before re-filling.
Call this from both methods (beginHitRegistration() and suckInHits()).

Miscellaneous changes to better support dump-hit-window case.

* RecoTracker/MkFitCore/interface/Track.h
  Add function mcHitIDofFirstHit() to simplify dump-hit-window code.

* RecoTracker/MkFitCore/src/MkBuilder.cc
  Add missing MkFinder setup in dump-hit-window case.

* RecoTracker/MkFitCore/standalone/Makefile.config
  Clarify usage of Ofast (by Steve).

* RecoTracker/MkFitCMS/standalone/Makefile
  Use GNU make &: syntax (grouped targets) for dictionary targets.

* RecoTracker/MkFitCore/src/MiniPropagators.h/cc:
  Implementations of propagators of track parameters only (no
  errors/covariances), with various levels of approximation and also
  supporting vectorization.

Use VDT for fast transcendentals in MiniPropagators.

Add scalar and element-wise arithemtic operators and transcendentals
to Matriplex. This makes writing vectorized loops using Matriplex
variables much clearer.

Prepare infrastructure for deep-dump comparisons in selectHitIndicesV2 (and elsewhere).

* MkFitCore/interface/Config.h
  Fix typo.

* MkFitCore/interface/MkBuilder.h
* MkFitCore/interface/Track.h
* MkFitCore/interface/TrackStructures.h
* MkFitCore/src/TrackStructures.cc
* MkFitCore/src/MkBuilder.cc
* MkFitCore/standalone/Event.cc
* MkFitCore/standalone/Event.h
  Pass seed-index in the current seed-vector along.
    In Event, provide a means of determining sim-track from hits of each
      seed track.

* MkFitCore/src/MkBuilder.cc
  Add handling of WSR_Failed.

* MkFitCore/src/Matrix.h
  Add short-int Matriplex typedefs

* MkFitCore/src/MiniPropagators.cc
* MkFitCore/src/MiniPropagators.h
  Fail-flag consistency, rename State dphi to dalpha.

* MkFitCore/src/MkBase.h
  Add radius() function.

* MkFitCore/src/MkFinder.cc
* MkFitCore/src/MkFinder.h
  Modularization of new/old hit-selection.
    Reimplemented bin-search for edge positions and determined global scaling
      of bin-search windows to reproduce current behavior.

* MkFitCore/standalone/Makefile
* MkFitCore/standalone/Makefile.config
  Add rules for building RntDumper stuff.

* MkFitCore/standalone/RntDumper/
  New sub-directory: Implementation of classes and structures for dumping ROOT
    TTrees or RNTuples.

* MkFitCMS/standalone/Makefile
  Add linking agains libMicRntDump.so

* MkFitCMS/standalone/MkStandaloneSeqs.cc
  Make it easier to find out why standalone tracks are not matched to sim
    tracks.

* MkFitCMS/standalone/Shell.cc
* MkFitCMS/standalone/buildtestMPlex.cc
  Setup Event current-seed-vector pointers as needed during event processing.

* MkFitCMS/standalone/mkFit.cc
  Finalize all RntDumpers on exit.

Standalone consolidation plus cleanup of parameters, remove unused ones.

* MkFitCMS/standalone/buildtestMPlex.cc
  When validation is on make sure seeds are restored after BH, STD, CE runs.

* MkFitCMS/standalone/mkFit.cc
  Rename run-all to run default -- make it run std, and ce.

* MkFitCore/src/MkBuilder.cc
  Missing MkFinder setup in backwardFitBH().

* MkFitCore/standalone/Geoms/CylCowWLids.cc
  Array of eta extents too short.

* MkFitCore/standalone/Makefile.config
  Consolidate CMSSW and other occurences of Ofast, msse2, std=c++17/1z.
  Cleanup unused -D defines / settings.

* MkFitCore/standalone/ConfigStandalone.h
  Remove unused simulation multiple scattering parameters.
  • Loading branch information
osschar committed Oct 27, 2023
1 parent b714992 commit 4f6a60e
Show file tree
Hide file tree
Showing 38 changed files with 1,913 additions and 429 deletions.
7 changes: 5 additions & 2 deletions RecoTracker/MkFit/plugins/MkFitGeometryESProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void MkFitGeometryESProducer::fillShapeAndPlacement(const GeomDet *det,
DetId detid = det->geographicalId();

float xy[4][2];
float dz;
float half_length, dz;
const Bounds *b = &((det->surface()).bounds());

if (const TrapezoidalPlaneBounds *b2 = dynamic_cast<const TrapezoidalPlaneBounds *>(b)) {
Expand All @@ -212,6 +212,7 @@ void MkFitGeometryESProducer::fillShapeAndPlacement(const GeomDet *det,
xy[2][1] = par[3];
xy[3][0] = par[0];
xy[3][1] = -par[3];
half_length = par[3];
dz = par[2];

#ifdef DUMP_MKF_GEO
Expand All @@ -229,6 +230,7 @@ void MkFitGeometryESProducer::fillShapeAndPlacement(const GeomDet *det,
xy[2][1] = dy;
xy[3][0] = dx;
xy[3][1] = -dy;
half_length = dy;
dz = b2->thickness() * 0.5; // half thickness

#ifdef DUMP_MKF_GEO
Expand Down Expand Up @@ -280,7 +282,8 @@ void MkFitGeometryESProducer::fillShapeAndPlacement(const GeomDet *det,
const auto &p = det->position();
auto z = det->rotation().z();
auto x = det->rotation().x();
layer_info.register_module({{p.x(), p.y(), p.z()}, {z.x(), z.y(), z.z()}, {x.x(), x.y(), x.z()}, detid.rawId()});
layer_info.register_module(
{{p.x(), p.y(), p.z()}, {z.x(), z.y(), z.z()}, {x.x(), x.y(), x.z()}, half_length, detid.rawId()});
// Set some layer parameters (repeatedly, would require hard-coding otherwise)
layer_info.set_subdet(detid.subdetId());
layer_info.set_is_pixel(detid.subdetId() <= 2);
Expand Down
23 changes: 15 additions & 8 deletions RecoTracker/MkFitCMS/standalone/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ CMS_DIR := ${SRCDIR}/RecoTracker/MkFitCMS

LIB_CMS := ../libMicCMS.so
MAIN := ../mkFit
MAIN_DEPS := ${LIB_CMS}
MAIN_LIBS := -lMicCore -lMicCMS
WRMEMF := ../writeMemoryFile
WMF_DICT_PCM := ../WriteMemFileDict_rdict.pcm
SHELL_DICT_PCM := ../ShellDict_rdict.pcm
ROOTOUT := WriteMemFileDict.cc ShellDict.cc

TGTS := ${LIB_CMS} ${MAIN}

ifdef WITH_ROOT
MAIN_DEPS += ../libMicRntDump.so
MAIN_LIBS += -lMicRntDump
TGTS += ${WRMEMF} ${WMF_DICT_PCM} ${SHELL_DICT_PCM}
endif

Expand All @@ -21,18 +26,19 @@ endif
all: ${TGTS}

SRCS := $(wildcard ${CMS_DIR}/src/*.cc) $(wildcard ${SACMS}/*.cc)

ifdef WITH_ROOT
SRCS += ${SACMS}/tkNtuple/WriteMemoryFile.cc
WriteMemFileDict.cc: ${SACMS}/tkNtuple/DictsLinkDef.h
WriteMemFileDict.cc ${WMF_DICT_PCM} &: ${SACMS}/tkNtuple/DictsLinkDef.h
rootcling -I=${SRCDIR} -f WriteMemFileDict.cc $<
${WMF_DICT_PCM}: WriteMemFileDict.cc
mv WriteMemFileDict_rdict.pcm ${WMF_DICT_PCM}

SRCS += ShellDict.cc
ShellDict.cc: ${SACMS}/Shell.h ${SACMS}/ShellLinkDef.h
ShellDict.cc ${SHELL_DICT_PCM} &: ${SACMS}/Shell.h ${SACMS}/ShellLinkDef.h
rootcling -I=${SRCDIR} -f ShellDict.cc ${SACMS}/Shell.h ${SACMS}/ShellLinkDef.h
${SHELL_DICT_PCM}: ShellDict.cc
mv ShellDict_rdict.pcm ${SHELL_DICT_PCM}
endif

SRCB := $(notdir ${SRCS})
DEPS := $(SRCB:.cc=.d)
OBJS := $(SRCB:.cc=.o)
Expand Down Expand Up @@ -60,11 +66,11 @@ ${LIB_CMS}: ${CMS_OBJS}
@mkdir -p $(@D)
${CXX} ${CXXFLAGS} ${VEC_HOST} ${CMS_OBJS} -shared -o $@ ${LDFLAGS_HOST} ${LDFLAGS}

${MAIN}: ${LIB_CMS} mkFit.o
${CXX} ${CXXFLAGS} ${VEC_HOST} ${LDFLAGS} mkFit.o -o $@ ${LDFLAGS_HOST} -ltbb -L.. -lMicCore -lMicCMS -Wl,-rpath=.
${MAIN}: ${MAIN_DEPS} mkFit.o
${CXX} ${CXXFLAGS} ${VEC_HOST} ${LDFLAGS} mkFit.o -o $@ ${LDFLAGS_HOST} -ltbb -L.. ${MAIN_LIBS} -Wl,-rpath=.

${WRMEMF}: WriteMemoryFile.o WriteMemFileDict.o
${CXX} ${CXXFLAGS} ${LDFLAGS} $^ -o $@ ${LDFLAGS_HOST} -ltbb -L.. -lMicCore -Wl,-rpath=.
${WRMEMF}: ${MAIN_DEPS} WriteMemoryFile.o WriteMemFileDict.o
${CXX} ${CXXFLAGS} ${LDFLAGS} $^ -o $@ ${LDFLAGS_HOST} -ltbb -L.. ${MAIN_LIBS} -Wl,-rpath=.

${OBJS}: %.o: %.cc %.d
${CXX} ${CPPFLAGS} ${CXXFLAGS} ${VEC_HOST} -c -o $@ $<
Expand All @@ -77,6 +83,7 @@ echo:
@echo SRCS = ${SRCS}
@echo DEPS = ${DEPS}
@echo OBJS = ${OBJS}
@echo MAIN_LIBS = ${MAIN_LIBS}

echo_cc_defs:
${CXX} -dM -E -mavx2 - < /dev/null
Expand Down
2 changes: 1 addition & 1 deletion RecoTracker/MkFitCMS/standalone/MkStandaloneSeqs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ namespace mkfit {

if (mctrk < 0 || static_cast<size_t>(mctrk) >= event->simTracks_.size()) {
++m_cnt_nomc;
dprint("XX bad track idx " << mctrk << ", orig label was " << label);
dprintf("XX bad track idx %d, orig label was %d\n", mctrk, label);
} else {
auto &simtrack = event->simTracks_[mctrk];
pTmc = simtrack.pT();
Expand Down
4 changes: 4 additions & 0 deletions RecoTracker/MkFitCMS/standalone/Shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ namespace mkfit {
s.sortHitsByLayer(); // sort seed hits for the matched hits (I hope it works here)
}

m_event->setCurrentSeedTracks(seeds);

builder.find_tracks_load_seeds(seeds, do_seed_clean);

builder.findTracksCloneEngine();
Expand Down Expand Up @@ -265,6 +267,8 @@ namespace mkfit {

printf("Shell::ProcessEvent post remove-duplicates: %d comb-cands\n", (int) out_tracks.size());

m_event->resetCurrentSeedTracks();

builder.end_event();
}

Expand Down
33 changes: 27 additions & 6 deletions RecoTracker/MkFitCMS/standalone/buildtestMPlex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ namespace mkfit {

const bool validation_on = (Config::sim_val || Config::quality_val);

TrackVec seeds1;
if (validation_on) {
TrackVec seeds1;

unsigned int algorithms[] = {4}; //only initialStep

for (auto const &s : ev.seedTracks_) {
Expand Down Expand Up @@ -187,6 +186,10 @@ namespace mkfit {

// ev.print_tracks(ev.candidateTracks_, true);

if (validation_on) {
ev.seedTracks_.swap(seeds1);
}

return time;
}

Expand All @@ -199,9 +202,8 @@ namespace mkfit {

const bool validation_on = (Config::sim_val || Config::quality_val);

TrackVec seeds1;
if (validation_on) {
TrackVec seeds1;

unsigned int algorithms[] = {4}; //only initialStep

for (auto const &s : ev.seedTracks_) {
Expand All @@ -226,6 +228,8 @@ namespace mkfit {

bool seeds_sorted = false;
// CCCC builder.PrepareSeeds();
ev.setCurrentSeedTracks(ev.seedTracks_);
ev.simLabelForCurrentSeed(0);

builder.find_tracks_load_seeds(ev.seedTracks_, seeds_sorted);

Expand All @@ -248,6 +252,7 @@ namespace mkfit {
check_nan_n_silly_candidates(ev);

// first store candidate tracks
ev.candidateTracks_.clear();
builder.export_best_comb_cands(ev.candidateTracks_);

job.switch_to_backward();
Expand All @@ -272,10 +277,16 @@ namespace mkfit {
StdSeq::root_val(&ev);
}

ev.resetCurrentSeedTracks();

builder.end_event();

// ev.print_tracks(ev.candidateTracks_, true);

if (validation_on) {
ev.seedTracks_.swap(seeds1);
}

return time;
}

Expand All @@ -288,9 +299,8 @@ namespace mkfit {

const bool validation_on = (Config::sim_val || Config::quality_val);

TrackVec seeds1;
if (validation_on) {
TrackVec seeds1;

unsigned int algorithms[] = {4}; //only initialStep

for (auto const &s : ev.seedTracks_) {
Expand All @@ -315,6 +325,7 @@ namespace mkfit {

bool seeds_sorted = false;
// CCCC builder.PrepareSeeds();
ev.setCurrentSeedTracks(ev.seedTracks_);

builder.find_tracks_load_seeds(ev.seedTracks_, seeds_sorted);

Expand All @@ -337,6 +348,7 @@ namespace mkfit {
check_nan_n_silly_candidates(ev);

// first store candidate tracks - needed for BH backward fit and root_validation
ev.candidateTracks_.clear();
builder.export_best_comb_cands(ev.candidateTracks_);

job.switch_to_backward();
Expand Down Expand Up @@ -365,10 +377,16 @@ namespace mkfit {
StdSeq::root_val(&ev);
}

ev.resetCurrentSeedTracks();

builder.end_event();

// ev.print_tracks(ev.candidateTracks_, true);

if (validation_on) {
ev.seedTracks_.swap(seeds1);
}

return time;
}

Expand Down Expand Up @@ -458,6 +476,8 @@ namespace mkfit {
// Add protection in case no seeds are found for iteration
if (seeds.size() <= 0)
continue;
ev.setCurrentSeedTracks(seeds);
ev.simLabelForCurrentSeed(0);

builder.find_tracks_load_seeds(seeds, do_seed_clean);

Expand Down Expand Up @@ -546,6 +566,7 @@ namespace mkfit {

builder.export_tracks(ev.fitTracks_);
}
ev.resetCurrentSeedTracks();

builder.end_event();
}
Expand Down
Loading

0 comments on commit 4f6a60e

Please sign in to comment.