CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/RecoMET/METAlgorithms/src/PFSpecificAlgo.cc

Go to the documentation of this file.
00001 /*
00002 class: PFSpecificAlgo.cc
00003 description:  MET made from Particle Flow candidates
00004 authors: R. Remington (UF), R. Cavanaugh (UIC/Fermilab)
00005   date: 10/27/08
00006 */
00007 
00008 #include "DataFormats/Math/interface/LorentzVector.h"
00009 #include "RecoMET/METAlgorithms/interface/PFSpecificAlgo.h"
00010 #include "RecoMET/METAlgorithms/interface/significanceAlgo.h"
00011 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00012 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00013 using namespace reco;
00014 using namespace std;
00015 
00016 //--------------------------------------------------------------------------------------
00017 // This algorithm adds Particle Flow specific global event information to the MET object
00018 //--------------------------------------------------------------------------------------
00019 
00020 reco::PFMET PFSpecificAlgo::addInfo(edm::Handle<edm::View<Candidate> > PFCandidates, CommonMETData met)
00021 {
00022   // Instantiate the container to hold the PF specific information
00023   SpecificPFMETData specific;
00024   // Initialize the container
00025   specific.NeutralEMFraction = 0.0;
00026   specific.NeutralHadFraction = 0.0;
00027   specific.ChargedEMFraction = 0.0;
00028   specific.ChargedHadFraction = 0.0;
00029   specific.MuonFraction = 0.0;
00030   specific.Type6Fraction = 0.0;
00031   specific.Type7Fraction = 0.0;
00032 
00033   if(!PFCandidates->size()) // if no Particle Flow candidates in the event
00034   {
00035     const LorentzVector p4( met.mex, met.mey, 0.0, met.met);
00036     const Point vtx(0.0, 0.0, 0.0 );
00037     PFMET specificPFMET( specific, met.sumet, p4, vtx);
00038     return specificPFMET;
00039   } 
00040 
00041   double NeutralEMEt = 0.0;
00042   double NeutralHadEt = 0.0;
00043   double ChargedEMEt = 0.0;
00044   double ChargedHadEt = 0.0;
00045   double MuonEt = 0.0;
00046   double type6Et = 0.0;
00047   double type7Et = 0.0;
00048 
00049 
00050   pfsignalgo_.useOriginalPtrs(PFCandidates.id());
00051   
00052   for( edm::View<reco::Candidate>::const_iterator iParticle = (PFCandidates.product())->begin() ; iParticle != (PFCandidates.product())->end() ; ++iParticle )
00053   {   
00054     const Candidate* candidate = &(*iParticle);
00055     if (candidate) {
00056       //const PFCandidate* pfCandidate = static_cast<const PFCandidate*> (candidate);
00057       const PFCandidate* pfCandidate = dynamic_cast<const PFCandidate*> (candidate);
00058       if (pfCandidate)
00059       {
00060         //cout << pfCandidate->et() << "     "
00061         //   << pfCandidate->hcalEnergy() << "    "
00062         //   << pfCandidate->ecalEnergy() << endl;
00063         //std::cout << "pfCandidate->particleId() = " << pfCandidate->particleId() << std::endl;
00064         const double theta = iParticle->theta();
00065         const double e     = iParticle->energy();
00066         const double et    = e*sin(theta);
00067         if(alsocalcsig){
00068             reco::CandidatePtr dau(PFCandidates, iParticle - PFCandidates->begin());
00069             if(dau.isNonnull () && dau.isAvailable()){
00070                 reco::PFCandidatePtr pf(dau.id(), pfCandidate, dau.key());
00071                 pfsignalgo_.addPFCandidate(pf);
00072             }
00073           //metSigInputVector.push_back(resolutions_.evalPF(pfCandidate));
00074         }
00075 
00076         if (pfCandidate->particleId() == 1) ChargedHadEt += et;
00077         if (pfCandidate->particleId() == 2) ChargedEMEt += et;
00078         if (pfCandidate->particleId() == 3) MuonEt += et;
00079         if (pfCandidate->particleId() == 4) NeutralEMEt += et;
00080         if (pfCandidate->particleId() == 5) NeutralHadEt += et;
00081         if (pfCandidate->particleId() == 6) type6Et += et;
00082         if (pfCandidate->particleId() == 7) type7Et += et;
00083       }
00084     } 
00085   }
00086 
00087   const double Et_total=NeutralEMEt+NeutralHadEt+ChargedEMEt+ChargedHadEt+MuonEt+type6Et+type7Et;
00088 
00089   if (Et_total!=0.0)
00090   {
00091     specific.NeutralEMFraction = NeutralEMEt/Et_total;
00092     specific.NeutralHadFraction = NeutralHadEt/Et_total;
00093     specific.ChargedEMFraction = ChargedEMEt/Et_total;
00094     specific.ChargedHadFraction = ChargedHadEt/Et_total;
00095     specific.MuonFraction = MuonEt/Et_total;
00096     specific.Type6Fraction = type6Et/Et_total;
00097     specific.Type7Fraction = type7Et/Et_total;
00098   }
00099   
00100   const LorentzVector p4(met.mex , met.mey, 0.0, met.met);
00101   const Point vtx(0.0,0.0,0.0);
00102   PFMET specificPFMET( specific, met.sumet, p4, vtx );
00103 
00104   specificPFMET.setSignificanceMatrix(pfsignalgo_.getSignifMatrix());
00105 
00106   return specificPFMET;
00107 }
00108 
00109 void PFSpecificAlgo::runSignificance(metsig::SignAlgoResolutions &resolutions, edm::Handle<edm::View<reco::PFJet> > jets)
00110 {
00111   alsocalcsig=true;
00112   pfsignalgo_.setResolutions( &resolutions );
00113   pfsignalgo_.addPFJets(jets);
00114 }