ATLAS Offline Software
SelectedParticles.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <sstream>
8 
9 using namespace std;
10 
11 SelectedParticles::SelectedParticles(const vector<unsigned>& indices):m_bits(){
12  int nind=indices.size();
13  this->SetMaxBits(nind);
14  for(int i=0;i<nind;++i){
15  this->SetBit(indices[i],true);
16  }
17 }
18 
19 void SelectedParticles::SetBit(unsigned i, bool good){
20  unsigned nwords=m_bits.size();
21  unsigned iword=i/32;
22 
23  if(iword+1>nwords){
24  for(unsigned iw=nwords; iw<iword+1; ++iw){
25  unsigned temp=0;
26  m_bits.push_back(temp);
27  }
28  }
29 
30  if(good==false) return;
31 
32  unsigned bitnum = i % 32 ;
33  unsigned temp = 1 << bitnum;
34  m_bits[iword] |= temp;
35 
36  return;
37 }
38 
39 void SelectedParticles::SetMaxBits(unsigned maxbits)
40 {
41  unsigned nwords=maxbits/32;
42  for(unsigned iw=0; iw<nwords+1; ++iw){
43  unsigned temp=0;
44  m_bits.push_back(temp);
45  }
46 }
47 
48 
50 {
51  stringstream os;
52  unsigned c;
53  // Invariant: displayed j 32-bit ints so far
54  unsigned nwords=m_bits.size();
55  vector<unsigned>::const_iterator itb=m_bits.begin();
56  int j=0;
57  for (; itb != m_bits.end(); ++itb){
58  // display mask will be a single 1 at the most significant bit
59  unsigned displayMask = 1u << 31;
60  // need to display the words in reverse order
61  int temp = nwords - j - 1;
62  ++j;
63  // Invariant: displayed c bits in the unsigned int
64  // displayMask has shifted its bits c places
65  for (c = 0; c != 32; c++ ) {
66  //if the current most significant bit in value temp is a 1
67  // display it if not display zero
68  os << (m_bits[temp] & displayMask ? '1' : '0');
69  // shift the displayMask one bit, so there is a new
70  // bit to check with value
71  displayMask >>= 1;
72 
73  // group display by bytes
74  if (c % 8 == 7 )
75  os << ' ';
76  }
77  // a new line for each 32-bit line
78  os << std::endl;
79  }
80  os << std::endl;
81  return os.str();
82 }
83 
84 bool SelectedParticles::isGood(unsigned ipart) const
85 {
86 
87  unsigned c;
88  unsigned nwords=m_bits.size();
89  vector<unsigned>::const_iterator itb=m_bits.begin();
90  unsigned j=ipart/32;
91  if(j>nwords-1) return false; // this should probably be an abort
92  for (; itb != m_bits.end(); ++itb){
93  // display mask will be a single 1 at the most significant bit
94  unsigned displayMask = 1;
95 
96  // Invariant: displayed c bits in the unsigned int
97  // displayMask has shifted its bits c places
98  for (c = 0; c != 32; c++ ) {
99  //if the current most significant bit in value temp is a 1
100  // display it if not display zero
101  if (m_bits[j] & displayMask) {
102  if(c==ipart) return true;
103  }
104  // shift the displayMask one bit, so there is a new
105  // bit to check with value
106  displayMask <<= 1;
107  }
108  }
109  return false;
110 }
111 
113 {
114  unsigned nwords=m_bits.size();
115  if(nwords==0) return 0;
116  vector<unsigned> goodparts;
117  goodParticles(goodparts);
118  return goodparts.size();
119 }
120 
121 void SelectedParticles::goodParticles(std::vector<unsigned>& goodparts ) const
122 {
123  unsigned nbits=m_bits.size()*32;
124  for(unsigned ibit=0; ibit<nbits; ++ibit) {
125  if(isGood(ibit)) goodparts.push_back(ibit);
126  }
127  return;
128 }
129 
temp
Definition: JetEventDict.h:21
SelectedParticles::SetBit
void SetBit(unsigned i, bool good=true)
Definition: SelectedParticles.cxx:19
SelectedParticles::SetMaxBits
void SetMaxBits(unsigned maxbits)
Definition: SelectedParticles.cxx:39
Trk::indices
std::pair< long int, long int > indices
Definition: AlSymMatBase.h:24
SelectedParticles.h
SelectedParticles::isGood
bool isGood(unsigned i) const
Definition: SelectedParticles.cxx:84
SelectedParticles::goodParticles
void goodParticles(std::vector< unsigned > &goodparts) const
Definition: SelectedParticles.cxx:121
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
lumiFormat.i
int i
Definition: lumiFormat.py:85
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
SelectedParticles::SelectedParticles
SelectedParticles()
Definition: SelectedParticles.h:58
SelectedParticles::m_bits
std::vector< unsigned > m_bits
Definition: SelectedParticles.h:78
ReadBchFromCool.good
good
Definition: ReadBchFromCool.py:433
SelectedParticles::displayBits
std::string displayBits() const
Definition: SelectedParticles.cxx:49
SelectedParticles::numGood
unsigned numGood() const
Definition: SelectedParticles.cxx:112
python.compressB64.c
def c
Definition: compressB64.py:93