Skip to content

Commit

Permalink
Moved graph satellite data and graph utilities into GraphDef
Browse files Browse the repository at this point in the history
  • Loading branch information
dchao committed Sep 22, 2014
1 parent 37e133e commit db3f8fa
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 148 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "RecoIndexer.h"
#include "BDtaunuDef.h"
#include "GraphDef.h"

#include <cmath>
#include <cstdlib>
#include <cassert>
#include <initializer_list>

RecoIndexer::RecoIndexer() :
RecoGraph::RecoIndexer::RecoIndexer() :
nY(0), nB(0), nD(0), nC(0),
nh(0), nl(0), ngamma(0) {};

RecoIndexer::RecoIndexer(
RecoGraph::RecoIndexer::RecoIndexer(
int _nY, int _nB, int _nD,
int _nC, int _nh, int _nl, int _ngamma) :
nY(_nY), nB(_nB), nD(_nD), nC(_nC),
Expand All @@ -23,7 +23,7 @@ RecoIndexer::RecoIndexer(
// C candidates: ... continue pattern.
// h candidates: ... continue pattern.
// gamma candidates: ... continue pattern.
int RecoIndexer::operator()(int lund, int idx) const {
int RecoGraph::RecoIndexer::operator()(int lund, int idx) const {

int abslund = std::abs(lund);
switch (abslund) {
Expand Down Expand Up @@ -54,7 +54,7 @@ int RecoIndexer::operator()(int lund, int idx) const {
return -1;
}

void RecoIndexer::clear() {
void RecoGraph::RecoIndexer::clear() {
nY = 0;
nB = 0;
nD = 0;
Expand All @@ -64,7 +64,7 @@ void RecoIndexer::clear() {
ngamma = 0;
}

void RecoIndexer::set(std::initializer_list<int> l) {
void RecoGraph::RecoIndexer::set(std::initializer_list<int> l) {

assert(l.size() == 7);

Expand Down
99 changes: 99 additions & 0 deletions create_database/tuple_reader/GraphDef.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#ifndef __GRAPHDEF_H_
#define __GRAPHDEF_H_

#include <initializer_list>
#include <boost/graph/adjacency_list.hpp>

#include "BDtaunuDef.h"

namespace boost {
enum vertex_lund_id_t { vertex_lund_id };
BOOST_INSTALL_PROPERTY(vertex, lund_id);
Expand Down Expand Up @@ -33,8 +36,85 @@ typedef typename boost::property_map<Graph, boost::vertex_lund_id_t>::type LundI
typedef typename boost::property_map<Graph, boost::vertex_reco_index_t>::type RecoIndexPropertyMap;
typedef typename boost::property_map<Graph, boost::vertex_block_index_t>::type BlockIndexPropertyMap;

struct RecoLepton {
int l_block_idx = -1;
int pi_block_idx = -1;
int tau_mode = static_cast<int>(bdtaunu::TauType::null);
};

struct RecoD {
RecoD() = default;
int D_mode = static_cast<int>(bdtaunu::RecoDTypeCatalogue::DType::null);
int Dstar_mode = static_cast<int>(bdtaunu::RecoDTypeCatalogue::DstarType::NoDstar);
};

struct RecoB {
RecoB() = default;
int flavor = static_cast<int>(bdtaunu::BFlavor::null);
RecoD *D = nullptr;
RecoLepton *Lepton = nullptr;
};

struct RecoY {
RecoY() = default;
RecoB *tagB = nullptr;
RecoB *sigB = nullptr;
};

/** @brief This class assigns a unique index to each reconstructed particle.
*
* @detail
* # Motivation
* The need for every reconstructed particle of the event to have a unique
* index arises primarily in accessessing vertex information in the BGL graph.
* However, such an indexing is more convenient to use than the existing
* BtaTupleMaker indexing.
*
* # Implementation
* This class builds a hash function from the reco particle's index in the
* BtaTupleMaker block to a unique index.
*
* See RecoIndexer.cc for details.
*/
class RecoIndexer {

private:
int nY, nB, nD, nC, nh, nl, ngamma;

public:
RecoIndexer();
RecoIndexer(int _nY, int _nB, int _nD,
int _nC, int _nh, int _nl, int _ngamma);
RecoIndexer(const RecoIndexer &r) = default;
RecoIndexer &operator=(const RecoIndexer &r) = default;
~RecoIndexer() {};

//! Given the lundId and block index, return the unique reco index.
int operator()(int lund, int idx) const;

//! Return total number of reco particles in this event.
int total() const { return nY + nB + nD + nC + nh + nl + ngamma; }

//! Set the total number of each type of reco particle.
/*! The list order is { nY, nB, nD, nC, nh, nl, ngamma } */
void set(std::initializer_list<int> l);

//! Clear cache.
void clear();
};

}











namespace boost {
enum vertex_mc_index_t { vertex_mc_index };
BOOST_INSTALL_PROPERTY(vertex, mc_index);
Expand All @@ -56,6 +136,25 @@ typedef typename boost::graph_traits<Graph>::adjacency_iterator AdjacencyIterato
typedef typename boost::property_map<Graph, boost::vertex_lund_id_t>::type LundIdPropertyMap;
typedef typename boost::property_map<Graph, boost::vertex_mc_index_t>::type McIndexPropertyMap;

struct McTau {
McTau() = default;
int mc_type = static_cast<int>(bdtaunu::TauMcType::null);
};

struct McB {
McB() = default;
int flavor = static_cast<int>(bdtaunu::BFlavor::null);
int mc_type = static_cast<int>(bdtaunu::McBTypeCatalogue::BMcType::null);
McTau *tau = nullptr;
};

struct McY {
McY() = default;
bool isBBbar = true;
McB *B1 = nullptr;
McB *B2 = nullptr;
};

}

#endif
4 changes: 2 additions & 2 deletions create_database/tuple_reader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ LIBNAME = libTupleReader.so
PKG_LIBPATH = lib

# package Contents
SOURCES = BDtaunuDef.cc \
SOURCES = BDtaunuDef.cc GraphDef.cc \
BDtaunuHelpers.cc UpsilonCandidate.cc \
RootReader.cc BDtaunuReader.cc BDtaunuMcReader.cc \
RecoIndexer.cc RecoGraphVisitors.cc RecoGraphManager.cc \
RecoGraphVisitors.cc RecoGraphManager.cc \
McGraphManager.cc McGraphVisitors.cc

# Dependencies
Expand Down
1 change: 0 additions & 1 deletion create_database/tuple_reader/McGraphManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "BDtaunuDef.h"
#include "GraphDef.h"
#include "Particles.h"
#include "BDtaunuMcReader.h"
#include "McGraphManager.h"
#include "BDtaunuGraphWriter.h"
Expand Down
13 changes: 6 additions & 7 deletions create_database/tuple_reader/McGraphManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "GraphManager.h"
#include "GraphDef.h"
#include "Particles.h"
#include "McGraphVisitors.h"

class BDtaunuMcReader;
Expand Down Expand Up @@ -112,13 +111,13 @@ class McGraphManager : public GraphManager {
void clear();

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

//! Returns pointer to one of the MC truth \f$B\f$ if it exists, nullptr otherwise.
const McB* get_mcB1() const;
const McGraph::McB* get_mcB1() const;

//! Returns pointer to the other MC truth \f$B\f$ if it exists, nullptr otherwise.
const McB* get_mcB2() const;
const McGraph::McB* get_mcB2() const;

private:

Expand All @@ -138,9 +137,9 @@ class McGraphManager : public GraphManager {
void ClearGraph();

// Graph analysis
std::map<McGraph::Vertex, McY> Y_map;
std::map<McGraph::Vertex, McB> B_map;
std::map<McGraph::Vertex, McTau> Tau_map;
std::map<McGraph::Vertex, McGraph::McY> Y_map;
std::map<McGraph::Vertex, McGraph::McB> B_map;
std::map<McGraph::Vertex, McGraph::McTau> Tau_map;
void ClearAnalysis();

};
Expand Down
5 changes: 2 additions & 3 deletions create_database/tuple_reader/McGraphVisitors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "BDtaunuDef.h"
#include "GraphDef.h"
#include "Particles.h"
#include "McGraphVisitors.h"
#include "McGraphManager.h"

Expand Down Expand Up @@ -70,7 +69,7 @@ void McGraphDfsVisitor::AnalyzeY(const Vertex &u, const Graph &g) {
// Analyze B meson. The quantities computed are:
// 1. B flavor.
// 2. Pointer to daughter tau.
// 3. MC type. See Particles.h.
// 3. MC type. See GraphDef.h.
void McGraphDfsVisitor::AnalyzeB(const Vertex &u, const Graph &g) {

McB mcB;
Expand Down Expand Up @@ -98,7 +97,7 @@ void McGraphDfsVisitor::AnalyzeB(const Vertex &u, const Graph &g) {
}

// Analyze tau. The quantities computed are:
// 1. MC type. See Particles.h.
// 1. MC type. See GraphDef.h.
void McGraphDfsVisitor::AnalyzeTau(const Vertex &u, const Graph &g) {

McTau mcTau;
Expand Down
63 changes: 0 additions & 63 deletions create_database/tuple_reader/Particles.h

This file was deleted.

3 changes: 1 addition & 2 deletions create_database/tuple_reader/RecoGraphManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <boost/graph/graphviz.hpp>

#include "GraphDef.h"
#include "Particles.h"
#include "BDtaunuReader.h"
#include "RecoGraphManager.h"
#include "BDtaunuGraphWriter.h"
Expand Down Expand Up @@ -127,7 +126,7 @@ void RecoGraphManager::AddCandidates(
// Each vertex has the following information attached:
//
// 1. vertex_reco_index: The unique reco particle index assigned by
// reco_indxer (See RecoIndexer.h). This tracks which
// reco_indexer (See GraphDef.h). This tracks which
// vertex a particlar reco particle is associated with.
//
// 2. vertex_block_index: This is the index of where this reco particle
Expand Down
20 changes: 9 additions & 11 deletions create_database/tuple_reader/RecoGraphManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
#include <vector>
#include <map>

#include "GraphManager.h"
#include "GraphDef.h"
#include "Particles.h"
#include "RecoIndexer.h"
#include "GraphManager.h"
#include "RecoGraphVisitors.h"

class BDtaunuReader;
Expand Down Expand Up @@ -101,7 +99,7 @@ class BDtaunuReader;
* #### Graph analysis
* We use BGL's generic algorithms and visitor classes to analyze the graph.
* Since we are often interested in specific reco particles, we cache `map`s
* of specific particles and its satellite data (see Particles.h); the contents of the
* of specific particles and its satellite data (see GraphDef.h); the contents of the
* `map`s can be reported to the supervising class for analysis.
*
*/
Expand Down Expand Up @@ -137,8 +135,8 @@ class RecoGraphManager : public GraphManager {
//! Get the unique reco particle index. See RecoIndexer.h.
int get_reco_index(int lund, int i) const { return reco_indexer(lund, i); }

//! Access information about the `i`th Y candidate. See Particles.h.
const RecoY* get_recoY(int i) const;
//! Access information about the `i`th Y candidate. See GraphDef.h.
const RecoGraph::RecoY* get_recoY(int i) const;

private:

Expand All @@ -149,7 +147,7 @@ class RecoGraphManager : public GraphManager {
RecoGraph::Graph g;

// Graph construction
RecoIndexer reco_indexer;
RecoGraph::RecoIndexer reco_indexer;
std::map<int, RecoGraph::Vertex> reco_vertex_map;
void ClearGraph();
void AddCandidates(
Expand All @@ -158,10 +156,10 @@ class RecoGraphManager : public GraphManager {
std::vector<int*> &CandDauLund);

// Graph analysis
std::map<RecoGraph::Vertex, RecoY> Y_map;
std::map<RecoGraph::Vertex, RecoB> B_map;
std::map<RecoGraph::Vertex, RecoD> D_map;
std::map<RecoGraph::Vertex, RecoLepton> Lepton_map;
std::map<RecoGraph::Vertex, RecoGraph::RecoY> Y_map;
std::map<RecoGraph::Vertex, RecoGraph::RecoB> B_map;
std::map<RecoGraph::Vertex, RecoGraph::RecoD> D_map;
std::map<RecoGraph::Vertex, RecoGraph::RecoLepton> Lepton_map;
void ClearAnalysis();
};

Expand Down
Loading

0 comments on commit db3f8fa

Please sign in to comment.