Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:21

0001 #ifndef __InitialClusteringStepBase_H__
0002 #define __InitialClusteringStepBase_H__
0003 
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "DataFormats/Common/interface/Handle.h"
0006 #include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
0007 #include "DataFormats/ParticleFlowReco/interface/PFRecHitFwd.h"
0008 #include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
0009 #include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h"
0010 #include "DataFormats/Common/interface/RefToBaseVector.h"
0011 #include "CondFormats/DataRecord/interface/HcalPFCutsRcd.h"
0012 #include "CondTools/Hcal/interface/HcalPFCutsHandler.h"
0013 
0014 #include <string>
0015 #include <iostream>
0016 #include <unordered_map>
0017 #include <tuple>
0018 
0019 namespace edm {
0020   class Event;
0021   class EventSetup;
0022 }  // namespace edm
0023 
0024 #include "FWCore/Framework/interface/ConsumesCollector.h"
0025 
0026 class InitialClusteringStepBase {
0027   typedef InitialClusteringStepBase ICSB;
0028 
0029 public:
0030   InitialClusteringStepBase(const edm::ParameterSet& conf, edm::ConsumesCollector& cc)
0031       : _nSeeds(0),
0032         _nClustersFound(0),
0033         _layerMap({{"PS2", (int)PFLayer::PS2},
0034                    {"PS1", (int)PFLayer::PS1},
0035                    {"ECAL_ENDCAP", (int)PFLayer::ECAL_ENDCAP},
0036                    {"ECAL_BARREL", (int)PFLayer::ECAL_BARREL},
0037                    {"NONE", (int)PFLayer::NONE},
0038                    {"HCAL_BARREL1", (int)PFLayer::HCAL_BARREL1},
0039                    {"HCAL_BARREL2_RING0", (int)PFLayer::HCAL_BARREL2},
0040                    {"HCAL_BARREL2_RING1", 100 * (int)PFLayer::HCAL_BARREL2},
0041                    {"HCAL_ENDCAP", (int)PFLayer::HCAL_ENDCAP},
0042                    {"HF_EM", (int)PFLayer::HF_EM},
0043                    {"HF_HAD", (int)PFLayer::HF_HAD},
0044                    {"HGCAL", (int)PFLayer::HGCAL}}),
0045         _algoName(conf.getParameter<std::string>("algoName")) {
0046     const std::vector<edm::ParameterSet>& thresholds = conf.getParameterSetVector("thresholdsByDetector");
0047     for (const auto& pset : thresholds) {
0048       const std::string& det = pset.getParameter<std::string>("detector");
0049 
0050       std::vector<int> depths;
0051       std::vector<double> thresh_E;
0052       std::vector<double> thresh_pT;
0053       std::vector<double> thresh_pT2;
0054 
0055       if (det == std::string("HCAL_BARREL1") || det == std::string("HCAL_ENDCAP")) {
0056         depths = pset.getParameter<std::vector<int> >("depths");
0057         thresh_E = pset.getParameter<std::vector<double> >("gatheringThreshold");
0058         thresh_pT = pset.getParameter<std::vector<double> >("gatheringThresholdPt");
0059         if (thresh_E.size() != depths.size() || thresh_pT.size() != depths.size()) {
0060           throw cms::Exception("InvalidGatheringThreshold")
0061               << "gatheringThresholds mismatch with the numbers of depths";
0062         }
0063       } else {
0064         depths.push_back(0);
0065         thresh_E.push_back(pset.getParameter<double>("gatheringThreshold"));
0066         thresh_pT.push_back(pset.getParameter<double>("gatheringThresholdPt"));
0067       }
0068 
0069       for (unsigned int i = 0; i < thresh_pT.size(); ++i) {
0070         thresh_pT2.push_back(thresh_pT[i] * thresh_pT[i]);
0071       }
0072 
0073       auto entry = _layerMap.find(det);
0074       if (entry == _layerMap.end()) {
0075         throw cms::Exception("InvalidDetectorLayer")
0076             << "Detector layer : " << det << " is not in the list of recognized"
0077             << " detector layers!";
0078       }
0079       _thresholds.emplace(_layerMap.find(det)->second, std::make_tuple(depths, thresh_E, thresh_pT2));
0080     }
0081   }
0082   virtual ~InitialClusteringStepBase() = default;
0083   // get rid of things we should never use...
0084   InitialClusteringStepBase(const ICSB&) = delete;
0085   ICSB& operator=(const ICSB&) = delete;
0086 
0087   virtual void update(const edm::EventSetup&) {}
0088 
0089   virtual void updateEvent(const edm::Event&) {}
0090 
0091   virtual void buildClusters(const edm::Handle<reco::PFRecHitCollection>&,
0092                              const std::vector<bool>& mask,   // mask flags
0093                              const std::vector<bool>& seeds,  // seed flags
0094                              reco::PFClusterCollection&,      //output
0095                              const HcalPFCuts*) = 0;
0096 
0097   std::ostream& operator<<(std::ostream& o) const {
0098     o << "InitialClusteringStep with algo \"" << _algoName << "\" located " << _nSeeds << " seeds and built "
0099       << _nClustersFound << " clusters from those seeds. ";
0100     return o;
0101   }
0102 
0103   void reset() { _nSeeds = _nClustersFound = 0; }
0104 
0105 protected:
0106   reco::PFRecHitRef makeRefhit(const edm::Handle<reco::PFRecHitCollection>& h, const unsigned i) const {
0107     return reco::PFRecHitRef(h, i);
0108   }
0109   unsigned _nSeeds, _nClustersFound;  // basic performance information
0110   const std::unordered_map<std::string, int> _layerMap;
0111 
0112   typedef std::tuple<std::vector<int>, std::vector<double>, std::vector<double> > I3tuple;
0113   std::unordered_map<int, I3tuple> _thresholds;
0114 
0115 private:
0116   const std::string _algoName;
0117 };
0118 
0119 std::ostream& operator<<(std::ostream& o, const InitialClusteringStepBase& a);
0120 
0121 #include "FWCore/PluginManager/interface/PluginFactory.h"
0122 typedef edmplugin::PluginFactory<InitialClusteringStepBase*(const edm::ParameterSet&, edm::ConsumesCollector&)>
0123     InitialClusteringStepFactory;
0124 
0125 #endif