CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 {
13  float BaseEtaBin = 0.087;
14  theBounds[0]=0.0;
15  for (int it=1; it <= 20; it++) 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 {
32  int number = 0;
33  for (int num = 1; num <= NumberOfTowers; num++) {
34  if ( fabs(eta) > theBounds[num-1]) {
35  number = num;
36  if (eta < 0) number = -num;
37  }
38  }
39  if (fabs(eta) >= theBounds[NumberOfTowers-1]) number = 0;
40  return number;
41 }
42 
43 vector<double> NominalEfficiencyThresholds::bins() const
44 {
45  vector<double> result;
46  for (unsigned int i=1; i <=EtaBounds::NumberOfTowers; i++) result.push_back(etabounds(i));
47  return result;
48 }
49 
51  const EfficiencyBin & e2) const
52 {
53  return e1.eff<= e2.eff_previous;
54 }
55 
57  const ThresholdLocation & l2) const
58 {
59  int itow1 = abs(etabounds.towerFromEta(l1.eta));
60  int itow2 = abs(etabounds.towerFromEta(l2.eta));
61  if (itow1 < itow2) return true;
62  if (itow1 == itow2 && l1.cone< l2.cone) return true;
63  return false;
64 }
65 
67 {
68  FILE *INFILE;
69  char buffer[81];
70  char tag[5];
71  if ( (INFILE=fopen(infile.c_str(),"r")) == NULL) {
72  cout << "Cannot open input file " << infile <<endl;
73  return;
74  }
75  ThresholdLocation location;
76  EfficiencyBin eb;
77  float thr_val;
78  while (fgets(buffer,80,INFILE)) {
79  sscanf(buffer,"%4s",tag);
80  if (strcmp(tag,"ver:") == 0){
81  cout <<" NominalEfficiencyThresholds: "<< infile <<" comment: "<<buffer<<endl;
82  thresholds.clear();
83  }
84  if (strcmp(tag,"loc:") == 0) {
85  sscanf(buffer,"%*s %f %*s %d", &location.eta, &location.cone);
86  eb.eff = 0.;
87  }
88  if (strcmp(tag,"thr:") == 0) {
89  eb.eff_previous = eb.eff;
90  sscanf(buffer,"%*s %f %f", &eb.eff, &thr_val);
91  add(location,ThresholdConstituent(eb,thr_val));
92  }
93  }
94  fclose(INFILE);
95  cout << "... done"<<endl;
96  //dump();
97 }
98 
99 
102 {
103  MapType::iterator ploc = thresholds.find(location);
104  if ( ploc == thresholds.end() ) {
106  mt.insert(threshold);
107  thresholds[location] = mt;
108  } else {
109 // cout << "insert element ("<<threshold.first.eff<<","
110 // <<threshold.first.eff_previous<<") to map "<<endl;
111  (*ploc).second.insert(threshold);
112 // cout << "new size is:"<< (*ploc).second.size() <<endl;
113  }
114 }
115 
117 {
118  MapType::iterator ploc;
119  for (ploc = thresholds.begin(); ploc != thresholds.end(); ploc++) {
120  cout << "eta: "<< (*ploc).first.eta
121  << " icone: "<< (*ploc).first.cone<<endl;
122  ThresholdConstituents::iterator it;
123  for (it = (*ploc).second.begin(); it != (*ploc).second.end(); it++) {
124  cout << " eff: " << (*it).first.eff
125  << " eff_previous: "<< (*it).first.eff_previous
126  << " cut value: " << (*it).second <<endl;
127  }
128  }
129 }
130 
132  ThresholdLocation location, float eff_thr) const
133 {
134  MapType::const_iterator ploc = thresholds.find(location);
135  if ( ploc == thresholds.end() ) {
136  cout << "NominalEfficiencyThresholds: Problem:can't find location in the map :( "
137  << location.eta << " " << location.cone << " " << eff_thr
138  <<endl;
139  return -1;
140  }
141 
142  const float epsilon=1.e-6;
143  EfficiencyBin eb = {eff_thr,eff_thr-epsilon};
144  ThresholdConstituents::const_iterator it = (*ploc).second.find(eb);
145  if (it == (*ploc).second.end()) {
146  cout << "NominalEfficiencyThresholds: Problem:can't find threshold in the map :("<<endl;
147  return -1;
148  }
149 
150  return (*it).second;
151 }
152 
int i
Definition: DBlmapReader.cc:9
dictionary thresholds
Definition: fff_deleter.py:273
std::map< EfficiencyBin, float, EfficiencyBin > ThresholdConstituents
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
#define NULL
Definition: scimark2.h:8
bool operator()(const EfficiencyBin &e1, const EfficiencyBin &e2) const
bool operator()(const ThresholdLocation &l1, const ThresholdLocation &l2) const
T eta() const
tuple result
Definition: query.py:137
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::pair< EfficiencyBin, float > ThresholdConstituent
float thresholdValueForEfficiency(ThresholdLocation location, float eff_thr) const
tuple cout
Definition: gather_cfg.py:121
void add(ThresholdLocation location, ThresholdConstituent threshold)