CMS 3D CMS Logo

CounterChecker.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * This is a part of the TOTEM offline software.
4  * Authors:
5  * Maciej Wróbel (wroblisko@gmail.com)
6  * Jan Kašpar (jan.kaspar@gmail.com)
7  *
8  ****************************************************************************/
9 
10 #ifndef EventFilter_CTPPSRawToDigi_CounterChecker
11 #define EventFilter_CTPPSRawToDigi_CounterChecker
12 
13 #include <map>
14 #include <string>
15 #include <vector>
16 #include <iostream>
17 
19 
21 
27 public:
28  typedef unsigned short word;
29 
30  typedef std::map<word, std::vector<TotemFramePosition> > CounterMap;
31 
33 
41  const std::string &_name = "",
42  unsigned int _min = 0,
43  double _fraction = 0.,
44  unsigned int _verbosity = 0)
45  : type(_type), name(_name), min(_min), fraction(_fraction), verbosity(_verbosity) {}
46 
49 
51  template <typename T>
52  void Analyze(T &status, bool error, std::ostream &es);
53 
54 private:
55  class Comparer {
56  public:
57  typedef unsigned short word;
58  bool operator()(const std::pair<word, std::vector<TotemFramePosition> > &a,
59  const std::pair<word, std::vector<TotemFramePosition> > &b) {
60  return a.second.size() < b.second.size();
61  }
62  };
63 
66 
69 
72 
74  unsigned int min;
75 
78  double fraction;
79 
81  unsigned int verbosity;
82 };
83 
84 template <typename T>
85 void CounterChecker::Analyze(T &status, bool error, std::ostream &es) {
86  word mostFrequentCounter = 0;
87  word mostFrequentSize = 0;
88  unsigned int totalFrames = 0;
89 
90  // finding the most frequent counter
91  for (CounterMap::iterator iter = relationMap.begin(); iter != relationMap.end(); iter++) {
92  unsigned int iterSize = iter->second.size();
93  totalFrames += iterSize;
94 
95  if (iterSize > mostFrequentSize) {
96  mostFrequentCounter = iter->first;
97  mostFrequentSize = iter->second.size();
98  }
99  }
100 
101  if (totalFrames < min) {
102  if (verbosity > 0)
103  es << "Too few frames to determine the most frequent " << name << " value.";
104 
105  return;
106  }
107 
108  // if there are too few frames with the most frequent value
109  if ((float)mostFrequentSize / (float)totalFrames < fraction) {
110  if (verbosity > 0)
111  es << "The most frequent " << name << " value is doubtful - variance is too high.";
112 
113  return;
114  }
115 
116  for (CounterMap::iterator iter = relationMap.begin(); iter != relationMap.end(); iter++) {
117  if (iter->first != mostFrequentCounter) {
118  for (std::vector<TotemFramePosition>::iterator fr = iter->second.begin(); fr != iter->second.end(); fr++) {
119  if (error) {
120  if (type == ECChecker)
121  status[*fr].status.setECProgressError();
122  if (type == BCChecker)
123  status[*fr].status.setBCProgressError();
124  }
125 
126  if (verbosity > 0)
127  es << "Frame at " << *fr << ": " << name << " number " << iter->first
128  << " is different from the most frequent one " << mostFrequentCounter << std::endl;
129  }
130  }
131  }
132 }
133 
134 #endif
unsigned int min
minimal required number of frames to search for the most frequent one
Class for finding the most popular both EC and BC counter, and filling the conversion status &#39;wrong E...
void Analyze(T &status, bool error, std::ostream &es)
summarizes and fill the status (wrong EC and BC progress error for some frames)
unsigned int verbosity
level of verbosity
std::string name
the name of this check, used in error messages
uint64_t word
unsigned short word
CounterChecker(CheckerType _type=CounterChecker::BCChecker, const std::string &_name="", unsigned int _min=0, double _fraction=0., unsigned int _verbosity=0)
double b
Definition: hdecay.h:118
void Fill(word counter, TotemFramePosition fr)
add new value to map, counter takes value of EC or BC number
double a
Definition: hdecay.h:119
CounterMap relationMap
counter value -> list of frames with this value
bool operator()(const std::pair< word, std::vector< TotemFramePosition > > &a, const std::pair< word, std::vector< TotemFramePosition > > &b)
long double T
CheckerType type
EC or BC counter checker.
std::map< word, std::vector< TotemFramePosition > > CounterMap