CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
Histos Class Reference

#include <Histos.h>

Public Types

typedef std::map< std::string, TObject * >::const_iterator HistoItr
 

Public Member Functions

void addObject (const std::string &name, TObject *obj)
 Add any object. More...
 
void book (const std::string &name, int nx, float xmin, float xmax, const std::string &option)
 
void book (const std::string &name, int nx, float xmin, float xmax, int ny=0, float ymin=0., float ymax=0.)
 Book an histogram (1D or 2D) More...
 
void bookByNumber (const std::string &name, int n1, int n2, int nx, float xmin, float xmax, int ny=0, float ymin=0., float ymax=0.)
 
void debug (std::string p="") const
 
void divide (const std::string &h1, const std::string &h2, const std::string &h3)
 Divide two histograms and put the result in the first. More...
 
void fill (const std::string &name, float val1, float val2=1., float val3=1.)
 Fill an histogram. More...
 
void fillByNumber (const std::string &name, int number, float val1, float val2=1., float val3=1.)
 
void put (const std::string &file, std::string name="")
 Write one or all histogram(s) in a file. More...
 
virtual ~Histos ()
 Destructor. More...
 

Static Public Member Functions

static Histosinstance ()
 

Private Member Functions

 Histos ()
 

Private Attributes

TObject * theHisto
 
std::map< std::string, TObject * > theHistos
 
std::map< std::string, TObject * > theObjects
 
std::map< std::string, unsigned > theTypes
 

Static Private Attributes

static Histosmyself = nullptr
 

Detailed Description

This class provides an interface to root histograms

Author
Patrick Janot $Date: 16 Jan 2004 19:30

Definition at line 19 of file Histos.h.

Member Typedef Documentation

◆ HistoItr

typedef std::map<std::string, TObject*>::const_iterator Histos::HistoItr

Definition at line 21 of file Histos.h.

Constructor & Destructor Documentation

◆ ~Histos()

Histos::~Histos ( )
virtual

Destructor.

Definition at line 21 of file Histos.cc.

21 {}

◆ Histos()

Histos::Histos ( )
private

Definition at line 13 of file Histos.cc.

13 {}

Referenced by instance().

Member Function Documentation

◆ addObject()

void Histos::addObject ( const std::string &  name,
TObject *  obj 
)

Add any object.

Definition at line 115 of file Histos.cc.

115  {
116  HistoItr hh = theObjects.find(name);
117  if (hh != theObjects.end()) {
118  std::cout << "FamosHistos::addObject() : Object " << name << " already exists" << std::endl;
119  return;
120  }
121  // Potential source of memory leaks if not carefully used
122  theObjects.insert(std::pair<std::string, TObject*>(name, obj->Clone()));
123 }

References gather_cfg::cout, hh, Skims_PA_cff::name, getGTfromDQMFile::obj, and theObjects.

◆ book() [1/2]

void Histos::book ( const std::string &  name,
int  nx,
float  xmin,
float  xmax,
const std::string &  option 
)

Book a TProfile option="S" -> spread "" -> error on mean (from Root documentation)

Definition at line 39 of file Histos.cc.

39  {
40  if (theHistos.find(name) != theHistos.end()) {
41  std::cout << "Histos::book() : Histogram " << name << " exists already. Nothing done" << std::endl;
42 
43  } else {
44  theHistos[name] = new TProfile(name.c_str(), "", nx, xmin, xmax, option.c_str());
45  theTypes[name] = 3;
46  }
47 }

References gather_cfg::cout, Skims_PA_cff::name, fileinputsource_cfi::option, theHistos, theTypes, TrackerOfflineValidation_Dqm_cff::xmax, and TrackerOfflineValidation_Dqm_cff::xmin.

◆ book() [2/2]

void Histos::book ( const std::string &  name,
int  nx,
float  xmin,
float  xmax,
int  ny = 0,
float  ymin = 0.,
float  ymax = 0. 
)

Book an histogram (1D or 2D)

Definition at line 23 of file Histos.cc.

23  {
24  if (theHistos.find(name) != theHistos.end()) {
25  std::cout << "Histos::book() : Histogram " << name << " exists already. Nothing done" << std::endl;
26 
27  } else {
28  if (ny) {
29  theHistos[name] = new TH2F(name.c_str(), "", nx, xmin, xmax, ny, ymin, ymax);
30  theTypes[name] = 2;
31 
32  } else {
33  theHistos[name] = new TH1F(name.c_str(), "", nx, xmin, xmax);
34  theTypes[name] = 1;
35  }
36  }
37 }

References gather_cfg::cout, Skims_PA_cff::name, theHistos, theTypes, TrackerOfflineValidation_Dqm_cff::xmax, TrackerOfflineValidation_Dqm_cff::xmin, L1TOccupancyClient_cfi::ymax, and L1TOccupancyClient_cfi::ymin.

