9#include <svd/modules/svdReconstruction/SVDCoGTimeEstimatorModule.h>
26 setDescription(
"From SVDShaperDigit to SVDRecoDigit. Strip charge is evaluated as the max of the 6 samples; hit time is evaluated as a corrected Centre of Gravity (CoG) time.");
30 "SVDEventInfo name",
string(
""));
32 "ShaperDigits collection name",
string(
""));
34 "RecoDigits collection name",
string(
""));
36 "Correct for the different peaking times of the strips, obtained from local run calibration",
true);
38 "Use the timing informations of the EventT0 in order to calibrate the CoG.",
86 B2DEBUG(25,
" 1. COLLECTIONS:");
107 std::vector<float> probabilities = {0.5};
117 if (relRecoDigitShaperDigit) relRecoDigitShaperDigit.
clear();
125 if (relRecoDigitMCParticle) relRecoDigitMCParticle.
clear();
130 if (relRecoDigitTrueHit) relRecoDigitTrueHit.
clear();
147 samples_vec = shaper.getSamples();
150 VxdID thisSensorID = shaper.getSensorID();
151 bool thisSide = shaper.isUStrip();
152 int thisCellID = shaper.getCellID();
168 B2DEBUG(25,
"ERROR: m_amplitude = " <<
m_amplitude <<
", should be <= 255");
189 B2DEBUG(25,
"thisLayerNumber = " << thisSensorID.
getLayerNumber());
192 B2DEBUG(25,
"thisSide = " << thisSide);
193 B2DEBUG(25,
"thisCellID = " << thisCellID);
194 B2DEBUG(25,
"-----");
203 vector<pair<unsigned int, float> > digit_weights;
204 digit_weights.reserve(1);
205 digit_weights.emplace_back(shaper.getArrayIndex(), 1.0);
206 relRecoDigitShaperDigit.
add(recoDigitIndex, digit_weights.begin(), digit_weights.end());
209 map<unsigned int, float> mc_relations;
210 map<unsigned int, float> truehit_relations;
217 if (!mc_relations.empty()) {
218 relRecoDigitMCParticle.
add(recoDigitIndex, mc_relations.begin(), mc_relations.end());
220 if (!truehit_relations.empty()) {
221 relRecoDigitTrueHit.
add(recoDigitIndex, truehit_relations.begin(), truehit_relations.end());
240 float averagetime = 0;
241 float sumAmplitudes = 0;
244 averagetime += k * samples[k];
245 sumAmplitudes += samples[k];
247 if (sumAmplitudes != 0) {
248 averagetime /= (sumAmplitudes);
253 B2WARNING(
"Trying to divide by 0 (ZERO)! Sum of amplitudes is nullptr! Skipping this SVDShaperDigit!");
264 if (samples[k] > amplitude)
265 amplitude = samples[k];
311 if (!relation)
return;
313 lookup.resize(digits);
314 for (
const auto& element : relation) {
315 lookup[element.getFromIndex()] = &element;
320 std::map<unsigned int, float>& relation,
unsigned int index)
323 if (!lookup.empty() && lookup[index]) {
325 const unsigned int size = element.getSize();
327 for (
unsigned int i = 0; i < size; ++i) {
330 if (element.getWeight(i) < 0)
continue;
331 relation[element.getToIndex(i)] += element.getWeight(i);
@ 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.
Class to store a single element of a relation.
double getCorrectedTimeError(const Belle2::VxdID &sensorID, const bool &isU, const unsigned short &strip, const double &raw_time, const double &raw_timeErr, const int &bin) const
Return the strip time error, given the raw strip time, and tje raw time error.
double getCorrectedTime(const Belle2::VxdID &sensorID, const bool &isU, const unsigned short &strip, const double &raw_time, const int &bin) const
Return the strip time, given the raw strip time.
std::string m_storeRecoDigitsName
Name of the collection to use for the SVDRecoDigits.
float m_chi2
Chi2, to be defined here.
SVDCoGTimeEstimatorModule()
Constructor defining the parameters.
StoreArray< SVDTrueHit > m_storeTrueHits
SVDTrueHits store array.
float CalculateAmplitudeError(VxdID ThisSensorID, bool ThisSide, int ThisCellID)
Function to calculate the amplitude error as the noise of the strip.
std::string m_relShaperDigitMCParticleName
Name of the relation between SVDShaperDigits and MCParticles.
SVDCoGTimeCalibrations m_TimeCal
SVD CoG Time calibrations db object.
bool m_corrPeakTime
correction of peakTime per strip from local calibrations
virtual void initialize() override
Initialize the SVDCoGTimeEstimator.
StoreArray< MCParticle > m_storeMCParticles
MCParticles Store array.
std::string m_storeShaperDigitsName
Name of the collection to use for the SVDShaperDigits.
virtual void event() override
This method is the core of the SVDCoGTimeEstimator.
std::vector< const RelationElement * > RelationLookup
Container for a RelationArray Lookup table.
std::string m_relRecoDigitTrueHitName
Name of the relation between SVDRecoDigits and SVDTrueHits.
float CalculateAmplitude(Belle2::SVDShaperDigit::APVFloatSamples samples)
Function to calculate the amplitude of the shaper, obtained as the largest of the 6 samples.
SVDNoiseCalibrations m_NoiseCal
SVDNoise calibrations db object.
virtual void endRun() override
This method is called if the current run ends.
std::string m_storeTrueHitsName
Name of the collection to use for the SVDTrueHits.
virtual ~SVDCoGTimeEstimatorModule()
default destructor
virtual void terminate() override
This method is called at the end of the event processing.
std::string m_relRecoDigitMCParticleName
Name of the relation between SVDRecoDigits and MCParticles.
void fillRelationMap(const RelationLookup &lookup, std::map< unsigned int, float > &relation, unsigned int index)
Add the relation from a given SVDShaperDigit index to a map.
std::string m_storeMCParticlesName
Name of the collection to use for the MCParticles.
int m_NumberOfAPVSamples
number of samples
StoreArray< SVDRecoDigit > m_storeReco
SVDRecoDigits store array.
float CalculateWeightedMeanPeakTimeError(Belle2::SVDShaperDigit::APVFloatSamples samples)
Function to calculate the peak time error.
SVDPulseShapeCalibrations m_PulseShapeCal
SVDPulseShaper calibrations db object.
float CalculateChi2()
Function to calculate chi2, that is not used here, so just set at 0.01.
std::string m_relShaperDigitTrueHitName
Name of the relation between SVDShaperDigits and SVDTrueHits.
RelationLookup m_trueRelation
Lookup table for SVDShaperDigit->SVDTrueHit relation.
virtual void beginRun() override
Called when entering a new run.
StoreArray< SVDShaperDigit > m_storeShaper
store arrays
float m_weightedMeanTime
The peak time estimation.
std::string m_svdEventInfoName
Name of the SVDEventInfo object.
void createRelationLookup(const RelationArray &relation, RelationLookup &lookup, size_t digits)
Create lookup maps for relations FIXME: This has to be significantly simplified here,...
float m_DeltaT
Time width of a sampling.
RelationLookup m_mcRelation
Lookup table for SVDShaperDigit->MCParticle relation.
bool m_StopCreationReco
To stop creation of the SVDShaperDigit if something is wrong.
StoreObjPtr< SVDEventInfo > m_storeSVDEvtInfo
storage for SVDEventInfo object
float m_weightedMeanTimeError
The peak time estimation error.
bool m_calEventT0
Parameters for the corrections.
float CalculateWeightedMeanPeakTime(Belle2::SVDShaperDigit::APVFloatSamples samples)
Function to calculate the peak time, obtained as the weighted mean of the time of the samples,...
float m_amplitudeError
The shaper amplitude estimation error.
float m_amplitude
The shaper amplitude estimation.
std::string m_relRecoDigitShaperDigitName
Name of the relation between SVDRecoDigits and SVDShaperDigits.
Class to store SVD mode information.
baseType getTriggerBin() const
Get the triggerBin id.
uint8_t baseType
The base integer type for SVDModeByte.
float getNoise(const VxdID &sensorID, const bool &isU, const unsigned short &strip) const
This is the method for getting the noise.
long int getADCFromCharge(const Belle2::VxdID &sensorID, const bool &isU, const unsigned short &strip, const double &charge) const
Return a signed long integer corresponding to the ADC pulse height per strip, provided the charge [e]...
double getChargeFromADC(const Belle2::VxdID &sensorID, const bool &isU, const unsigned short &strip, const double &pulseADC) const
Return the charge (number of electrons/holes) collected on a specific strip, given the number of ADC ...
float getPeakTime(const VxdID &sensorID, const bool &isU, const unsigned short &strip) const
Return the peaking time of the strip.
The SVD ShaperDigit class.
std::array< APVFloatSampleType, c_nAPVSamples > APVFloatSamples
array of APVFloatSampleType objects
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.
Class to uniquely identify a any structure of the PXD and SVD.
baseType getSensorNumber() const
Get the sensor id.
baseType getLadderNumber() const
Get the ladder id.
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.
Abstract base class for different kinds of events.