CMS 3D CMS Logo

HLTHGCalLayerClusterIsolationProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <vector>
3 #include <memory>
4 
13 
15 
17 
20 
23 
25 
28 
31 
34 
36 
37 template <typename T1>
39  typedef std::vector<T1> T1Collection;
42 
43 public:
45  ~HLTHGCalLayerClusterIsolationProducer() override = default;
46 
47  void produce(edm::Event&, const edm::EventSetup&) override;
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
49 
50 private:
54 
55  const double drMax_;
56  const double drVetoEM_;
57  const double drVetoHad_;
58  const double minEnergyEM_;
59  const double minEnergyHad_;
60  const double minEtEM_;
61  const double minEtHad_;
62  const bool useEt_;
63  const bool doRhoCorrection_;
64  const double rhoMax_;
65  const double rhoScale_;
66  const std::vector<double> effectiveAreas_;
67 };
68 
69 template <typename T1>
71  : layerClusterProducer_(
72  consumes<reco::CaloClusterCollection>(config.getParameter<edm::InputTag>("layerClusterProducer"))),
73  rhoProducer_(consumes<double>(config.getParameter<edm::InputTag>("rhoProducer"))),
74  drMax_(config.getParameter<double>("drMax")),
75  drVetoEM_(config.getParameter<double>("drVetoEM")),
76  drVetoHad_(config.getParameter<double>("drVetoHad")),
77  minEnergyEM_(config.getParameter<double>("minEnergyEM")),
78  minEnergyHad_(config.getParameter<double>("minEnergyHad")),
79  minEtEM_(config.getParameter<double>("minEtEM")),
80  minEtHad_(config.getParameter<double>("minEtHad")),
81  useEt_(config.getParameter<bool>("useEt")),
82  doRhoCorrection_(config.getParameter<bool>("doRhoCorrection")),
83  rhoMax_(config.getParameter<double>("rhoMax")),
84  rhoScale_(config.getParameter<double>("rhoScale")),
85  effectiveAreas_(config.getParameter<std::vector<double>>("effectiveAreas")) {
86  if (doRhoCorrection_) {
87  if (effectiveAreas_.size() != 2)
88  throw cms::Exception("IncompatibleVects")
89  << "effectiveAreas should have two elements for em and had components. \n";
90  }
91 
92  std::string recoCandidateProducerName = "recoCandidateProducer";
95  recoCandidateProducerName = "recoEcalCandidateProducer";
96 
97  recoCandidateProducer_ = consumes<T1Collection>(config.getParameter<edm::InputTag>(recoCandidateProducerName));
98  produces<T1IsolationMap>();
99  produces<T1IsolationMap>("em");
100  produces<T1IsolationMap>("had");
101 }
102 
103 template <typename T1>
105  std::string recoCandidateProducerName = "recoCandidateProducer";
108  recoCandidateProducerName = "recoEcalCandidateProducer";
109 
111  desc.add<edm::InputTag>(recoCandidateProducerName, edm::InputTag("hltL1SeededRecoEcalCandidatePF"));
112  desc.add<edm::InputTag>("layerClusterProducer", edm::InputTag("hltParticleFlowClusterECAL"));
113  desc.add<edm::InputTag>("rhoProducer", edm::InputTag("fixedGridRhoFastjetAllCalo"));
114  desc.add<bool>("doRhoCorrection", false);
115  desc.add<bool>("useEt", false);
116  desc.add<double>("rhoMax", 9.9999999E7);
117  desc.add<double>("rhoScale", 1.0);
118  desc.add<double>("drMax", 0.3);
119  desc.add<double>("drVetoEM", 0.0);
120  desc.add<double>("drVetoHad", 0.0);
121  desc.add<double>("minEnergyEM", 0.0);
122  desc.add<double>("minEnergyHad", 0.0);
123  desc.add<double>("minEtEM", 0.0);
124  desc.add<double>("minEtHad", 0.0);
125  desc.add<std::vector<double>>("effectiveAreas", {0.0, 0.0}); // for em and had components
127 }
128 
129 template <typename T1>
131  edm::Handle<double> rhoHandle;
132  double rho = 0.0;
133  if (doRhoCorrection_) {
134  iEvent.getByToken(rhoProducer_, rhoHandle);
135  rho = *(rhoHandle.product());
136  }
137 
138  rho = std::min(rho, rhoMax_);
139  rho = rho * rhoScale_;
140 
141  edm::Handle<T1Collection> recoCandHandle;
143 
144  iEvent.getByToken(recoCandidateProducer_, recoCandHandle);
145  iEvent.getByToken(layerClusterProducer_, clusterHandle);
146 
147  const std::vector<reco::CaloCluster> layerClusters = *(clusterHandle.product());
148 
149  T1IsolationMap recoCandMap(recoCandHandle);
150  T1IsolationMap recoCandMapEm(recoCandHandle);
151  T1IsolationMap recoCandMapHad(recoCandHandle);
152 
153  for (unsigned int iReco = 0; iReco < recoCandHandle->size(); iReco++) {
154  T1Ref candRef(recoCandHandle, iReco);
155 
156  float sumEm =
157  HGCalClusterTools::emEnergyInCone(candRef->eta(),
158  candRef->phi(),
160  drVetoEM_,
161  drMax_,
162  minEtEM_,
163  minEnergyEM_,
165 
166  float sumHad =
167  HGCalClusterTools::hadEnergyInCone(candRef->eta(),
168  candRef->phi(),
170  drVetoHad_,
171  drMax_,
172  minEtHad_,
173  minEnergyHad_,
175 
176  if (doRhoCorrection_) {
177  sumEm = sumEm - rho * effectiveAreas_.at(0);
178  sumHad = sumHad - rho * effectiveAreas_.at(1);
179  }
180 
181  float sum = sumEm + sumHad;
182 
183  recoCandMap.insert(candRef, sum);
184  recoCandMapEm.insert(candRef, sumEm);
185  recoCandMapHad.insert(candRef, sumHad);
186  }
187 
188  iEvent.put(std::make_unique<T1IsolationMap>(recoCandMap));
189  iEvent.put(std::make_unique<T1IsolationMap>(recoCandMapEm), "em");
190  iEvent.put(std::make_unique<T1IsolationMap>(recoCandMapHad), "had");
191 }
192 
195 
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HLTHGCalLayerClusterIsolationProducer< reco::RecoChargedCandidate > MuonHLTHGCalLayerClusterIsolationProducer
HLTHGCalLayerClusterIsolationProducer< reco::RecoEcalCandidate > EgammaHLTHGCalLayerClusterIsolationProducer
void produce(edm::Event &, const edm::EventSetup &) override
T const * product() const
Definition: Handle.h:70
~HLTHGCalLayerClusterIsolationProducer() override=default
Definition: config.py:1
std::string defaultModuleLabel()
static float emEnergyInCone(const float eta, const float phi, const std::vector< reco::CaloCluster > &layerClusters, const float minDR, const float maxDR, const float minEt, const float minEnergy, const HGCalClusterTools::EType &eType=EType::ENERGY)
int iEvent
Definition: GenABIO.cc:224
std::vector< CaloCluster > CaloClusterCollection
collection of CaloCluster objects
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::AssociationMap< edm::OneToValue< std::vector< T1 >, float > > T1IsolationMap
const edm::EDGetTokenT< reco::CaloClusterCollection > layerClusterProducer_
void insert(const key_type &k, const data_type &v)
insert an association
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.
static float hadEnergyInCone(const float eta, const float phi, const std::vector< reco::CaloCluster > &layerClusters, const float minDR, const float maxDR, const float minEt, const float minEnergy, const HGCalClusterTools::EType &eType=EType::ENERGY)