Belle II Software development
SectorMapComparer.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
9
10#pragma once
11
12#include <framework/logging/Logger.h>
13
14#include <TTree.h>
15#include <TH1F.h>
16
17#include <unordered_map>
18#include <iostream>
19
20namespace Belle2 {
38 class SectorMapComparer : public TObject {
39 public:
47 SectorMapComparer(const std::string& SMFileFirst, const std::string& SMFileSecond);
48
50 ~SectorMapComparer() = default;
51
52
59 void plot(bool logScale = true, TString pdfFileName = "", bool drawLegend = true);
60
67 void plotSectorStats(bool logScale = true, TString pdfFileName = "", bool drawLegend = true);
68
70 void compareMaps(TString setup, bool unmatchedEntries = false);
71
74 {
75 std::cout << std::endl;
77 std::cout << std::endl;
79 }
80
82 void showSetups(TString sectorMapFileName);
83
85 void showFiles()
86 {
87 B2INFO("Following files will be compared:");
88 B2INFO("=================================");
89 B2INFO("First : " << m_SMFileName_first);
90 B2INFO("Second: " << m_SMFileName_second);
91 }
92
93
94 private:
95
96
102 uint countConnections(const std::unordered_map<uint, uint>& map, int layer = -1, int ladder = -1, int sensor = -1,
103 int sector = -1);
104
109 std::string getHash(long l1, long l2, long l3);
110
115 void findTrees(TDirectory* aDir, std::vector<std::string>& listOfTrees);
116
122 void setLeafAddresses(TTree* t, std::unordered_map<std::string, double>& filterVals,
123 std::unordered_map<std::string, uint>& SecIDVals);
124
130 void fillSectorToTreeIndexMap(TTree* tree, std::unordered_map<std::string, long>& map);
131
137 void compareTrees(TTree* t_first, TTree* t_second, bool unmatchedEntries = false);
138
141 {
142 m_histo_map_first.clear();
143 m_histo_map_second.clear();
144 m_histo_map_diff.clear();
147 m_map_N2HitCombs.clear();
149 m_map_N3HitCombs.clear();
151 }
152
153 // stores the histograms
154 // WARNING: these will be reused!
155 std::unordered_map<std::string, TH1F> m_histo_map_first;
156 std::unordered_map<std::string, TH1F> m_histo_map_second;
157 std::unordered_map<std::string, TH1F> m_histo_map_diff;
158 std::unordered_map<std::string, TH1F> m_histo_map_range_first;
159 std::unordered_map<std::string, TH1F> m_histo_map_range_second;
160
162 std::unordered_map<uint, uint> m_map_N2HitCombs;
164 std::unordered_map<uint, uint> m_map_N2HitCombs_matched;
165
167 std::unordered_map<uint, uint> m_map_N3HitCombs;
169 std::unordered_map<uint, uint> m_map_N3HitCombs_matched;
170
171
172
173 std::string m_SMFileName_first;
175
176 std::string m_setupsTreeName = "Setups";
177 std::string m_setupsBranchName = "name";
178
180 bool m_isCompared = false;
181
182 // we dont want to write out this class, so version number should stay 0
183 ClassDef(SectorMapComparer, 0)
184 };
186}// end namespace
A root tool that compares two Sectormaps (local root files) and produces some statistics output.
std::string m_SMFileName_first
name of the file containing the first sectormap
void findTrees(TDirectory *aDir, std::vector< std::string > &listOfTrees)
helper function that returns a list of names for all trees contained in the TDirectory including sub-...
std::unordered_map< uint, uint > m_map_N3HitCombs_matched
count the number of 3Hit connections for each sector, only if sector combination was "matched" (Note:...
std::unordered_map< uint, uint > m_map_N3HitCombs
count the number of 3Hit connections for each sector, can be used to do some statistics
void compareMaps(TString setup, bool unmatchedEntries=false)
runs the comparison for all filters (and only the filters) in the sectormap files
std::string getHash(long l1, long l2, long l3)
I was too lacy to implement a proper hash function, so I convert the three numbers into a string and ...
std::string m_setupsBranchName
name of the branch in the setups tree that holds the names of the setups
std::string m_SMFileName_second
name of the file containing the second sectormap
std::unordered_map< std::string, TH1F > m_histo_map_second
histograms for the second sector map
void fillSectorToTreeIndexMap(TTree *tree, std::unordered_map< std::string, long > &map)
fills a map that maps sector combinations in the tree to string which is a hash combining the three (...
void clearMaps()
helper that clears all the maps used
std::unordered_map< uint, uint > m_map_N2HitCombs
count the number of 2Hit connections for each sector,
void showSetups()
lists all setups of sectormaps included in the two files
void showFiles()
lists the names of the files which are used
std::unordered_map< std::string, TH1F > m_histo_map_range_second
histograms that store the range of that filter (max - min)
void plot(bool logScale=true, TString pdfFileName="", bool drawLegend=true)
will create lots of Canvases!!!
std::unordered_map< std::string, TH1F > m_histo_map_diff
histograms that store differences between the two sector maps
std::unordered_map< std::string, TH1F > m_histo_map_range_first
histograms that store the range of that filter (max - min)
std::unordered_map< std::string, TH1F > m_histo_map_first
histograms for the first sector map
void setLeafAddresses(TTree *t, std::unordered_map< std::string, double > &filterVals, std::unordered_map< std::string, uint > &SecIDVals)
automatically sets the TLeaf addresses for a tree.
SectorMapComparer()=delete
dont use this constructor
void compareTrees(TTree *t_first, TTree *t_second, bool unmatchedEntries=false)
makes the comparison of two trees, and fills histograms and certain maps
uint countConnections(const std::unordered_map< uint, uint > &map, int layer=-1, int ladder=-1, int sensor=-1, int sector=-1)
counts all connections for given layer, ladder, sensor, sector.
std::unordered_map< uint, uint > m_map_N2HitCombs_matched
count the number of 2Hit connections for each sector, only if sector combination was "matched" (Note:...
std::string m_setupsTreeName
name of the tree all the setups are stored
bool m_isCompared
remember if CompareMaps already has been run, to give warnings if functions are called that need Comp...
~SectorMapComparer()=default
default destructor
void plotSectorStats(bool logScale=true, TString pdfFileName="", bool drawLegend=true)
Will create canvases showing statistics.
Abstract base class for different kinds of events.