ATLAS Offline Software
BunchCrossingCondData.cxx
Go to the documentation of this file.
3 #include <algorithm>
4 
6 
7  const int bcidi=static_cast<int>(bcid);
8  const auto it=std::find_if(m_trains.begin(),m_trains.end(),[&bcidi](const bunchTrain_t& bt){return (bt.m_first<=bcidi && bt.m_last>=bcidi);});
9 
10  if (it==m_trains.end()) {
11  return nullptr;
12  }
13  else {
14  return &(*it);
15  }
16 
17  /*
18  auto& it=std::lower_bound(m_trains.begin(),m_trains.end(),bunchTrain_t(bcid,0,0));
19  if (it==m_trains.end() || it==m_trains.begin()) return nullptr;
20 
21  //it points now tho the train that starts after the bcid we are looking for
22  //if the bcid is in a train, it must be the train before.
23  it--;
24  if (it->m_first>=bcid && it->m_last<=bcid) {
25  return &(*it);
26  }
27  else {
28  return nullptr;
29  }
30  */
31 
32 
33 }
34 
36  const BunchDistanceType type ) const {
37 
38  const bunchTrain_t* bt=findTrain(bcid);
39  if (!bt) {
40  return -1;
41  }
42 
43  const int dist=bcid-bt->m_first;
44 
45  switch( type ) {
46  case NanoSec:
47  return dist*m_BUNCH_SPACING;
48  break;
49  case BunchCrossings:
50  return dist;
51  case FilledBunches:
52  return countColliding(bt->m_first,bt->m_last);
53  default:
54  MsgStream msg(Athena::getMessageSvc(),"BunchCrossingCondData::distanceFromFront");
55  msg << MSG::ERROR << "BunchDistanceType not understood!" << endmsg;
56  return -1;
57  }//end switch
58 }
59 
61  const BunchDistanceType type ) const {
62 
63  const bunchTrain_t* bt=findTrain(bcid);
64  if (!bt) {
65  return -1;
66  }
67 
68  const int dist=bt->m_last-bcid;
69 
70  switch( type ) {
71  case NanoSec:
72  return dist*m_BUNCH_SPACING;
73  break;
74  case BunchCrossings:
75  return dist;
76  case FilledBunches:
77  return countColliding(bt->m_first,bt->m_last);
78  default:
79  MsgStream msg(Athena::getMessageSvc(),"BunchCrossingCondData::distanceFromTail");
80  msg << MSG::ERROR << "BunchDistanceType not understood!" << endmsg;
81  return -1;
82  }//end switch
83 }
84 
86  return ((m_beam1 | m_beam2) & ~m_luminous).count();
87 }
88 
89 
90 std::pair<unsigned,unsigned> BunchCrossingCondData::bunchTrainPopulation(const bcid_type bcid) const {
91 
92  const bunchTrain_t* bt=findTrain(bcid);
93  if (!bt) {
94  return std::pair<unsigned,unsigned>(0,0);
95  }
96  else {
97  return std::pair<unsigned,unsigned>(bt->m_nColl,(bt->m_last-bt->m_first));
98  }
99 }
100 
101 
102 unsigned BunchCrossingCondData::countColliding(int from, int to) const {
103  unsigned ncoll=0;
104 
105  if (from<0) {
106  //wrap-around ...
107  for (int idx=m_MAX_BCID-from;idx<0;++idx) {
108  if (m_luminous.test(idx)) ++ncoll;
109  }
110  from=0;
111  }
112 
113  if (to>m_MAX_BCID) {
114  for (int idx=0;idx<m_MAX_BCID-to;++idx) {
115  if (m_luminous.test(idx)) ++ncoll;
116  }
117  to=m_MAX_BCID;
118  }
119 
120  for (int idx=from;idx<to;++idx) {
121  if (m_luminous.test(idx)) ++ncoll;
122  }
123  return ncoll;
124 }
125 
126 
128  BunchDistanceType type) const {
129 
130  const bunchTrain_t* bt=findTrain(bcid);
131  if (bt==nullptr) {
132  return -1;
133  }
134 
135  return gapBeforeBunch(bt->m_first,type);
136 }
137 
139  BunchDistanceType type) const {
140  int index=bcid-1;
141  if (index<0) {
142  index=m_MAX_BCID-1;
143  }
144 
145  int result=0;
146 
147  while (!m_luminous.test(index) && result<m_MAX_BCID) {
148  result++;
149  index--;
150  if (index<0) {
151  index=m_MAX_BCID-1;
152  }
153  }
154 
155  if (type==NanoSec) {
157  }
158 
159  return result;
160 }
161 
162 
163 
165  BunchDistanceType type) const {
166  const bunchTrain_t* bt=findTrain(bcid);
167  if (bt==nullptr) {
168  return -1;
169  }
170  return gapAfterBunch(bt->m_last,type);
171 }
172 
174  BunchDistanceType type) const {
175  int index=bcid+1;
176  if (index>=m_MAX_BCID) {
177  index=0;
178  }
179  int result=0;
180  while (!m_luminous.test(index) && result<m_MAX_BCID) {
181  result++;
182  index++;
183  if (index>=m_MAX_BCID) {
184  index=0;
185  }
186  }
187 
188  if (type==NanoSec) {
190  }
191 
192  return result;
193 }
194 
196  // First the obvious check:
197  if (!isFilled(bcid))
198  {
199  // Check if it's an unpaired bunch:
200  if (isUnpaired(bcid))
201  {
202  return Unpaired;
203  }
204  // If the previous bunch crossing is the tail of a bunch train:
206  {
207  return FirstEmpty;
208  }
209  // Check if it's in the middle of a bunch train:
210  if (findTrain(bcid) != nullptr) {
211  return MiddleEmpty;
212  }
213  // If none of the above are true, it has to be a "simple" empty bunch:
214  return Empty;
215  }
216 
217  // Now we know that the bunch has to be a filled one...
218 
219  // If it's not in a train, it has to be a single filled bunch:
220  if (!isInTrain(bcid))
221  return Single;
222 
223  // Let's check if it is close to the front of a bunch train:
225  if ((distance >= 0) && (distance <= m_headTailLength))
226  {
227  return Front;
228  }
229  // Now let's check if it's close to the tail of a bunch train:
231  if ((distance >= 0) && (distance <= m_headTailLength))
232  {
233  return Tail;
234  }
235 
236  // If none of the above are true, it has to be in the middle of a train:
237  return Middle;
238 }
BunchCrossingCondData::gapAfterBunch
int gapAfterBunch(bcid_type bcid=0, BunchDistanceType type=NanoSec) const
Get the distance of the specified bunch crossing to the next filled bunch.
Definition: BunchCrossingCondData.cxx:173
BunchCrossingCondData::distanceFromTail
int distanceFromTail(const bcid_type bcid, const BunchDistanceType type=NanoSec) const
The distance of the specific bunch crossing from the tail of the train.
Definition: BunchCrossingCondData.cxx:60
BunchCrossingCondData::m_BUNCH_SPACING
static constexpr int m_BUNCH_SPACING
Definition: BunchCrossingCondData.h:29
BunchCrossingCondData::m_headTailLength
static const int m_headTailLength
Definition: BunchCrossingCondData.h:313
BunchCrossingCondData::isUnpaired
bool isUnpaired(const bcid_type bcid) const
Function deciding if a given bunch crossing has an unpaired bunch.
Definition: BunchCrossingCondData.h:358
get_generator_info.result
result
Definition: get_generator_info.py:21
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
BunchCrossingCondData::gapAfterTrain
int gapAfterTrain(bcid_type bcid=0, BunchDistanceType type=NanoSec) const
Gap after the train this BCID is in.
Definition: BunchCrossingCondData.cxx:164
BunchCrossingCondData::NanoSec
@ NanoSec
Distance in nanoseconds.
Definition: BunchCrossingCondData.h:131
BunchCrossingCondData::BunchCrossingType
BunchCrossingType
Enumeration type for a given bunch crossing.
Definition: BunchCrossingCondData.h:101
index
Definition: index.py:1
BunchCrossingCondData::bunchTrain_t::m_nColl
unsigned m_nColl
Last BCID of this train.
Definition: BunchCrossingCondData.h:320
skel.it
it
Definition: skel.GENtoEVGEN.py:423
BunchCrossingCondData::m_trains
std::vector< bunchTrain_t > m_trains
Definition: BunchCrossingCondData.h:323
BunchCrossingCondData::gapBeforeTrain
int gapBeforeTrain(bcid_type bcid=0, BunchDistanceType type=NanoSec) const
Gap before the train this BCID is in.
Definition: BunchCrossingCondData.cxx:127
BunchCrossingCondData::bcid_type
unsigned int bcid_type
Definition: BunchCrossingCondData.h:27
BunchCrossingCondData::m_beam1
std::bitset< m_MAX_BCID > m_beam1
Definition: BunchCrossingCondData.h:310
BunchCrossingCondData::m_luminous
std::bitset< m_MAX_BCID > m_luminous
Definition: BunchCrossingCondData.h:312
BunchCrossingCondData::gapBeforeBunch
int gapBeforeBunch(bcid_type bcid=0, BunchDistanceType type=NanoSec) const
Get the distance of the specified bunch crossing to the preceeding filled bunch.
Definition: BunchCrossingCondData.cxx:138
BunchCrossingCondData::BunchDistanceType
BunchDistanceType
Enumeration specifying the units in which to expect the bunch distance type.
Definition: BunchCrossingCondData.h:130
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
BunchCrossingCondData::FirstEmpty
@ FirstEmpty
The first empty bunch after a train.
Definition: BunchCrossingCondData.h:103
BunchCrossingCondData::Tail
@ Tail
The BCID belongs to the last few bunces in a train.
Definition: BunchCrossingCondData.h:108
BunchCrossingCondData::m_MAX_BCID
static constexpr int m_MAX_BCID
Definition: BunchCrossingCondData.h:28
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
BunchCrossingCondData::BunchCrossings
@ BunchCrossings
Distance in units of 25 nanoseconds.
Definition: BunchCrossingCondData.h:132
BunchCrossingCondData::bunchTrain_t::m_last
int m_last
First BCID of this train.
Definition: BunchCrossingCondData.h:319
BunchCrossingCondData::MiddleEmpty
@ MiddleEmpty
An empty BCID in the middle of a train.
Definition: BunchCrossingCondData.h:104
BunchCrossingCondData::numberOfUnpairedBunches
unsigned int numberOfUnpairedBunches() const
Get the number of unpaired bunches in the current configuration.
Definition: BunchCrossingCondData.cxx:85
BunchCrossingCondData::distanceFromFront
int distanceFromFront(const bcid_type bcid, const BunchDistanceType type=NanoSec) const
The distance of the specific bunch crossing from the front of the train.
Definition: BunchCrossingCondData.cxx:35
BunchCrossingCondData::countColliding
unsigned countColliding(int from, int to) const
Helper method to count colliding bunches in the range from-to.
Definition: BunchCrossingCondData.cxx:102
BunchCrossingCondData::FilledBunches
@ FilledBunches
Distance in units of filled bunches (depends on filling scheme)
Definition: BunchCrossingCondData.h:134
xAOD::bcid
setEventNumber setTimeStamp bcid
Definition: EventInfo_v1.cxx:133
BunchCrossingCondData::Front
@ Front
The BCID belongs to the first few bunches in a train.
Definition: BunchCrossingCondData.h:106
CxxUtils::to
CONT to(RANGE &&r)
Definition: ranges.h:32
BunchCrossingCondData::isInTrain
bool isInTrain(const bcid_type bcid) const
Function deciding if a given bunch crossing is in a filled train.
Definition: BunchCrossingCondData.h:376
BunchCrossingCondData::Single
@ Single
This is a filled, single bunch (not in a train)
Definition: BunchCrossingCondData.h:105
BunchCrossingCondData::Unpaired
@ Unpaired
This is an unpaired bunch (either beam1 or beam2)
Definition: BunchCrossingCondData.h:109
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
BunchCrossingCondData::bcType
BunchCrossingType bcType(const bcid_type bcid) const
Convenience function for the type of the specific bunch crossing.
Definition: BunchCrossingCondData.cxx:195
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
BunchCrossingCondData::findTrain
const bunchTrain_t * findTrain(const bcid_type bcid) const
Helper method to find the train of a bcid (nullptr if bcd is not in a train)
Definition: BunchCrossingCondData.cxx:5
BunchCrossingCondData.h
Replaces the BunchCrossing AlgTool used in run1/2.
BunchCrossingCondData::bunchTrainPopulation
std::pair< unsigned, unsigned > bunchTrainPopulation(const bcid_type bcid) const
Get colliding and total bcids in a train.
Definition: BunchCrossingCondData.cxx:90
BunchCrossingCondData::m_beam2
std::bitset< m_MAX_BCID > m_beam2
Definition: BunchCrossingCondData.h:311
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
BunchCrossingCondData::Middle
@ Middle
The BCID belongs to the middle bunches in a train.
Definition: BunchCrossingCondData.h:107
BunchCrossingCondData::bunchTrain_t::m_first
int m_first
Definition: BunchCrossingCondData.h:317
BunchCrossingCondData::isFilled
bool isFilled(const bcid_type bcid) const
The simplest query: Is the bunch crossing filled or not?
Definition: BunchCrossingCondData.h:339
BunchCrossingCondData::Empty
@ Empty
An empty bunch far away from filled bunches.
Definition: BunchCrossingCondData.h:102
BunchCrossingCondData::bunchTrain_t
Definition: BunchCrossingCondData.h:315