Belle II Software  release-08-01-10
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 Belle2;
11 
12 
15 {
16  auto* foundTCTypeData = m_algoDataDouble.find(tcTypeName); // a KeyValBox with all algorithms and data collected to given tcTypeName
17 
18  // skip if there is nothing stored for this tcType:
19  if (foundTCTypeData == nullptr) { return; }
20 
21  // looping over algorithms:
22  for (auto& entry : *foundTCTypeData) {
23  // increase readability:
24  auto* anAlgorithm = entry.second.first;
25  auto* dataVector = entry.second.second;
26  // sanity check: key has to be compatible with stored algorithm:
27  std::string algoName = anAlgorithm->getIDName();
28  if (entry.first != algoName) {
29  B2ERROR("RootParameterTracker::collectData4DoubleAlgorithms() key (" << entry.first <<
30  ") of container does not match to its content (" << algoName <<
31  ") - skipping entry! ");
32  continue;
33  }
34  B2DEBUG(21, "RootParameterTracker::collectData4DoubleAlgorithms(), executing algorithm of type: " << algoName <<
35  " with collected data-entries of " << dataVector->size());
36 
37  try {
38  double calcVal = anAlgorithm->calcData(aTC);
39  dataVector->push_back(calcVal);
40  B2DEBUG(20, "RootParameterTracker::collectData4DoubleAlgorithms(), tc with type " << tcTypeName <<
41  " and applied algorithm " << algoName <<
42  " and got " << calcVal << " as a result!");
43  } catch (AnalyzingAlgorithm<double>::No_refTC_Attached& anException) {
44  B2WARNING("RootParameterTracker::collectData4DoubleAlgorithms(), Exception caught for tc with type " << tcTypeName <<
45  " and applied algorithm " << algoName <<
46  ". Failed with exception: " << anException.what() <<
47  " -> skipping tc!");
48  }
49  }// looping over algorithms
50 }
51 
52 
53 
54 
55 
57 void RootParameterTracker::collectData4IntAlgorithms(std::string tcTypeName, const AnalizerTCInfo& aTC)
58 {
59  auto* foundTCTypeData = m_algoDataInt.find(tcTypeName); // a KeyValBox with all algorithms and data collected to given tcTypeName
60 
61  // skip if there is nothing stored for this tcType:
62  if (foundTCTypeData == nullptr) { return; }
63 
64  // looping over algorithms:
65  for (auto& entry : *foundTCTypeData) {
66  // increase readability:
67  auto* anAlgorithm = entry.second.first;
68  auto* dataVector = entry.second.second;
69  // sanity check: key has to be compatible with stored algorithm:
70  std::string algoName = anAlgorithm->getIDName();
71  if (entry.first != algoName) {
72  B2ERROR("RootParameterTracker::collectData4DoubleAlgorithms() key (" << entry.first <<
73  ") of container does not match to its content (" << algoName <<
74  ") - skipping entry! ");
75  continue;
76  }
77  B2DEBUG(50, "RootParameterTracker::collectData4DoubleAlgorithms(), executing algorithm of type: " << algoName <<
78  " with collected data-entries of " << dataVector->size());
79 
80  try {
81  int calcVal = anAlgorithm->calcData(aTC);
82  dataVector->push_back(calcVal);
83  B2DEBUG(20, "RootParameterTracker::collectData4DoubleAlgorithms(), tc with type " << tcTypeName <<
84  " and applied algorithm " << algoName <<
85  " and got " << calcVal << " as a result!");
86  } catch (AnalyzingAlgorithm<int>::No_refTC_Attached& anException) {
87  B2WARNING("RootParameterTracker::collectData4DoubleAlgorithms(), Exception caught for tc with type " << tcTypeName <<
88  " and applied algorithm " << algoName <<
89  ". Failed with exception: " << anException.what() <<
90  " -> skipping tc!");
91  }
92  }// looping over algorithms
93 }
94 
95 
96 
97 
98 
101 {
102  auto* foundTCTypeData = m_algoDataVecDouble.find(
103  tcTypeName); // a KeyValBox with all algorithms and data collected to given tcTypeName
104 
105  // skip if there is nothing stored for this tcType:
106  if (foundTCTypeData == nullptr) { return; }
107 
108  // looping over algorithms:
109  for (auto& entry : *foundTCTypeData) {
110  // increase readability:
111  auto* anAlgorithm = entry.second.first;
112  auto* dataVector = entry.second.second; // std::vector< vector < double>>
113  // sanity check: key has to be compatible with stored algorithm:
114  std::string algoName = anAlgorithm->getIDName();
115  if (entry.first != algoName) {
116  B2ERROR("RootParameterTracker::collectData4VecDoubleAlgorithms() key (" << entry.first <<
117  ") of container does not match to its content (" << algoName <<
118  ") - skipping entry! ");
119  continue;
120  }
121  B2DEBUG(50, "RootParameterTracker::collectData4VecDoubleAlgorithms(), executing algorithm of type: " << algoName <<
122  " with collected data-entries of " << dataVector->size());
123 
124  try {
125  std::vector<double> calcVal = anAlgorithm->calcData(aTC);
126  dataVector->push_back(calcVal);
127  auto printVec = [&]() -> std::string {
128  std::string out;
129  for (double val : calcVal)
130  {
131  out += (" " + std::to_string(val));
132  }
133  return (out += "\n");
134  };
135  B2DEBUG(20, "RootParameterTracker::collectData4VecDoubleAlgorithms(), tc with type " << tcTypeName <<
136  " and applied algorithm " << algoName <<
137  " and got: " << printVec() <<
138  " as a result!");
139  } catch (AnalyzingAlgorithm<std::vector<double>>::No_refTC_Attached& anException) {
140  B2WARNING("RootParameterTracker::collectData4VecDoubleAlgorithms(), Exception caught for tc with type " << tcTypeName <<
141  " and applied algorithm " << algoName <<
142  ". Failed with exception: " << anException.what() <<
143  " -> skipping tc!");
144  }
145  }// looping over algorithms
146 }
147 
148 
149 
150 
151 
155 void RootParameterTracker::addParameters4DoubleAlgorithms(std::string tcTypeName, std::string algorithmName)
156 {
178  B2DEBUG(5, "RootParameterTracker::addParameters4DoubleAlgorithms(), given parameters are tcTypeName/algorithmName: " << tcTypeName
179  << "/" <<
180  algorithmName);
181 
182  TTree* tree4tcType = prepareTTree(tcTypeName);
183 
185  auto* algorithms4tcType = m_algoDataDouble.find(tcTypeName);
186  if (algorithms4tcType == nullptr) {
187  B2DEBUG(5, "RootParameterTracker::addParameters4DoubleAlgorithms(), tcType " << tcTypeName <<
188  " not yet added to m_algoDataDouble, doing it now...");
189  m_algoDataDouble.push_back({
190  tcTypeName,
191  StringKeyBox<std::pair<AnalyzingAlgorithm<double>*, std::vector<double>*> >()
192  });
193  algorithms4tcType = m_algoDataDouble.find(tcTypeName);
194  }
195  B2DEBUG(5, "RootParameterTracker::addParameters4DoubleAlgorithms(), m_algoDataDouble has " << m_algoDataDouble.size() <<
196  " tcTypes stored");
197 
199  auto* data4AlgorithmOftcType = algorithms4tcType->find(algorithmName);
200  if (data4AlgorithmOftcType == nullptr) {
201  B2DEBUG(5, "RootParameterTracker::addParameters4DoubleAlgorithms(), algorithm " << algorithmName <<
202  " not yet added to m_algoDataDouble[tcType], doing it now...");
203  AnalyzingAlgorithm<double>* newAlgorithm = AnalyzingAlgorithmFactoryDouble<double, AnalizerTCInfo, ROOT::Math::XYZVector>
204  (AlgoritmType::getTypeEnum(algorithmName));
205  algorithms4tcType->push_back({
206  algorithmName,
207  {
208  newAlgorithm,
209  new std::vector<double>()
210  }
211  });
212  data4AlgorithmOftcType = algorithms4tcType->find(algorithmName);
213 
215  auto* newBranch = tree4tcType->Branch(algorithmName.c_str(), data4AlgorithmOftcType->second);
216  if (newBranch == nullptr) B2ERROR("Could not create Branch " << algorithmName); // mainly to suppress compiler warning
217  // newBranch->Print();
218  } else {
219  B2WARNING("RootParameterTracker::addParameters4DoubleAlgorithms() given tcTypeName/algorithmName: " << tcTypeName <<
220  "/" << algorithmName <<
221  " was already added and will not be added again. This is a sign for unintended behavior - nothing will be added!");
222  }
223  B2DEBUG(5, "RootParameterTracker::addParameters4DoubleAlgorithms(), m_algoDataDouble[tcType] has " << algorithms4tcType->size() <<
224  " algorithms stored");
225 }
226 
227 
228 
229 
230 
234 void RootParameterTracker::addParameters4IntAlgorithms(std::string tcTypeName, std::string algorithmName)
235 {
236  B2DEBUG(5, "RootParameterTracker::addParameters4IntAlgorithms(), given parameters are tcTypeName/algorithmName: " << tcTypeName <<
237  "/" <<
238  algorithmName);
239 
240  TTree* tree4tcType = prepareTTree(tcTypeName);
241 
243  auto* algorithms4tcType = m_algoDataInt.find(tcTypeName);
244  if (algorithms4tcType == nullptr) {
245  B2DEBUG(5, "RootParameterTracker::addParameters4IntAlgorithms(), tcType " << tcTypeName <<
246  " not yet added to m_algoDataInt, doing it now...");
247  m_algoDataInt.push_back({
248  tcTypeName,
249  StringKeyBox<std::pair<AnalyzingAlgorithm<int>*, std::vector<int>*> >()
250  });
251  algorithms4tcType = m_algoDataInt.find(tcTypeName);
252  }
253  B2DEBUG(5, "RootParameterTracker::addParameters4IntAlgorithms(), m_algoDataInt has " << m_algoDataInt.size() << " tcTypes stored");
254 
256  auto* data4AlgorithmOftcType = algorithms4tcType->find(algorithmName);
257  if (data4AlgorithmOftcType == nullptr) {
258  B2DEBUG(5, "RootParameterTracker::addParameters4IntAlgorithms(), algorithm " << algorithmName <<
259  " not yet added to m_algoDataInt[tcType], doing it now...");
260  AnalyzingAlgorithm<int>* newAlgorithm =
261  AnalyzingAlgorithmFactoryInt<int, AnalizerTCInfo, ROOT::Math::XYZVector>(AlgoritmType::getTypeEnum(algorithmName));
262 
263  algorithms4tcType->push_back({
264  algorithmName,
265  {
266  newAlgorithm,
267  new std::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<std::pair<AnalyzingAlgorithm<std::vector<double>>*, std::vector<std::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...");
320  AnalyzingAlgorithmFactoryVecDouble<std::vector<double>, AnalizerTCInfo, ROOT::Math::XYZVector>
321  (AlgoritmType::getTypeEnum(algorithmName));
322  algorithms4tcType->push_back({
323  algorithmName,
324  {
325  newAlgorithm,
326  new std::vector<std::vector<double>>()
327  }
328  });
329  data4AlgorithmOftcType = algorithms4tcType->find(algorithmName);
330 
332  auto* newBranch = tree4tcType->Branch(algorithmName.c_str(), data4AlgorithmOftcType->second);
333  if (newBranch == nullptr) B2ERROR("Could not create Branch " << algorithmName); // mainly to suppress compiler warning
334  // newBranch->Print();
335  } else {
336  B2WARNING("RootParameterTracker::addParameters4VecDoubleAlgorithms() given tcTypeName/algorithmName: " << tcTypeName <<
337  "/" << algorithmName <<
338  " was already added and will not be added again. This is a sign for unintended behavior - nothing will be added!");
339  }
340  B2DEBUG(5, "RootParameterTracker::addParameters4VecDoubleAlgorithms(), m_algoDataVecDouble[tcType] has " <<
341  algorithms4tcType->size() << " algorithms stored");
342 }
static AlgoritmType::Type getTypeEnum(std::string type)
for given string name of a AlgoritmType the corresponding AlgoritmType will be returned.
Definition: AlgoritmType.h:98
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
AlgoDataBox< int > m_algoDataInt
contains all algorithms and its data storing one int per TC
void addParameters4DoubleAlgorithms(std::string tcTypeName, std::string algorithmName)
relevant for all algorithms storing one double per TC:
void addParameters4VecDoubleAlgorithms(std::string tcTypeName, std::string algorithmName)
relevant for all algorithms storing one vector of double per TC:
void collectData4DoubleAlgorithms(std::string tcTypeName, const AnalizerTCInfo &aTC)
takes aTC with tcTypeName and applies the algorithms for it
void collectData4IntAlgorithms(std::string tcTypeName, const AnalizerTCInfo &aTC)
takes aTC with tcTypeName and applies the algorithms for it
void addParameters4IntAlgorithms(std::string tcTypeName, std::string algorithmName)
relevant for all algorithms storing one int per TC:
void collectData4VecDoubleAlgorithms(std::string tcTypeName, const AnalizerTCInfo &aTC)
takes aTC with tcTypeName and applies the algorithms for it
TTree * prepareTTree(std::string tcTypeName)
checks if ttree for given tcTypeName exists and creates it if not.
AlgoDataBox< std::vector< double > > m_algoDataVecDouble
contains all algorithms and its data storing one vector of double per TC
AlgoDataBox< double > m_algoDataDouble
contains all algorithms and its data storing one double per TC
Abstract base class for different kinds of events.