CMS 3D CMS Logo

NominalEfficiencyThresholds.cc
Go to the documentation of this file.
2 
3 #include <cmath>
4 #include <iostream>
5 #include <cstring>
6 #include <cstdlib>
7 #include <cstdio>
8 using namespace muonisolation;
9 using namespace std;
10 
12  float BaseEtaBin = 0.087;
13  theBounds[0] = 0.0;
14  for (int it = 1; it <= 20; it++)
15  theBounds[it] = it * BaseEtaBin;
16  theBounds[21] = 1.83;
17  theBounds[22] = 1.93;
18  theBounds[23] = 2.043;
19  theBounds[24] = 2.172;
20  theBounds[25] = 2.322;
21  theBounds[26] = 2.5;
22  theBounds[27] = 2.65;
23  theBounds[28] = 3.0;
24  theBounds[29] = 3.13;
25  theBounds[30] = 3.305;
26  theBounds[31] = 3.48;
27  theBounds[32] = 3.655;
28 }
29 
31  int number = 0;
32  for (int num = 1; num <= NumberOfTowers; num++) {
33  if (fabs(eta) > theBounds[num - 1]) {
34  number = num;
35  if (eta < 0)
36  number = -num;
37  }
38  }
39  if (fabs(eta) >= theBounds[NumberOfTowers - 1])
40  number = 0;
41  return number;
42 }
43 
44 vector<double> NominalEfficiencyThresholds::bins() const {
45  vector<double> result;
46  for (unsigned int i = 1; i <= EtaBounds::NumberOfTowers; i++)
47  result.push_back(etabounds(i));
48  return result;
49 }
50 
52  return e1.eff <= e2.eff_previous;
53 }
54 
56  int itow1 = abs(etabounds.towerFromEta(l1.eta));
57  int itow2 = abs(etabounds.towerFromEta(l2.eta));
58  if (itow1 < itow2)
59  return true;
60  if (itow1 == itow2 && l1.cone < l2.cone)
61  return true;
62  return false;
63 }
64 
66  FILE *INFILE;
67  char buffer[81];
68  char tag[5];
69  if ((INFILE = fopen(infile.c_str(), "r")) == nullptr) {
70  cout << "Cannot open input file " << infile << endl;
71  return;
72  }
73  ThresholdLocation location;
74  EfficiencyBin eb;
75  eb.eff = 0;
76  float thr_val;
77  while (fgets(buffer, 80, INFILE)) {
78  sscanf(buffer, "%4s", tag);
79  if (strcmp(tag, "ver:") == 0) {
80  cout << " NominalEfficiencyThresholds: " << infile << " comment: " << buffer << endl;
81  thresholds.clear();
82  }
83  if (strcmp(tag, "loc:") == 0) {
84  sscanf(buffer, "%*s %f %*s %d", &location.eta, &location.cone);
85  eb.eff = 0.;
86  }
87  if (strcmp(tag, "thr:") == 0) {
88  eb.eff_previous = eb.eff;
89  sscanf(buffer, "%*s %f %f", &eb.eff, &thr_val);
90  add(location, ThresholdConstituent(eb, thr_val));
91  }
92  }
93  fclose(INFILE);
94  cout << "... done" << endl;
95  //dump();
96 }
97 
99  MapType::iterator ploc = thresholds.find(location);
100  if (ploc == thresholds.end()) {
102  mt.insert(threshold);
104  } else {
105  // cout << "insert element ("<<threshold.first.eff<<","
106  // <<threshold.first.eff_previous<<") to map "<<endl;
107  (*ploc).second.insert(threshold);
108  // cout << "new size is:"<< (*ploc).second.size() <<endl;
109  }
110 }
111 
113  MapType::iterator ploc;
114  for (ploc = thresholds.begin(); ploc != thresholds.end(); ploc++) {
115  cout << "eta: " << (*ploc).first.eta << " icone: " << (*ploc).first.cone << endl;
116  ThresholdConstituents::iterator it;
117  for (it = (*ploc).second.begin(); it != (*ploc).second.end(); it++) {
118  cout << " eff: " << (*it).first.eff << " eff_previous: " << (*it).first.eff_previous
119  << " cut value: " << (*it).second << endl;
120  }
121  }
122 }
123 
125  MapType::const_iterator ploc = thresholds.find(location);
126  if (ploc == thresholds.end()) {
127  cout << "NominalEfficiencyThresholds: Problem:can't find location in the map :( " << location.eta << " "
128  << location.cone << " " << eff_thr << endl;
129  return -1;
130  }
131 
132  const float epsilon = 1.e-6;
133  EfficiencyBin eb = {eff_thr, eff_thr - epsilon};
134  ThresholdConstituents::const_iterator it = (*ploc).second.find(eb);
135  if (it == (*ploc).second.end()) {
136  cout << "NominalEfficiencyThresholds: Problem:can't find threshold in the map :(" << endl;
137  return -1;
138  }
139 
140  return (*it).second;
141 }
std::pair< EfficiencyBin, float > ThresholdConstituent
std::map< EfficiencyBin, float, EfficiencyBin > ThresholdConstituents
bool operator()(const ThresholdLocation &l1, const ThresholdLocation &l2) const
float thresholdValueForEfficiency(ThresholdLocation location, float eff_thr) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool operator()(const EfficiencyBin &e1, const EfficiencyBin &e2) const
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
void add(ThresholdLocation location, ThresholdConstituent threshold)