Belle II Software development
DATCONSVDClusterizer.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <tracking/datcon/findlets/DATCONSVDClusterizer.h>
9#include <tracking/datcon/entities/DATCONSVDDigit.h>
10#include <tracking/datcon/entities/DATCONSVDClusterCandidate.h>
11#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
12#include <svd/dataobjects/SVDShaperDigit.h>
13#include <svd/dataobjects/SVDCluster.h>
14#include <svd/geometry/SensorInfo.h>
15#include <vxd/dataobjects/VxdID.h>
16#include <framework/core/ModuleParamList.h>
17#include <framework/core/ModuleParamList.templateDetails.h>
18
19using namespace Belle2;
20using namespace TrackFindingCDC;
21
23{
24}
25
26void DATCONSVDClusterizer::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
27{
28 Super::exposeParameters(moduleParamList, prefix);
29
30 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "noiseMap"), m_param_noiseMapfileName,
31 "Name of the text file containing strip noise information.", m_param_noiseMapfileName);
32
33 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "writeNoiseMapsToFile"), m_param_writeNoiseMapsToFile,
34 "Write noise information to text file?", m_param_writeNoiseMapsToFile);
35
36 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "maximumClusterSize"), m_param_maxiClusterSize,
37 "Maximum SVD cluster size for this side. Data type: unsigned short", m_param_maxiClusterSize);
38
39 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "noiseCut"), m_param_noiseCut,
40 "Cut for using default noise (noise < this value), or actual noise (noise > this value).",
42
43 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "requiredSNRstrip"),
44 m_param_requiredSNRstrip, "Required SNR per strip.", m_param_requiredSNRstrip);
45
46 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "requiredSNRcluster"),
47 m_param_requiredSNRcluster, "Required SNR for the cluster.", m_param_requiredSNRcluster);
48
49 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "isUClusterizer"),
50 m_param_isU, "Is this u or v side?", m_param_isU);
51
52 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "saveClusterToDataStore"),
53 m_param_saveClusterToDataStore, "Save SVDClusters for analysis?", m_param_saveClusterToDataStore);
54
55 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "storeSVDClustersName"),
56 m_param_storeSVDClustersName, "Name of the SVDClusters StoreArray", m_param_storeSVDClustersName);
57
58}
59
61{
62 m_svdNoiseMap.clear();
64}
65
67{
69
72 }
73}
74
75void DATCONSVDClusterizer::apply(const std::vector<DATCONSVDDigit>& digits, std::vector<SVDCluster>& clusters)
76{
77 if (digits.size() == 0) return;
78
79 DATCONSVDClusterCandidate clusterCand;
80
81 // create a dummy cluster just to start
82 clusterCand.vxdID = digits.at(0).getSensorID();
83
84 for (auto& digit : digits) {
85
86 float stripSNR = calculateSNR(digit);
87 if (stripSNR < m_param_requiredSNRstrip) {
88 continue;
89 }
90
91 //retrieve the VxdID, sensor and cellID of the current DATCONSVDDigit
92 VxdID thisSensorID = digit.getSensorID();
93 unsigned short thisCellID = digit.getCellID();
94 unsigned short thisCharge = digit.getMaxSampleCharge();
95
96 //try to add the strip to the existing cluster
97 if (! clusterCand.add(thisSensorID, thisCharge, thisCellID, stripSNR, m_param_maxiClusterSize)) {
98 //if the strip is not added, write the cluster, if present and good:
99 if (clusterCand.strips.size() > 0) {
100 saveCluster(clusterCand, clusters);
101 }
102
103 // start the next cluster
104 clusterCand.strips.clear();
105 clusterCand.charges.clear();
106 clusterCand.vxdID = thisSensorID;
107 clusterCand.strips.emplace_back(thisCellID);
108 clusterCand.charges.emplace_back(thisCharge);
109 clusterCand.maxSNRinClusterCandidate = stripSNR;
110 }
111 }
112
113 //write the last cluster, if good
114 if (clusterCand.strips.size() > 0) {
115 saveCluster(clusterCand, clusters);
116 }
117
119 for (const auto& cluster : clusters) {
121 }
122 }
123
124}
125
126
127void DATCONSVDClusterizer::saveCluster(DATCONSVDClusterCandidate& clusterCand, std::vector<SVDCluster>& clusters)
128{
129 const VXD::SensorInfoBase& info = m_geoCache.getSensorInfo(clusterCand.vxdID);
130 double pitch = m_param_isU ? info.getUPitch() : info.getVPitch();
131 unsigned short numberofStrips = m_param_isU ? info.getUCells() : info.getVCells();
132
133 clusterCand.finalizeCluster(pitch, numberofStrips);
135
136 double clusterPositionError = pitch;
137 if (clusterCand.strips.size() == 1) {
138 clusterPositionError = pitch / sqrt(12.);
139 } else if (clusterCand.strips.size() == 2) {
140 clusterPositionError = pitch / 2.;
141 }
142
143 clusters.emplace_back(SVDCluster(clusterCand.vxdID, m_param_isU, clusterCand.clusterPosition, clusterPositionError,
144 0.0, 0.0, clusterCand.charge, clusterCand.seedCharge, clusterCand.strips.size(), 0.0, 0.0));
145 }
146}
147
148
150{
151 unsigned short maxSampleIndex = digit.getMaxSampleIndex();
152 const DATCONSVDDigit::APVRawSamples& sample = digit.getRawSamples();
153 unsigned short stripID = digit.getCellID();
154 VxdID sensorID = digit.getSensorID();
155 int simpleVXDID = 131072 * (sensorID.getLayerNumber() - 3) + 8192 * (sensorID.getLadderNumber() - 1)
156 + 1024 * (sensorID.getSensorNumber() - 1) + stripID;
157
158 // set noise value to default value and only use actual noise if it is too large (> m_param_noiseCut)
159 float stripNoise = m_param_noiseCut;
160 if (m_svdNoiseMap.find(simpleVXDID) != m_svdNoiseMap.end()) {
161 stripNoise = m_svdNoiseMap.at(simpleVXDID);
162 }
163
164 float currentSNR = (float)sample[maxSampleIndex] / stripNoise;
165 return currentSNR;
166}
167
168
170{
171 //call for a geometry instance
173 std::set<Belle2::VxdID> svdLayers = aGeometry.getLayers(VXD::SensorInfoBase::SVD);
174 std::set<Belle2::VxdID>::iterator itSvdLayers = svdLayers.begin();
175
176 std::ofstream noiseMap;
178 noiseMap.open(m_param_noiseMapfileName, std::ios::trunc);
179 }
180
181 while (itSvdLayers != svdLayers.end()) { //loop on Layers
182
183 std::set<Belle2::VxdID> svdLadders = aGeometry.getLadders(*itSvdLayers);
184 std::set<Belle2::VxdID>::iterator itSvdLadders = svdLadders.begin();
185
186 while (itSvdLadders != svdLadders.end()) { //loop on Ladders
187
188 std::set<Belle2::VxdID> svdSensors = aGeometry.getSensors(*itSvdLadders);
189 std::set<Belle2::VxdID>::iterator itSvdSensors = svdSensors.begin();
190 B2DEBUG(29, " svd sensor info " << * (svdSensors.begin()));
191
192 while (itSvdSensors != svdSensors.end()) { //loop on sensors
193 B2DEBUG(29, " svd sensor info " << *itSvdSensors);
194
195 int layer = itSvdSensors->getLayerNumber();
196 int ladder = itSvdSensors->getLadderNumber();
197 int sensor = itSvdSensors->getSensorNumber();
198 Belle2::VxdID theVxdID(layer, ladder, sensor);
199 const SVD::SensorInfo* currentSensorInfo = dynamic_cast<const SVD::SensorInfo*>(&VXD::GeoCache::getInstance().getSensorInfo(
200 theVxdID));
201
202 int simpleVXDID = 131072 * (layer - 3) + 8192 * (ladder - 1) + 1024 * (sensor - 1);
203
204 int Ncells = m_param_isU ? currentSensorInfo->getUCells() : currentSensorInfo->getVCells();
205
206 for (int strip = 0; strip < Ncells; strip++) {
207
208 float noise = -1;
209 if (m_NoiseCal.isValid()) {
210 noise = m_NoiseCal.getNoise(theVxdID, m_param_isU, strip);
211 }
212
213 if (noise > m_param_noiseCut) {
214 m_svdNoiseMap.insert(std::make_pair(simpleVXDID + strip, noise));
216 noiseMap << 4096 * (layer - 3) + 16 * (ladder - 1) + (sensor - 1) << " " << strip << " " << noise << std::endl;
217 }
218 }
219 }
220 ++itSvdSensors;
221 }
222 ++itSvdLadders;
223 }
224 ++itSvdLayers;
225 }
227 noiseMap.close();
228 }
229
230}
void initialize() override
Create the store arrays.
float m_param_noiseCut
Value above which u-strips are considered noisy, all other u-strips will get assigned a standard nois...
bool m_param_writeNoiseMapsToFile
Write the noise map to file m_param_noiseMapfileName for export to FPGA?
SimpleSVDNoiseMap m_svdNoiseMap
Simple noise map for u-strips*‍/.
SVDNoiseCalibrations m_NoiseCal
SVD Noise payload.
bool m_param_isU
Is this the finldlet for u-side or for v-side?
float m_param_requiredSNRstrip
Require a SNR for a u-strip signal to be valid.
StoreArray< SVDCluster > m_storeSVDClusters
StoreArray to save the clusters to.
std::string m_param_noiseMapfileName
File name for a file containing the noise of the strips for export to FPGA.
unsigned short m_param_maxiClusterSize
maximum cluster size
void apply(const std::vector< DATCONSVDDigit > &digits, std::vector< SVDCluster > &clusters) override
Load in the DATCONSVDDigits and create SVDClusters from them.
float calculateSNR(DATCONSVDDigit digit)
calculate the SNR of a DATCONSVDDigit (= one strip) in a simplified way
void beginRun() override
Begin Run.
void saveCluster(DATCONSVDClusterCandidate &clusterCand, std::vector< SVDCluster > &clusters)
save the current cluster candidate as a SVDCluster
void fillDATCONSVDNoiseMap()
fill the noise map to be used for SNR cuts
DATCONSVDClusterizer()
Cluster SVD strips.
const VXD::GeoCache & m_geoCache
instance of GeoCache to avoid creating it again for every cluster
float m_param_requiredSNRcluster
Require a SNR for at least one strip in the u-cluster to make the cluster valid.
bool m_param_saveClusterToDataStore
Save SVDCluster to DataStore for analysis?
std::string m_param_storeSVDClustersName
SVDClusters StoreArray name.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters of the sub findlets.
The DATCONSVDDigit class.
unsigned short getMaxSampleIndex()
Getter for the index of the biggest sample inside the cluster (0...6)
APVRawSamples getRawSamples() const
Get int-array of of 6 APV25 samples.
std::array< APVRawSampleType, c_nAPVSamples > APVRawSamples
Type for array of samples received from DAQ.
VxdID getSensorID() const
Getter for the sensor ID.
short int getCellID() const
Getter for the strip ID.
The Module parameter list class.
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:29
float getNoise(const VxdID &sensorID, const bool &isU, const unsigned short &strip) const
This is the method for getting the noise.
bool isValid()
returns true if the m_aDBObtPtr is valid in the requested IoV
Specific implementation of SensorInfo for SVD Sensors which provides additional sensor specific infor...
Definition: SensorInfo.h:25
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
void initialize() override
Receive and dispatch signal before the start of the event processing.
virtual void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix)
Forward prefixed parameters of this findlet to the module parameter list.
Definition: Findlet.h:69
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
Definition: GeoCache.h:39
const std::set< Belle2::VxdID > getLayers(SensorInfoBase::SensorType sensortype=SensorInfoBase::VXD)
Return a set of all known Layers.
Definition: GeoCache.cc:176
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
Definition: GeoCache.cc:67
const std::set< Belle2::VxdID > & getSensors(Belle2::VxdID ladder) const
Return a set of all sensor IDs belonging to a given ladder.
Definition: GeoCache.cc:204
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
const std::set< Belle2::VxdID > & getLadders(Belle2::VxdID layer) const
Return a set of all ladder IDs belonging to a given layer.
Definition: GeoCache.cc:193
Base class to provide Sensor Information for PXD and SVD.
int getVCells() const
Return number of pixel/strips in v direction.
int getUCells() const
Return number of pixel/strips in u direction.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
baseType getSensorNumber() const
Get the sensor id.
Definition: VxdID.h:100
baseType getLadderNumber() const
Get the ladder id.
Definition: VxdID.h:98
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:96
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.
struct containing a cluster candidate for easier handling
void finalizeCluster(const double pitch, const int stripsInSensor)
calculate cluster properties once a cluster is ready to be stored
float maxSNRinClusterCandidate
Maximum SNR of all the strips in the cluster candidate.
float clusterPosition
Position of the cluster.
std::vector< unsigned short > charges
Vector containing the charges of the corresponding strips that are added.
std::vector< unsigned short > strips
Vector containing strips (DATCONSVDDigits) that are added.
bool add(VxdID nextID, int nextCharge, unsigned short nextCellID, float nextStripSNR, unsigned short maxClusterSize)
add a new strip to the current cluster candidate if possible
int seedCharge
Seed Charge of the cluster.