ATLAS Offline Software
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  *
21 Based 100% on (i.e., this is pretty much a copy with the option to remove
22 the original from its current place):
23 NAME: EVComboHelper.h
24 PACKAGE: offline/PhysicsAnalysis/EventViewBuilder/EventViewCombiners/
25 
26 AUTHORS: Akira Shibata (ashibata@cern.ch)
27 CREATED: Feb 2006
28 
29 Methods used in combiner tools. The problem is to generate unique
30 set of N indeces from M containers in a general way. For eg, suppose
31 there are three containers each containing 3, 4, 5 elements respectively:
32 one way to solve it is to construct an "odometer" each digit going up
33 to the number of elements. Of cource, uniqueness of each combinations
34 should be ensured. The problem is that some digits of the odometer
35 may come from the same container. For the problem to be solved by odometer
36 approach (is a useful approach to be able to specify a combination by
37 ["jet" "jet" "lepton"] etc), digits that come from the same container
38 always have smaller number on the left.
39 
40 eg. if the combination is ["jet", "jet", "lepton", "bjet", "lepton"]
41 (problem is simplified if repeated labels always come together but
42 this cannot be assumed)
43 and "jet" container has 4 elements, "lepton" 2, and "bjet" 2, then
44 00000 is not acceptable since two jets and leptons chosen are the same.
45 01001 is the smallest acceptable number.
46 01101 is not acceptable since leptons are the same
47 01100 is not acceptable since the lepton digits 21 an 12 are indifferent
48  in terms of combination and 01102 has already been counted.
49 01102 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
62 class FlexDigit
63 {
64 public:
65  FlexDigit(int , FlexDigit* =0);
66  ~FlexDigit(){};
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 
75 private:
76  int m_digit;
77  int m_digitMax;
79 };
80 
83 inline int FlexDigit::digit() const { return m_digit; }
84 inline void FlexDigit::setDigit( int digit ){ m_digit = digit; }
85 inline bool FlexDigit::isAtMax(){ return m_digit >= m_digitMax; }
86 inline bool FlexDigit::isFirstDigit(){ return !m_nextDigit; }
87 
88 //vector of pointers to flexible digits.
89 class FlexDigits : public DataVector<FlexDigit>
90 {
91 public:
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 
103 private:
104  bool m_started;
105 };
106 
107 inline bool FlexDigits::hasStarted(){ return m_started; }
108 inline void FlexDigits::setStarted(){ m_started = true; }
109 
110 
111 class OdoMeter : public FlexDigits
112 {
113 public:
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);
123 private:
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 
133 class PairMeter : public OdoMeter
134 {
135 public:
136  PairMeter(int numDigits);
137  virtual ~PairMeter();
138  virtual bool increment();
139 private:
140 };
141 
142 #endif
FlexDigit::m_nextDigit
FlexDigit * m_nextDigit
Definition: CombinatoricsOdometer.h:120
FlexDigit::digit
int digit() const
Definition: CombinatoricsOdometer.h:83
OdoMeter::m_digitAssoc
std::map< std::string, std::set< int > > m_digitAssoc
Definition: CombinatoricsOdometer.h:128
FlexDigit::~FlexDigit
~FlexDigit()
Definition: CombinatoricsOdometer.h:108
OdoMeter::m_onlyUnique
bool m_onlyUnique
Definition: CombinatoricsOdometer.h:124
FlexDigits::increment
virtual bool increment()
Definition: CombinatoricsOdometer.cxx:94
FlexDigit::FlexDigit
FlexDigit(int, FlexDigit *=0)
Definition: CombinatoricsOdometer.cxx:27
FlexDigits::print
virtual void print()
Definition: CombinatoricsOdometer.cxx:110
FlexDigits::hasStarted
bool hasStarted()
Definition: CombinatoricsOdometer.h:107
OdoMeter::increment
virtual bool increment()
Definition: CombinatoricsOdometer.cxx:242
FlexDigits::~FlexDigits
virtual ~FlexDigits()
Definition: CombinatoricsOdometer.cxx:77
OdoMeter::getPair
std::pair< int, int > getPair()
Definition: CombinatoricsOdometer.cxx:307
checkRpcDigits.digit
digit
Definition: checkRpcDigits.py:186
FlexDigits
Definition: CombinatoricsOdometer.h:90
OdoMeter::isUnique
bool isUnique(bool doCheck)
Definition: CombinatoricsOdometer.cxx:191
FlexDigit::setNext
void setNext(FlexDigit *next)
Definition: CombinatoricsOdometer.h:81
beamspotnt.labels
list labels
Definition: bin/beamspotnt.py:1447
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
FlexDigit
Definition: CombinatoricsOdometer.h:63
OdoMeter::OdoMeter
OdoMeter(std::vector< std::string > &labels, std::map< std::string, int > &numObj)
Definition: CombinatoricsOdometer.cxx:147
PairMeter::PairMeter
PairMeter(int numDigits)
Definition: CombinatoricsOdometer.cxx:321
FlexDigits::FlexDigits
FlexDigits(std::vector< std::string > &labels, std::map< std::string, int > &digitMax)
Definition: CombinatoricsOdometer.cxx:51
OdoMeter::hasOnlySingleEntry
bool hasOnlySingleEntry(bool doCheck)
Definition: CombinatoricsOdometer.cxx:218
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
OdoMeter::m_labels
std::set< std::string > m_labels
Definition: CombinatoricsOdometer.h:129
FlexDigits::operator++
virtual FlexDigits & operator++(int)
Definition: CombinatoricsOdometer.cxx:134
OdoMeter::nextPair
bool nextPair()
Definition: CombinatoricsOdometer.cxx:288
PairMeter::~PairMeter
virtual ~PairMeter()
Definition: CombinatoricsOdometer.cxx:327
FlexDigit::m_digitMax
int m_digitMax
Definition: CombinatoricsOdometer.h:119
FlexDigit::next
FlexDigit * next()
Definition: CombinatoricsOdometer.h:82
FlexDigits::setStarted
void setStarted()
Definition: CombinatoricsOdometer.h:108
FlexDigit::isAtMax
bool isAtMax()
Definition: CombinatoricsOdometer.h:85
FlexDigits::push_back
virtual void push_back(FlexDigit *)
Definition: CombinatoricsOdometer.cxx:84
FlexDigit::isFirstDigit
bool isFirstDigit()
Definition: CombinatoricsOdometer.h:86
FlexDigit::setDigit
void setDigit(int digit)
Definition: CombinatoricsOdometer.h:84
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
OdoMeter::m_onlySingleEntry
bool m_onlySingleEntry
Definition: CombinatoricsOdometer.h:125
FlexDigits::m_started
bool m_started
Definition: CombinatoricsOdometer.h:104
PairMeter::increment
virtual bool increment()
Definition: CombinatoricsOdometer.cxx:332
FlexDigits::isZero
bool isZero()
Definition: CombinatoricsOdometer.cxx:122
OdoMeter::m_pairMeter
OdoMeter * m_pairMeter
Definition: CombinatoricsOdometer.h:127
OdoMeter::m_numLabels
int m_numLabels
Definition: CombinatoricsOdometer.h:126
FlexDigit::m_digit
int m_digit
Definition: CombinatoricsOdometer.h:118
FlexDigit::operator++
FlexDigit operator++(int)
Definition: CombinatoricsOdometer.cxx:35
OdoMeter::getVector
std::vector< int > getVector()
Definition: CombinatoricsOdometer.cxx:276
OdoMeter::~OdoMeter
virtual ~OdoMeter()
Definition: CombinatoricsOdometer.cxx:181
PairMeter
Definition: CombinatoricsOdometer.h:134
OdoMeter
Definition: CombinatoricsOdometer.h:112