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