CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoJets/FFTJetProducers/src/FFTJetInterface.cc

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 #include "FWCore/Utilities/interface/isFinite.h"
00007 
00008 #include "DataFormats/JetReco/interface/Jet.h"
00009 #include "DataFormats/CaloTowers/interface/CaloTower.h"
00010 #include "DataFormats/VertexReco/interface/Vertex.h"
00011 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00012 
00013 #define init_param(type, varname) varname (ps.getParameter< type >( #varname ))
00014 
00015 namespace fftjetcms {
00016 
00017 bool FFTJetInterface::storeInSinglePrecision() const 
00018 {
00019     return true;
00020 }
00021 
00022 
00023 FFTJetInterface::FFTJetInterface(const edm::ParameterSet& ps)
00024     : inputLabel(ps.getParameter<edm::InputTag>("src")),
00025       init_param(std::string, outputLabel),
00026       jetType(parseJetType(ps.getParameter<std::string>("jetType"))),
00027       init_param(bool, doPVCorrection),
00028       init_param(edm::InputTag, srcPVs),
00029       etaDependentMagnutideFactors(
00030           ps.getParameter<std::vector<double> >(
00031               "etaDependentMagnutideFactors")),
00032       init_param(edm::ParameterSet, anomalous),
00033       init_param(bool, insertCompleteEvent),
00034       init_param(double, completeEventScale),
00035       vertex_(0.0, 0.0, 0.0)
00036 {
00037       if (insertCompleteEvent && completeEventScale <= 0.0)
00038         throw cms::Exception("FFTJetBadConfig")
00039           << "Bad scale for the complete event : must be positive"
00040           << std::endl;
00041 }
00042 
00043 
00044 double FFTJetInterface::getEventScale() const
00045 {
00046      return insertCompleteEvent ? completeEventScale : 0.0;
00047 }
00048 
00049 
00050 void FFTJetInterface::loadInputCollection(const edm::Event& iEvent)
00051 {
00052     // Figure out if we are going to perform the vertex adjustment
00053     const bool adjustForVertex = doPVCorrection && jetType == CALOJET;
00054 
00055     // Figure out the vertex
00056     if (adjustForVertex)
00057     {
00058         edm::Handle<reco::VertexCollection> pvCollection;
00059         iEvent.getByLabel(srcPVs, pvCollection);
00060         if (pvCollection->empty())
00061             vertex_ = reco::Particle::Point(0.0, 0.0, 0.0);
00062         else
00063             vertex_ = pvCollection->begin()->position();
00064     }
00065 
00066     // Get the input collection
00067     iEvent.getByLabel(inputLabel, inputCollection);
00068 
00069     // Create the set of 4-vectors needed by the algorithm
00070     eventData.clear();
00071     candidateIndex.clear();
00072     unsigned index = 0;
00073     const reco::CandidateView::const_iterator end = inputCollection->end();
00074     for (reco::CandidateView::const_iterator it = inputCollection->begin();
00075          it != end; ++it, ++index)
00076     {
00077         const reco::Candidate& item(*it);
00078         if (anomalous(item))
00079             continue;
00080         if (edm::isNotFinite(item.pt()))
00081             continue;
00082 
00083         if (adjustForVertex)
00084         {
00085             const CaloTower& tower(dynamic_cast<const CaloTower&>(item));
00086             eventData.push_back(VectorLike(tower.p4(vertex_)));
00087         }
00088         else
00089             eventData.push_back(item.p4());
00090         candidateIndex.push_back(index);
00091     }
00092     assert(eventData.size() == candidateIndex.size());
00093 }
00094 
00095 
00096 void FFTJetInterface::discretizeEnergyFlow()
00097 {
00098     // It is a bug to call this function before defining the energy flow grid
00099     assert(energyFlow.get());
00100 
00101     fftjet::Grid2d<Real>& g(*energyFlow);
00102     g.reset();
00103 
00104     const unsigned nInputs = eventData.size();
00105     const VectorLike* inp = nInputs ? &eventData[0] : 0;
00106     for (unsigned i=0; i<nInputs; ++i)
00107     {
00108         const VectorLike& item(inp[i]);
00109         g.fill(item.Eta(), item.Phi(), item.Et());
00110     }
00111 
00112     if (!etaDependentMagnutideFactors.empty())
00113     {
00114         if (etaDependentMagnutideFactors.size() != g.nEta())
00115             throw cms::Exception("FFTJetBadConfig")
00116                 << "ERROR in FFTJetInterface::discretizeEnergyFlow() :"
00117                 " number of elements in the \"etaDependentMagnutideFactors\""
00118                 " vector is inconsistent with the grid binning"
00119                 << std::endl;
00120         g.scaleData(&etaDependentMagnutideFactors[0],
00121                     etaDependentMagnutideFactors.size());
00122     }
00123 }
00124 
00125 }