CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoParticleFlow/PFRootEvent/src/ProtoJet.cc

Go to the documentation of this file.
00001 //  ProtJet2.cc
00002 //  Revision History:  R. Harris 10/19/05  Modified to work with real CaloTowers from Jeremy Mans
00003 //
00004 // #include <stdio.h>
00005 // #include "stl_algobase.h"
00006 // #include "stl_algo.h"
00007 
00008 #include "DataFormats/Candidate/interface/Candidate.h"
00009 #include "RecoParticleFlow/PFRootEvent/interface/ProtoJet.h"
00010 #include "RecoParticleFlow/PFRootEvent/interface/JetAlgoHelper.h"
00011 
00012 #include <vector>
00013 #include <algorithm>               // include STL algorithm implementations
00014 #include <numeric>                 // For the use of numeric
00015 
00016 
00017 namespace {
00018   class ERecombination {
00019     public: inline double weight (const reco::Candidate& c) {return c.energy();}
00020   };
00021   class EtRecombination {
00022     public: inline double weight (const reco::Candidate& c) {return c.et();}
00023   };
00024   class PRecombination {
00025     public: inline double weight (const reco::Candidate& c) {return c.p();}
00026   };
00027   class PtRecombination {
00028     public: inline double weight (const reco::Candidate& c) {return c.pt();}
00029   };
00030 
00031   template <class T>
00032    inline ProtoJet::LorentzVector calculateLorentzVectorRecombination(const ProtoJet::Constituents& fConstituents) {
00033     T weightMaker;
00034     ProtoJet::LorentzVector result (0,0,0,0);
00035     double weights = 0;
00036     for(ProtoJet::Constituents::const_iterator i = fConstituents.begin(); i !=  fConstituents.end(); ++i) {
00037       const ProtoJet::Constituent c = *i;
00038       double weight = weightMaker.weight (*c);
00039       result += c->p4() * weight;
00040       weights += weight;
00041     } //end of loop over the jet constituents
00042     result = result / weights;
00043     return result;
00044   }
00045 
00046 }
00047 
00048 ProtoJet::ProtoJet()
00049   : mOrdered (false), 
00050     mJetArea (0), 
00051     mPileupEnergy (0), 
00052     mPassNumber (0) 
00053 {}
00054 
00055 ProtoJet::ProtoJet(const Constituents& fConstituents) 
00056   : mConstituents (fConstituents),
00057     mOrdered (false), 
00058     mJetArea (0), 
00059     mPileupEnergy (0), 
00060     mPassNumber (0) 
00061 {
00062   calculateLorentzVector(); 
00063 }
00064 
00065 ProtoJet::ProtoJet(const LorentzVector& fP4, const Constituents& fConstituents) 
00066   : mP4 (fP4), 
00067     mConstituents (fConstituents),
00068     mOrdered (false), 
00069     mJetArea (0), 
00070     mPileupEnergy (0), 
00071     mPassNumber (0) 
00072 
00073 {}
00074 
00075 void ProtoJet::setJetArea (float fArea) {mJetArea = fArea;}
00076 float ProtoJet::jetArea () const {return mJetArea;}
00077 void ProtoJet::setPileup (float fEnergy) {mPileupEnergy = fEnergy;}
00078 float ProtoJet::pileup () const {return mPileupEnergy;}
00079 void ProtoJet::setNPasses (int fPasses) {mPassNumber = fPasses;}
00080 int ProtoJet::nPasses () const {return mPassNumber;}
00081 
00082 const ProtoJet::Constituents& ProtoJet::getTowerList() {
00083   reorderTowers ();
00084   return mConstituents;
00085 }
00086   
00087 ProtoJet::Constituents ProtoJet::getTowerList() const {
00088   if (mOrdered) return mConstituents;
00089   ProtoJet::Constituents result (mConstituents);
00090   sortByEtRef (&result);
00091   return result;
00092 }
00093 
00094 const ProtoJet::Constituents& ProtoJet::getPresortedTowerList() const {
00095   if (!mOrdered) std::cerr << "ProtoJet::getPresortedTowerList-> ERROR: constituents are not sorted." << std::endl;
00096   return mConstituents;
00097 }
00098 
00099 void ProtoJet::putTowers(const Constituents& towers) {
00100   mConstituents = towers; 
00101   mOrdered = false;
00102   calculateLorentzVector();
00103 }
00104 
00105 void ProtoJet::reorderTowers () {
00106   if (!mOrdered) {
00107     sortByEtRef (&mConstituents);
00108     mOrdered = true;
00109   }
00110 }
00111 
00112 void ProtoJet::calculateLorentzVectorERecombination() {
00113   mP4 = LorentzVector (0,0,0,0);
00114   for(Constituents::const_iterator i = mConstituents.begin(); i !=  mConstituents.end(); ++i) {
00115     const Constituent c = *i;
00116     mP4 += c->p4();
00117   } //end of loop over the jet constituents
00118 }
00119 
00120 void ProtoJet::calculateLorentzVectorEtRecombination() {
00121   mP4 = calculateLorentzVectorRecombination <EtRecombination> (mConstituents);
00122 }
00123 
00124