diff --git a/Control/AthenaMonitoring/AthenaMonitoring/HistogramDef.h b/Control/AthenaMonitoring/AthenaMonitoring/HistogramDef.h index afe8f7f43a9e645e35d9370fa6308238ca9357a7..3e9ed68b7672e8c1bc560eb89ba1548b63c98a36 100644 --- a/Control/AthenaMonitoring/AthenaMonitoring/HistogramDef.h +++ b/Control/AthenaMonitoring/AthenaMonitoring/HistogramDef.h @@ -25,6 +25,7 @@ namespace Monitored { std::string path; //!< booking path std::string title; //!< title of the histogram std::string opt; //!< options + std::string weight; //!< names of weights int xbins{0}; //!< number of bins in X float xmin{0}; //!< left diff --git a/Control/AthenaMonitoring/AthenaMonitoring/HistogramFiller.h b/Control/AthenaMonitoring/AthenaMonitoring/HistogramFiller.h index 255fe37833c0a398ed424fefa6c103ed9ea04f3e..3d2387a8fedecc4824ed2cec681ddefaad9ceff9 100644 --- a/Control/AthenaMonitoring/AthenaMonitoring/HistogramFiller.h +++ b/Control/AthenaMonitoring/AthenaMonitoring/HistogramFiller.h @@ -61,10 +61,22 @@ namespace Monitored { void setMonitoredVariables(std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> monitoredVariables) { m_monVariables = monitoredVariables; } + + /** + * @brief Stores histogram weight + * @param monitoredWeight weight to use + */ + void setMonitoredWeight(Monitored::IMonitoredVariable* monitoredWeight) { + m_monWeight = monitoredWeight; + } std::vector<std::string> histogramVariablesNames() const { return m_histDef->name; } + + std::string histogramWeightName() { + return m_histDef->weight; + } protected: template <class H> @@ -76,6 +88,7 @@ namespace Monitored { std::shared_ptr<HistogramDef> m_histDef; std::shared_ptr<IHistogramProvider> m_histogramProvider; std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> m_monVariables; + Monitored::IMonitoredVariable* m_monWeight; private: HistogramFiller& operator=(HistogramFiller const&) = delete; diff --git a/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py b/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py index d525ad2db8fa0dc9673b18ef3064bc39537c56b3..4b58715f781c7f3e65afc017e1afebde2c00f85c 100644 --- a/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py +++ b/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py @@ -83,7 +83,7 @@ def ExampleMonitoringConfig(inputFlags): myGroup.defineHistogram('lumiPerBCID',title='Luminosity;L/BCID;Events', path='ToRuleThemAll',xbins=10,xmin=0.0,xmax=10.0) myGroup.defineHistogram('lb', title='Luminosity Block;lb;Events', - path='ToFindThem',xbins=1000,xmin=-0.5,xmax=999.5) + path='ToFindThem',xbins=1000,xmin=-0.5,xmax=999.5,weight='testweight') myGroup.defineHistogram('random', title='LB;x;Events', path='ToBringThemAll',xbins=30,xmin=0,xmax=1,opt='kLBNHistoryDepth=10') myGroup.defineHistogram('pT_passed,pT',type='TEfficiency',title='Test TEfficiency;x;Eff', diff --git a/Control/AthenaMonitoring/python/GenericMonitoringTool.py b/Control/AthenaMonitoring/python/GenericMonitoringTool.py index cab4d02d75755ed4b3dfe3d395cad7dc84fa3a3f..5c8a786f59002f93c83d5e42fb56cae498d1e641 100644 --- a/Control/AthenaMonitoring/python/GenericMonitoringTool.py +++ b/Control/AthenaMonitoring/python/GenericMonitoringTool.py @@ -23,11 +23,12 @@ class GenericMonitoringTool(_GenericMonitoringTool): # @param varname one (1D) or two (2D) variable names separated by comma # @param type histogram type # @param path top-level histogram directory (e.g. EXPERT, SHIFT, etc.) +# @param weight Name of the variable containing the fill weight # @param title Histogram title and optional axis title (same syntax as in TH constructor) # @param opt Histrogram options (see GenericMonitoringTool) # @param labels List of bin labels (for a 2D histogram, sequential list of x- and y-axis labels) def defineHistogram(varname, type='TH1F', path=None, - title=None, + title=None,weight='', xbins=100, xmin=0, xmax=1, ybins=None, ymin=None, ymax=None, zmin=None, zmax=None, opt='', labels=None): @@ -42,7 +43,7 @@ def defineHistogram(varname, type='TH1F', path=None, log.warning('Histogram %s of type %s is not supported for online running and will not be added', varname, type) return "" - coded = "%s, %s, %s, %s, %d, %f, %f" % (path, type, varname, title, xbins, xmin, xmax) + coded = "%s, %s, %s, %s, %s, %d, %f, %f" % (path, type, weight, varname, title, xbins, xmin, xmax) if ybins is not None: coded += ", %d, %f, %f" % (ybins, ymin, ymax) if zmin is not None: diff --git a/Control/AthenaMonitoring/share/GenericMon.txt b/Control/AthenaMonitoring/share/GenericMon.txt index ec95f24e1021c251b8b6aaaf7058e506b1fea0fd..7678aed82c66c4bfcada048134e67ecbc71a9c2e 100644 --- a/Control/AthenaMonitoring/share/GenericMon.txt +++ b/Control/AthenaMonitoring/share/GenericMon.txt @@ -16,10 +16,10 @@ THistSvc.OutputLevel = 0; THistSvc.Output= {"EXPERT DATAFILE='expert-monitoring.root' OPT='RECREATE'" }; ToolSvc.MonTool.OutputLevel =0; ToolSvc.MonTool.HistPath="TestGroup"; -ToolSvc.MonTool.Histograms = { "EXPERT, TH1F, Eta, #eta of Clusters; #eta; number of RoIs, 2, -2.500000, 2.500000" }; -ToolSvc.MonTool.Histograms += { "EXPERT, TH1F, Phi, #phi of Clusters; #phi; number of RoIs, 2, -3.15, 3.15" }; -ToolSvc.MonTool.Histograms += { "EXPERT, TH2F, Eta,Phi, #eta vs #phi of Clusters; #eta; #phi; number of RoIs, 2, -2.500000, 2.500000, 2, -3.15, 3.15" }; -ToolSvc.MonTool.Histograms += { "EXPERT, TH1F, TIME_t1, Timing of tool 1, 100, 0., 1000." }; -ToolSvc.MonTool.Histograms += { "EXPERT, TH1F, TIME_t2, Timing of tool 2, 100, 0., 1000." }; +ToolSvc.MonTool.Histograms = { "EXPERT, TH1F, , Eta, #eta of Clusters; #eta; number of RoIs, 2, -2.500000, 2.500000" }; +ToolSvc.MonTool.Histograms += { "EXPERT, TH1F, , Phi, #phi of Clusters; #phi; number of RoIs, 2, -3.15, 3.15" }; +ToolSvc.MonTool.Histograms += { "EXPERT, TH2F, , Eta,Phi, #eta vs #phi of Clusters; #eta; #phi; number of RoIs, 2, -2.500000, 2.500000, 2, -3.15, 3.15" }; +ToolSvc.MonTool.Histograms += { "EXPERT, TH1F, , TIME_t1, Timing of tool 1, 100, 0., 1000." }; +ToolSvc.MonTool.Histograms += { "EXPERT, TH1F, , TIME_t2, Timing of tool 2, 100, 0., 1000." }; diff --git a/Control/AthenaMonitoring/src/ExampleMonitorAlgorithm.cxx b/Control/AthenaMonitoring/src/ExampleMonitorAlgorithm.cxx index 1c712557e09e978ba44e15e78e6b5ee3816c7df7..619983eeb3f33332056c08c952ae8a3ae9882925 100644 --- a/Control/AthenaMonitoring/src/ExampleMonitorAlgorithm.cxx +++ b/Control/AthenaMonitoring/src/ExampleMonitorAlgorithm.cxx @@ -26,6 +26,7 @@ StatusCode ExampleMonitorAlgorithm::fillHistograms( const EventContext& ctx ) co auto lb = Monitored::Scalar<int>("lb",0); auto run = Monitored::Scalar<int>("run",0); auto random = Monitored::Scalar<float>("random",0.0); + auto testweight = Monitored::Scalar<float>("testweight",1.0); // Two variables (value and passed) needed for TEfficiency auto pT = Monitored::Scalar<float>("pT",0.0); @@ -35,6 +36,7 @@ StatusCode ExampleMonitorAlgorithm::fillHistograms( const EventContext& ctx ) co lumiPerBCID = lbAverageInteractionsPerCrossing(); lb = GetEventInfo(ctx)->lumiBlock(); run = GetEventInfo(ctx)->runNumber(); + testweight = 2.0; TRandom3 r(ctx.eventID().event_number()); // Example of using flags @@ -47,7 +49,7 @@ StatusCode ExampleMonitorAlgorithm::fillHistograms( const EventContext& ctx ) co pT_passed = pT>r.Poisson(15); // Fill. First argument is the tool name, all others are the variables to be saved. - fill("ExampleMonitor",lumiPerBCID,lb,random,pT,pT_passed); + fill("ExampleMonitor",lumiPerBCID,lb,random,pT,pT_passed,testweight); // Alternative fill method. Get the group yourself, and pass it to the fill function. auto tool = getGroup("ExampleMonitor"); diff --git a/Control/AthenaMonitoring/src/GenericMonitoringTool.cxx b/Control/AthenaMonitoring/src/GenericMonitoringTool.cxx index 1d1b48a23b74c3742e8316373e85fd0be5c1d640..891a4ff998fbebdf73d69809e638bc62762c3da4 100644 --- a/Control/AthenaMonitoring/src/GenericMonitoringTool.cxx +++ b/Control/AthenaMonitoring/src/GenericMonitoringTool.cxx @@ -61,13 +61,13 @@ StatusCode GenericMonitoringTool::book() { HistogramDef def = HistogramDef::parse(item); if (def.ok) { - std::shared_ptr<HistogramFiller> filler(factory.create(def)); - - if (filler) { - m_fillers.push_back(filler); - } else { - ATH_MSG_WARNING( "The histogram filler cannot be instantiated for: " << def.name ); - } + std::shared_ptr<HistogramFiller> filler(factory.create(def)); + + if (filler) { + m_fillers.push_back(filler); + } else { + ATH_MSG_WARNING( "The histogram filler cannot be instantiated for: " << def.name ); + } } else { ATH_MSG_ERROR( "Unparsable histogram definition: " << item ); return StatusCode::FAILURE; @@ -90,7 +90,9 @@ std::vector<std::shared_ptr<HistogramFiller>> GenericMonitoringTool::getHistogra std::vector<std::shared_ptr<HistogramFiller>> result; for (auto filler : m_fillers) { + // Find the associated monitored variable for each histogram's variable(s) auto fillerVariables = filler->histogramVariablesNames(); + std::vector<std::reference_wrapper<IMonitoredVariable>> variables; for (auto fillerVariable : fillerVariables) { @@ -102,6 +104,18 @@ std::vector<std::shared_ptr<HistogramFiller>> GenericMonitoringTool::getHistogra } } + // Find the weight variable in the list of monitored variables + auto fillerWeight = filler->histogramWeightName(); + Monitored::IMonitoredVariable* weight = nullptr; + if ( fillerWeight != "" ) { + for (auto monValue : monitoredVariables) { + if (fillerWeight.compare(monValue.get().name()) == 0) { + weight = &monValue.get(); + break; + } + } + } + if (fillerVariables.size() != variables.size()) { ATH_MSG_DEBUG("Filler has different variables than monitoredVariables"); continue; @@ -109,6 +123,7 @@ std::vector<std::shared_ptr<HistogramFiller>> GenericMonitoringTool::getHistogra std::shared_ptr<HistogramFiller> fillerCopy(filler->clone()); fillerCopy->setMonitoredVariables(variables); + fillerCopy->setMonitoredWeight(weight); result.push_back(fillerCopy); } diff --git a/Control/AthenaMonitoring/src/HistogramDef.cxx b/Control/AthenaMonitoring/src/HistogramDef.cxx index 37a35e888ad51cad289a5e06a3a9cec7b6c95fa5..f377be46e5cbeb26238eac12696490c1233b65aa 100644 --- a/Control/AthenaMonitoring/src/HistogramDef.cxx +++ b/Control/AthenaMonitoring/src/HistogramDef.cxx @@ -25,6 +25,7 @@ const HistogramDef HistogramDef::parse(const std::string &histogramDefinition) { result.path = nextProperty(propertiesIterator); result.type = nextProperty(propertiesIterator); + result.weight = nextProperty(propertiesIterator); result.name.push_back(nextProperty(propertiesIterator)); if (result.type.find("TH2") == 0 || result.type == "TProfile" || result.type == "TEfficiency") { diff --git a/Control/AthenaMonitoring/src/HistogramFiller/HistogramFiller1D.h b/Control/AthenaMonitoring/src/HistogramFiller/HistogramFiller1D.h index c89e94dec5f2dc8b036b189afe14db24502bcdbb..dc1e310836c026ac277484c9502119e0da7360be 100644 --- a/Control/AthenaMonitoring/src/HistogramFiller/HistogramFiller1D.h +++ b/Control/AthenaMonitoring/src/HistogramFiller/HistogramFiller1D.h @@ -8,6 +8,7 @@ #include "TH1.h" #include "AthenaMonitoring/HistogramFiller.h" +#include <boost/range/combine.hpp> namespace Monitored { /** @@ -27,10 +28,22 @@ namespace Monitored { auto histogram = this->histogram<TH1>(); auto valuesVector = m_monVariables[0].get().getVectorRepresentation(); + std::lock_guard<std::mutex> lock(*(this->m_mutex)); - for (auto value : valuesVector) { - histogram->Fill(value); + if ( m_monWeight && m_monWeight->getVectorRepresentation().size()==valuesVector.size() ) { + // When using weights, get the weight vector and fill + auto weightVector = m_monWeight->getVectorRepresentation(); + double value,weight; + for (const auto& zipped : boost::combine(valuesVector,weightVector)) { + boost::tie(value,weight) = zipped; + histogram->Fill(value,weight); + } + } else { + // Otherwise, simply loop over the values and fill + for (auto value : valuesVector) { + histogram->Fill(value); + } } return std::size(valuesVector); diff --git a/Control/AthenaMonitoring/src/HistogramFiller/HistogramFiller2D.h b/Control/AthenaMonitoring/src/HistogramFiller/HistogramFiller2D.h index 0bc820ab58852c69854a2f4e32f7c2ec59ad6163..5e5014e114e99c9199187e3f970b56a70bb1664a 100644 --- a/Control/AthenaMonitoring/src/HistogramFiller/HistogramFiller2D.h +++ b/Control/AthenaMonitoring/src/HistogramFiller/HistogramFiller2D.h @@ -8,6 +8,7 @@ #include "TH2.h" #include "AthenaMonitoring/HistogramFiller.h" +#include <boost/range/combine.hpp> namespace Monitored { /** @@ -42,23 +43,55 @@ namespace Monitored { auto histogram = this->histogram<TH2>(); std::lock_guard<std::mutex> lock(*(this->m_mutex)); - if (areVectorsSameSize) { - for (unsigned i = 0; i < size1; ++i) { - histogram->Fill(vector1[i], vector2[i]); + if (areVectorsSameSize) { // Two equal-size vectors + if ( m_monWeight && m_monWeight->getVectorRepresentation().size()==size1 ) { + // Weighted fill + auto weightVector = m_monWeight->getVectorRepresentation(); + double value1,value2,weight; + for (const auto& zipped : boost::combine(vector1,vector2,weightVector)) { + boost::tie(value1,value2,weight) = zipped; + histogram->Fill(value1,value2,weight); + } + } else { + // Unweighted fill + for (unsigned i = 0; i < size1; ++i) { + histogram->Fill(vector1[i], vector2[i]); + } } - result = size1; - } else if (size1 == 1) { - for (auto value : vector2) { - histogram->Fill(vector1[0], value); - } - result = size2; - } else { - for (auto value : vector1) { - histogram->Fill(value, vector2[0]); + } else if (size1 == 1) { // Scalar vector1 and vector vector2 + if ( m_monWeight && m_monWeight->getVectorRepresentation().size()==size2 ) { + // Weighted fill + auto weightVector = m_monWeight->getVectorRepresentation(); + double value,weight; + for (const auto& zipped : boost::combine(vector2,weightVector)) { + boost::tie(value,weight) = zipped; + histogram->Fill(vector1[0],value,weight); + } + } else { + // Unweighted fill + for (auto value : vector2) { + histogram->Fill(vector1[0], value); + } } + result = size2; + } else { // Vector vector1 and scalar vector2 + if ( m_monWeight && m_monWeight->getVectorRepresentation().size()==size1 ) { + // Weighted fill + auto weightVector = m_monWeight->getVectorRepresentation(); + double value,weight; + for (const auto& zipped : boost::combine(vector1,weightVector)) { + boost::tie(value,weight) = zipped; + histogram->Fill(value,vector2[0],weight); + } + } else { + // Unweighted fill + for (auto value : vector1) { + histogram->Fill(value, vector2[0]); + } + } result = size1; } diff --git a/Control/AthenaMonitoring/src/HistogramFiller/HistogramFiller2DProfile.h b/Control/AthenaMonitoring/src/HistogramFiller/HistogramFiller2DProfile.h index 71e607072961c14781e42799c38bae8669f17e30..c10efafa3d4f04da7016cd35fcb765a2d8e88afa 100644 --- a/Control/AthenaMonitoring/src/HistogramFiller/HistogramFiller2DProfile.h +++ b/Control/AthenaMonitoring/src/HistogramFiller/HistogramFiller2DProfile.h @@ -37,10 +37,20 @@ namespace Monitored { }*/ //For now lets just consider the case in which all variables are of the same length - for (unsigned i = 0; i < std::size(valuesVector1); ++i) { - histogram->Fill(valuesVector1[i], valuesVector2[i], valuesVector3[i]); + if ( m_monWeight && m_monWeight->getVectorRepresentation().size()==valuesVector1.size() ) { + // Weighted fill + auto weightVector = m_monWeight->getVectorRepresentation(); + double value1,value2,value3,weight; + for (const auto& zipped : boost::combine(valuesVector1,valuesVector2,valuesVector3,weightVector)) { + boost::tie(value1,value2,value3,weight) = zipped; + histogram->Fill(value1,value2,value3,weight); + } + } else { + // Unweighted fill + for (unsigned i = 0; i < std::size(valuesVector1); ++i) { + histogram->Fill(valuesVector1[i], valuesVector2[i], valuesVector3[i]); + } } - return std::size(valuesVector1); } }; diff --git a/Control/AthenaMonitoring/src/HistogramFiller/HistogramFillerProfile.h b/Control/AthenaMonitoring/src/HistogramFiller/HistogramFillerProfile.h index d171db2efa790b194b02d88a338961cee3ed6978..9fc8fe27dd36bdc9e1dc9ad641ea03bf045208d0 100644 --- a/Control/AthenaMonitoring/src/HistogramFiller/HistogramFillerProfile.h +++ b/Control/AthenaMonitoring/src/HistogramFiller/HistogramFillerProfile.h @@ -29,28 +29,66 @@ namespace Monitored { auto histogram = this->histogram<TProfile>(); auto valuesVector1 = m_monVariables[0].get().getVectorRepresentation(); auto valuesVector2 = m_monVariables[1].get().getVectorRepresentation(); + const unsigned size1 = std::size(valuesVector1); + const unsigned size2 = std::size(valuesVector2); + const bool isAnyVectorEmpty = size1 == 0 || size2 == 0; + const bool isAnyVectorScalar = size1 == 1 || size2 == 1; + const bool areVectorsSameSize = size1 == size2; + const bool areVectorsValid = !isAnyVectorEmpty && (areVectorsSameSize || isAnyVectorScalar); + if (!areVectorsValid) return 0; + std::lock_guard<std::mutex> lock(*(this->m_mutex)); - if (valuesVector1.size() != valuesVector2.size()) { - if (valuesVector1.size() == 1) { - // first variable is scalar -- loop over second + if (areVectorsSameSize) { // Two equal-size vectors + if ( m_monWeight && m_monWeight->getVectorRepresentation().size()==valuesVector1.size() ) { + // Weighted fill + auto weightVector = m_monWeight->getVectorRepresentation(); + double value1,value2,weight; + for (const auto& zipped : boost::combine(valuesVector1,valuesVector2,weightVector)) { + boost::tie(value1,value2,weight) = zipped; + histogram->Fill(value1,value2,weight); + } + } else { + // Unweighted fill + for (i = 0; i < std::size(valuesVector1); ++i) { + histogram->Fill(valuesVector1[i], valuesVector2[i]); + } + } + + } else if (size1==1) { // first variable is scalar -- loop over second + if ( m_monWeight && m_monWeight->getVectorRepresentation().size()==valuesVector2.size() ) { + // Weighted fill + auto weightVector = m_monWeight->getVectorRepresentation(); + double value2,weight; + for (const auto& zipped : boost::combine(valuesVector2,weightVector)) { + boost::tie(value2,weight) = zipped; + histogram->Fill(valuesVector1[0],value2,weight); + } + } else { + // Unweighted fill for (auto value2 : valuesVector2) { histogram->Fill(valuesVector1[0], value2); ++i; } - } else if (valuesVector2.size() == 1) { - // second variable is scalar -- loop over first + } + + } else if (size2==1) { // second variable is scalar -- loop over first + if ( m_monWeight && m_monWeight->getVectorRepresentation().size()==valuesVector1.size() ) { + // Weighted fill + auto weightVector = m_monWeight->getVectorRepresentation(); + double value1,weight; + for (const auto& zipped : boost::combine(valuesVector1,weightVector)) { + boost::tie(value1,weight) = zipped; + histogram->Fill(value1,valuesVector2[0],weight); + } + } else { + // Unweighted fill for (auto value1 : valuesVector1) { histogram->Fill(value1, valuesVector2[0]); ++i; - } - } - } else { - for (i = 0; i < std::size(valuesVector1); ++i) { - histogram->Fill(valuesVector1[i], valuesVector2[i]); + } } } - return i; } }; diff --git a/Control/AthenaMonitoring/test/GenericMonFilling_test.cxx b/Control/AthenaMonitoring/test/GenericMonFilling_test.cxx index 94200d25d4b225076a7a4bd7779aba6080e79c54..0562945939f4339e4a73ebad0f60feb99807ea76 100644 --- a/Control/AthenaMonitoring/test/GenericMonFilling_test.cxx +++ b/Control/AthenaMonitoring/test/GenericMonFilling_test.cxx @@ -333,6 +333,7 @@ int main() { return -1; } MsgStream log( Athena::getMessageSvc(), "GenericMonFilling_test" ); + log.setLevel(0); ITHistSvc* histSvc; if( pSvcLoc->service( "THistSvc", histSvc, true ).isFailure() ) { @@ -344,8 +345,6 @@ int main() { ToolHandle<GenericMonitoringTool> emptyMon(""); VALUE( emptyMon.isEnabled() ) EXPECTED( false ); // self test log << MSG::DEBUG << " mon tool validity " << emptyMon.isValid() << endmsg; - - ToolHandle<GenericMonitoringTool> validMon( "GenericMonitoringTool/MonTool" ); if ( validMon.retrieve().isFailure() ) { diff --git a/Control/AthenaMonitoring/test/GenericMonParsing_test.cxx b/Control/AthenaMonitoring/test/GenericMonParsing_test.cxx index a9ff1cb7f548c5d6baa8d69773e8c8ac602e8c2a..b18b39cceeabb7800c8d1b55ceb885cd60f4f732 100644 --- a/Control/AthenaMonitoring/test/GenericMonParsing_test.cxx +++ b/Control/AthenaMonitoring/test/GenericMonParsing_test.cxx @@ -16,7 +16,7 @@ using namespace Monitored; bool parsing1DWorks() { - auto def = HistogramDef::parse("EXPERT, TH1F, Eta, #eta of Clusters; #eta; number of RoIs, 50, -2.500000, 2.500000"); + auto def = HistogramDef::parse("EXPERT, TH1F, , Eta, #eta of Clusters; #eta; number of RoIs, 50, -2.500000, 2.500000"); VALUE ( def.ok ) EXPECTED ( true ); VALUE ( def.path ) EXPECTED ( "EXPERT" ); VALUE ( def.type ) EXPECTED ( "TH1F" ); @@ -30,7 +30,7 @@ bool parsing1DWorks() { } bool parsing2DWorks() { - auto def = HistogramDef::parse("SHIFT, TH2F, Eta,Phi, #eta vs #phi of Clusters; #eta; #phi, 50, -2.500000, 2.500000, 64, -3.200000, 3.200000"); + auto def = HistogramDef::parse("SHIFT, TH2F, , Eta,Phi, #eta vs #phi of Clusters; #eta; #phi, 50, -2.500000, 2.500000, 64, -3.200000, 3.200000"); VALUE ( def.ok ) EXPECTED ( true ) ; VALUE ( def.path ) EXPECTED ( "SHIFT" ); VALUE ( def.type ) EXPECTED ( "TH2F" ); @@ -50,7 +50,7 @@ bool parsing2DWorks() { } bool parsing3DWorks() { - auto def = HistogramDef::parse("SHIFT, TProfile2D, Eta,Phi,pt, title, 50, -2.500000, 2.500000, 64, -3.200000, 3.200000, -1.000000, 1.000000"); + auto def = HistogramDef::parse("SHIFT, TProfile2D, , Eta,Phi,pt, title, 50, -2.500000, 2.500000, 64, -3.200000, 3.200000, -1.000000, 1.000000"); VALUE ( def.ok ) EXPECTED ( true ) ; VALUE ( def.path ) EXPECTED ( "SHIFT" ); VALUE ( def.type ) EXPECTED ( "TProfile2D" ); @@ -72,7 +72,7 @@ bool parsing3DWorks() { } bool parsingLabeledWorks() { - auto def = HistogramDef::parse("SHIFT, TH1D, Cut, Cut counter, 5, 0, 5, Cut1:Cut2:Eta:Pt:R"); + auto def = HistogramDef::parse("SHIFT, TH1D, , Cut, Cut counter, 5, 0, 5, Cut1:Cut2:Eta:Pt:R"); VALUE ( def.ok ) EXPECTED ( true ) ; VALUE ( def.path ) EXPECTED ( "SHIFT" ); VALUE ( def.type ) EXPECTED ( "TH1D" ); @@ -88,9 +88,22 @@ bool parsingLabeledWorks() { return true; } +bool parsingWeightedWorks() { + auto def = HistogramDef::parse("EXPERT, TH1F, Weight, Cut, Cut counter, 5, 0, 5"); + VALUE ( def.ok ) EXPECTED ( true ) ; + VALUE ( def.path ) EXPECTED ( "EXPERT" ); + VALUE ( def.type ) EXPECTED ( "TH1F" ); + VALUE ( def.name.size() ) EXPECTED ( 1 ); + VALUE ( std::string(def.name[0]) ) EXPECTED ( "Cut"); + VALUE ( def.labels.size() )EXPECTED ( 5 ); + VALUE ( def.weight ) EXPECTED ("Weight"); + + return true; +} + bool badDefGeneratesExecption() { EXPECT_EXCEPTION( HistogramDefParseException, - HistogramDef::parse("S, TH1D, x, 2.5, 0, 45") ); //2.5 bins can not be valid + HistogramDef::parse("S, TH1D, , x, 2.5, 0, 45") ); //2.5 bins can not be valid return true; } diff --git a/Control/AthenaMonitoring/test/test_defineHistogram.py b/Control/AthenaMonitoring/test/test_defineHistogram.py index 1b691a41f89f96af64914ed76a9077571b7c1cb9..35bf12280062fce3407852be75b5de1bc1b6d8eb 100644 --- a/Control/AthenaMonitoring/test/test_defineHistogram.py +++ b/Control/AthenaMonitoring/test/test_defineHistogram.py @@ -8,24 +8,28 @@ from AthenaMonitoring.GenericMonitoringTool import defineHistogram class Test( unittest.TestCase ): def test_1D( self ): - s = defineHistogram('var', 'TH1F', 'EXPERT', 'title', 10, 0.0, 10.0) - self.assertEqual(s, 'EXPERT, TH1F, var, title, 10, 0.000000, 10.000000') + s = defineHistogram('var', 'TH1F', 'EXPERT', 'title', '', 10, 0.0, 10.0) + self.assertEqual(s, 'EXPERT, TH1F, , var, title, 10, 0.000000, 10.000000') def test_1D_label( self ): - s = defineHistogram('var', 'TH1F', 'EXPERT', 'title', 10, 0.0, 10.0, labels=['a','b']) - self.assertEqual(s, 'EXPERT, TH1F, var, title, 10, 0.000000, 10.000000, a:b:') + s = defineHistogram('var', 'TH1F', 'EXPERT', 'title', '', 10, 0.0, 10.0, labels=['a','b']) + self.assertEqual(s, 'EXPERT, TH1F, , var, title, 10, 0.000000, 10.000000, a:b:') def test_1D_opt( self ): - s = defineHistogram('var', 'TH1F', 'EXPERT', 'title', 10, 0.0, 10.0, opt='myopt') - self.assertEqual(s, 'EXPERT, TH1F, var, title, 10, 0.000000, 10.000000, myopt') + s = defineHistogram('var', 'TH1F', 'EXPERT', 'title', '', 10, 0.0, 10.0, opt='myopt') + self.assertEqual(s, 'EXPERT, TH1F, , var, title, 10, 0.000000, 10.000000, myopt') + + def test_1D_weight( self ): + s = defineHistogram('var', 'TH1F', 'EXPERT', 'title', 'weight', 10, 0.0, 10.0) + self.assertEqual(s, 'EXPERT, TH1F, weight, var, title, 10, 0.000000, 10.000000') def test_2D( self ): - s = defineHistogram('var1,var2', 'TH2F', 'EXPERT', 'title', 10, 0.0, 10.0, 20, 0.0, 20.0) - self.assertEqual(s, 'EXPERT, TH2F, var1,var2, title, 10, 0.000000, 10.000000, 20, 0.000000, 20.000000') + s = defineHistogram('var1,var2', 'TH2F', 'EXPERT', 'title', '', 10, 0.0, 10.0, 20, 0.0, 20.0) + self.assertEqual(s, 'EXPERT, TH2F, , var1,var2, title, 10, 0.000000, 10.000000, 20, 0.000000, 20.000000') def test_3D( self ): - s = defineHistogram('var1,var2,var3', 'TProfile2D', 'EXPERT', 'title', 10, 0.0, 10.0, 20, 0.0, 20.0, -1.0, 1.0) - self.assertEqual(s, 'EXPERT, TProfile2D, var1,var2,var3, title, 10, 0.000000, 10.000000, 20, 0.000000, 20.000000, -1.000000, 1.000000') + s = defineHistogram('var1,var2,var3', 'TProfile2D', 'EXPERT', 'title', '', 10, 0.0, 10.0, 20, 0.0, 20.0, -1.0, 1.0) + self.assertEqual(s, 'EXPERT, TProfile2D, , var1,var2,var3, title, 10, 0.000000, 10.000000, 20, 0.000000, 20.000000, -1.000000, 1.000000') def test_enforcePath( self ): with self.assertRaises(AssertionError): @@ -36,8 +40,8 @@ class Test( unittest.TestCase ): defineHistogram('var', 'TH1F', path='EXPERT', labels='l1:l2') def test_efficiency( self ): - s = defineHistogram('var', 'TEfficiency', 'EXPERT', 'title', 10, 0.0, 10.0) - self.assertEqual(s, 'EXPERT, TEfficiency, var, title, 10, 0.000000, 10.000000') + s = defineHistogram('var', 'TEfficiency', 'EXPERT', 'title', '', 10, 0.0, 10.0) + self.assertEqual(s, 'EXPERT, TEfficiency, , var, title, 10, 0.000000, 10.000000') if __name__ == '__main__': unittest.main()