Belle II Software  release-06-02-00
RootParameterTracker.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 #include <tracking/trackFindingVXD/analyzingTools/RootParameterTracker.h>
9 
10 using namespace std;
11 using namespace Belle2;
12 
13 
15 void RootParameterTracker::collectData4DoubleAlgorithms(std::string tcTypeName, const AnalizerTCInfo& aTC)
16 {
17  auto* foundTCTypeData = m_algoDataDouble.find(tcTypeName); // a KeyValBox with all algorithms and data collected to given tcTypeName
18 
19  // skip if there is nothing stored for this tcType:
20  if (foundTCTypeData == nullptr) { return; }
21 
22  // looping over algorithms:
23  for (auto& entry : *foundTCTypeData) {
24  // increase readability:
25  auto* anAlgorithm = entry.second.first;
26  auto* dataVector = entry.second.second;
27  // sanity check: key has to be compatible with stored algorithm:
28  string algoName = anAlgorithm->getIDName();
29  if (entry.first != algoName) {
30  B2ERROR("RootParameterTracker::collectData4DoubleAlgorithms() key (" << entry.first <<
31  ") of container does not match to its content (" << algoName <<
32  ") - skipping entry! ");
33  continue;
34  }
35  B2DEBUG(50, "RootParameterTracker::collectData4DoubleAlgorithms(), executing algorithm of type: " << algoName <<
36  " with collected data-entries of " << dataVector->size());
37 
38  try {
39  double calcVal = anAlgorithm->calcData(aTC);
40  dataVector->push_back(calcVal);
41  B2DEBUG(20, "RootParameterTracker::collectData4DoubleAlgorithms(), tc with type " << tcTypeName <<
42  " and applied algorithm " << algoName <<
43  " and got " << calcVal << " as a result!");
44  } catch (AnalyzingAlgorithm<double>::No_refTC_Attached& anException) {
45  B2WARNING("RootParameterTracker::collectData4DoubleAlgorithms(), Exception caught for tc with type " << tcTypeName <<
46  " and applied algorithm " << algoName <<
47  ". Failed with exception: " << anException.what() <<
48  " -> skipping tc!");
49  }
50  }// looping over algorithms
51 }
52 
53 
54 
55 
56 
58 void RootParameterTracker::collectData4IntAlgorithms(std::string tcTypeName, const AnalizerTCInfo& aTC)
59 {
60  auto* foundTCTypeData = m_algoDataInt.find(tcTypeName); // a KeyValBox with all algorithms and data collected to given tcTypeName
61 
62  // skip if there is nothing stored for this tcType:
63  if (foundTCTypeData == nullptr) { return; }
64 
65  // looping over algorithms:
66  for (auto& entry : *foundTCTypeData) {
67  // increase readability:
68  auto* anAlgorithm = entry.second.first;
69  auto* dataVector = entry.second.second;
70  // sanity check: key has to be compatible with stored algorithm:
71  string algoName = anAlgorithm->getIDName();
72  if (entry.first != algoName) {
73  B2ERROR("RootParameterTracker::collectData4DoubleAlgorithms() key (" << entry.first <<
74  ") of container does not match to its content (" << algoName <<
75  ") - skipping entry! ");
76  continue;
77  }
78  B2DEBUG(50, "RootParameterTracker::collectData4DoubleAlgorithms(), executing algorithm of type: " << algoName <<
79  " with collected data-entries of " << dataVector->size());
80 
81  try {
82  int calcVal = anAlgorithm->calcData(aTC);
83  dataVector->push_back(calcVal);
84  B2DEBUG(20, "RootParameterTracker::collectData4DoubleAlgorithms(), tc with type " << tcTypeName <<
85  " and applied algorithm " << algoName <<
86  " and got " << calcVal << " as a result!");
87  } catch (AnalyzingAlgorithm<int>::No_refTC_Attached& anException) {
88  B2WARNING("RootParameterTracker::collectData4DoubleAlgorithms(), Exception caught for tc with type " << tcTypeName <<
89  " and applied algorithm " << algoName <<
90  ". Failed with exception: " << anException.what() <<
91  " -> skipping tc!");
92  }
93  }// looping over algorithms
94 }
95 
96 
97 
98 
99 
101 void RootParameterTracker::collectData4VecDoubleAlgorithms(std::string tcTypeName, const AnalizerTCInfo& aTC)
102 {
103  auto* foundTCTypeData = m_algoDataVecDouble.find(
104  tcTypeName); // a KeyValBox with all algorithms and data collected to given tcTypeName
105 
106  // skip if there is nothing stored for this tcType:
107  if (foundTCTypeData == nullptr) { return; }
108 
109  // looping over algorithms:
110  for (auto& entry : *foundTCTypeData) {
111  // increase readability:
112  auto* anAlgorithm = entry.second.first;
113  auto* dataVector = entry.second.second; // vector< vector < double>>
114  // sanity check: key has to be compatible with stored algorithm:
115  string algoName = anAlgorithm->getIDName();
116  if (entry.first != algoName) {
117  B2ERROR("RootParameterTracker::collectData4VecDoubleAlgorithms() key (" << entry.first <<
118  ") of container does not match to its content (" << algoName <<
119  ") - skipping entry! ");
120  continue;
121  }
122  B2DEBUG(50, "RootParameterTracker::collectData4VecDoubleAlgorithms(), executing algorithm of type: " << algoName <<
123  " with collected data-entries of " << dataVector->size());
124 
125  try {
126  vector<double> calcVal = anAlgorithm->calcData(aTC);
127  dataVector->push_back(calcVal);
128  auto printVec = [&]() -> string {
129  string out;
130  for (double val : calcVal)
131  {
132  out += (" " + to_string(val));
133  }
134  return (out += "\n");
135  };
136  B2DEBUG(20, "RootParameterTracker::collectData4VecDoubleAlgorithms(), tc with type " << tcTypeName <<
137  " and applied algorithm " << algoName <<
138  " and got: " << printVec() <<
139  " as a result!");
140  } catch (AnalyzingAlgorithm<vector<double>>::No_refTC_Attached& anException) {
141  B2WARNING("RootParameterTracker::collectData4VecDoubleAlgorithms(), Exception caught for tc with type " << tcTypeName <<
142  " and applied algorithm " << algoName <<
143  ". Failed with exception: " << anException.what() <<
144  " -> skipping tc!");
145  }
146  }// looping over algorithms
147 }
148 
149 
150 
151 
152 
156 void RootParameterTracker::addParameters4DoubleAlgorithms(std::string tcTypeName, std::string algorithmName)
157 {
179  B2DEBUG(5, "RootParameterTracker::addParameters4DoubleAlgorithms(), given parameters are tcTypeName/algorithmName: " << tcTypeName
180  << "/" <<
181  algorithmName);
182 
183  TTree* tree4tcType = prepareTTree(tcTypeName);
184 
186  auto* algorithms4tcType = m_algoDataDouble.find(tcTypeName);
187  if (algorithms4tcType == nullptr) {
188  B2DEBUG(5, "RootParameterTracker::addParameters4DoubleAlgorithms(), tcType " << tcTypeName <<
189  " not yet added to m_algoDataDouble, doing it now...");
190  m_algoDataDouble.push_back({
191  tcTypeName,
192  StringKeyBox<pair<AnalyzingAlgorithm<double>*, vector<double>*> >()
193  });
194  algorithms4tcType = m_algoDataDouble.find(tcTypeName);
195  }
196  B2DEBUG(5, "RootParameterTracker::addParameters4DoubleAlgorithms(), m_algoDataDouble has " << m_algoDataDouble.size() <<
197  " tcTypes stored");
198 
200  auto* data4AlgorithmOftcType = algorithms4tcType->find(algorithmName);
201  if (data4AlgorithmOftcType == nullptr) {
202  B2DEBUG(5, "RootParameterTracker::addParameters4DoubleAlgorithms(), algorithm " << algorithmName <<
203  " not yet added to m_algoDataDouble[tcType], doing it now...");
204  AnalyzingAlgorithm<double>* newAlgorithm = AnalyzingAlgorithmFactoryDouble<double, AnalizerTCInfo, TVector3>
205  (AlgoritmType::getTypeEnum(algorithmName));
206  algorithms4tcType->push_back({
207  algorithmName,
208  {
209  newAlgorithm,
210  new vector<double>()
211  }
212  });
213  data4AlgorithmOftcType = algorithms4tcType->find(algorithmName);
214 
216  auto* newBranch = tree4tcType->Branch(algorithmName.c_str(), data4AlgorithmOftcType->second);
217  if (newBranch == nullptr) B2ERROR("Could not create Branch " << algorithmName); // mainly to suppress compiler warning
218  // newBranch->Print();
219  } else {
220  B2WARNING("RootParameterTracker::addParameters4DoubleAlgorithms() given tcTypeName/algorithmName: " << tcTypeName <<
221  "/" << algorithmName <<
222  " was already added and will not be added again. This is a sign for unintended behavior - nothing will be added!");
223  }
224  B2DEBUG(5, "RootParameterTracker::addParameters4DoubleAlgorithms(), m_algoDataDouble[tcType] has " << algorithms4tcType->size() <<
225  " algorithms stored");
226 }
227 
228 
229 
230 
231 
235 void RootParameterTracker::addParameters4IntAlgorithms(std::string tcTypeName, std::string algorithmName)
236 {
237  B2DEBUG(5, "RootParameterTracker::addParameters4IntAlgorithms(), given parameters are tcTypeName/algorithmName: " << tcTypeName <<
238  "/" <<
239  algorithmName);
240 
241  TTree* tree4tcType = prepareTTree(tcTypeName);
242 
244  auto* algorithms4tcType = m_algoDataInt.find(tcTypeName);
245  if (algorithms4tcType == nullptr) {
246  B2DEBUG(5, "RootParameterTracker::addParameters4IntAlgorithms(), tcType " << tcTypeName <<
247  " not yet added to m_algoDataInt, doing it now...");
248  m_algoDataInt.push_back({
249  tcTypeName,
251  });
252  algorithms4tcType = m_algoDataInt.find(tcTypeName);
253  }
254  B2DEBUG(5, "RootParameterTracker::addParameters4IntAlgorithms(), m_algoDataInt has " << m_algoDataInt.size() << " tcTypes stored");
255 
257  auto* data4AlgorithmOftcType = algorithms4tcType->find(algorithmName);
258  if (data4AlgorithmOftcType == nullptr) {
259  B2DEBUG(5, "RootParameterTracker::addParameters4IntAlgorithms(), algorithm " << algorithmName <<
260  " not yet added to m_algoDataInt[tcType], doing it now...");
261  AnalyzingAlgorithm<int>* newAlgorithm = AnalyzingAlgorithmFactoryInt<int, AnalizerTCInfo, TVector3>(AlgoritmType::getTypeEnum(
262  algorithmName));
263  algorithms4tcType->push_back({
264  algorithmName,
265  {
266  newAlgorithm,
267  new vector<int>()
268  }
269  });
270  data4AlgorithmOftcType = algorithms4tcType->find(algorithmName);
271 
273  auto* newBranch = tree4tcType->Branch(algorithmName.c_str(), data4AlgorithmOftcType->second);
274  if (newBranch == nullptr) B2ERROR("Could not create Branch " << algorithmName); // mainly to suppress compiler warning
275  // newBranch->Print();
276  } else {
277  B2WARNING("RootParameterTracker::addParameters4DoubleAlgorithms() given tcTypeName/algorithmName: " << tcTypeName <<
278  "/" << algorithmName <<
279  " was already added and will not be added again. This is a sign for unintended behavior - nothing will be added!");
280  }
281  B2DEBUG(5, "RootParameterTracker::addParameters4DoubleAlgorithms(), m_algoDataInt[tcType] has " << algorithms4tcType->size() <<
282  " algorithms stored");
283 }
284 
285 
286 
287 
288 
292 void RootParameterTracker::addParameters4VecDoubleAlgorithms(std::string tcTypeName, std::string algorithmName)
293 {
294  B2DEBUG(5, "RootParameterTracker::addParameters4VecDoubleAlgorithms(), given parameters are tcTypeName/algorithmName: " <<
295  tcTypeName << "/" <<
296  algorithmName);
297 
298  TTree* tree4tcType = prepareTTree(tcTypeName);
299 
301  auto* algorithms4tcType = m_algoDataVecDouble.find(tcTypeName);
302  if (algorithms4tcType == nullptr) {
303  B2DEBUG(5, "RootParameterTracker::addParameters4VecDoubleAlgorithms(), tcType " << tcTypeName <<
304  " not yet added to m_algoDataVecDouble, doing it now...");
305  m_algoDataVecDouble.push_back({
306  tcTypeName,
307  StringKeyBox<pair<AnalyzingAlgorithm<vector<double>>*, vector<vector<double>>*> >()
308  });
309  algorithms4tcType = m_algoDataVecDouble.find(tcTypeName);
310  }
311  B2DEBUG(5, "RootParameterTracker::addParameters4VecDoubleAlgorithms(), m_algoDataVecDouble has " << m_algoDataVecDouble.size() <<
312  " tcTypes stored");
313 
315  auto* data4AlgorithmOftcType = algorithms4tcType->find(algorithmName);
316  if (data4AlgorithmOftcType == nullptr) {
317  B2DEBUG(5, "RootParameterTracker::addParameters4VecDoubleAlgorithms(), algorithm " << algorithmName <<
318  " not yet added to m_algoDataVecDouble[tcType], doing it now...");
319  AnalyzingAlgorithm<vector<double>>* newAlgorithm = AnalyzingAlgorithmFactoryVecDouble<vector<double>, AnalizerTCInfo, TVector3>
320  (AlgoritmType::getTypeEnum(algorithmName));
321  algorithms4tcType->push_back({
322  algorithmName,
323  {
324  newAlgorithm,
325  new vector<vector<double>>()
326  }
327  });
328  data4AlgorithmOftcType = algorithms4tcType->find(algorithmName);
329 
331  auto* newBranch = tree4tcType->Branch(algorithmName.c_str(), data4AlgorithmOftcType->second);
332  if (newBranch == nullptr) B2ERROR("Could not create Branch " << algorithmName); // mainly to suppress compiler warning
333  // newBranch->Print();
334  } else {
335  B2WARNING("RootParameterTracker::addParameters4VecDoubleAlgorithms() given tcTypeName/algorithmName: " << tcTypeName <<
336  "/" << algorithmName <<
337  " was already added and will not be added again. This is a sign for unintended behavior - nothing will be added!");
338  }
339  B2DEBUG(5, "RootParameterTracker::addParameters4VecDoubleAlgorithms(), m_algoDataVecDouble[tcType] has " <<
340  algorithms4tcType->size() << " algorithms stored");
341 }
simple class storing infos relevant for a TC for analizing it.
Base class for storing an algorithm determining the data one wants to have.
Minimal container storing a pair of < KeyType, ValueType>
Definition: KeyValBox.h:24
Abstract base class for different kinds of events.