Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DataFormats/Detectors/ITSMFT/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ O2_SETUP(NAME ${MODULE_NAME})

set(SRCS
src/Cluster.cxx
src/ClusterPattern.cxx
src/ClusterTopology.cxx
src/TopologyDictionary.cxx
)

Set(HEADERS
include/${MODULE_NAME}/Cluster.h
include/${MODULE_NAME}/ClusterPattern.h
include/${MODULE_NAME}/ClusterTopology.h
include/${MODULE_NAME}/TopologyDictionary.h
)
Expand All @@ -19,5 +21,3 @@ Set(LIBRARY_NAME ${MODULE_NAME})
set(BUCKET_NAME data_format_itsmft_bucket)

O2_GENERATE_LIBRARY()


Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// \file ClusterTopology.h
/// \brief Definition of the ClusterTopology class.
///
/// \author Luca Barioglio, University and INFN of Torino
///
/// Short ClusterPattern descritpion
///
/// This class contains the information of the pattern of a cluster of pixels (bitmask), together with the number of
/// rows and columns of the vinding box.
///

#ifndef ALICEO2_ITSMFT_CLUSTERPATTERN_H
#define ALICEO2_ITSMFT_CLUSTERPATTERN_H
#include <Rtypes.h>
#include <array>
#include <iosfwd>
#include "DataFormatsITSMFT/Cluster.h"

namespace o2
{
namespace ITSMFT
{
class ClusterTopology;
class TopologyDictionary;
class BuildTopologyDictionary;

class ClusterPattern
{
public:
/// Default constructor
ClusterPattern();
/// Standard constructor
ClusterPattern(int nRow, int nCol, const unsigned char patt[Cluster::kMaxPatternBytes]);
/// Maximum number of bytes for the cluster puttern + 2 bytes respectively for the number of rows and columns of the bounding box
static constexpr int kExtendedPatternBytes = Cluster::kMaxPatternBytes + 2;
/// Returns the pattern
std::array<unsigned char, kExtendedPatternBytes> getPattern() const { return mBitmap; }
/// Returns a specific byte of the pattern
unsigned char getByte(int n) const;
/// Returns the number of rows
int getRowSpan() const { return (int)mBitmap[0]; }
/// Returns the number of columns
int getColumnSpan() const { return (int)mBitmap[1]; }
/// Returns the number of bytes used for the pattern
int getUsedBytes() const;
/// Prints the pattern
friend std::ostream& operator<<(std::ostream& os, const ClusterPattern& top);
/// Sets the pattern
void setPattern(int nRow, int nCol, const unsigned char patt[Cluster::kMaxPatternBytes]);
/// Sets the whole bitmask: the number of rows, the number of columns and the pattern
void setPattern(const unsigned char bitmask[kExtendedPatternBytes]);

friend ClusterTopology;
friend TopologyDictionary;
friend BuildTopologyDictionary;

private:
/// Pattern:
///
/// - 1st byte: number of rows
/// - 2nd byte: number of columns
/// - remainig bytes : pixels of the cluster, where 1 is a fired pixel and 0
/// is a non-fired pixel. The number of bytes used for the pixels depends on
/// the size of the bounding box

std::array<unsigned char, kExtendedPatternBytes> mBitmap; ///< Cluster pattern: 1 is a fired pixel and 0 is a non-fired pixel

ClassDefNV(ClusterPattern, 1);
};
}
}
#endif /* ALICEO2_ITS_CLUSTERPATTERN_H */
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@

#ifndef ALICEO2_ITSMFT_CLUSTERTOPOLOGY_H
#define ALICEO2_ITSMFT_CLUSTERTOPOLOGY_H
#include <Rtypes.h>
#include <array>
#include <iosfwd>
#include <string>
#include "DataFormatsITSMFT/Cluster.h"
#include "DataFormatsITSMFT/ClusterPattern.h"

