Skip to content

Commit

Permalink
Completed truth match algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
dchao committed Sep 30, 2014
1 parent 4082119 commit e8d8842
Show file tree
Hide file tree
Showing 16 changed files with 714 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ const int DcLund = 411;
const int Dstar0Lund = 423;
const int DstarcLund = 413;
const int KSLund = 310;
const int K0Lund = 311;
const int rhoLund = 213;
const int pi0Lund = 111;
const int KLund = 321;
const int piLund = 211;
const int eLund = 11;
const int nu_eLund = 12;
const int muLund = 13;
const int nu_muLund = 14;
const int tauLund = 15;
const int nu_tauLund = 16;
const int gammaLund = 22;
const int protonLund = 2212;
const int neutronLund = 2112;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <iostream>
#include <fstream>
#include <string>

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
Expand Down Expand Up @@ -41,9 +42,9 @@ void BDtaunuGraphWriter<GraphT, LundMap, LundPM, IdxPM>::operator() (

typename LundMap::const_iterator it = lund_map.find(lund_pm[v]);
if (it != lund_map.end()) {
out << "[label=\"" << idx_pm[v] << ": " << it->second << "\",color=\"red\"]";
out << "[label=\"" << idx_pm[v] << ": " << it->second << "\",color=\"blue\"]";
} else {
out << "[label=\"" << idx_pm[v] << ": " << lund_pm[v] << "\",color=\"red\"]";
out << "[label=\"" << idx_pm[v] << ": " << lund_pm[v] << "\",color=\"blue\"]";
}

}
Expand All @@ -57,4 +58,136 @@ make_graph_writer(const GraphT &g, const LundMap lund_map,
return BDtaunuGraphWriter<GraphT, LundMap, LundPM, IdxPM>(g, lund_map, lund_pm, idx_pm);
}

template <typename GraphT, typename LundMap, typename TruthMatchMap,
typename LundPM, typename IdxPM>
class MyVertexWriter {

private:
typedef typename boost::graph_traits<GraphT>::vertex_descriptor VertexT;

public:
MyVertexWriter(
const GraphT &_graph,
const LundMap &_lund_map,
const TruthMatchMap &_tm_map,
const LundPM &_lund_pm,
const IdxPM &_idx_pm) :
g(_graph),
lund_map(_lund_map),
tm_map(_tm_map),
lund_pm(_lund_pm),
idx_pm(_idx_pm) {}

void operator()(std::ostream &out, const VertexT &v) const;

private:
GraphT g;
LundMap lund_map;
TruthMatchMap tm_map;
LundPM lund_pm;
IdxPM idx_pm;
};

template <typename GraphT, typename LundMap, typename TruthMatchMap,
typename LundPM, typename IdxPM>
void MyVertexWriter<GraphT, LundMap, TruthMatchMap, LundPM, IdxPM>::operator() (
std::ostream &out, const VertexT &v) const {

typename LundMap::const_iterator it = lund_map.find(lund_pm[v]);
typename TruthMatchMap::const_iterator tm_it = tm_map.find(idx_pm[v]);
if (it != lund_map.end()) {
if (tm_it != tm_map.end() && tm_it->second >= 0) {
//out << "[label=\"" << idx_pm[v] << ": " << it->second << "\",color=\"blue\",penwidth=\"3\",fillcolor=\"cyan\",style=\"filled\"]";
out << "[label=\"" << idx_pm[v] << ": " << it->second << "\",color=\"red\",penwidth=\"3\",fillcolor=\"lightskyblue\",style=\"filled\"]";
} else {
out << "[label=\"" << idx_pm[v] << ": " << it->second << "\",color=\"red\"]";
}
} else {
out << "[label=\"" << idx_pm[v] << ": " << lund_pm[v] << "\",color=\"red\"]";
}

}

template <typename GraphT, typename LundMap, typename TruthMatchMap,
typename LundPM, typename IdxPM>
MyVertexWriter<GraphT, LundMap, TruthMatchMap, LundPM, IdxPM>
make_myvertex_writer(const GraphT &g, const LundMap lund_map, const TruthMatchMap truthmatch_map,
const LundPM lund_pm, const IdxPM idx_pm) {

return MyVertexWriter<GraphT, LundMap, TruthMatchMap, LundPM, IdxPM>(g, lund_map, truthmatch_map, lund_pm, idx_pm);
}

template <typename GraphT, typename LundMap, typename TruthMatchMap,
typename LundPM, typename IdxPM>
class MyEdgeWriter {

private:
typedef typename boost::graph_traits<GraphT>::edge_descriptor EdgeT;

public:
MyEdgeWriter(
const GraphT &_graph,
const LundMap &_lund_map,
const TruthMatchMap &_tm_map,
const LundPM &_lund_pm,
const IdxPM &_idx_pm) :
g(_graph),
lund_map(_lund_map),
tm_map(_tm_map),
lund_pm(_lund_pm),
idx_pm(_idx_pm) {}

void operator()(std::ostream &out, const EdgeT &v) const;

private:
GraphT g;
LundMap lund_map;
TruthMatchMap tm_map;
LundPM lund_pm;
IdxPM idx_pm;
};

