Skip to content

Commit a4e0816

Browse files
committed
adding changes with v1 to test default rawp and modification with rawp
1 parent 05248a5 commit a4e0816

File tree

10 files changed

+569
-13
lines changed

10 files changed

+569
-13
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#ifndef DataFormats_SiStripCluster_SiStripApproximateClusterCollection_v1_h
2+
#define DataFormats_SiStripCluster_SiStripApproximateClusterCollection_v1_h
3+
4+
#include <vector>
5+
6+
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster_v1.h"
7+
#include <iostream>
8+
#include <numeric>
9+
/**
10+
* This class provides a minimal interface that resembles
11+
* edmNew::DetSetVector, but is crafted such that we are comfortable
12+
* to provide an infinite backwards compatibility guarantee for it
13+
* (like all RAW data). Any modifications need to be made with care.
14+
* Please consult core software group if in doubt.
15+
**/
16+
namespace v1 {
17+
class SiStripApproximateClusterCollection {
18+
public:
19+
// Helper classes to make creation and iteration easier
20+
class Filler {
21+
public:
22+
void push_back(SiStripApproximateCluster_v1 const& cluster) { clusters_.push_back(cluster); }
23+
24+
private:
25+
friend SiStripApproximateClusterCollection;
26+
Filler(std::vector<SiStripApproximateCluster_v1>& clusters) : clusters_(clusters) {}
27+
28+
std::vector<SiStripApproximateCluster_v1>& clusters_;
29+
};
30+
31+
class const_iterator;
32+
class DetSet {
33+
public:
34+
using const_iterator = std::vector<SiStripApproximateCluster_v1>::const_iterator;
35+
36+
unsigned int id() const { return std::accumulate(coll_->detIds_.cbegin(), coll_->detIds_.cbegin()+detIndex_+1, 0); }
37+
38+
void move(unsigned int clusBegin) const { clusBegin_ = clusBegin; }
39+
const_iterator begin() const { return coll_->clusters_.begin() + clusBegin_; }
40+
const_iterator cbegin() const { return begin(); }
41+
const_iterator end() const { return coll_->clusters_.begin() + clusEnd_; }
42+
const_iterator cend() const { return end(); }
43+
44+
private:
45+
friend SiStripApproximateClusterCollection::const_iterator;
46+
DetSet(SiStripApproximateClusterCollection const* coll, unsigned int detIndex)
47+
: coll_(coll),
48+
detIndex_(detIndex),
49+
clusEnd_(coll->clusters_.size())
50+
//clusBegin_(coll_->beginIndices_[detIndex]),
51+
//clusEnd_(detIndex == coll_->beginIndices_.size() - 1 ? coll->clusters_.size()
52+
//: coll_->beginIndices_[detIndex + 1]) {}
53+
{}
54+
55+
SiStripApproximateClusterCollection const* const coll_;
56+
unsigned int const detIndex_;
57+
mutable unsigned int clusBegin_ = 0;
58+
unsigned int const clusEnd_;
59+
};
60+
61+
class const_iterator {
62+
public:
63+
DetSet operator*() const { return DetSet(coll_, index_); }
64+
65+
const_iterator& operator++() {
66+
++index_;
67+
if (index_ == coll_->detIds_.size()) {
68+
*this = const_iterator();
69+
}
70+
return *this;
71+
}
72+
73+
const_iterator operator++(int) {
74+
const_iterator clone = *this;
75+
++(*this);
76+
return clone;
77+
}
78+
79+
bool operator==(const_iterator const& other) const { return coll_ == other.coll_ and index_ == other.index_; }
80+
bool operator!=(const_iterator const& other) const { return not operator==(other); }
81+
82+
private:
83+
friend SiStripApproximateClusterCollection;
84+
// default-constructed object acts as the sentinel
85+
const_iterator() = default;
86+
const_iterator(SiStripApproximateClusterCollection const* coll) : coll_(coll) {}
87+
88+
SiStripApproximateClusterCollection const* coll_ = nullptr;
89+
unsigned int index_ = 0;
90+
};
91+
92+
// Actual public interface
93+
SiStripApproximateClusterCollection() = default;
94+
95+
void reserve(std::size_t dets, std::size_t clusters);
96+
Filler beginDet(unsigned int detId);
97+
98+
const_iterator begin() const { return clusters_.empty() ? end() : const_iterator(this); }
99+
const_iterator cbegin() const { return begin(); }
100+
const_iterator end() const { return const_iterator(); }
101+
const_iterator cend() const { return end(); }
102+
103+
private:
104+
// The detIds_ and beginIndices_ have one element for each Det. An
105+
// element of beginIndices_ points to the first cluster of the Det
106+
// in clusters_.
107+
std::vector<unsigned int> detIds_; // DetId for the Det
108+
std::vector<SiStripApproximateCluster_v1> clusters_;
109+
};
110+
}
111+
#endif
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef DataFormats_SiStripCluster_SiStripApproximateCluster_v1_h
2+
#define DataFormats_SiStripCluster_SiStripApproximateCluster_v1_h
3+
4+
#include "FWCore/Utilities/interface/typedefs.h"
5+
#include "assert.h"
6+
7+
class SiStripCluster;
8+
class SiStripApproximateCluster_v1 {
9+
public:
10+
SiStripApproximateCluster_v1() {}
11+
12+
explicit SiStripApproximateCluster_v1(cms_uint16_t compBarycenter,
13+
cms_uint8_t width,
14+
cms_uint8_t compavgCharge,
15+
bool filter,
16+
bool isSaturated,
17+
bool peakFilter = false
18+
)
19+
: compBarycenter_(compBarycenter),
20+
width_(width),
21+
compavgCharge_(compavgCharge)
22+
{}
23+
24+
explicit SiStripApproximateCluster_v1(const SiStripCluster& cluster,
25+
unsigned int maxNSat,
26+
float hitPredPos,
27+
float& previous_cluster,
28+
unsigned int& module_length,
29+
unsigned int& previous_module_length,
30+
bool peakFilter);
31+
32+
const cms_uint16_t compBarycenter() const {
33+
return compBarycenter_;
34+
}
35+
36+
float barycenter(float previous_barycenter=0,
37+
unsigned int module_length=0, unsigned int previous_module_length=0) const {
38+
float _barycenter;
39+
cms_uint16_t compBarycenter = (compBarycenter_&0x7FFF);
40+
if ( previous_barycenter == -999 )
41+
_barycenter = compBarycenter * maxBarycenter_/maxRange_;
42+
else {
43+
_barycenter = ((compBarycenter * maxBarycenter_/maxRange_) - (module_length-previous_module_length)) + previous_barycenter;
44+
}
45+
assert(_barycenter <= maxBarycenter_ && "Returning barycenter > maxBarycenter");
46+
return _barycenter; }
47+
cms_uint8_t width() const {return width_; }
48+
float avgCharge() const {
49+
cms_uint8_t compavgCharge = (compavgCharge_ & 0x3F);
50+
float avgCharge_ = compavgCharge * maxavgCharge_/maxavgChargeRange_ ;
51+
assert(avgCharge_ <= maxavgCharge_ && "Returning avgCharge > maxavgCharge");
52+
return avgCharge_; }
53+
bool filter() const { return (compavgCharge_& (1<<kfilterMask)); }
54+
bool isSaturated() const { return (compavgCharge_& (1<<kSaturatedMask)); }
55+
bool peakFilter() const { return (compBarycenter_ & (1<<kpeakFilterMask)); }
56+
57+
private:
58+
cms_uint16_t compBarycenter_ = 0;
59+
cms_uint8_t width_ = 0;
60+
cms_uint8_t compavgCharge_ = 0;
61+
static constexpr double maxRange_ = 32767; //32767;
62+
static constexpr double maxBarycenter_ = 1536.;
63+
static constexpr double maxavgChargeRange_ = 63; //63;
64+
static constexpr double maxavgCharge_ = 255.;
65+
static constexpr double trimMaxADC_ = 30.;
66+
static constexpr double trimMaxFracTotal_ = .15;
67+
static constexpr double trimMaxFracNeigh_ = .25;
68+
static constexpr double maxTrimmedSizeDiffNeg_ = .7;
69+
static constexpr double maxTrimmedSizeDiffPos_ = 1.;
70+
static constexpr int kfilterMask = 6;
71+
static constexpr int kpeakFilterMask = 7;
72+
static constexpr int kSaturatedMask = 15;
73+
};
74+
#endif // DataFormats_SiStripCluster_SiStripApproximateCluster_v1_h

