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