namespace o2
{
Expand All @@ -40,46 +36,38 @@ class ClusterTopology
/// Standard constructor
ClusterTopology(int nRow, int nCol, const unsigned char patt[Cluster::kMaxPatternBytes]);

/// Returns a specific byte of the pattern
unsigned char getByte(int n) const { return mPattern.getByte(n); }
/// Returns the pattern
const std::array<unsigned char, Cluster::kMaxPatternBytes + 2>& getPattern() const { return mPattern; }
std::array<unsigned char, ClusterPattern::kExtendedPatternBytes> getPattern() const { return mPattern.getPattern(); }
/// Returns the number of rows
int getRowSpan() const { return (int)mPattern[0]; }
int getRowSpan() const { return mPattern.getRowSpan(); }
/// Returns the number of columns
int getColumnSpan() const { return (int)mPattern[1]; }
int getColumnSpan() const { return mPattern.getColumnSpan(); }
/// Returns the number of used bytes
int getUsedBytes() const { return mNbytes; }
int getUsedBytes() const { return mPattern.getUsedBytes(); }
/// Returns the hashcode
unsigned long getHash() const { return mHash; }
/// Prints the topology
friend std::ostream& operator<<(std::ostream& os, const ClusterTopology& top);
/// MurMur2 hash fucntion
static unsigned int hashFunction(const void* key, int len);
/// Compute the complete hash as defined for mHash
static unsigned long getCompleteHash(int nRow, int nCol, const unsigned char patt[Cluster::kMaxPatternBytes],
int nBytesUsed);
static unsigned long getCompleteHash(int nRow, int nCol, const unsigned char patt[Cluster::kMaxPatternBytes]);
static unsigned long getCompleteHash(const ClusterTopology& topology);
/// Sets the pattern
void setPattern(int nRow, int nCol, const unsigned char patt[Cluster::kMaxPatternBytes]);

private:
/// Pattern:
///
/// - 1st byte: number of rows
/// - 2nd byte: number of columns
/// - remainig bytes : pixels of the cluster, where 1 is a fired pixel and 0
/// is a non-fired pixel. The number of pixels used for the pixel depends on
/// the size of the bounding box
std::array<unsigned char, Cluster::kMaxPatternBytes + 2>
mPattern; ///< Cluster pattern: 1 is a fired pixel and 0 is a non-fired pixel
int mNbytes; ///< Number of bytes that are effectively used in mPattern
ClusterPattern mPattern; ///< Pattern of pixels
/// Hashcode computed from the pattern
///
/// The first four bytes are computed with MurMur2 hash-function. The remaining
/// four bytes are the first 32 pixels of the pattern. If the number of pixles
/// is less than 32, the remaining bits are set to 0.
unsigned long mHash;

ClassDefNV(ClusterTopology, 1);
ClassDefNV(ClusterTopology, 2);
};
} // namespace ITSMFT
} // namespace o2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
///
/// Short TopologyDictionary descritpion
///
/// The entries of the dictionaries are the cluster topologies, with all the indormation
/// The entries of the dictionaries are the cluster topologies, with all the information
/// which is common to the clusters with the same topology:
/// - number of rows
/// - number of columns
/// - pixel bitmask
/// - position of the Centre Of Gravity (COG) wrt the bottom left corner pixel of the bounding box
/// - error associated to the position of the hit point
/// Rare topologies, i.e. with a frequency below a threshold defined a priori, have not their own entries
/// in the dictionaries, but are grouped together with topologies with similar dimensions.
///
/// For the groups of rare topollogies a dummy bitmask is used.

#ifndef ALICEO2_ITSMFT_TOPOLOGYDICTIONARY_H
#define ALICEO2_ITSMFT_TOPOLOGYDICTIONARY_H
#include <Rtypes.h>
#include "DataFormatsITSMFT/ClusterPattern.h"
#include <fstream>
#include <iosfwd>
#include <string>
#include <unordered_map>
#include <vector>
Expand All @@ -44,42 +44,64 @@ class TopologyFastSimulation;

/// Structure containing the most relevant pieces of information of a topology
struct GroupStruct {
unsigned long mHash; ///< Hashcode
float mErrX; ///< Error associated to the hit point in the x direction.
float mErrZ; ///< Error associated to the hit point in the z direction.
float mXCOG; ///< x position of te COG wrt the boottom left corner of the bounding box
float mZCOG; ///< z position of te COG wrt the boottom left corner of the bounding box
int mNpixels; ///< Number of fired pixels
double mFrequency; ///< Frequency of the topology
unsigned long mHash; ///< Hashcode
float mErrX; ///< Error associated to the hit point in the x direction.
float mErrZ; ///< Error associated to the hit point in the z direction.
float mXCOG; ///< x position of te COG wrt the boottom left corner of the bounding box
float mZCOG; ///< z position of te COG wrt the boottom left corner of the bounding box
int mNpixels; ///< Number of fired pixels
ClusterPattern mPattern; ///< Bitmask of pixels. For groups the biggest bounding box for the group is taken, with all
///the bits set to 1.
double mFrequency; ///< Frequency of the topology
};

