Commit 8a61f0d1 authored by Riccardo Longo's avatar Riccardo Longo
Browse files

PlotManyPads added

parent cf6a35ec
......@@ -21,17 +21,20 @@ class Visualizer {
//Styles (so fa only ATLAS)
TStyle* AtlasStyle();
//Methods to set a give style
//Methods to set a given style
void SetAtlasStyle();
/** @brief allow the user to define the extension of the plots once they're printed. ".pdf" by default */
void SetPlotExtension( std::string _extension ) { m_extension = _extension; }
/** @brief make the argument true to activate the debug mode. False to deactivate it*/
void SetDebugMode( bool _isDebugon ) { m_debug = _isDebugon; }
void SetDebugMode ( bool _isDebugon ) { m_debug = _isDebugon; }
//Special plot treatments
void OverlayHistos ( TH1D *h1, TH1D *h2 , TVirtualPad* pad);
void OverlayHistos ( TH1 *h1, TH1 *h2 , TVirtualPad* pad);
//Main visualization methods
void ManyPadsPlot( std:: vector < TH1 > raw_form, std::vector < TH1 > der_form, int nx, int ny, std::string out_name, std::string treatment );
void ManyPadsPlot ( std::vector< TH1* > _first_form, std::vector< TH1* > _second_form, int _ncol, int _nrow, std::string _out_name, std::string _treatment );
private :
......@@ -39,6 +42,8 @@ class Visualizer {
std::string m_style;
/** Debug flag */
bool m_debug = false;
/** String defining the extension used to print the plots */
std::string m_extension = ".pdf";
};
#endif
......@@ -12,6 +12,7 @@
#include <TAxis.h>
#include <TGaxis.h>
#include <TPad.h>
#include <TCanvas.h>
#include <iostream>
......@@ -125,7 +126,7 @@ void Visualizer::SetAtlasStyle(){
* @param3 Address of a pad (TPad or TCanvas) to be drawn on
* @param4 Save option. If true, save a .pdf
*/
void Visualizer::OverlayHistos( TH1D *h1, TH1D *h2 , TVirtualPad* pad){
void Visualizer::OverlayHistos( TH1 *h1, TH1 *h2 , TVirtualPad* pad){
// If there is no pad or no data in the histograms, return
if( pad == nullptr ) {std::cerr<< "WARNING: No pad to overlay histos onto" << std::endl; return;}
......@@ -155,3 +156,48 @@ void Visualizer::OverlayHistos( TH1D *h1, TH1D *h2 , TVirtualPad* pad){
if( m_debug ) pad->Print( Form( "%s_Overlay.pdf", h1->GetTitle() ) ) ;
}
/**
* @brief Implementation of Visualizer::ManyPadsPlot. This method takes two vector of histograms that needs to be treated in a peculiar way and
* takes care of plot those together in a canvas with a given number of columns and rows.
* @param _first_form - vector of the first type of histograms to be plotted
* @param _second_form - vector of the second type of histograms to be plotted s
* @param _ncol - number of columns of the canvas
* @param _nrow - number of rows of the canvas
* @param _out_name - name of the plot (w/o extension, that's defined by a data member [ .pdf by default ]
* @param _treatment - treatment of the plots (at the moment only one available, overlay)
*/
void Visualizer::ManyPadsPlot( std::vector< TH1* > _first_form, std::vector< TH1* > _second_form, int _ncol, int _nrow, std::string _out_name, std::string _treatment){
if(_treatment != "overlay" && _treatment != "OVERLAY" && _treatment != "Overlay"){
std::cerr << "WARNING!!! You're looking for a treatment that has not been implemented yet! Please check it carefully" << std::endl;
std::cerr << "Exiting w/o doing anything .." << std::endl;
return;
}
if(_first_form.size() != _second_form.size())
std::cerr << "WARNING!!! The two vectors of histograms "
"have different size. May result in a crash..." << std::endl;
if( _first_form.size() < _ncol*_nrow || _second_form.size() < _ncol*_nrow )
std::cerr << "WARNING!!! You have selected a vector of histrograms that will not fill all your pads"
"This may result in a crash..." << std::endl;
if( _first_form.size() > _ncol*_nrow || _second_form.size() > _ncol*_nrow )
std::cerr << "WARNING!!! You have selected a vector of histrograms that is bigger than the number of requested pads"
"This may result in histograms lost w/o plotting..." << std::endl;
//This for the moment is hardcoded. Maybe can be moved to data member to have more general usage also for single plots.
int squared_pad_size = 300;
TCanvas* canv = new TCanvas( _out_name.c_str(),_out_name.c_str(),
squared_pad_size*_ncol, squared_pad_size*_nrow);
canv->Divide(_ncol,_nrow);
for( int idraw = 0; idraw < _first_form.size(); idraw++){
canv->cd(idraw+1);
if( _treatment == "overlay" || _treatment != "OVERLAY" || _treatment != "Overlay" ){
OverlayHistos( _first_form.at(idraw), _second_form.at(idraw), gPad);
}
}
canv->Print(( _out_name + m_extension ).c_str());
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment