CMS 3D CMS Logo

ExpressionHisto.h
Go to the documentation of this file.
1 #ifndef CommonTools_Utils_ExpressionHisto_h
2 #define CommonTools_Utils_ExpressionHisto_h
3 // -*- C++ -*-
4 //
5 // Package: UtilAlgos
6 // Class : ExpressionHisto
7 //
16 //
17 // Original Author: Benedikt HEGNER
18 // Created: Fri Jun 1 14:35:22 CEST 2007
19 // $Id: ExpressionHisto.h,v 1.2 2009/07/09 10:52:01 gpetrucc Exp $
20 //
21 
22 // system include files
23 
24 // user include files
28 
29 #include "TFile.h"
30 #include "TH1F.h"
31 #include "TH1.h"
32 
33 template <typename T>
35 public:
36  ExpressionHisto(const edm::ParameterSet& iConfig);
38 
39  void initialize(TFileDirectory& fs);
45  bool fill(const T& element, double weight = 1.0, uint32_t i = 0);
46 
47 private:
48  double min, max;
49  int nbins;
51  uint32_t nhistos;
53  TH1F** hist;
55 };
56 
57 template <typename T>
59  : min(iConfig.template getUntrackedParameter<double>("min")),
60  max(iConfig.template getUntrackedParameter<double>("max")),
61  nbins(iConfig.template getUntrackedParameter<int>("nbins")),
62  name(iConfig.template getUntrackedParameter<std::string>("name")),
63  description(iConfig.template getUntrackedParameter<std::string>("description")),
64  function(iConfig.template getUntrackedParameter<std::string>("plotquantity"),
65  iConfig.template getUntrackedParameter<bool>("lazyParsing", false)) {
66  int32_t itemsToPlot = iConfig.template getUntrackedParameter<int32_t>("itemsToPlot", -1);
67  if (itemsToPlot <= 0) {
68  nhistos = 1;
69  separatePlots = false;
70  } else {
71  nhistos = itemsToPlot;
72  separatePlots = true;
73  }
74 }
75 
76 template <typename T>
78 
79 template <typename T>
81  hist = new TH1F*[nhistos];
82  char buff[1024], baff[1024];
83  if (separatePlots) {
84  for (uint32_t i = 0; i < nhistos; i++) {
85  if (strstr(name.c_str(), "%d") != nullptr) {
86  snprintf(buff, 1024, name.c_str(), i + 1);
87  } else {
88  snprintf(buff, 1024, "%s [#%d]", name.c_str(), i + 1);
89  }
90  if (strstr(description.c_str(), "%d") != nullptr) {
91  snprintf(baff, 1024, description.c_str(), i + 1);
92  } else {
93  snprintf(baff, 1024, "%s [#%d]", description.c_str(), i + 1);
94  }
95  hist[i] = fs.make<TH1F>(buff, baff, nbins, min, max);
96  }
97  } else {
98  hist[0] = fs.make<TH1F>(name.c_str(), description.c_str(), nbins, min, max);
99  }
100 }
101 
102 template <typename T>
103 bool ExpressionHisto<T>::fill(const T& element, double weight, uint32_t i) {
104  if (!separatePlots)
105  hist[0]->Fill(function(element), weight);
106  else if (i < nhistos)
107  hist[i]->Fill(function(element), weight);
108  else
109  return false;
110  return true;
111 }
112 
113 #endif
ExpressionHisto::separatePlots
bool separatePlots
Definition: ExpressionHisto.h:52
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
StringObjectFunction< T >
funct::false
false
Definition: Factorize.h:29
min
T min(T a, T b)
Definition: MathUtil.h:58
edmLumisInFiles.description
description
Definition: edmLumisInFiles.py:11
ExpressionHisto
Definition: ExpressionHisto.h:34
ExpressionHisto::fill
bool fill(const T &element, double weight=1.0, uint32_t i=0)
Definition: ExpressionHisto.h:103
ExpressionHisto::max
double max
Definition: ExpressionHisto.h:48
ExpressionHisto::min
double min
Definition: ExpressionHisto.h:48
ExpressionHisto::initialize
void initialize(TFileDirectory &fs)
Definition: ExpressionHisto.h:80
TFileDirectory
Definition: TFileDirectory.h:24
TFileDirectory.h
ExpressionHisto::hist
TH1F ** hist
Definition: ExpressionHisto.h:53
ExpressionHisto::nbins
int nbins
Definition: ExpressionHisto.h:49
LaserClient_cfi.nbins
nbins
Definition: LaserClient_cfi.py:51
ExpressionHisto::description
std::string description
Definition: ExpressionHisto.h:50
ExpressionHisto::name
std::string name
Definition: ExpressionHisto.h:50
ExpressionHisto::ExpressionHisto
ExpressionHisto(const edm::ParameterSet &iConfig)
Definition: ExpressionHisto.h:58
edm::ParameterSet
Definition: ParameterSet.h:47
ExpressionHisto::nhistos
uint32_t nhistos
Definition: ExpressionHisto.h:51
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
gpuVertexFinder::hist
__shared__ Hist hist
Definition: gpuClusterTracksDBSCAN.h:48
createfilelist.int
int
Definition: createfilelist.py:10
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
std
Definition: JetResolutionObject.h:76
T
long double T
Definition: Basic3DVectorLD.h:48
TFileDirectory::make
T * make(const Args &...args) const
make new ROOT object
Definition: TFileDirectory.h:53
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
ParameterSet.h
StringObjectFunction.h
ExpressionHisto::~ExpressionHisto
~ExpressionHisto()
Definition: ExpressionHisto.h:77
weight
Definition: weight.py:1