00001 #include "fastjet/PseudoJet.hh"
00002 #include "fastjet/ClusterSequence.hh"
00003 #include "fastjet/ClusterSequenceActiveArea.hh"
00004
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "DataFormats/Candidate/interface/Candidate.h"
00007 #include "RecoJets/JetAlgorithms/interface/ProtoJet.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009
00010 #include "RecoJets/JetAlgorithms/interface/FastJetBaseWrapper.h"
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 FastJetBaseWrapper::FastJetBaseWrapper(const edm::ParameterSet& fConfig)
00025 : mJetDefinition (0),
00026 mActiveArea (0)
00027 {
00028 mJetPtMin = fConfig.getParameter<double> ("jetPtMin");
00029 if (fConfig.getParameter<std::string> ("UE_Subtraction") == "yes") {
00030 double ghostEtaMax = fConfig.getParameter<double> ("Ghost_EtaMax");
00031 int activeAreaRepeats = fConfig.getParameter<int> ("Active_Area_Repeats");
00032 double ghostArea = fConfig.getParameter<double> ("GhostArea");
00033 mActiveArea = new fastjet::ActiveAreaSpec (ghostEtaMax, activeAreaRepeats, ghostArea);
00034 }
00035 }
00036
00037
00038 FastJetBaseWrapper::~FastJetBaseWrapper(){
00039 delete mJetDefinition;
00040 delete mActiveArea;
00041 }
00042
00043 void FastJetBaseWrapper::run(const JetReco::InputCollection& fInput, JetReco::OutputCollection* fOutput) {
00044 if (!fOutput) return;
00045 fOutput->clear();
00046
00047
00048 std::vector<fastjet::PseudoJet> fjInputs;
00049 fjInputs.reserve (fInput.size());
00050
00051 JetReco::InputCollection::const_iterator input = fInput.begin();
00052 for (unsigned i = 0; i < fInput.size(); ++i) {
00053 const JetReco::InputItem& c = fInput[i];
00054 fjInputs.push_back (fastjet::PseudoJet (c->px(),c->py(),c->pz(),c->energy()));
00055 fjInputs.back().set_user_index(i);
00056 }
00057
00058
00059
00060
00061
00062
00063 fastjet::ClusterSequenceActiveArea* clusterSequenceWithArea = 0;
00064 fastjet::ClusterSequenceWithArea* clusterSequence = 0;
00065 if (mActiveArea) {
00066 clusterSequenceWithArea = new fastjet::ClusterSequenceActiveArea (fjInputs, *mJetDefinition, *mActiveArea);
00067 clusterSequence = clusterSequenceWithArea;
00068 }
00069 else {
00070 clusterSequence = new fastjet::ClusterSequenceWithArea (fjInputs, *mJetDefinition);
00071 }
00072
00073 std::vector<fastjet::PseudoJet> jets = clusterSequence->inclusive_jets (mJetPtMin);
00074
00075
00076 double median_Pt_Per_Area = clusterSequenceWithArea ? clusterSequenceWithArea->pt_per_unit_area() : 0.;
00077
00078
00079 for (std::vector<fastjet::PseudoJet>::const_iterator jet=jets.begin(); jet!=jets.end();++jet) {
00080
00081 double px=jet->px();
00082 double py=jet->py();
00083 double pz=jet->pz();
00084 double E=jet->E();
00085 double jetArea=clusterSequence->area(*jet);
00086 double pu=0.;
00087
00088 if (clusterSequenceWithArea) {
00089 fastjet::PseudoJet pu_p4 = median_Pt_Per_Area * clusterSequenceWithArea->area_4vector(*jet);
00090 pu = pu_p4.E();
00091 if (pu_p4.perp2() >= jet->perp2() || pu_p4.E() >= jet->E()) {
00092 px = py = pz = E = 0.;
00093 }
00094 else {
00095 px -= pu_p4.px();
00096 py -= pu_p4.py();
00097 pz -= pu_p4.pz();
00098 E -= pu_p4.E();
00099 }
00100 }
00101 math::XYZTLorentzVector p4(px,py,pz,E);
00102
00103 std::vector<fastjet::PseudoJet> fastjet_constituents = clusterSequence->constituents(*jet);
00104 JetReco::InputCollection jetConstituents;
00105 jetConstituents.reserve (fastjet_constituents.size());
00106 for (std::vector<fastjet::PseudoJet>::const_iterator itConst=fastjet_constituents.begin();
00107 itConst!=fastjet_constituents.end();itConst++){
00108 jetConstituents.push_back(fInput[(*itConst).user_index()]);
00109 }
00110
00111 fOutput->push_back(ProtoJet(p4,jetConstituents));
00112 fOutput->back().setJetArea (jetArea);
00113 fOutput->back().setPileup (pu);
00114 }
00115
00116 if (clusterSequenceWithArea) delete clusterSequenceWithArea;
00117 else delete clusterSequence;
00118 }
00119
00120