ATLAS Offline Software
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 
12 FixedArrayBM::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 
20 {
21  delete [] m_intensityPattern;
22 }
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
73 
74  //FIXME add a check that entry 0 is zero? In data, BCID=1 is always the first filled bunch.
75 
76  //check m_t0Offset is within allowed values
78  {
79  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.");
81  }
82  assert(m_intensityPattern[m_t0Offset % m_ipLength]>0.0); //just in case
84  {
85  ATH_MSG_DEBUG( "T0 offset set to " << m_t0Offset << " for all events in this run." );
86  }
87  else
88  {
89  if (!(m_allowEmptyT0BunchCrossing.value()))
90  {
91  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.");
92  return StatusCode::FAILURE;
93  }
94  else
95  {
96  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." );
97  }
98  }
99  return StatusCode::SUCCESS;
100 }
101 
102 float FixedArrayBM::normFactor(int iXing) const
103  {
104  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));
105  //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.
106  ATH_MSG_VERBOSE("normFactor for BCID " << iXing
107  << " (offset " << m_t0Offset
108  << " index " << index
111  }
FixedArrayBM::FixedArrayBM
FixedArrayBM(const std::string &name, ISvcLocator *svc)
Definition: FixedArrayBM.cxx:12
FixedArrayBM::~FixedArrayBM
virtual ~FixedArrayBM()
Definition: FixedArrayBM.cxx:19
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
FixedArrayBM::m_intensityPatternProp
Gaudi::Property< std::vector< float > > m_intensityPatternProp
Definition: FixedArrayBM.h:59
FixedArrayBM::m_largestElementInPattern
float m_largestElementInPattern
The largest value in the pattern assuming that the pattern has mean value 1.0.
Definition: FixedArrayBM.h:72
index
Definition: index.py:1
FixedArrayBM::m_allowEmptyT0BunchCrossing
Gaudi::Property< bool > m_allowEmptyT0BunchCrossing
Definition: FixedArrayBM.h:56
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
FixedArrayBM::normFactor
virtual float normFactor(int iXing) const override final
Definition: FixedArrayBM.cxx:102
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
FixedArrayBM::m_ipLength
unsigned int m_ipLength
length of the intensity pattern
Definition: FixedArrayBM.h:65
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
FixedArrayBM::m_maxBunchCrossingPerOrbit
Gaudi::Property< unsigned int > m_maxBunchCrossingPerOrbit
Definition: FixedArrayBM.h:50
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
ReadTripsProbsFromCool.denominator
denominator
Definition: ReadTripsProbsFromCool.py:96
FixedArrayBM::m_t0Offset
Gaudi::Property< unsigned int > m_t0Offset
Definition: FixedArrayBM.h:53
UtilityFuncs.h
Holds helper functions used by FixedArrayBM and ArrayBM.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
FixedArrayBM.h
A IBeamIntensity service configured with an intensity array The Gaudi::Property<std::vector<float>> d...
DeMoScan.index
string index
Definition: DeMoScan.py:362
runIDAlign.accumulate
accumulate
Update flags based on parser line args.
Definition: runIDAlign.py:60
FixedArrayBM::initialize
virtual StatusCode initialize() override final
Definition: FixedArrayBM.cxx:24
FixedArrayBM::m_intensityPattern
double * m_intensityPattern
normalized intensity pattern.
Definition: FixedArrayBM.h:67