Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:35

0001 // -*- C++ -*-
0002 //
0003 // Package:    JetVertexAssociation
0004 // Class:      JetVertexAssociation
0005 //
0006 /**\class JetVertexAssociation JetVertexAssociation.cc JetMETCorrections/JetVertexAssociation/src/JetVertexAssociation.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Natalia Ilina
0015 // Modified by Eduardo Luiggi
0016 //
0017 //         Created:  Tue Oct 31 10:52:41 CET 2006
0018 //
0019 //
0020 
0021 /**
0022   * 'JetVertexAssociation' represents the association of the jet with the signal vertex
0023   *
0024   * Parameters of the method: JV_deltaZ, JV_alpha_threshold(alpha_0 or beta_0),
0025   *                           JV_cone_size, JV_type_Algo ("1" - alpha, "2" - beta) - (the details are in CMS NOTE 2006/091),
0026   *
0027   * Output: <pair<double, bool> >.
0028   *                    The first - variable alpha(beta) for the jet,
0029   *                    the second - "true" for jet from signal vertex, "false" for jet from pile-up.
0030   **/
0031 
0032 #include <memory>
0033 #include <iostream>
0034 #include <iomanip>
0035 #include <cmath>
0036 
0037 #include "FWCore/Framework/interface/Frameworkfwd.h"
0038 #include "FWCore/Framework/interface/EDProducer.h"
0039 #include "FWCore/Framework/interface/Event.h"
0040 
0041 #include "FWCore/PluginManager/interface/ModuleDef.h"
0042 #include "FWCore/Framework/interface/MakerMacros.h"
0043 
0044 #include "DataFormats/Common/interface/Handle.h"
0045 #include "FWCore/Framework/interface/EventSetup.h"
0046 #include "DataFormats/JetReco/interface/CaloJet.h"
0047 #include "DataFormats/VertexReco/interface/Vertex.h"
0048 
0049 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0050 #include "JetMETCorrections/JetVertexAssociation/interface/JetVertexAssociation.h"
0051 #include "JetMETCorrections/JetVertexAssociation/interface/JetVertexMain.h"
0052 
0053 using namespace std;
0054 using namespace reco;
0055 namespace cms {
0056 
0057   JetVertexAssociation::JetVertexAssociation(const edm::ParameterSet& iConfig)
0058       : m_algo(iConfig),
0059         jet_token(consumes<CaloJetCollection>(edm::InputTag(iConfig.getParameter<std::string>("JET_ALGO")))),
0060         track_token(consumes<TrackCollection>(edm::InputTag(iConfig.getParameter<std::string>("TRACK_ALGO")))),
0061         vertex_token(consumes<VertexCollection>(edm::InputTag(iConfig.getParameter<std::string>("VERTEX_ALGO")))) {
0062     produces<ResultCollection1>("Var");
0063     produces<ResultCollection2>("JetType");
0064   }
0065 
0066   void JetVertexAssociation::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0067     edm::Handle<CaloJetCollection> jets;
0068     iEvent.getByToken(jet_token, jets);
0069 
0070     edm::Handle<TrackCollection> tracks;
0071     iEvent.getByToken(track_token, tracks);
0072 
0073     edm::Handle<VertexCollection> vertexes;
0074     iEvent.getByToken(vertex_token, vertexes);
0075 
0076     double SIGNAL_V_Z = 0.;
0077     double SIGNAL_V_Z_ERROR = 0.;
0078     double ptmax = -100.;
0079 
0080     VertexCollection::const_iterator vert = vertexes->begin();
0081     if (!vertexes->empty()) {
0082       for (; vert != vertexes->end(); vert++) {
0083         SIGNAL_V_Z = vert->z();
0084         double pt = 0.;
0085         reco::Vertex::trackRef_iterator tr = vert->tracks_begin();
0086         for (; tr != vert->tracks_end(); tr++)
0087           pt += (*tr)->pt();
0088         if (pt >= ptmax) {
0089           ptmax = pt;
0090           SIGNAL_V_Z = vert->z();
0091           SIGNAL_V_Z_ERROR = vert->zError();
0092         }
0093       }
0094     }
0095 
0096     pair<double, bool> result;
0097     std::unique_ptr<ResultCollection1> result1(new ResultCollection1);
0098     std::unique_ptr<ResultCollection2> result2(new ResultCollection2);
0099 
0100     CaloJetCollection::const_iterator jet = jets->begin();
0101 
0102     if (!jets->empty()) {
0103       for (; jet != jets->end(); jet++) {
0104         result = m_algo.Main(*jet, tracks, SIGNAL_V_Z, SIGNAL_V_Z_ERROR);
0105         result1->push_back(result.first);
0106         result2->push_back(result.second);
0107       }
0108     }
0109 
0110     iEvent.put(std::move(result1), "Var");
0111     iEvent.put(std::move(result2), "JetType");
0112   }
0113 }  // namespace cms