ATLAS Offline Software
Loading...
Searching...
No Matches
FixedArrayBM.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include<algorithm> /*count_if,max_element*/
6#include<cassert>
7#include<limits> /*epsilon*/
8#include<numeric> /*accumulate*/
9#include "UtilityFuncs.h"
10#include "FixedArrayBM.h"
11
12FixedArrayBM::FixedArrayBM(const std::string& name,ISvcLocator* svc)
13 : base_class(name,svc)
14 , m_intensityPattern(new double[m_ipLength])
15{
16 m_intensityPattern[0]=1.0;
17}
18
23
25{
26 const std::vector<float>& rProp(m_intensityPatternProp.value());
27 std::vector<float>::const_iterator pBegin(rProp.begin());
28 std::vector<float>::const_iterator pEnd(rProp.end());
29 m_ipLength = rProp.size();
30 if(m_ipLength<1)
31 {
32 ATH_MSG_ERROR("IntensityPattern length (" << m_ipLength << ") is less than 1!");
33 return StatusCode::FAILURE;
34 }
35 //Consistency checks
37 {
38 ATH_MSG_ERROR("IntensityPattern length (" << m_ipLength << "), exceeds the maximum number of bunch crossings per orbit (" << m_maxBunchCrossingPerOrbit << ").");
39 return StatusCode::FAILURE;
40 }
41
42 // Normalise the pattern so that the non-zero elements average to 1.0
43 float nonZeroElementCount(static_cast<float>(std::count_if(pBegin, pEnd, IsNonZero)));
44 if(nonZeroElementCount<1.0)
45 {
46 ATH_MSG_ERROR("IntensityPattern has no non-zero elements!");
47 return StatusCode::FAILURE;
48 }
49 float elementSum(static_cast<float>(std::accumulate(pBegin, pEnd,0.0)));
50 float denominator(elementSum/nonZeroElementCount);
51
52 // Normalise the pattern so that the highest element value is 1.0
53 float maxElement(*(std::max_element(pBegin, pEnd)));
54 float inv_maxElement = maxElement != 0 ? 1. / maxElement : 1;
55
56 // Copy normalized intensity pattern from the property
57 delete [] m_intensityPattern;
58 m_intensityPattern = new double[m_ipLength];
59
60 for (unsigned int i(0); i<m_ipLength; ++i)
61 {
62 if (rProp[i]<0.0)
63 {
64 ATH_MSG_ERROR("All IntensityPattern elements must be >=0. Please fix element #" << i );
65 return StatusCode::FAILURE;
66 }
67 m_intensityPattern[i] = rProp[i] * inv_maxElement; // this ensures that the elements are all in the range [0,1]
68 }
69
70 // Will be used to convert values in the m_intensityPattern
71 // from having max value 1.0 to having mean value 1.0
72 if (denominator != 0) {
73 m_largestElementInPattern = (maxElement/denominator);
74 }
75
76 //FIXME add a check that entry 0 is zero? In data, BCID=1 is always the first filled bunch.
77
78 //check m_t0Offset is within allowed values
80 {
81 ATH_MSG_INFO("Requested T0 offset (" << m_t0Offset << ") does not lie within IntensityPattern provided. Resetting offset to " << (m_t0Offset % m_ipLength) << " as this will give the same result.");
83 }
84 assert(m_intensityPattern[m_t0Offset % m_ipLength]>0.0); //just in case
86 {
87 ATH_MSG_DEBUG( "T0 offset set to " << m_t0Offset << " for all events in this run." );
88 }
89 else
90 {
91 if (!(m_allowEmptyT0BunchCrossing.value()))
92 {
93 ATH_MSG_ERROR("Requested T0 offset (" << m_t0Offset << ") coincides with an empty bunch crossing in the IntensityPattern provided. Please re-submit your job and select an offset corresponding to a bunch crossing with non-zero luminosity.");
94 return StatusCode::FAILURE;
95 }
96 else
97 {
98 ATH_MSG_INFO( "Allowing T0 to coincide with an empty bunch crossing in the IntensityPattern provided. T0 offset set to " << m_t0Offset << " for all events in this run." );
99 }
100 }
101 return StatusCode::SUCCESS;
102}
103
104float FixedArrayBM::normFactor(int iXing) const
105 {
106 unsigned int index = static_cast<unsigned int>((((iXing + static_cast<int>(m_t0Offset)) % static_cast<int>(m_ipLength)) + static_cast<int>(m_ipLength) ) % static_cast<int>(m_ipLength));
107 //The array itself has max-value 1.0, but we want it to have mean value 1.0 (for filled bunch crossings), so we multiple by the m_largestElementInPattern.
108 ATH_MSG_VERBOSE("normFactor for BCID " << iXing
109 << " (offset " << m_t0Offset
110 << " index " << index
113 }
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
A IBeamIntensity service configured with an intensity array The Gaudi::Property<std::vector<float>> d...
Holds helper functions used by FixedArrayBM and ArrayBM.
static bool IsNonZero(float lumi)
Gaudi::Property< unsigned int > m_maxBunchCrossingPerOrbit
Gaudi::Property< unsigned int > m_t0Offset
double * m_intensityPattern
normalized intensity pattern.
Gaudi::Property< std::vector< float > > m_intensityPatternProp
virtual StatusCode initialize() override final
Gaudi::Property< bool > m_allowEmptyT0BunchCrossing
unsigned int m_ipLength
length of the intensity pattern
FixedArrayBM(const std::string &name, ISvcLocator *svc)
virtual ~FixedArrayBM()
float m_largestElementInPattern
The largest value in the pattern assuming that the pattern has mean value 1.0.
virtual float normFactor(int iXing) const override final
Definition index.py:1