test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
22 //----------------------------------------------------------------------------------------------------
23 
29 {
30  public:
31  typedef unsigned short word;
32 
33  typedef std::map<word, std::vector<TotemFramePosition> > CounterMap;
34 
36 
44  unsigned int _min=0, double _fraction=0., unsigned int _verbosity=0) : type(_type),
45  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  {
57  public:
58  typedef unsigned short word;
59  bool operator()(const std::pair<word, std::vector<TotemFramePosition> > &a, const std::pair<word, std::vector<TotemFramePosition> > &b)
60  {
61  return a.second.size() < b.second.size();
62  }
63  };
64 
67 
70 
73 
75  unsigned int min;
76 
79  double fraction;
80 
82  unsigned int verbosity;
83 };
84 
85 //-------------------------------------------------------------------------------------------------
86 
87 template<typename T>
88 void CounterChecker::Analyze(T &status, bool error, std::ostream &es)
89 {
90  word mostFrequentCounter = 0;
91  word mostFrequentSize = 0;
92  unsigned int totalFrames = 0;
93 
94  // finding the most frequent counter
95  for (CounterMap::iterator iter = relationMap.begin(); iter != relationMap.end(); iter++)
96  {
97  unsigned int iterSize = iter->second.size();
98  totalFrames += iterSize;
99 
100  if (iterSize > mostFrequentSize)
101  {
102  mostFrequentCounter = iter->first;
103  mostFrequentSize = iter->second.size();
104  }
105  }
106 
107  if (totalFrames < min)
108  {
109  if (verbosity > 0)
110  es << "Too few frames to determine the most frequent " << name << " value.";
111 
112  return;
113  }
114 
115  // if there are too few frames with the most frequent value
116  if ((float)mostFrequentSize/(float)totalFrames < fraction)
117  {
118  if (verbosity > 0)
119  es << " The most frequent " << name << " value is doubtful - variance is too high.";
120 
121  return;
122  }
123 
124  for (CounterMap::iterator iter = relationMap.begin(); iter != relationMap.end(); iter++)
125  {
126  if (iter->first != mostFrequentCounter)
127  {
128  for (std::vector<TotemFramePosition>::iterator fr = iter->second.begin(); fr != iter->second.end(); fr++)
129  {
130  if (error)
131  {
132  if (type == ECChecker)
133  status[*fr].status.setECProgressError();
134  if (type == BCChecker)
135  status[*fr].status.setBCProgressError();
136  }
137 
138  if (verbosity > 0)
139  es << " Frame at " << *fr << ": " << name << " number " << iter->first
140  << " is different from the most frequent one " << mostFrequentCounter << std::endl;
141  }
142  }
143  }
144 }
145 
146 #endif
unsigned int min
minimal required number of frames to search for the most frequent one
type
Definition: HCALResponse.h:21
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
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:120
void Fill(word counter, TotemFramePosition fr)
add new value to map, counter takes value of EC or BC number
double a
Definition: hdecay.h:121
static std::atomic< unsigned int > counter
CounterMap relationMap
counter value -&gt; 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
tuple status
Definition: mps_update.py:57