template <typename GraphT, typename LundMap, typename TruthMatchMap,
typename LundPM, typename IdxPM>
void MyEdgeWriter<GraphT, LundMap, TruthMatchMap, LundPM, IdxPM>::operator() (
std::ostream &out, const EdgeT &e) const {

auto u = source(e, g);
auto v = target(e, g);
typename TruthMatchMap::const_iterator u_tm_it, v_tm_it;
u_tm_it = tm_map.find(idx_pm[u]);
v_tm_it = tm_map.find(idx_pm[v]);
if (
(u_tm_it != tm_map.end() && u_tm_it->second >= 0) &&
(v_tm_it != tm_map.end() && v_tm_it->second >= 0)
) {
out << "[color=\"black\",weight=\"1\", penwidth=\"3\"]";
} else {
out << "[color=\"grey\"]";
}

}

template <typename GraphT, typename LundMap, typename TruthMatchMap,
typename LundPM, typename IdxPM>
MyEdgeWriter<GraphT, LundMap, TruthMatchMap, LundPM, IdxPM>
make_myedge_writer(const GraphT &g, const LundMap lund_map, const TruthMatchMap truthmatch_map,
const LundPM lund_pm, const IdxPM idx_pm) {

return MyEdgeWriter<GraphT, LundMap, TruthMatchMap, LundPM, IdxPM>(g, lund_map, truthmatch_map, lund_pm, idx_pm);
}

class MyGraphWriter {

public:
MyGraphWriter(std::string _title) : title(_title) {}
void operator()(std::ostream &out) const {
out << "graph[fontsize=\"32\"]" << std::endl;
out << "labelloc=\"t\"" << std::endl;
out << "label = " << "\"" << title << "\"" << std::endl;
};
private:
std::string title;
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ RootReader::Status BDtaunuMcReader::next_record() {
mc_graph_manager.analyze_graph();

// Outsource truth match operations to truth matcher
truth_match_manager.update_graph(reco_graph_manager);
truth_match_manager.update_graph(reco_graph_manager, mc_graph_manager);
truth_match_manager.analyze_graph();

// Make derived information ready for access
Expand All @@ -131,5 +131,13 @@ void BDtaunuMcReader::FillMcInfo() {
if (mc_graph_manager.get_mcB2()->tau)
b2_tau_mctype = mc_graph_manager.get_mcB2()->tau->mc_type;
}

auto it = upsilon_candidates.begin();
while (it != upsilon_candidates.end()) {
it->set_truth_match(
truth_match_manager.get_truth_match_status(it->get_reco_index()));
++it;
}

return;
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class BDtaunuMcReader : public BDtaunuReader {

//! Printer
void print_mc_graph(std::ostream &os) const { mc_graph_manager.print(os); }
void print_contracted_mc_graph(std::ostream &os) const { truth_match_manager.print_mc(os); }
void print_truthmatch_reco_graph(std::ostream &os) const { truth_match_manager.print_reco(os); }

std::map<int, int> get_truth_map() const { return truth_match_manager.get_truth_map(); }

private:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace RecoGraph {

// Boost graph typedefs
typedef boost::adjacency_list<
boost::vecS, boost::vecS, boost::directedS,
boost::vecS, boost::vecS, boost::bidirectionalS,
boost::property<boost::vertex_reco_index_t, int,
boost::property<boost::vertex_block_index_t, int,
boost::property<boost::vertex_lund_id_t, int>>>,
Expand Down Expand Up @@ -150,7 +150,7 @@ namespace McGraph {

// Boost graph typedefs
typedef boost::adjacency_list<
boost::vecS, boost::vecS, boost::directedS,
boost::vecS, boost::vecS, boost::bidirectionalS,
boost::property<boost::vertex_mc_index_t, int,
boost::property<boost::vertex_lund_id_t, int>>,
boost::property<boost::edge_index_t, int>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,7 @@ void McGraphManager::print(std::ostream &os) const {
os, g,
make_graph_writer(g, BDtaunuMcReader::lund_to_name,
get(vertex_lund_id, g),
get(vertex_mc_index, g)));
get(vertex_mc_index, g)),
boost::default_writer(),
MyGraphWriter("MC Graph"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class McGraphManager : public GraphManager {
//! Clear cache.
void clear();

//! Get the mc graph
const McGraph::Graph& get_mc_graph() const { return g; }

//! Returns pointer to the MC truth \f$\Upsilon(4S)\f$ if it exists, nullptr otherwise.
const McGraph::Y* get_mcY() const;

Expand Down
Loading

0 comments on commit e8d8842

Please sign in to comment.