CMS 3D CMS Logo

List of all members | Static Public Member Functions
cscdqm::Utility Class Reference

General and CSCDQM Framework related utility routines. More...

#include <CSCDQM_Utility.h>

Static Public Member Functions

static bool checkError (const unsigned int N, const unsigned int n, const double threshold, const double sigfail)
 Check the hypothesis that error events (n) value above threshold comparing with the expected 0 and statistics is enough. More...
 
static short checkOccupancy (const unsigned int N, const unsigned int n, const double low_threshold, const double high_threshold, const double low_sigfail, const double high_sigfail)
 Check the hypothesis that observed events (n) value is too low or too high comparing with the expected N. More...
 
static uint32_t fastHash (const char *data, int len)
 Calculate super fast hash (from http://www.azillionmonkeys.com/qed/hash.html) More...
 
static uint32_t fastHash (const char *data)
 
static int getCSCTypeBin (const std::string &cstr)
 Get CSC y-axis position from chamber string. More...
 
static std::string getCSCTypeLabel (int endcap, int station, int ring)
 Get CSC label from CSC parameters. More...
 
static int getRUIfromDDUId (unsigned ddu_id)
 Get RUI Number from DDU source ID for post LS1 configuration. More...
 
static bool regexMatch (const std::string &expression, const std::string &message)
 Match RegExp expression string against string message and return result. More...
 
static bool regexMatch (const TPRegexp &re_expression, const std::string &message)
 Match RegExp expression against string message and return result. More...
 
static void regexReplace (const std::string &expression, std::string &message, const std::string replace="")
 Replace string part that matches RegExp expression with some string. More...
 
static void regexReplace (const TPRegexp &re_expression, std::string &message, const std::string replace="")
 Replace string part that matches RegExp expression with some string. More...
 
static std::string regexReplaceStr (const std::string &expression, const std::string &message, const std::string replace="")
 Replace string part that matches RegExp expression with some string. More...
 
static std::string regexReplaceStr (const TPRegexp &re_expression, const std::string &message, const std::string replace="")
 Replace string part that matches RegExp expression with some string. More...
 
static double SignificanceLevelHigh (const unsigned int N, const unsigned int n)
 Calculate error significance alpha for the given number of events based on reference number of errors for "hot" elements: actual number of events have to be larger then the reference. More...
 
static double SignificanceLevelLow (const unsigned int N, const unsigned int n, const double eps)
 Calculate error significance alpha for the given number of errors based on reference number of errors for "cold" elements: actual number of events have to be less then the reference. More...
 
static void splitString (const std::string &str, const std::string &delim, std::vector< std::string > &results)
 Split string according to delimiter. More...
 
static int tokenize (const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
 Break string into tokens. More...
 
static void trimString (std::string &str)
 Trim string. More...
 

Detailed Description

General and CSCDQM Framework related utility routines.

Definition at line 67 of file CSCDQM_Utility.h.

Member Function Documentation

◆ checkError()

bool cscdqm::Utility::checkError ( const unsigned int  N,
const unsigned int  n,
const double  threshold,
const double  sigfail 
)
static

Check the hypothesis that error events (n) value above threshold comparing with the expected 0 and statistics is enough.

Parameters
NNumber of total events
nActual (observed) number of events errors
thresholdRate of tolerance (<1)
sigfailSignificance threshold for low value
Returns
check result: true - error is significant, false - otherwise

Definition at line 331 of file CSCDQM_Utility.cc.

References N, create_idmaps::n, SignificanceLevelLow(), and DiMuonV_cfg::threshold.

Referenced by cscdqm::Summary::ReadErrorChambers().

331  {
332  if (N > 0) {
333  const double eps_meas = (1.0 * n) / (1.0 * N);
334  if (eps_meas > threshold) {
335  if (Utility::SignificanceLevelLow(N, n, threshold) > sigfail) {
336  return true;
337  }
338  }
339  }
340  return false;
341  }
static double SignificanceLevelLow(const unsigned int N, const unsigned int n, const double eps)
Calculate error significance alpha for the given number of errors based on reference number of errors...
#define N
Definition: blowfish.cc:9

◆ checkOccupancy()

short cscdqm::Utility::checkOccupancy ( const unsigned int  N,
const unsigned int  n,
const double  low_threshold,
const double  high_threshold,
const double  low_sigfail,
const double  high_sigfail 
)
static

Check the hypothesis that observed events (n) value is too low or too high comparing with the expected N.

Parameters
NExpected number of events
nActual (observed) number of events
low_thresholdRate of lower boundary of tolerance (< 1)
high_thresholdRate of higher boundary of tolerance (> 1)
low_sigfailSignificance threshold for low value
high_sigfailSignificance threshold for high value
Returns
check outcome: 1 - observed number of events too high wrt expected (HOT), -1 - observed number of events too low wrt expected (COLD), 0 - observed number of events is fine wrt expected

Definition at line 302 of file CSCDQM_Utility.cc.

References N, create_idmaps::n, SignificanceLevelHigh(), and SignificanceLevelLow().

Referenced by cscdqm::Summary::ReadReportingChambersRef().

307  {
308  if (N > 0) {
309  double eps_meas = (1.0 * n) / (1.0 * N);
310  if (eps_meas < low_threshold) {
311  double S = Utility::SignificanceLevelLow(N, n, low_threshold);
312  if (S > low_sigfail)
313  return -1;
314  } else if (eps_meas > high_threshold) {
315  double S = Utility::SignificanceLevelHigh(N, n);
316  if (S > high_sigfail)
317  return 1;
318  }
319  }
320  return 0;
321  }
static double SignificanceLevelHigh(const unsigned int N, const unsigned int n)
Calculate error significance alpha for the given number of events based on reference number of errors...
static double SignificanceLevelLow(const unsigned int N, const unsigned int n, const double eps)
Calculate error significance alpha for the given number of errors based on reference number of errors...
#define N
Definition: blowfish.cc:9

◆ fastHash() [1/2]

uint32_t cscdqm::Utility::fastHash ( const char *  data,
int  len 
)
static

Calculate super fast hash (from http://www.azillionmonkeys.com/qed/hash.html)

Parameters
dataSource Data
lengthof data
Returns
hash result

Definition at line 242 of file CSCDQM_Utility.cc.

References data, get16bits, cond::hash, and createJobs::tmp.

242  {
243  uint32_t hash = len, tmp;
244  int rem;
245 
246  if (len <= 0 || data == nullptr)
247  return 0;
248  rem = len & 3;
249  len >>= 2;
250 
251  /* Main loop */
252  for (; len > 0; len--) {
253  hash += get16bits(data);
254  tmp = (get16bits(data + 2) << 11) ^ hash;
255  hash = (hash << 16) ^ tmp;
256  data += 2 * sizeof(uint16_t);
257  hash += hash >> 11;
258  }
259 
260  /* Handle end cases */
261  switch (rem) {
262  case 3:
263  hash += get16bits(data);
264  hash ^= hash << 16;
265  hash ^= data[sizeof(uint16_t)] << 18;
266  hash += hash >> 11;
267  break;
268  case 2:
269  hash += get16bits(data);
270  hash ^= hash << 11;
271  hash += hash >> 17;
272  break;
273  case 1:
274  hash += *data;
275  hash ^= hash << 10;
276  hash += hash >> 1;
277  }
278 
279  /* Force "avalanching" of final 127 bits */
280  hash ^= hash << 3;
281  hash += hash >> 5;
282  hash ^= hash << 4;
283  hash += hash >> 17;
284  hash ^= hash << 25;
285  hash += hash >> 6;
286 
287  return hash;
288  }
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
#define get16bits(d)
tmp
align.sh
Definition: createJobs.py:716

◆ fastHash() [2/2]

static uint32_t cscdqm::Utility::fastHash ( const char *  data)
inlinestatic

Definition at line 86 of file CSCDQM_Utility.h.

References data, and fastHash().

Referenced by fastHash().

86 { return fastHash(data, strlen(data)); }
static uint32_t fastHash(const char *data, int len)
Calculate super fast hash (from http://www.azillionmonkeys.com/qed/hash.html)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80

◆ getCSCTypeBin()

int cscdqm::Utility::getCSCTypeBin ( const std::string &  cstr)
static

Get CSC y-axis position from chamber string.

Parameters
cstrChamber string
Returns
chamber y-axis position

Definition at line 33 of file CSCDQM_Utility.cc.

Referenced by cscdqm::EventProcessor::getCSCFromMap().

33  {
34  if (cstr == "ME-4/2")
35  return 0;
36  if (cstr == "ME-4/1")
37  return 1;
38  if (cstr == "ME-3/2")
39  return 2;
40  if (cstr == "ME-3/1")
41  return 3;
42  if (cstr == "ME-2/2")
43  return 4;
44  if (cstr == "ME-2/1")
45  return 5;
46  if (cstr == "ME-1/3")
47  return 6;
48  if (cstr == "ME-1/2")
49  return 7;
50  if (cstr == "ME-1/1")
51  return 8;
52  if (cstr == "ME+1/1")
53  return 9;
54  if (cstr == "ME+1/2")
55  return 10;
56  if (cstr == "ME+1/3")
57  return 11;
58  if (cstr == "ME+2/1")
59  return 12;
60  if (cstr == "ME+2/2")
61  return 13;
62  if (cstr == "ME+3/1")
63  return 14;
64  if (cstr == "ME+3/2")
65  return 15;
66  if (cstr == "ME+4/1")
67  return 16;
68  if (cstr == "ME+4/2")
69  return 17;
70  return 0;
71  }

◆ getCSCTypeLabel()

std::string cscdqm::Utility::getCSCTypeLabel ( int  endcap,
int  station,
int  ring 
)
static

Get CSC label from CSC parameters.

Parameters
endcapEndcap number
stationStation number
ringRing number
Returns
chamber label

Definition at line 80 of file CSCDQM_Utility.cc.

References makeMuonMisalignmentScenario::endcap, label, relativeConstraints::ring, relativeConstraints::station, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by cscdqm::EventProcessor::getCSCFromMap().

80  {
81  std::string label = "Unknown";
82  std::ostringstream st;
83  if ((endcap > 0) && (station > 0) && (ring > 0)) {
84  if (endcap == 1) {
85  st << "ME+" << station << "/" << ring;
86  label = st.str();
87  } else if (endcap == 2) {
88  st << "ME-" << station << "/" << ring;
89  label = st.str();
90  } else {
91  label = "Unknown";
92  }
93  }
94  return label;
95  }
char const * label

◆ getRUIfromDDUId()

int cscdqm::Utility::getRUIfromDDUId ( unsigned  ddu_id)
static

Get RUI Number from DDU source ID for post LS1 configuration.

Parameters
ddu_idDDI Source ID

Definition at line 397 of file CSCDQM_Utility.cc.

References mps_fire::i, FEDNumbering::MAXCSCDDUFEDID, and FEDNumbering::MINCSCDDUFEDID.

Referenced by cscdqm::EventProcessor::processDDU(), and cscdqm::EventProcessor::processExaminer().

397  {
398  int rui = -1;
399  const unsigned postLS1_map[] = {841, 842, 843, 844, 845, 846, 847, 848, 849, 831, 832, 833,
400  834, 835, 836, 837, 838, 839, 861, 862, 863, 864, 865, 866,
401  867, 868, 869, 851, 852, 853, 854, 855, 856, 857, 858, 859};
402  if ((ddu_id >= FEDNumbering::MINCSCDDUFEDID) && (ddu_id <= FEDNumbering::MAXCSCDDUFEDID)) {
403  for (int i = 0; i < 36; i++) {
404  if (ddu_id == postLS1_map[i]) {
405  rui = i + 1;
406  return rui;
407  }
408  }
409  } else {
410  rui = ddu_id & 0xFF;
411  }
412  return rui;
413  }

◆ regexMatch() [1/2]

bool cscdqm::Utility::regexMatch ( const std::string &  expression,
const std::string &  message 
)
static

Match RegExp expression string against string message and return result.

Parameters
expressionRegExp expression in string to match
messagevalue to check
Returns
true if message matches RegExp expression

Definition at line 166 of file CSCDQM_Utility.cc.

References l1tGTMenu_BTagSeeds_cff::expression.

Referenced by CSCOfflineClient::bookMonitorObject(), CSCMonitorModule::bookMonitorObject(), cscdqm::Collection::load(), cscdqm::Configuration::needBookMO(), and cscdqm::HistoDef::processName().

166  {
167  return regexMatch(TPRegexp(expression), message);
168  }
static bool regexMatch(const std::string &expression, const std::string &message)
Match RegExp expression string against string message and return result.

◆ regexMatch() [2/2]

bool cscdqm::Utility::regexMatch ( const TPRegexp &  re_expression,
const std::string &  message 
)
static

Match RegExp expression against string message and return result.

Parameters
re_expressionRegExp expression to match
messagevalue to check
Returns
true if message matches RegExp expression

Definition at line 155 of file CSCDQM_Utility.cc.

155  {
156  TPRegexp* re = const_cast<TPRegexp*>(&re_expression);
157  return re->MatchB(message);
158  }

◆ regexReplace() [1/2]

void cscdqm::Utility::regexReplace ( const std::string &  expression,
std::string &  message,
const std::string  replace = "" 
)
static

Replace string part that matches RegExp expression with some string.

Parameters
expressionRegExp expression in string to match
messagevalue to check
replacestring to replace matched part

Definition at line 177 of file CSCDQM_Utility.cc.

References l1tGTMenu_BTagSeeds_cff::expression, and python.rootplot.root2matplotlib::replace().

177  {
178  Utility::regexReplace(TPRegexp(expression), message, replace);
179  }
def replace(string, replacements)
static void regexReplace(const std::string &expression, std::string &message, const std::string replace="")
Replace string part that matches RegExp expression with some string.

◆ regexReplace() [2/2]

void cscdqm::Utility::regexReplace ( const TPRegexp &  re_expression,
std::string &  message,
const std::string  replace = "" 
)
static

Replace string part that matches RegExp expression with some string.

Parameters
re_expressionRegExp expression to match
messagevalue to check
replacestring to replace matched part

Definition at line 188 of file CSCDQM_Utility.cc.

References python.rootplot.root2matplotlib::replace(), and alignCSCRings::s.

188  {
189  TString s(message);
190  TPRegexp* re = const_cast<TPRegexp*>(&re_expression);
191  re->Substitute(s, replace);
192  message = static_cast<const char*>(s);
193  }
def replace(string, replacements)

◆ regexReplaceStr() [1/2]

std::string cscdqm::Utility::regexReplaceStr ( const std::string &  expression,
const std::string &  message,
const std::string  replace = "" 
)
static

Replace string part that matches RegExp expression with some string.

Parameters
expressionRegExp expression in string to match
messagevalue to check
replacestring to replace matched part
Returns
modified string

Definition at line 203 of file CSCDQM_Utility.cc.

References l1tGTMenu_BTagSeeds_cff::expression, and python.rootplot.root2matplotlib::replace().

205  {
206  return regexReplaceStr(TPRegexp(expression), message, replace);
207  }
static std::string regexReplaceStr(const std::string &expression, const std::string &message, const std::string replace="")
Replace string part that matches RegExp expression with some string.
def replace(string, replacements)

◆ regexReplaceStr() [2/2]

std::string cscdqm::Utility::regexReplaceStr ( const TPRegexp &  re_expression,
const std::string &  message,
const std::string  replace = "" 
)
static

Replace string part that matches RegExp expression with some string.

Parameters
re_expressionRegExp expression to match
messagevalue to check
replacestring to replace matched part
Returns
modified string

Definition at line 217 of file CSCDQM_Utility.cc.

References python.rootplot.root2matplotlib::replace(), and alignCSCRings::s.

219  {
220  TString s(message);
221  TPRegexp* re = const_cast<TPRegexp*>(&re_expression);
222  re->Substitute(s, replace);
223  return s.Data();
224  }
def replace(string, replacements)

◆ SignificanceLevelHigh()

double cscdqm::Utility::SignificanceLevelHigh ( const unsigned int  N,
const unsigned int  n 
)
static

Calculate error significance alpha for the given number of events based on reference number of errors for "hot" elements: actual number of events have to be larger then the reference.

Parameters
Nnumber of reference events
nnumber of actual events
Returns
error significance

no - n observed, ne - n expected

Definition at line 385 of file CSCDQM_Utility.cc.

References CrabHelper::log, N, create_idmaps::n, compareTotals::ne, and mathSSE::sqrt().

Referenced by checkOccupancy().

385  {
386  if (N > n)
387  return 0.0;
389  double no = 1.0 * n, ne = 1.0 * N;
390  return sqrt(2.0 * (no * (log(no / ne) - 1) + ne));
391  }
T sqrt(T t)
Definition: SSEVec.h:23
#define N
Definition: blowfish.cc:9

◆ SignificanceLevelLow()

double cscdqm::Utility::SignificanceLevelLow ( const unsigned int  N,
const unsigned int  n,
const double  eps 
)
static

Calculate error significance alpha for the given number of errors based on reference number of errors for "cold" elements: actual number of events have to be less then the reference.

Parameters
NNumber of events
nNumber of errors
epsRate of tolerance
Returns
Significance level

std::cout << "N = " << N << ", n = " << n << ", eps = " << eps << "\n";

Definition at line 352 of file CSCDQM_Utility.cc.

References a, b, HLT_2024v14_cff::eps, CrabHelper::log, N, create_idmaps::n, and mathSSE::sqrt().

Referenced by checkError(), and checkOccupancy().

352  {
355  double l_eps = eps;
356  if (l_eps <= 0.0)
357  l_eps = 0.000001;
358  if (l_eps >= 1.0)
359  l_eps = 0.999999;
360 
361  double eps_meas = (1.0 * n) / (1.0 * N);
362  double a = 1.0, b = 1.0;
363 
364  if (n > 0) {
365  for (unsigned int r = 0; r < n; r++)
366  a = a * (eps_meas / l_eps);
367  }
368 
369  if (n < N) {
370  for (unsigned int r = 0; r < (N - n); r++)
371  b = b * (1 - eps_meas) / (1 - l_eps);
372  }
373 
374  return sqrt(2.0 * log(a * b));
375  }
T sqrt(T t)
Definition: SSEVec.h:23
#define N
Definition: blowfish.cc:9
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121

◆ splitString()

void cscdqm::Utility::splitString ( const std::string &  str,
const std::string &  delim,
std::vector< std::string > &  results 
)
static

Split string according to delimiter.

Parameters
strString to split
delimDelimiter
resultsVector to write results to
Returns

Definition at line 122 of file CSCDQM_Utility.cc.

References mysort::results, and str.

Referenced by cscdqm::Detector::AddressFromString().

122  {
123  std::string::size_type lastPos = str.find_first_not_of(delim, 0);
124  std::string::size_type pos = str.find_first_of(delim, lastPos);
125  while (std::string::npos != pos || std::string::npos != lastPos) {
126  results.push_back(str.substr(lastPos, pos - lastPos));
127  lastPos = str.find_first_not_of(delim, pos);
128  pos = str.find_first_of(delim, lastPos);
129  }
130  }
uint16_t size_type
results
Definition: mysort.py:8
#define str(s)

◆ tokenize()

int cscdqm::Utility::tokenize ( const std::string &  str,
std::vector< std::string > &  tokens,
const std::string &  delimiters = " " 
)
static

Break string into tokens.

Parameters
strsource string to break
tokenspointer to result vector
delimitersdelimiter string, default " "
Returns

Definition at line 104 of file CSCDQM_Utility.cc.

References str.

Referenced by cscdqm::Collection::book().

104  {
105  std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
106  std::string::size_type pos = str.find_first_of(delimiters, lastPos);
107  while (std::string::npos != pos || std::string::npos != lastPos) {
108  tokens.push_back(str.substr(lastPos, pos - lastPos));
109  lastPos = str.find_first_not_of(delimiters, pos);
110  pos = str.find_first_of(delimiters, lastPos);
111  }
112  return tokens.size();
113  }
uint16_t size_type
#define str(s)

◆ trimString()

void cscdqm::Utility::trimString ( std::string &  str)
static

Trim string.

Parameters
strstring to trim

Definition at line 136 of file CSCDQM_Utility.cc.

References str.

Referenced by cscdqm::Detector::AddressFromString().

136  {
137  std::string::size_type pos = str.find_last_not_of(' ');
138  if (pos != std::string::npos) {
139  str.erase(pos + 1);
140  pos = str.find_first_not_of(' ');
141  if (pos != std::string::npos) {
142  str.erase(0, pos);
143  }
144  } else {
145  str.erase(str.begin(), str.end());
146  }
147  }
uint16_t size_type
#define str(s)