Referenced by bookByNumber().

◆ bookByNumber()

void Histos::bookByNumber ( const std::string &  name,
int  n1,
int  n2,
int  nx,
float  xmin,
float  xmax,
int  ny = 0,
float  ymin = 0.,
float  ymax = 0. 
)

Definition at line 151 of file Histos.cc.

152  {
153  if (n1 > n2) {
154  std::cout << " Histos: problem with bookByNumber - Do nothing" << std::endl;
155  }
156  for (int ih = n1; ih <= n2; ++ih) {
157  std::ostringstream oss;
158  oss << name << ih;
159  book(oss.str(), nx, xmin, xmax, ny, ymin, ymax);
160  }
161 }

References book(), gather_cfg::cout, callgraph::n2, Skims_PA_cff::name, TrackerOfflineValidation_Dqm_cff::xmax, TrackerOfflineValidation_Dqm_cff::xmin, L1TOccupancyClient_cfi::ymax, and L1TOccupancyClient_cfi::ymin.

◆ debug()

void Histos::debug ( std::string  p = "") const
inline

Definition at line 63 of file Histos.h.

63 { std::cout << " Histos myMap : " << &theHistos << " " << p << std::endl; }

References gather_cfg::cout, AlCaHLTBitMon_ParallelJobs::p, and theHistos.

◆ divide()

void Histos::divide ( const std::string &  h1,
const std::string &  h2,
const std::string &  h3 
)

Divide two histograms and put the result in the first.

Definition at line 85 of file Histos.cc.

85  {
86  HistoItr hh1 = theHistos.find(h1);
87  HistoItr hh2 = theHistos.find(h2);
88  HistoItr hh3 = theHistos.find(h3);
89 
90  if (hh1 == theHistos.end() || hh2 == theHistos.end() || hh3 != theHistos.end()) {
91  if (hh1 == theHistos.end())
92  std::cout << "Histos::divide() : First histo " << h1 << " does not exist" << std::endl;
93 
94  if (hh2 == theHistos.end())
95  std::cout << "Histos::divide() : Second histo " << h2 << " does not exist" << std::endl;
96 
97  if (hh3 != theHistos.end())
98  std::cout << "Histos::divide() : Third histo " << h3 << " already exists" << std::endl;
99 
100  } else {
101  if (theTypes[h1] == 1 && theTypes[h2] == 1) {
102  theHistos[h3] = (TH1F*)((*hh1).second)->Clone(h3.c_str());
103  theTypes[h3] = 1;
104  ((TH1F*)theHistos[h3])->Divide((TH1F*)((*hh2).second));
105  }
106 
107  if (theTypes[h1] == 2 && theTypes[h2] == 2) {
108  theHistos[h3] = (TH2F*)((*hh1).second)->Clone(h3.c_str());
109  theTypes[h3] = 2;
110  ((TH2F*)theHistos[h3])->Divide((TH2F*)((*hh2).second));
111  }
112  }
113 }

References gather_cfg::cout, theHistos, and theTypes.

Referenced by python.rootplot.utilities.Hist::__div__().

◆ fill()

void Histos::fill ( const std::string &  name,
float  val1,
float  val2 = 1.,
float  val3 = 1. 
)

Fill an histogram.

Definition at line 125 of file Histos.cc.

125  {
126  // std::cout << " Fill " << name << " " << val1 << " " << val2 << " " << val3 << std::endl;
127  // std::cout << &theHistos << std::endl;
128  HistoItr hh = theHistos.find(name);
129  // std::cout << " Fill done " << std::endl;
130  if (hh == theHistos.end()) {
131  std::cout << "Histos::fill() : Histogram " << name << " does not exist" << std::endl;
132 
133  } else {
134  if (theTypes[name] == 1)
135  ((TH1F*)((*hh).second))->Fill(val1, val2);
136 
137  if (theTypes[name] == 2)
138  ((TH2F*)((*hh).second))->Fill(val1, val2, val3);
139 
140  if (theTypes[name] == 3)
141  ((TProfile*)((*hh).second))->Fill(val1, val2, val3);
142  }
143 }

References gather_cfg::cout, HcalObjRepresent::Fill(), hh, Skims_PA_cff::name, theHistos, and theTypes.

Referenced by fillByNumber(), and CaloGeometryHelper::getClosestCell().

◆ fillByNumber()

void Histos::fillByNumber ( const std::string &  name,
int  number,
float  val1,
float  val2 = 1.,
float  val3 = 1. 
)

Definition at line 145 of file Histos.cc.

145  {
146  std::ostringstream oss;
147  oss << name << number;
148  fill(oss.str(), val1, val2, val3);
149 }

References fill(), Skims_PA_cff::name, and contentValuesFiles::number.

◆ instance()

Histos * Histos::instance ( )
static

