ATLAS Offline Software
BunchCrossingCondData.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2024 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 
93 std::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 
105 unsigned 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<0;++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<m_MAX_BCID-to;++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) {
145  index=m_MAX_BCID-1;
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) {
154  index=m_MAX_BCID-1;
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:
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:
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:
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 }
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:176
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:63
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:167
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:396
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:130
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:141
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:88
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:38
BunchCrossingCondData::countColliding
unsigned countColliding(int from, int to) const
Helper method to count colliding bunches in the range from-to.
Definition: BunchCrossingCondData.cxx:105
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:39
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:198
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:8
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:93
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:318
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