Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:06

0001 //
0002 // Package:    EgammaHFProducers
0003 // Class:      HFRecoEcalCandidateProducers
0004 //
0005 /**\class HFRecoEcalCandidateProducers.cc  
0006 */
0007 //
0008 // Original Author:  Kevin Klapoetke University of Minnesota
0009 //         Created:  Wed 26 Sept 2007
0010 // $Id:
0011 //
0012 //
0013 
0014 #include "DataFormats/Common/interface/Handle.h"
0015 #include "DataFormats/EgammaReco/interface/HFEMClusterShape.h"
0016 #include "DataFormats/EgammaReco/interface/HFEMClusterShapeAssociation.h"
0017 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0018 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
0019 #include "DataFormats/VertexReco/interface/Vertex.h"
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/EventSetup.h"
0022 #include "FWCore/Framework/interface/stream/EDProducer.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/Utilities/interface/Exception.h"
0025 
0026 #include "HFRecoEcalCandidateAlgo.h"
0027 #include "HFValueStruct.h"
0028 
0029 #include <vector>
0030 #include <memory>
0031 
0032 class HFRecoEcalCandidateProducer : public edm::stream::EDProducer<> {
0033 public:
0034   explicit HFRecoEcalCandidateProducer(edm::ParameterSet const& conf);
0035   void produce(edm::Event& e, edm::EventSetup const& iSetup) override;
0036 
0037 private:
0038   std::vector<double> defaultDB_;
0039   edm::EDGetToken hfclustersSC_, hfclustersHFEM_, vertices_;
0040   int HFDBversion_;
0041   std::vector<double> HFDBvector_;
0042   bool doPU_;
0043   double Cut2D_;
0044   double defaultSlope2D_;
0045   reco::HFValueStruct hfvars_;
0046   HFRecoEcalCandidateAlgo algo_;
0047 };
0048 
0049 #include "FWCore/Framework/interface/MakerMacros.h"
0050 DEFINE_FWK_MODULE(HFRecoEcalCandidateProducer);
0051 
0052 HFRecoEcalCandidateProducer::HFRecoEcalCandidateProducer(edm::ParameterSet const& conf)
0053     : defaultDB_(std::vector<double>()),
0054       hfclustersSC_(consumes<reco::SuperClusterCollection>(conf.getParameter<edm::InputTag>("hfclusters"))),
0055       hfclustersHFEM_(
0056           consumes<reco::HFEMClusterShapeAssociationCollection>(conf.getParameter<edm::InputTag>("hfclusters"))),
0057 
0058       HFDBversion_(conf.existsAs<int>("HFDBversion") ? conf.getParameter<int>("HFDBversion") : 99),  //do nothing
0059       HFDBvector_(conf.existsAs<std::vector<double> >("HFDBvector")
0060                       ? conf.getParameter<std::vector<double> >("HFDBvector")
0061                       : defaultDB_),
0062       doPU_(false),
0063       Cut2D_(conf.getParameter<double>("intercept2DCut")),
0064       defaultSlope2D_(
0065           (Cut2D_ <= 0.83)
0066               ? (0.475)
0067               : ((Cut2D_ > 0.83 && Cut2D_ <= 0.9) ? (0.275) : (0.2))),  //fix for hlt unable to add slope variable now
0068       hfvars_(HFDBversion_, HFDBvector_),
0069       algo_(conf.existsAs<bool>("Correct") ? conf.getParameter<bool>("Correct") : true,
0070             conf.getParameter<double>("e9e25Cut"),
0071             conf.getParameter<double>("intercept2DCut"),
0072             conf.existsAs<double>("intercept2DSlope") ? conf.getParameter<double>("intercept2DSlope") : defaultSlope2D_,
0073             conf.getParameter<std::vector<double> >("e1e9Cut"),
0074             conf.getParameter<std::vector<double> >("eCOREe9Cut"),
0075             conf.getParameter<std::vector<double> >("eSeLCut"),
0076             hfvars_) {
0077   if (conf.existsAs<edm::InputTag>("VertexCollection")) {
0078     vertices_ = consumes<reco::VertexCollection>(conf.getParameter<edm::InputTag>("VertexCollection"));
0079   } else
0080     vertices_ = consumes<reco::VertexCollection>(edm::InputTag("offlinePrimaryVertices"));
0081 
0082   produces<reco::RecoEcalCandidateCollection>();
0083 }
0084 
0085 void HFRecoEcalCandidateProducer::produce(edm::Event& e, edm::EventSetup const& iSetup) {
0086   edm::Handle<reco::SuperClusterCollection> super_clus;
0087   edm::Handle<reco::HFEMClusterShapeAssociationCollection> hf_assoc;
0088 
0089   e.getByToken(hfclustersSC_, super_clus);
0090   e.getByToken(hfclustersHFEM_, hf_assoc);
0091 
0092   int nvertex = 0;
0093   if (HFDBversion_ != 99) {
0094     edm::Handle<reco::VertexCollection> pvHandle;
0095     e.getByToken(vertices_, pvHandle);
0096     const reco::VertexCollection& vertices = *pvHandle.product();
0097     static const int minNDOF = 4;
0098     static const double maxAbsZ = 15.0;
0099     static const double maxd0 = 2.0;
0100 
0101     //count verticies
0102 
0103     for (reco::VertexCollection::const_iterator vit = vertices.begin(); vit != vertices.end(); ++vit) {
0104       if (vit->ndof() > minNDOF && ((maxAbsZ <= 0) || fabs(vit->z()) <= maxAbsZ) &&
0105           ((maxd0 <= 0) || fabs(vit->position().rho()) <= maxd0))
0106         nvertex++;
0107     }
0108   } else {
0109     nvertex = 1;
0110   }
0111 
0112   // create return data
0113   auto retdata1 = std::make_unique<reco::RecoEcalCandidateCollection>();
0114 
0115   algo_.produce(super_clus, *hf_assoc, *retdata1, nvertex);
0116 
0117   e.put(std::move(retdata1));
0118 }