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
40 changes: 33 additions & 7 deletions DataFormats/SiStripCluster/interface/SiStripCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class SiStripCluster {
typedef std::vector<SiStripDigi>::const_iterator SiStripDigiIter;
typedef std::pair<SiStripDigiIter, SiStripDigiIter> SiStripDigiRange;

static const uint16_t stripIndexMask = 0x7FFF; // The first strip index is in the low 15 bits of firstStrip_
static const uint16_t stripIndexMask = 0x3FFF; // The first strip index is in the low 15 bits of firstStrip_
static const uint16_t mergedValueMask = 0x8000; // The merged state is given by the high bit of firstStrip_
static const uint16_t approximateMask = 0x4000; // The approximate state is the high-1 bit of firstStrip_

/** Construct from a range of digis that form a cluster and from
* a DetID. The range is assumed to be non-empty.
Expand All @@ -26,16 +27,21 @@ class SiStripCluster {
explicit SiStripCluster(const SiStripDigiRange& range);

SiStripCluster(uint16_t firstStrip, std::vector<uint8_t>&& data)
: amplitudes_(std::move(data)), firstStrip_(firstStrip) {}
: amplitudes_(std::move(data)), firstStrip_(firstStrip) {
initQB();
}

template <typename Iter>
SiStripCluster(const uint16_t& firstStrip, Iter begin, Iter end) : amplitudes_(begin, end), firstStrip_(firstStrip) {}
SiStripCluster(const uint16_t& firstStrip, Iter begin, Iter end) : amplitudes_(begin, end), firstStrip_(firstStrip) {
initQB();
}

template <typename Iter>
SiStripCluster(const uint16_t& firstStrip, Iter begin, Iter end, bool merged)
: amplitudes_(begin, end), firstStrip_(firstStrip) {
if (merged)
firstStrip_ |= mergedValueMask; // if this is a candidate merged cluster
initQB();
}

SiStripCluster(const SiStripApproximateCluster cluster, const uint16_t maxStrips);
Expand All @@ -44,6 +50,7 @@ class SiStripCluster {
template <typename Iter>
void extend(Iter begin, Iter end) {
amplitudes_.insert(amplitudes_.end(), begin, end);
initQB();
}

/** The amplitudes of the strips forming the cluster.
Expand Down Expand Up @@ -75,16 +82,16 @@ class SiStripCluster {
/** The barycenter of the cluster, not corrected for Lorentz shift;
* should not be used as position estimate for tracking.
*/
float barycenter() const;
float barycenter() const { return barycenter_; }

/** total charge
*
*/
int charge() const;
int charge() const { return charge_; }

bool filter() const;
bool filter() const { return filter_; }

bool isFromApprox() const;
bool isFromApprox() const { return (firstStrip_ & approximateMask) != 0; }

/** Test (set) the merged status of the cluster
*
Expand All @@ -95,6 +102,8 @@ class SiStripCluster {
float getSplitClusterError() const { return error_x; }
void setSplitClusterError(float errx) { error_x = errx; }

void initQB();

private:
std::vector<uint8_t> amplitudes_;

Expand Down Expand Up @@ -134,4 +143,21 @@ inline bool operator<(const SiStripCluster& cluster, const uint16_t& firstStrip)
inline bool operator<(const uint16_t& firstStrip, const SiStripCluster& cluster) {
return firstStrip < cluster.firstStrip();
}

inline void SiStripCluster::initQB() {
int sumx = 0;
int suma = 0;
auto asize = size();
for (auto i = 0U; i < asize; ++i) {
sumx += i * amplitudes_[i];
suma += amplitudes_[i];
}
charge_ = suma;

// strip centers are offset by half pitch w.r.t. strip numbers,
// so one has to add 0.5 to get the correct barycenter position.
// Need to mask off the high bit of firstStrip_, which contains the merged status.
barycenter_ = float((firstStrip_ & stripIndexMask)) + float(sumx) / float(suma) + 0.5f;
}

#endif // DATAFORMATS_SISTRIPCLUSTER_H
33 changes: 2 additions & 31 deletions DataFormats/SiStripCluster/src/SiStripCluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SiStripCluster::SiStripCluster(const SiStripDigiRange& range) : firstStrip_(rang
v.push_back(i->adc());
}
amplitudes_ = v;
initQB();
}

SiStripCluster::SiStripCluster(const SiStripApproximateCluster cluster, const uint16_t maxStrips) : error_x(-99999.9) {
Expand All @@ -36,35 +37,5 @@ SiStripCluster::SiStripCluster(const SiStripApproximateCluster cluster, const ui
if UNLIKELY (firstStrip_ + cluster.width() > maxStrips) {
firstStrip_ = maxStrips - cluster.width();
}
firstStrip_ |= approximateMask;
}

int SiStripCluster::charge() const {
if (barycenter_ > 0)
return charge_;
return std::accumulate(begin(), end(), int(0));
}

float SiStripCluster::barycenter() const {
if (barycenter_ > 0)
return barycenter_;

int sumx = 0;
int suma = 0;
auto asize = size();
for (auto i = 0U; i < asize; ++i) {
sumx += i * amplitudes_[i];
suma += amplitudes_[i];
}

// strip centers are offcet by half pitch w.r.t. strip numbers,
// so one has to add 0.5 to get the correct barycenter position.
// Need to mask off the high bit of firstStrip_, which contains the merged status.
return float((firstStrip_ & stripIndexMask)) + float(sumx) / float(suma) + 0.5f;
}
bool SiStripCluster::filter() const {
if (barycenter_ > 0)
return filter_;
return false;
}

bool SiStripCluster::isFromApprox() const { return (barycenter_ > 0); }
9 changes: 8 additions & 1 deletion DataFormats/SiStripCluster/src/classes_def.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<lcgdict>

<class name="SiStripCluster" ClassVersion="13">
<class name="SiStripCluster" ClassVersion="14">
<version ClassVersion="14" checksum="1374720584"/>
<version ClassVersion="13" checksum="1374720584"/>
<version ClassVersion="12" checksum="2984011925"/>
<version ClassVersion="11" checksum="3702468681"/>
<version ClassVersion="10" checksum="3791198690"/>
<field name="error_x" transient="true"/>
</class>
<ioread sourceClass="SiStripCluster" version="[10-11]" targetClass="SiStripCluster" source="std::vector<uint8_t> amplitudes_; uint16_t firstStrip_;" target="amplitudes_,firstStrip_,barycenter_,charge_" >
<![CDATA[amplitudes_ = onfile.amplitudes_; firstStrip_ = onfile.firstStrip_; newObj->initQB();]]>
</ioread>
<ioread sourceClass="SiStripCluster" version="[12-13]" targetClass="SiStripCluster" source="std::vector<uint8_t> amplitudes_; uint16_t firstStrip_; float barycenter_; int charge_;" target="amplitudes_,firstStrip_,barycenter_,charge_" >
<![CDATA[amplitudes_ = onfile.amplitudes_; firstStrip_ = onfile.firstStrip_; barycenter_ = onfile.barycenter_; charge_ = onfile.charge_; if (onfile.barycenter_ == 0) { newObj->initQB(); } else { firstStrip_ |= SiStripCluster::approximateMask; }]]>
</ioread>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pcanal Could you check and comment if there would any way to simplify the read rules above?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks already minimal. The only minor change would be to use:

if (onfile.barycenter_ == 0) { newObj->initQB(); } else { barycenter_ = onfile.barycenter_; charge_ = onfile.charge_; firstStrip_ |= SiStripCluster::approximateMask; }

since initQB already sets charge_ and firstStrip_.

<class name="std::vector<SiStripCluster>"/>

<class name="edmNew::DetSetVector<SiStripCluster>"/>
Expand Down