Go to the documentation of this file.00001 #include <cassert>
00002
00003 #include "RecoJets/FFTJetProducers/interface/FFTJetInterface.h"
00004
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006
00007 #include "DataFormats/JetReco/interface/Jet.h"
00008 #include "DataFormats/CaloTowers/interface/CaloTower.h"
00009 #include "DataFormats/VertexReco/interface/Vertex.h"
00010 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00011
00012 #define init_param(type, varname) varname (ps.getParameter< type >( #varname ))
00013
00014 using namespace fftjetcms;
00015
00016 namespace fftjetcms {
00017
00018 bool FFTJetInterface::storeInSinglePrecision() const
00019 {
00020 return true;
00021 }
00022
00023
00024 FFTJetInterface::JetType FFTJetInterface::parse_jet_type(
00025 const std::string& name)
00026 {
00027 if (!name.compare("BasicJet"))
00028 return BASICJET;
00029 else if (!name.compare("GenJet"))
00030 return GENJET;
00031 else if (!name.compare("CaloJet"))
00032 return CALOJET;
00033 else if (!name.compare("PFJet"))
00034 return PFJET;
00035 else if (!name.compare("TrackJet"))
00036 return TRACKJET;
00037 else if (!name.compare("JPTJet"))
00038 return JPTJET;
00039 else
00040 throw cms::Exception("FFTJetBadConfig")
00041 << "Unsupported jet type specification \""
00042 << name << "\"" << std::endl;
00043 }
00044
00045
00046 FFTJetInterface::FFTJetInterface(const edm::ParameterSet& ps)
00047 : inputLabel(ps.getParameter<edm::InputTag>("src")),
00048 init_param(std::string, outputLabel),
00049 jetType(parse_jet_type(ps.getParameter<std::string>("jetType"))),
00050 init_param(bool, doPVCorrection),
00051 init_param(edm::InputTag, srcPVs),
00052 etaDependentMagnutideFactors(
00053 ps.getParameter<std::vector<double> >(
00054 "etaDependentMagnutideFactors")),
00055 init_param(edm::ParameterSet, anomalous),
00056 init_param(bool, insertCompleteEvent),
00057 init_param(double, completeEventScale),
00058 vertex_(0.0, 0.0, 0.0)
00059 {
00060 if (insertCompleteEvent && completeEventScale <= 0.0)
00061 throw cms::Exception("FFTJetBadConfig")
00062 << "Bad scale for the complete event : must be positive"
00063 << std::endl;
00064 }
00065
00066
00067 double FFTJetInterface::getEventScale() const
00068 {
00069 return insertCompleteEvent ? completeEventScale : 0.0;
00070 }
00071
00072
00073 void FFTJetInterface::loadInputCollection(const edm::Event& iEvent)
00074 {
00075
00076 const bool adjustForVertex = doPVCorrection && jetType == CALOJET;
00077
00078
00079 if (adjustForVertex)
00080 {
00081 edm::Handle<reco::VertexCollection> pvCollection;
00082 iEvent.getByLabel(srcPVs, pvCollection);
00083 if (pvCollection->empty())
00084 vertex_ = reco::Particle::Point(0.0, 0.0, 0.0);
00085 else
00086 vertex_ = pvCollection->begin()->position();
00087 }
00088
00089
00090 iEvent.getByLabel(inputLabel, inputCollection);
00091
00092
00093 eventData.clear();
00094 candidateIndex.clear();
00095 unsigned index = 0;
00096 const reco::CandidateView::const_iterator end = inputCollection->end();
00097 for (reco::CandidateView::const_iterator it = inputCollection->begin();
00098 it != end; ++it, ++index)
00099 {
00100 const reco::Candidate& item(*it);
00101 if (anomalous(item))
00102 continue;
00103 if (std::isnan(item.pt()))
00104 continue;
00105
00106 if (adjustForVertex)
00107 {
00108 const CaloTower& tower(dynamic_cast<const CaloTower&>(item));
00109 eventData.push_back(VectorLike(tower.p4(vertex_)));
00110 }
00111 else
00112 eventData.push_back(item.p4());
00113 candidateIndex.push_back(index);
00114 }
00115 assert(eventData.size() == candidateIndex.size());
00116 }
00117
00118
00119 void FFTJetInterface::discretizeEnergyFlow()
00120 {
00121
00122 assert(energyFlow.get());
00123
00124 fftjet::Grid2d<Real>& g(*energyFlow);
00125 g.reset();
00126
00127 const unsigned nInputs = eventData.size();
00128 const VectorLike* inp = nInputs ? &eventData[0] : 0;
00129 for (unsigned i=0; i<nInputs; ++i)
00130 {
00131 const VectorLike& item(inp[i]);
00132 g.fill(item.Eta(), item.Phi(), item.Et());
00133 }
00134
00135 if (!etaDependentMagnutideFactors.empty())
00136 {
00137 if (etaDependentMagnutideFactors.size() != g.nEta())
00138 throw cms::Exception("FFTJetBadConfig")
00139 << "ERROR in FFTJetInterface::discretizeEnergyFlow() :"
00140 " number of elements in the \"etaDependentMagnutideFactors\""
00141 " vector is inconsistent with the grid binning"
00142 << std::endl;
00143 g.scaleData(&etaDependentMagnutideFactors[0],
00144 etaDependentMagnutideFactors.size());
00145 }
00146 }
00147
00148 }