Skip to content

Commit

Permalink
Identifier class now called IdCoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Alice committed Mar 21, 2017
1 parent 9d71dff commit 16b8d23
Show file tree
Hide file tree
Showing 34 changed files with 262 additions and 262 deletions.
4 changes: 2 additions & 2 deletions examples/PythiaConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void PythiaConnector::writeClustersROOT(const char* fname, const papas::Clusters

auto checkClusters = ConvertClustersToPapas(ccoll,
0, // size or 0 for merged
papas::Identifier::ItemType::kEcalCluster,
papas::IdCoder::ItemType::kEcalCluster,
's');

writer.writeEvent();
Expand All @@ -207,7 +207,7 @@ void PythiaConnector::writeClustersROOT(const char* fname, const papas::Clusters

papas::Clusters PythiaConnector::ConvertClustersToPapas(const fcc::CaloClusterCollection& fccClusters,
float size,
papas::Identifier::ItemType itemtype,
papas::IdCoder::ItemType itemtype,
char subtype) const {
papas::Clusters clusters;
for (const auto& c : fccClusters) {
Expand Down
4 changes: 2 additions & 2 deletions examples/PythiaConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include "papas/datatypes/Cluster.h"
#include "papas/datatypes/DefinitionsCollections.h"
#include "papas/datatypes/Identifier.h"
#include "papas/datatypes/IdCoder.h"
#include "papas/datatypes/Particle.h"
#include "papas/reconstruction/PapasManager.h"

Expand All @@ -52,7 +52,7 @@ class PythiaConnector {
papas::ListParticles makePapasParticlesFromGeneratedParticles(
const fcc::MCParticleCollection* ptcs); ///< converts pythia particles into Papas type particles
papas::Clusters ConvertClustersToPapas(const fcc::CaloClusterCollection& fccClusters, float size,
papas::Identifier::ItemType itemtype, char subtype) const;
papas::IdCoder::ItemType itemtype, char subtype) const;

void AddClustersToEDM(const papas::Clusters& papasClusters, fcc::CaloClusterCollection& fccClusters);

Expand Down
12 changes: 6 additions & 6 deletions papas/datatypes/Cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "TVector3.h"
#include "papas/datatypes/Definitions.h"
#include "papas/datatypes/Identifier.h"
#include "papas/datatypes/IdCoder.h"
#include <list>
#include <stdio.h>

Expand All @@ -20,20 +20,20 @@ class Cluster {
@param[in] energy Cluster energy
@param[in] position location of Cluster
@param[in] size_m size of cluster (units?)
@param[in] id Identifier type of cluster eg kEcalCluster or kHcalCluster
@param[in] id IdCoder type of cluster eg kEcalCluster or kHcalCluster
@param[in] subtype single char describing type of cluster eg s = smeared, t= true, m = merged
*/
Cluster(double energy, const TVector3& position, double size_m, unsigned int index, Identifier::ItemType id,
Cluster(double energy, const TVector3& position, double size_m, unsigned int index, IdCoder::ItemType id,
char subtype = 't');

/** 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] type eg Identifier::kHcalCluster the Identifier type
@param[in] type eg IdCoder::kHcalCluster the IdCoder 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.
When creating a merged cluster it should ideally be set to the total eneergy of the cluster
*/
Cluster(const Cluster& cluster, unsigned int index, Identifier::ItemType type, char subtype = 'u', float val = 0.0);
Cluster(const Cluster& cluster, unsigned int index, IdCoder::ItemType type, char subtype = 'u', float val = 0.0);
Cluster() = default;
Cluster(Cluster&& c); // needed for unordered_map
Cluster(const Cluster& cluster) = default; // needed for unordered_map
Expand All @@ -55,7 +55,7 @@ class Cluster {
return s_maxEnergy;
}; ///< static that returns max cluster energy (intended for display purposes)
protected:
IdType m_uniqueId; ///< Unique Identifier for Cluster
IdType m_uniqueId; ///< Unique IdCoder for Cluster
double m_size; ///< Cluster size (radius?)
double m_angularSize; ///< Cluster angular size (only valid for non-merged clusters)
double m_pt; ///< Transverse momentum (magnitude of p3 in transverse plane)
Expand Down
10 changes: 5 additions & 5 deletions papas/datatypes/DefinitionsCollections.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define DefinitionsCollections_h

#include "papas/datatypes/Cluster.h"
#include "papas/datatypes/Identifier.h"
#include "papas/datatypes/IdCoder.h"
#include "papas/datatypes/PFParticle.h"
#include "papas/datatypes/Particle.h"
#include "papas/datatypes/Track.h"
Expand All @@ -35,9 +35,9 @@ typedef std::unordered_map<IdType, Track> Tracks; ///< collection of
typedef std::unordered_map<IdType, PFBlock> Blocks; ///< collection of Blocks
typedef std::unordered_map<IdType, Cluster> Clusters; ///< collection of Clusters

typedef std::unordered_map<Identifier::SubType, const PFParticles*> CollectionPFParticles; ///< collection of PFParticles
typedef std::unordered_map<Identifier::SubType, const Tracks*> CollectionTracks; ///< collection of Tracks
typedef std::unordered_map<Identifier::SubType, const Clusters*> CollectionClusters; ///< collection of Clusters
typedef std::unordered_map<Identifier::SubType, const Blocks*> CollectionBlocks; ///< collection of Clusters
typedef std::unordered_map<IdCoder::SubType, const PFParticles*> CollectionPFParticles; ///< collection of PFParticles
typedef std::unordered_map<IdCoder::SubType, const Tracks*> CollectionTracks; ///< collection of Tracks
typedef std::unordered_map<IdCoder::SubType, const Clusters*> CollectionClusters; ///< collection of Clusters
typedef std::unordered_map<IdCoder::SubType, const Blocks*> CollectionBlocks; ///< collection of Clusters
}
#endif /* DefinitionsCollections_h */
66 changes: 33 additions & 33 deletions papas/datatypes/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define Event_h

#include "papas/datatypes/DefinitionsCollections.h"
#include "papas/datatypes/Identifier.h"
#include "papas/datatypes/IdCoder.h"
#include "papas/graphtools/DefinitionsNodes.h"
#include "papas/reconstruction/PFBlock.h"

Expand All @@ -22,7 +22,7 @@ namespace papas {
* Examples of typeAndSubtype are:
* "es" ecal-smeared
* "ps" particle-simulated
* etc see also Identifier class
* etc see also IdCoder class
* The types are
* e = ecal
* h = hcal
Expand Down Expand Up @@ -51,25 +51,25 @@ class Event {
Event(std::shared_ptr<Nodes> hist = std::make_shared<Nodes>(Nodes()));
/**
* @brief adds a pointer to a Clusters collection (unordered map) into the Event
* @param[in] clusters unordered map of Clusters, all of which have the same Identifier typeAndSubtype.
* @param[in] clusters unordered map of Clusters, all of which have the same IdCoder typeAndSubtype.
* The typeAndSubtype will be used as the map index, eg "em" for ecals-merged.
*/
void addCollection(const Clusters& clusters);
/**
* @brief adds a pointer to a Tracks collection (unordered map) into the Event
* @param[in] tracks unordered map of Tracks, all of which have the same Identifier typeAndSubtype
* @param[in] tracks unordered map of Tracks, all of which have the same IdCoder typeAndSubtype
* The typeAndSubtype will be used as the map index, eg "tt" for track-true.
*/
void addCollection(const Tracks& tracks);
/**
* @brief adds a pointer to a Blocks collection (unordered map) into the Event
* @param[in] blocks unordered map of Blocks, all of which have the same Identifier typeAndSubtype
* @param[in] blocks unordered map of Blocks, all of which have the same IdCoder typeAndSubtype
* The typeAndSubtype will be used as the map index, eg "br" for blocks-raw.
*/
void addCollection(const Blocks& blocks);
/**
* @brief adds a pointer to a PFParticles collection (unordered map) into the Event
* @param[in] blocks unordered map of PFParticles, all of which have the same Identifier typeAndSubtype
* @param[in] blocks unordered map of PFParticles, all of which have the same IdCoder typeAndSubtype
* The typeAndSubtype will be used as the map index, eg "pr" for particles-reconstructed.
*/
void addCollection(const PFParticles& particles);
Expand All @@ -87,85 +87,85 @@ class Event {
void extendHistory(const Nodes& history);
/**
* @brief returns true if a collection with type and subtype of id is found
* @param[in] id the Identifier of an object
* @param[in] id the IdCoder of an object
*/
bool hasCollection(IdType id) const;
/**
* @brief returns true if a collection with matching type and subtype is found
* @param[in] type The type of an object eg Identifier::kEcalCluster
* @param[in] type The type of an object eg IdCoder::kEcalCluster
* @param[in] subtype The subtype of an object eg 'm' for merged
*/
bool hasCollection(const Identifier::ItemType type, const Identifier::SubType subtype) const;
bool hasCollection(const IdCoder::ItemType type, const IdCoder::SubType subtype) const;
/**
* @brief returns true if an object matching the Identifier is found in the Event collections
* @param[in] id the Identifier of an object
* @brief returns true if an object matching the IdCoder is found in the Event collections
* @param[in] id the IdCoder of an object
*/
bool hasObject(IdType id) const;
/**
* @brief returns a Clusters collection with typeAndSubtype that match the identifier
* @param[in] id the Identifier of an object
* @param[in] id the IdCoder of an object
*/
const Clusters& clusters(IdType id) const;
/**
* @brief returns a Clusters collection matching type and subtype
* @param[in] type The type of an object eg Identifier::kEcalCluster
* @param[in] type The type of an object eg IdCoder::kEcalCluster
* @param[in] subtype The subtype of an object eg 'm' for merged
*/
const Clusters& clusters(const Identifier::ItemType type, const Identifier::SubType subtype) const;
const Clusters& clusters(const IdCoder::ItemType type, const IdCoder::SubType subtype) const;
/**
* @brief returns a Clusters collection matching type and subtype as a string
* @param[in] typeAndSubtype The type and subtype of an object as a string eg "em" for ecals-merged.
*/
const Clusters& clusters(const std::string& typeAndSubtype) const;
/**
* @brief returns a Cluster with the required id
* @param[in] id the Identifier of an object
* @param[in] id the IdCoder of an object
*/
const Cluster& cluster(IdType id) const { return clusters(id).at(id); };

/**
* @brief returns a Tracks collection matching type and subtype
* @param[in] subtype The subtype of the track eg 's' for smeared
*/
const Tracks& tracks(const Identifier::SubType subtype) const;
const Tracks& tracks(const IdCoder::SubType subtype) const;
/**
* @brief returns a Tracks collection with typeAndSubtype that match the identifier
* @param[in] id the Identifier of an object
* @param[in] id the IdCoder of an object
*/
const Tracks& tracks(IdType id) const { return tracks(Identifier::subtype(id)); };
const Tracks& tracks(IdType id) const { return tracks(IdCoder::subtype(id)); };
/**
* @brief returns a Track with the required id
* @param[in] id the Identifier of an object
* @param[in] id the IdCoder of an object
*/
const Track& track(IdType id) const { return tracks(id).at(id); };
/**
* @brief returns a Particles collection matching type and subtype
* @param[in] subtype The subtype of the particle eg 'r' for reconstructed
*/
const PFParticles& particles(const Identifier::SubType subtype) const;
const PFParticles& particles(const IdCoder::SubType subtype) const;
/**
* @brief returns a PFParticles collection with typeAndSubtype that match the identifier
* @param[in] id the Identifier of an object
* @param[in] id the IdCoder of an object
*/
const PFParticles& particles(IdType id) const { return particles(Identifier::subtype(id)); };
const PFParticles& particles(IdType id) const { return particles(IdCoder::subtype(id)); };
/**
* @brief returns a PFParticle with the required id
* @param[in] id the Identifier of an object
* @param[in] id the IdCoder of an object
*/
const PFParticle& particle(IdType id) const { return particles(id).at(id); };
/**
* @brief returns a Blocks collection matching type and subtype
* @param[in] subtype The subtype of the block eg 'r' for reconstructed
*/
const Blocks& blocks(const Identifier::SubType subtype) const;
const Blocks& blocks(const IdCoder::SubType subtype) const;
/**
* @brief returns a Blocks collection with typeAndSubtype that match the identifier
* @param[in] id the Identifier of an object
* @param[in] id the IdCoder of an object
*/
const Blocks& blocks(IdType id) const { return blocks(Identifier::subtype(id)); };
const Blocks& blocks(IdType id) const { return blocks(IdCoder::subtype(id)); };
/**
* @brief returns a Block with the required id
* @param[in] id the Identifier of an object
* @param[in] id the IdCoder of an object
*/
const PFBlock& block(IdType id) const { return blocks(id).at(id); };
/**
Expand All @@ -184,7 +184,7 @@ class Event {
std::shared_ptr<const Nodes> history() const { return m_history; }

/**
* @brief resets everything, deletes all the clusters, tracks etc etc and resets the Identifier counter
* @brief resets everything, deletes all the clusters, tracks etc etc and resets the IdCoder counter
*/
void clear();
void setEventNo(unsigned int eventNo) { m_eventNo = eventNo;}
Expand All @@ -198,7 +198,7 @@ class Event {
template <class T>
void
addCollectionInternal(const std::unordered_map<IdType, T>& collection,
std::unordered_map<Identifier::SubType, const std::unordered_map<IdType, T>*>& collections);
std::unordered_map<IdCoder::SubType, const std::unordered_map<IdType, T>*>& collections);
/// Unordered map of pointers to unordered map of (concrete) Ecal Clusters
CollectionClusters m_ecalClustersCollection;
/// Unordered map of pointers to unordered map of (concrete) Hcal Clusters
Expand All @@ -220,20 +220,20 @@ class Event {
template <class T>
void Event::addCollectionInternal(
const std::unordered_map<IdType, T>& collection,
std::unordered_map<Identifier::SubType, const std::unordered_map<IdType, T>*>& collections) {
std::unordered_map<IdCoder::SubType, const std::unordered_map<IdType, T>*>& collections) {
IdType firstId = 0;
if (collection.size() == 0) return;
for (const auto& it : collection) {
if (!firstId) {
firstId = it.first;
if (hasCollection(firstId)) throw "Collection already exists";
}
if (Identifier::typeAndSubtype(it.first) != Identifier::typeAndSubtype(firstId)) {
std::cout << Identifier::pretty(it.first) << " : " << Identifier::pretty(firstId) << std::endl;
if (IdCoder::typeAndSubtype(it.first) != IdCoder::typeAndSubtype(firstId)) {
std::cout << IdCoder::pretty(it.first) << " : " << IdCoder::pretty(firstId) << std::endl;
throw "more than one typeandSubtype found in collection";
}
}
collections.emplace(Identifier::subtype(firstId), &collection);
collections.emplace(IdCoder::subtype(firstId), &collection);
}

template <class T>
Expand Down
12 changes: 6 additions & 6 deletions papas/datatypes/HistoryHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define HistoryHelper_h

#include "papas/datatypes/DefinitionsCollections.h"
#include "papas/datatypes/Identifier.h"
#include "papas/datatypes/IdCoder.h"
#include "papas/datatypes/Event.h"
#include "papas/graphtools/DirectedAcyclicGraph.h"

Expand All @@ -21,7 +21,7 @@ namespace papas {
//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'
auto fids = hhelper.filteredIds(ids, Identifier::kEcalCluster, 'm');
auto fids = hhelper.filteredIds(ids, IdCoder::kEcalCluster, 'm');
...
@endcode
*/
Expand All @@ -33,12 +33,12 @@ class HistoryHelper {
HistoryHelper(const Event& event);
/**
* @brief Finds all ids which have a history link with the input id
* @param[in] id Identifier for which we want to find connected items
* @param[in] id IdCoder for which we want to find connected items
* @param[in] direction whether to search parents, children or both
*/
Ids linkedIds(IdType id, DAG::enumVisitType direction = DAG::enumVisitType::UNDIRECTED) const;
/**
* @brief Finds all ids which have a history link with the input id and have specified typeAndSubtype * @param[in] id Identifier for which we want to find connected items
* @brief Finds all ids which have a history link with the input id and have specified typeAndSubtype * @param[in] id IdCoder for which we want to find connected items
* @param[in] typeAndSubType The identifier type and subtype for which we are searching eg "pr"
for a reconstructed particle, should be a string of length 2
* @param[in] direction whether to search parents, children or both
Expand All @@ -49,10 +49,10 @@ class HistoryHelper {
* @brief Filters a vector of ids to find a subset which have the required type and subtype
* for example could be used to identify all ids which are merged Ecal clusters.
* @param[in] ids vector of identifiers that is to be filtered
* @param[in] type Itemtype for which we are filtering eg Identifier::kEcalCluster
* @param[in] type Itemtype for which we are filtering eg IdCoder::kEcalCluster
* @param[in] subtype Subtype for the filtered items eg 'm' for merged
*/
Ids filteredIds(Ids ids, const Identifier::ItemType type, const Identifier::SubType subtype) const;
Ids filteredIds(Ids ids, const IdCoder::ItemType type, const IdCoder::SubType subtype) const;
/**
* @brief Filters a vector of ids to find a subset which have the required typeAndSubtype
* for example could be used to identify all ids which are merged Ecal clusters.
Expand Down
Loading

0 comments on commit 16b8d23

Please sign in to comment.