Belle II Software development
CountContainer Class Reference

a container for counting accepted and rejected stuff, just delivers some interfaces to make the code more readable More...

Classes

struct  AcceptRejectPair
 simple struct for counting accepted and rejected cases. More...
 

Public Types

typedef std::vector< int > Particles
 a vector containing IDs
 
typedef std::pair< bool, ParticlesKey
 key for the internal container of this map
 

Public Member Functions

 CountContainer ()
 constructor.
 
void clear ()
 clear container
 
unsigned int size ()
 size of container
 
bool IncreaseCounter (Key &aKey, bool accepted)
 accepts a key (first parameter) and if given key was accepted by the filter (second parameter)
 
AcceptRejectPair ReturnResult (const Key &givenKey)
 for given key, the function returns the result found.
 
AcceptRejectPair ReturnResult (const Particles &givenKey)
 for given key, the function returns the result found.
 
void PrintResults (const string &identifier="unknown")
 for easy printing of results collected so far
 

Static Public Member Functions

template<class ContainerType >
static void uniqueIdentifier (ContainerType &particles)
 cleans a container of double entries
 
static std::string key2str (const Key &aKey)
 small helper for easily printing vectors
 
static std::string key2str (const Key *aKey)
 small helper for easily printing vectors
 
template<class Type >
static std::string vec2str (const vector< Type > &vec)
 small helper for easily printing vectors
 

Protected Attributes

std::map< Key, AcceptRejectPairm_container
 collects the data
 

Detailed Description

a container for counting accepted and rejected stuff, just delivers some interfaces to make the code more readable

Definition at line 204 of file observers.cc.

Member Typedef Documentation

◆ Key

typedef std::pair< bool, Particles > Key

key for the internal container of this map

.first is a bool which is true, if combination was from the same particle which was primary .second vector of IDs (e.g. PDG or mcParticleIDs)

Definition at line 217 of file observers.cc.

◆ Particles

typedef std::vector<int> Particles

a vector containing IDs

Definition at line 209 of file observers.cc.

Constructor & Destructor Documentation

◆ CountContainer()

CountContainer ( )
inline

constructor.

Definition at line 206 of file observers.cc.

Member Function Documentation

◆ clear()

void clear ( )
inline

clear container

Definition at line 242 of file observers.cc.

242{ m_container.clear(); }
std::map< Key, AcceptRejectPair > m_container
collects the data
Definition: observers.cc:353

◆ IncreaseCounter()

bool IncreaseCounter ( Key aKey,
bool  accepted 
)
inline

accepts a key (first parameter) and if given key was accepted by the filter (second parameter)

Definition at line 259 of file observers.cc.

260 {
261 bool keyAlreadyExisted = true;
262 auto foundPos = m_container.find(aKey);
263 if (foundPos == m_container.end()) {
264 B2DEBUG(100, " the IDs " << key2str(aKey) << " collected haven't been found yet");
265 foundPos = m_container.insert({aKey, AcceptRejectPair() }).first;
266 keyAlreadyExisted = false;
267 } else { B2DEBUG(100, " the IDs " << key2str(aKey) << " collected were already there"); }
268
269 foundPos->second.Increase(accepted);
270
271 return keyAlreadyExisted;
272 }
static std::string key2str(const Key &aKey)
small helper for easily printing vectors
Definition: observers.cc:321

◆ key2str() [1/2]

static std::string key2str ( const Key aKey)
inlinestatic

small helper for easily printing vectors

Definition at line 321 of file observers.cc.

322 {
323 return key2str(&aKey);
324 }

◆ key2str() [2/2]

static std::string key2str ( const Key aKey)
inlinestatic

small helper for easily printing vectors

Definition at line 328 of file observers.cc.

329 {
330 string output;
331
332 if (aKey->first == true) { output += "GoodCombi: "; }
333 else { output += "BadCombi: "; }
334
335 output += vec2str(aKey->second);
336
337 return output;
338 }
static std::string vec2str(const vector< Type > &vec)
small helper for easily printing vectors
Definition: observers.cc:342

◆ PrintResults()

void PrintResults ( const string &  identifier = "unknown")
inline

for easy printing of results collected so far

Definition at line 306 of file observers.cc.

307 {
308 for (auto& entry : m_container) {
309 B2WARNING(" for " << identifier << "-combination: " <<
310 key2str(entry.first) <<
311 ", combi was accepted/rejected: " <<
312 entry.second.accept <<
313 "/" <<
314 entry.second.reject);
315 }
316 }

◆ ReturnResult() [1/2]

AcceptRejectPair ReturnResult ( const Key givenKey)
inline

for given key, the function returns the result found.

If key was not found in container, a AcceptRejectPair with 0, 0 is returned

Definition at line 277 of file observers.cc.

278 {
279
280 auto foundPos = m_container.find(givenKey);
281
282 if (foundPos == m_container.end()) {
283 return AcceptRejectPair();
284 }
285
286 return foundPos->second;
287 }

◆ ReturnResult() [2/2]

AcceptRejectPair ReturnResult ( const Particles givenKey)
inline

for given key, the function returns the result found.

If key was not found in container, a AcceptRejectPair with 0, 0 is returned

Definition at line 292 of file observers.cc.

293 {
294 for (const auto& aKey : m_container) {
295 B2DEBUG(100, "comparing given particles: " << vec2str(givenKey) << " with entry: " << vec2str(
296 aKey.first.second) << " with result " << (aKey.first.second == givenKey));
297 if (aKey.first.second == givenKey) { return aKey.second; }
298 }
299
300 return AcceptRejectPair();
301 }

◆ size()

unsigned int size ( )
inline

size of container

Definition at line 246 of file observers.cc.

246{ return m_container.size(); }

◆ uniqueIdentifier()

static void uniqueIdentifier ( ContainerType &  particles)
inlinestatic

cleans a container of double entries

Definition at line 250 of file observers.cc.

251 {
252 std::sort(particles.begin(), particles.end());
253 auto newEndIterator = std::unique(particles.begin(), particles.end());
254 particles.resize(std::distance(particles.begin(), newEndIterator));
255 }

◆ vec2str()

static std::string vec2str ( const vector< Type > &  vec)
inlinestatic

small helper for easily printing vectors

Definition at line 342 of file observers.cc.

343 {
344 string output;
345
346 for (const auto& entry : vec) {
347 output += " " + std::to_string(entry);
348 }
349
350 return output;
351 }

Member Data Documentation

◆ m_container

std::map< Key, AcceptRejectPair> m_container
protected

collects the data

Definition at line 353 of file observers.cc.


The documentation for this class was generated from the following file: