CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoParticleFlow/PFRootEvent/src/JetMaker.cc

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00007 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00008 #include "DataFormats/CaloTowers/interface/CaloTowerDetId.h"
00009 #include "DataFormats/RecoCandidate/interface/RecoCaloTowerCandidate.h"
00010 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00011 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00012 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00013 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00014 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00015 
00016 #include "RecoParticleFlow/PFRootEvent/interface/JetMaker.h"
00017 
00018 using namespace std;
00019 using namespace reco;
00020 
00021 bool JetMaker::makeSpecific (const JetReco::InputCollection& fTowers,
00022                              const CaloSubdetectorGeometry& fTowerGeometry,
00023                              CaloJet::Specific* fJetSpecific) {
00024   if (!fJetSpecific) return false;
00025   
00026   // 1.- Loop over the tower Ids, 
00027   // 2.- Get the corresponding CaloTower
00028   // 3.- Calculate the different CaloJet specific quantities
00029   vector<double> eECal_i;
00030   vector<double> eHCal_i;
00031   double eInHad = 0.;
00032   double eInEm = 0.;
00033   double eInHO = 0.;
00034   double eInHB = 0.;
00035   double eInHE = 0.;
00036   double eHadInHF = 0.;
00037   double eEmInHF = 0.;
00038   double eInEB = 0.;
00039   double eInEE = 0.;
00040   double jetArea = 0.;
00041   
00042   for (JetReco::InputCollection::const_iterator towerCand = fTowers.begin(); towerCand != fTowers.end(); ++towerCand) {
00043     const Candidate* candidate = towerCand->get ();
00044     if (candidate) {
00045       const CaloTower* tower = dynamic_cast<const CaloTower*> (candidate);
00046       if (tower) {
00047         //Array of energy in EM Towers:
00048         eECal_i.push_back(tower->emEnergy());
00049         eInEm += tower->emEnergy();
00050         //Array of energy in HCAL Towers:
00051         eHCal_i.push_back(tower->hadEnergy()); 
00052         eInHad += tower->hadEnergy();
00053         
00054         //  figure out contributions
00055         switch (JetMaker::hcalSubdetector (tower->id().ieta())) {
00056         case HcalBarrel:
00057           eInHB += tower->hadEnergy(); 
00058           eInHO += tower->outerEnergy();
00059           eInEB += tower->emEnergy();
00060           break;
00061         case HcalEndcap:
00062           eInHE += tower->hadEnergy();
00063           eInEE += tower->emEnergy();
00064           break;
00065         case HcalForward:
00066           eHadInHF += tower->hadEnergy();
00067           eEmInHF += tower->emEnergy();
00068           break;
00069         default:
00070           break;
00071         }
00072         // get area of the tower (++ minus --)
00073         if ( tower->energy() > 0 ) {
00074           const CaloCellGeometry* geometry = fTowerGeometry.getGeometry(tower->id());
00075           if (geometry) {
00076             float dEta = fabs (geometry->getCorners() [0].eta() - geometry->getCorners() [2].eta());
00077             float dPhi = fabs (geometry->getCorners() [0].phi() - geometry->getCorners() [2].phi());
00078             jetArea += dEta * dPhi;
00079           }
00080         }
00081         else {
00082           std::cerr << "JetMaker::makeSpecific (CaloJet)-> Geometry for cell " << tower->id() << " can not be found. Ignoring cell" << std::endl;
00083         }
00084       }
00085       else {
00086         std::cerr << "JetMaker::makeSpecific (CaloJet)-> Constituent is not of CaloTower type" << std::endl;
00087       }
00088     }
00089     else {
00090       std::cerr << "JetMaker::makeSpecific (CaloJet)-> Referred constituent is not available in the event" << std::endl;
00091     }
00092   }
00093   double towerEnergy = eInHad + eInEm;
00094   fJetSpecific->mHadEnergyInHO = eInHO;
00095   fJetSpecific->mHadEnergyInHB = eInHB;
00096   fJetSpecific->mHadEnergyInHE = eInHE;
00097   fJetSpecific->mHadEnergyInHF = eHadInHF;
00098   fJetSpecific->mEmEnergyInHF = eEmInHF;
00099   fJetSpecific->mEmEnergyInEB = eInEB;
00100   fJetSpecific->mEmEnergyInEE = eInEE;
00101   if (towerEnergy > 0) {
00102     fJetSpecific->mEnergyFractionHadronic = eInHad / towerEnergy;
00103     fJetSpecific->mEnergyFractionEm = eInEm / towerEnergy;
00104   }
00105   else { // HO only jet
00106     fJetSpecific->mEnergyFractionHadronic = 1.;
00107     fJetSpecific->mEnergyFractionEm = 0.;
00108   }
00109   fJetSpecific->mTowersArea = jetArea;
00110   fJetSpecific->mMaxEInEmTowers = 0;
00111   fJetSpecific->mMaxEInHadTowers = 0;
00112   
00113   //Sort the arrays
00114   sort(eECal_i.begin(), eECal_i.end(), greater<double>());
00115   sort(eHCal_i.begin(), eHCal_i.end(), greater<double>());
00116   
00117   if (!fTowers.empty ()) {  
00118     //Highest value in the array is the first element of the array
00119     fJetSpecific->mMaxEInEmTowers = eECal_i.front(); 
00120     fJetSpecific->mMaxEInHadTowers = eHCal_i.front();
00121     
00122   }
00123   return true;
00124 }
00125 
00127 bool JetMaker::makeSpecific (const JetReco::InputCollection& fPFCandidates,                
00128                    PFJet::Specific* fJetSpecific) {
00129   if (!fJetSpecific) return false;
00130   
00131   // 1.- Loop over PFCandidates, 
00132   // 2.- Get the corresponding PFCandidate
00133   // 3.- Calculate the different PFJet specific quantities
00134   
00135   float chargedHadronEnergy=0.;
00136   float neutralHadronEnergy=0.;
00137   float chargedEmEnergy=0.;
00138   float neutralEmEnergy=0.;
00139   float chargedMuEnergy=0.;
00140   int   chargedMultiplicity=0;
00141   int   neutralMultiplicity=0;
00142   int   muonMultiplicity=0;
00143   
00144   JetReco::InputCollection::const_iterator constituent = fPFCandidates.begin();
00145   for (; constituent != fPFCandidates.end(); ++constituent) {
00146     const Candidate* candidate = constituent->get ();
00147     if (candidate) {
00148       const PFCandidate* pfCand = dynamic_cast<const PFCandidate*> (candidate);
00149       if (pfCand) {
00150         switch ( PFCandidate::ParticleType (pfCand->particleId())) {
00151         case PFCandidate::h:       // charged hadron
00152           chargedHadronEnergy += pfCand->energy();
00153           chargedMultiplicity++;
00154           break;
00155           
00156         case PFCandidate::e:       // electron 
00157           chargedEmEnergy += pfCand->energy(); 
00158           chargedMultiplicity++;
00159           break;
00160           
00161         case PFCandidate::mu:      // muon
00162           chargedMuEnergy += pfCand->energy();
00163           chargedMultiplicity++;
00164           muonMultiplicity++;
00165           break;
00166           
00167         case PFCandidate::gamma:   // photon
00168         case PFCandidate::egamma_HF :    // electromagnetic in HF
00169           neutralEmEnergy += pfCand->energy();
00170           neutralMultiplicity++;
00171           break;
00172           
00173         case PFCandidate::h0 :    // neutral hadron
00174         case PFCandidate::h_HF :    // hadron in HF
00175           neutralHadronEnergy += pfCand->energy();
00176           neutralMultiplicity++;
00177           break;
00178           
00179         default:
00180           std::cerr << "JetMaker::makeSpecific (PFJetJet)-> Unknown PFCandidate::ParticleType: " << pfCand->particleId() << " is ignored" << std::endl;
00181           break;
00182         }
00183       }
00184       else {
00185         std::cerr << "JetMaker::makeSpecific (PFJetJet)-> Referred constituent is not PFCandidate" << std::endl;
00186       }
00187     }
00188     else {
00189       std::cerr << "JetMaker::makeSpecific (PFJetJet)-> Referred constituent is not available in the event" << std::endl;
00190     }
00191   }
00192   fJetSpecific->mChargedHadronEnergy=chargedHadronEnergy;
00193   fJetSpecific->mNeutralHadronEnergy= neutralHadronEnergy;
00194   fJetSpecific->mChargedEmEnergy=chargedEmEnergy;
00195   fJetSpecific->mChargedMuEnergy=chargedMuEnergy;
00196   fJetSpecific->mNeutralEmEnergy=neutralEmEnergy;
00197   fJetSpecific->mChargedMultiplicity=chargedMultiplicity;
00198   fJetSpecific->mNeutralMultiplicity=neutralMultiplicity;
00199   fJetSpecific->mMuonMultiplicity=muonMultiplicity;
00200   return true;
00201 }
00202 
00203 
00204 bool JetMaker::makeSpecific (const JetReco::InputCollection& fMcParticles, 
00205                    GenJet::Specific* fJetSpecific) {
00206   for (JetReco::InputCollection::const_iterator genCand = fMcParticles.begin(); genCand != fMcParticles.end(); ++genCand) {
00207     const Candidate* candidate = genCand->get ();
00208     if (candidate->hasMasterClone ()) candidate = candidate->masterClone().get ();
00209     if (candidate) {
00210       const GenParticle* genParticle = GenJet::genParticle (candidate);
00211       if (genParticle) {
00212         double e = genParticle->energy();
00213         switch (std::abs (genParticle->pdgId ())) {
00214         case 22: // photon
00215         case 11: // e
00216           fJetSpecific->m_EmEnergy += e;
00217           break;
00218         case 211: // pi
00219         case 321: // K
00220         case 130: // KL
00221         case 2212: // p
00222         case 2112: // n
00223           fJetSpecific->m_HadEnergy += e;
00224           break;
00225         case 13: // muon
00226         case 12: // nu_e
00227         case 14: // nu_mu
00228         case 16: // nu_tau
00229           
00230           fJetSpecific->m_InvisibleEnergy += e;
00231           break;
00232         default: 
00233           fJetSpecific->m_AuxiliaryEnergy += e;
00234         }
00235       }
00236       else {
00237         std::cerr << "JetMaker::makeSpecific (GenJet)-> Referred  GenParticleCandidate is not available in the event" << std::endl;
00238       }
00239     }
00240     else {
00241       std::cerr << "JetMaker::makeSpecific (GenJet)-> Referred constituent is not available in the event" << std::endl;
00242     }
00243   }
00244   return true;
00245 }
00246 
00247 HcalSubdetector JetMaker::hcalSubdetector (int fEta) {
00248   static const HcalTopology topology;
00249   int eta = std::abs (fEta);
00250   if (eta <= topology.lastHBRing()) return HcalBarrel;
00251   else if (eta <= topology.lastHERing()) return HcalEndcap;
00252   else if (eta <= topology.lastHFRing()) return HcalForward;
00253   return HcalEmpty;
00254 }
00255