CMS 3D CMS Logo

MuIsoDeposit.cc

Go to the documentation of this file.
00001 #define USE_MUISODEPOSIT_REQUIRED 1
00002 #include "DataFormats/MuonReco/interface/MuIsoDeposit.h"
00003 #include "DataFormats/MuonReco/interface/MuIsoDepositVetos.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 
00006 #include <sstream>
00007 
00008 using namespace reco;
00009 
00010 //bool MuIsoDeposit::Closer::operator()( const Distance & d1, const Distance & d2) const
00011 //{
00012 //  if ( d1.deltaR < d2.deltaR) return true;
00013 //  else if (d1.deltaR == d2.deltaR && d1.relativeAngle < d2.relativeAngle) return true;
00014 //  else return false;
00015 //}
00016 
00017 MuIsoDeposit::MuIsoDeposit(const std::string type, const Direction & muonDirection)
00018   : theType(type), theDirection(muonDirection),theMuonTag(0.)
00019 { 
00020   theVeto.vetoDir = theDirection;
00021   theVeto.dR = 0.;
00022 }
00023 
00024 MuIsoDeposit::MuIsoDeposit(const std::string type, double eta, double phi)
00025   : theType(type), theDirection(Direction(eta,phi)), theMuonTag(0.)
00026 { 
00027   theVeto.vetoDir = theDirection;
00028   theVeto.dR = 0.;
00029 }
00030 
00031 void MuIsoDeposit::addDeposit(double dr, double value){
00032   Distance relDir = {dr,0.};
00033   theDeposits.insert( std::make_pair( relDir, value));
00034 }
00035 
00036 void MuIsoDeposit::addDeposit(const Direction & depDir, double deposit)
00037 {
00038   Distance relDir = depDir - theDirection;
00039   theDeposits.insert( std::make_pair( relDir,deposit));
00040 /*
00041   {
00042     Direction dtmp = theDirection+relDir;
00043     if (dtmp.deltaR(depDir) > 1.e-4) {
00044          std::cout <<"ERROR, dR= "<<dtmp.deltaR(depDir)<<std::endl;
00045          std::cout<<" theDirection"<<theDirection.print()<<std::endl;
00046          std::cout<<" depDir:     "<<depDir.print()<<std::endl;
00047          std::cout<<" recovered:  "<<dtmp.print()<<std::endl;
00048          std::cout<<" relative dr: " << relDir.deltaR<<" relative angle: " << relDir.relativeAngle<<std::endl;
00049     }
00050   }
00051 */
00052 }
00053 
00054 double MuIsoDeposit::depositWithin(double coneSize, const Vetos& vetos, bool skipDepositVeto) const 
00055 {
00056   return depositAndCountWithin(coneSize, vetos, -1e+36, skipDepositVeto).first;
00057 }
00058 
00059 double MuIsoDeposit::depositWithin(Direction dir, double coneSize, const Vetos& vetos, bool skipDepositVeto) const 
00060 {
00061   return depositAndCountWithin(dir, coneSize, vetos, -1e+36, skipDepositVeto).first;
00062 }
00063 
00064 std::pair<double,int> MuIsoDeposit::depositAndCountWithin(double coneSize, const Vetos& vetos, 
00065                                                           double threshold, bool skipDepositVeto) const 
00066 {
00067   double result = 0;
00068   int count = 0;
00069 
00070   Vetos allVetos = vetos;
00071   typedef Vetos::const_iterator IV;
00072   if (!skipDepositVeto) allVetos.push_back(theVeto);
00073   IV ivEnd = allVetos.end();
00074 
00075   Distance maxDistance = {coneSize,999.};
00076   typedef DepositsMultimap::const_iterator IM;
00077   IM imLoc = theDeposits.upper_bound( maxDistance ); 
00078   for (IM im = theDeposits.begin(); im != imLoc; ++im) {
00079     bool vetoed = false;
00080     for ( IV iv = allVetos.begin(); iv < ivEnd; ++iv) {
00081       Direction dirDep = theDirection+im->first;
00082       if (dirDep.deltaR(iv->vetoDir) < iv->dR) vetoed = true; 
00083     }  
00084     if (!vetoed && im->second > threshold){
00085       result += im->second;
00086       count++;
00087     }
00088   }
00089   return std::pair<double,int>(result,count);
00090 }
00091 
00092 std::pair<double,int> MuIsoDeposit::depositAndCountWithin(Direction dir, double coneSize, const Vetos& vetos, 
00093                                                           double threshold, bool skipDepositVeto) const 
00094 {
00095   double result = 0;
00096   int count = 0;
00097 
00098   Vetos allVetos = vetos;
00099   typedef Vetos::const_iterator IV;
00100   if (!skipDepositVeto) allVetos.push_back(theVeto);
00101   IV ivEnd = allVetos.end();
00102 
00103   typedef DepositsMultimap::const_iterator IM;
00104   for (IM im = theDeposits.begin(); im != theDeposits.end(); ++im) {
00105     bool vetoed = false;
00106     Direction dirDep = theDirection+im->first;
00107     Distance newDist = dirDep - dir;
00108     if (newDist.deltaR > coneSize) continue;
00109     for ( IV iv = allVetos.begin(); iv < ivEnd; ++iv) {
00110       if (dirDep.deltaR(iv->vetoDir) < iv->dR) vetoed = true; 
00111     }  
00112     if (!vetoed && im->second > threshold){
00113       result += im->second;
00114       count++;
00115     }
00116   }
00117   return std::pair<double,int>(result,count);
00118 }
00119 
00120 std::pair<double,int>  MuIsoDeposit::depositAndCountWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const 
00121 {
00122   using namespace reco::muisodeposit;
00123   double result = 0;
00124   int count =  0;
00125   typedef AbsVetos::const_iterator IV;
00126 
00127   IV ivEnd = vetos.end();
00128 
00129   Distance maxDistance = {coneSize,999.};
00130   typedef DepositsMultimap::const_iterator IM;
00131   IM imLoc = theDeposits.upper_bound( maxDistance ); 
00132   for (IM im = theDeposits.begin(); im != imLoc; ++im) {
00133     bool vetoed = false;
00134     Direction dirDep = theDirection+im->first;
00135     for ( IV iv = vetos.begin(); iv < ivEnd; ++iv) {
00136       if ((*iv)->veto(dirDep.eta(), dirDep.phi(), im->second)) { vetoed = true;  break; }
00137     }
00138     if (!vetoed) {
00139        if (skipDepositVeto || (dirDep.deltaR(theVeto.vetoDir) > theVeto.dR)) {
00140           result += im->second;
00141                   count++;
00142         }
00143     }
00144   }
00145   return std::pair<double,int>(result,count);
00146 }
00147 
00148 
00149 double MuIsoDeposit::depositWithin(double coneSize, const AbsVetos& vetos, bool skipDepositVeto) const 
00150 {
00151         return depositAndCountWithin(coneSize, vetos, skipDepositVeto).first;
00152 }
00153 
00154 
00155 
00156 std::string MuIsoDeposit::print() const
00157 {
00158   std::ostringstream str;
00159   str<<"Direction : "<<theDirection.print()<<std::endl;
00160   str<<"Veto:       ("<<theVeto.vetoDir.eta()<<", "<<theVeto.vetoDir.phi()<<" dR="<<theVeto.dR<<")"<<std::endl;
00161   typedef DepositsMultimap::const_iterator IM;
00162   IM imEnd = theDeposits.end();
00163   for (IM im = theDeposits.begin(); im != imEnd; ++im) {
00164     str<<"(dR="<< im->first.deltaR<<", alpha="<<im->first.relativeAngle<<", Pt="<<im->second<<"),";
00165   }
00166   str<<std::endl;
00167 
00168   
00169   
00170   return str.str();
00171 }

Generated on Tue Jun 9 17:31:21 2009 for CMSSW by  doxygen 1.5.4