Belle II Software  release-05-01-25
VXDTFFiltersHelperFunctions.h
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 *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <fstream>
13 #include <string>
14 
15 #include <framework/logging/Logger.h>
16 #include <tracking/trackFindingVXD/environment/VXDTFFilters.h>
17 
18 namespace Belle2 {
25  namespace SecMapHelper {
26 
28 // // // // /** overloaded print-version for typical activeSector-networks without CACell-stuff */
29 // // // // template<class HitType>
30 // // // // void printStaticSectorRelations(const VXDTFFilters<HitType>& filters, std::string configName, unsigned int nHitCombinations = 2, bool print2File = true, bool suppressDeadSectors = true)
31 // // // // {
32 // // // // if (nHitCombinations <2 or nHitCombinations > 4)
33 // // // // B2FATAL("printStaticSectorRelations: input-parameter wrong ("
34 // // // // << nHitCombinations
35 // // // // << ", allowed only 2-4), skipping print-function!")
36 // // // //
37 // // // // std::string fullOut = "digraph G {\n";
38 // // // // fullOut += "ranksep=\"0.2\" edge[labelfontsize=\"8\" fontsize=\"8\" arrowsize=\"0.9\"] nodesep=\"0.2\" node[shape=\"box\" width=\"0\" height=\"0\" fontsize=\"10\"]";
39 // // // // // rankdir="LR" ranksep="0.2" edge[labelfontsize="8" fontsize="8" labeldistance="0.8" arrowsize="0.9" labelangle="-30" dir="none"] nodesep="0.2" node[width="0" height="0" fontsize="10"]
40 // // // // for (auto* entry : network) { // write vertices:
41 // // // //
42 // // // // std::stringstream outStream;
43 // // // // outStream << entry->getEntry();
44 // // // // fullOut += std::to_string(entry->getIndex()) +
45 // // // // " [label=\"" +
46 // // // // outStream.str() +
47 // // // // // " State: " +
48 // // // // // std::to_string(entry->getMetaInfo().getState()) +
49 // // // // // " isSeed: " +
50 // // // // // std::to_string(entry->getMetaInfo().isSeed()) +
51 // // // // "\"];\n";
52 // // // // }
53 // // // // for (auto* entry : network) { // write edges:
54 // // // // for (auto* nb : entry->getInnerNodes()) {
55 // // // // std::string arrowStyle = "";
56 // // // // fullOut += std::to_string(entry->getIndex()) + " -> " + std::to_string(nb->getIndex()) + arrowStyle + ";\n";
57 // // // // }
58 // // // // }
59 // // // // fullOut += "labelloc=\"t\";\nlabel=\"" + fName + "\";\n";
60 // // // // fullOut += "}\n";
61 // // // //
62 // // // // std::ofstream ofs;
63 // // // // ofs.open(fName + ".gv", std::ofstream::out | std::ofstream::trunc);
64 // // // // ofs << fullOut;
65 // // // // ofs.close();
66 // // // // };
67 
76  template<class HitType>
77  void printStaticSectorRelations(const VXDTFFilters<HitType>& filters, const std::string& configName,
78  unsigned int nHitCombinations = 2, bool print2File = true, bool suppressDeadSectors = true)
79  {
80  if (nHitCombinations <2 or nHitCombinations > 4)
81  B2FATAL("printStaticSectorRelations: input-parameter wrong ("
82  << nHitCombinations
83  << ", allowed only 2-4), skipping print-function!");
84 
85  std::string secIDCombis = "## printed " + std::to_string(nHitCombinations) + "-sector-combi-output of secMap: " + configName +
86  "\n{";
87  for (const auto* staticSector : filters.getStaticSectors()) {
88  if (staticSector == nullptr) continue;
89  std::string mainSecID = staticSector->getFullSecID().getFullSecString();
90 
91  if (nHitCombinations == 2) {
92  const auto& innerSectors = staticSector->getInner2spSecIDs();
93  if (innerSectors.empty()) {
94  if (suppressDeadSectors == false) { secIDCombis += "\"" + mainSecID + "\",\n"; }
95  } else {
96  for (const auto& innerID : innerSectors) {
97  secIDCombis += "\"" + mainSecID + "\" -> \"" + innerID.getFullSecString() + "\",\n";
98  }
99  }
100 
101  } else if (nHitCombinations == 3) {
102  // TODO discuss: do we want to treat the nodes as sectors or as sector-pairs in this case? more correct would be sector-pair...)
103  const auto& innerSectors = staticSector->getInner3spSecIDs();
104  if (innerSectors.empty()) {
105  if (suppressDeadSectors == false) { secIDCombis += "\"" + mainSecID + "\",\n"; }
106  } else {
107  for (const auto& innerIDpair : innerSectors) {
108  secIDCombis += "\"" + mainSecID + "\" -> \"" + innerIDpair.first.getFullSecString() + "\",\n";
109  secIDCombis += "\"" + innerIDpair.first.getFullSecString() + "\" -> \"" + innerIDpair.second.getFullSecString() + "\",\n";
110  }
111  }
112 
113  } else if (nHitCombinations == 4) {
114  // TODO discuss: do we want to treat the nodes as sectors or as sector-pairs in this case? more correct would be sector-pair...)
115  const auto& innerSectors = staticSector->getInner4spSecIDs();
116  if (innerSectors.empty()) {
117  if (suppressDeadSectors == false) { secIDCombis += "\"" + mainSecID + "\",\n"; }
118  } else {
119  for (const auto& innerIDtriplet : innerSectors) {
120  secIDCombis += "\"" + mainSecID + "\" -> \"" + std::get<0>(innerIDtriplet).getFullSecString() + "\",\n";
121  secIDCombis += "\"" + std::get<0>(innerIDtriplet).getFullSecString() + "\" -> \"" + std::get<1>
122  (innerIDtriplet).getFullSecString() + "\",\n";
123  secIDCombis += "\"" + std::get<1>(innerIDtriplet).getFullSecString() + "\" -> \"" + std::get<2>
124  (innerIDtriplet).getFullSecString() + "\",\n";
125  }
126  }
127 
128  }
129  }
130 
131  secIDCombis += "};";
132 
133  if (print2File == true) {
134  B2DEBUG(99, "Printing static sector relations to file " << configName << "4Mathematica.txt...\n");
135  std::ofstream ofs;
136  ofs.open(configName + "4Mathematica.txt", std::ofstream::out | std::ofstream::trunc);
137  ofs << secIDCombis;
138  ofs.close();
139  }
140  }
141 
142  } // SecMapHelper namespace
144 } //Belle2 namespace
Belle2::SecMapHelper::printStaticSectorRelations
void printStaticSectorRelations(const VXDTFFilters< HitType > &filters, const std::string &configName, unsigned int nHitCombinations=2, bool print2File=true, bool suppressDeadSectors=true)
TODO dot-compatible version of printStaticSectorRelations:
Definition: VXDTFFiltersHelperFunctions.h:85
Belle2::VXDTFFilters
Class that contains all the static sectors to which the filters are attached.
Definition: VXDTFFilters.h:75
Belle2::VXDTFFilters::getStaticSectors
const std::vector< staticSector_t * > & getStaticSectors() const
JKL: intended for some checks only - returns CompactIDsMap storing the static sectors.
Definition: VXDTFFilters.h:296
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19