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