9#include <svd/modules/svdReconstruction/SVDClusterizerModule.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>
15#include <framework/core/Environment.h>
17#include <svd/geometry/SensorInfo.h>
18#include <svd/dataobjects/SVDEventInfo.h>
20#include <svd/reconstruction/SVDReconstructionBase.h>
22#include <svd/reconstruction/SVDRecoTimeFactory.h>
23#include <svd/reconstruction/SVDRecoChargeFactory.h>
24#include <svd/reconstruction/SVDRecoPositionFactory.h>
45 m_cutSeed(5.0), m_cutAdjacent(3.0), m_useDB(true)
48 setDescription(
"This module produces SVDClusters from SVDShaperDigits, providing 1-D hit position, charge and time on SVD sensors.");
53 "SVDEventInfo collection name.",
string(
"SVDEventInfo"));
55 "SVDShaperDigits collection name.",
string(
""));
57 "SVDCluster collection name.",
string(
""));
59 "TrueHit collection name.",
string(
""));
61 "MCParticles collection name.",
string(
""));
65 "minimum SNR for strips to be considered for clustering. Overwritten by the dbobject, unless you set useDB = False.",
68 "if True, returns the raw cluster time (to be used for time calibration).",
73 "minimum SNR for strips to be considered as cluster seed. Overwritten by the dbobject, unless you set useDB = False.",
m_cutSeed);
75 "minimum value of the SNR of the cluster. Overwritten by the dbobject, unless you set useDB = False.",
m_cutCluster);
77 "cluster-time reconstruction algorithm for the 6-sample DAQ mode: CoG6 = 6-sample CoG (default), CoG3 = 3-sample CoG, ELS3 = 3-sample ELS. Overwritten by the dbobject, unless you set useDB = False.",
80 "cluster-time reconstruction algorithm for the 3-sample DAQ mode: CoG6 = 6-sample CoG, CoG3 = 3-sample CoG (default), ELS3 = 3-sample ELS. Overwritten by the dbobject, unless you set useDB = False.",
83 "cluster-charge reconstruction algorithm for 6-sample DAQ mode: MaxSample (default), SumSamples, ELS3 = 3-sample ELS. Overwritten by the dbobject, unless you set useDB = False.",
86 "cluster-charge reconstruction algorithm for 3-sample DAQ mode: MaxSample (default), SumSamples, ELS3 = 3-sample ELS. Overwritten by the dbobject, unless you set useDB = False.",
89 "cluster-position reconstruction algorithm for 6-sample DAQ mode: old (default), CoGOnly. Overwritten by the dbobject, unless you set useDB = False.",
92 "cluster-position reconstruction algorithm for 3-sample DAQ mode: old (default), CoGOnly. Overwritten by the dbobject, unless you set useDB = False.",
96 "strip-time reconstruction algorithm used for cluster position reconstruction for the 6-sample DAQ mode: dontdo = not done (default), CoG6 = 6-sample CoG, CoG3 = 3-sample CoG, ELS3 = 3-sample ELS. Overwritten by the dbobject, unless you set useDB = False.",
99 "strip-time reconstruction algorithm used for cluster position reconstruction for the 3-sample DAQ mode: dontdo = not done (default), CoG6 = 6-sample CoG, CoG3 = 3-sample CoG, ELS3 = 3-sample ELS. Overwritten by the dbobject, unless you set useDB = False.",
102 "strip-charge reconstruction algorithm used for cluster position reconstruction for the 6-sample DAQ mode: dontdo = not done, MaxSample, SumSamples, ELS3 = 3-sample ELS. Overwritten by the dbobject, unless you set useDB = False.",
105 "strip-charge reconstruction algorithm used for cluster position reconstruction for the 3-sample DAQ mode: dontdo = not done, MaxSample, SumSamples, ELS3 = 3-sample ELS. Overwritten by the dbobject, unless you set useDB = False.",
109 "if False, use clustering and reconstruction configuration module parameters",
m_useDB);
117 B2FATAL(
"no valid configuration found for SVD reconstruction");
119 B2DEBUG(20,
"SVDRecoConfiguration: from now on we are using " <<
m_recoConfig->get_uniqueID());
178 string israwtime =
"";
181 ", cluster charge algorithm: " <<
188 ", cluster charge algorithm: " <<
231 B2DEBUG(20,
"SVDClusterizer Parameters (in default system unit, *=cannot be set directly):");
233 B2DEBUG(20,
" 1. COLLECTIONS:");
238 B2DEBUG(20,
" 2. RELATIONS:");
244 B2DEBUG(20,
" 3. CLUSTERING:");
246 B2DEBUG(20,
" --> Seed cut: " <<
m_cutSeed);
262 if (relClusterMCParticle) relClusterMCParticle.
clear();
266 if (relClusterDigit) relClusterDigit.
clear();
270 if (relClusterTrueHit) relClusterTrueHit.
clear();
286 VxdID thisSensorID = currentDigit.getSensorID();
287 bool thisSide = currentDigit.isUStrip();
288 int thisCellID = currentDigit.getCellID();
298 int thisCharge = currentDigit.getMaxADCCounts();
299 B2DEBUG(20,
"Noise = " << thisNoise <<
" ADC, MaxSample = " << thisCharge <<
" ADC");
308 aStrip.
cellID = thisCellID;
309 aStrip.
noise = thisNoise;
310 aStrip.
samples = currentDigit.getSamples();
313 if (! rawCluster.
add(thisSensorID, thisSide, aStrip)) {
323 if (! rawCluster.
add(thisSensorID, thisSide, aStrip))
324 B2WARNING(
"this state is forbidden!!");
341 bool isU = rawCluster.
isUSide();
342 int size = rawCluster.
getSize();
349 if (!eventinfo) B2ERROR(
"No SVDEventInfo!");
358 double time = std::numeric_limits<double>::quiet_NaN();
359 double timeError = std::numeric_limits<double>::quiet_NaN();
360 int firstFrame = std::numeric_limits<int>::quiet_NaN();
362 double charge = std::numeric_limits<double>::quiet_NaN();
363 double seedCharge = std::numeric_limits<float>::quiet_NaN();
364 double SNR = std::numeric_limits<double>::quiet_NaN();
366 double position = std::numeric_limits<float>::quiet_NaN();
367 double positionError = std::numeric_limits<float>::quiet_NaN();
390 B2FATAL(
"SVD Reconstruction not available for this cluster (unrecognized or not supported number of acquired APV samples!!");
393 time = eventinfo->getTimeInFTSWReference(time, firstFrame);
400 m_storeClusters.
appendNew(sensorID, isU, position, positionError, time, timeError, charge, seedCharge, size, SNR, -1,
403 B2DEBUG(20,
"CLUSTER SIZE = " << size);
404 B2DEBUG(20,
" time = " << time <<
", timeError = " << timeError <<
", firstframe = " << firstFrame);
405 B2DEBUG(20,
" charge = " << charge <<
", SNR = " << SNR <<
", seedCharge = " << seedCharge);
406 B2DEBUG(20,
" position = " << position <<
", positionError = " << positionError);
440 map<int, float> mc_relations;
441 map<int, float> truehit_relations;
443 vector<pair<int, float> > digit_weights;
448 for (
const auto& strip : strips) {
451 if (relDigitMCParticle) {
456 if (mcRel.weight < 0)
continue;
457 mc_relations[mcRel.indexTo] += mcRel.
weight;
461 if (relDigitTrueHit) {
466 if (trueRel.weight < 0)
continue;
467 truehit_relations[trueRel.indexTo] += trueRel.
weight;
471 digit_weights.push_back(make_pair(strip.shaperDigitIndex, strip.maxSample));
475 if (!mc_relations.empty()) {
476 relClusterMCParticle.
add(clsIndex, mc_relations.begin(), mc_relations.end());
478 if (!truehit_relations.empty()) {
479 relClusterTrueHit.
add(clsIndex, truehit_relations.begin(), truehit_relations.end());
482 relClusterDigit.
add(clsIndex, digit_weights.begin(), digit_weights.end());
519 double trkAngle = 0.;
525 trkAngle = atan2(trkLength, trkHeight);
532 float fudgeFactor = (float) gRandom->Gaus(0., sigma);
535 B2DEBUG(20,
"Layer number: " << layerNum <<
", is U side: " << isU <<
", track angle: " << trkAngle <<
", sigma: " << sigma <<
536 ", cluster position: " << clsPosition <<
", fudge factor: " << fudgeFactor);
553 float fudgeFactor = (float) gRandom->Gaus(0., sigma);
556 B2DEBUG(20,
"Layer number: " << sensorID.
getLayerNumber() <<
", is U side: " << isU <<
", sigma: " << sigma <<
557 ", cluster time: " << clsTime <<
", fudge factor: " << fudgeFactor);
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
bool isMC() const
Do we have generated, not real data?
static Environment & Instance()
Static method to get a reference to the Environment instance.
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 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.
double getFudgeFactor(const Belle2::VxdID &sensorID, const bool &isU, const double &trkAngle) const
Return the MC fudge factor.
double getFudgeFactor(const Belle2::VxdID &sensorID, const bool &isU) const
Return the MC fudge factor.
float getNoise(const VxdID &sensorID, const bool &isU, const unsigned short &strip) const
This is the method for getting the noise.
The SVD ShaperDigit class.
Class SVDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Class representing a raw cluster candidate during clustering of the SVD.
const std::vector< StripInRawCluster > getStripsInRawCluster() const
bool add(VxdID vxdID, bool isUside, struct StripInRawCluster &aStrip)
Add a Strip to the current cluster.
VxdID getSensorID() const
virtual void computeClusterCharge(Belle2::SVD::RawCluster &rawCluster, double &charge, double &SNR, double &seedCharge)=0
computes the cluster charge, SNR and seedCharge
void set_stripChargeAlgo(const std::string &user_stripChargeAlgo)
set which algorithm to use for strip charge in cluster position reconstruction
virtual void computeClusterPosition(Belle2::SVD::RawCluster &rawCluster, double &position, double &positionError)=0
computes the cluster position and position error
void set_stripTimeAlgo(const std::string &user_stripTimeAlgo)
set which algorithm to use for strip time in cluster position reconstruction, 'dontdo' will skip it
virtual void computeClusterTime(Belle2::SVD::RawCluster &rawCluster, double &time, double &timeError, int &firstFrame)=0
computes the cluster time, timeError and FirstFrame
std::string m_stripChargeRecoWith3SamplesAlgorithm
string storing the strip charge reconstruction algorithm for cluster reconstruction in 3-sample DAQ m...
double applyLorentzShiftCorrection(double position, VxdID vxdID, bool isU)
returns the position of the cluster after lorentz shift correction
SVDClusterCharge * m_charge6SampleClass
cluster charge class for the 6-sample acquisition mode
SVDClusterCharge * m_charge3SampleClass
cluster charge class for the 3-sample acquisition mode
SVDClusterPosition * m_position3SampleClass
cluster position class for the 3-sample acquisition mode
StoreArray< SVDTrueHit > m_storeTrueHits
Collection of SVDTrueHits.
StoreArray< SVDShaperDigit > m_storeDigits
Collection of SVDShaperDigits.
std::string m_relShaperDigitMCParticleName
Name of the relation between SVDShaperDigits and MCParticles.
DBObjPtr< SVDClusterTimeShifter > m_svdClusterTimeShifter
SVDCluster time shift.
void initialize() override
Initialize the module.
StoreArray< MCParticle > m_storeMCParticles
Collection of MCParticles.
SVDMCClusterPositionFudgeFactor m_mcPositionFudgeFactor
SVDMCClusterPositionFudgeFactor db object.
std::string m_storeShaperDigitsName
Name of the collection to use for the SVDShaperDigits.
void event() override
does the actual clustering
SVDNoiseCalibrations m_NoiseCal
SVDNoise calibrations db object.
void endRun() override
delete pointers
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.
SVDClustering m_ClusterCal
SVDCluster calibrations db object.
SVDClusterTime * m_time6SampleClass
cluster time class for the 6-sample acquisition mode
std::string m_storeMCParticlesName
Name of the collection to use for the MCParticles.
bool m_shiftSVDClusterTime
if true applies SVDCluster time shift based on cluster-size
void alterClusterPosition()
alter the cluster position (applied on MC to match resolution measured on data)
void writeClusterRelations(const Belle2::SVD::RawCluster &rawCluster)
writes the relations of the SVDClusters with the other StoreArrays
std::string m_chargeRecoWith6SamplesAlgorithm
string storing the cluster charge reconstruction algorithm in 6-sample DAQ mode
std::string m_chargeRecoWith3SamplesAlgorithm
string storing the cluster charge reconstruction algorithm in 3-sample DAQ mode
int m_numberOfAcquiredSamples
number of acquired samples, can be 6 or 3 (1 is not supported!)
std::string m_relShaperDigitTrueHitName
Name of the relation between SVDShaperDigits and SVDTrueHits.
std::string m_positionRecoWith3SamplesAlgorithm
string storing the cluster position reconstruction algorithm in 3-sample DAQ mode
std::string m_stripTimeRecoWith6SamplesAlgorithm
string storing the strip time reconstruction algorithm for cluster position reconstruction in 6-sampl...
void beginRun() override
configure clustering
SVDClusterPosition * m_position6SampleClass
cluster position class for the 6-sample acquisition mode
std::string m_stripChargeRecoWith6SamplesAlgorithm
string storing the strip charge reconstruction algorithm for cluster position reconstruction in 6-sam...
DBObjPtr< HardwareClockSettings > m_hwClock
systems clock
std::string m_svdEventInfoName
Name of the collection to use for the SVDEventInfo.
std::string m_storeClustersName
Name of the collection to use for the SVDClusters.
SVDMCClusterTimeFudgeFactor m_mcTimeFudgeFactor
SVDMCClusterTimeFudgeFactor db object.
double m_cutSeed
Seed cut in units of noise.
std::string m_relClusterShaperDigitName
Name of the relation between SVDClusters and SVDShaperDigits.
void shiftSVDClusterTime()
Apply cluster time shift depending on cluster size.
std::string m_relClusterMCParticleName
Name of the relation between SVDClusters and MCParticles.
void finalizeCluster(Belle2::SVD::RawCluster &rawCluster)
computes charge, position and time of the raw cluster and appends the new SVDCluster to the StoreArra...
std::string m_stripTimeRecoWith3SamplesAlgorithm
string storing the strip time reconstruction algorithm for cluster position reconstruction in 3-sampl...
SVDClusterizerModule()
Constructor defining the parameters.
std::string m_timeRecoWith6SamplesAlgorithm
string storing the cluster time reconstruction algorithm in 6-sample DAQ mode
DBObjPtr< SVDRecoConfiguration > m_recoConfig
SVD Reconstruction Configuration payload.
std::string m_positionRecoWith6SamplesAlgorithm
string storing the cluster position reconstruction algorithm in 6-sample DAQ mode
StoreArray< SVDCluster > m_storeClusters
Collection of SVDClusters.
std::string m_timeRecoWith3SamplesAlgorithm
string storing the cluster time reconstruction algorithm in 3-sample DAQ mode
bool m_useDB
if true takes the clusterizer cuts and reconstruction configuration from the DB objects
SVDClusterTime * m_time3SampleClass
cluster time class for the 3-sample acquisition mode
void alterClusterTime()
alter the cluster time (applied on MC to match resolution measured on data)
double m_cutAdjacent
Adjacent cut in units of noise.
std::string m_relClusterTrueHitName
Name of the relation between SVDClusters and SVDTrueHits.
bool m_returnRawClusterTime
if true cluster time is not calibrated, to be used for time calibration
static SVDClusterCharge * NewCharge(const std::string &description)
static function that returns the class to compute the cluster charge
static SVDClusterPosition * NewPosition(const std::string &description)
static function that returns the class to compute the cluster position
static SVDClusterTime * NewTime(const std::string &description, const bool &returnRawClusterTime)
static function that returns the class to compute the cluster time
Class to check whether the reconstruction algorithms are available or not.
bool isChargeAlgorithmAvailable(TString chargeAlg)
bool isTimeAlgorithmAvailable(TString timeAlg)
bool isPositionAlgorithmAvailable(TString positionAlg)
Specific implementation of SensorInfo for SVD Sensors which provides additional sensor specific infor...
const ROOT::Math::XYZVector & getLorentzShift(double uCoord, double vCoord) const
Calculate Lorentz shift along a given coordinate in a magnetic field at a given position.
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.
float getEntryU() const
Return local u coordinate of hit when entering silicon.
float getExitW() const
Return local w coordinate of hit at the endpoint of the track.
float getEntryW() const
Return local w coordinate of the start point of the track.
float getExitU() const
Return local u coordinate of hit at the endpoint of the track.
float getExitV() const
Return local v coordinate of hit at the endpoint of the track.
float getEntryV() const
Return local v coordinate of the start point of the track.
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
static GeoCache & getInstance()
Return a reference to the singleton instance.
Class to uniquely identify a any structure of the PXD and SVD.
baseType getLayerNumber() const
Get the layer id.
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 each strip of the raw cluster
Belle2::SVDShaperDigit::APVFloatSamples samples
ADC of the acquired samples.
int shaperDigitIndex
index of the shaper digit
int maxSample
ADC max of the acquired samples.