Definition at line 15 of file Histos.cc.

15  {
16  if (!myself)
17  myself = new Histos();
18  return myself;
19 }

References Histos(), and myself.

Referenced by EcalHitMaker::EcalHitMaker(), and CaloGeometryHelper::getClosestCell().

◆ put()

void Histos::put ( const std::string &  file,
std::string  name = "" 
)

Write one or all histogram(s) in a file.

Definition at line 49 of file Histos.cc.

49  {
50  TFile* f = new TFile(file.c_str(), "recreate");
51  f->cd();
52 
53  HistoItr ho;
54  for (ho = theObjects.begin(); ho != theObjects.end(); ++ho) {
55  (*ho).second->Write((*ho).first.c_str());
56  }
57 
58  HistoItr hh = theHistos.find(name);
59  if (name.empty())
60  for (hh = theHistos.begin(); hh != theHistos.end(); ++hh) {
61  if (theTypes[(*hh).first] == 1)
62  ((TH1F*)((*hh).second))->Write();
63  if (theTypes[(*hh).first] == 2)
64  ((TH2F*)((*hh).second))->Write();
65  if (theTypes[(*hh).first] == 3)
66  ((TProfile*)((*hh).second))->Write();
67  }
68 
69  else if (hh != theHistos.end()) {
70  if (theTypes[name] == 1)
71  ((TH1F*)((*hh).second))->Write();
72  if (theTypes[name] == 2)
73  ((TH2F*)((*hh).second))->Write();
74  if (theTypes[name] == 3)
75  ((TProfile*)((*hh).second))->Write();
76  }
77 
78  else
79  std::cout << "Histos::put() : Histogram " << name << " does not exist. Nothing done" << std::endl;
80 
81  f->Write();
82  f->Close();
83 }

References gather_cfg::cout, f, geometryDiff::file, hh, photonIsolationHIProducer_cfi::ho, Skims_PA_cff::name, theHistos, theObjects, and theTypes.

Member Data Documentation

◆ myself

Histos * Histos::myself = nullptr
staticprivate

Definition at line 71 of file Histos.h.

Referenced by instance().

◆ theHisto

TObject* Histos::theHisto
private

Definition at line 74 of file Histos.h.

◆ theHistos

std::map<std::string, TObject*> Histos::theHistos
private

Definition at line 75 of file Histos.h.

Referenced by book(), debug(), divide(), fill(), and put().

◆ theObjects

std::map<std::string, TObject*> Histos::theObjects
private

Definition at line 77 of file Histos.h.

Referenced by addObject(), and put().

◆ theTypes

std::map<std::string, unsigned> Histos::theTypes
private

Definition at line 76 of file Histos.h.

Referenced by book(), divide(), fill(), and put().

Histos::theHistos
std::map< std::string, TObject * > theHistos
Definition: Histos.h:75
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
gather_cfg.cout
cout
Definition: gather_cfg.py:144
fileinputsource_cfi.option
option
Definition: fileinputsource_cfi.py:94
Histos::theTypes
std::map< std::string, unsigned > theTypes
Definition: Histos.h:76
Histos::HistoItr
std::map< std::string, TObject * >::const_iterator HistoItr
Definition: Histos.h:21
Histos::book
void book(const std::string &name, int nx, float xmin, float xmax, int ny=0, float ymin=0., float ymax=0.)
Book an histogram (1D or 2D)
Definition: Histos.cc:23
L1TOccupancyClient_cfi.ymax
ymax
Definition: L1TOccupancyClient_cfi.py:43
contentValuesFiles.number
number
Definition: contentValuesFiles.py:53
Histos::Histos
Histos()
Definition: Histos.cc:13
callgraph.n2
n2
Definition: callgraph.py:50
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
geometryDiff.file
file
Definition: geometryDiff.py:13
hh
const auto & hh
Definition: CAHitNtupletGeneratorKernelsImpl.h:552
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
Histos::myself
static Histos * myself
Definition: Histos.h:71
Histos::theObjects
std::map< std::string, TObject * > theObjects
Definition: Histos.h:77
photonIsolationHIProducer_cfi.ho
ho
Definition: photonIsolationHIProducer_cfi.py:10
HcalObjRepresent::Fill
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Definition: HcalObjRepresent.h:1053
L1TOccupancyClient_cfi.ymin
ymin
Definition: L1TOccupancyClient_cfi.py:43
TrackerOfflineValidation_Dqm_cff.xmax
xmax
Definition: TrackerOfflineValidation_Dqm_cff.py:11
Histos::fill
void fill(const std::string &name, float val1, float val2=1., float val3=1.)
Fill an histogram.
Definition: Histos.cc:125
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
TrackerOfflineValidation_Dqm_cff.xmin
xmin
Definition: TrackerOfflineValidation_Dqm_cff.py:10