diff --git a/DAQ/DAQMonitors/src/RawBankSizeMonitor.cpp b/DAQ/DAQMonitors/src/RawBankSizeMonitor.cpp index 1cd8460d48de856d368c47bc73add3d505c92100..f9fe5ef7284d5630b919c0962c96d4d2e70acd41 100644 --- a/DAQ/DAQMonitors/src/RawBankSizeMonitor.cpp +++ b/DAQ/DAQMonitors/src/RawBankSizeMonitor.cpp @@ -16,6 +16,9 @@ #include "GaudiUtils/Aida2ROOT.h" #include "LHCbAlgs/Consumer.h" #include "TProfile.h" + +#include + #include namespace { @@ -37,10 +40,7 @@ class RawBankSizeMonitor : public LHCb::Algorithm::Consumer> { public: RawBankSizeMonitor( const std::string& name, ISvcLocator* pSvcLocator ) - : Consumer{ name, pSvcLocator, { "RawEventLocation", LHCb::RawEventLocation::Default } } { - setHistoDir( name ); - setProperty( "HistoPrint", true ).ignore(); - } + : Consumer{ name, pSvcLocator, { "RawEventLocation", LHCb::RawEventLocation::Default } } {} StatusCode initialize() override; void operator()( const LHCb::RawEvent& rawEvent ) const override; @@ -50,39 +50,38 @@ private: Gaudi::Property> m_bankNames{ this, "bankNames", allBankNames() }; Gaudi::Property> m_max{ this, "MaxSizeMap", {} }; Gaudi::Property m_def{ this, "MaxSizeDef", 40000 }; - Gaudi::Property m_bin{ this, "Bins", 200 }; + Gaudi::Property m_bin{ this, "Bins", 200 }; Gaudi::Property m_prof{ this, "Profile", true }; mutable Gaudi::Accumulators::StatCounter m_totalBankSize{ this, "Total RawEvent size (bytes)" }; - - /// mutex lock - mutable std::mutex m_mutex; + mutable std::map> m_overallBankSize; + mutable std::map> m_profBankSizePerID; + mutable std::map> m_2DBankSizePerID; + mutable std::mutex m_histoMutex; }; // Declaration of the Algorithm Factory DECLARE_COMPONENT( RawBankSizeMonitor ) StatusCode RawBankSizeMonitor::initialize() { - const auto sc = GaudiHistoAlg::initialize(); - if ( sc.isFailure() ) return sc; - // convert bankNames to bankTypes - for ( const auto& bname : m_bankNames ) { - bool found = false; - for ( int i = 0; i != (int)LHCb::RawBank::LastType && !found; i++ ) { - const auto _name = LHCb::RawBank::typeName( (LHCb::RawBank::BankType)i ); - if ( _name == bname ) { - found = true; - m_bankTypes.push_back( (LHCb::RawBank::BankType)i ); + return GaudiHistoAlg::initialize().andThen( [&] { + // convert bankNames to bankTypes + for ( const auto& bname : m_bankNames ) { + bool found = false; + for ( int i = 0; i != (int)LHCb::RawBank::LastType && !found; i++ ) { + const auto _name = LHCb::RawBank::typeName( (LHCb::RawBank::BankType)i ); + if ( _name == bname ) { + found = true; + m_bankTypes.push_back( (LHCb::RawBank::BankType)i ); + } } + if ( !found ) warning() << "Requested bank '" << bname << "' is not a valid name" << endmsg; } - if ( !found ) warning() << "Requested bank '" << bname << "' is not a valid name" << endmsg; - } - return sc; + return StatusCode::SUCCESS; + } ); } void RawBankSizeMonitor::operator()( const LHCb::RawEvent& rawEvent ) const { - // lock for histogram updating - std::lock_guard lock( m_mutex ); // Loop over banks unsigned int total = 0; for ( const auto& bt : m_bankTypes ) { @@ -97,7 +96,7 @@ void RawBankSizeMonitor::operator()( const LHCb::RawEvent& rawEvent ) const { const auto max = ( im == m_max.end() ? m_def.value() : im->second ); std::map size; int s_min = 9999; - int s_max = -1; + int s_max = 0; int s_sum = 0; for ( const auto ib : bks ) { const auto source = ib->sourceID(); @@ -106,17 +105,40 @@ void RawBankSizeMonitor::operator()( const LHCb::RawEvent& rawEvent ) const { s_sum += ib->size(); // size in Bytes size[source] = ib->size(); // size in Bytes } - plot1D( s_sum, name + "/size", "Overall " + name + " bank size (bytes)", 0, (double)max, m_bin.value() ); + // Create histograms if needed, in a thread safe manner + if ( !m_overallBankSize.contains( name ) ) { + std::scoped_lock lock{ m_histoMutex }; + if ( !m_overallBankSize.contains( name ) ) { + // now we are alone and there is still nothing, let's create the histogram + m_overallBankSize.emplace( + std::piecewise_construct, std::forward_as_tuple( name ), + std::forward_as_tuple( this, name + "/size", "Overall " + name + " bank size (bytes)", + Gaudi::Accumulators::Axis{ m_bin.value(), 0, (double)max } ) ); + if ( m_prof.value() ) { + m_profBankSizePerID.emplace( + std::piecewise_construct, std::forward_as_tuple( name ), + std::forward_as_tuple( this, name + "/sizeVsSourceID", + name + " bank size (bytes) as a function of sourceID", + Gaudi::Accumulators::Axis{ (unsigned int)( s_max - s_min + 1 ), + (double)s_min, (double)( s_max + 1 ), "s" } ) ); + } else { + m_2DBankSizePerID.emplace( + std::piecewise_construct, std::forward_as_tuple( name ), + std::forward_as_tuple( this, name + "/sizeVsSourceID", + name + " bank size (bytes) as a function of sourceID", + Gaudi::Accumulators::Axis{ (unsigned int)( s_max - s_min + 1 ), + (double)s_min, (double)( s_max + 1 ) }, + Gaudi::Accumulators::Axis{ m_bin.value(), 0, (double)max } ) ); + } + } + } + ++m_overallBankSize.at( name )[s_sum]; total += s_sum; for ( auto [k, v] : size ) { if ( m_prof.value() ) { - profile1D( (double)k, (double)v, name + "/sizeVsSourceID", // - name + " bank size (bytes) as a function of sourceID", // - s_min, s_max + 1, s_max - s_min + 1, "s" ); + m_profBankSizePerID.at( name )[k] += v; } else { - plot2D( (double)k, (double)v, name + "/sizeVsSourceID", // - name + " bank size (bytes) as a function of sourceID", // - s_min, s_max + 1, 0., (double)max, s_max - s_min + 1, m_bin.value() ); + ++m_2DBankSizePerID.at( name )[{ k, v }]; } } } // bank type loop diff --git a/UT/UTCheckers/src/MCUTDepositMonitor.cpp b/UT/UTCheckers/src/MCUTDepositMonitor.cpp index a74ff841bf4b17b69b7cfb59e0a9b07341f1d4a0..cdd692e13bc9ae7b862e2c1eab936d2f7a6b2b60 100644 --- a/UT/UTCheckers/src/MCUTDepositMonitor.cpp +++ b/UT/UTCheckers/src/MCUTDepositMonitor.cpp @@ -14,9 +14,9 @@ #include "LHCbAlgs/Consumer.h" -#include "GaudiAlg/GaudiHistoAlg.h" +#include -using namespace LHCb; +#include /** * Make plots for MCUTDeposits @@ -26,55 +26,65 @@ using namespace LHCb; * @author J. van Tilburg * @date 2018-09-04 */ -class MCUTDepositMonitor : public LHCb::Algorithm::Consumer> { +class MCUTDepositMonitor : public LHCb::Algorithm::Consumer { public: MCUTDepositMonitor( const std::string& name, ISvcLocator* svcloc ); - StatusCode initialize() override; - void operator()( const MCUTDeposits& depositsCont ) const override; + void operator()( const LHCb::MCUTDeposits& depositsCont ) const override; private: - void fillHistograms( const LHCb::MCUTDeposit& aDeposit ) const; + void fillHistograms( const LHCb::MCUTDeposit& aDeposit ) const; + mutable Gaudi::Accumulators::StaticHistogram<1> m_nDeposits{ this, "1", "Number of deposits", { 200, 0., 10000. } }; + mutable Gaudi::Accumulators::StaticHistogram<1> m_depositedCharge{ this, "2", "Deposited charge", { 100, 0., 100. } }; + mutable Gaudi::Accumulators::StaticHistogram<1> m_nDepositsPerStation{ + this, "3", "Number of deposits per station", { 5, -0.5, 4.5 } }; + mutable Gaudi::Accumulators::StaticHistogram<1> m_nDepositsPerLayer{ + this, "4", "Number of deposits per layer", { 41, -0.5, 40.5 } }; + mutable std::map> m_depositedChargeXvY; + mutable std::mutex m_depositedChargeXvYLock; }; DECLARE_COMPONENT( MCUTDepositMonitor ) MCUTDepositMonitor::MCUTDepositMonitor( const std::string& name, ISvcLocator* pSvcLocator ) - : Consumer{ name, pSvcLocator, { "InputData", MCUTDepositLocation::UTDeposits } } {} + : Consumer{ name, pSvcLocator, { "InputData", LHCb::MCUTDepositLocation::UTDeposits } } {} -StatusCode MCUTDepositMonitor::initialize() { - if ( "" == histoTopDir() ) setHistoTopDir( "UT/" ); - return Consumer::initialize(); -} - -void MCUTDepositMonitor::operator()( const MCUTDeposits& depositsCont ) const { +void MCUTDepositMonitor::operator()( const LHCb::MCUTDeposits& depositsCont ) const { // number of digits - plot( (double)depositsCont.size(), 1, "Number of deposits", 0., 10000., 200 ); + ++m_nDeposits[depositsCont.size()]; // histos per digit for ( const auto& i : depositsCont ) fillHistograms( *i ); } -void MCUTDepositMonitor::fillHistograms( const MCUTDeposit& aDeposit ) const { +void MCUTDepositMonitor::fillHistograms( const LHCb::MCUTDeposit& aDeposit ) const { // Plot deposited charge - plot( aDeposit.depositedCharge(), 2, "Deposited charge", 0., 100., 100 ); + ++m_depositedCharge[aDeposit.depositedCharge()]; // Plot number of deposits per station const int iStation = aDeposit.channelID().station(); - plot( (double)iStation, 3, "Number of deposits per station", -0.5, 4.5, 5 ); + ++m_nDepositsPerStation[iStation]; // by layer - plot( (double)( 10 * iStation + aDeposit.channelID().layer() ), 4, "Number of deposits per layer", -0.5, 40.5, 41 ); + ++m_nDepositsPerLayer[10 * iStation + aDeposit.channelID().layer()]; // detailed level histos - if ( fullDetail() ) { - const MCHit* aHit = aDeposit.mcHit(); - if ( aHit ) { - // take midPoint - Gaudi::XYZPoint impactPoint = aHit->midPoint(); + const LHCb::MCHit* aHit = aDeposit.mcHit(); + if ( aHit ) { + // take midPoint + Gaudi::XYZPoint impactPoint = aHit->midPoint(); - // fill x vs y scatter plots - std::string title = "x vs y " + UTNames::StationToString( aDeposit.channelID() ); - plot2D( impactPoint.x(), impactPoint.y(), 200 + iStation, title, -1000., 1000., -1000., 1000., 50, 50 ); + // fill x vs y scatter plots + std::string title = "x vs y " + LHCb::UTNames::StationToString( aDeposit.channelID() ); + if ( !m_depositedChargeXvY.contains( title ) ) { + // create new histo, stay thread safe + std::scoped_lock lock{ m_depositedChargeXvYLock }; + if ( !m_depositedChargeXvY.contains( title ) ) { + // now we are alone and there is still nothing, let's create the histogram + m_depositedChargeXvY.emplace( std::piecewise_construct, std::forward_as_tuple( title ), + std::forward_as_tuple( this, fmt::format( "{}", 200 + iStation ), title, + Gaudi::Accumulators::Axis{ 50, -1000., 1000. }, + Gaudi::Accumulators::Axis{ 50, -1000., 1000. } ) ); + } } + ++m_depositedChargeXvY.at( title )[{ impactPoint.x(), impactPoint.y() }]; } } diff --git a/UT/UTCheckers/src/MCUTDigitMonitor.cpp b/UT/UTCheckers/src/MCUTDigitMonitor.cpp index 7cb64e1d3f35879136667a5fa06e31884678b18f..97f3ca6ae051becc9a45521258fdafbbe04a4fd7 100644 --- a/UT/UTCheckers/src/MCUTDigitMonitor.cpp +++ b/UT/UTCheckers/src/MCUTDigitMonitor.cpp @@ -13,9 +13,7 @@ #include "LHCbAlgs/Consumer.h" #include "UTDet/DeUTDetector.h" -#include "GaudiAlg/GaudiHistoAlg.h" - -using namespace LHCb; +#include /** * Make plots for MCUTDigits @@ -25,16 +23,26 @@ using namespace LHCb; * @author J. van Tilburg * @date 2018-09-04 */ -class MCUTDigitMonitor - : public LHCb::Algorithm::Consumer> { +class MCUTDigitMonitor : public LHCb::Algorithm::Consumer> { public: MCUTDigitMonitor( const std::string& name, ISvcLocator* svcloc ); - StatusCode initialize() override; - void operator()( const MCUTDigits&, const DeUTDetector& deUT ) const override; + void operator()( const LHCb::MCUTDigits&, const DeUTDetector& deUT ) const override; private: void fillHistograms( const LHCb::MCUTDigit& aDigit, const DeUTDetector& deUT ) const; + mutable Gaudi::Accumulators::StaticHistogram<1> m_nMCDigits{ this, "1", "Number of MCDigits", { 100, 0., 10000. } }; + mutable Gaudi::Accumulators::StaticHistogram<1> m_nDepositsPerDigit{ + this, "2", "Number of deposits per digit", { 11, -0.5, 10.5 } }; + mutable Gaudi::Accumulators::StaticHistogram<1> m_nDigitsPerStation{ + this, "3", "Number of digits per station", { 11, -0.5, 4.5 } }; + mutable Gaudi::Accumulators::StaticHistogram<2> m_digitsVsXY{ this, + "UTDigits X vs. Y (Strip Center)", + "UTDigits X vs. Y (Strip Center)", + { 57, -908.6, 908.6 }, + { 24, -764.8, 764.8 } }; + mutable Gaudi::Accumulators::StaticHistogram<1> m_nDigitsPerLayer{ + this, "Number of digits per layer", "Number of digits per layer", { 41, -0.5, 40.5 } }; }; DECLARE_COMPONENT( MCUTDigitMonitor ) @@ -42,28 +50,22 @@ DECLARE_COMPONENT( MCUTDigitMonitor ) MCUTDigitMonitor::MCUTDigitMonitor( const std::string& name, ISvcLocator* pSvcLocator ) : Consumer{ name, pSvcLocator, - { { "InputData", MCUTDigitLocation::UTDigits }, { "DeUT", DeUTDetLocation::location() } } } {} - -StatusCode MCUTDigitMonitor::initialize() { - // Set the top directory to IT or TT. - if ( histoTopDir().empty() ) setHistoTopDir( "UT/" ); - return Consumer::initialize(); -} + { { "InputData", LHCb::MCUTDigitLocation::UTDigits }, { "DeUT", DeUTDetLocation::location() } } } {} -void MCUTDigitMonitor::operator()( const MCUTDigits& digitsCont, const DeUTDetector& deUT ) const { +void MCUTDigitMonitor::operator()( const LHCb::MCUTDigits& digitsCont, const DeUTDetector& deUT ) const { // number of digits - plot( (double)digitsCont.size(), 1, "Number of MCDigits", 0., 10000., 100 ); + ++m_nMCDigits[digitsCont.size()]; // histos per digit for ( const auto& i : digitsCont ) fillHistograms( *i, deUT ); } -void MCUTDigitMonitor::fillHistograms( const MCUTDigit& aDigit, const DeUTDetector& deUT ) const { +void MCUTDigitMonitor::fillHistograms( const LHCb::MCUTDigit& aDigit, const DeUTDetector& deUT ) const { // number of deposits that contribute - plot( (double)aDigit.mcDeposit().size(), 2, "Number of deposits per digit", -0.5, 10.5, 11 ); + ++m_nDepositsPerDigit[aDigit.mcDeposit().size()]; // histogram by station const int iStation = aDigit.channelID().station(); - plot( (double)iStation, 3, "Number of digits per station", -0.5, 4.5, 11 ); + ++m_nDigitsPerStation[iStation]; // digits x vs. y auto hitChanID = aDigit.channelID(); @@ -83,10 +85,10 @@ void MCUTDigitMonitor::fillHistograms( const MCUTDigit& aDigit, const DeUTDetect ROOT::Math::XYZPoint hitPos = g1 + ( g2 - g1 ) * 0.5; auto hitX = hitPos.X(); auto hitY = hitPos.Y(); - plot2D( hitX, hitY, "UTDigits X vs. Y (Strip Center)", -908.6, 908.6, -764.8, 764.8, 57, 24 ); + ++m_digitsVsXY[{ hitX, hitY }]; } // by layer const int iLayer = aDigit.channelID().layer(); - plot( (double)( 10 * iStation + iLayer ), "Number of digits per layer", -0.5, 40.5, 41 ); + ++m_nDigitsPerLayer[10 * iStation + iLayer]; } diff --git a/UT/UTCheckers/src/UTDigitMonitor.cpp b/UT/UTCheckers/src/UTDigitMonitor.cpp index 22182303b6e99e4139604b54371a483478cb8fce..2470ddedf4ae600c40b76a0005737f463b8455df 100644 --- a/UT/UTCheckers/src/UTDigitMonitor.cpp +++ b/UT/UTCheckers/src/UTDigitMonitor.cpp @@ -14,13 +14,13 @@ #include "LHCbAlgs/Consumer.h" -#include "GaudiAlg/GaudiHistoAlg.h" +#include + +#include using namespace LHCb; -/** @class UTDigitMonitor UTDigitMonitor.h - * - * Class for monitoring UTDigits +/** Class for monitoring UTDigits * * @author A.Beiter based on code by: * @author M.Needham @@ -28,45 +28,47 @@ using namespace LHCb; * @date 2018-09-04 */ -class UTDigitMonitor - : public LHCb::Algorithm::Consumer> { +class UTDigitMonitor : public LHCb::Algorithm::Consumer> { + + mutable Gaudi::Accumulators::StaticHistogram<1> m_nDigits{ this, "1", "Number of digits", { 500, 0., 10000. } }; + mutable Gaudi::Accumulators::StaticHistogram<1> m_shorth{ this, "shorth", "shorth", { 200, 0., 100. } }; + mutable Gaudi::Accumulators::StaticHistogram<1> m_nDigitsPerStation{ + this, "2", "Number of digits per station", { 5, -0.5, 4.5 } }; + mutable Gaudi::Accumulators::StaticHistogram<1> m_nDigitsPerLayer{ + this, "3", "Number of digits per layer", { 41, -0.5, 40.5 } }; + mutable Gaudi::Accumulators::StaticHistogram<2> m_digitsVsXY{ this, + "UTDigits X vs. Y (Strip Center)", + "UTDigits X vs. Y (Strip Center)", + { 57, -908.6, 908.6 }, + { 24, -764.8, 764.8 } }; + mutable std::map> m_chargePerSector; + mutable std::mutex m_chargePerSectorLock; public: - /// constructer UTDigitMonitor( const std::string& name, ISvcLocator* svcloc ) : Consumer{ name, svcloc, { { "InputData", UTDigitLocation::UTDigits }, { "UTLocation", DeUTDetLocation::location() } } } {} - /// initialize - StatusCode initialize() override { - return Consumer::initialize().andThen( [&] { - // Set the top directory to UT - if ( histoTopDir().empty() ) setHistoTopDir( "UT/" ); - } ); - } - - /// execute void operator()( const UTDigits& digitsCont, DeUTDetector const& det ) const override { // number of digits - plot( (double)digitsCont.size(), 1, "Number of digits", 0., 10000., 500 ); + ++m_nDigits[digitsCont.size()]; // histos per digit for ( const auto& d : digitsCont ) fillHistograms( d, det ); double shorth = SiChargeFun::shorth( digitsCont.begin(), digitsCont.end() ); - plot( shorth, "shorth", 0., 100., 200 ); + ++m_shorth[shorth]; } private: void fillHistograms( const LHCb::UTDigit* aDigit, DeUTDetector const& det ) const { // histogram by station const int iStation = aDigit->station(); - plot( (double)iStation, 2, "Number of digits per station", -0.5, 4.5, 5 ); - + ++m_nDigitsPerStation[iStation]; // by layer const int iLayer = aDigit->layer(); - plot( (double)( 10 * iStation + iLayer ), 3, "Number of digits per layer", -0.5, 40.5, 41 ); + ++m_nDigitsPerLayer[10 * iStation + iLayer]; // digits x vs. y auto hitChanID = aDigit->channelID(); @@ -86,19 +88,26 @@ private: ROOT::Math::XYZPoint hitPos = g1 + ( g2 - g1 ) * 0.5; auto hitX = hitPos.X(); auto hitY = hitPos.Y(); - plot2D( hitX, hitY, "UTDigits X vs. Y (Strip Center)", -908.6, 908.6, -764.8, 764.8, 57, 24 ); + ++m_digitsVsXY[{ hitX, hitY }]; } - if ( fullDetail() ) { - auto const sector = det.findSector( aDigit->channelID() ); + auto const sector = det.findSector( aDigit->channelID() ); #ifdef USE_DD4HEP - plot( aDigit->depositedCharge(), ( sector.isValid() ? sector.type() : "Unknown" ) + "/1", "Deposited charge ", 0., - 31, 31 ); + std::string type = sector.isValid() ? sector.type() + "/1" : "Unknown/1"; #else - plot( aDigit->depositedCharge(), ( sector ? sector->type() : "Unknown" ) + "/1", "Deposited charge ", 0., 31., - 31 ); + std::string type = sector ? sector->type() + "/1" : "Unknown/1"; #endif + if ( !m_chargePerSector.contains( type ) ) { + // create new histo, stay thread safe + std::scoped_lock lock{ m_chargePerSectorLock }; + if ( !m_chargePerSector.contains( type ) ) { + // now we are alone and there is still nothing, let's create the histogram + m_chargePerSector.emplace( std::piecewise_construct, std::forward_as_tuple( type ), + std::forward_as_tuple( this, "Deposited charge", "Deposited charge", + Gaudi::Accumulators::Axis{ 31, 0., 31. } ) ); + } } + ++m_chargePerSector.at( type )[aDigit->depositedCharge()]; } }; diff --git a/VP/VPCheckers/src/VPClusterEffSimDQ.cpp b/VP/VPCheckers/src/VPClusterEffSimDQ.cpp index feec7124cd9faad121bba72c34c0c8bc474c669d..18596c76d8ab325e92a1a6bf5fc0bdcb84e66632 100644 --- a/VP/VPCheckers/src/VPClusterEffSimDQ.cpp +++ b/VP/VPCheckers/src/VPClusterEffSimDQ.cpp @@ -48,7 +48,7 @@ namespace LHCb { class VPClusterEffSimDQ : public Algorithm::Consumer&, const LHCb::MCHits&, const LHCb::MCParticles&, const LHCb::LinksByKey&, const DeVP& ), - Algorithm::Traits::usesBaseAndConditions> { + Algorithm::Traits::usesConditions> { public: /// Standard constructor VPClusterEffSimDQ( const std::string& name, ISvcLocator* pSvcLocator );