Skip to content

Commit

Permalink
tidying and removing use of unique for identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Alice committed Mar 21, 2017
1 parent 16b8d23 commit 371eba1
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 92 deletions.
4 changes: 2 additions & 2 deletions papas/datatypes/Cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Cluster {
double energy() const { return m_energy; } ///< Energy
double eta() const { return m_p3.Eta(); } ///< Pseudo-rapidity (-ln(tan self._tlv.Theta()/2))
double theta() const { return M_PI / 2. - m_p3.Theta(); } ///< Angle w/r to transverse plane
IdType id() const { return m_uniqueId; } ///< Unique identifier
IdType id() const { return m_id; } ///< Unique identifier
const TVector3& position() const { return m_p3; } ///< position (x, y, z)
void setEnergy(double energy); ///< Set cluster energy
void setSize(double value); ///< Set cluster size
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 IdCoder for Cluster
IdType m_id; ///< 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
47 changes: 23 additions & 24 deletions papas/datatypes/IdCoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
namespace papas {

/**
@brief An IdCoder is a uniqueid that contains encoded information about an element
@brief An Identifier is a long long that contains encoded information about an element
IdCoders are used to uniquely identify all clusters, tracks, blocks etc in PAPAS
Identifiers are used to uniquely identify all clusters, tracks, blocks etc in PAPAS
They are also used in Nodes which store the history (linkages) between items.
Given an identifier, we can determine the type of an object, for example an ecal_cluster.
Expand All @@ -23,13 +23,13 @@ namespace papas {
from left: bits 64 to 61 = PFOBJECTTYPE enumeration eg ECAL, HCAL, PARTICLE (max value = 7)
bits 60 to 53 = subtype - a single char eg 'g'
bits 52 to 20 = encoded float value eg energy
bits 21 to 1 = unique id (max value = 2097152 -1)
bits 21 to 1 = index (max value = 2097152 -1)
Note that sorting on id will result in sorting by:
type
subtype
value (small to large)
uniqueid
index
reverses sorting will result in items sorted into groups of type and subtype with largest values first in
each type and subtype group.
Expand All @@ -49,17 +49,17 @@ class IdCoder {
enum ItemType { kNone = 0, kEcalCluster = 1, kHcalCluster, kTrack, kParticle, kBlock };
typedef char SubType;
/** Makes new identifier.
@param[in] index to collection in which object will be stored
@param[in] type is an enum IdCoder::ItemType to say whether this id is for a cluster, particle etc
@param[in] subtype is a single letter subtype code eg 'm' for merged
@param[in] value: a float representing energy or momentum etc
@param[in] uniqueid: not used in normal use
@return identifier
*/
static IdType makeId(unsigned int uniqueid, ItemType type, char subtype = 'u', float value = 0.0);
static IdType makeId(unsigned int index, ItemType type, char subtype = 'u', float value = 0.0);

/** returns the item type of the the identifier
/** returns the item type of the identifier
This is one of: None = 0, kEcalCluster = 1, kHcalCluster, kTrack, kParticle, kBlock
@param[in] id: the unique identifier
@param[in] id: the identifier
@return an enum IdCoder::ItemType
*/
static ItemType itemType(IdType id); ///< Returns encoded ItemType eg kParticle etc;
Expand All @@ -74,60 +74,59 @@ class IdCoder {
's' simulated (particles)
smeared (tracks ecals hcals)
split (blocks)
@param[in] id: unique identifier
@param[in] id: identifier
@return single letter subtype
*/
static char subtype(IdType id); /// return the one letter subtype

/** returns the float value encoded in the identifier
@param[in] id: unique identifier
@param[in] id: identifier
@return the encoded value
*/
static float value(IdType id); /// return the float value

/** Takes an identifier and returns the index component of it
@param[in] id: unique identifier
@param[in] id: identifier
@return the index
*/
static unsigned int index(IdType id); ///< Returns encoded unique id
static unsigned int index(IdType id); ///< Returns encoded index


/** Takes an identifier and returns the unique counter component of it
@param[in] id: unique identifier
@return the unique counter
*/
/** Takes an identifier and returns a unique id component of it (excludes value information)
@param[in] id: identifier
@return the index */
static unsigned int uniqueId(IdType id); ///< Returns encoded unique id

static char typeLetter(IdType id); ///< One letter short code eg 'e' for ecal, 't' for track, 'x' for unknown
static std::string typeAndSubtype(IdType id); ///< Two letter string of type and subtype eg "em"
static std::string pretty(IdType id); ///< Pretty string Id name eg "es101" for a smeared ecal with uniqueid 101;
static std::string pretty(IdType id); ///< Pretty string Id name eg "es101" for a smeared ecal with index 101;
/** boolean test of whether identifier is from an ecal cluster
@param ident: unique identifier
@param ident: identifier
*/
static bool isEcal(IdType id) { return (IdCoder::itemType(id) == kEcalCluster); }

/** boolean test of whether identifier is from an hcal cluster
@param ident: unique identifier
@param ident: identifier
*/
static bool isHcal(IdType id) { return (IdCoder::itemType(id) == kHcalCluster); }

/** boolean test of whether identifier is from a cluster
@param ident: unique identifier
@param ident: identifier
*/
static bool isCluster(IdType id) { return (IdCoder::isEcal(id) || IdCoder::isHcal(id)); }

/** boolean test of whether identifier is from an track
@param ident: unique identifier
@param ident: identifier
*/
static bool isTrack(IdType id) { return (IdCoder::itemType(id) == kTrack); }

/** boolean test of whether identifier is from a particle
@param ident: unique identifier
@param ident: identifier
*/
static bool isParticle(IdType id) { return (IdCoder::itemType(id) == kParticle); }

/** boolean test of whether identifier is from a block
@param ident: unique identifier
@param ident: identifier
*/
static bool isBlock(IdType id) { return (IdCoder::itemType(id) == kBlock); }

Expand All @@ -139,7 +138,7 @@ class IdCoder {
static ItemType itemType(char s);

/** Uses identifier type to work out what detector layer the item belongs to, may be kNone
@param id: unique identifier
@param id: identifier
@return ItemType enumeration value papas::Layer eg kTracker
*/
static papas::Layer layer(IdType id);
Expand Down
8 changes: 4 additions & 4 deletions papas/datatypes/PFParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PFParticle : public Particle {
@param[in] vertex start vertex (3d point)
@param[in] index index to the collection to which thie particle will belown
@param[in] field Magnetic field
@param[in] subtype IdCoder subtype to be used when creating unique IdCoder eg 'r' for reconstructed
@param[in] subtype subtype to be used when creating identifier eg 'r' for reconstructed
*/
PFParticle(int pdgid, double charge, const TLorentzVector& tlv, unsigned int index, char subtype = 's', const TVector3& vertex = TVector3(0., 0., 0.), double field = 0. );
/** Constructor
Expand All @@ -34,7 +34,7 @@ class PFParticle : public Particle {
@param[in] tlv 4-momentum, px, py, pz, E
@param[in] track The track to use in creating a particle
@param[in] index index to the collection to which thie particle will belown
@param[in] subtype IdCoder subtype to be used when creating unique IdCoder eg 'r' for reconstructed
@param[in] subtype subtype to be used when creating identifier eg 'r' for reconstructed
*/
PFParticle(int pdgid, double charge, const TLorentzVector& tlv, const Track& track, unsigned int index , char subtype = 'r');
/** check id this position exists in particle path
Expand All @@ -48,11 +48,11 @@ class PFParticle : public Particle {
//void setPath(Path::Ptr path) { m_path = path; } ///< Set ponter to path of particle
bool isHelix() const { return m_isHelix; } ///< Helix or straighline
const Path::Ptr path() const { return m_path; } ///< Return pointer to path
IdType id() const { return m_uniqueId; } ///< unique IdCoder for object
IdType id() const { return m_id; } ///< identifier for object
bool isElectroMagnetic() const; ///< Is it electroMagnetic
const TVector3& vertex() const { return m_vertex; }
private:
IdType m_uniqueId; ///< unique IdCoder
IdType m_id; ///< identifier
TVector3 m_vertex; ///< start vertex (3d)
Path::Ptr m_path; ///< pointer to path object
bool m_isHelix; ///< Boolean to say if path is Helix or straightline
Expand Down
8 changes: 4 additions & 4 deletions papas/datatypes/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ class Track {
@param[in] p3 3-momentum of particle
@param[in] charge particle charge
@param[in] path associated path
@param[in] index used to create track unique id, normally the index of the collection to which the track will belong
@param[in] the subtype of the track used in creating the unique id
@param[in] index used to create track identifier, normally the index of the collection to which the track will belong
@param[in] the subtype of the track used in creating the identifer
*/
Track(const TVector3& p3, double charge, const Path::Ptr path, unsigned int index, char subtype = 'u');
double energy() const { return m_p3.Mag(); } ///<energy
double charge() const { return m_charge; }
IdType id() const { return m_uniqueId; } ///<unique identifier
IdType id() const { return m_id; } ///<identifier
const TVector3& p3() const { return m_p3; } /// momentum
const Path::Ptr path() const { return m_path; }
void setEnergy(double energy);
void setSize(double value);
std::string info() const; ///< string representation of track
protected:
IdType m_uniqueId; ///< Unique identifier of track
IdType m_id; ///< Identifier of track
TVector3 m_p3; ///< momentum in 3D space (px, py, pz)
double m_charge; ///< Charge of associated particle
const Path::Ptr m_path; ///< pointer to path (not owned by track)
Expand Down
20 changes: 10 additions & 10 deletions papas/datatypes/src/Cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ namespace papas {
double Cluster::s_maxEnergy = 0;

Cluster::Cluster(double energy, const TVector3& position, double size_m, unsigned int index, IdCoder::ItemType idtype, char subtype)
: m_uniqueId(IdCoder::makeId(index, idtype, subtype, fmax(0, energy))), m_p3(position), m_subClusters() {
: m_id(IdCoder::makeId(index, idtype, subtype, fmax(0, energy))), m_p3(position), m_subClusters() {
setSize(size_m);
setEnergy(energy);
m_subClusters.push_back(this);
}

Cluster::Cluster(const Cluster& c, unsigned int index, IdCoder::ItemType type, char subtype, float val)
: m_uniqueId(IdCoder::makeId(index, type, subtype, val)),
: m_id(IdCoder::makeId(index, type, subtype, val)),
m_size(c.m_size),
m_angularSize(c.m_angularSize),
m_pt(c.m_pt),
Expand All @@ -33,7 +33,7 @@ Cluster::Cluster(const Cluster& c, unsigned int index, IdCoder::ItemType type, c
}

Cluster::Cluster(Cluster&& c)
: m_uniqueId(c.id()),
: m_id(c.id()),
m_size(c.m_size),
m_angularSize(c.m_angularSize),
m_pt(c.m_pt),
Expand Down Expand Up @@ -78,7 +78,7 @@ void Cluster::setEnergy(double energy) {
}

Cluster& Cluster::operator+=(const Cluster& rhs) {
if (IdCoder::itemType(m_uniqueId) != IdCoder::itemType(rhs.id())) {
if (IdCoder::itemType(m_id) != IdCoder::itemType(rhs.id())) {
throw "can only add a cluster from the same layer";
}
m_p3 = m_p3 * m_energy + rhs.position() * rhs.energy();
Expand Down Expand Up @@ -112,7 +112,7 @@ Cluster::Cluster( Cluster && c) :
m_size(c.m_size),
m_angularSize(c.m_angularSize),
m_pt(c.m_pt),
m_uniqueId(c.m_uniqueId),
m_id(c.m_id),
m_energy(c.m_energy),
m_subClusters(std::move(c.m_subClusters))
Expand All @@ -127,7 +127,7 @@ std::cout<< "Move Cluster" <<std::endl;
m_p3=c.m_p3;
m_size=c.m_size;
m_pt=c.m_pt;
m_uniqueId=c.m_uniqueId;
m_id=c.m_id;
std::cout<< "move assign cluster" <<std::endl;
return *this;
};*/
Expand All @@ -137,19 +137,19 @@ m_energy=c.m_energy;
m_p3=c.m_p3;
m_size=c.m_size;
m_pt=c.m_pt;
m_uniqueId=c.m_uniqueId;
m_id=c.m_id;
std::cout<< "copy cluster=" <<std::endl;
return *this;
};
Cluster::Cluster(const Cluster&) {
PDebug::write("copy cluster {}" , IdCoder::pretty(m_uniqueId));
PDebug::write("copy cluster {}" , IdCoder::pretty(m_id));
std::cout<< "copy cluster" ;
} ;*/

/*Cluster::~Cluster() {
PDebug::write("delete cluster {}" , IdCoder::pretty(m_uniqueId));
std::cout<< " delete cluster " << IdCoder::pretty(m_uniqueId) ;
PDebug::write("delete cluster {}" , IdCoder::pretty(m_id));
std::cout<< " delete cluster " << IdCoder::pretty(m_id) ;
} ;*/

} // end namespace papas
4 changes: 2 additions & 2 deletions papas/datatypes/src/IdCoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <bitset>

//
// Encode information into a unique identifier
// Encode information into an identifier
//
// accessible intro to use of bitwise operations can be found here
// http://stackoverflow.com/questions/6556961/use-of-the-bitwise-operators-to-pack-multiple-values-in-one-int
Expand All @@ -22,7 +22,7 @@ IdType IdCoder::makeId(unsigned int index, ItemType type, char subt, float val)
throw "Id must have a valid type";
}

if (index >= pow(2, m_bitshift) - 1) throw "IdCoder unique id is too big: too many identifiers";
if (index >= pow(2, m_bitshift) - 1) throw "IdCoder: index is too big: too many identifiers";

// Shift all the parts and join together
// NB uint64_t is needed to make sure the shift is carried out over 64 bits, otherwise
Expand Down
2 changes: 1 addition & 1 deletion papas/datatypes/src/PFParticle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace papas {

PFParticle::PFParticle(int pdgid, double charge, const TLorentzVector& tlv, unsigned int index, char subtype, const TVector3& vertex, double field)
: Particle(pdgid, charge, tlv),
m_uniqueId(IdCoder::makeId(index, IdCoder::kParticle, subtype, tlv.E())),
m_id(IdCoder::makeId(index, IdCoder::kParticle, subtype, tlv.E())),
m_vertex(vertex),
m_isHelix(fabs(charge) > 0.5) {

Expand Down
2 changes: 1 addition & 1 deletion papas/datatypes/src/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace papas {

Track::Track(const TVector3& p3, double charge,const Path::Ptr path, unsigned int index, char subtype)
: m_uniqueId(IdCoder::makeId(index, IdCoder::ItemType::kTrack, subtype, p3.Mag())),
: m_id(IdCoder::makeId(index, IdCoder::ItemType::kTrack, subtype, p3.Mag())),
m_p3(p3),
m_charge(charge),
m_path(path) {}
Expand Down
2 changes: 1 addition & 1 deletion papas/graphtools/DirectedAcyclicGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* For example if the nodes were either tracks or clusters then
* we need:- stl::unordered_map<id,cluster>
* stl::unordered_map<id,track>
* And the user must generate a unique id for each cluster and track
* And the user must generate an identifier for each cluster and track
* The identifier class provides an example of the encoding and decoding of node information
*
* (ii) Polymorphic classes
Expand Down
4 changes: 2 additions & 2 deletions papas/graphtools/EventRuler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Event;
/**
* @brief distance between id1 and id2
*
* @param[in] id1 : element uniqueid enerated from Id class. Must exist in Event
* @param[in] id2 : element2 uniqueid generated from Id class. Must exist in Event
* @param[in] id1 : element identifier enerated from Id class. Must exist in Event
* @param[in] id2 : element2 identifie generated from Id class. Must exist in Event
* @return Distance (ie isLinked : boolean T/F and distance value)
*/
Distance distance(IdType id1, IdType id2) const;
Expand Down
6 changes: 3 additions & 3 deletions papas/graphtools/GraphBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace papas {
* Each element will end up in one (and only one) block.
* Blocks retain information of the elements and edges including the distances between elements.
* The blocks can be used for future particle reconstruction.
* The ids of all elements must be unique and are expected to come from the Id class.
* The ids of all elements must be unique and are expected to come from the IdCoder class.
Usage example:
Expand All @@ -34,7 +34,7 @@ class GraphBuilder {
public:
/** Constructor
* @param[in] ids : vector of unique identifiers eg of tracks, clusters etc
* @param[in] ids : vector of identifiers eg of tracks, clusters etc
* @param[in] edges : unordered_map of edges which contains all edges between the ids (and maybe more),
* an edge records the distance and links between two ids. The edges will be moved into the
* resulting blocks and become owned by them.
Expand All @@ -49,7 +49,7 @@ class GraphBuilder {
Edges m_edges; ///< must contain all edges corresponding to all pairs of ids for ids in m_elementIda
std::vector<Ids> m_subGraphs; ///< vector of subgraphs made by graphbuilder
private:
Ids m_elementIds; ///<uniqueids to be grouped into subgraphs
Ids m_elementIds; ///<identifiers to be grouped into subgraphs
Nodes m_localNodes; ///<local nodes used in building subgraphs
};
} // end namespace papas
Expand Down
2 changes: 1 addition & 1 deletion papas/reconstruction/BlockBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace papas {
class BlockBuilder : public GraphBuilder {
public:
/** Constructor
* @param[in] ids : list of unique identifiers eg of tracks, clusters etc
* @param[in] ids : list of identifiers eg of tracks, clusters etc
* @param[in] edges : unordered_map of edges which contains all edges between the ids (and maybe more)
* an edge records the distance and links between two ids
* @param[inout] history : external collection of Nodes to which parent child relations can be added
Expand Down
Loading

0 comments on commit 371eba1

Please sign in to comment.