Skip to content
Snippets Groups Projects
Commit 770030a4 authored by Adam Edward Barton's avatar Adam Edward Barton
Browse files

Merge branch 'branch-MBTS-first' into 'master'

preliminary MBTS trigger DQ alg

See merge request atlas/athena!40798
parents 09b6b5c3 c27a8905
No related branches found
No related tags found
No related merge requests found
#
# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
#
'''
@brief configuration for the min bias monitoring
'''
def TrigMBTS(configFlags):
from AthenaMonitoring import AthMonitorCfgHelper
monConfig = AthMonitorCfgHelper(configFlags, 'HLTMBTSMonitoringAlgMTflags')
from AthenaConfiguration.ComponentFactory import CompFactory
alg = monConfig.addAlgorithm(
CompFactory.HLTMBTSMonitoringAlgMT, 'HLTMBTSMonitoringAlgMT')
alg.triggerList = ["HLT_mb_mbts_L1MBTS_1_EMPTY"]
length = len(alg.triggerList)
MBTS_countsSideA = 12
MBTS_countsSideC = 12
mbtsGroup = monConfig.addGroup(alg, 'MBTSall', topPath='HLT/MBTSMon/')
mbtsGroup.defineHistogram('TrigCounts', title='Trigger counts;;Event rate',
xbins=length, xmin=0, xmax=length, xlabels=list(alg.triggerList))
for chain in alg.triggerList:
mbShiftGroup = monConfig.addGroup(alg, chain+'_shifter',
topPath='HLT/MBTSMon/Shifter/'+chain+'/')
mbShiftGroup.defineHistogram('MBTS_A_hits', type='TH1I', title='MBTS hits side A; Entry rate; MBTS side A',
xbins=MBTS_countsSideA+1, xmin=-0.5, xmax=MBTS_countsSideA+0.5)
mbShiftGroup.defineHistogram('MBTS_C_hits', type='TH1I', title='MBTS hits side C; Entry rate; MBTS side C',
xbins=MBTS_countsSideC+1, xmin=-0.5, xmax=MBTS_countsSideC+0.5)
mbShiftGroup.defineHistogram('MBTS_A_hits,MBTS_C_hits', type='TH2I', title='MBTS hits correlation; MBTS side A; MBTS side C',
xbins=MBTS_countsSideA+1, xmin=-0.5, xmax=MBTS_countsSideA+0.5, ybins=MBTS_countsSideC+1, ymin=-0.5, ymax=MBTS_countsSideC+0.5)
mbShiftGroup.defineHistogram(
'MBTStime', type='TH1F', title='MBTS time; MBTS time [ns]', xbins=100, xmin=-100, xmax=100)
mbShiftGroup.defineHistogram(
'MBTSenergy', type='TH1F', title='MBTS energy; MBTS energy [pC]', xbins=100, xmin=-100, xmax=100)
mbShiftGroup.defineHistogram('MBTSChannelID', type='TH1F', title='MBTS Channel ID; Channel ID; Entry rate',
xbins=MBTS_countsSideA+MBTS_countsSideC, xmin=0, xmax=MBTS_countsSideA+MBTS_countsSideC)
mbShiftGroup.defineHistogram('MBTSChannelID,MBTStime', type='TH2F', title='MBTS time; Channel ID;MBTS time [ns]; Entry rate',
xbins=MBTS_countsSideA+MBTS_countsSideC, xmin=0, xmax=MBTS_countsSideA+MBTS_countsSideC, ybins=100, ymin=-100, ymax=100)
mbShiftGroup.defineHistogram('MBTSChannelID,MBTSenergy', type='TH2F', title='MBTS energy; Channel ID;MBTS energy [pC]; Entry rate',
xbins=MBTS_countsSideA+MBTS_countsSideC, xmin=0, xmax=MBTS_countsSideA+MBTS_countsSideC, ybins=100, ymin=-100, ymax=100)
mbExpGroup = monConfig.addGroup(alg, chain+'_expert',
topPath='HLT/MBTSMon/Expert/'+chain+'/')
mbExpGroup.defineHistogram(
'MBTShits', type='TH2F', title='MBTS total hits;# of Hits;Entry Rate', xbins=24, xmin=0, xmax=100)
mbExpGroup.defineHistogram('MBTS_A_meanEnergy', type='TH1F',
title='Mean MBTS Energy A side passed;MBTS Energy [pC];Entry Rate', xbins=100, xmin=-1, xmax=1)
mbExpGroup.defineHistogram('MBTS_C_meanEnergy', type='TH1F',
title='Mean MBTS Energy C side passed;MBTS Energy [pC];Entry Rate', xbins=100, xmin=-1, xmax=1)
mbExpGroup.defineHistogram('MBTS_A_meanTime', type='TH1F',
title='Mean MBTS Time A side; MBTS time [ns]', xbins=100, xmin=-100, xmax=100)
mbExpGroup.defineHistogram('MBTS_C_meanTime', type='TH1F',
title='Mean MBTS Time C side; MBTS time [ns]', xbins=100, xmin=-100, xmax=100)
return monConfig.result()
if __name__ == '__main__':
# Setup the Run III behavior
from AthenaCommon.Configurable import Configurable
Configurable.configurableRun3Behavior = 1
# Setup logs
from AthenaCommon.Constants import DEBUG
# Set the Athena configuration flags
from AthenaConfiguration.AllConfigFlags import ConfigFlags
ConfigFlags.Input.Files = ['myAOD.pool.root']
ConfigFlags.Output.HISTFileName = 'TestMBTSMonitorOutput.root'
# ConfigFlags.fillFromArgs(sys.argv[1:])
ConfigFlags.lock()
# Initialize configuration object, add accumulator, merge, and run.
from AthenaConfiguration.MainServicesConfig import MainServicesCfg
from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
cfg = MainServicesCfg(ConfigFlags)
cfg.merge(PoolReadCfg(ConfigFlags))
cfg.merge(TrigMBTS(ConfigFlags))
# If you want to turn on more detailed messages ...
# exampleMonitorAcc.getEventAlgo('ExampleMonAlg').OutputLevel = 2 # DEBUG
cfg.getEventAlgo('HLTMBTSMonitoringAlgMT').OutputLevel = DEBUG # DEBUG
cfg.printConfig(withDetails=True) # set True for exhaustive info
with open("cfg.pkl", "wb") as f:
cfg.store(f)
cfg.run() # use cfg.run(20) to only run on first 20 events
# to run:
# python -m TrigMinBiasMonitoring.TrigMBTSMonitoringMT
/*
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/
#include "HLTMBTSMonitoringAlgMT.h"
HLTMBTSMonitoringAlgMT::HLTMBTSMonitoringAlgMT(const std::string &name, ISvcLocator *pSvcLocator) : AthMonitorAlgorithm(name, pSvcLocator)
{
}
HLTMBTSMonitoringAlgMT::~HLTMBTSMonitoringAlgMT()
{
}
StatusCode HLTMBTSMonitoringAlgMT::initialize()
{
using namespace Monitored;
ATH_CHECK(AthMonitorAlgorithm::initialize());
ATH_CHECK(m_TrigT2MbtsBitsContainerKey.initialize());
return AthMonitorAlgorithm::initialize();
}
StatusCode HLTMBTSMonitoringAlgMT::finalize()
{
return StatusCode::SUCCESS;
}
StatusCode HLTMBTSMonitoringAlgMT::fillHistograms(const EventContext &context) const
{
using namespace Monitored;
const auto &trigDecTool = getTrigDecisionTool();
//==============================================================================
// MBTS BITS INFORMATION
//==============================================================================
auto mbtsbits = SG::makeHandle(m_TrigT2MbtsBitsContainerKey, context);
ATH_MSG_DEBUG("MBTS monitoring, handle validity " << mbtsbits.isValid());
if (!mbtsbits.isValid())
{
ATH_MSG_DEBUG("Could not retrieve mbtsbits");
return StatusCode::SUCCESS;
}
if (mbtsbits->size() == 0)
{
return StatusCode::SUCCESS;
}
ATH_CHECK(mbtsbits->size() == 1);
auto triggerWord = Scalar<unsigned int>("triggerWord", 0);
auto timeWord = Scalar<unsigned int>("timeWord", 0);
auto energyMean_A = Scalar<float>("MBTS_A_meanEnergy", 0.);
auto energyMean_C = Scalar<float>("MBTS_C_meanEnergy", 0.);
auto timeMean_A = Scalar<float>("MBTS_A_meanTime", 0.);
auto timeMean_C = Scalar<float>("MBTS_C_meanTime", 0.);
auto ebaCounters = Scalar<int>("energy_ebaCounters", 1);
for (auto &trig : m_triggerList)
{
if (trigDecTool->isPassed(trig, TrigDefs::requireDecision))
{
ATH_MSG_DEBUG("Chain " << trig << " is passed: YES");
auto TrigCounts = Scalar<std::string>("TrigCounts", trig);
fill("MBTSall", TrigCounts);
for (const auto &mbts_itr : *mbtsbits)
{
auto mbtsHitEnergies = mbts_itr->triggerEnergies(); // energy (in pC) of signal in a counter (relative to IP), vector for all counters
auto mbtsHitTimes = mbts_itr->triggerTimes(); // time of signal in counter (relative to IP), vector for all counters
ATH_MSG_DEBUG("MBTS hits times container size: " << mbtsHitTimes.size());
if (mbtsHitTimes.size() != 32)
ATH_MSG_WARNING("MBTS Cell Times are stored incorrectly. The array should have 32 elements (24 should be filled).");
if (mbtsHitEnergies.size() != 32)
ATH_MSG_WARNING("MBTS Cell Energies are stored incorrectly. The array should have 32 elements (24 should be filled).");
for (unsigned i = 0; i < xAOD::TrigT2MbtsBits::NUM_MBTS; i++)
{
if (i < 16)
{ // A side
energyMean_A += mbtsHitEnergies.at(i);
timeMean_A += mbtsHitTimes.at(i);
ebaCounters++;
ATH_MSG_DEBUG("energy A side: " << mbtsHitEnergies.at(i));
ATH_MSG_DEBUG("time A side: " << mbtsHitTimes.at(i));
if (i == 15)
{
if (ebaCounters > 0)
{
energyMean_A /= ebaCounters;
timeMean_A /= ebaCounters;
ATH_MSG_DEBUG("MEAN energy A side: " << energyMean_A);
ATH_MSG_DEBUG("MEAN time A side: " << timeMean_A);
fill(trig + "_expert", energyMean_A, timeMean_A);
}
}
}
else // C side
{
energyMean_C += mbtsHitEnergies.at(i);
timeMean_C += mbtsHitTimes.at(i);
ebaCounters++;
ATH_MSG_DEBUG("energy C side: " << mbtsHitEnergies.at(i));
ATH_MSG_DEBUG("time C side: " << mbtsHitTimes.at(i));
if (i == 31)
{
if (ebaCounters > 0)
{
energyMean_C /= ebaCounters;
timeMean_C /= ebaCounters;
ATH_MSG_DEBUG("MEAN energy C side: " << energyMean_C);
ATH_MSG_DEBUG("MEAN time C side: " << timeMean_C);
fill(trig + "_expert", energyMean_C, timeMean_C);
}
}
}
}
auto sideA_hits = 0;
auto sideC_hits = 0;
auto MBTStime = Scalar<float>("MBTStime", 3.5);
auto MBTSChannelID = Scalar<float>("MBTSChannelID", 1.0);
auto MBTS_A_hits = Scalar<int>("MBTS_A_hits", sideA_hits);
auto MBTS_C_hits = Scalar<int>("MBTS_C_hits", sideC_hits);
fill(trig + "_shifter", MBTStime, MBTSChannelID, MBTS_A_hits, MBTS_C_hits);
}
}
}
return StatusCode::SUCCESS;
}
/*
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRIGMINBIASMONITORING_HLTMBTSMONITORINGALGMT_H
#define TRIGMINBIASMONITORING_HLTMBTSMONITORINGALGMT_H
#include "AthenaMonitoring/AthMonitorAlgorithm.h"
#include "AthenaMonitoringKernel/Monitored.h"
#include "StoreGate/ReadHandleKey.h"
#include "TrigDecisionTool/TrigDecisionTool.h"
#include "xAODTrigMinBias/TrigT2MbtsBitsContainer.h"
#include "xAODTrigMinBias/TrigT2MbtsBits.h"
#include <string>
/**
* @class HLTMBTSMonitoringAlgMT
* @brief
**/
class HLTMBTSMonitoringAlgMT : public AthMonitorAlgorithm {
public:
HLTMBTSMonitoringAlgMT(const std::string& name, ISvcLocator* pSvcLocator);
virtual ~HLTMBTSMonitoringAlgMT() override;
virtual StatusCode initialize() override;
virtual StatusCode fillHistograms(const EventContext& context) const override;
virtual StatusCode finalize() override;
private:
Gaudi::Property<std::vector<std::string>> m_triggerList{this, "triggerList",{}, "Add triggers to this to be monitored"};
SG::ReadHandleKey<xAOD::TrigT2MbtsBitsContainer> m_TrigT2MbtsBitsContainerKey {this, "MBTSbitsKey","HLT_MbtsBitsContainer","Name of MbtsBitsContainer"};
};
#endif // TRIGMINBIASMONITORING_HLTMBTSMONITORINGALG_H
#include "../HLTMinBiasMonTool.h"
#include "../HLTMinBiasTrkMonAlg.h"
#include "../HLTMBTSMonitoringAlgMT.h"
DECLARE_COMPONENT( HLTMinBiasMonTool )
DECLARE_COMPONENT( HLTMinBiasTrkMonAlg )
DECLARE_COMPONENT( HLTMBTSMonitoringAlgMT )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment