CMS 3D CMS Logo

NominalEfficiencyThresholds.cc

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

Generated on Tue Jun 9 17:44:22 2009 for CMSSW by  doxygen 1.5.4