CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DataFormats/EgammaCandidates/src/Photon.cc

Go to the documentation of this file.
00001 // $Id: Photon.cc,v 1.28 2011/11/07 21:16:15 nancy Exp $
00002 #include "DataFormats/EgammaCandidates/interface/Photon.h"
00003 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00004 
00005 using namespace reco;
00006 
00007 Photon::Photon( const LorentzVector & p4,
00008                 Point caloPos,
00009     const PhotonCoreRef & core,
00010                 const Point & vtx) :
00011     RecoCandidate( 0, p4, vtx, 22 ),
00012     caloPosition_( caloPos ),
00013     photonCore_(core),
00014     pixelSeed_(false)
00015  {}
00016 
00017 
00018 Photon::Photon( const Photon& rhs ) :
00019   RecoCandidate(rhs),
00020   caloPosition_(rhs.caloPosition_),
00021   photonCore_ ( rhs.photonCore_),
00022   pixelSeed_  ( rhs.pixelSeed_ ),
00023   fiducialFlagBlock_ ( rhs.fiducialFlagBlock_ ),
00024   isolationR04_ ( rhs.isolationR04_),
00025   isolationR03_ ( rhs.isolationR03_),
00026   showerShapeBlock_ ( rhs.showerShapeBlock_),
00027   eCorrections_(rhs.eCorrections_),
00028   mipVariableBlock_ (rhs.mipVariableBlock_),
00029   pfIsolation_ ( rhs.pfIsolation_ )
00030  {}
00031 
00032 
00033 
00034 
00035 Photon::~Photon() { }
00036 
00037 Photon * Photon::clone() const {
00038   return new Photon( * this );
00039 }
00040 
00041 
00042 bool Photon::overlap( const Candidate & c ) const {
00043   const RecoCandidate * o = dynamic_cast<const RecoCandidate *>( & c );
00044   return ( o != 0 &&
00045            ( checkOverlap( superCluster(), o->superCluster() ) )
00046            );
00047   return false;
00048 }
00049 
00050 void Photon::setVertex(const Point & vertex) {
00051   math::XYZVectorF direction = caloPosition() - vertex;
00052   double energy = this->energy();
00053   math::XYZVectorF momentum = direction.unit() * energy;
00054   math::XYZTLorentzVector lv(momentum.x(), momentum.y(), momentum.z(), energy );
00055   setP4(lv);
00056   vertex_ = vertex;
00057 }
00058 
00059 reco::SuperClusterRef Photon::superCluster() const {
00060   return this->photonCore()->superCluster();
00061 }
00062 
00063 int Photon::conversionTrackProvenance(const edm::RefToBase<reco::Track>& convTrack) const{
00064 
00065   const reco::ConversionRefVector & conv2leg = this->photonCore()->conversions();
00066   const reco::ConversionRefVector & conv1leg = this->photonCore()->conversionsOneLeg();
00067 
00068   int origin = -1;
00069   bool isEg=false, isPf=false;
00070 
00071   for (unsigned iConv=0; iConv<conv2leg.size(); iConv++){
00072     std::vector<edm::RefToBase<reco::Track> > convtracks = conv2leg[iConv]->tracks();
00073     for (unsigned itk=0; itk<convtracks.size(); itk++){
00074       if (convTrack==convtracks[itk]) isEg=true;
00075     }
00076   }
00077 
00078   for (unsigned iConv=0; iConv<conv1leg.size(); iConv++){
00079     std::vector<edm::RefToBase<reco::Track> > convtracks = conv1leg[iConv]->tracks();
00080     for (unsigned itk=0; itk<convtracks.size(); itk++){
00081       if (convTrack==convtracks[itk]) isPf=true;
00082     }
00083   }
00084 
00085   if (isEg) origin=egamma;
00086   if (isPf) origin=pflow;
00087   if (isEg && isPf) origin=both;
00088 
00089   return origin;
00090 }
00091 
00092 
00093 void Photon::setCorrectedEnergy( P4type type, float newEnergy, float delta_e,  bool setToRecoCandidate ) {
00094 
00095   math::XYZTLorentzVectorD newP4 = p4() ;
00096   newP4 *= newEnergy/newP4.e() ;
00097   switch(type)
00098     {
00099     case ecal_standard:
00100       eCorrections_.scEcalEnergy = newEnergy;
00101       eCorrections_.scEcalEnergyError = delta_e;
00102       break ;
00103     case ecal_photons:
00104       eCorrections_.phoEcalEnergy = newEnergy;
00105       eCorrections_.phoEcalEnergyError = delta_e;
00106       break ;
00107     case  regression1:
00108       eCorrections_.regression1Energy = newEnergy ;
00109       eCorrections_.regression1EnergyError = delta_e;
00110     case  regression2:
00111       eCorrections_.regression2Energy = newEnergy ;
00112       eCorrections_.regression2EnergyError = delta_e;
00113       break ;
00114     default:
00115       throw cms::Exception("reco::Photon")<<"unexpected p4 type: "<< type ;
00116     }
00117   setP4(type, newP4,  delta_e,  setToRecoCandidate); 
00118 
00119 }
00120 
00121 
00122 
00123 
00124  float  Photon::getCorrectedEnergy( P4type type) const {
00125   switch(type)
00126     {
00127     case ecal_standard:
00128       return      eCorrections_.scEcalEnergy;
00129       break ;
00130     case ecal_photons:
00131       return eCorrections_.phoEcalEnergy;
00132       break ;
00133     case  regression1:
00134       return eCorrections_.regression1Energy;
00135     case  regression2:
00136       return eCorrections_.regression2Energy;
00137       break ;
00138     default:
00139       throw cms::Exception("reco::Photon")<<"unexpected p4 type " << type << " cannot return the energy value: " ;
00140    }
00141  }
00142 
00143 
00144  float  Photon::getCorrectedEnergyError( P4type type) const {
00145   switch(type)
00146     {
00147     case ecal_standard:
00148       return      eCorrections_.scEcalEnergyError;
00149       break ;
00150     case ecal_photons:
00151       return eCorrections_.phoEcalEnergyError;
00152       break ;
00153     case  regression1:
00154       return eCorrections_.regression1EnergyError;
00155     case  regression2:
00156       return eCorrections_.regression2EnergyError;
00157       break ;
00158     default:
00159       throw cms::Exception("reco::Photon")<<"unexpected p4 type " << type << " cannot return the uncertainty on the energy: " ;
00160    }
00161  }
00162 
00163 
00164 
00165 void Photon::setP4(P4type type, const LorentzVector & p4, float error, bool setToRecoCandidate ) {
00166 
00167 
00168   switch(type)
00169    {
00170     case ecal_standard:
00171       eCorrections_.scEcalP4 = p4 ;
00172       eCorrections_.scEcalEnergyError = error ;
00173       break ;
00174     case ecal_photons:
00175       eCorrections_.phoEcalP4 = p4 ;
00176       eCorrections_.phoEcalEnergyError = error ;
00177       break ;
00178     case  regression1:
00179       eCorrections_.regression1P4 = p4 ;
00180       eCorrections_.regression1EnergyError = error ;
00181     case  regression2:
00182       eCorrections_.regression2P4 = p4 ;
00183       eCorrections_.regression2EnergyError = error ;
00184       break ;
00185     default:
00186       throw cms::Exception("reco::Photon")<<"unexpected p4 type: "<< type ;
00187    }
00188   if (setToRecoCandidate)
00189    {
00190     setP4(p4) ;
00191     eCorrections_.candidateP4type = type ;
00192    }
00193 
00194 
00195 }
00196 
00197 const Candidate::LorentzVector& Photon::p4( P4type type ) const
00198  {
00199   switch(type)
00200     {
00201     case ecal_standard: return eCorrections_.scEcalP4 ;
00202     case ecal_photons: return eCorrections_.phoEcalP4 ;
00203     case regression1: return eCorrections_.regression1P4 ;
00204     case regression2: return eCorrections_.regression2P4 ;
00205     default: throw cms::Exception("reco::Photon")<<"unexpected p4 type: "<< type << " cannot return p4 ";
00206    }
00207  }