Imperial Analysis
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ICJetFlavourCalculator.cc
Go to the documentation of this file.
2 #include <vector>
3 #include "FWCore/Framework/interface/Event.h"
4 #include "FWCore/Framework/interface/EventSetup.h"
5 #include "FWCore/Framework/interface/MakerMacros.h"
6 #include "FWCore/ParameterSet/interface/ParameterSet.h"
7 #include "FWCore/Utilities/interface/InputTag.h"
8 #include "DataFormats/Common/interface/Handle.h"
9 #include "DataFormats/Common/interface/ValueMap.h"
10 #include "SimDataFormats/JetMatching/interface/JetFlavourInfoMatching.h"
11 #include "SimDataFormats/JetMatching/interface/JetFlavourMatching.h"
13 
15  const edm::ParameterSet& config)
16  : input_(config.getParameter<edm::InputTag>("input")),
17  input_jet_flavour_(config.getParameter<edm::InputTag>("flavourMap")) {
18  consumes<edm::View<reco::Jet>>(input_);
19  #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION==7 && CMSSW_MINOR_VERSION >=4)
20  consumes<reco::JetFlavourInfoMatchingCollection>(input_jet_flavour_);
21  #else
22  consumes<reco::JetFlavourMatchingCollection>(input_jet_flavour_);
23  #endif
24  produces<edm::ValueMap<std::vector<int>> >();
25 }
26 
28 
29 void ICJetFlavourCalculator::produce(edm::Event& event,
30  const edm::EventSetup& setup) {
31  std::auto_ptr<edm::ValueMap<std::vector<int>> > product(new edm::ValueMap<std::vector<int>>());
32  edm::Handle <edm::View <reco::Jet> > jets_handle;
33  event.getByLabel(input_, jets_handle);
34 
35 #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION==7 && CMSSW_MINOR_VERSION >=4 )
36  edm::Handle<reco::JetFlavourInfoMatchingCollection> flavour_handle;
37 #else
38  edm::Handle<reco::JetFlavourMatchingCollection> flavour_handle;
39 #endif
40  event.getByLabel(input_jet_flavour_, flavour_handle);
41 
42  std::vector<int> dummy_vec(2,0);
43  std::vector<std::vector<int>> values(jets_handle->size(), dummy_vec);
44  for (unsigned i = 0; i < jets_handle->size(); ++i) {
45 #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION==7 && CMSSW_MINOR_VERSION>=4)
46  values[i].at(0) = (*flavour_handle)[jets_handle->refAt(i)].getPartonFlavour();
47  values[i].at(1) = (*flavour_handle)[jets_handle->refAt(i)].getHadronFlavour();
48 #else
49  values[i].at(0) = (*flavour_handle)[jets_handle->refAt(i)].getFlavour();
50 #endif
51  }
52 
53  edm::ValueMap<std::vector<int>>::Filler filler(*product);
54  filler.insert(jets_handle, values.begin(), values.end());
55  filler.fill();
56 
57  event.put(product);
58 }
59 
60 void ICJetFlavourCalculator::beginJob() {}
61 
62 void ICJetFlavourCalculator::endJob() {}
63 
64 // define this as a plug-in
ICJetFlavourCalculator(const edm::ParameterSet &)
DEFINE_FWK_MODULE(ICJetFlavourCalculator)
Definition: Consumes.h:19