Skip to content
Snippets Groups Projects

New merge to master for VELO monitoring (rebased from velomon_rhel9, TAEmonitor only now)

Merged Lanxing Li requested to merge lali_velomon_rebase_TAE_only into master
Compare and
5 files
+ 1527
210
Compare changes
  • Side-by-side
  • Inline
Files
5
+ 247
0
/*****************************************************************************\
* (c) Copyright 2020 CERN for the benefit of the LHCb Collaboration *
* *
* This software is distributed under the terms of the GNU General Public *
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
* *
* In applying this licence, CERN does not waive the privileges and immunities *
* granted to it by virtue of its status as an Intergovernmental Organization *
* or submit itself to any jurisdiction. *
\*****************************************************************************/
#include "Event/ODIN.h"
#include "Event/VPFullCluster.h"
//#include "VPRetinaFullCluster.h"
#include "Kernel/VPConstants.h"
#include "VPDet/DeVP.h"
#include "DetDesc/GenericConditionAccessorHolder.h"
#include "VPDet/DeVPSensor.h"
#include "GaudiAlg/Consumer.h"
#include "GaudiAlg/GaudiTupleAlg.h"
#include <GaudiAlg/GaudiHistoAlg.h>
#include <GaudiKernel/IHistogramSvc.h>
#include <GaudiUtils/HistoLabels.h>
#include "Gaudi/Accumulators/Histogram.h"
#include "Gaudi/Accumulators/HistogramArray.h"
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <vector>
/* @class VPBunchMonitors VPBunchMonitors.cpp
*
* * Class for plotting
* - Number of clusters per bunch ID for each module
*
* @author T.H.McGrath
* @date 2022-05-19
*/
namespace {
constexpr auto NAsicsTotal = VP::NSensorsPerModule * VP::NChipsPerSensor * VP::NModules;
// Get asic in range [0, 623]
constexpr uint get_asic( uint sensor, uint chipNr ) { return 3 * sensor + chipNr; }
} // namespace
using Gaudi::Functional::Consumer; // Consumer
namespace LHCb {
class VPBunchMonitors : public Consumer<void( const ODIN&, const std::vector<VPFullCluster>& ),
DetDesc::usesBaseAndConditions<GaudiHistoAlg>> {
public:
// Constructor
VPBunchMonitors( const std::string& name, ISvcLocator* pSvcLocator );
// Functional operator
void operator()( const ODIN&, const std::vector<VPFullCluster>& ) const override;
private:
// Input variables
Gaudi::Property<bool> applyCut{this, "ClearNoise", false, "Whether to remove noisy pixels to clean data"};
Gaudi::Property<bool> printInfo{this, "PrintInfo", true, "Whether to print BxID info for each event"};
Gaudi::Property<bool> debug{this, "DebugMode", true, "Whether to produce extra plots for debugging"};
// Builder for array of 1D histos with same range and same titles!
template <std::size_t... IDXs>
static std::array<Gaudi::Accumulators::Histogram<1>, sizeof...( IDXs )>
histoArrayBuilderST( const VPBunchMonitors* owner, const std::string& name, const std::string& title,
const std::string& title_suffix, std::tuple<unsigned, double, double> bins,
std::index_sequence<IDXs...> ) {
return {{{owner,
name + std::to_string( IDXs ),
title + std::to_string( IDXs ) + title_suffix,
{std::get<0>( bins ), std::get<1>( bins ), std::get<2>( bins )}}...}};
}
// Builder for array of 2D histos with fixed ranges and labels (General)
template <std::size_t... IDXs>
static std::array<Gaudi::Accumulators::Histogram<2>, sizeof...( IDXs )>
histoArrayBuilder2D( const VPBunchMonitors* owner, const std::string& name, const std::string& title,
const std::string& title_suffix, std::tuple<unsigned, double, double> xbins,
std::tuple<unsigned, double, double> ybins, std::index_sequence<IDXs...> ) {
return {{{owner,
name + std::to_string( IDXs ),
title + std::to_string( IDXs ) + title_suffix,
{std::get<0>( xbins ), std::get<1>( xbins ), std::get<2>( xbins )},
{std::get<0>( ybins ), std::get<1>( ybins ), std::get<2>( ybins )}}...}};
}
// Book all plots
mutable Gaudi::Accumulators::Histogram<1> m_ncl{this, // Clusters / event frequency
"VPClustersPerEvent",
"Frequency of # of VP clusters per event (Frequency vs Clusters/event); Clusters/event;",
{25, 0., 25.}};
mutable Gaudi::Accumulators::Histogram<1> m_bxid{this, "BxIDFrequency", "# of VP clusters per BxID (Frequency vs BxID); BxID;", {3564, 0.5, 3564.5}};
mutable Gaudi::Accumulators::Histogram<2> m_bxidpe{this,
"VPClustersPerEventVSBxID",
"# of VP clusters per event per BxID (Clusters/event vs BxID); BxID; Clusters/event",
{3564, 0.5, 3564.5},
{5001, -1, 10001}};
mutable Gaudi::Accumulators::Histogram<2> m_allmods{this,
"VPClustersPerModulePerBxID",
"Cluster frequency per module per BxID (BxID vs Modules); Module; BxId",
{VP::NModules, -0.5, VP::NModules - 0.5},
{3564, 0.5, 3564.5}};
mutable Gaudi::Accumulators::Histogram<2> m_allasics{this,
"VPClustersPerASICPerBxID",
"Cluster frequency per ASIC per BxID (BxID vs ASIC); ASIC; BxId",
{NAsicsTotal, -0.5, NAsicsTotal - 0.5},
{3564, 0.5, 3564.5}};
// Only book per module plots if in debug mode (currently add all debug plots)
mutable Gaudi::Accumulators::HistogramArray<Gaudi::Accumulators::Histogram<2>, VP::NModules> m_bxidpepm{this, "VPClustersPerEventVSBxIDForModule_{}",
"# of VP clusters per event per BxID for Module {} (Clusters/event vs BxID); BxID; Clusters/event", {3564, 0.5, 3564.5, "X"},
{25, 0., 25., "Y"} };
mutable Gaudi::Accumulators::HistogramArray<Gaudi::Accumulators::Histogram<1>, VP::NModules> m_nclpm{this, "VPClustersPerEventForModule_{}",
"Frequency of # of VP clusters per event for Module {} (Frequency vs Clusters/event); Clusters/event;", {25, 0., 25., "X"} };
mutable Gaudi::Accumulators::HistogramArray<Gaudi::Accumulators::Histogram<1>, VP::NModules> m_listmods{this, "VPClustersPerBxIDForModule_{}", "Cluster frequency per BxID for Module {} (Clusters vs BxID); BxID; Clusters", {3564, 0.5, 3564.5, "X"} };
mutable Gaudi::Accumulators::HistogramArray<Gaudi::Accumulators::Histogram<2>, VP::NModules> m_pixmaps{this, "VPClusterssMapModule_{}", "VP cluster map on module {} (Row vs Column); Column; Row", {VP::NColumns, 0, VP::NColumns, "X"},
{VP::NRows, 0, VP::NRows,"Y"} };
mutable Gaudi::Accumulators::Histogram<1> m_csize{this,
"VPClusterSize",
"Number of pixels per VP cluster (Frequency vs Cluster Size); Cluster Size;",
{49, 1, 50}};
/*
mutable std::array<Gaudi::Accumulators::Histogram<2>, VP::NModules> m_bxidpepm{histoArrayBuilder2D( this, "VPClustersPerEventVSBxIDForModule",
"# of VP clusters per event per BxID for Module ",
" (Clusters/event vs BxID); BxID; Clusters/event", {3564, 0.5, 3564.5},
{25, 0., 25.}, std::make_index_sequence<VP::NModules>() )};
mutable std::array<Gaudi::Accumulators::Histogram<1>, VP::NModules> m_nclpm{histoArrayBuilderST( this, "VPClustersPerEventForModule",
"Frequency of # of VP clusters per event for Module ",
" (Frequency vs Clusters/event); Clusters/event;", {25, 0., 25.},
std::make_index_sequence<VP::NModules>() )};
mutable std::array<Gaudi::Accumulators::Histogram<1>, VP::NModules> m_listmods{histoArrayBuilderST( this, "VPClustersPerBxIDForModule", "Cluster frequency per BxID for Module ",
" (Clusters vs BxID); BxID; Clusters", {3564, 0.5, 3564.5},
std::make_index_sequence<VP::NModules>() )};
mutable std::array<Gaudi::Accumulators::Histogram<2>, VP::NModules> m_pixmaps{histoArrayBuilder2D( this, "VPClusterssMapModule", "VP cluster map on module ",
" (Row vs Column); Column; Row", {VP::NColumns, 0, VP::NColumns},
{VP::NRows, 0, VP::NRows}, std::make_index_sequence<VP::NModules>() )};
mutable Gaudi::Accumulators::Histogram<1> m_csize{this,
"VPClusterSize",
"Number of pixels per VP cluster (Frequency vs Cluster Size); Cluster Size;",
{49, 1, 50}};
*/
}; // End of class
} // end of the LHCb namespace
// Declaration of the Algorithm Factory
DECLARE_COMPONENT_WITH_ID( LHCb::VPBunchMonitors, "VPBunchMonitors" )
// ===============================================================
// Constructor
// ===============================================================
LHCb::VPBunchMonitors::VPBunchMonitors( const std::string& name, ISvcLocator* pSvcLocator )
: Consumer( name, pSvcLocator,
{KeyValue{"ODINLocation", LHCb::ODINLocation::Default},
KeyValue{"ClusterLocation", LHCb::VPFullClusterLocation::Default}} ) {}
//We abondon the initialise funciotn as we have nothing specific to initialise in current stage (can add in need)
// ===============================================================
// Main
// ===============================================================
void LHCb::VPBunchMonitors::operator()( const LHCb::ODIN& odin, const std::vector<LHCb::VPFullCluster>& vpClusters ) const {
// Get event information from ODIN
const auto bxid = odin.bunchId();
const auto runNr = odin.runNumber();
const auto evtNr = odin.eventNumber();
if ( printInfo ) {
info() << "BxID: " << bxid << " run #: " << runNr << " event #: " << evtNr << endmsg;
info() << "Number of clusters: " << vpClusters.size() << endmsg;
}
std::vector<uint> nClusPerMod( VP::NModules, 0 );
std::vector<uint> nClusPerChip( NAsicsTotal, 0 );
uint nClusPerEvent( 0 );
// Loop over clusters vector
for ( const auto& vpCluster : vpClusters ) {
// Get VP Channel IDs of pixels in cluster
const auto vpID = vpCluster.channelID();
const auto pixels = vpCluster.pixels();
// Get module where cluster is
const auto mod = vpID.module();
const auto asic = get_asic( to_unsigned( vpID.sensor() ), to_unsigned( vpID.chip() ) );
// info() << "Module: " << mod << endmsg;
// Get pixel
const auto row = to_unsigned( vpID.row() );
const auto col = to_unsigned( vpID.col() );
// Fill histograms
++m_bxid[bxid];
++m_allmods[{mod, bxid}];
++m_allasics[{asic, bxid}];
++m_csize[pixels.size()];
// Add each cluster from asic
++nClusPerChip[asic];
++nClusPerEvent;
if ( debug ) {
++m_listmods[mod][bxid];
++m_pixmaps[mod][{col, row}];
++nClusPerMod[mod];
}
} // Loop over clusters per event
++m_bxidpe[{bxid, nClusPerEvent}];
++m_ncl[nClusPerEvent];
if ( debug ) {
for ( uint modNr = 0; modNr < VP::NModules; ++modNr ) {
++m_nclpm[modNr][nClusPerMod[modNr]];
++m_bxidpepm[modNr][{bxid, nClusPerMod[modNr]}];
// info() << "Clusters in this event for module " << modNr << ": " << nClusPerMod[modNr] << endmsg;
}
}
// clear vector before next event
nClusPerMod.clear();
}
Loading