class TopologyDictionary
{
public:
/// constexpr for the definition of the groups of rare topologies
static constexpr int NumberOfRowClasses = 7; ///< Number of row classes for the groups of rare topologies
static constexpr int NumberOfColClasses = 7; ///< Number of column classes for the groups of rare topologies
static constexpr int RowClassSpan = 5; ///< Row span of the classes of rare topologies
static constexpr int ColClassSpan = 5; ///< Column span of the classes of rare topologies
static constexpr int MaxRowSpan = 32; ///< Maximum row span
static constexpr int MaxColSpan = 32; ///< Maximum column span
/// Default constructor
TopologyDictionary();
/// constexpr for the definition of the groups of rare topologies.
/// The attritbution of the group ID is stringly dependent on the following parameters: it must be a power of 2.
static constexpr int RowClassSpan = 4; ///< Row span of the classes of rare topologies
static constexpr int ColClassSpan = 4; ///< Column span of the classes of rare topologies
static constexpr int MinimumClassArea = RowClassSpan * ColClassSpan; ///< Area of the smallest class of rare topologies (used as reference)
static constexpr int MaxNumberOfClasses = Cluster::kMaxPatternBits / MinimumClassArea; ///< Maximum number of row/column classes for the groups of rare topologies
static constexpr int NumberOfRareGroups = MaxNumberOfClasses * MaxNumberOfClasses; ///< Number of entries corresponding to groups of rare topologies (those whos matrix exceed the max number of bytes are empty).
/// Prints the dictionary
friend std::ostream& operator<<(std::ostream& os, const TopologyDictionary& dictionary);
/// Prints the dictionary in a binary file
void WriteBinaryFile(std::string outputFile);
/// Reads the dictionary from a file
void ReadFile(std::string fileName);
/// Reads the dictionary from a binary file
void ReadBinaryFile(std::string fileName);
/// Returns the x position of the COG for the n_th element
float GetXcog(int n);
/// Returns the error on the x position of the COG for the n_th element
float GetErrX(int n);
/// Returns the z position of the COG for the n_th element
float GetZcog(int n);
/// Returns the error on the z position of the COG for the n_th element
float GetErrZ(int n);
/// Returns the hash of the n_th element
unsigned long GetHash(int n);
/// Returns the number of fired pixels of the n_th element
int GetNpixels(int n);
/// Returns the pattern of the topology
ClusterPattern GetPattern(int n);
/// Returns the frequency of the n_th element;
double GetFrequency(int n);
/// Returns the number of elements in the dicionary;
int GetSize() { return (int)mVectorOfGroupIDs.size(); }

friend BuildTopologyDictionary;
friend LookUp;
friend TopologyFastSimulation;

private:
std::unordered_map<unsigned long, int> mFinalMap; ///< Map of pair <hash, position in mVectorOfGroupIDs>
int mSmallTopologiesLUT[8 * 255]; ///< Look-Up Table for the topologies with 1-byte linearised matrix
std::vector<GroupStruct> mVectorOfGroupIDs; ///< Vector of topologies and groups

ClassDefNV(TopologyDictionary, 1);
ClassDefNV(TopologyDictionary, 2);
};
} // namespace ITSMFT
} // namespace o2
Expand Down
101 changes: 101 additions & 0 deletions DataFormats/Detectors/ITSMFT/common/src/ClusterPattern.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// \file ClusterTopology.cxx
/// \brief Implementation of the ClusterPattern class.
///
/// \author Luca Barioglio, University and INFN of Torino
#include "DataFormatsITSMFT/ClusterTopology.h"
#include <iostream>

ClassImp(o2::ITSMFT::ClusterPattern)

namespace o2
{
namespace ITSMFT
{
ClusterPattern::ClusterPattern() : mBitmap{ 0 } {}

ClusterPattern::ClusterPattern(int nRow, int nCol, const unsigned char patt[Cluster::kMaxPatternBytes])
{
setPattern(nRow, nCol, patt);
}

unsigned char ClusterPattern::getByte(int n) const
{
if (n < 0 || n > Cluster::kMaxPatternBytes + 1) {
std::cout << "Invalid element of the pattern" << std::endl;
return -1;
} else {
return mBitmap[n];
}
}

int ClusterPattern::getUsedBytes() const
{
int nBits = (int)mBitmap[0] * (int)mBitmap[1];
int nBytes = nBits / 8;
if (nBits % 8 != 0)
nBytes++;
return nBytes;
}

void ClusterPattern::setPattern(int nRow, int nCol, const unsigned char patt[Cluster::kMaxPatternBytes])
{
mBitmap[0] = (unsigned char)nRow;
mBitmap[1] = (unsigned char)nCol;
int nBytes = nRow * nCol / 8;
if (((nRow * nCol) % 8) != 0)
nBytes++;
memcpy(&mBitmap[2], patt, nBytes);
}

void ClusterPattern::setPattern(const unsigned char patt[ClusterPattern::kExtendedPatternBytes])
{
memcpy(&mBitmap[0], patt, ClusterPattern::kExtendedPatternBytes);
}

std::ostream& operator<<(std::ostream& os, const ClusterPattern& pattern)
{
os << "rowSpan: " << pattern.getRowSpan() << " columnSpan: " << pattern.getColumnSpan()
<< " #bytes: " << pattern.getUsedBytes() << std::endl;
unsigned char tempChar = 0;
int s = 0;
int ic = 0;
for (unsigned int i = 2; i < pattern.getUsedBytes() + 2; i++) {
tempChar = pattern.mBitmap[i];
s = 128; // 0b10000000
while (s > 0) {
if (ic % pattern.getColumnSpan() == 0) {
os << "|";
}
ic++;
if ((tempChar & s) != 0) {
os << '+';
} else {
os << ' ';
}
s /= 2;
if (ic % pattern.getColumnSpan() == 0) {
os << "|" << std::endl;
}
if (ic == (pattern.getRowSpan() * pattern.getColumnSpan())) {
break;
}
}
if (ic == (pattern.getRowSpan() * pattern.getColumnSpan())) {
break;
}
}
os << std::endl;
return os;
}
}
}
Loading