ATLAS Offline Software
StepArrayBM.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 "StepArrayBM.h"
11 
12 StepArrayBM::StepArrayBM(const std::string& name,ISvcLocator* svc)
13  : base_class(name,svc)
14  , m_maxBunchCrossingPerOrbit(3564)
15  , m_t0Offset(0)
16  , m_signalOffset(0)
17  , m_intensityPatternProp()
18  , m_signalPatternProp()
19  , m_ipLength(1)
20  , m_spLength(1)
21  , m_intensityPattern(new double[m_ipLength])
22  , m_signalPattern(new bool[m_spLength])
23  , m_largestElementInPattern(1.0)
24 {
25  declareProperty("MaxBunchCrossingPerOrbit", m_maxBunchCrossingPerOrbit, "The number of slots in each LHC beam. Default: 3564.");
26  declareProperty("IntensityPattern", m_intensityPatternProp,
27  "An array of floats containing the beam intensity distribution as a function of time in bins of 25ns. ArrayBM normalizes the distribution and uses it as a stencil to determine the relative intensity at each beam xing in the simulated range"
28  );
29  declareProperty("SignalPattern", m_signalPatternProp, "An array of booleans to complement the IntensityPattern to indicate where the signal event should happen (i.e. which events to actually simulate). Default behaviour is to do EVERY bunch crossing."
30  );
31  m_intensityPattern[0]=1.0;
32  m_signalPattern[0]=true;
33 }
34 
36 {
37  delete [] m_intensityPattern;
38  delete [] m_signalPattern;
39 }
40 
42 {
43  const std::vector<float>& rProp(m_intensityPatternProp.value());
44  const std::vector<float>& sProp(m_signalPatternProp.value());
45  std::vector<float>::const_iterator pBegin(rProp.begin());
46  std::vector<float>::const_iterator pEnd(rProp.end());
47  m_ipLength = rProp.size();
48  //Consistency checks
50  {
51  ATH_MSG_ERROR("IntensityPattern length (" << m_ipLength << "), exceeds the maximum number of bunch crossings per orbit (" << m_maxBunchCrossingPerOrbit << ").");
52  return StatusCode::FAILURE;
53  }
54 
55  // Normalise the pattern so that the non-zero elements average to 1.0
56  float nonZeroElementCount(static_cast<float>(std::count_if(pBegin, pEnd, IsNonZero)));
57  if(nonZeroElementCount<1.0)
58  {
59  ATH_MSG_ERROR("IntensityPattern has no non-zero elements!");
60  return StatusCode::FAILURE;
61  }
62  float elementSum(static_cast<float>(std::accumulate(pBegin, pEnd,0.0)));
63  float denominator(elementSum/nonZeroElementCount);
64 
65  // Normalise the pattern so that the highest element value is 1.0
66  float maxElement(*(std::max_element(pBegin, pEnd)));
67  float inv_maxElement = maxElement != 0 ? 1. / maxElement : 1;
68 
69  //copy normalized intensity pattern from the property, and match signal pattern if requested
70  delete [] m_intensityPattern;
71  m_intensityPattern = new double[m_ipLength];
72 
73  for (unsigned int i(0); i<m_ipLength; ++i)
74  {
75  if (rProp[i]<0.0)
76  {
77  ATH_MSG_ERROR("All IntensityPattern elements must be >=0. Please fix element #" << i );
78  return StatusCode::FAILURE;
79  }
80  m_intensityPattern[i] = rProp[i] * inv_maxElement;
81  }
82 
83  // Will be used to convert values in the m_intensityPattern
84  // from having max value 1.0 to having mean value 1.0
86 
87  //FIXME add a check that entry 0 is zero? In data, BCID=1 is always the first filled bunch.
88 
89  //get the signal pattern from the property
90  m_spLength = sProp.size();
91  delete [] m_signalPattern;
92  m_signalPattern = new bool[m_spLength];
93  bool isOk=false;
94  for (unsigned int i(0); i<m_spLength; ++i)
95  {
96  m_signalPattern[i] = (sProp[i]>0.0);
97  if(m_signalPattern[i]) { isOk=true; }
98  }
99  if(!isOk)
100  {
101  ATH_MSG_ERROR("SignalPattern MUST have at least one non-zero value in it.");
102  return StatusCode::FAILURE;
103  }
104 
105  //start the t0Offset and signalOffset at the LAST entry in the arrays, so that the first event is for the FIRST entry in the arrays
108 
109  return StatusCode::SUCCESS;
110 }
111 
112 void StepArrayBM::selectT0(unsigned int /*run*/, unsigned long long /*event*/)
113 {
114  //move to the next xing as dictated by the signalPattern, for each incremember, shift the t0Offset
115  do {
117  m_t0Offset = (unsigned int)((m_t0Offset+1) % m_ipLength);
118  } while(!m_signalPattern[m_signalOffset]);
119 
120 
121  //assert(m_intensityPattern[m_t0Offset % m_ipLength]>0.0); //commented out to allow events with no intensity
122 
123  ATH_MSG_DEBUG( "selectT0 offset for this event " << m_t0Offset );
124 }
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
StepArrayBM::initialize
virtual StatusCode initialize() override final
Definition: StepArrayBM.cxx:41
StepArrayBM::selectT0
virtual void selectT0(unsigned int run, unsigned long long event) override final
Definition: StepArrayBM.cxx:112
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
StepArrayBM::StepArrayBM
StepArrayBM(const std::string &name, ISvcLocator *svc)
Definition: StepArrayBM.cxx:12
StepArrayBM::m_intensityPatternProp
Gaudi::Property< std::vector< float > > m_intensityPatternProp
user-defined intensity pattern
Definition: StepArrayBM.h:62
UtilityFuncs.h
prototypes for utility POOL collection funcs
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
StepArrayBM.h
A IBeamIntensity service configured with an intensity array and an optional signal pattern array The ...
StepArrayBM::m_largestElementInPattern
float m_largestElementInPattern
The largest value in the pattern assuming that the pattern has mean value 1.0.
Definition: StepArrayBM.h:77
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
StepArrayBM::m_ipLength
unsigned int m_ipLength
length of the intensity pattern
Definition: StepArrayBM.h:66
StepArrayBM::m_t0Offset
Gaudi::Hive::ContextSpecificData< unsigned int > m_t0Offset
offset of the t0 wrto our intensity pattern
Definition: StepArrayBM.h:58
StepArrayBM::m_maxBunchCrossingPerOrbit
unsigned int m_maxBunchCrossingPerOrbit
max bunch crossings per orbit
Definition: StepArrayBM.h:56
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
ReadTripsProbsFromCool.denominator
denominator
Definition: ReadTripsProbsFromCool.py:96
StepArrayBM::m_signalPattern
bool * m_signalPattern
locally stored siganlPattern
Definition: StepArrayBM.h:72
StepArrayBM::m_signalPatternProp
Gaudi::Property< std::vector< float > > m_signalPatternProp
user-defined signal pattern - non zero numbers means "Do Signal"
Definition: StepArrayBM.h:64
StepArrayBM::m_intensityPattern
double * m_intensityPattern
normalized intensity pattern. C array to make clhep RandGeneral happy
Definition: StepArrayBM.h:70
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
StepArrayBM::~StepArrayBM
virtual ~StepArrayBM()
Definition: StepArrayBM.cxx:35
StepArrayBM::m_signalOffset
Gaudi::Hive::ContextSpecificData< unsigned int > m_signalOffset
offset of the current xing wrto the signal pattern
Definition: StepArrayBM.h:60
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
StepArrayBM::m_spLength
unsigned int m_spLength
length of the signal pattern
Definition: StepArrayBM.h:68