ATLAS Offline Software
SCT_SimpleHisto.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5 */
6 
14 #ifndef SCT_SimpleHisto_h
15 #define SCT_SimpleHisto_h
16 
17 #include <map>
18 #include <string>
19 #include <sstream>
20 
21 namespace SCT_ConditionsAlgorithms {
22  typedef std::map<float, unsigned int> S_t;
23 
25  bool
26  init(S_t& s, const float xlo, const float xhi, const unsigned int nbins) {
27  if ((xhi <= xlo) or (nbins<2)) return false;
28  float increment{(xhi-xlo)/nbins};
29  float acc{xlo};
30  unsigned int init{0};
31  for (unsigned int i{0}; i!=nbins; ++i) {
32  s[acc]=init;
33  acc+=increment;
34  }
35  return (s.size()==nbins); //should be true now
36  }//initHisto function
37 
38  //increment a bin
39  int
40  fill(S_t& s, const float value) {
41  S_t::const_iterator start{s.begin()};
42  S_t::const_iterator end{s.end()};
43  unsigned int nbins{static_cast<unsigned int>(s.size())};
44  if (value * nbins > ((--end)->first - start->first) * (nbins+1)) return 1;
45  S_t::iterator i=s.upper_bound(value);
46  if (i==start) return -1;
47  ++((--i)->second);
48  return 0;
49  }//fill function
50 
51  //return xml string representation
52  std::string
53  asXmlString(const S_t& s) {
54  std::ostringstream os;
55  os<<"<histogram>\n";
56  for (S_t::const_iterator i{s.begin()}; i!=s.end(); ++i) {
57  os<<"<b x=\""<<i->first<<"\">"<<i->second<<"</b>\n";
58  }
59  os<<"</histogram>\n";
60  return os.str();
61  }//asXmlString
62 
63  std::string
64  xmlHeader(const std::string& version="1.0", const std::string& encoding="UTF-8") {
65  return "<?xml version=\""+version+"\" encoding=\""+encoding+"\" standalone=\"yes\"?>";
66  }
67  std::string
68  stylesheet(const std::string& path) {
69  return "<?xml-stylesheet type=\"text/xsl\" href=\""+path+"\"?>";
70  }
71 
72 }//namespace
73 
74 #endif // SCT_SimpleHisto_h
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
SCT_ConditionsAlgorithms::stylesheet
std::string stylesheet(const std::string &path)
Definition: SCT_SimpleHisto.h:68
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
athena.value
value
Definition: athena.py:124
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
SCT_ConditionsAlgorithms::fill
int fill(S_t &s, const float value)
Definition: SCT_SimpleHisto.h:40
SCT_ConditionsAlgorithms::xmlHeader
std::string xmlHeader(const std::string &version="1.0", const std::string &encoding="UTF-8")
Definition: SCT_SimpleHisto.h:64
WritePulseShapeToCool.xhi
xhi
Definition: WritePulseShapeToCool.py:152
lumiFormat.i
int i
Definition: lumiFormat.py:85
generateReferenceFile.encoding
encoding
Definition: generateReferenceFile.py:15
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
WritePulseShapeToCool.xlo
xlo
Definition: WritePulseShapeToCool.py:133
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
SCT_ConditionsAlgorithms::S_t
std::map< float, unsigned int > S_t
Definition: SCT_SimpleHisto.h:22
SCT_ConditionsAlgorithms::asXmlString
std::string asXmlString(const S_t &s)
Definition: SCT_SimpleHisto.h:53
SCT_ConditionsAlgorithms
SCT_SimpleHisto.h C++ projects.
Definition: SCT_ConditionsUtilities.cxx:14
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
get_generator_info.version
version
Definition: get_generator_info.py:33
DeMoScan.first
bool first
Definition: DeMoScan.py:536
SCT_ConditionsAlgorithms::init
bool init(S_t &s, const float xlo, const float xhi, const unsigned int nbins)
Initialize a map to be used as a histogram.
Definition: SCT_SimpleHisto.h:26