Belle II Software  release-08-01-10
SVDRecoDigitCreatorModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <svd/modules/svdReconstruction/SVDRecoDigitCreatorModule.h>
10 
11 #include <framework/core/Environment.h>
12 #include <framework/datastore/DataStore.h>
13 #include <framework/logging/LogConfig.h>
14 #include <framework/logging/Logger.h>
15 
16 #include <svd/dataobjects/SVDEventInfo.h>
17 
18 #include <svd/reconstruction/SVDReconstructionBase.h>
19 
20 #include <svd/reconstruction/SVDRecoTimeFactory.h>
21 #include <svd/reconstruction/SVDRecoChargeFactory.h>
22 
23 using namespace std;
24 using namespace Belle2;
25 using namespace Belle2::SVD;
26 
27 
28 //-----------------------------------------------------------------
29 // Register the Module
30 //-----------------------------------------------------------------
31 REG_MODULE(SVDRecoDigitCreator);
32 
33 //-----------------------------------------------------------------
34 // Implementation
35 //-----------------------------------------------------------------
36 
37 SVDRecoDigitCreatorModule::SVDRecoDigitCreatorModule() : Module(),
38  m_useDB(true)
39 {
40  //Set module properties
41  setDescription("This module reconstructs SVDShaperDigit in SVDRecoDigit, i.e. calibrated strip with reconstructed charge and time.");
43 
44  // 1. Collections.
45  addParam("ShaperDigits", m_storeShaperDigitsName,
46  "SVDShaperDigits collection name.", string(""));
47  addParam("RecoDigits", m_storeRecoDigitsName,
48  "SVDRecoDigits collection name.", string(""));
49  addParam("Clusters", m_storeClustersName,
50  "SVDCluster collection name.", string(""));
51 
52  // 2. Reconstruction
53  addParam("timeAlgorithm6Samples", m_timeRecoWith6SamplesAlgorithm,
54  "strip-time reconstruction algorithm for the 6-sample DAQ mode: CoG6 = 6-sample CoG (default), CoG3 = 3-sample CoG, ELS3 = 3-sample ELS",
55  std::string("inRecoDBObject"));
56  addParam("timeAlgorithm3Samples", m_timeRecoWith3SamplesAlgorithm,
57  "strip-time reconstruction algorithm for the 3-sample DAQ mode: CoG6 = 6-sample CoG, CoG3 = 3-sample CoG (default), ELS3 = 3-sample ELS",
58  std::string("inRecoDBObject"));
59  addParam("chargeAlgorithm6Samples", m_chargeRecoWith6SamplesAlgorithm,
60  " choose charge algorithm for 6-sample DAQ mode: MaxSample (default), SumSamples, ELS3 = 3-sample ELS",
61  std::string("inRecoDBObject"));
62  addParam("chargeAlgorithm3Samples", m_chargeRecoWith3SamplesAlgorithm,
63  " choose charge algorithm for 3-sample DAQ mode: MaxSample (default), SumSamples, ELS3 = 3-sample ELS",
64  std::string("inRecoDBObject"));
65 
66  addParam("useDB", m_useDB,
67  "if false use clustering and reconstruction configuration module parameters", m_useDB);
68 
69 }
70 
72 {
73 
74  if (m_useDB) {
75  if (!m_recoConfig.isValid())
76  B2FATAL("no valid configuration found for SVD reconstruction");
77  else
78  B2DEBUG(20, "SVDRecoConfiguration: from now on we are using " << m_recoConfig->get_uniqueID());
79 
80  m_timeRecoWith6SamplesAlgorithm = m_recoConfig->getStripTimeRecoWith6Samples();
81  m_timeRecoWith3SamplesAlgorithm = m_recoConfig->getStripTimeRecoWith3Samples();
82  m_chargeRecoWith6SamplesAlgorithm = m_recoConfig->getStripChargeRecoWith6Samples();
83  m_chargeRecoWith3SamplesAlgorithm = m_recoConfig->getStripChargeRecoWith3Samples();
84  }
85 
86  //check that all algorithms are available, otherwise use the default one
87  SVDReconstructionBase recoBase;
88 
90  B2WARNING("strip time algorithm " << m_timeRecoWith6SamplesAlgorithm << " is NOT available, using CoG6");
92  };
93 
95  B2WARNING("strip time algorithm " << m_timeRecoWith3SamplesAlgorithm << " is NOT available, using CoG3");
97  };
99  B2WARNING("strip charge algorithm " << m_chargeRecoWith6SamplesAlgorithm << " is NOT available, using MaxSample");
100  m_chargeRecoWith6SamplesAlgorithm = "MaxSample";
101  };
103  B2WARNING("strip charge algorithm " << m_chargeRecoWith3SamplesAlgorithm << " is NOT available, using MaxSample");
104  m_chargeRecoWith3SamplesAlgorithm = "MaxSample";
105  };
106 
107  bool returnRawClusterTime = false;
112 
113  B2INFO("SVD 6-sample DAQ SVDRecoDigit, time algorithm: " << m_timeRecoWith6SamplesAlgorithm << ", charge algorithm: " <<
115 
116  B2INFO("SVD 3-sample DAQ SVDRecoDigit, time algorithm: " << m_timeRecoWith3SamplesAlgorithm << ", charge algorithm: " <<
118 
119 }
120 
122 {
123  //Register collections
127 
128  m_storeReco.registerRelationTo(m_storeShaper);
130 
131  //Store names to speed up creation later
134 
135  // Report:
136  B2DEBUG(25, "SVDRecoDigitCreator Parameters (in default system unit, *=cannot be set directly):");
137 
138  B2DEBUG(25, " 1. COLLECTIONS:");
139  B2DEBUG(25, " --> SVDShaperDigits: " << DataStore::arrayName<SVDShaperDigit>(m_storeShaperDigitsName));
140  B2DEBUG(25, " --> SVDRecoDigits: " << DataStore::arrayName<SVDRecoDigit>(m_storeRecoDigitsName));
141  B2DEBUG(25, " --> SVDClusters: " << DataStore::arrayName<SVDCluster>(m_storeClustersName));
142 }
143 
145 {
146 
147  StoreObjPtr<SVDEventInfo> temp_eventinfo("SVDEventInfo");
148  std::string m_svdEventInfoName = "SVDEventInfo";
149  if (!temp_eventinfo.isValid())
150  m_svdEventInfoName = "SVDEventInfoSim";
151  StoreObjPtr<SVDEventInfo> eventinfo(m_svdEventInfoName);
152  if (!eventinfo) {
153  if (Environment::Instance().getRealm() == LogConfig::c_Online) {
154  // If there is no SVDEventInfo and we are running online, it means that SVD is excluded: better to return
155  B2WARNING("No SVDEventInfo object in this event: SVD is excluded, so don't worry");
156  return;
157  } else {
158  // Otherwise, throw a FATAL
159  B2FATAL("No SVDEventInfo object in this event: something went wrong");
160  }
161  }
162 
163  int numberOfAcquiredSamples = eventinfo->getNSamples();
164 
165  int nShaperDigits = m_storeShaper.getEntries();
166 
167  //loop over the SVDShaperDigits
168  for (int i = 0; i < nShaperDigits; ++i) {
169 
170  VxdID sensorID = m_storeShaper[i]->getSensorID();
171  bool isU = m_storeShaper[i]->isUStrip();
172  int cellID = m_storeShaper[i]->getCellID();
173 
174  //build the StripInRawCluster and a fake RawCluster
175  RawCluster rawCluster(sensorID, isU, 0, 0);
177  strip.shaperDigitIndex = i;
178  strip.cellID = cellID;
179  strip.maxSample = m_storeShaper[i]->getMaxADCCounts();
180  strip.noise = m_NoiseCal.getNoise(sensorID, isU, cellID);
181  strip.samples = m_storeShaper[i]->getSamples();;
182  strip.charge = std::numeric_limits<double>::quiet_NaN();;
183  strip.time = std::numeric_limits<double>::quiet_NaN();;
184 
185  if (rawCluster.add(sensorID, rawCluster.isUSide(), strip)) {
186 
187  double time = std::numeric_limits<float>::quiet_NaN();
188  double timeError = std::numeric_limits<float>::quiet_NaN();
189  double charge = std::numeric_limits<float>::quiet_NaN();
190  float chargeError = std::numeric_limits<float>::quiet_NaN();
191  int firstFrame = std::numeric_limits<int>::quiet_NaN();
192  std::vector<float> probabilities = {0.5};
193  double chi2 = std::numeric_limits<double>::quiet_NaN();
194 
195  //dummy containers:
196  double SNR = std::numeric_limits<double>::quiet_NaN();
197  double seedCharge = std::numeric_limits<double>::quiet_NaN();
198 
199  if (numberOfAcquiredSamples == 6) {
200 
201  //time
202  m_time6SampleClass->computeClusterTime(rawCluster, time, timeError, firstFrame);
203  //charge
204  m_charge6SampleClass->computeClusterCharge(rawCluster, charge, SNR, seedCharge);
205  } else if (numberOfAcquiredSamples == 3) {
206  //time
207  m_time3SampleClass->computeClusterTime(rawCluster, time, timeError, firstFrame);
208 
209  //charge
210  m_charge3SampleClass->computeClusterCharge(rawCluster, charge, SNR, seedCharge);
211 
212  } else
213  B2ERROR("SVD Reconstruction not available for this strip: not supported number of acquired APV samples!!");
214 
215  // now go into FTSW reference frame
216  time = eventinfo->getTimeInFTSWReference(time, firstFrame);
217 
218  //append the new SVDRecoDigit to the StoreArray
219  SVDRecoDigit* recoDigit = m_storeReco.appendNew(sensorID, isU, cellID, charge, chargeError, time, timeError, probabilities, chi2);
220 
221  // set the relation SVDRecoDigit -> SVDShaperDigit
222  recoDigit->addRelationTo(m_storeShaper[i]);
223  // and SVDCluster -> SVDRecoDigit
224  SVDCluster* cluster = m_storeShaper[i]->getRelated<SVDCluster>(m_storeClustersName);
225  cluster->addRelationTo(recoDigit, recoDigit->getCharge());
226  }
227  } //exit loop on ShaperDigits
228 }
229 
230 
232 {
233 
234  delete m_time6SampleClass;
235  delete m_time3SampleClass;
236  delete m_charge6SampleClass;
237  delete m_charge3SampleClass;
238 
239 }
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition: DataStore.h:72
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
@ c_Online
Online data taking.
Definition: LogConfig.h:49
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:29
float getNoise(const VxdID &sensorID, const bool &isU, const unsigned short &strip) const
This is the method for getting the noise.
The SVD RecoDigit class.
Definition: SVDRecoDigit.h:43
float getCharge() const
Get amplitude estimate, alternate getter name.
Definition: SVDRecoDigit.h:124
Class representing a raw cluster candidate during clustering of the SVD.
Definition: RawCluster.h:33
bool add(VxdID vxdID, bool isUside, struct StripInRawCluster &aStrip)
Add a Strip to the current cluster.
Definition: RawCluster.cc:54
bool isUSide() const
Definition: RawCluster.h:85
virtual void computeClusterCharge(Belle2::SVD::RawCluster &rawCluster, double &charge, double &SNR, double &seedCharge)=0
computes the cluster charge, SNR and seedCharge
virtual void computeClusterTime(Belle2::SVD::RawCluster &rawCluster, double &time, double &timeError, int &firstFrame)=0
computes the cluster time, timeError and FirstFrame
static SVDClusterCharge * NewCharge(const std::string &description)
static function that returns the class to compute the cluster charge
std::string m_storeRecoDigitsName
Name of the collection to use for the SVDRecoDigits.
SVDClusterCharge * m_charge6SampleClass
strip charge class for the 6-sample acquisition mode
SVDClusterCharge * m_charge3SampleClass
strip charge class for the 3-sample acquisition mode
void initialize() override
Initialize the module.
std::string m_storeShaperDigitsName
Name of the collection to use for the SVDShaperDigits.
void event() override
does the actual strip reconstruction
SVDNoiseCalibrations m_NoiseCal
wrapper of the noise calibrations
SVDClusterTime * m_time6SampleClass
strip time class for the 6-sample acquisition mode
StoreArray< SVDRecoDigit > m_storeReco
Collection of SVDRecoDigits.
std::string m_chargeRecoWith6SamplesAlgorithm
string storing the strip charge reconstruction algorithm in 6-sample DAQ mode
std::string m_chargeRecoWith3SamplesAlgorithm
string storing the strip charge reconstruction algorithm in 3-sample DAQ mode
void beginRun() override
configure strip reconstruction
StoreArray< SVDShaperDigit > m_storeShaper
Collection of SVDShaperDigits.
std::string m_storeClustersName
Name of the collection to use for the SVDClusters.
std::string m_timeRecoWith6SamplesAlgorithm
string storing the strip time reconstruction algorithm in 6-sample DAQ mode
DBObjPtr< SVDRecoConfiguration > m_recoConfig
SVD Reconstruction Configuration payload.
StoreArray< SVDCluster > m_storeClusters
Collection of SVDClusters.
std::string m_timeRecoWith3SamplesAlgorithm
string storing the strip time reconstruction algorithm in 3-sample DAQ mode
bool m_useDB
if true takes the strip reconstruction configuration from the DB objects
SVDClusterTime * m_time3SampleClass
strip time class for the 3-sample acquisition mode
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 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 registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition: StoreArray.h:140
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:111
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Namespace to encapsulate code needed for simulation and reconstrucion of the SVD.
Definition: GeoSVDCreator.h:23
Abstract base class for different kinds of events.
structure containing the relevant informations of each strip of the raw cluster
Definition: RawCluster.h:20
double charge
strip charge
Definition: RawCluster.h:26
Belle2::SVDShaperDigit::APVFloatSamples samples
ADC of the acquired samples.
Definition: RawCluster.h:25
int shaperDigitIndex
index of the shaper digit
Definition: RawCluster.h:21
int maxSample
ADC max of the acquired samples.
Definition: RawCluster.h:23