Belle II Software  release-06-00-14
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 
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.");
42  setPropertyFlags(c_ParallelProcessingCertified);
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 
71 void SVDRecoDigitCreatorModule::beginRun()
72 {
73 
74  if (m_useDB) {
75  if (!m_recoConfig.isValid())
76  B2FATAL("no valid configuration found for SVD reconstruction");
77  else
78  B2INFO("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 
89  if (!recoBase.isTimeAlgorithmAvailable(m_timeRecoWith6SamplesAlgorithm)) {
90  B2WARNING("strip time algorithm " << m_timeRecoWith6SamplesAlgorithm << " is NOT available, using CoG6");
91  m_timeRecoWith6SamplesAlgorithm = "CoG6";
92  };
93 
94  if (!recoBase.isTimeAlgorithmAvailable(m_timeRecoWith3SamplesAlgorithm)) {
95  B2WARNING("strip time algorithm " << m_timeRecoWith3SamplesAlgorithm << " is NOT available, using CoG3");
96  m_timeRecoWith3SamplesAlgorithm = "CoG3";
97  };
98  if (!recoBase.isChargeAlgorithmAvailable(m_chargeRecoWith6SamplesAlgorithm)) {
99  B2WARNING("strip charge algorithm " << m_chargeRecoWith6SamplesAlgorithm << " is NOT available, using MaxSample");
100  m_chargeRecoWith6SamplesAlgorithm = "MaxSample";
101  };
102  if (!recoBase.isChargeAlgorithmAvailable(m_chargeRecoWith3SamplesAlgorithm)) {
103  B2WARNING("strip charge algorithm " << m_chargeRecoWith3SamplesAlgorithm << " is NOT available, using MaxSample");
104  m_chargeRecoWith3SamplesAlgorithm = "MaxSample";
105  };
106 
107  bool returnRawClusterTime = false;
108  m_time6SampleClass = SVDRecoTimeFactory::NewTime(m_timeRecoWith6SamplesAlgorithm, returnRawClusterTime);
109  m_time3SampleClass = SVDRecoTimeFactory::NewTime(m_timeRecoWith3SamplesAlgorithm, returnRawClusterTime);
110  m_charge6SampleClass = SVDRecoChargeFactory::NewCharge(m_chargeRecoWith6SamplesAlgorithm);
111  m_charge3SampleClass = SVDRecoChargeFactory::NewCharge(m_chargeRecoWith3SamplesAlgorithm);
112 
113  B2INFO("SVD 6-sample DAQ SVDRecoDigit, time algorithm: " << m_timeRecoWith6SamplesAlgorithm << ", charge algorithm: " <<
114  m_chargeRecoWith6SamplesAlgorithm);
115 
116  B2INFO("SVD 3-sample DAQ SVDRecoDigit, time algorithm: " << m_timeRecoWith3SamplesAlgorithm << ", charge algorithm: " <<
117  m_chargeRecoWith3SamplesAlgorithm);
118 
119 }
120 
121 void SVDRecoDigitCreatorModule::initialize()
122 {
123  //Register collections
124  m_storeReco.registerInDataStore(m_storeRecoDigitsName, DataStore::c_ErrorIfAlreadyRegistered);
125  m_storeClusters.isOptional(m_storeClustersName);
126  m_storeShaper.isOptional(m_storeShaperDigitsName);
127 
128  m_storeReco.registerRelationTo(m_storeShaper);
129  m_storeClusters.registerRelationTo(m_storeReco);
130 
131  //Store names to speed up creation later
132  m_storeClustersName = m_storeClusters.getName();
133  m_storeShaperDigitsName = m_storeShaper.getName();
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 
144 void SVDRecoDigitCreatorModule::event()
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 
231 void SVDRecoDigitCreatorModule::endRun()
232 {
233 
234  delete m_time6SampleClass;
235  delete m_time3SampleClass;
236  delete m_charge6SampleClass;
237  delete m_charge3SampleClass;
238 
239 }
Base class for Modules.
Definition: Module.h:72
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:28
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
Class to check whether the reconstruction algorithms are available or not.
bool isChargeAlgorithmAvailable(TString chargeAlg)
bool isTimeAlgorithmAvailable(TString timeAlg)
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:110
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
#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