CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoMET/METAlgorithms/src/GenSpecificAlgo.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    METAlgorithms
00004 // Class:      GenSpecificAlgo
00005 // 
00006 // Original Authors:  R. Cavanaugh (taken from F.Ratnikov, UMd)
00007 //          Created:  June 6, 2006
00008 // $Id: GenSpecificAlgo.cc,v 1.11 2013/05/03 18:53:44 salee Exp $
00009 //
00010 //
00011 //____________________________________________________________________________||
00012 #include "RecoMET/METAlgorithms/interface/GenSpecificAlgo.h"
00013 #include "TMath.h"
00014 
00015 #include <set>
00016 
00017 //____________________________________________________________________________||
00018 reco::GenMET GenSpecificAlgo::addInfo(edm::Handle<edm::View<reco::Candidate> > particles, CommonMETData *met, double globalThreshold, bool onlyFiducial,bool applyFiducialThresholdForFractions, bool usePt)
00019 { 
00020   fillCommonMETData(met, particles, globalThreshold, onlyFiducial, usePt);
00021 
00022   SpecificGenMETData specific = mkSpecificGenMETData(particles, globalThreshold, onlyFiducial, applyFiducialThresholdForFractions, usePt);
00023 
00024   const LorentzVector p4( met->mex, met->mey, met->mez, met->met );
00025   const Point vtx( 0.0, 0.0, 0.0 );
00026 
00027   reco::GenMET genMet(specific, met->sumet, p4, vtx );
00028   return genMet;
00029 }
00030 
00031 //____________________________________________________________________________||
00032 void GenSpecificAlgo::fillCommonMETData(CommonMETData *met, edm::Handle<edm::View<reco::Candidate> >& particles, double globalThreshold, bool onlyFiducial, bool usePt)
00033 {
00034   double sum_et = 0.0;
00035   double sum_ex = 0.0;
00036   double sum_ey = 0.0;
00037   double sum_ez = 0.0;
00038 
00039   for( edm::View<reco::Candidate>::const_iterator iParticle = (particles.product())->begin(); iParticle != (particles.product())->end(); ++iParticle)
00040     {
00041         if( (onlyFiducial && TMath::Abs(iParticle->eta()) >= 5.0)) continue;
00042 
00043         if( iParticle->et() <= globalThreshold  ) continue;
00044 
00045         if(usePt)
00046           {
00047             double phi = iParticle->phi();
00048             double et = iParticle->pt();
00049             sum_ez += iParticle->pz();
00050             sum_et += et;
00051             sum_ex += et*cos(phi);
00052             sum_ey += et*sin(phi);
00053           }
00054         else
00055           {
00056             double phi = iParticle->phi();
00057             double theta = iParticle->theta();
00058             double e = iParticle->energy();
00059             double et = e*sin(theta);
00060             sum_ez += e*cos(theta);
00061             sum_et += et;
00062             sum_ex += et*cos(phi);
00063             sum_ey += et*sin(phi);
00064           }
00065     }
00066   
00067   met->mex   = -sum_ex;
00068   met->mey   = -sum_ey;
00069   met->mez   = -sum_ez;
00070   met->met   = sqrt( sum_ex*sum_ex + sum_ey*sum_ey );
00071   met->sumet = sum_et;
00072   met->phi   = atan2( -sum_ey, -sum_ex );
00073 }
00074 
00075 //____________________________________________________________________________||
00076 SpecificGenMETData GenSpecificAlgo::mkSpecificGenMETData(edm::Handle<edm::View<reco::Candidate> >& particles,double globalThreshold, bool onlyFiducial,bool applyFiducialThresholdForFractions, bool usePt)
00077 {
00078   const static int neutralEMpdgId[] = { 22 /* photon */ };
00079   const static std::set<int> neutralEMpdgIdSet(neutralEMpdgId, neutralEMpdgId + sizeof(neutralEMpdgId)/sizeof(int));
00080 
00081   const static int chargedEMpdgId[] = { 11 /* e */ };
00082   const static std::set<int> chargedEMpdgIdSet(chargedEMpdgId, chargedEMpdgId + sizeof(chargedEMpdgId)/sizeof(int));
00083 
00084   const static int muonpdgId[] = { 13 /* muon */ };
00085   const static std::set<int> muonpdgIdSet(muonpdgId, muonpdgId + sizeof(muonpdgId)/sizeof(int));
00086 
00087   const static int neutralHADpdgId[] = {
00088     130  /* K_long          */,
00089     310  /* K_short         */,
00090     3122 /* Lambda          */,
00091     2112 /* n               */,
00092     3222 /* Neutral Cascade */
00093   };
00094   const static std::set<int> neutralHADpdgIdSet(neutralHADpdgId, neutralHADpdgId + sizeof(neutralHADpdgId)/sizeof(int));
00095 
00096   const static int chargedHADpdgId[] = {
00097     211  /* pi        */,
00098     321  /* K+/K-     */,
00099     2212 /* p         */,
00100     3312 /* Cascade - */,
00101     3112 /* Sigma -   */,
00102     3322 /* Sigma +   */,
00103     3334 /* Omega -   */
00104   };
00105   const static std::set<int> chargedHADpdgIdSet(chargedHADpdgId, chargedHADpdgId + sizeof(chargedHADpdgId)/sizeof(int));
00106 
00107   const static int invisiblepdgId[] = {
00108     12      /* e_nu            */,
00109     14      /* mu_nu           */,
00110     16      /* tau_nu          */,
00111     1000022 /* Neutral ~Chi_0  */,
00112     1000012 /* LH ~e_nu        */,
00113     1000014 /* LH ~mu_nu       */,
00114     1000016 /* LH ~tau_nu      */,
00115     2000012 /* RH ~e_nu        */,
00116     2000014 /* RH ~mu_nu       */,
00117     2000016 /* RH ~tau_nu      */,
00118     39      /* G               */,
00119     1000039 /* ~G              */,
00120     5100039 /* KK G            */,
00121     4000012 /* excited e_nu    */,
00122     4000014 /* excited mu_nu   */,
00123     4000016 /* excited tau_nu  */,
00124     9900012 /* Maj e_nu        */,
00125     9900014 /* Maj mu_nu       */,
00126     9900016 /* Maj tau_nu      */,
00127   };
00128   const static std::set<int> invisiblepdgIdSet(invisiblepdgId, invisiblepdgId + sizeof(invisiblepdgId)/sizeof(int));
00129   
00130   SpecificGenMETData specific = SpecificGenMETData();
00131   specific.NeutralEMEtFraction     = 0.0;
00132   specific.NeutralHadEtFraction    = 0.0;
00133   specific.ChargedEMEtFraction     = 0.0;
00134   specific.ChargedHadEtFraction    = 0.0;
00135   specific.MuonEtFraction          = 0.0;
00136   specific.InvisibleEtFraction     = 0.0;
00137   double Et_unclassified = 0.0;
00138   
00139   for(edm::View<reco::Candidate>::const_iterator iParticle = (particles.product())->begin(); iParticle != (particles.product())->end(); ++iParticle)
00140     {
00141       if(applyFiducialThresholdForFractions) if( onlyFiducial && (TMath::Abs(iParticle->eta()) >= 5.0) ) continue;
00142       if(applyFiducialThresholdForFractions) if( iParticle->et() <= globalThreshold ) continue;
00143 
00144       int pdgId = TMath::Abs( iParticle->pdgId() ) ;
00145       double pt = (usePt) ? iParticle->pt() : iParticle->et();
00146       if(neutralEMpdgIdSet.count(pdgId))       specific.NeutralEMEtFraction  += pt;
00147       else if(chargedEMpdgIdSet.count(pdgId))  specific.ChargedEMEtFraction  += pt;
00148       else if(muonpdgIdSet.count(pdgId))       specific.MuonEtFraction       += pt;
00149       else if(neutralHADpdgIdSet.count(pdgId)) specific.NeutralHadEtFraction += pt;
00150       else if(chargedHADpdgIdSet.count(pdgId)) specific.ChargedHadEtFraction += pt;
00151       else if(invisiblepdgIdSet.count(pdgId))  specific.InvisibleEtFraction  += pt;
00152       else Et_unclassified += pt;
00153     }
00154   
00155   double Et_Total = specific.NeutralEMEtFraction + specific.NeutralHadEtFraction + specific.ChargedEMEtFraction + 
00156     specific.ChargedHadEtFraction + specific.MuonEtFraction + specific.InvisibleEtFraction + Et_unclassified;
00157   
00158   if(Et_Total) 
00159     {
00160       specific.NeutralEMEtFraction /= Et_Total;
00161       specific.NeutralHadEtFraction /= Et_Total;
00162       specific.ChargedEMEtFraction /= Et_Total;
00163       specific.ChargedHadEtFraction /= Et_Total;
00164       specific.MuonEtFraction /= Et_Total;
00165       specific.InvisibleEtFraction /= Et_Total;
00166     }
00167 
00168   return specific;
00169 }
00170 
00171 //____________________________________________________________________________||