9#include <svd/modules/svdReconstruction/SVDNNShapeReconstructorModule.h>
11#include <framework/datastore/DataStore.h>
12#include <framework/datastore/StoreArray.h>
13#include <framework/logging/Logger.h>
15#include <mdst/dataobjects/MCParticle.h>
16#include <svd/dataobjects/SVDTrueHit.h>
17#include <svd/dataobjects/SVDShaperDigit.h>
18#include <svd/dataobjects/SVDRecoDigit.h>
19#include <mva/dataobjects/DatabaseRepresentationOfWeightfile.h>
21#include <svd/reconstruction/NNWaveFitTool.h>
27using namespace std::placeholders;
42 B2DEBUG(200,
"Now in SVDNNShapeReconstructorModule ctor");
49 "Shaperdigits collection name",
string(
""));
51 "RecoDigits collection name",
string(
""));
53 "TrueHits collection name",
string(
""));
55 "MCParticles collection name",
string(
""));
59 "SVDEventInfo name",
string(
""));
62 "Name of time fitter data file",
string(
"SVDTimeNet_6samples"));
63 addParam(
"CalibratePeak",
m_calibratePeak,
"Use calibrattion (vs. default) for peak widths and positions",
bool(
false));
90 RelationArray relRecoDigitShaperDigits(storeRecoDigits, storeShaperDigits);
91 RelationArray relRecoDigitTrueHits(storeRecoDigits, storeTrueHits);
92 RelationArray relRecoDigitMCParticles(storeRecoDigits, storeMCParticles);
93 RelationArray relShaperDigitTrueHits(storeShaperDigits, storeTrueHits);
94 RelationArray relShaperDigitMCParticles(storeShaperDigits, storeMCParticles);
118 B2INFO(
" 1. COLLECTIONS:");
129 B2INFO(
" 2. CALIBRATION:");
144 if (!relation)
return;
146 lookup.resize(digits);
147 for (
const auto& element : relation) {
148 lookup[element.getFromIndex()] = &element;
153 std::map<unsigned int, float>& relation,
unsigned int index)
156 if (!lookup.empty() && lookup[index]) {
158 const unsigned int size = element.getSize();
160 for (
unsigned int i = 0; i < size; ++i) {
163 if (element.getWeight(i) < 0)
continue;
164 relation[element.getToIndex(i)] += element.getWeight(i);
178 size_t nDigits = storeShaperDigits.
getEntries();
179 B2DEBUG(90,
"Initial size of StoreDigits array: " << nDigits);
188 storeRecoDigits.
clear();
190 RelationArray relRecoDigitMCParticle(storeRecoDigits, storeMCParticles,
192 if (relRecoDigitMCParticle) relRecoDigitMCParticle.
clear();
194 RelationArray relRecoDigitShaperDigit(storeRecoDigits, storeShaperDigits,
196 if (relRecoDigitShaperDigit) relRecoDigitShaperDigit.
clear();
198 RelationArray relRecoDigitTrueHit(storeRecoDigits, storeTrueHits,
200 if (relRecoDigitTrueHit) relRecoDigitTrueHit.
clear();
210 vector<pair<unsigned short, unsigned short> > sensorDigits;
211 VxdID lastSensorID(0);
212 size_t firstSensorDigit = 0;
213 for (
size_t iDigit = 0; iDigit < nDigits; ++iDigit) {
217 if (sensorID != lastSensorID) {
218 sensorDigits.push_back(make_pair(firstSensorDigit, iDigit));
219 firstSensorDigit = iDigit;
220 lastSensorID = sensorID;
224 sensorDigits.push_back(make_pair(firstSensorDigit, nDigits));
227 for (
auto id_indices : sensorDigits) {
229 unsigned int firstDigit = id_indices.first;
230 unsigned int lastDigit = id_indices.second;
232 const SVDShaperDigit& exampleDigit = *storeShaperDigits[firstDigit];
238 B2DEBUG(300,
"Reconstructing digits " << firstDigit <<
" to " << lastDigit);
239 for (
size_t iDigit = firstDigit; iDigit < lastDigit; ++iDigit) {
242 unsigned short stripNo = shaperDigit.
getCellID();
243 bool validDigit =
true;
244 const double triggerBinSep = 4 * 1.96516;
245 double apvPhase = triggerBinSep * (0.5 +
static_cast<int>(modeByte.
getTriggerBin()));
252 double stripSignalWidth = 270;
253 double stripT0 = isU ? 2.5 : -2.2;
257 - 0.25 * stripSignalWidth;
260 B2DEBUG(300,
"Strip parameters: stripNoiseADU: " << stripNoiseADU <<
261 " Width: " << stripSignalWidth <<
267 transform(samples.begin(), samples.end(), normedSamples.begin(),
268 bind(divides<float>(), _1, stripNoiseADU));
280 os <<
"Input to NNFitter: iDigit = " << iDigit << endl <<
"Samples: ";
281 copy(normedSamples.begin(), normedSamples.end(), ostream_iterator<double>(os,
" "));
283 std::shared_ptr<nnFitterBinData> pStrip =
m_fitter.
getFit(normedSamples, stripSignalWidth);
284 os <<
"Output from NNWaveFitter: " << endl;
285 copy(pStrip->begin(), pStrip->end(), ostream_iterator<double>(os,
" "));
289 B2DEBUG(200, os.str());
291 double stripTime, stripTimeError;
292 tie(stripTime, stripTimeError) = fitTool.
getTimeShift(*pStrip);
294 double stripAmplitude, stripAmplitudeError, stripChi2;
295 tie(stripAmplitude, stripAmplitudeError, stripChi2) =
301 <<
" Time: " << stripTime <<
" +/- " << stripTimeError
302 <<
" Amplitude: " << stripAmplitude <<
" +/- " << stripAmplitudeError
303 <<
" Chi2: " << stripChi2
307 map<unsigned int, float> mc_relations;
308 map<unsigned int, float> truehit_relations;
309 vector<pair<unsigned int, float> > digit_weights;
310 digit_weights.reserve(1);
316 digit_weights.emplace_back(iDigit, 1.0);
319 int recoDigitIndex = storeRecoDigits.
getEntries();
322 stripAmplitudeError, stripTime, stripTimeError, *pStrip, stripChi2)
326 if (!mc_relations.empty()) {
327 relRecoDigitMCParticle.
add(recoDigitIndex, mc_relations.begin(), mc_relations.end());
329 if (!truehit_relations.empty()) {
330 relRecoDigitTrueHit.
add(recoDigitIndex, truehit_relations.begin(), truehit_relations.end());
332 relRecoDigitShaperDigit.
add(recoDigitIndex, digit_weights.begin(), digit_weights.end());
337 B2DEBUG(100,
"Number of RecoDigits: " << storeRecoDigits.
getEntries());
Class for accessing objects in the database.
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
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.
Class to store SVD mode information.
baseType getTriggerBin() const
Get the triggerBin id.
float getNoise(const VxdID &sensorID, const bool &isU, const unsigned short &strip) const
This is the method for getting the noise.
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.
float getWidth(const VxdID &sensorID, const bool &isU, const unsigned short &strip) const
Return the width of the pulse shape for a given strip.
The SVD ShaperDigit class.
VxdID getSensorID() const
Get the sensor ID.
APVFloatSamples getSamples() const
Get array of samples.
short int getCellID() const
Get strip ID.
bool isUStrip() const
Get strip direction.
void setNetwrok(const std::string &xmlData)
Set proper network definition file.
const NNWaveFitTool & getFitTool() const
Get a handle to a NNWaveFit object.
std::shared_ptr< nnFitterBinData > getFit(const apvSamples &samples, double tau)
Fitting method Send data and get rseult structure.
std::string m_storeRecoDigitsName
Name of the collection to use for the SVDRecoDigits.
std::string m_relShaperDigitMCParticleName
Name of the relation between SVDShaperDigits and MCParticles.
bool m_writeRecoDigits
Write SVDRecoDigits? (no in normal operation)
virtual void initialize() override
Initialize the module.
SVDNNShapeReconstructorModule()
Constructor defining the parameters.
std::string m_storeShaperDigitsName
Name of the collection to use for the SVDShaperDigits.
virtual void event() override
do the clustering
std::vector< const RelationElement * > RelationLookup
Container for a RelationArray Lookup table.
std::string m_relRecoDigitTrueHitName
Name of the relation between SVDRecoDigits and SVDTrueHits.
std::string m_storeTrueHitsName
Name of the collection to use for the SVDTrueHits.
std::string m_relRecoDigitMCParticleName
Name of the relation between SVDRecoDigits and MCParticles.
std::string m_timeFitterName
Name of the time fitter data xml.
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.
std::string m_relShaperDigitTrueHitName
Name of the relation between SVDShaperDigits and SVDTrueHits.
RelationLookup m_trueRelation
Lookup table for SVDShaperDigit->SVDTrueHit relation.
SVDPulseShapeCalibrations m_pulseShapeCal
Calibrations: pusle shape and gain.
std::string m_svdEventInfoName
Name of the SVDEventInfo object.
SVDNoiseCalibrations m_noiseCal
Calibrations: noise.
NNWaveFitter m_fitter
Time fitter.
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_cutAdjacent
Zero-suppression cut.
RelationLookup m_mcRelation
Lookup table for SVDShaperDigit->MCParticle relation.
StoreObjPtr< SVDEventInfo > m_storeSVDEvtInfo
Storage for SVDEventInfo object.
bool m_calibratePeak
Use peak widths and peak time calibrations? Unitl this is also simulated, set to true only for testbe...
std::string m_relRecoDigitShaperDigitName
Name of the relation between SVDRecoDigits and SVDShaperDigits.
const std::string & getName() const
Return name under which the object is saved in the DataStore.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
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.
Accessor to arrays stored in the data store.
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.
Class to uniquely identify a any structure of the PXD and SVD.
void setSegmentNumber(baseType segment)
Set the sensor segment.
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.
std::array< apvSampleBaseType, nAPVSamples > apvSamples
vector od apvSample BaseType objects
void zeroSuppress(T &a, double thr)
pass zero suppression
bool pass3Samples(const T &a, double thr)
pass 3-samples
Abstract base class for different kinds of events.