Belle II Software  release-05-02-19
SectorMapComparer.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Lueck *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 
12 #pragma once
13 
14 #include <framework/logging/Logger.h>
15 
16 #include <TTree.h>
17 #include <TH1F.h>
18 
19 #include <unordered_map>
20 #include <iostream>
21 
22 namespace Belle2 {
40  class SectorMapComparer : public TObject {
41  public:
43  SectorMapComparer() = delete;
49  SectorMapComparer(const std::string& SMFileFirst, const std::string& SMFileSecond);
50 
52  ~SectorMapComparer() = default;
53 
54 
61  void plot(bool logScale = true, TString pdfFileName = "", bool drawLegend = true);
62 
69  void plotSectorStats(bool logScale = true, TString pdfFileName = "", bool drawLegend = true);
70 
72  void compareMaps(TString setup, bool unmatchedEntries = false);
73 
75  void showSetups()
76  {
77  std::cout << std::endl;
79  std::cout << std::endl;
81  }
82 
84  void showSetups(TString sectorMapFileName);
85 
87  void showFiles()
88  {
89  B2INFO("Following files will be compared:");
90  B2INFO("=================================");
91  B2INFO("First : " << m_SMFileName_first);
92  B2INFO("Second: " << m_SMFileName_second);
93  }
94 
95 
96  private:
97 
98 
104  uint countConnections(const std::unordered_map<uint, uint>& map, int layer = -1, int ladder = -1, int sensor = -1,
105  int sector = -1);
106 
111  std::string getHash(long l1, long l2, long l3);
112 
117  void findTrees(TDirectory* aDir, std::vector<std::string>& listOfTrees);
118 
124  void setLeafAddresses(TTree* t, std::unordered_map<std::string, double>& filterVals,
125  std::unordered_map<std::string, uint>& SecIDVals);
126 
132  void fillSectorToTreeIndexMap(TTree* tree, std::unordered_map<std::string, long>& map);
133 
139  void compareTrees(TTree* t_first, TTree* t_second, bool unmatchedEntries = false);
140 
142  void clearMaps()
143  {
144  m_histo_map_first.clear();
145  m_histo_map_second.clear();
146  m_histo_map_diff.clear();
147  m_histo_map_range_first.clear();
148  m_histo_map_range_second.clear();
149  m_map_N2HitCombs.clear();
151  m_map_N3HitCombs.clear();
152  m_map_N3HitCombs_matched.clear();
153  }
154 
155  // stores the histograms
156  // WARNING: these will be reused!
157  std::unordered_map<std::string, TH1F> m_histo_map_first;
158  std::unordered_map<std::string, TH1F> m_histo_map_second;
159  std::unordered_map<std::string, TH1F> m_histo_map_diff;
160  std::unordered_map<std::string, TH1F> m_histo_map_range_first;
161  std::unordered_map<std::string, TH1F> m_histo_map_range_second;
162 
164  std::unordered_map<uint, uint> m_map_N2HitCombs;
166  std::unordered_map<uint, uint> m_map_N2HitCombs_matched;
167 
169  std::unordered_map<uint, uint> m_map_N3HitCombs;
171  std::unordered_map<uint, uint> m_map_N3HitCombs_matched;
172 
173 
174 
175  std::string m_SMFileName_first;
176  std::string m_SMFileName_second;
177 
178  std::string m_setupsTreeName = "Setups";
179  std::string m_setupsBranchName = "name";
180 
182  bool m_isCompared = false;
183 
184  // we dont want to write out this class, so version number should stay 0
185  ClassDef(SectorMapComparer, 0)
186  };
188 }// end namespace
setup
Belle2::SectorMapComparer::clearMaps
void clearMaps()
helper that clears all the maps used
Definition: SectorMapComparer.h:150
Belle2::SectorMapComparer::m_histo_map_first
std::unordered_map< std::string, TH1F > m_histo_map_first
histograms for the first sector map
Definition: SectorMapComparer.h:165
Belle2::SectorMapComparer::compareMaps
void compareMaps(TString setup, bool unmatchedEntries=false)
runs the comparison for all filters (and only the filters) in the sectormap files
Definition: SectorMapComparer.cc:339
Belle2::SectorMapComparer::~SectorMapComparer
~SectorMapComparer()=default
default destructor
Belle2::SectorMapComparer::getHash
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 ...
Definition: SectorMapComparer.cc:42
Belle2::SectorMapComparer::m_map_N3HitCombs_matched
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:...
Definition: SectorMapComparer.h:179
Belle2::SectorMapComparer::m_histo_map_diff
std::unordered_map< std::string, TH1F > m_histo_map_diff
histograms that store differences between the two sector maps
Definition: SectorMapComparer.h:167
Belle2::SectorMapComparer::SectorMapComparer
SectorMapComparer()=delete
dont use this constructor
Belle2::SectorMapComparer::m_histo_map_second
std::unordered_map< std::string, TH1F > m_histo_map_second
histograms for the second sector map
Definition: SectorMapComparer.h:166
Belle2::SectorMapComparer::m_map_N2HitCombs
std::unordered_map< uint, uint > m_map_N2HitCombs
count the number of 2Hit connections for each sector,
Definition: SectorMapComparer.h:172
Belle2::SectorMapComparer::plotSectorStats
void plotSectorStats(bool logScale=true, TString pdfFileName="", bool drawLegend=true)
Will create canvases showing statistics.
Definition: SectorMapComparer.cc:426
Belle2::SectorMapComparer::m_isCompared
bool m_isCompared
remember if CompareMaps already has been run, to give warnings if functions are called that need Comp...
Definition: SectorMapComparer.h:190
Belle2::SectorMapComparer::m_SMFileName_first
std::string m_SMFileName_first
name of the file containing the first sectormap
Definition: SectorMapComparer.h:183
Belle2::SectorMapComparer::findTrees
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-...
Definition: SectorMapComparer.cc:268
Belle2::SectorMapComparer::m_setupsBranchName
std::string m_setupsBranchName
name of the branch in the setups tree that holds the names of the setups
Definition: SectorMapComparer.h:187
Belle2::SectorMapComparer::plot
void plot(bool logScale=true, TString pdfFileName="", bool drawLegend=true)
will create lots of Canvases!!!
Definition: SectorMapComparer.cc:287
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SectorMapComparer::showFiles
void showFiles()
lists the names of the files which are used
Definition: SectorMapComparer.h:95
Belle2::SectorMapComparer::m_setupsTreeName
std::string m_setupsTreeName
name of the tree all the setups are stored
Definition: SectorMapComparer.h:186
Belle2::SectorMapComparer::m_histo_map_range_first
std::unordered_map< std::string, TH1F > m_histo_map_range_first
histograms that store the range of that filter (max - min)
Definition: SectorMapComparer.h:168
Belle2::SectorMapComparer::setLeafAddresses
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.
Definition: SectorMapComparer.cc:53
Belle2::SectorMapComparer::m_map_N2HitCombs_matched
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:...
Definition: SectorMapComparer.h:174
Belle2::SectorMapComparer::m_SMFileName_second
std::string m_SMFileName_second
name of the file containing the second sectormap
Definition: SectorMapComparer.h:184
Belle2::SectorMapComparer::fillSectorToTreeIndexMap
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 (...
Definition: SectorMapComparer.cc:83
Belle2::SectorMapComparer::countConnections
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.
Definition: SectorMapComparer.cc:408
Belle2::SectorMapComparer
A root tool that compares two Sectormaps (local root files) and produces some statistics output.
Definition: SectorMapComparer.h:48
Belle2::SectorMapComparer::m_map_N3HitCombs
std::unordered_map< uint, uint > m_map_N3HitCombs
count the number of 3Hit connections for each sector, can be used to do some statistics
Definition: SectorMapComparer.h:177
Belle2::SectorMapComparer::showSetups
void showSetups()
lists all setups of sectormaps included in the two files
Definition: SectorMapComparer.h:83
Belle2::SectorMapComparer::m_histo_map_range_second
std::unordered_map< std::string, TH1F > m_histo_map_range_second
histograms that store the range of that filter (max - min)
Definition: SectorMapComparer.h:169
Belle2::SectorMapComparer::compareTrees
void compareTrees(TTree *t_first, TTree *t_second, bool unmatchedEntries=false)
makes the comparison of two trees, and fills histograms and certain maps
Definition: SectorMapComparer.cc:113