ATLAS Offline Software
FixedArrayBM.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 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_maxBunchCrossingPerOrbit(3564)
15  , m_t0Offset(0)
16  , m_allowEmptyT0BunchCrossing(false)
17  , m_intensityPatternProp()
18  , m_ipLength(1)
19  , m_intensityPattern(new double[m_ipLength])
20  , m_largestElementInPattern(1.0)
21 {
22  declareProperty("MaxBunchCrossingPerOrbit", m_maxBunchCrossingPerOrbit, "The number of slots in each LHC beam. Default: 3564.");
23  declareProperty("T0Offset", m_t0Offset, "Offset of the T0 w.r.t. our intensity pattern" );
24  declareProperty("AllowEmptyT0BunchCrossing", m_allowEmptyT0BunchCrossing, "Allow the offset of the T0 to sit in an empty bunch crossing." );
25  declareProperty("IntensityPattern", m_intensityPatternProp,
26  "An array of floats containing the beam intensity distribution as a function of time in bins of 25ns. FixedArrayBM normalizes the distribution and uses it as a stencil to determine the relative intensity at each beam xing in the simulated range"
27  );
28  m_intensityPattern[0]=1.0;
29 }
30 
32 {
33  delete [] m_intensityPattern;
34 }
35 
37 {
38  const std::vector<float>& rProp(m_intensityPatternProp.value());
39  std::vector<float>::const_iterator pBegin(rProp.begin());
40  std::vector<float>::const_iterator pEnd(rProp.end());
41  m_ipLength = rProp.size();
42  if(m_ipLength<1)
43  {
44  ATH_MSG_ERROR("IntensityPattern length (" << m_ipLength << ") is less than 1!");
45  return StatusCode::FAILURE;
46  }
47  //Consistency checks
49  {
50  ATH_MSG_ERROR("IntensityPattern length (" << m_ipLength << "), exceeds the maximum number of bunch crossings per orbit (" << m_maxBunchCrossingPerOrbit << ").");
51  return StatusCode::FAILURE;
52  }
53 
54  // Normalise the pattern so that the non-zero elements average to 1.0
55  float nonZeroElementCount(static_cast<float>(std::count_if(pBegin, pEnd, IsNonZero)));
56  if(nonZeroElementCount<1.0)
57  {
58  ATH_MSG_ERROR("IntensityPattern has no non-zero elements!");
59  return StatusCode::FAILURE;
60  }
61  float elementSum(static_cast<float>(std::accumulate(pBegin, pEnd,0.0)));
62  float denominator(elementSum/nonZeroElementCount);
63 
64  // Normalise the pattern so that the highest element value is 1.0
65  float maxElement(*(std::max_element(pBegin, pEnd)));
66  float inv_maxElement = maxElement != 0 ? 1. / maxElement : 1;
67 
68  // Copy normalized intensity pattern from the property
69  delete [] m_intensityPattern;
70  m_intensityPattern = new double[m_ipLength];
71 
72  for (unsigned int i(0); i<m_ipLength; ++i)
73  {
74  if (rProp[i]<0.0)
75  {
76  ATH_MSG_ERROR("All IntensityPattern elements must be >=0. Please fix element #" << i );
77  return StatusCode::FAILURE;
78  }
79  m_intensityPattern[i] = rProp[i] * inv_maxElement; // this ensures that the elements are all in the range [0,1]
80  }
81 
82  // Will be used to convert values in the m_intensityPattern
83  // from having max value 1.0 to having mean value 1.0
85 
86  //FIXME add a check that entry 0 is zero? In data, BCID=1 is always the first filled bunch.
87 
88  //check m_t0Offset is within allowed values
90  {
91  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.");
93  }
94  assert(m_intensityPattern[m_t0Offset % m_ipLength]>0.0); //just in case
96  {
97  ATH_MSG_DEBUG( "T0 offset set to " << m_t0Offset << " for all events in this run." );
98  }
99  else
100  {
101  if (!(m_allowEmptyT0BunchCrossing.value()))
102  {
103  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.");
104  return StatusCode::FAILURE;
105  }
106  else
107  {
108  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." );
109  }
110  }
111  return StatusCode::SUCCESS;
112 }
113 
114 float FixedArrayBM::normFactor(int iXing) const
115  {
116  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));
117  //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.
118  ATH_MSG_VERBOSE("normFactor for BCID " << iXing
119  << " (offset " << m_t0Offset
120  << " index " << index
123  }
FixedArrayBM::FixedArrayBM
FixedArrayBM(const std::string &name, ISvcLocator *svc)
Definition: FixedArrayBM.cxx:12
FixedArrayBM::~FixedArrayBM
virtual ~FixedArrayBM()
Definition: FixedArrayBM.cxx:31
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
FixedArrayBM::m_intensityPatternProp
Gaudi::Property< std::vector< float > > m_intensityPatternProp
user-defined intensity pattern
Definition: FixedArrayBM.h:56
FixedArrayBM::m_largestElementInPattern
float m_largestElementInPattern
The largest value in the pattern assuming that the pattern has mean value 1.0.
Definition: FixedArrayBM.h:65
index
Definition: index.py:1
FixedArrayBM::m_allowEmptyT0BunchCrossing
Gaudi::Property< bool > m_allowEmptyT0BunchCrossing
allow t0 to be in an empty bunch crossing
Definition: FixedArrayBM.h:54
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
FixedArrayBM::m_maxBunchCrossingPerOrbit
unsigned int m_maxBunchCrossingPerOrbit
max bunch crossings per orbit
Definition: FixedArrayBM.h:50
FixedArrayBM::m_t0Offset
unsigned int m_t0Offset
offset of the t0 wrto our intensity pattern
Definition: FixedArrayBM.h:52
FixedArrayBM::normFactor
virtual float normFactor(int iXing) const override final
Definition: FixedArrayBM.cxx:114
UtilityFuncs.h
prototypes for utility POOL collection funcs
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:58
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
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
ReadTripsProbsFromCool.denominator
denominator
Definition: ReadTripsProbsFromCool.py:96
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
FixedArrayBM.h
A IBeamIntensity service configured with an intensity array The Gaudi::Property<std::vector<float>> d...
DeMoScan.index
string index
Definition: DeMoScan.py:364
FixedArrayBM::initialize
virtual StatusCode initialize() override final
Definition: FixedArrayBM.cxx:36
FixedArrayBM::m_intensityPattern
double * m_intensityPattern
normalized intensity pattern.
Definition: FixedArrayBM.h:60