CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/RecoMuon/MuonIsolation/src/NominalEfficiencyThresholds.cc

Go to the documentation of this file.
00001 #include "RecoMuon/MuonIsolation/src/NominalEfficiencyThresholds.h"
00002 
00003 #include <cmath>
00004 #include <iostream>
00005 #include <cstring>
00006 #include <cstdlib>
00007 #include <cstdio>
00008 using namespace muonisolation;
00009 using namespace std;
00010 
00011 NominalEfficiencyThresholds::EtaBounds::EtaBounds()
00012 {
00013   float BaseEtaBin = 0.087;
00014   theBounds[0]=0.0;
00015   for (int it=1; it <= 20; it++) theBounds[it] = it*BaseEtaBin;
00016   theBounds[21]=1.83;
00017   theBounds[22]=1.93;
00018   theBounds[23]=2.043;
00019   theBounds[24]=2.172;
00020   theBounds[25]=2.322;
00021   theBounds[26]=2.5;
00022   theBounds[27]=2.65;
00023   theBounds[28]=3.0;
00024   theBounds[29]=3.13;
00025   theBounds[30]=3.305;
00026   theBounds[31]=3.48;
00027   theBounds[32]=3.655;
00028 }
00029 
00030 int NominalEfficiencyThresholds::EtaBounds::towerFromEta(double eta) const
00031 {
00032   int number = 0;
00033   for (int num = 1; num <= NumberOfTowers; num++) {
00034     if ( fabs(eta) > theBounds[num-1]) {
00035       number = num;
00036       if (eta < 0) number = -num;
00037     }
00038   }
00039   if (fabs(eta) >= theBounds[NumberOfTowers-1]) number = 0;
00040   return number;
00041 }
00042 
00043 vector<double> NominalEfficiencyThresholds::bins() const
00044 {
00045   vector<double> result;
00046   for (unsigned int i=1; i <=EtaBounds::NumberOfTowers; i++) result.push_back(etabounds(i));
00047   return result;  
00048 }
00049 
00050 bool NominalEfficiencyThresholds::EfficiencyBin::operator() (const EfficiencyBin & e1,
00051                                      const EfficiencyBin & e2) const
00052 {
00053   return e1.eff<= e2.eff_previous;
00054 }
00055 
00056 bool NominalEfficiencyThresholds::locless::operator()(const ThresholdLocation & l1,
00057                                 const ThresholdLocation & l2) const
00058 {
00059   int itow1 = abs(etabounds.towerFromEta(l1.eta));
00060   int itow2 = abs(etabounds.towerFromEta(l2.eta));
00061   if (itow1 < itow2) return true;
00062   if (itow1 == itow2 && l1.cone< l2.cone) return true;
00063   return false;
00064 }
00065 
00066 NominalEfficiencyThresholds::NominalEfficiencyThresholds(const string & infile)
00067 {
00068   FILE *INFILE;
00069   char buffer[81];
00070   char tag[5];
00071   if ( (INFILE=fopen(infile.c_str(),"r")) == NULL) {
00072     cout << "Cannot open input file " << infile <<endl;
00073     return;
00074   }
00075   ThresholdLocation location;
00076   EfficiencyBin eb;
00077   float thr_val;
00078   while (fgets(buffer,80,INFILE)) {
00079     sscanf(buffer,"%4s",tag);
00080     if (strcmp(tag,"ver:") == 0){
00081       cout <<" NominalEfficiencyThresholds: "<< infile <<" comment: "<<buffer<<endl;
00082       thresholds.clear();
00083     }
00084     if (strcmp(tag,"loc:") == 0) {
00085       sscanf(buffer,"%*s %f %*s %d", &location.eta, &location.cone);
00086       eb.eff = 0.;
00087     }
00088     if (strcmp(tag,"thr:") == 0) {
00089       eb.eff_previous = eb.eff;
00090       sscanf(buffer,"%*s %f %f", &eb.eff, &thr_val);
00091       add(location,ThresholdConstituent(eb,thr_val));
00092     }
00093   }
00094   fclose(INFILE);
00095   cout << "... done"<<endl;
00096   //dump();
00097 }
00098 
00099 
00100 void NominalEfficiencyThresholds::add(ThresholdLocation location,
00101                            ThresholdConstituent threshold)
00102 {
00103   MapType::iterator ploc = thresholds.find(location);
00104   if ( ploc == thresholds.end() ) {
00105     ThresholdConstituents mt;
00106     mt.insert(threshold);
00107     thresholds[location] = mt;
00108   } else {
00109 //    cout << "insert element ("<<threshold.first.eff<<","
00110 //                            <<threshold.first.eff_previous<<") to map "<<endl;
00111     (*ploc).second.insert(threshold);
00112 //    cout << "new size is:"<< (*ploc).second.size() <<endl;
00113   }
00114 }
00115 
00116 void NominalEfficiencyThresholds::dump()
00117 {
00118   MapType::iterator ploc;
00119   for (ploc = thresholds.begin(); ploc != thresholds.end(); ploc++) {
00120     cout << "eta: "<< (*ploc).first.eta
00121          << " icone: "<< (*ploc).first.cone<<endl;
00122     ThresholdConstituents::iterator it;
00123     for (it = (*ploc).second.begin(); it != (*ploc).second.end(); it++) {
00124       cout << " eff: "         << (*it).first.eff
00125            << " eff_previous: "<< (*it).first.eff_previous
00126            << " cut value: "   << (*it).second <<endl;
00127     }
00128   }
00129 }
00130 
00131 float NominalEfficiencyThresholds::thresholdValueForEfficiency( 
00132    ThresholdLocation location, float eff_thr) const 
00133 {
00134   MapType::const_iterator ploc = thresholds.find(location);
00135   if ( ploc == thresholds.end() ) {
00136     cout << "NominalEfficiencyThresholds: Problem:can't find location in the map :( "
00137        << location.eta << " " << location.cone << " " << eff_thr
00138        <<endl;
00139     return -1;
00140   }
00141 
00142   const float epsilon=1.e-6;
00143   EfficiencyBin eb = {eff_thr,eff_thr-epsilon};
00144   ThresholdConstituents::const_iterator it = (*ploc).second.find(eb);
00145   if (it == (*ploc).second.end()) {
00146     cout << "NominalEfficiencyThresholds: Problem:can't find threshold in the map :("<<endl;
00147     return -1;
00148   }
00149 
00150   return (*it).second;
00151 }
00152