CMS 3D CMS Logo

FFTJetInterface.cc
Go to the documentation of this file.
1 #include <cassert>
2 
4 
7 
10 
11 #define init_param(type, varname) varname(ps.getParameter<type>(#varname))
12 
13 namespace fftjetcms {
14 
15  bool FFTJetInterface::storeInSinglePrecision() const { return true; }
16 
18  : edm::EDProducer(),
19  inputLabel(ps.getParameter<edm::InputTag>("src")),
21  jetType(parseJetType(ps.getParameter<std::string>("jetType"))),
24  etaDependentMagnutideFactors(ps.getParameter<std::vector<double> >("etaDependentMagnutideFactors")),
28  vertex_(0.0, 0.0, 0.0) {
30  throw cms::Exception("FFTJetBadConfig") << "Bad scale for the complete event : must be positive" << std::endl;
31 
32  inputToken = consumes<reco::CandidateView>(inputLabel);
33 
34  if (doPVCorrection && jetType == CALOJET)
35  srcPVsToken = consumes<reco::VertexCollection>(srcPVs);
36  }
37 
39 
41  // Figure out if we are going to perform the vertex adjustment
42  const bool adjustForVertex = doPVCorrection && jetType == CALOJET;
43 
44  // Figure out the vertex
45  if (adjustForVertex) {
47  iEvent.getByToken(srcPVsToken, pvCollection);
48  if (pvCollection->empty())
49  vertex_ = reco::Particle::Point(0.0, 0.0, 0.0);
50  else
51  vertex_ = pvCollection->begin()->position();
52  }
53 
54  // Get the input collection
55  iEvent.getByToken(inputToken, inputCollection);
56 
57  // Create the set of 4-vectors needed by the algorithm
58  eventData.clear();
59  candidateIndex.clear();
60  unsigned index = 0;
62  for (reco::CandidateView::const_iterator it = inputCollection->begin(); it != end; ++it, ++index) {
63  const reco::Candidate& item(*it);
64  if (anomalous(item))
65  continue;
66  if (edm::isNotFinite(item.pt()))
67  continue;
68 
69  if (adjustForVertex) {
70  const CaloTower& tower(dynamic_cast<const CaloTower&>(item));
71  eventData.push_back(VectorLike(tower.p4(vertex_)));
72  } else
73  eventData.push_back(item.p4());
74  candidateIndex.push_back(index);
75  }
76  assert(eventData.size() == candidateIndex.size());
77  }
78 
80  // It is a bug to call this function before defining the energy flow grid
81  assert(energyFlow.get());
82 
83  fftjet::Grid2d<Real>& g(*energyFlow);
84  g.reset();
85 
86  const unsigned nInputs = eventData.size();
87  const VectorLike* inp = nInputs ? &eventData[0] : nullptr;
88  for (unsigned i = 0; i < nInputs; ++i) {
89  const VectorLike& item(inp[i]);
90  g.fill(item.Eta(), item.Phi(), item.Et());
91  }
92 
93  if (!etaDependentMagnutideFactors.empty()) {
94  if (etaDependentMagnutideFactors.size() != g.nEta())
95  throw cms::Exception("FFTJetBadConfig") << "ERROR in FFTJetInterface::discretizeEnergyFlow() :"
96  " number of elements in the \"etaDependentMagnutideFactors\""
97  " vector is inconsistent with the grid binning"
98  << std::endl;
100  }
101  }
102 
103 } // namespace fftjetcms
edm::EDGetTokenT< reco::CandidateView > inputToken
const edm::InputTag inputLabel
edm::Handle< reco::CandidateView > inputCollection
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
void loadInputCollection(const edm::Event &)
const edm::InputTag srcPVs
assert(be >=bs)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
int iEvent
Definition: GenABIO.cc:224
std::vector< unsigned > candidateIndex
reco::Particle::Point vertex_
std::unique_ptr< fftjet::Grid2d< fftjetcms::Real > > energyFlow
math::XYZTLorentzVector VectorLike
const std::vector< double > etaDependentMagnutideFactors
edm::EDGetTokenT< reco::VertexCollection > srcPVsToken
math::XYZPoint Point
point in the space
Definition: Particle.h:25
const AnomalousTower anomalous
JetType parseJetType(const std::string &name)
Definition: JetType.cc:5
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
#define init_param(type, varname)
std::vector< fftjetcms::VectorLike > eventData