CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BJetEnergyRegressionMVA.cc
Go to the documentation of this file.
1 //
2 // Original Author: Andre Rizzi
3 // Created: Mon, 07 Sep 2017 09:18:03 GMT
4 //
5 //
6 
9 
12 
15 
19 
22 
26 
28 #include <vector>
29 
31 public:
33  : BaseMVAValueMapProducer<pat::Jet>(iConfig, cache),
34  pvsrc_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("pvsrc"))),
35  svsrc_(consumes<edm::View<reco::VertexCompositePtrCandidate>>(iConfig.getParameter<edm::InputTag>("svsrc"))),
36  rhosrc_(consumes<double>(iConfig.getParameter<edm::InputTag>("rhosrc"))) {}
37 
39  iEvent.getByToken(pvsrc_, pvs_);
40  iEvent.getByToken(svsrc_, svs_);
41  iEvent.getByToken(rhosrc_, rho_);
42  }
43 
44  void fillAdditionalVariables(const pat::Jet& j) override {
45  this->setValue("nPVs", pvs_->size());
46  this->setValue("rho", *(rho_.product()));
47 
48  float cone_boundaries[] = {0.05, 0.1, 0.2, 0.3, 0.4};
49  size_t ncone_boundaries = sizeof(cone_boundaries) / sizeof(float);
50  std::vector<float> emFractionEnergyRings(ncone_boundaries + 1);
51  std::vector<float> chFractionEnergyRings(ncone_boundaries + 1);
52  std::vector<float> neFractionEnergyRings(ncone_boundaries + 1);
53  std::vector<float> muFractionEnergyRings(ncone_boundaries + 1);
54  float jetRawEnergy = j.p4().E() * j.jecFactor("Uncorrected");
55  int numDaughtersPt03 = 0;
56  for (unsigned int ijcone = 0; ijcone < ncone_boundaries; ijcone++) {
57  emFractionEnergyRings[ijcone] = 0;
58  muFractionEnergyRings[ijcone] = 0;
59  chFractionEnergyRings[ijcone] = 0;
60  neFractionEnergyRings[ijcone] = 0;
61  }
62  for (const auto& d : j.daughterPtrVector()) {
63  float candDr = Geom::deltaR(d->p4(), j.p4());
64  size_t icone =
65  std::lower_bound(&cone_boundaries[0], &cone_boundaries[ncone_boundaries], candDr) - &cone_boundaries[0];
66  float candEnergy = d->energy() / jetRawEnergy;
67  int pdgid = abs(d->pdgId());
68  if (pdgid == 22 || pdgid == 11) {
69  emFractionEnergyRings[icone] += candEnergy;
70  } else if (pdgid == 13) {
71  muFractionEnergyRings[icone] += candEnergy;
72  } else if (d->charge() != 0) {
73  chFractionEnergyRings[icone] += candEnergy;
74  } else {
75  neFractionEnergyRings[icone] += candEnergy;
76  }
77  if (d->pt() > 0.3)
78  numDaughtersPt03 += 1;
79  } // end of jet daughters loop
80 
81  this->setValue("Jet_energyRing_dR0_em_Jet_rawEnergy", emFractionEnergyRings[0]);
82  this->setValue("Jet_energyRing_dR1_em_Jet_rawEnergy", emFractionEnergyRings[1]);
83  this->setValue("Jet_energyRing_dR2_em_Jet_rawEnergy", emFractionEnergyRings[2]);
84  this->setValue("Jet_energyRing_dR3_em_Jet_rawEnergy", emFractionEnergyRings[3]);
85  this->setValue("Jet_energyRing_dR4_em_Jet_rawEnergy", emFractionEnergyRings[4]);
86  // this->setValue("Jet_energyRing_dR5_em_Jet_rawEnergy", emFractionEnergyRings[5]);
87 
88  this->setValue("Jet_energyRing_dR0_ch_Jet_rawEnergy", chFractionEnergyRings[0]);
89  this->setValue("Jet_energyRing_dR1_ch_Jet_rawEnergy", chFractionEnergyRings[1]);
90  this->setValue("Jet_energyRing_dR2_ch_Jet_rawEnergy", chFractionEnergyRings[2]);
91  this->setValue("Jet_energyRing_dR3_ch_Jet_rawEnergy", chFractionEnergyRings[3]);
92  this->setValue("Jet_energyRing_dR4_ch_Jet_rawEnergy", chFractionEnergyRings[4]);
93  // this->setValue("Jet_energyRing_dR5_ch_Jet_rawEnergy", chFractionEnergyRings[5]);
94 
95  this->setValue("Jet_energyRing_dR0_mu_Jet_rawEnergy", muFractionEnergyRings[0]);
96  this->setValue("Jet_energyRing_dR1_mu_Jet_rawEnergy", muFractionEnergyRings[1]);
97  this->setValue("Jet_energyRing_dR2_mu_Jet_rawEnergy", muFractionEnergyRings[2]);
98  this->setValue("Jet_energyRing_dR3_mu_Jet_rawEnergy", muFractionEnergyRings[3]);
99  this->setValue("Jet_energyRing_dR4_mu_Jet_rawEnergy", muFractionEnergyRings[4]);
100  // this->setValue("Jet_energyRing_dR5_mu_Jet_rawEnergy", muFractionEnergyRings[5]);
101 
102  this->setValue("Jet_energyRing_dR0_neut_Jet_rawEnergy", neFractionEnergyRings[0]);
103  this->setValue("Jet_energyRing_dR1_neut_Jet_rawEnergy", neFractionEnergyRings[1]);
104  this->setValue("Jet_energyRing_dR2_neut_Jet_rawEnergy", neFractionEnergyRings[2]);
105  this->setValue("Jet_energyRing_dR3_neut_Jet_rawEnergy", neFractionEnergyRings[3]);
106  this->setValue("Jet_energyRing_dR4_neut_Jet_rawEnergy", neFractionEnergyRings[4]);
107  // this->setValue("Jet_energyRing_dR5_neut_Jet_rawEnergy", neFractionEnergyRings[5]);
108 
109  this->setValue("Jet_numDaughters_pt03", numDaughtersPt03);
110  }
111 
114  desc.add<edm::InputTag>("pvsrc")->setComment("primary vertices input collection");
115  desc.add<edm::InputTag>("svsrc")->setComment("secondary vertices input collection");
116  desc.add<edm::InputTag>("rhosrc")->setComment("rho input collection");
117  descriptions.add("BJetEnergyRegressionMVA", desc);
118  }
119 
120 private:
127 };
128 
129 //define this as a plug-in
static edm::ParameterSetDescription getDescription()
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setValue(const std::string var, float val)
const LorentzVector & p4() const final
four-momentum Lorentz vector
tuple d
Definition: ztail.py:151
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< edm::View< reco::VertexCompositePtrCandidate > > svsrc_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
BJetEnergyRegressionMVA(const edm::ParameterSet &iConfig, const BaseMVACache *cache)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::Handle< std::vector< reco::Vertex > > pvs_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::Handle< edm::View< reco::VertexCompositePtrCandidate > > svs_
edm::EDGetTokenT< double > rhosrc_
const edm::EDGetTokenT< std::vector< reco::Vertex > > pvsrc_
T const * product() const
Definition: Handle.h:70
Analysis-level calorimeter jet class.
Definition: Jet.h:77
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const reco::CompositePtrCandidate::daughters & daughterPtrVector() const override
references to daughtes
void readAdditionalCollections(edm::Event &iEvent, const edm::EventSetup &) override
to be implemented in derived classes, filling values for additional variables
constexpr char Jet[]
Definition: modules.cc:9
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
float jecFactor(const std::string &level, const std::string &flavor="none", const std::string &set="") const
def cache
Definition: utilities.py:3
void fillAdditionalVariables(const pat::Jet &j) override