#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. | |
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) | |
void | book (const std::string &name, int nx, float xmin, float xmax, const std::string &option) |
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. | |
void | fill (const std::string &name, float val1, float val2=1., float val3=1.) |
Fill an histogram. | |
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. | |
virtual | ~Histos () |
Destructor. | |
Static Public Member Functions | |
static Histos * | instance () |
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 Histos * | myself = 0 |
typedef std::map<std::string,TObject*>::const_iterator Histos::HistoItr |
Histos::Histos | ( | ) | [private] |
void Histos::addObject | ( | const std::string & | name, |
TObject * | obj | ||
) |
Add any object.
Definition at line 152 of file Histos.cc.
References gather_cfg::cout, and theObjects.
{ HistoItr hh = theObjects.find(name); if (hh != theObjects.end()) { std::cout << "FamosHistos::addObject() : Object " << name << " already exists" << std::endl; return; } // Potential source of memory leaks if not carefully used theObjects.insert(std::pair<std::string,TObject*>(name,obj->Clone())); }
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.
References gather_cfg::cout, AlCaRecoCosmics_cfg::name, theHistos, and theTypes.
Referenced by bookByNumber(), and CalorimetryManager::CalorimetryManager().
{ if ( theHistos.find(name) != theHistos.end() ) { std::cout << "Histos::book() : Histogram " << name << " exists already. Nothing done" << std::endl; } else { if ( ny ) { theHistos[name] = new TH2F(name.c_str(),"",nx,xmin,xmax,ny,ymin,ymax); theTypes[name] = 2; } else { theHistos[name] = new TH1F(name.c_str(),"",nx,xmin,xmax); theTypes[name] = 1; } } }
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 51 of file Histos.cc.
References gather_cfg::cout, AlCaRecoCosmics_cfg::name, theHistos, and theTypes.
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 200 of file Histos.cc.
References book(), and gather_cfg::cout.
Referenced by CalorimetryManager::CalorimetryManager().
void Histos::debug | ( | std::string | p = "" | ) | const [inline] |
Definition at line 64 of file Histos.h.
References gather_cfg::cout, L1TEmulatorMonitor_cff::p, and theHistos.
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 108 of file Histos.cc.
References gather_cfg::cout, theHistos, and theTypes.
{ HistoItr hh1 = theHistos.find(h1); HistoItr hh2 = theHistos.find(h2); HistoItr hh3 = theHistos.find(h3); if ( hh1 == theHistos.end() || hh2 == theHistos.end() || hh3 != theHistos.end() ) { if ( hh1 == theHistos.end() ) std::cout << "Histos::divide() : First histo " << h1 << " does not exist" << std::endl; if ( hh2 == theHistos.end() ) std::cout << "Histos::divide() : Second histo " << h2 << " does not exist" << std::endl; if ( hh3 != theHistos.end() ) std::cout << "Histos::divide() : Third histo " << h3 << " already exists" << std::endl; } else { if ( theTypes[h1] == 1 && theTypes[h2] == 1 ) { theHistos[h3] = (TH1F*) ((*hh1).second)->Clone(h3.c_str()); theTypes[h3] = 1; ((TH1F*)theHistos[h3])->Divide( (TH1F*)( (*hh2).second ) ); } if ( theTypes[h1] == 2 && theTypes[h2] == 2 ) { theHistos[h3] = (TH2F*)((*hh1).second)->Clone(h3.c_str()); theTypes[h3] = 2; ((TH2F*)theHistos[h3])->Divide( (TH2F*)( (*hh2).second ) ); } } }
void Histos::fill | ( | const std::string & | name, |
float | val1, | ||
float | val2 = 1. , |
||
float | val3 = 1. |
||
) |
Fill an histogram.
Definition at line 168 of file Histos.cc.
References gather_cfg::cout, theHistos, and theTypes.
Referenced by fillByNumber(), and CaloGeometryHelper::getClosestCell().
{ // std::cout << " Fill " << name << " " << val1 << " " << val2 << " " << val3 << std::endl; // std::cout << &theHistos << std::endl; HistoItr hh = theHistos.find(name); // std::cout << " Fill done " << std::endl; if ( hh == theHistos.end() ) { std::cout << "Histos::fill() : Histogram " << name << " does not exist" << std::endl; } else { if ( theTypes[name] == 1 ) ( (TH1F*) ( (*hh).second ) )->Fill(val1,val2); if ( theTypes[name] == 2 ) ( (TH2F*) ( (*hh).second ) )->Fill(val1,val2,val3); if ( theTypes[name] == 3 ) ( (TProfile*) ( (*hh).second ) )->Fill(val1,val2,val3); } }
void Histos::fillByNumber | ( | const std::string & | name, |
int | number, | ||
float | val1, | ||
float | val2 = 1. , |
||
float | val3 = 1. |
||
) |
Histos * Histos::instance | ( | void | ) | [static] |
Definition at line 15 of file Histos.cc.
References Histos(), and myself.
Referenced by CalorimetryManager::CalorimetryManager(), EcalHitMaker::EcalHitMaker(), and CaloGeometryHelper::getClosestCell().
void Histos::put | ( | const std::string & | file, |
std::string | name = "" |
||
) |
Write one or all histogram(s) in a file.
Definition at line 69 of file Histos.cc.
References gather_cfg::cout, f, theHistos, theObjects, and theTypes.
Referenced by CalorimetryManager::~CalorimetryManager().
{ TFile * f = new TFile(file.c_str(),"recreate"); f->cd(); HistoItr ho ; for(ho=theObjects.begin();ho!=theObjects.end();++ho) { (*ho).second->Write((*ho).first.c_str()); } HistoItr hh = theHistos.find(name); if ( name == "" ) for ( hh = theHistos.begin(); hh != theHistos.end(); ++hh ) { if ( theTypes[(*hh).first] == 1 ) ( (TH1F*)((*hh).second) )->Write(); if ( theTypes[(*hh).first] == 2 ) ( (TH2F*)((*hh).second) )->Write(); if ( theTypes[(*hh).first] == 3 ) ( (TProfile*)((*hh).second) )->Write(); } else if ( hh != theHistos.end() ) { if ( theTypes[name] == 1 ) ( (TH1F*)((*hh).second) )->Write(); if ( theTypes[name] == 2 ) ( (TH2F*)((*hh).second) )->Write(); if ( theTypes[name] == 3 ) ( (TProfile*)((*hh).second) )->Write(); } else std::cout << "Histos::put() : Histogram " << name << " does not exist. Nothing done" << std::endl; f->Write(); f->Close(); }
Histos * Histos::myself = 0 [static, private] |
Definition at line 73 of file Histos.h.
Referenced by instance().
TObject* Histos::theHisto [private] |
std::map<std::string,TObject*> Histos::theHistos [private] |
std::map<std::string,TObject*> Histos::theObjects [private] |
Definition at line 79 of file Histos.h.
Referenced by addObject(), and put().