ATLAS Offline Software
FlexProfileArray.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Header file for class FlexProfileArray //
9 // //
10 // Description: Container for the information needed by //
11 // the bins in profile histograms. Using float //
12 // internally, but double in all interfaces. //
13 // //
14 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
15 // Initial version: July 2009 //
16 // //
18 
19 #ifndef FLEXPROFILEARRAY_H
20 #define FLEXPROFILEARRAY_H
21 
22 #include <cstring>//memset
23 #include <cmath>
24 #include <cassert>
25 #include <iostream>
26 #include "LWPools.h"
27 
28 #define FLEXPROFILEARRAY_NBINSPERGROUP 8
29 
31 public:
32 
33  static unsigned extraAllocSize(unsigned nbins) { return nGroups(nbins)*sizeof(float*); }
34 
35  FlexProfileArray( unsigned nbins );
37 
38  unsigned getNBins() const { return m_nbins; }
39 
40  //Filling:
41  void fill(unsigned bin, const double& profiledpar);
42  void fill(unsigned bin, const double& profiledpar, const double& weight);
43 
44  //Getters:
45  double getBinEntries(unsigned bin) const;
46  double getBinContent(unsigned bin) const;
47  double getBinError(unsigned bin) const;
48  void getBinInfo(unsigned bin, double& entries, double& content, double& error ) const;
49 
50  //Setters:
51  void setBinEntries(unsigned bin, const double&);
52  void setBinContent(unsigned bin, const double&);
53  void setBinError(unsigned bin, const double&);
54  void setBinInfo(unsigned bin, const double& entries, const double& content, const double& error );
55 
56  //get all contents in flat arrays:
57  void copyContents(double* entries, double*contents, double*errors) const;
58 
59  //Options to change error calculations:
62  void setErrorOptionFromString(const char *option);
63  const char* getErrorOptionAsString() const;
64 
65  //Misc:
66  void reset();
67  double integral() const;
68 
69 private:
70  //Simple arrays for now:
71  const unsigned m_nbins;
73  float ** m_groups;
74  float * getPtr(unsigned ibin);//returns f -> f[0]: entries, f[1]: contents, f[2]: error
75  float * getPtrNoAlloc(unsigned ibin) const;//returns 0 or pointer as above
77  static unsigned groupIndex(unsigned ibin) { return ibin/FLEXPROFILEARRAY_NBINSPERGROUP; }
78  static unsigned indexInGroup(unsigned ibin) { return (ibin%FLEXPROFILEARRAY_NBINSPERGROUP)*3; }//3 because there are three fields per bin
79  static float* allocateGroup();
80  static void deallocateGroup(float*);
81  unsigned nbinsInLastGroup() const
82  {
85  }
86 
87  //For now we keep a float for each of contents, errors, and entries,
88  //and we keep those 12 bytes next to each other. This already gives
89  //a factor of 2 reduction compared to ROOT (NB: internally the float
90  //used for "errors" might be used for a different, more numerically
91  //robust, quantity).
92  //
93  //We also allocate those 12 bytes in groups of X bins (X=16?), meaning that we need an index
94  //array (overhead of unused groups sizeof(void*)).
95  //
96  //Footprint in bytes per group/per bin given X bins-per-group is:
97  //
98  //------|--------------------|------------------------|
99  // X | <unused groups> | <used groups> |
100  // | 32bit 64bit | 32bit 64bit |
101  //------|--------------------|------------------------|
102  // 1 | 4/4 8/8 | 16/16 20/20 |
103  // 2 | 4/2 8/4 | 28/14 32/16 |
104  // 4 | 4/1 8/2 | 52/13 56/14 |
105  // 8 | 4/0.5 8/1 | 100/12.5 104/13 |
106  // 16 | 4/0.25 8/0.5 | 196/12.25 200/12.5 |
107  // 32 | 4/0.125 8/0.25 | 388/12.125 392/12.25 |
108  // 64 | 4/0.0625 8/0.125 | 772/12.0625 776/12.125 |
109  //------|--------------------|------------------------|
110  //
111  //The optimal size is difficult to guess in advance, as it will
112  //depend on how the histograms are used. But from looking at it, X=8
113  //seems to be a good guess to get started.
114  //
115  //At a cost in cpu, this can be improved upon. For instance, entries
116  //could follow the uchar->ushrt->float cycle, at a potential gain of
117  //up to 25% (12bytes->9bytes, excluding pointer-to-group overhead),
118  //in the case where no weighted fills are used, giving an average
119  //gain of perhaps O(10%)? This is probably not worth it.
120 
121  double computeBinError(float*f) const;
122 
123 };
124 
125 #include "FlexProfileArray.icc"
126 
127 #endif
FlexProfileArray::m_errOpt
ERROROPTION m_errOpt
Definition: FlexProfileArray.h:72
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
FlexProfileArray::getPtrNoAlloc
float * getPtrNoAlloc(unsigned ibin) const
LWPools.h
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:128
FlexProfileArray::setBinContent
void setBinContent(unsigned bin, const double &)
FlexProfileArray::m_groups
float ** m_groups
Definition: FlexProfileArray.h:73
FlexProfileArray::computeBinError
double computeBinError(float *f) const
FlexProfileArray.icc
FlexProfileArray::ERRORSPREADG
@ ERRORSPREADG
Definition: FlexProfileArray.h:60
FlexProfileArray::setErrorOption
void setErrorOption(ERROROPTION e)
Definition: FlexProfileArray.h:61
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
FlexProfileArray::groupIndex
static unsigned groupIndex(unsigned ibin)
Definition: FlexProfileArray.h:77
FlexProfileArray::deallocateGroup
static void deallocateGroup(float *)
bin
Definition: BinsDiffFromStripMedian.h:43
FlexProfileArray::FlexProfileArray
FlexProfileArray(unsigned nbins)
FlexProfileArray::setBinError
void setBinError(unsigned bin, const double &)
FlexProfileArray::~FlexProfileArray
~FlexProfileArray()
FlexProfileArray::nbinsInLastGroup
unsigned nbinsInLastGroup() const
Definition: FlexProfileArray.h:81
FlexProfileArray::ERRORMEAN
@ ERRORMEAN
Definition: FlexProfileArray.h:60
FlexProfileArray::extraAllocSize
static unsigned extraAllocSize(unsigned nbins)
Definition: FlexProfileArray.h:33
FlexProfileArray::integral
double integral() const
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:190
grepfile.content
string content
Definition: grepfile.py:56
FlexProfileArray::setErrorOptionFromString
void setErrorOptionFromString(const char *option)
FlexProfileArray::getBinEntries
double getBinEntries(unsigned bin) const
FlexProfileArray::copyContents
void copyContents(double *entries, double *contents, double *errors) const
FlexProfileArray::ERROROPTION
ERROROPTION
Definition: FlexProfileArray.h:60
beamspotman.n
n
Definition: beamspotman.py:731
FlexProfileArray::setBinEntries
void setBinEntries(unsigned bin, const double &)
FlexProfileArray
Definition: FlexProfileArray.h:30
FlexProfileArray::getBinError
double getBinError(unsigned bin) const
FlexProfileArray::getNBins
unsigned getNBins() const
Definition: FlexProfileArray.h:38
contents
void contents(std::vector< std::string > &keys, TDirectory *td, const std::string &directory, const std::string &pattern, const std::string &path)
Definition: computils.cxx:319
FlexProfileArray::setBinInfo
void setBinInfo(unsigned bin, const double &entries, const double &content, const double &error)
mergePhysValFiles.errors
list errors
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:43
FlexProfileArray::getBinContent
double getBinContent(unsigned bin) const
FlexProfileArray::ERRORSPREADI
@ ERRORSPREADI
Definition: FlexProfileArray.h:60
FlexProfileArray::nGroups
static unsigned nGroups(unsigned nbins)
Definition: FlexProfileArray.h:76
FLEXPROFILEARRAY_NBINSPERGROUP
#define FLEXPROFILEARRAY_NBINSPERGROUP
Definition: FlexProfileArray.h:28
FlexProfileArray::fill
void fill(unsigned bin, const double &profiledpar, const double &weight)
FlexProfileArray::getErrorOptionAsString
const char * getErrorOptionAsString() const
FlexProfileArray::ERRORSPREAD
@ ERRORSPREAD
Definition: FlexProfileArray.h:60
FlexProfileArray::getPtr
float * getPtr(unsigned ibin)
FlexProfileArray::fill
void fill(unsigned bin, const double &profiledpar)
entries
double entries
Definition: listroot.cxx:49
FlexProfileArray::allocateGroup
static float * allocateGroup()
FlexProfileArray::indexInGroup
static unsigned indexInGroup(unsigned ibin)
Definition: FlexProfileArray.h:78
error
Definition: IImpactPoint3dEstimator.h:70
FlexProfileArray::reset
void reset()
FlexProfileArray::m_nbins
const unsigned m_nbins
Definition: FlexProfileArray.h:71
FlexProfileArray::getBinInfo
void getBinInfo(unsigned bin, double &entries, double &content, double &error) const