DataFormats/SiStripCluster/interface/SiStripCluster.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
55
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
6+
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster_v1.h"
67
#include <vector>
78
#include <numeric>
89
#include <iostream>
@@ -45,6 +46,7 @@ class SiStripCluster {
4546
}
4647

4748
SiStripCluster(const SiStripApproximateCluster cluster, const uint16_t maxStrips);
49+
SiStripCluster(const SiStripApproximateCluster_v1 cluster, const uint16_t maxStrips, float pc=-999, unsigned int module_length=0, unsigned int previous_module_length=0);
4850

4951
// extend the cluster
5052
template <typename Iter>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollection_v1.h"
2+
using namespace v1;
3+
void SiStripApproximateClusterCollection::reserve(std::size_t dets, std::size_t clusters) {
4+
detIds_.reserve(dets);
5+
clusters_.reserve(clusters);
6+
}
7+
8+
SiStripApproximateClusterCollection::Filler SiStripApproximateClusterCollection::beginDet(unsigned int detId) {
9+
detIds_.push_back((detIds_.size() == 0) ? detId : detId - (std::accumulate(detIds_.cbegin(), detIds_.cend(),0)));
10+
return Filler(clusters_);
11+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster_v1.h"
2+
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
3+
#include <algorithm>
4+
#include <cmath>
5+
#include <assert.h>
6+
7+
SiStripApproximateCluster_v1::SiStripApproximateCluster_v1(const SiStripCluster& cluster,
8+
unsigned int maxNSat,
9+
float hitPredPos,
10+
float& previous_cluster,
11+
unsigned int& module_length,
12+
unsigned int& previous_module_length,
13+
bool peakFilter) {
14+
bool filter_, isSaturated_, peakFilter_;
15+
if (previous_cluster == -999.)
16+
compBarycenter_ = std::round(cluster.barycenter() * maxRange_/maxBarycenter_);
17+
else
18+
compBarycenter_ = std::round(((cluster.barycenter()-previous_cluster)+(module_length-previous_module_length))* maxRange_/maxBarycenter_);
19+
previous_cluster = barycenter(previous_cluster, module_length, previous_module_length);
20+
assert(cluster.barycenter() <= maxBarycenter_ && "Got a barycenter > maxBarycenter");
21+
assert(compBarycenter_ <= maxRange_ && "Filling compBarycenter > maxRange");
22+
width_ = std::min(255,(int)cluster.size());//cluster.size();
23+
float avgCharge_ = cluster.charge() * 1. / width_;
24+
assert(avgCharge_ <= maxavgCharge_ && "Got a avgCharge > maxavgCharge");
25+
compavgCharge_ = std::round(avgCharge_ * maxavgChargeRange_/maxavgCharge_);
26+
assert(compavgCharge_ <= maxavgChargeRange_ && "Filling compavgCharge > maxavgChargeRange");
27+
filter_ = false;
28+
isSaturated_ = false;
29+
peakFilter_ = peakFilter;
30+
31+
//mimicing the algorithm used in StripSubClusterShapeTrajectoryFilter...
32+
//Looks for 3 adjacent saturated strips (ADC>=254)
33+
const auto& ampls = cluster.amplitudes();
34+
unsigned int thisSat = (ampls[0] >= 254), maxSat = thisSat;
35+
for (unsigned int i = 1, n = ampls.size(); i < n; ++i) {
36+
if (ampls[i] >= 254) {
37+
thisSat++;
38+
} else if (thisSat > 0) {
39+
maxSat = std::max<int>(maxSat, thisSat);
40+
thisSat = 0;
41+
}
42+
}
43+
if (thisSat > 0) {
44+
maxSat = std::max<int>(maxSat, thisSat);
45+
}
46+
if (maxSat >= maxNSat) {
47+
filter_ = true;
48+
isSaturated_ = true;
49+
}
50+
51+
unsigned int hitStripsTrim = ampls.size();
52+
int sum = std::accumulate(ampls.begin(), ampls.end(), 0);
53+
uint8_t trimCut = std::min<uint8_t>(trimMaxADC_, std::floor(trimMaxFracTotal_ * sum));
54+
auto begin = ampls.begin();
55+
auto last = ampls.end() - 1;
56+
while (hitStripsTrim > 1 && (*begin < std::max<uint8_t>(trimCut, trimMaxFracNeigh_ * (*(begin + 1))))) {
57+
hitStripsTrim--;
58+
++begin;
59+
}
60+
while (hitStripsTrim > 1 && (*last < std::max<uint8_t>(trimCut, trimMaxFracNeigh_ * (*(last - 1))))) {
61+
hitStripsTrim--;
62+
--last;
63+
}
64+
if (hitStripsTrim < std::floor(std::abs(hitPredPos) - maxTrimmedSizeDiffNeg_)) {
65+
filter_ = false;
66+
} else if (hitStripsTrim <= std::ceil(std::abs(hitPredPos) + maxTrimmedSizeDiffPos_)) {
67+
filter_ = true;
68+
} else {
69+
filter_ = peakFilter_;
70+
}
71+
compavgCharge_ = (compavgCharge_ | (filter_ << kfilterMask));
72+
compavgCharge_ = (compavgCharge_ | (peakFilter_ << kpeakFilterMask));
73+
compBarycenter_ = (compBarycenter_ | (isSaturated_ << kSaturatedMask));
74+
}

DataFormats/SiStripCluster/src/SiStripCluster.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,20 @@ SiStripCluster::SiStripCluster(const SiStripApproximateCluster cluster, const ui
3939
}
4040
firstStrip_ |= approximateMask;
4141
}
42+
43+
SiStripCluster::SiStripCluster(const SiStripApproximateCluster_v1 cluster, const uint16_t maxStrips, float p_bc,unsigned int module_length, unsigned int previous_module_length) : error_x(-99999.9) {
44+
barycenter_ = cluster.barycenter(p_bc, module_length, previous_module_length);
45+
charge_ = cluster.width() * cluster.avgCharge();
46+
amplitudes_.resize(cluster.width(), cluster.avgCharge());
47+
filter_ = cluster.filter();
48+
49+
float halfwidth_ = 0.5f * float(cluster.width());
50+
51+
//initialize firstStrip_
52+
firstStrip_ = std::max(barycenter_ - halfwidth_, 0.f);
53+
54+
if UNLIKELY (firstStrip_ + cluster.width() > maxStrips) {
55+
firstStrip_ = maxStrips - cluster.width();
56+
}
57+
firstStrip_ |= approximateMask;
58+
}

