9#include <svd/modules/svdReconstruction/SVDSimpleClusterizerModule.h>
11#include <framework/datastore/DataStore.h>
12#include <framework/datastore/RelationArray.h>
13#include <framework/datastore/RelationIndex.h>
14#include <framework/logging/Logger.h>
16#include <svd/geometry/SensorInfo.h>
17#include <svd/dataobjects/SVDEventInfo.h>
34 m_cutSeed(5.0), m_cutAdjacent(3.0), m_sizeHeadTail(3), m_cutCluster(0), m_useDB(true)
37 setDescription(
"Clusterize SVDRecoDigits fitted by the Center of Gravity estimator");
42 "SVDRecoDigits collection name",
string(
""));
44 "SVDCluster collection name",
string(
""));
46 "TrueHit collection name",
string(
""));
48 "MCParticles collection name",
string(
""));
50 "SVDShaperDigits collection name",
55 "SN for digits to be considered for clustering",
m_cutAdjacent);
57 "SN for digits to be considered as seed",
m_cutSeed);
59 "Cluster size at which to switch to Analog head tail algorithm",
m_sizeHeadTail);
61 "minimum value of the SNR of the cluster",
m_cutCluster);
63 " int to choose time algorithm: 0 = 6-sample CoG (default for 6-sample acquisition mode), 1 = 3-sample CoG (default for 3-sample acquisition mode), 2 = 3-sample ELS",
66 " if true returns the calibrated time instead of the raw time for 3-sample time algorithms",
69 "if false use clustering module parameters",
m_useDB);
71 "Set the SVDEventInfo to use",
string(
"SVDEventInfoSim"));
109 B2DEBUG(1,
"SVDSimpleClusterizer Parameters (in default system unit, *=cannot be set directly):");
111 B2DEBUG(1,
" 1. COLLECTIONS:");
121 B2DEBUG(1,
" 2. CLUSTERING:");
123 B2DEBUG(1,
" --> Seed cut: " <<
m_cutSeed);
140 if (relClusterMCParticle) relClusterMCParticle.
clear();
144 if (relClusterDigit) relClusterDigit.
clear();
148 if (relClusterTrueHit) relClusterTrueHit.
clear();
162 while (i < nDigits) {
178 B2DEBUG(10,
"Noise = " << thisNoise <<
" e-, Charge = " << thisCharge);
188 aStrip.
charge = thisCharge;
189 aStrip.
cellID = thisCellID;
190 aStrip.
noise = thisNoise;
196 if (! clusterCandidate.
add(thisSensorID, thisSide, aStrip)) {
199 if (clusterCandidate.
size() > 0) {
212 if (! clusterCandidate.
add(thisSensorID, thisSide, aStrip))
213 B2WARNING(
"this state is forbidden!!");
220 if (clusterCandidate.
size() > 0) {
242 VxdID sensorID = cluster.getSensorID();
243 bool isU = cluster.isUSide();
244 float seedCharge = cluster.getSeedCharge();
245 float charge = cluster.getCharge();
246 float size = cluster.size();
247 float SNR = cluster.getSNR();
248 float position = cluster.getPosition();
251 float time = cluster.getTime();
252 float timeError = cluster.getTimeError();
253 int firstFrame = cluster.getFirstFrame();
259 m_svdEventInfoName =
"SVDEventInfo";
265 if (!eventinfo) B2ERROR(
"No SVDEventInfo!");
272 float caltime = time;
282 time = eventinfo->getTimeInFTSWReference(caltime, firstFrame);
285 m_storeClusters.
appendNew(sensorID, isU, position, positionError, time, timeError, charge, seedCharge, size, SNR, -1, firstFrame);
290 map<int, float> mc_relations;
291 map<int, float> truehit_relations;
293 vector<pair<int, float> > digit_weights;
294 digit_weights.reserve(size);
296 std::vector<stripInCluster> strips = cluster.getStripsInCluster();
298 for (
auto strip : strips) {
301 if (relDigitMCParticle) {
306 if (mcRel.weight < 0)
continue;
307 mc_relations[mcRel.indexTo] += mcRel.
weight;
311 if (relDigitTrueHit) {
316 if (trueRel.weight < 0)
continue;
317 truehit_relations[trueRel.indexTo] += trueRel.
weight;
321 digit_weights.push_back(make_pair(strip.recoDigitIndex, strip.charge));
326 if (!mc_relations.empty()) {
327 relClusterMCParticle.
add(clsIndex, mc_relations.begin(), mc_relations.end());
329 if (!truehit_relations.empty()) {
330 relClusterTrueHit.
add(clsIndex, truehit_relations.begin(), truehit_relations.end());
333 relClusterDigit.
add(clsIndex, digit_weights.begin(), digit_weights.end());
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Low-level class to create/modify relations between StoreArrays.
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.
void clear() override
Clear all elements from the relation.
Provides access to fast ( O(log n) ) bi-directional lookups on a specified relation.
range_from getElementsFrom(const FROM *from) const
Return a range of all elements pointing from the given object.
double getCorrectedTime(const Belle2::VxdID &sensorID, const bool &isU, const unsigned short &strip, const double &raw_time, const int &bin) const
Return the charge (number of electrons/holes) collected on a specific strip, given the number of ADC ...
double getCorrectedTime(const Belle2::VxdID &sensorID, const bool &isU, const unsigned short &strip, const double &raw_time, const int &bin) const
Return the charge (number of electrons/holes) collected on a specific strip, given the number of ADC ...
double getMinClusterSNR(const Belle2::VxdID &sensorID, const bool &isU) const
Return the minimum SNR for the cluster.
double getMinSeedSNR(const Belle2::VxdID &sensorID, const bool &isU) const
Return the minimum SNR for the seed.
double getMinAdjSNR(const Belle2::VxdID &sensorID, const bool &isU) const
Return the minimum SNR for the adjacent.
float getNoiseInElectrons(const VxdID &sensorID, const bool &isU, const unsigned short &strip) const
This method provides the correct noise conversion into electrons, taking into account that the noise ...
double getCorrectedClusterPositionError(const Belle2::VxdID &sensorID, const bool &isU, const int &size, const double &raw_error) const
Return the corrected cluster position error.
std::string m_storeRecoDigitsName
Name of the collection to use for the SVDRecoDigits.
SVDOldDefaultErrorScaleFactors m_OldDefaultSF
SVDCluster calibrations db object.
StoreArray< SVDTrueHit > m_storeTrueHits
Collection of SVDTrueHits.
virtual void initialize() override
Initialize the module.
StoreArray< MCParticle > m_storeMCParticles
Collection of MCParticles.
std::string m_storeShaperDigitsName
Name of the collection to use for the SVDShaperDigits.
virtual void event() override
do the clustering
SVDSimpleClusterizerModule()
Constructor defining the parameters.
void writeClusters(SimpleClusterCandidate clusterCand)
write the cluster candidate to clusters
std::string m_relRecoDigitTrueHitName
Name of the relation between SVDRecoDigits and SVDTrueHits.
SVDNoiseCalibrations m_NoiseCal
SVDNoise calibrations db object.
double m_cutCluster
Cluster cut in units of m_elNoise, not included (yet?)
std::string m_storeTrueHitsName
Name of the collection to use for the SVDTrueHits.
SVD3SampleCoGTimeCalibrations m_3CoGTimeCal
SVD 3-sample CoG Time calibrations db object.
std::string m_relRecoDigitMCParticleName
Name of the relation between SVDRecoDigits and MCParticles.
std::string m_svdEventInfoSet
Name of the SVDEventInfo to be used instead of SVDEventInfo.
SVDClustering m_ClusterCal
SVDCluster calibrations db object.
SVD3SampleELSTimeCalibrations m_3ELSTimeCal
SVD 3-sample ELS Time calibrations db object.
std::string m_storeMCParticlesName
Name of the collection to use for the MCParticles.
StoreArray< SVDRecoDigit > m_storeDigits
Collection of SVDRecoDigits.
int m_sizeHeadTail
Size of the cluster at which we switch from Center of Gravity to Analog Head Tail.
int m_timeAlgorithm
selects the algorithm to compute the cluster time 0 = 6-sample CoG (default) 1 = 3-sample CoG (TO DO:...
std::string m_storeClustersName
Name of the collection to use for the SVDClusters.
double m_cutSeed
Seed cut in units of noise.
std::string m_relClusterMCParticleName
Name of the relation between SVDClusters and MCParticles.
bool m_calibrate3SampleWithEventT0
if true returns the calibrated time instead of the raw time for 3-sample time algorithms
StoreArray< SVDCluster > m_storeClusters
Collection of SVDClusters.
std::string m_relClusterRecoDigitName
Name of the relation between SVDClusters and SVDRecoDigits.
bool m_useDB
if true takes the clusterizer cuts from the DB object
double m_cutAdjacent
Adjacent cut in units of noise.
std::string m_relClusterTrueHitName
Name of the relation between SVDClusters and SVDTrueHits.
Class representing a cluster candidate during simple clustering of the SVD.
bool add(VxdID vxdID, bool isUside, struct stripInCluster &aStrip)
Add a Strip to the current cluster.
void finalizeCluster()
compute the position, time and their error of the cluster
bool isGoodCluster()
return true if the cluster candidate can be promoted to cluster
int size() const
return the cluster size (number of strips of the cluster
const std::string & getName() const
Return name under which the object is saved in the DataStore.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
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.
int getEntries() const
Get the number of objects in the array.
void clear() override
Delete all entries in this array.
Type-safe access to single objects in the data store.
bool isValid() const
Check whether the object was created.
Class to uniquely identify a any structure of the PXD and SVD.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Namespace to encapsulate code needed for simulation and reconstrucion of the SVD.
Abstract base class for different kinds of events.
Element type for the index.
RelationElement::weight_type weight
weight of the relation.
structure containing the relevant informations of eachstrip of the cluster
float timeError
6-sample CoG strip time error
int recoDigitIndex
index of the reco digit
float time
6-sample CoG strip time