ATLAS Offline Software
Loading...
Searching...
No Matches
CombinatoricsOdometer.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Dear emacs, this is -*-c++-*-
6#ifndef PATCORE_COMBINATORICSODOMETER_H
7#define PATCORE_COMBINATORICSODOMETER_H
8
9/*****************************************************************************
10 * @Project: PATCore
11 *
12 * @class CombinatoricsOdometer
13 *
14 * @author Steven Sekula <Stephen.Jacob.Sekula@cernSPAMNOT.ch>
15 * @author Karsten Koeneke <karsten.koeneke@cernSPAMNOT.ch>
16 *
17 * @date January 2010
18 *
19 * @brief Helper class for particle combinatorics of several lists.
20 *
21Based 100% on (i.e., this is pretty much a copy with the option to remove
22the original from its current place):
23NAME: EVComboHelper.h
24PACKAGE: offline/PhysicsAnalysis/EventViewBuilder/EventViewCombiners/
25
26AUTHORS: Akira Shibata (ashibata@cern.ch)
27CREATED: Feb 2006
28
29Methods used in combiner tools. The problem is to generate unique
30set of N indeces from M containers in a general way. For eg, suppose
31there are three containers each containing 3, 4, 5 elements respectively:
32one way to solve it is to construct an "odometer" each digit going up
33to the number of elements. Of cource, uniqueness of each combinations
34should be ensured. The problem is that some digits of the odometer
35may come from the same container. For the problem to be solved by odometer
36approach (is a useful approach to be able to specify a combination by
37["jet" "jet" "lepton"] etc), digits that come from the same container
38always have smaller number on the left.
39
40eg. if the combination is ["jet", "jet", "lepton", "bjet", "lepton"]
41(problem is simplified if repeated labels always come together but
42this cannot be assumed)
43and "jet" container has 4 elements, "lepton" 2, and "bjet" 2, then
4400000 is not acceptable since two jets and leptons chosen are the same.
4501001 is the smallest acceptable number.
4601101 is not acceptable since leptons are the same
4701100 is not acceptable since the lepton digits 21 an 12 are indifferent
48 in terms of combination and 01102 has already been counted.
4901102 won't be counted since there's only two leptons.
50
51********************************************************************/
52
53#include <map>
54#include <set>
55#include <string>
56#include <iostream>
57#include <vector>
59
60//flexible digit class, maximum number as specified, knows about
61//another digit typicaly the next digit
63{
64public:
65 FlexDigit(int , FlexDigit* =0);
67 void setNext( FlexDigit* next );
68 FlexDigit* next();
69 int digit() const;
70 void setDigit( int digit );
71 bool isAtMax();
72 bool isFirstDigit();
73 FlexDigit operator++( int );
74
75private:
79};
80
83inline int FlexDigit::digit() const { return m_digit; }
84inline void FlexDigit::setDigit( int digit ){ m_digit = digit; }
85inline bool FlexDigit::isAtMax(){ return m_digit >= m_digitMax; }
86inline bool FlexDigit::isFirstDigit(){ return !m_nextDigit; }
87
88//vector of pointers to flexible digits.
89class FlexDigits : public DataVector<FlexDigit>
90{
91public:
92 FlexDigits(std::vector<std::string>& labels, std::map<std::string, int>& digitMax);
93 FlexDigits(int numDigits, int digitMax);
94 virtual ~FlexDigits();
95 virtual bool increment();
96 virtual void push_back(FlexDigit*);
97 virtual void print();
98 bool isZero();
99 virtual FlexDigits& operator++( int );
100 bool hasStarted();
101 void setStarted();
102
103private:
105};
106
107inline bool FlexDigits::hasStarted(){ return m_started; }
108inline void FlexDigits::setStarted(){ m_started = true; }
109
110
111class OdoMeter : public FlexDigits
112{
113public:
114 OdoMeter(std::vector<std::string>& labels, std::map<std::string, int>& numObj);
115 OdoMeter(int numDigits, int digitMax);
116 virtual ~OdoMeter();
117 std::vector<int> getVector();
118 std::pair<int,int> getPair();
119 virtual bool increment();
120 bool nextPair();
121 bool isUnique(bool doCheck);
122 bool hasOnlySingleEntry(bool doCheck);
123private:
125 bool m_onlySingleEntry; //allow two same ones from the same container?
128 std::map<std::string, std::set<int> > m_digitAssoc;
129 std::set<std::string> m_labels;
130};
131
132
133class PairMeter : public OdoMeter
134{
135public:
136 PairMeter(int numDigits);
137 virtual ~PairMeter();
138 virtual bool increment();
139private:
140};
141
142#endif
An STL vector of pointers that by default owns its pointed-to elements.
DataVector(SG::OwnershipPolicy ownPolicy=SG::OWN_ELEMENTS, SG::IndexTrackingPolicy trackIndices=SG::DEFAULT_TRACK_INDICES)
FlexDigit(int, FlexDigit *=0)
void setDigit(int digit)
FlexDigit * m_nextDigit
FlexDigit operator++(int)
void setNext(FlexDigit *next)
int digit() const
FlexDigit * next()
virtual bool increment()
virtual void print()
FlexDigits(std::vector< std::string > &labels, std::map< std::string, int > &digitMax)
virtual void push_back(FlexDigit *)
virtual FlexDigits & operator++(int)
bool isUnique(bool doCheck)
OdoMeter * m_pairMeter
std::vector< int > getVector()
std::pair< int, int > getPair()
std::set< std::string > m_labels
std::map< std::string, std::set< int > > m_digitAssoc
bool hasOnlySingleEntry(bool doCheck)
virtual bool increment()
OdoMeter(std::vector< std::string > &labels, std::map< std::string, int > &numObj)
PairMeter(int numDigits)
virtual bool increment()