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>
39 SVDNNShapeReconstructorModule::SVDNNShapeReconstructorModule() :
Module()
41 B2DEBUG(200,
"Now in SVDNNShapeReconstructorModule ctor");
48 "Shaperdigits collection name",
string(
""));
50 "RecoDigits collection name",
string(
""));
52 "TrueHits collection name",
string(
""));
54 "MCParticles collection name",
string(
""));
58 "SVDEventInfo name",
string(
""));
61 "Name of time fitter data file",
string(
"SVDTimeNet_6samples"));
62 addParam(
"CalibratePeak",
m_calibratePeak,
"Use calibrattion (vs. default) for peak widths and positions",
bool(
false));
89 RelationArray relRecoDigitShaperDigits(storeRecoDigits, storeShaperDigits);
90 RelationArray relRecoDigitTrueHits(storeRecoDigits, storeTrueHits);
91 RelationArray relRecoDigitMCParticles(storeRecoDigits, storeMCParticles);
92 RelationArray relShaperDigitTrueHits(storeShaperDigits, storeTrueHits);
93 RelationArray relShaperDigitMCParticles(storeShaperDigits, storeMCParticles);
117 B2INFO(
" 1. COLLECTIONS:");
128 B2INFO(
" 2. CALIBRATION:");
143 if (!relation)
return;
145 lookup.resize(digits);
146 for (
const auto& element : relation) {
147 lookup[element.getFromIndex()] = &element;
152 std::map<unsigned int, float>& relation,
unsigned int index)
155 if (!lookup.empty() && lookup[index]) {
157 const unsigned int size = element.getSize();
159 for (
unsigned int i = 0; i < size; ++i) {
162 if (element.getWeight(i) < 0)
continue;
163 relation[element.getToIndex(i)] += element.getWeight(i);
177 size_t nDigits = storeShaperDigits.
getEntries();
178 B2DEBUG(90,
"Initial size of StoreDigits array: " << nDigits);
187 storeRecoDigits.
clear();
189 RelationArray relRecoDigitMCParticle(storeRecoDigits, storeMCParticles,
191 if (relRecoDigitMCParticle) relRecoDigitMCParticle.
clear();
193 RelationArray relRecoDigitShaperDigit(storeRecoDigits, storeShaperDigits,
195 if (relRecoDigitShaperDigit) relRecoDigitShaperDigit.
clear();
197 RelationArray relRecoDigitTrueHit(storeRecoDigits, storeTrueHits,
199 if (relRecoDigitTrueHit) relRecoDigitTrueHit.
clear();
209 vector<pair<unsigned short, unsigned short> > sensorDigits;
210 VxdID lastSensorID(0);
211 size_t firstSensorDigit = 0;
212 for (
size_t iDigit = 0; iDigit < nDigits; ++iDigit) {
216 if (sensorID != lastSensorID) {
217 sensorDigits.push_back(make_pair(firstSensorDigit, iDigit));
218 firstSensorDigit = iDigit;
219 lastSensorID = sensorID;
223 sensorDigits.push_back(make_pair(firstSensorDigit, nDigits));
226 for (
auto id_indices : sensorDigits) {
228 unsigned int firstDigit = id_indices.first;
229 unsigned int lastDigit = id_indices.second;
231 const SVDShaperDigit& exampleDigit = *storeShaperDigits[firstDigit];
237 B2DEBUG(300,
"Reconstructing digits " << firstDigit <<
" to " << lastDigit);
238 for (
size_t iDigit = firstDigit; iDigit < lastDigit; ++iDigit) {
241 unsigned short stripNo = shaperDigit.
getCellID();
242 bool validDigit =
true;
243 const double triggerBinSep = 4 * 1.96516;
244 double apvPhase = triggerBinSep * (0.5 +
static_cast<int>(modeByte.
getTriggerBin()));
251 double stripSignalWidth = 270;
252 double stripT0 = isU ? 2.5 : -2.2;
256 - 0.25 * stripSignalWidth;
259 B2DEBUG(300,
"Strip parameters: stripNoiseADU: " << stripNoiseADU <<
260 " Width: " << stripSignalWidth <<
266 transform(samples.begin(), samples.end(), normedSamples.begin(),
267 bind2nd(divides<float>(), stripNoiseADU));
279 os <<
"Input to NNFitter: iDigit = " << iDigit << endl <<
"Samples: ";
280 copy(normedSamples.begin(), normedSamples.end(), ostream_iterator<double>(os,
" "));
282 std::shared_ptr<nnFitterBinData> pStrip =
m_fitter.
getFit(normedSamples, stripSignalWidth);
283 os <<
"Output from NNWaveFitter: " << endl;
284 copy(pStrip->begin(), pStrip->end(), ostream_iterator<double>(os,
" "));
288 B2DEBUG(200, os.str());
290 double stripTime, stripTimeError;
291 tie(stripTime, stripTimeError) = fitTool.
getTimeShift(*pStrip);
293 double stripAmplitude, stripAmplitudeError, stripChi2;
294 tie(stripAmplitude, stripAmplitudeError, stripChi2) =
300 <<
" Time: " << stripTime <<
" +/- " << stripTimeError
301 <<
" Amplitude: " << stripAmplitude <<
" +/- " << stripAmplitudeError
302 <<
" Chi2: " << stripChi2
306 map<unsigned int, float> mc_relations;
307 map<unsigned int, float> truehit_relations;
308 vector<pair<unsigned int, float> > digit_weights;
309 digit_weights.reserve(1);
315 digit_weights.emplace_back(iDigit, 1.0);
318 int recoDigitIndex = storeRecoDigits.
getEntries();
321 stripAmplitudeError, stripTime, stripTimeError, *pStrip, stripChi2)
325 if (!mc_relations.empty()) {
326 relRecoDigitMCParticle.
add(recoDigitIndex, mc_relations.begin(), mc_relations.end());
328 if (!truehit_relations.empty()) {
329 relRecoDigitTrueHit.
add(recoDigitIndex, truehit_relations.begin(), truehit_relations.end());
331 relRecoDigitShaperDigit.
add(recoDigitIndex, digit_weights.begin(), digit_weights.end());
336 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.
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.
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.
const std::string & getName() const
Return name under which the object is saved in the DataStore.
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.
void zeroSuppress(T &a, double thr)
pass zero suppression
std::array< apvSampleBaseType, nAPVSamples > apvSamples
vector od apvSample BaseType objects
bool pass3Samples(const T &a, double thr)
pass 3-samples
Abstract base class for different kinds of events.