Skip to content

Commit 511f952

Browse files
authored
Merge pull request #41815 from Ksavva1021/RAW_Prime_2804
Adding filter flag to SiStripApproximateClusters
2 parents 538e072 + a185ded commit 511f952

File tree

16 files changed

+384
-102
lines changed

16 files changed

+384
-102
lines changed

Configuration/StandardSequences/python/DigiToRaw_Repack_cff.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,17 @@
7272
cms.InputTag('siStripZeroSuppressionHLT','ScopeMode')),
7373
)
7474

75-
from RecoLocalTracker.SiStripClusterizer.SiStripClusters2ApproxClusters_cff import hltSiStripClusters2ApproxClusters
75+
from RecoLocalTracker.SiStripClusterizer.SiStripClusters2ApproxClusters_cff import *
7676

7777
from EventFilter.Utilities.EvFFEDExcluder_cfi import EvFFEDExcluder as _EvFFEDExcluder
7878
rawPrimeDataRepacker = _EvFFEDExcluder.clone(
7979
src = 'rawDataCollector',
8080
fedsToExclude = [foo for foo in range(50, 490)]
8181
)
8282

83-
DigiToApproxClusterRawTask = cms.Task(siStripDigisHLT,siStripZeroSuppressionHLT,siStripClustersHLT,hltSiStripClusters2ApproxClusters,rawPrimeDataRepacker)
83+
hltScalersRawToDigi = cms.EDProducer( "ScalersRawToDigi",
84+
scalersInputTag = cms.InputTag( "rawDataRepacker" )
85+
)
86+
87+
DigiToApproxClusterRawTask = cms.Task(siStripDigisHLT,siStripZeroSuppressionHLT,hltScalersRawToDigi,hltBeamSpotProducer,siStripClustersHLT,hltSiStripClusters2ApproxClusters,rawPrimeDataRepacker)
8488
DigiToApproxClusterRaw = cms.Sequence(DigiToApproxClusterRawTask)

DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h