DataFormats/SiStripCluster/src/classes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
88
#include "DataFormats/SiStripCluster/interface/SiStripClustersSOA.h"
99
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
10+
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster_v1.h"
1011
#include "DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollection.h"
12+
#include "DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollection_v1.h"
1113
#include "DataFormats/Common/interface/ContainerMask.h"
1214

1315
#endif // SISTRIPCLUSTER_CLASSES_H

DataFormats/SiStripCluster/src/classes_def.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,36 @@
5959
<class name="edmNew::DetSetVector<edm::Ref<edmNew::DetSetVector<SiStripApproximateCluster>,SiStripApproximateCluster,edmNew::DetSetVector<SiStripApproximateCluster>::FindForDetSetVector> >" />
6060
<class name="edm::Wrapper<edmNew::DetSetVector<edm::Ref<edmNew::DetSetVector<SiStripApproximateCluster>,SiStripApproximateCluster,edmNew::DetSetVector<SiStripApproximateCluster>::FindForDetSetVector> > >" />
6161

62+
63+
64+
<class name="SiStripApproximateCluster_v1" ClassVersion="7">
65+
<version ClassVersion="7" checksum="1154754493"/>
66+
<version ClassVersion="6" checksum="132211472"/>
67+
<version ClassVersion="5" checksum="3495825183"/>
68+
<version ClassVersion="4" checksum="2854791577"/>
69+
<version ClassVersion="3" checksum="2041370183"/>
70+
</class>
71+
<class name="v1::SiStripApproximateClusterCollection" ClassVersion="4">
72+
<version ClassVersion="4" checksum="2896589077"/>
73+
<version ClassVersion="3" checksum="3101417750"/>
74+
</class>
75+
<class name="edm::Wrapper<v1::SiStripApproximateClusterCollection>"/>
76+
77+
<class name="edmNew::DetSetVector<SiStripApproximateCluster_v1>"/>
78+
<class name="edm::Wrapper<edmNew::DetSetVector<SiStripApproximateCluster_v1>>"/>
79+
80+
<class name="std::vector<SiStripApproximateCluster_v1>"/>
81+
82+
<class name="edm::Ref<edmNew::DetSetVector<SiStripApproximateCluster_v1>, SiStripApproximateCluster_v1, edmNew::DetSetVector<SiStripApproximateCluster_v1>::FindForDetSetVector>"/>
83+
84+
85+
<class name="edm::ContainerMask<edmNew::DetSetVector<SiStripApproximateCluster_v1> >"/>
86+
<class name="edm::Wrapper<edm::ContainerMask<edmNew::DetSetVector<SiStripApproximateCluster_v1> > >"/>
87+
88+
89+
<class name="std::vector<edm::Ref<edmNew::DetSetVector<SiStripApproximateCluster_v1>,SiStripApproximateCluster_v1,edmNew::DetSetVector<SiStripApproximateCluster_v1>::FindForDetSetVector> >" />
90+
<class name="edmNew::DetSetVector<edm::Ref<edmNew::DetSetVector<SiStripApproximateCluster_v1>,SiStripApproximateCluster_v1,edmNew::DetSetVector<SiStripApproximateCluster_v1>::FindForDetSetVector> >" />
91+
<class name="edm::Wrapper<edmNew::DetSetVector<edm::Ref<edmNew::DetSetVector<SiStripApproximateCluster_v1>,SiStripApproximateCluster_v1,edmNew::DetSetVector<SiStripApproximateCluster_v1>::FindForDetSetVector> > >" />
6292
<class name="SiStripClustersSOA" ClassVersion="3">
6393
<version ClassVersion="3" checksum="2739562998"/>
6494
</class>

0 commit comments

Comments
 (0)