Skip to content

Commit

Permalink
merge fixing issue HEP-FCC/heppy#39
Browse files Browse the repository at this point in the history
  • Loading branch information
Alice committed Mar 22, 2017
2 parents 15e8bec + 3ce4b3e commit e3666cc
Show file tree
Hide file tree
Showing 33 changed files with 183 additions and 207 deletions.
6 changes: 2 additions & 4 deletions examples/PythiaConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ papas::ListParticles PythiaConnector::makePapasParticlesFromGeneratedParticles(c
if (ptc.core().status == 1) { // only stable ones

if (tlv.Pt() > 1e-5 && (abs(pdgid) != 12) && (abs(pdgid) != 14) && (abs(pdgid) != 16)) {

auto particle =
papas::Particle(pdgid, (double)ptc.core().charge, tlv, ptc.core().status, startVertex, endVertex);
papas::Particle particle(pdgid, (double)ptc.core().charge, tlv, ptc.core().status, startVertex, endVertex);
particles.push_back(std::move(particle));
// papas::PDebug::write("Selected Papas{}", particle);
}
Expand Down Expand Up @@ -213,7 +211,7 @@ papas::Clusters PythiaConnector::ConvertClustersToPapas(const fcc::CaloClusterCo
for (const auto& c : fccClusters) {
const auto position = c.core().position;
const auto energy = c.core().energy;
auto cluster = papas::Cluster(energy, TVector3(position.x, position.y, position.z), size, clusters.size(), itemtype, subtype);
papas::Cluster cluster(energy, TVector3(position.x, position.y, position.z), size, clusters.size(), itemtype, subtype);
clusters.emplace(cluster.id(), std::move(cluster));
}
return clusters;
Expand Down
6 changes: 3 additions & 3 deletions examples/example_dag_pair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ int main() {
// BFSVisitor uses an iterative method to traverse
// output the Datatype of all children
std::cout << std::endl << "TRAVERSE CHILDREN (start Node 0) 1 level" << std::endl;
for (auto n : bfs.traverseChildren(n0, 1)) {
for (const auto& n : bfs.traverseChildren(n0, 1)) {
std::cout << n->value().itype << ":" << n->value().ivalue << std::endl;
}

std::cout << std::endl << "TRAVERSE UNDIRECTED (start Node 5) 2 levels " << std::endl;
for (auto n : bfs.traverseUndirected(n5, 2)) {
for (const auto& n : bfs.traverseUndirected(n5, 2)) {
std::cout << n->value().itype << ":" << n->value().ivalue << std::endl;
}

std::cout << std::endl << "TRAVERSE CHILDREN (start Node 0) all levels" << std::endl;

for (auto n : bfs.traverseChildren(n0)) {
for (const auto& n : bfs.traverseChildren(n0)) {
std::cout << n->value().itype << ":" << n->value().ivalue << std::endl;
}

Expand Down
4 changes: 2 additions & 2 deletions examples/example_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ int main(int argc, char* argv[]) {
const char* fname = argv[1];
// open the Pythia file fname
try {
auto pythiaConnector = PythiaConnector(fname);
PythiaConnector pythiaConnector(fname);
#if WITHSORT
std::cout << "doing sorting";
#else
std::cout << "no sort";
#endif
// Create CMS detector and PapasManager
papas::CMS CMSDetector;
auto papasManager = papas::PapasManager(CMSDetector);
papas::PapasManager papasManager(CMSDetector);

unsigned int eventNo = 0;
unsigned int nEvents = 100;
Expand Down
4 changes: 2 additions & 2 deletions examples/example_pdebug_python_comparer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main(int argc, char* argv[]) {
return 1;
}
const char* fname = argv[1];
auto pythiaConnector = PythiaConnector(fname);
PythiaConnector pythiaConnector(fname);

if (argc == 3) {
const char* lname = argv[2];
Expand All @@ -37,7 +37,7 @@ int main(int argc, char* argv[]) {
CMS CMSDetector;
papas::PapasManager papasManager{CMSDetector};
unsigned int eventNo = 0;
unsigned int nEvents = 5;
unsigned int nEvents = 10;

auto start = std::chrono::steady_clock::now();

Expand Down
2 changes: 1 addition & 1 deletion examples/example_plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main(int argc, char* argv[]) {
return 1;
}
const char* fname = argv[1];
auto pythiaConnector = PythiaConnector(fname);
PythiaConnector pythiaConnector(fname);

// Create CMS detector and PapasManager
CMS CMSDetector;
Expand Down
2 changes: 1 addition & 1 deletion examples/example_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main(int argc, char* argv[]) {
return 1;
}
const char* fname = argv[1];
auto pythiaConnector = PythiaConnector(fname);
PythiaConnector pythiaConnector(fname);

if (argc == 3) {
const char* lname = argv[2];
Expand Down
1 change: 1 addition & 0 deletions papas/datatypes/Cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Cluster {

/** Constructor: makes new cluster with a new id based on a copy of an existing cluster. The new id must be provided.
@param[in] cluster the cluster that is to be "copied"
@param[in] index of the collection into which the cluster is to be stored
@param[in] type eg IdCoder::kHcalCluster the identifier type
@param[in] subtype subtype of cluster eg 'm' for merged, 's' for smeared. Defaults to 'u' for unset.
@param[in] val the value that will be used when creating the Cluster identifier and which is used for sorting.
Expand Down
6 changes: 4 additions & 2 deletions papas/datatypes/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class Event {
* @param[in] collection the collection
*/
template <class T>
Ids collectionIds(const T& collection) const;
Ids collectionIds(const T& collection, bool sort = false) const;
/**
* @brief takes all the history collection and merged them into one single history
*/
Expand Down Expand Up @@ -237,11 +237,13 @@ void Event::addCollectionInternal(
}

template <class T>
Ids Event::collectionIds(const T& collection) const {
Ids Event::collectionIds(const T& collection, bool sort) const {
Ids ids;
for (const auto& item : collection) {
ids.push_back(item.first);
}
if (sort)
ids.sort(std::greater<Identifier>());
return ids;
}
}
Expand Down
2 changes: 1 addition & 1 deletion papas/datatypes/HistoryHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace papas {
@code
Usage example:
auto hhelper = HistoryHelper(event);
HistoryHelper hhelper(event);
//find what is connected to (say) a reconstructed particle
auto ids =hhelper.linkedIds(id);
//filter the connected ids selecting only the ecals of subtype 'm'
Expand Down
4 changes: 2 additions & 2 deletions papas/datatypes/src/Cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Cluster::Cluster(Cluster&& c)
if (c.subClusters().size() == 1 && c.id() == (*c.subClusters().begin())->id())
m_subClusters.push_back(this); // non merged cluster point to itself
else
for (auto s : c.subClusters()) // merged clusters
for (const auto& s : c.subClusters()) // merged clusters
m_subClusters.push_back(s);
}

Expand Down Expand Up @@ -100,7 +100,7 @@ std::ostream& operator<<(std::ostream& os, const Cluster& cluster) {
os << "Cluster: " << std::setw(6) << std::left << IdCoder::pretty(cluster.id()) << ":" << cluster.id() << ": "
<< cluster.info();
os << " sub(";
for (auto c : cluster.subClusters()) {
for (const auto& c : cluster.subClusters()) {
os << IdCoder::pretty(c->id()) << ", ";
}
os << ")";
Expand Down
4 changes: 2 additions & 2 deletions papas/datatypes/src/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const Blocks& Event::blocks(const IdCoder::SubType subtype) const {
}
bool Event::hasCollection(IdCoder::ItemType type, const IdCoder::SubType subtype) const {
// Check if this collection is present
auto found = false;
bool found = false;
switch (type) {
case IdCoder::kEcalCluster:
found = (m_ecalClustersCollection.find(subtype) != m_ecalClustersCollection.end());
Expand Down Expand Up @@ -125,7 +125,7 @@ bool Event::hasObject(Identifier id) const {
void Event::extendHistory(const Nodes& history) {
// A separate history is created at each stage.
// the following adds this history into the papasevent history
for (const auto node : history) {
for (const auto& node : history) {
for (const auto& c : node.second.children()) {
makeHistoryLink(node.first, c->value(), *m_history);
}
Expand Down
10 changes: 5 additions & 5 deletions papas/datatypes/src/HistoryHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace papas {
HistoryHelper::HistoryHelper(const Event& event) : m_event(event) {}

Ids HistoryHelper::linkedIds(Identifier id, DAG::enumVisitType direction) const {
const auto history = m_event.history();
auto& startnode = history->at(id);
auto bfs = DAG::BFSRecurseVisitor<PFNode>();
auto nodes = bfs.traverseNodes(startnode, direction);
const auto& history = m_event.history();
const auto& startnode = history->at(id);
DAG::BFSRecurseVisitor<PFNode> bfs;
const auto& nodes = bfs.traverseNodes(startnode, direction);
Ids ids;
for (auto node : nodes) {
for (const auto& node : nodes) {
ids.push_back(node->value());
}
return ids;
Expand Down
4 changes: 2 additions & 2 deletions papas/display/src/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Display::Display(std::list<ViewPane::Projection> views) {
views = {ViewPane::Projection::xy, ViewPane::Projection::yz, ViewPane::Projection::xz};
}
/// Creates viewpanes
for (auto view : views) {
for (auto& view : views) {
if ((view == ViewPane::Projection::xy) | (view == ViewPane::Projection::yz) | (view == ViewPane::Projection::xz)) {
m_views[ViewPane::ProjectionStrings[view]] =
std::unique_ptr<ViewPane>{new ViewPane(view, 100, -4, 4, 100, -4, 4)};
Expand All @@ -27,7 +27,7 @@ Display::Display(std::list<ViewPane::Projection> views) {
};

void Display::addToRegister(std::shared_ptr<Drawable> obj, int layer, bool clearable) {
for (auto const& view : m_views) {
for (auto& view : m_views) {
view.second->addToRegister(obj, layer, clearable);
}
};
Expand Down
8 changes: 3 additions & 5 deletions papas/graphtools/DefinitionsNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ typedef std::list<const Nodes*> ListNodes; ///< collection of Nodes

inline PFNode& findOrMakeNode(Identifier id, Nodes& history) {
if (history.empty() || (history.find(id) == history.end()) ) {

auto newnode = PFNode(id);

PFNode newnode(id);
history.emplace(id, newnode);
}
return history.at(id);
Expand All @@ -41,8 +39,8 @@ inline void makeHistoryLinks(const Ids& parentids, const Ids& childids, Nodes& h
}

inline void printHistory(const Nodes& history) {
for (auto node : history)
for (auto cnode : node.second.children())
for (const auto& node : history)
for (const auto& cnode : node.second.children())
std::cout << IdCoder::pretty(node.first) << ":" << IdCoder::pretty(cnode->value()) << " ";
}

Expand Down
12 changes: 6 additions & 6 deletions papas/graphtools/DirectedAcyclicGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void BFSVisitor<N>::traverse(const Nodeset<N>& nodes, typename DAG::enumVisitTyp
std::queue<int> nodeDepth; // keeps track of the node depths so we can limit how deep we go if we wish

// Mark the current node as visited and enqueue it
for (auto const& node : nodes) {
for (auto& node : nodes) {
if (m_visited.find(node) == m_visited.end()) { // if node is not listed as already being visited
node->accept(*this); // mark as visited and add to results
nodeQueue.push(node); // put into the queue
Expand All @@ -242,7 +242,7 @@ void BFSVisitor<N>::traverse(const Nodeset<N>& nodes, typename DAG::enumVisitTyp

if ((depth < 0 || curdepth < depth) && // NB depth=-1 means we are visiting everything
((visittype == pt::CHILDREN) | (visittype == pt::UNDIRECTED))) { // use the children
for (auto node : nodeQueue.front()->children()) {
for (auto& node : nodeQueue.front()->children()) {
if (m_visited.find(node) == m_visited.end()) { // check node is not already being visited
node->accept(*this);
nodeQueue.push(node);
Expand All @@ -252,7 +252,7 @@ void BFSVisitor<N>::traverse(const Nodeset<N>& nodes, typename DAG::enumVisitTyp
}
if ((depth < 0 || curdepth < depth) && // NB depth=-1 means we are visiting everything
((visittype == pt::PARENTS) | (visittype == pt::UNDIRECTED))) { // use the parents
for (auto node : nodeQueue.front()->parents()) {
for (auto& node : nodeQueue.front()->parents()) {

if (m_visited.find(node) == m_visited.end()) { // check node is not already being visited
node->accept(*this);
Expand Down Expand Up @@ -283,7 +283,7 @@ void BFSRecurseVisitor<N>::traverse(const Nodeset<N>& nodes, typename DAG::enumV
return; // end of the recursion
}

for (auto node : nodes) {
for (auto& node : nodes) {

// Only process a node if not already visited
if (BFSVisitor<N>::m_visited.find(node) == BFSVisitor<N>::m_visited.end()) {
Expand All @@ -294,11 +294,11 @@ void BFSRecurseVisitor<N>::traverse(const Nodeset<N>& nodes, typename DAG::enumV
// and store these into visitnextnodes
// NB depth=-1 means we are visiting everything
if (depth != 0 && (visittype == pt::CHILDREN | visittype == pt::UNDIRECTED))
for (const auto child : node->children()) {
for (const auto& child : node->children()) {
if (!this->alreadyVisited(child)) visitnextnodes.insert(child);
}
if (depth != 0 && (visittype == pt::PARENTS | visittype == pt::UNDIRECTED))
for (const auto parent : node->parents()) {
for (const auto& parent : node->parents()) {
if (!this->alreadyVisited(parent)) visitnextnodes.insert(parent);
}
}
Expand Down
2 changes: 1 addition & 1 deletion papas/graphtools/FloodFill.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ std::vector<typename FloodFill<T>::Nodevector> FloodFill<T>::traverse(FloodFill<
m_visited.clear();
BFSVisitor<TNode> bfs;

for (auto& elem : nodes) {
for (const auto& elem : nodes) {

if (m_visited.find(&elem.second) != m_visited.end()) continue; // already done this node so skip the rest

Expand Down
2 changes: 1 addition & 1 deletion papas/graphtools/GraphBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace papas {
Usage example:
@code
auto builder = GraphBuilder(ids, edges);
GraphBuilder builder(ids, edges);
for (b in builder.blocks()) {
...
}
Expand Down
9 changes: 5 additions & 4 deletions papas/graphtools/src/GraphBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@ GraphBuilder::GraphBuilder(const Ids& ids, Edges&& edges) : m_edges(edges), m_el
}
DAG::FloodFill<Identifier> FFill;
// traverse does the work and returns a vector of connected node groups
for (auto& group : FFill.traverse(m_localNodes)) {
for (const auto& group : FFill.traverse(m_localNodes)) {
// each of the nodevectors is about to become a separate block
// we need the vector of ids and the map of edges in order to make the block
Ids subgraph;
for (auto& node : group) {
for (const auto& node : group) {
subgraph.push_back(node->value());
}
#if WITHSORT
sortIds(subgraph); //sort in descending order
#endif
m_subGraphs.push_back(subgraph);
}
}

void GraphBuilder::sortIds(Ids& ids) {
#if WITHSORT
ids.sort(std::greater<uint64_t>()); //sort in descending order
#endif
}

} // end namespace papas
4 changes: 2 additions & 2 deletions papas/graphtools/src/Ruler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Distance Ruler::clusterClusterDistance(const Cluster& cluster1, const Cluster& c
std::list<double> allDistances;
std::list<double> linkedDistances;
bool isLinked = false;
for (const auto c1 : cluster1.subClusters()) {
for (const auto c2 : cluster2.subClusters()) {
for (const auto& c1 : cluster1.subClusters()) {
for (const auto& c2 : cluster2.subClusters()) {
Distance d = clusterClusterDistance(*c1, *c2); // recursive call
allDistances.push_back(d.distance());
if (d.isLinked()) {
Expand Down
2 changes: 1 addition & 1 deletion papas/reconstruction/BlockBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace papas {
Usage example:
@code
auto builder = BlockBuilder (ids, edges, history, blocks, 'r');
BlockBuilder builder(ids, edges, history, blocks, 'r');
}
@endcode
Expand Down
5 changes: 3 additions & 2 deletions papas/reconstruction/PFBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PFBlock {
PFBlock(const Ids& elementIds, Edges& edges, unsigned int index,
char subtype = 'u'); // relevant parts of edges will be removed and become owned by PFBlock
PFBlock(PFBlock&& pfblock) = default; // allow move
const Ids& elementIds() const { return m_elementIds; } ///< returns vector of all ids in the block
const Ids& elementIds(bool sort = false) const { return m_elementIds; } ///< returns vector of all ids in the block
const Edge& findEdge(Edge::EdgeKey key) const; ///< return Edge corresponding to Edge key
/**
Returns list of all edges of a given edge type that are connected to a given id.
Expand All @@ -60,7 +60,8 @@ class PFBlock {
@param[in] edgetype : is an optional type of edge. If specified only links of the given edgetype will be returned
@return vector of ids that are linked to the id
*/
Ids linkedIds(Identifier id, Edge::EdgeType edgetype = Edge::EdgeType::kUnknown) const;

Ids linkedIds(Identifier id, Edge::EdgeType edgetype = Edge::EdgeType::kUnknown, bool sort = false) const;

std::string shortName() const; ///< Short descriptor of block such as E3H1T2 (three Ecals, 1 Hcal, 2 tracks)
int countEcal() const; ///< Counts how many ecal cluster ids are in the block
Expand Down
2 changes: 1 addition & 1 deletion papas/reconstruction/PFBlockSplitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Usage example:
@code
auto& simplifiedblocks = createBlocks();
auto& history = createHistory();
auto blockBuilder = PFBlockSplitter(m_event, blockSubtype, simplifiedblocks, history);
PFBlockSplitter blockBuilder(m_event, blockSubtype, simplifiedblocks, history);
//store a pointer to the ouputs into the event
m_event.addCollection(simplifiedblocks);
Expand Down
4 changes: 2 additions & 2 deletions papas/reconstruction/PFReconstructor.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class PFReconstructor {
Ids ids = m_pfEvent.mergedElementIds();
// create the blocks of linked ids
auto bBuilder = PFBlockBuilder(m_pfEvent, ids);
PFBlockBuilder bBuilder(m_pfEvent, ids);
// do the reconstruction of the blocks
auto pfReconstructor = PFReconstructor(m_pfEvent);
PFReconstructor pfReconstructor(m_pfEvent);
pfReconstructor.reconstruct(bBuilder.blocks());
m_pfEvent.setReconstructedParticles(std::move(pfReconstructor.particles()));
@endcode
Expand Down
Loading

0 comments on commit e3666cc

Please sign in to comment.