+16-5
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,38 @@ class SiStripApproximateCluster {
88
public:
99
SiStripApproximateCluster() {}
1010

11-
explicit SiStripApproximateCluster(cms_uint16_t barycenter,
12-
cms_uint8_t width,
13-
cms_uint8_t avgCharge,
14-
bool isSaturated) {
11+
explicit SiStripApproximateCluster(
12+
cms_uint16_t barycenter, cms_uint8_t width, cms_uint8_t avgCharge, bool filter, bool isSaturated) {
1513
barycenter_ = barycenter;
1614
width_ = width;
1715
avgCharge_ = avgCharge;
16+
filter_ = filter;
1817
isSaturated_ = isSaturated;
1918
}
2019

21-
explicit SiStripApproximateCluster(const SiStripCluster& cluster, unsigned int maxNSat);
20+
explicit SiStripApproximateCluster(const SiStripCluster& cluster,
21+
unsigned int maxNSat,
22+
float hitPredPos,
23+
bool peakFilter);
2224

2325
cms_uint16_t barycenter() const { return barycenter_; }
2426
cms_uint8_t width() const { return width_; }
2527
cms_uint8_t avgCharge() const { return avgCharge_; }
28+
bool filter() const { return filter_; }
2629
bool isSaturated() const { return isSaturated_; }
30+
bool peakFilter() const { return peakFilter_; }
2731

2832
private:
2933
cms_uint16_t barycenter_ = 0;
3034
cms_uint8_t width_ = 0;
3135
cms_uint8_t avgCharge_ = 0;
36+
bool filter_ = false;
3237
bool isSaturated_ = false;
38+
bool peakFilter_ = false;
39+
static constexpr double trimMaxADC_ = 30.;
40+
static constexpr double trimMaxFracTotal_ = .15;
41+
static constexpr double trimMaxFracNeigh_ = .25;
42+
static constexpr double maxTrimmedSizeDiffNeg_ = .7;
43+
static constexpr double maxTrimmedSizeDiffPos_ = 1.;
3344
};
3445
#endif // DataFormats_SiStripCluster_SiStripApproximateCluster_h

DataFormats/SiStripCluster/interface/SiStripCluster.h

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ class SiStripCluster {
8282
*/
8383
int charge() const;
8484

85+
bool filter() const;
86+
87+
bool isFromApprox() const;
88+
8589
/** Test (set) the merged status of the cluster
8690
*
8791
*/
@@ -99,6 +103,7 @@ class SiStripCluster {
99103
//these are used if amplitude information is not available (using approximate cluster constructor)
100104
float barycenter_ = 0;
101105
int charge_ = 0;
106+
bool filter_ = false;
102107

103108
// [email protected], 01/05/12
104109
// Add cluster errors to be used by rechits from split clusters.

DataFormats/SiStripCluster/src/SiStripApproximateCluster.cc

+28-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
#include <algorithm>
44
#include <cmath>
55

6-
SiStripApproximateCluster::SiStripApproximateCluster(const SiStripCluster& cluster, unsigned int maxNSat) {
6+
SiStripApproximateCluster::SiStripApproximateCluster(const SiStripCluster& cluster,
7+
unsigned int maxNSat,
8+
float hitPredPos,
9+
bool peakFilter) {
710
barycenter_ = std::round(cluster.barycenter() * 10);
811
width_ = cluster.size();
912
avgCharge_ = cluster.charge() / cluster.size();
13+
filter_ = false;
1014
isSaturated_ = false;
15+
peakFilter_ = peakFilter;
1116

1217
//mimicing the algorithm used in StripSubClusterShapeTrajectoryFilter...
1318
//Looks for 3 adjacent saturated strips (ADC>=254)
@@ -25,6 +30,28 @@ SiStripApproximateCluster::SiStripApproximateCluster(const SiStripCluster& clust
2530
maxSat = std::max<int>(maxSat, thisSat);
2631
}
2732
if (maxSat >= maxNSat) {
33+
filter_ = true;
2834
isSaturated_ = true;
2935
}
36+
37+
unsigned int hitStripsTrim = ampls.size();
38+
int sum = std::accumulate(ampls.begin(), ampls.end(), 0);
39+
uint8_t trimCut = std::min<uint8_t>(trimMaxADC_, std::floor(trimMaxFracTotal_ * sum));
40+
auto begin = ampls.begin();
41+
auto last = ampls.end() - 1;
42+
while (hitStripsTrim > 1 && (*begin < std::max<uint8_t>(trimCut, trimMaxFracNeigh_ * (*(begin + 1))))) {
43+
hitStripsTrim--;
44+
++begin;
45+
}
46+
while (hitStripsTrim > 1 && (*last < std::max<uint8_t>(trimCut, trimMaxFracNeigh_ * (*(last - 1))))) {
47+
hitStripsTrim--;
48+
--last;
49+
}
50+
if (hitStripsTrim < std::floor(std::abs(hitPredPos) - maxTrimmedSizeDiffNeg_)) {
51+
filter_ = false;
52+
} else if (hitStripsTrim <= std::ceil(std::abs(hitPredPos) + maxTrimmedSizeDiffPos_)) {
53+
filter_ = true;
54+
} else {
55+
filter_ = peakFilter_;
56+
}
3057
}

DataFormats/SiStripCluster/src/SiStripCluster.cc

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SiStripCluster::SiStripCluster(const SiStripApproximateCluster cluster, const ui
2626
barycenter_ = cluster.barycenter() / 10.0;
2727
charge_ = cluster.width() * cluster.avgCharge();
2828
amplitudes_.resize(cluster.width(), cluster.avgCharge());
29+
filter_ = cluster.filter();
2930

3031
float halfwidth_ = 0.5f * float(cluster.width());
3132

@@ -60,3 +61,10 @@ float SiStripCluster::barycenter() const {
6061
// Need to mask off the high bit of firstStrip_, which contains the merged status.
6162
return float((firstStrip_ & stripIndexMask)) + float(sumx) / float(suma) + 0.5f;
6263
}
64+
bool SiStripCluster::filter() const {
65+
if (barycenter_ > 0)
66+
return filter_;
67+
return false;
68+
}
69+
70+
bool SiStripCluster::isFromApprox() const { return (barycenter_ > 0); }

DataFormats/SiStripCluster/src/classes_def.xml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<lcgdict>
22

3-
<class name="SiStripCluster" ClassVersion="12">
3+
<class name="SiStripCluster" ClassVersion="13">
4+
<version ClassVersion="13" checksum="1374720584"/>
45
<version ClassVersion="12" checksum="2984011925"/>
56
<version ClassVersion="11" checksum="3702468681"/>
67
<version ClassVersion="10" checksum="3791198690"/>
@@ -24,7 +25,8 @@
2425
<class name="edm::Wrapper<edmNew::DetSetVector<edm::Ref<edmNew::DetSetVector<SiStripCluster>,SiStripCluster,edmNew::DetSetVector<SiStripCluster>::FindForDetSetVector> > >" />
2526

2627

27-
<class name="SiStripApproximateCluster" ClassVersion="5">
28+
<class name="SiStripApproximateCluster" ClassVersion="6">
29+
<version ClassVersion="6" checksum="132211472"/>
2830
<version ClassVersion="5" checksum="3495825183"/>
2931
<version ClassVersion="4" checksum="2854791577"/>
3032
<version ClassVersion="3" checksum="2041370183"/>

DataFormats/SiStripCommon/interface/ConstantsForHardwareSystems.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace sistrip {
4444
static const uint16_t STRIPS_PER_FEDCH = STRIPS_PER_APV * APVS_PER_FEDCH;
4545
static const uint16_t STRIPS_PER_FEUNIT = STRIPS_PER_FEDCH * FEDCH_PER_FEUNIT; // 3072
4646
static const uint16_t STRIPS_PER_FED = STRIPS_PER_FEUNIT * FEUNITS_PER_FED; // 24576
47+
static constexpr float MeVperADCStrip = 9.5665E-4;
4748

4849
// -------------------- FED buffers --------------------
4950

HLTrigger/Configuration/python/customizeHLTforCMSSW.py

+11
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,16 @@ def customizeHLTfor41495(process):
226226

227227
return process
228228

229+
def customizeHLTfor41815(process):
230+
# use hlt online BeamSpot for SiStripClusters2ApproxClusters
231+
for producer in producers_by_type(process, 'SiStripClusters2ApproxClusters'):
232+
producer.beamSpot = cms.InputTag('hltOnlineBeamSpot')
233+
234+
if hasattr(process, 'HLT_HIRandom_v4'):
235+
getattr(process,'HLT_HIRandom_v4').insert(2,process.HLTBeamSpot)
236+
237+
return process
238+
229239
# CMSSW version specific customizations
230240
def customizeHLTforCMSSW(process, menuType="GRun"):
231241

@@ -236,5 +246,6 @@ def customizeHLTforCMSSW(process, menuType="GRun"):
236246

237247
process = customizeHLTfor41058(process)
238248
process = customizeHLTfor41495(process)
249+
process = customizeHLTfor41815(process)
239250

240251
return process

RecoLocalTracker/SiStripClusterizer/plugins/BuildFile.xml

+3
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
<use name="HeterogeneousCore/CUDAUtilities"/>
77
<use name="CUDADataFormats/SiStripCluster"/>
88
<use name="cuda"/>
9+
<use name="RecoTracker/PixelLowPtUtilities"/>
10+
<use name="CalibFormats/SiStripObjects"/>
11+
<use name="CalibTracker/SiStripCommon"/>
912
<flags EDM_PLUGIN="1"/>
1013
</library>

RecoLocalTracker/SiStripClusterizer/plugins/SiStripApprox2ApproxClusters.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void SiStripApprox2ApproxClusters::produce(edm::Event& event, edm::EventSetup co
5959
float barycenter = cluster.barycenter();
6060
uint8_t width = cluster.width();
6161
float avgCharge = cluster.avgCharge();
62+
bool filter = cluster.filter();
6263
bool isSaturated = cluster.isSaturated();
6364

6465
switch (approxVersion) {
@@ -86,7 +87,7 @@ void SiStripApprox2ApproxClusters::produce(edm::Event& event, edm::EventSetup co
8687
break;
8788
}
8889

89-
ff.push_back(SiStripApproximateCluster(barycenter, width, avgCharge, isSaturated));
90+
ff.push_back(SiStripApproximateCluster(barycenter, width, avgCharge, filter, isSaturated));
9091
}
9192
}
9293

RecoLocalTracker/SiStripClusterizer/plugins/SiStripClusters2ApproxClusters.cc

+111-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
1-
2-
3-
#include "FWCore/Framework/interface/MakerMacros.h"
1+
#include "CalibFormats/SiStripObjects/interface/SiStripDetInfo.h"
2+
#include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
3+
#include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
4+
#include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
5+
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
6+
#include "DataFormats/Common/interface/DetSetVector.h"
7+
#include "DataFormats/Common/interface/DetSetVectorNew.h"
8+
#include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
9+
#include "DataFormats/GeometryVector/interface/GlobalPoint.h"
10+
#include "DataFormats/GeometryVector/interface/LocalPoint.h"
11+
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
12+
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
13+
#include "DataFormats/TrackReco/interface/Track.h"
14+
#include "DataFormats/TrackReco/interface/TrackBase.h"
15+
#include "DataFormats/SiStripCommon/interface/ConstantsForHardwareSystems.h"
416
#include "FWCore/Framework/interface/Frameworkfwd.h"
17+
#include "FWCore/Framework/interface/MakerMacros.h"
518
#include "FWCore/Framework/interface/stream/EDProducer.h"
6-
#include "FWCore/ParameterSet/interface/ParameterSet.h"
7-
#include "FWCore/Utilities/interface/InputTag.h"
819
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
20+
#include "FWCore/ParameterSet/interface/FileInPath.h"
21+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
922
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
10-
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
11-
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
12-
#include "DataFormats/Common/interface/DetSetVectorNew.h"
13-
#include "DataFormats/Common/interface/DetSetVector.h"
23+
#include "FWCore/Utilities/interface/ESInputTag.h"
24+
#include "FWCore/Utilities/interface/InputTag.h"
25+
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
26+
#include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
27+
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
28+
#include "RecoTracker/PixelLowPtUtilities/interface/ClusterShapeHitFilter.h"
29+
#include "RecoTracker/PixelLowPtUtilities/interface/SlidingPeakFinder.h"
30+
#include "RecoTracker/Record/interface/CkfComponentsRecord.h"
1431

1532
#include <vector>
1633
#include <memory>
@@ -27,25 +44,105 @@ class SiStripClusters2ApproxClusters : public edm::stream::EDProducer<> {
2744
edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster> > clusterToken;
2845

2946
unsigned int maxNSat;
47+
static constexpr double subclusterWindow_ = .7;
48+
static constexpr double seedCutMIPs_ = .35;
49+
static constexpr double seedCutSN_ = 7.;
50+
static constexpr double subclusterCutMIPs_ = .45;
51+
static constexpr double subclusterCutSN_ = 12.;
52+
53+
edm::InputTag beamSpot_;
54+
edm::EDGetTokenT<reco::BeamSpot> beamSpotToken_;
55+
56+
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
57+
58+
edm::FileInPath fileInPath_;
59+
SiStripDetInfo detInfo_;
60+
61+
std::string csfLabel_;
62+
edm::ESGetToken<ClusterShapeHitFilter, CkfComponentsRecord> csfToken_;
63+
64+
edm::ESGetToken<SiStripNoises, SiStripNoisesRcd> stripNoiseToken_;
65+
edm::ESHandle<SiStripNoises> theNoise_;
3066
};
3167

3268
SiStripClusters2ApproxClusters::SiStripClusters2ApproxClusters(const edm::ParameterSet& conf) {
3369
inputClusters = conf.getParameter<edm::InputTag>("inputClusters");
3470
maxNSat = conf.getParameter<unsigned int>("maxSaturatedStrips");
3571

3672
clusterToken = consumes<edmNew::DetSetVector<SiStripCluster> >(inputClusters);
73+
74+
beamSpot_ = conf.getParameter<edm::InputTag>("beamSpot");
75+
beamSpotToken_ = consumes<reco::BeamSpot>(beamSpot_);
76+
77+
tkGeomToken_ = esConsumes();
78+
79+
fileInPath_ = edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile);
80+
detInfo_ = SiStripDetInfoFileReader::read(fileInPath_.fullPath());
81+
82+
csfLabel_ = conf.getParameter<std::string>("clusterShapeHitFilterLabel");
83+
csfToken_ = esConsumes(edm::ESInputTag("", csfLabel_));
84+
85+
stripNoiseToken_ = esConsumes();
86+
3787
produces<edmNew::DetSetVector<SiStripApproximateCluster> >();
3888
}
3989

40-
void SiStripClusters2ApproxClusters::produce(edm::Event& event, edm::EventSetup const&) {
90+
void SiStripClusters2ApproxClusters::produce(edm::Event& event, edm::EventSetup const& iSetup) {
4191
auto result = std::make_unique<edmNew::DetSetVector<SiStripApproximateCluster> >();
4292
const auto& clusterCollection = event.get(clusterToken);
4393

94+
auto const beamSpotHandle = event.getHandle(beamSpotToken_);
95+
auto const& bs = beamSpotHandle.isValid() ? *beamSpotHandle : reco::BeamSpot();
96+
if (not beamSpotHandle.isValid()) {
97+
edm::LogError("SiStripClusters2ApproxClusters")
98+
<< "didn't find a valid beamspot with label \"" << beamSpot_.encode() << "\" -> using (0,0,0)";
99+
}
100+
101+
const auto& tkGeom = &iSetup.getData(tkGeomToken_);
102+
const auto& theFilter = &iSetup.getData(csfToken_);
103+
const auto& theNoise_ = &iSetup.getData(stripNoiseToken_);
104+
44105
for (const auto& detClusters : clusterCollection) {
45106
edmNew::DetSetVector<SiStripApproximateCluster>::FastFiller ff{*result, detClusters.id()};
46107

47-
for (const auto& cluster : detClusters)
48-
ff.push_back(SiStripApproximateCluster(cluster, maxNSat));
108+
unsigned int detId = detClusters.id();
109+
const GeomDet* det = tkGeom->idToDet(detId);
110+
double nApvs = detInfo_.getNumberOfApvsAndStripLength(detId).first;
111+
double stripLength = detInfo_.getNumberOfApvsAndStripLength(detId).second;
112+
double barycenter_ypos = 0.5 * stripLength;
113+
114+
const StripGeomDetUnit* stripDet = dynamic_cast<const StripGeomDetUnit*>(det);
115+
float mip = 3.9 / (sistrip::MeVperADCStrip / stripDet->surface().bounds().thickness());
116+
117+
for (const auto& cluster : detClusters) {
118+
const LocalPoint& lp = LocalPoint(((cluster.barycenter() * 10 / (sistrip::STRIPS_PER_APV * nApvs)) -
119+
((stripDet->surface().bounds().width()) * 0.5f)),
120+
barycenter_ypos - (0.5f * stripLength),
121+
0.);
122+
const GlobalPoint& gpos = det->surface().toGlobal(lp);
123+
GlobalPoint beamspot(bs.position().x(), bs.position().y(), bs.position().z());
124+
const GlobalVector& gdir = gpos - beamspot;
125+
const LocalVector& ldir = det->toLocal(gdir);
126+
127+
int hitStrips;
128+
float hitPredPos;
129+
theFilter->getSizes(detId, cluster, lp, ldir, hitStrips, hitPredPos);
130+
131+
bool peakFilter = false;
132+
SlidingPeakFinder pf(std::max<int>(2, std::ceil(std::abs(hitPredPos) + subclusterWindow_)));
133+
float mipnorm = mip / std::abs(ldir.z());
134+
PeakFinderTest test(mipnorm,
135+
detId,
136+
cluster.firstStrip(),
137+
theNoise_,
138+
seedCutMIPs_,
139+
seedCutSN_,
140+
subclusterCutMIPs_,
141+
subclusterCutSN_);
142+
peakFilter = pf.apply(cluster.amplitudes(), test);
143+
144+
ff.push_back(SiStripApproximateCluster(cluster, maxNSat, hitPredPos, peakFilter));
145+
}
49146
}
50147

51148
event.put(std::move(result));
@@ -55,6 +152,8 @@ void SiStripClusters2ApproxClusters::fillDescriptions(edm::ConfigurationDescript
55152
edm::ParameterSetDescription desc;
56153
desc.add<edm::InputTag>("inputClusters", edm::InputTag("siStripClusters"));
57154
desc.add<unsigned int>("maxSaturatedStrips", 3);
155+
desc.add<std::string>("clusterShapeHitFilterLabel", "ClusterShapeHitFilter"); // add CSF label
156+
desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot")); // add BeamSpot tag
58157
descriptions.add("SiStripClusters2ApproxClusters", desc);
59158
}
60159

0 commit comments

Comments
 (0)