CMS 3D CMS Logo

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 
16 
20 
23 
27 
29 #include <vector>
30 
32  public:
33  explicit BJetEnergyRegressionMVA(const edm::ParameterSet &iConfig):
34  BaseMVAValueMapProducer<pat::Jet>(iConfig),
35  pvsrc_(edm::stream::EDProducer<>::consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("pvsrc"))),
36  svsrc_(edm::stream::EDProducer<>::consumes<edm::View<reco::VertexCompositePtrCandidate>> (iConfig.getParameter<edm::InputTag>("svsrc")))
37 
38  {
39 
40 
41  }
43  iEvent.getByToken(pvsrc_, pvs_);
44  iEvent.getByToken(svsrc_, svs_);
45  }
46 
47  void fillAdditionalVariables(const pat::Jet&j) override {
48  this->setValue("nPVs",pvs_->size());
50 
51  if(!j.overlaps("muons").empty()) {
52  const auto *lep=dynamic_cast<const pat::Muon *>(&*j.overlaps("muons")[0]);
53  if(lep!=nullptr) {BaseMVAValueMapProducer<pat::Jet>::setValue("Jet_leptonPtRel",lep->userFloat("ptRel"));}
54  }
55  else if(!j.overlaps("electrons").empty()) {
56  const auto *lep=dynamic_cast<const pat::Electron *>(&*j.overlaps("electrons")[0]);
57  if(lep!=nullptr) {BaseMVAValueMapProducer<pat::Jet>::setValue("Jet_leptonPtRel",lep->userFloat("ptRel"));}
58  }
59 
60  float ptMax=0;
61  for(const auto & d : j.daughterPtrVector()){if(d->pt()>ptMax) ptMax=d->pt();}
62  BaseMVAValueMapProducer<pat::Jet>::setValue("Jet_leadTrackPt",ptMax);
63 
64  //Fill vertex properties
65  VertexDistance3D vdist;
66  float maxFoundSignificance=0;
67  const auto & pv = (*pvs_)[0];
68  this->setValue("Jet_vtxPt",0);
69  this->setValue("Jet_vtxMass",0);
70  this->setValue("Jet_vtx3dL",0);
71  this->setValue("Jet_vtx3deL",0);
72  this->setValue("Jet_vtxNtrk",0);
73 
74  for(const auto &sv: *svs_){
75  GlobalVector flightDir(sv.vertex().x() - pv.x(), sv.vertex().y() - pv.y(),sv.vertex().z() - pv.z());
76  GlobalVector jetDir(j.px(),j.py(),j.pz());
77  if( Geom::deltaR2( flightDir, jetDir ) < 0.09 ){
79  if(dl.significance() > maxFoundSignificance){
80  maxFoundSignificance=dl.significance();
81  this->setValue("Jet_vtxPt",sv.pt());
82  this->setValue("Jet_vtxMass",sv.p4().M());
83  this->setValue("Jet_vtx3dL",dl.value());
84  this->setValue("Jet_vtx3deL",dl.error());
85  this->setValue("Jet_vtxNtrk",sv.numberOfSourceCandidatePtrs());
86  }
87  }
88  }
89 
90  }
91 
92  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
94  desc.add<edm::InputTag>("pvsrc")->setComment("primary vertices input collection");
95  desc.add<edm::InputTag>("svsrc")->setComment("secondary vertices input collection");
96  descriptions.add("BJetEnergyRegressionMVA",desc);
97  }
98 
99  private:
104 
105 };
106 
107 //define this as a plug-in
109 
static edm::ParameterSetDescription getDescription()
reco::Vertex::Point convertPos(const GlobalPoint &p)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double px() const final
x coordinate of momentum vector
bool empty() const
Is the RefVector empty.
Definition: PtrVectorBase.h:71
reco::Vertex::Error convertError(const GlobalError &ge)
Definition: ConvertError.h:8
double error() const
Definition: Measurement1D.h:30
void setValue(const std::string var, float val)
Definition: HeavyIon.h:7
const reco::CandidatePtrVector & overlaps(const std::string &label) const
Definition: PATObject.h:742
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
int iEvent
Definition: GenABIO.cc:230
Definition: Jet.py:1
double pz() const final
z coordinate of momentum vector
const edm::EDGetTokenT< edm::View< reco::VertexCompositePtrCandidate > > svsrc_
def pv(vc)
Definition: MetAnalyzer.py:6
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_
double significance() const
Definition: Measurement1D.h:32
const edm::EDGetTokenT< std::vector< reco::Vertex > > pvsrc_
Analysis-level electron class.
Definition: Electron.h:52
double py() const final
y coordinate of momentum vector
Analysis-level calorimeter jet class.
Definition: Jet.h:80
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double value() const
Definition: Measurement1D.h:28
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
BJetEnergyRegressionMVA(const edm::ParameterSet &iConfig)
void readAdditionalCollections(edm::Event &iEvent, const edm::EventSetup &) override
to be implemented in derived classes, filling values for additional variables
fixed size matrix
HLT enums.
const daughters & daughterPtrVector() const
references to daughtes
Analysis-level muon class.
Definition: Muon.h:50
void fillAdditionalVariables(const pat::Jet &j) override