From 6de5d6962dc3a6dc1497e02c129556fd2a5b5cc0 Mon Sep 17 00:00:00 2001 From: kirschen <> Date: Thu, 29 Mar 2012 11:50:34 +0000 Subject: [PATCH] added RunNumber as plot variable; minor changes to bintitles(add option to ommit cut); add: allow explicit xbin edges; add: logy option --- ControlPlots.cc | 2 + ControlPlotsConfig.cc | 88 +++++++++++++++++++++++++---------------- ControlPlotsConfig.h | 15 +++++-- ControlPlotsFunction.cc | 13 +++++- ControlPlotsFunction.h | 5 ++- 5 files changed, 83 insertions(+), 40 deletions(-) diff --git a/ControlPlots.cc b/ControlPlots.cc index d89b34f..f035c98 100644 --- a/ControlPlots.cc +++ b/ControlPlots.cc @@ -259,6 +259,8 @@ ControlPlotsFunction::Function ControlPlots::findJetTruthEventFunction(const std //! \p type. // ------------------------------------------------------------- ControlPlotsFunction::Function ControlPlots::findTwoJetsPtBalanceEventFunction(const std::string& varName, ControlPlotsConfig::CorrectionType type) const { + if( varName == "RunNumber" ) + return &ControlPlotsFunction::twoJetsPtBalanceEventRunNumber; if( varName == "Eta" ) return &ControlPlotsFunction::twoJetsPtBalanceEventJetEta; if( varName == "AbsEta" ) diff --git a/ControlPlotsConfig.cc b/ControlPlotsConfig.cc index e5fdf01..67c766c 100644 --- a/ControlPlotsConfig.cc +++ b/ControlPlotsConfig.cc @@ -1,4 +1,4 @@ -// $Id: ControlPlotsConfig.cc,v 1.23 2012/02/06 22:14:47 kirschen Exp $ +// $Id: ControlPlotsConfig.cc,v 1.24 2012/02/09 16:41:51 kirschen Exp $ #include "ControlPlotsConfig.h" @@ -41,7 +41,7 @@ std::string ControlPlotsConfig::binName(int binIdx) const { //! This is used for the profile histogram title //! and consists of "min < varTitle(binning) < max (unit)". // -------------------------------------------------- -std::string ControlPlotsConfig::binTitle(double min, double max) const { +std::string ControlPlotsConfig::binTitle(double min, double max, bool showCut) const { std::string title = toString(min); title += " #leq "; title += varTitle(binVariable()); @@ -53,16 +53,18 @@ std::string ControlPlotsConfig::binTitle(double min, double max) const { title += " " + unit; } - if(cutVariable() != "") { - title += " and "; - title += toString(cutMin()); - title += " #leq "; - title += varTitle(cutVariable()); - title += " < "; - title += toString(cutMax()); - std::string unit = unitTitle(cutVariable()); - if( unit != "" ) { - title += " " + unit; + if(showCut){ + if(cutVariable() != "") { + title += " and "; + title += toString(cutMin()); + title += " #leq "; + title += varTitle(cutVariable()); + title += " < "; + title += toString(cutMax()); + std::string unit = unitTitle(cutVariable()); + if( unit != "" ) { + title += " " + unit; + } } } @@ -89,8 +91,8 @@ std::string ControlPlotsConfig::xBinName(int xBinIdx) const { //! It is drawn on the histogram and consists of //! "min < varTitle() < max (unit), xBinMin < varTitle(x) < xBinMax (unit)" // -------------------------------------------------- -std::string ControlPlotsConfig::xBinTitle(int xBinIdx, double binMin, double binMax) const { - std::string title = binTitle(binMin,binMax); +std::string ControlPlotsConfig::xBinTitle(int xBinIdx, double binMin, double binMax, bool showCut) const { + std::string title = binTitle(binMin,binMax,showCut); if( xBinIdx >= 0 && xBinIdx < nXBins() ) { title += ", "; title += toString(round(xBinEdges_.at(xBinIdx))); @@ -409,6 +411,7 @@ void ControlPlotsConfig::init() { logX_ = true; } } + bool useDirectBinEdges=false; double min = 20.; double max = 100.; std::vector var = bag_of(config_->read(name_+" x edges","15 10 1000")); @@ -418,20 +421,30 @@ void ControlPlotsConfig::init() { max = var.at(2); } else { std::cerr << "WARNING: Wrong number of arguments in config line '" << name_ << " x edges'\n"; - nXBins_ = 5; - } - xBinEdges_ = std::vector(nXBins_+1); - if( logX_ ) { - if( !equidistLogBins(xBinEdges_,nXBins_,min,max) ) - std::cerr << "ERROR creating equidistant logarithmic binning.\n"; - } else { - double width = (max - min) / nXBins_; - for(int i = 0; i < nXBins_+1; i++) { - xBinEdges_.at(i) = min + width*i; + std::cerr << " Trying to take arguments as bin edges, instead.\n"; + xBinEdges_ = bag_of(config_->read(name_+" x edges","0. 1.")); + assert( xBinEdges_.size() > 1 ); + for(size_t i = 1; i < xBinEdges_.size(); i++) { + assert( xBinEdges_.at(i) > xBinEdges_.at(i-1) ); } + nXBins_ = static_cast(xBinEdges_.size())-1; + if(nXBins_>2)useDirectBinEdges=true; + else nXBins_ = 5; } - for(int i = 0; i < nXBins_; i++) { - assert( xBinEdges_.at(i) < xBinEdges_.at(i+1) ); + if(!useDirectBinEdges){ + xBinEdges_ = std::vector(nXBins_+1); + if( logX_ ) { + if( !equidistLogBins(xBinEdges_,nXBins_,min,max) ) + std::cerr << "ERROR creating equidistant logarithmic binning.\n"; + } else { + double width = (max - min) / nXBins_; + for(int i = 0; i < nXBins_+1; i++) { + xBinEdges_.at(i) = min + width*i; + } + } + for(int i = 0; i < nXBins_; i++) { + assert( xBinEdges_.at(i) < xBinEdges_.at(i+1) ); + } } cutVar_ = config_->read(name_+" cut variable",""); @@ -477,9 +490,14 @@ void ControlPlotsConfig::init() { } } yBinEdges_ = std::vector(nYBins_+1); - double width = (max - min) / nYBins_; - for(int i = 0; i < nYBins_+1; i++) { - yBinEdges_.at(i) = min + width*i; + if( logY_ ) { + if( !equidistLogBins(yBinEdges_,nYBins_,min,max) ) + std::cerr << "ERROR creating equidistant logarithmic binning.\n"; + } else { + double width = (max - min) / nXBins_; + for(int i = 0; i < nXBins_+1; i++) { + xBinEdges_.at(i) = min + width*i; + } } for(int i = 0; i < nYBins_; i++) { assert( yBinEdges_.at(i) < yBinEdges_.at(i+1) ); @@ -695,13 +713,17 @@ std::string ControlPlotsConfig::varTitle(const std::string &varName) const { else if( varName == "VtxN") title = "Reconstructed vertices"; else if( varName == "PF_CH_Fraction") - title = "PF charged hadron fraction"; + title = "Charged hadrons"; + // title = "PF charged hadron fraction"; else if( varName == "PF_NH_Fraction") - title = "PF neutral hadron fraction"; + title = "Neutral hadrons"; + // title = "PF neutral hadron fraction"; else if( varName == "PF_PH_Fraction") - title = "PF photon fraction"; + title = "Photons"; + /// title = "PF photon fraction"; else if( varName == "PF_EL_Fraction") - title = "PF electron fraction"; + title = "Electrons"; + // title = "PF electron fraction"; else if( varName == "DeltaPhi") title = "#Delta #varphi_{1,2}"; diff --git a/ControlPlotsConfig.h b/ControlPlotsConfig.h index fd3f2ad..3b1463d 100644 --- a/ControlPlotsConfig.h +++ b/ControlPlotsConfig.h @@ -1,4 +1,4 @@ -// $Id: ControlPlotsConfig.h,v 1.11 2012/01/24 16:26:37 kirschen Exp $ +// $Id: ControlPlotsConfig.h,v 1.12 2012/02/09 16:41:51 kirschen Exp $ #ifndef CONTROLPLOTS_CONFIG_H #define CONTROLPLOTS_CONFIG_H @@ -56,7 +56,7 @@ class ConfigFile; //! //! \author Matthias Schroeder //! \date 2009/12/18 -//! $Id: ControlPlotsConfig.h,v 1.11 2012/01/24 16:26:37 kirschen Exp $ +//! $Id: ControlPlotsConfig.h,v 1.12 2012/02/09 16:41:51 kirschen Exp $ // ---------------------------------------------------------------- class ControlPlotsConfig { public: @@ -102,13 +102,17 @@ class ControlPlotsConfig { //! Returns the name of the bin std::string binName(int binIdx) const; //! Returns the title of the bin - std::string binTitle(double min, double max) const; + std::string binTitle(double min, double max, bool showCut=true) const; + //! Returns the title of the bin used for axis + std::string binAxisTitle() const { return axisTitle(binVariable()); } //! Returns the name of the cut variable std::string cutVariable() const { return cutVar_; } //! Returns the minimum of the cut range double cutMin() const { return cutEdges_.first; } //! Returns the maximum of the cut range double cutMax() const { return cutEdges_.second; } + //! Returns the title of the cut used for axis + std::string cutAxisTitle() const { return axisTitle(cutVariable()); } //! Returns the bin edges of the x variable const std::vector *xBinEdges() const { return &xBinEdges_; } @@ -125,9 +129,11 @@ class ControlPlotsConfig { //! Returns the name of the x bin std::string xBinName(int xBinIdx) const; //! Returns the title of the x bin - std::string xBinTitle(int xBinIdx, double binMin, double binMax) const; + std::string xBinTitle(int xBinIdx, double binMin, double binMax, bool showCut=true) const; //! Specifies whether there is logarithmic binning of the x axis bool logX() const { return logX_; } + //! Specifies whether there is logarithmic binning of the y axis. Beware: often does not make sense for profiles + bool logY() const { return logY_; } //! Returns the bin edges of the y variable const std::vector *yBinEdges() const { return &yBinEdges_; } @@ -221,6 +227,7 @@ class ControlPlotsConfig { std::vector xBinEdges_; int nXBins_; bool logX_; + bool logY_; std::string cutVar_; std::pair cutEdges_; diff --git a/ControlPlotsFunction.cc b/ControlPlotsFunction.cc index 310a04d..e8a178e 100644 --- a/ControlPlotsFunction.cc +++ b/ControlPlotsFunction.cc @@ -1,4 +1,4 @@ -// $Id: ControlPlotsFunction.cc,v 1.24 2012/02/06 22:14:47 kirschen Exp $ +// $Id: ControlPlotsFunction.cc,v 1.25 2012/02/09 16:41:51 kirschen Exp $ #include "ControlPlotsFunction.h" @@ -239,6 +239,17 @@ double ControlPlotsFunction::jetTruthEventResponseL2L3ResL4Corrected(const Event } +//! \brief Returns run number uf the Event +//! +//! The \p Event \p evt has to be of type \p TwoJetsPtBalanceEvent. +//! Implements \p Function. +// ---------------------------------------------------------------- +double ControlPlotsFunction::twoJetsPtBalanceEventRunNumber(const Event *evt) const { + const TwoJetsPtBalanceEvent * jte = static_cast(evt); + return jte->runNumber(); +} + + //! \brief Returns #eta of the jet //! //! The \p Event \p evt has to be of type \p TwoJetsPtBalanceEvent. diff --git a/ControlPlotsFunction.h b/ControlPlotsFunction.h index 8ea933a..91934da 100644 --- a/ControlPlotsFunction.h +++ b/ControlPlotsFunction.h @@ -1,4 +1,4 @@ -// $Id: ControlPlotsFunction.h,v 1.22 2012/02/06 22:14:47 kirschen Exp $ +// $Id: ControlPlotsFunction.h,v 1.23 2012/02/09 16:41:51 kirschen Exp $ #ifndef CONTROLPLOTS_FUNCTION_H #define CONTROLPLOTS_FUNCTION_H @@ -24,7 +24,7 @@ class Event; //! //! \author Matthias Schroeder //! \date 2009/12/18 -//! $Id: ControlPlotsFunction.h,v 1.22 2012/02/06 22:14:47 kirschen Exp $ +//! $Id: ControlPlotsFunction.h,v 1.23 2012/02/09 16:41:51 kirschen Exp $ // ---------------------------------------------------------------- class ControlPlotsFunction { public: @@ -79,6 +79,7 @@ class ControlPlotsFunction { double jetTruthEventResponseL2L3L4Corrected(const Event * evt) const; double jetTruthEventResponseL2L3ResL4Corrected(const Event * evt) const; + double twoJetsPtBalanceEventRunNumber(const Event *evt) const; double twoJetsPtBalanceEventJetEta(const Event *evt) const; double twoJetsPtBalanceEventJetAbsEta(const Event *evt) const; double twoJetsPtBalanceEventJetPt(const Event *evt) const;