ATLAS Offline Software
PrimaryDPDPrescaler.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
8 #include "CLHEP/Random/RandFlat.h"
9 #include <sstream>
10 
11 PrimaryDPDPrescaler::PrimaryDPDPrescaler(const std::string& name, ISvcLocator* pSvcLocator) :
12  AthReentrantAlgorithm(name, pSvcLocator){
13  declareProperty("AcceptAlgs", m_theAcceptAlgNames );
14  declareProperty("RequireAlgs", m_theRequireAlgNames );
15 }
16 
18  ATH_MSG_DEBUG( "in initialize()" );
19  ATH_CHECK( m_rndmSvc.retrieve());
20  return StatusCode::SUCCESS;
21 }
22 
23 StatusCode PrimaryDPDPrescaler::execute(const EventContext& ctx) const {
24  if (m_prescale <= 1.){
25  ATH_MSG_DEBUG("No prescale active. Do nothing");
26  return StatusCode::SUCCESS;
27  }
28 
29  ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this);
30  rngWrapper->setSeed( name(), ctx );
31  CLHEP::HepRandomEngine* rndmEngine= rngWrapper->getEngine(ctx);
32 
33 
34  const double random_number = CLHEP::RandFlat::shoot( rndmEngine, 0, 1 );
35  if (random_number * m_prescale > 1.){
36  ATH_MSG_DEBUG("The event "<<ctx<<" exceeds the prescale");
37  setFilterPassed(false, ctx);
38  ++m_vetoed;
39  } else {
40  ATH_MSG_DEBUG("The event "<<ctx<<" is accepted");
41  ++m_accepted;
42  setFilterPassed(true,ctx);
43  }
44  return StatusCode::SUCCESS;
45 }
46 
48 {
49  ATH_MSG_DEBUG( "***************************************************************");
50  ATH_MSG_DEBUG( "Total processed events : " << m_accepted + m_vetoed);
51  ATH_MSG_DEBUG( "Accepted events : " << m_accepted );
52  ATH_MSG_DEBUG( "Vetoed events : " << m_vetoed );
53  ATH_MSG_DEBUG( "Nominal prescale/ratio : " << m_prescale << " / " << 1./m_prescale );
54  if( (m_accepted+m_vetoed)>0 ){
55  ATH_MSG_DEBUG( "Accept ratio : " << 1.*m_accepted/(m_accepted+m_vetoed) );
56  }
57  else{ ATH_MSG_DEBUG( "Accept ratio : " << 0 ); }
58  ATH_MSG_DEBUG( "File rollover : " << m_rollover );
59  ATH_MSG_DEBUG( "***************************************************************" );
60  return StatusCode::SUCCESS;
61 }
62 
ATHRNG::RNGWrapper::setSeed
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition: RNGWrapper.h:169
PrimaryDPDPrescaler::initialize
StatusCode initialize() override
Gaudi Service Interface method implementations:
Definition: PrimaryDPDPrescaler.cxx:17
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
PrimaryDPDPrescaler::m_accepted
std::atomic< unsigned int > m_accepted
Definition: PrimaryDPDPrescaler.h:36
PrimaryDPDPrescaler::m_prescale
Gaudi::Property< double > m_prescale
Definition: PrimaryDPDPrescaler.h:35
PrimaryDPDPrescaler::execute
StatusCode execute(const EventContext &ctx) const override
Definition: PrimaryDPDPrescaler.cxx:23
PrimaryDPDPrescaler::finalize
StatusCode finalize() override
Definition: PrimaryDPDPrescaler.cxx:47
PrimaryDPDPrescaler.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
PrimaryDPDPrescaler::m_theAcceptAlgNames
StringArrayProperty m_theAcceptAlgNames
Keep these two properties for now in order not to break the current configuration.
Definition: PrimaryDPDPrescaler.h:43
PrimaryDPDPrescaler::m_theRequireAlgNames
StringArrayProperty m_theRequireAlgNames
List of algorithms names to combine with logical AND.
Definition: PrimaryDPDPrescaler.h:46
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition: RNGWrapper.h:56
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition: RNGWrapper.h:134
RNGWrapper.h
PrimaryDPDPrescaler::m_vetoed
std::atomic< unsigned int > m_vetoed
Definition: PrimaryDPDPrescaler.h:37
PrimaryDPDPrescaler::m_rollover
unsigned int m_rollover
Definition: PrimaryDPDPrescaler.h:38
PrimaryDPDPrescaler::m_rndmSvc
ServiceHandle< IAthRNGSvc > m_rndmSvc
handle to the IAthRNGSvc we want to test
Definition: PrimaryDPDPrescaler.h:33
PrimaryDPDPrescaler::PrimaryDPDPrescaler
PrimaryDPDPrescaler(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
Definition: PrimaryDPDPrescaler.cxx:11
AthReentrantAlgorithm::setFilterPassed
virtual void setFilterPassed(bool state, const EventContext &ctx) const
Definition: AthReentrantAlgorithm.h:139