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 
26 class CounterChecker {
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
counter
Definition: counter.py:1
CounterChecker::word
unsigned short word
Definition: CounterChecker.h:33
mps_update.status
status
Definition: mps_update.py:68
CounterChecker::name
std::string name
the name of this check, used in error messages
Definition: CounterChecker.h:76
CounterChecker::min
unsigned int min
minimal required number of frames to search for the most frequent one
Definition: CounterChecker.h:79
relativeConstraints.error
error
Definition: relativeConstraints.py:53
CounterChecker::type
CheckerType type
EC or BC counter checker.
Definition: CounterChecker.h:73
CounterChecker::CheckerType
CheckerType
Definition: CounterChecker.h:37
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
CounterChecker
Class for finding the most popular both EC and BC counter, and filling the conversion status 'wrong E...
Definition: CounterChecker.h:25
CounterChecker::relationMap
CounterMap relationMap
counter value -> list of frames with this value
Definition: CounterChecker.h:70
CounterChecker::verbosity
unsigned int verbosity
level of verbosity
Definition: CounterChecker.h:86
b
double b
Definition: hdecay.h:118
TotemVFATStatus.h
CounterChecker::BCChecker
Definition: CounterChecker.h:37
CounterChecker::CounterMap
std::map< word, std::vector< TotemFramePosition > > CounterMap
Definition: CounterChecker.h:35
CounterChecker::CounterChecker
CounterChecker(CheckerType _type=CounterChecker::BCChecker, const std::string &_name="", unsigned int _min=0, double _fraction=0., unsigned int _verbosity=0)
Definition: CounterChecker.h:45
a
double a
Definition: hdecay.h:119
TotemFramePosition
Definition: TotemFramePosition.h:31
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
CounterChecker::ECChecker
Definition: CounterChecker.h:37
TotemFramePosition.h
CounterChecker::Comparer::operator()
bool operator()(const std::pair< word, std::vector< TotemFramePosition > > &a, const std::pair< word, std::vector< TotemFramePosition > > &b)
Definition: CounterChecker.h:63
CounterChecker::fraction
double fraction
Definition: CounterChecker.h:83
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
T
long double T
Definition: Basic3DVectorLD.h:48
CounterChecker::Analyze
void Analyze(T &status, bool error, std::ostream &es)
summarizes and fill the status (wrong EC and BC progress error for some frames)
Definition: CounterChecker.h:84
CounterChecker::Fill
void Fill(word counter, TotemFramePosition fr)
add new value to map, counter takes value of EC or BC number
Definition: CounterChecker.cc:14
CounterChecker::Comparer::word
unsigned short word
Definition: CounterChecker.h:62