File indexing completed on 2024-04-06 12:10:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EventFilter_CTPPSRawToDigi_CounterChecker
0011 #define EventFilter_CTPPSRawToDigi_CounterChecker
0012
0013 #include <map>
0014 #include <string>
0015 #include <vector>
0016 #include <iostream>
0017
0018 #include "CondFormats/PPSObjects/interface/TotemFramePosition.h"
0019
0020 #include "DataFormats/CTPPSDigi/interface/TotemVFATStatus.h"
0021
0022
0023
0024
0025
0026 class CounterChecker {
0027 public:
0028 typedef unsigned short word;
0029
0030 typedef std::map<word, std::vector<TotemFramePosition> > CounterMap;
0031
0032 enum CheckerType { BCChecker, ECChecker };
0033
0034
0035
0036
0037
0038
0039
0040 CounterChecker(CheckerType _type = CounterChecker::BCChecker,
0041 const std::string &_name = "",
0042 unsigned int _min = 0,
0043 double _fraction = 0.,
0044 unsigned int _verbosity = 0)
0045 : type(_type), name(_name), min(_min), fraction(_fraction), verbosity(_verbosity) {}
0046
0047
0048 void Fill(word counter, TotemFramePosition fr);
0049
0050
0051 template <typename T>
0052 void Analyze(T &status, bool error, std::ostream &es);
0053
0054 private:
0055 class Comparer {
0056 public:
0057 typedef unsigned short word;
0058 bool operator()(const std::pair<word, std::vector<TotemFramePosition> > &a,
0059 const std::pair<word, std::vector<TotemFramePosition> > &b) {
0060 return a.second.size() < b.second.size();
0061 }
0062 };
0063
0064
0065 CounterMap relationMap;
0066
0067
0068 CheckerType type;
0069
0070
0071 std::string name;
0072
0073
0074 unsigned int min;
0075
0076
0077
0078 double fraction;
0079
0080
0081 unsigned int verbosity;
0082 };
0083
0084 template <typename T>
0085 void CounterChecker::Analyze(T &status, bool error, std::ostream &es) {
0086 word mostFrequentCounter = 0;
0087 word mostFrequentSize = 0;
0088 unsigned int totalFrames = 0;
0089
0090
0091 for (CounterMap::iterator iter = relationMap.begin(); iter != relationMap.end(); iter++) {
0092 unsigned int iterSize = iter->second.size();
0093 totalFrames += iterSize;
0094
0095 if (iterSize > mostFrequentSize) {
0096 mostFrequentCounter = iter->first;
0097 mostFrequentSize = iter->second.size();
0098 }
0099 }
0100
0101 if (totalFrames < min) {
0102 if (verbosity > 0)
0103 es << "Too few frames to determine the most frequent " << name << " value.";
0104
0105 return;
0106 }
0107
0108
0109 if ((float)mostFrequentSize / (float)totalFrames < fraction) {
0110 if (verbosity > 0)
0111 es << "The most frequent " << name << " value is doubtful - variance is too high.";
0112
0113 return;
0114 }
0115
0116 for (CounterMap::iterator iter = relationMap.begin(); iter != relationMap.end(); iter++) {
0117 if (iter->first != mostFrequentCounter) {
0118 for (std::vector<TotemFramePosition>::iterator fr = iter->second.begin(); fr != iter->second.end(); fr++) {
0119 if (error) {
0120 if (type == ECChecker)
0121 status[*fr].status.setECProgressError();
0122 if (type == BCChecker)
0123 status[*fr].status.setBCProgressError();
0124 }
0125
0126 if (verbosity > 0)
0127 es << "Frame at " << *fr << ": " << name << " number " << iter->first
0128 << " is different from the most frequent one " << mostFrequentCounter << std::endl;
0129 }
0130 }
0131 }
0132 }
0133
0134 #endif