Skip to content

Commit

Permalink
Merge branch 'prop-plane-rb1' of github.com:trackreco/cmssw into prop…
Browse files Browse the repository at this point in the history
…-plane-rb1
  • Loading branch information
cerati committed Aug 10, 2024
2 parents aab435b + c609972 commit 6f9a138
Show file tree
Hide file tree
Showing 17 changed files with 293 additions and 35 deletions.
6 changes: 4 additions & 2 deletions RecoTracker/MkFitCMS/standalone/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ SRCS := $(wildcard ${CMS_DIR}/src/*.cc) $(wildcard ${SACMS}/*.cc)
ifdef WITH_ROOT
SRCS += ${SACMS}/tkNtuple/WriteMemoryFile.cc
WriteMemFileDict.cc ${WMF_DICT_PCM} &: ${SACMS}/tkNtuple/DictsLinkDef.h
rootcling -I=${SRCDIR} -f WriteMemFileDict.cc $<
rootcling ${CPPFLAGS} -I=${SRCDIR} -f WriteMemFileDict.cc $<
mv WriteMemFileDict_rdict.pcm ${WMF_DICT_PCM}

SRCS += ShellDict.cc
ShellDict.cc ${SHELL_DICT_PCM} &: ${SACMS}/ShellDict.h ${SACMS}/ShellLinkDef.h
rootcling -I=${SRCDIR} -f ShellDict.cc $^
rootcling ${CPPFLAGS} -I=${SRCDIR} -f ShellDict.cc $^
mv ShellDict_rdict.pcm ${SHELL_DICT_PCM}
else
SRCS := $(filter-out ${SACMS}/Shell.cc, ${SRCS})
endif

SRCB := $(notdir ${SRCS})
Expand Down
126 changes: 114 additions & 12 deletions RecoTracker/MkFitCMS/standalone/Shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@

#include "RecoTracker/MkFitCore/standalone/Event.h"

#ifndef NO_ROOT
#include "RecoTracker/MkFitCore/interface/TrackerInfo.h"

#include "TROOT.h"
#include "TRint.h"

#ifdef WITH_REVE
#include "TRandom.h"
#include "ROOT/REveJetCone.hxx"
#include "ROOT/REveManager.hxx"
#include "ROOT/REveScene.hxx"
#include "ROOT/REveBoxSet.hxx"
#endif

#include "oneapi/tbb/task_arena.h"
Expand All @@ -46,29 +54,38 @@ namespace mkfit {
m_backward_fit = Config::backwardFit;

m_data_file = new DataFile;
m_evs_in_file = m_data_file->openRead(in_file, Config::TrkInfo.n_layers());

m_event = new Event(0, Config::TrkInfo.n_layers());
GoToEvent(start_ev);

if ( ! in_file.empty() && Config::nEvents > 0) {
m_evs_in_file = m_data_file->openRead(in_file, Config::TrkInfo.n_layers());
GoToEvent(start_ev);
} else {
printf("Shell initialized but the %s, running on an empty Event.\n",
in_file.empty() ? "input-file not specified" : "requested number of events to process is 0");
}
}

Shell::~Shell() {
delete m_event;
delete m_data_file;
delete m_builder;
delete m_eoh;
delete gApplication;
}

void Shell::Run() {
#ifndef NO_ROOT
std::vector<const char *> argv = { "mkFit", "-l" };
int argc = argv.size();
TRint rint("mkFit-shell", &argc, const_cast<char**>(argv.data()));
gApplication = new TRint("mkFit-shell", &argc, const_cast<char**>(argv.data()));

char buf[256];
sprintf(buf, "mkfit::Shell &s = * (mkfit::Shell*) %p;", this);
gROOT->ProcessLine(buf);
printf("Shell &s variable is set\n");
printf("Shell &s variable is set: ");
gROOT->ProcessLine("s");

rint.Run(true);
gApplication->Run(true);
printf("Shell::Run finished\n");
#else
printf("Shell::Run() no root, we rot -- erroring out. Recompile with WITH_ROOT=1\n");
exit(1);
#endif
}

void Shell::Status() {
Expand All @@ -80,6 +97,8 @@ namespace mkfit {
b2a(m_clean_seeds), b2a(m_backward_fit), b2a(m_remove_duplicates));
}

TrackerInfo* Shell::tracker_info() { return &Config::TrkInfo; }

//===========================================================================
// Event navigation / processing
//===========================================================================
Expand Down Expand Up @@ -561,4 +580,87 @@ namespace mkfit {
printf("\n");
}

//===========================================================================
// Visualization helpers
//===========================================================================

#ifdef WITH_REVE

void Shell::ShowTracker() {
namespace REX = ROOT::Experimental;
auto eveMng = REX::REveManager::Create();
eveMng->AllowMultipleRemoteConnections(false, false);

{
REX::REveElement *holder = new REX::REveElement("Jets");

int N_Jets = 4;
TRandom &r = *gRandom;

//const Double_t kR_min = 240;
const Double_t kR_max = 250;
const Double_t kZ_d = 300;
for (int i = 0; i < N_Jets; i++)
{
auto jet = new REX::REveJetCone(Form("Jet_%d",i ));
jet->SetCylinder(2*kR_max, 2*kZ_d);
jet->AddEllipticCone(r.Uniform(-0.5, 0.5), r.Uniform(0, TMath::TwoPi()),
0.1, 0.2);
jet->SetFillColor(kRed + 4);
jet->SetLineColor(kBlack);
jet->SetMainTransparency(90);

holder->AddElement(jet);
}
eveMng->GetEventScene()->AddElement(holder);
}

auto &ti = Config::TrkInfo;
for (int l = 0; l < ti.n_layers(); ++l) {
auto &li = ti[l];
auto* bs = new REX::REveBoxSet(Form("Layer %d", l));
bs->Reset(REX::REveBoxSet::kBT_InstancedScaledRotated, true, li.n_modules());
bs->SetMainColorPtr(new Color_t);
bs->UseSingleColor();
if (li.is_pixel())
bs->SetMainColor(li.is_barrel() ? kBlue - 3 : kCyan - 3);
else
bs->SetMainColor(li.is_barrel() ? kMagenta - 3 : kGreen - 3);

float t[16];
t[3] = t[7] = t[11] = 0;
t[15] = 1;
for (int m = 0; m < li.n_modules(); ++m) {
auto &mi = li.module_info(m);
auto &si = li.module_shape(mi.shapeid);

auto &x = mi.xdir;
t[0] = x[0] * si.dx1;
t[1] = x[1] * si.dx1;
t[2] = x[2] * si.dx1;
auto y = mi.calc_ydir();
t[4] = y[0] * si.dy;
t[5] = y[1] * si.dy;
t[6] = y[2] * si.dy;
auto &z = mi.zdir;
t[8] = z[0] * si.dz;
t[9] = z[1] * si.dz;
t[10] = z[2] * si.dz;
auto &p = mi.pos;
t[12] = p[0];
t[13] = p[1];
t[14] = p[2];

bs->AddInstanceMat4(t);
}
bs->SetMainTransparency(60);
bs->RefitPlex();

eveMng->GetEventScene()->AddElement(bs);
}
eveMng->Show();
}

#endif // WITH_REVE

}
9 changes: 9 additions & 0 deletions RecoTracker/MkFitCMS/standalone/Shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ namespace mkfit {
class Event;
class EventOfHits;
class MkBuilder;
class TrackerInfo;

class Shell {
public:
enum SeedSelect_e { SS_UseAll = 0, SS_Label, SS_IndexPreCleaning, SS_IndexPostCleaning };

Shell(std::vector<DeadVec> &dv, const std::string &in_file, int start_ev);
~Shell();
void Run();

void Status();
Expand All @@ -40,6 +42,7 @@ namespace mkfit {
Event *event() { return m_event; }
EventOfHits *eoh() { return m_eoh; }
MkBuilder *builder() { return m_builder; }
TrackerInfo *tracker_info();

const TrackVec &seeds() const { return m_seeds; }
const TrackVec &tracks() const { return m_tracks; }
Expand All @@ -57,6 +60,12 @@ namespace mkfit {

void Compare();

// --------------------------------------------------------
// Visualization stuff
#ifdef WITH_REVE
void ShowTracker();
#endif

private:
std::vector<DeadVec> &m_deadvectors;
DataFile *m_data_file = nullptr;
Expand Down
4 changes: 4 additions & 0 deletions RecoTracker/MkFitCMS/standalone/ShellDict.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
#include "RecoTracker/MkFitCMS/standalone/Shell.h"
#include "RecoTracker/MkFitCore/standalone/Event.h"
#include "RecoTracker/MkFitCore/standalone/ConfigStandalone.h"
#include "RecoTracker/MkFitCore/interface/TrackerInfo.h"

#include "RecoTracker/MkFitCore/standalone/RntDumper/RntDumper.h"
26 changes: 24 additions & 2 deletions RecoTracker/MkFitCMS/standalone/ShellLinkDef.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
#pragma link C++ nestedclass;
#pragma link C++ nestedtypedef;

#pragma link C++ namespace mkfit::Const;
#pragma link C++ defined_in namespace mkfit::Const;

#pragma link C++ namespace mkfit::Config;
#pragma link C++ defined_in namespace mkfit::Config;

#pragma link C++ class mkfit::Shell;
#pragma link C++ class mkfit::Event;
#pragma link C++ class mkfit::Hit;
#pragma link C++ class mkfit::Track;
#pragma link C++ class mkfit::Hit+;
#pragma link C++ class mkfit::HitOnTrack+;
#pragma link C++ class std::vector<mkfit::HitOnTrack>+;
#pragma link C++ class mkfit::TrackState+;
#pragma link C++ class mkfit::TrackBase+;
#pragma link C++ class mkfit::TrackBase::Status+;
#pragma link C++ class mkfit::Track+;
#pragma link C++ class std::vector<mkfit::Track>+;

#pragma link C++ class mkfit::ModuleShape;
#pragma link C++ class mkfit::ModuleInfo;
#pragma link C++ class mkfit::LayerInfo;
#pragma link C++ class mkfit::TrackerInfo;

#pragma link C++ class RntDumper;
22 changes: 18 additions & 4 deletions RecoTracker/MkFitCMS/standalone/mkFit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "RecoTracker/MkFitCore/standalone/Event.h"

#ifndef NO_ROOT
#ifdef WITH_ROOT
#include "RecoTracker/MkFitCore/standalone/Validation.h"
#include "RecoTracker/MkFitCore/standalone/RntDumper/RntDumper.h"
#endif
Expand Down Expand Up @@ -802,6 +802,10 @@ int main(int argc, const char* argv[]) {
} else if (*i == "--loop-over-file") {
Config::loopOverFile = true;
} else if (*i == "--shell") {
#ifndef WITH_ROOT
std::cerr << "--shell option is only supported when compiled with ROOT.\n";
exit(1);
#endif
run_shell = true;
} else if (*i == "--num-tracks") {
next_arg_or_die(mArgs, i);
Expand Down Expand Up @@ -1003,18 +1007,28 @@ int main(int argc, const char* argv[]) {
MPT_SIZE, Config::numThreadsEvents, Config::numThreadsFinder,
sizeof(Track), sizeof(Hit), sizeof(SVector3), sizeof(SMatrixSym33), sizeof(MCHitInfo));

#ifdef WITH_ROOT
Shell *shell = nullptr;
#endif
if (run_shell) {
#ifdef WITH_ROOT
tbb::global_control global_limit(tbb::global_control::max_allowed_parallelism, Config::numThreadsFinder);

initGeom();
Shell s(mkfit::internal::deadvectors, g_input_file, g_start_event);
s.Run();
shell = new Shell(mkfit::internal::deadvectors, g_input_file, g_start_event);
shell->Run();
#else
std::cerr << "shell selected on a non-ROOT build.\n";
#endif
} else {
test_standard();
}

#ifndef NO_ROOT
#ifdef WITH_ROOT
RntDumper::FinalizeAll();
if (run_shell) {
delete shell;
}
#endif

// clang-format on
Expand Down
49 changes: 49 additions & 0 deletions RecoTracker/MkFitCore/src/MiniPropagators.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "RecoTracker/MkFitCore/src/MiniPropagators.h"
#include "RecoTracker/MkFitCore/interface/TrackerInfo.h"
#include "vdt/atan2.h"
#include "vdt/tan.h"
#include "vdt/sincos.h"
Expand Down Expand Up @@ -102,6 +103,54 @@ namespace mkfit::mini_propagators {
return c.fail_flag;
}

bool InitialState::propagate_to_plane(PropAlgo_e algo, const ModuleInfo& mi, State& c, bool update_momentum) const {
switch (algo) {
case PA_Line: {
// Momentum is never changed ... we simply step along its direction
// to hit the plane.
// const float k = 1.0f / inv_k;

// const float curv = 0.5f * inv_k * inv_pt;
// const float oo_curv = 1.0f / curv; // 2 * radius of curvature
// const float lambda = pz * inv_pt;

//X float dist = (x - mi.pos(0)) * mi.zdir(0) +
//X (y - mi.pos(1)) * mi.zdir(1) +
//X (z - mi.pos(2)) * mi.zdir(2);

// t * p_vec intersects the plane:
float t = (mi.pos(0) * mi.zdir(0) + mi.pos(1) * mi.zdir(1) + mi.pos(2) * mi.zdir(2) -
x * mi.zdir(0) - y * mi.zdir(1) - z * mi.zdir(2)) /
(px * mi.zdir(0) + py * mi.zdir(1) + pz * mi.zdir(2));

//X printf(" module-center: %.2f,%.2f,%.2f pos: %.2f,%.2f,%.2f normal: %.2f,%.2f,%.2f\n",
//X mi.pos(0),mi.pos(1),mi.pos(2), x, y, z, mi.zdir(0),mi.zdir(1),mi.zdir(2));


c = *this;
c.x += t * c.px;
c.y += t * c.py;
c.z += t * c.pz;

//X re-check ditance to plane
//X float dist2 = (c.x - mi.pos(0)) * mi.zdir(0) +
//X (c.y - mi.pos(1)) * mi.zdir(1) +
//X (c.z - mi.pos(2)) * mi.zdir(2);
//X printf(" dist = %.3f, t = %.4f ..... dist2 = %.4f\n", dist, t, dist2);
break;
}

case PA_Quadratic: {
throw std::runtime_error("Quadratic prop_to_plane not implemented");
}

case PA_Exact: {
throw std::runtime_error("Exact prop_to_plane not implemented");
}
}
return false;
}

//===========================================================================
// Vectorized version
//===========================================================================
Expand Down
6 changes: 6 additions & 0 deletions RecoTracker/MkFitCore/src/MiniPropagators.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include "RecoTracker/MkFitCore/interface/MatrixSTypes.h"
#include "Matrix.h"

namespace mkfit {
class ModuleInfo;
}

namespace mkfit::mini_propagators {

enum PropAlgo_e { PA_Line, PA_Quadratic, PA_Exact };
Expand Down Expand Up @@ -33,6 +37,8 @@ namespace mkfit::mini_propagators {

bool propagate_to_r(PropAlgo_e algo, float R, State& c, bool update_momentum) const;
bool propagate_to_z(PropAlgo_e algo, float Z, State& c, bool update_momentum) const;

bool propagate_to_plane(PropAlgo_e algo, const ModuleInfo& mi, State& c, bool update_momentum) const;
};

//-----------------------------------------------------------
Expand Down
Loading

0 comments on commit 6f9a138

Please sign in to comment.