-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathSiStripClusters2ApproxClusters.cc
160 lines (129 loc) · 7.09 KB
/
SiStripClusters2ApproxClusters.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "CalibFormats/SiStripObjects/interface/SiStripDetInfo.h"
#include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
#include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
#include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
#include "DataFormats/Common/interface/DetSetVector.h"
#include "DataFormats/Common/interface/DetSetVectorNew.h"
#include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
#include "DataFormats/GeometryVector/interface/GlobalPoint.h"
#include "DataFormats/GeometryVector/interface/LocalPoint.h"
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackBase.h"
#include "DataFormats/SiStripCommon/interface/ConstantsForHardwareSystems.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/FileInPath.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Utilities/interface/ESInputTag.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
#include "RecoTracker/PixelLowPtUtilities/interface/ClusterShapeHitFilter.h"
#include "RecoTracker/PixelLowPtUtilities/interface/SlidingPeakFinder.h"
#include "RecoTracker/Record/interface/CkfComponentsRecord.h"
#include <vector>
#include <memory>
class SiStripClusters2ApproxClusters : public edm::stream::EDProducer<> {
public:
explicit SiStripClusters2ApproxClusters(const edm::ParameterSet& conf);
void produce(edm::Event&, const edm::EventSetup&) override;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
private:
edm::InputTag inputClusters;
edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster> > clusterToken;
unsigned int maxNSat;
static constexpr double subclusterWindow_ = .7;
static constexpr double seedCutMIPs_ = .35;
static constexpr double seedCutSN_ = 7.;
static constexpr double subclusterCutMIPs_ = .45;
static constexpr double subclusterCutSN_ = 12.;
edm::InputTag beamSpot_;
edm::EDGetTokenT<reco::BeamSpot> beamSpotToken_;
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
edm::FileInPath fileInPath_;
SiStripDetInfo detInfo_;
std::string csfLabel_;
edm::ESGetToken<ClusterShapeHitFilter, CkfComponentsRecord> csfToken_;
edm::ESGetToken<SiStripNoises, SiStripNoisesRcd> stripNoiseToken_;
edm::ESHandle<SiStripNoises> theNoise_;
};
SiStripClusters2ApproxClusters::SiStripClusters2ApproxClusters(const edm::ParameterSet& conf) {
inputClusters = conf.getParameter<edm::InputTag>("inputClusters");
maxNSat = conf.getParameter<unsigned int>("maxSaturatedStrips");
clusterToken = consumes<edmNew::DetSetVector<SiStripCluster> >(inputClusters);
beamSpot_ = conf.getParameter<edm::InputTag>("beamSpot");
beamSpotToken_ = consumes<reco::BeamSpot>(beamSpot_);
tkGeomToken_ = esConsumes();
fileInPath_ = edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile);
detInfo_ = SiStripDetInfoFileReader::read(fileInPath_.fullPath());
csfLabel_ = conf.getParameter<std::string>("clusterShapeHitFilterLabel");
csfToken_ = esConsumes(edm::ESInputTag("", csfLabel_));
stripNoiseToken_ = esConsumes();
produces<edmNew::DetSetVector<SiStripApproximateCluster> >();
}
void SiStripClusters2ApproxClusters::produce(edm::Event& event, edm::EventSetup const& iSetup) {
auto result = std::make_unique<edmNew::DetSetVector<SiStripApproximateCluster> >();
const auto& clusterCollection = event.get(clusterToken);
auto const beamSpotHandle = event.getHandle(beamSpotToken_);
auto const& bs = beamSpotHandle.isValid() ? *beamSpotHandle : reco::BeamSpot();
if (not beamSpotHandle.isValid()) {
edm::LogError("SiStripClusters2ApproxClusters")
<< "didn't find a valid beamspot with label \"" << beamSpot_.encode() << "\" -> using (0,0,0)";
}
const auto& tkGeom = &iSetup.getData(tkGeomToken_);
const auto& theFilter = &iSetup.getData(csfToken_);
const auto& theNoise_ = &iSetup.getData(stripNoiseToken_);
for (const auto& detClusters : clusterCollection) {
edmNew::DetSetVector<SiStripApproximateCluster>::FastFiller ff{*result, detClusters.id()};
unsigned int detId = detClusters.id();
const GeomDet* det = tkGeom->idToDet(detId);
double nApvs = detInfo_.getNumberOfApvsAndStripLength(detId).first;
double stripLength = detInfo_.getNumberOfApvsAndStripLength(detId).second;
double barycenter_ypos = 0.5 * stripLength;
const StripGeomDetUnit* stripDet = dynamic_cast<const StripGeomDetUnit*>(det);
float mip = 3.9 / (sistrip::MeVperADCStrip / stripDet->surface().bounds().thickness());
for (const auto& cluster : detClusters) {
const LocalPoint& lp = LocalPoint(((cluster.barycenter() * 10 / (sistrip::STRIPS_PER_APV * nApvs)) -
((stripDet->surface().bounds().width()) * 0.5f)),
barycenter_ypos - (0.5f * stripLength),
0.);
const GlobalPoint& gpos = det->surface().toGlobal(lp);
GlobalPoint beamspot(bs.position().x(), bs.position().y(), bs.position().z());
const GlobalVector& gdir = gpos - beamspot;
const LocalVector& ldir = det->toLocal(gdir);
int hitStrips;
float hitPredPos;
theFilter->getSizes(detId, cluster, lp, ldir, hitStrips, hitPredPos);
bool peakFilter = false;
SlidingPeakFinder pf(std::max<int>(2, std::ceil(std::abs(hitPredPos) + subclusterWindow_)));
float mipnorm = mip / std::abs(ldir.z());
PeakFinderTest test(mipnorm,
detId,
cluster.firstStrip(),
theNoise_,
seedCutMIPs_,
seedCutSN_,
subclusterCutMIPs_,
subclusterCutSN_);
peakFilter = pf.apply(cluster.amplitudes(), test);
ff.push_back(SiStripApproximateCluster(cluster, maxNSat, hitPredPos, peakFilter));
}
}
event.put(std::move(result));
}
void SiStripClusters2ApproxClusters::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("inputClusters", edm::InputTag("siStripClusters"));
desc.add<unsigned int>("maxSaturatedStrips", 3);
desc.add<std::string>("clusterShapeHitFilterLabel", "ClusterShapeHitFilter"); // add CSF label
desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot")); // add BeamSpot tag
descriptions.add("SiStripClusters2ApproxClusters", desc);
}
DEFINE_FWK_MODULE(SiStripClusters2ApproxClusters);