CMS 3D CMS Logo

ElectronSeedProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ElectronProducers
4 // Class: ElectronSeedProducer
5 //
13 //
14 // Original Author: Ursula Berthon, Claude Charlot
15 // Created: Mon Mar 27 13:22:06 CEST 2006
16 //
17 //
18 
35 
37 public:
38  explicit ElectronSeedProducer(const edm::ParameterSet&);
39 
40  void produce(edm::Event&, const edm::EventSetup&) final;
41 
42  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
43 
44 private:
47  HcalPFCuts const* hcalCuts) const;
48 
50  std::vector<edm::EDGetTokenT<TrajectorySeedCollection>> initialSeeds_;
52 
53  std::unique_ptr<ElectronSeedGenerator> matcher_;
54 
55  bool applyHOverECut_ = true;
56  std::unique_ptr<ElectronHcalHelper> hcalHelper_ = nullptr;
59  double SCEtCut_;
60 
62  std::unique_ptr<hgcal::ClusterTools> hgcClusterTools_;
63 
66 };
67 
68 using namespace reco;
69 
71  :
72 
73  initialSeeds_{
74  edm::vector_transform(conf.getParameter<std::vector<edm::InputTag>>("initialSeedsVector"),
75  [this](edm::InputTag const& tag) { return consumes<TrajectorySeedCollection>(tag); })}
76 
77 {
78  SCEtCut_ = conf.getParameter<double>("SCEtCut");
79  auto theconsumes = consumesCollector();
80 
81  // new beamSpot tag
82  beamSpotTag_ = consumes(conf.getParameter<edm::InputTag>("beamSpot"));
83 
84  // for H/E
85  applyHOverECut_ = conf.getParameter<bool>("applyHOverECut");
86  if (applyHOverECut_) {
88  hcalCfg.hOverEConeSize = conf.getParameter<double>("hOverEConeSize");
89  if (hcalCfg.hOverEConeSize > 0) {
90  hcalCfg.onlyBehindCluster = false;
91  hcalCfg.checkHcalStatus = false;
92 
93  hcalCfg.hbheRecHits = consumes<HBHERecHitCollection>(conf.getParameter<edm::InputTag>("hbheRecHits"));
94 
95  hcalCfg.eThresHB = conf.getParameter<EgammaHcalIsolation::arrayHB>("recHitEThresholdHB");
96  hcalCfg.maxSeverityHB = conf.getParameter<int>("maxHcalRecHitSeverity");
97  hcalCfg.eThresHE = conf.getParameter<EgammaHcalIsolation::arrayHE>("recHitEThresholdHE");
98  hcalCfg.maxSeverityHE = hcalCfg.maxSeverityHB;
99  }
100  hcalHelper_ = std::make_unique<ElectronHcalHelper>(hcalCfg, consumesCollector());
101 
102  allowHGCal_ = conf.getParameter<bool>("allowHGCal");
103  if (allowHGCal_) {
104  const edm::ParameterSet& hgcCfg = conf.getParameterSet("HGCalConfig");
105  hgcClusterTools_ = std::make_unique<hgcal::ClusterTools>(hgcCfg, theconsumes);
106  }
107 
108  maxHOverEBarrel_ = conf.getParameter<double>("maxHOverEBarrel");
109  maxHOverEEndcaps_ = conf.getParameter<double>("maxHOverEEndcaps");
110  }
111 
112  //Retrieve HCAL PF thresholds - from config or from DB
113  cutsFromDB_ = conf.getParameter<bool>("usePFThresholdsFromDB");
114  if (cutsFromDB_) {
115  hcalCutsToken_ = esConsumes<HcalPFCuts, HcalPFCutsRcd>(edm::ESInputTag("", "withTopo"));
116  }
117 
119  esg_tokens.token_bs = beamSpotTag_;
120  esg_tokens.token_vtx = mayConsume<reco::VertexCollection>(conf.getParameter<edm::InputTag>("vertices"));
121 
122  matcher_ = std::make_unique<ElectronSeedGenerator>(conf, esg_tokens, consumesCollector());
123 
124  superClusters_[0] = consumes(conf.getParameter<edm::InputTag>("barrelSuperClusters"));
125  superClusters_[1] = consumes(conf.getParameter<edm::InputTag>("endcapSuperClusters"));
126 
127  //register your products
128  produces<ElectronSeedCollection>();
129 }
130 
132  LogDebug("ElectronSeedProducer") << "[ElectronSeedProducer::produce] entering ";
133 
134  HcalPFCuts const* hcalCuts = nullptr;
135  if (cutsFromDB_) {
136  hcalCuts = &iSetup.getData(hcalCutsToken_);
137  }
138 
139  std::vector<TrajectorySeedCollection const*> initialSeedCollections;
140  std::unique_ptr<TrajectorySeedCollection> initialSeedCollectionPtr = nullptr; //created on the fly
141 
142  if (hcalHelper_) {
143  hcalHelper_->beginEvent(e, iSetup);
144  if (allowHGCal_) {
145  hgcClusterTools_->getEventSetup(iSetup);
146  hgcClusterTools_->getEvent(e);
147  }
148  }
149 
150  matcher_->setupES(iSetup);
151 
152  // get initial TrajectorySeeds
153  initialSeedCollections.clear();
154  for (auto const& seeds : initialSeeds_) {
155  initialSeedCollections.push_back(&e.get(seeds));
156  }
157 
158  auto seeds = std::make_unique<ElectronSeedCollection>();
159  auto const& beamSpotPosition = e.get(beamSpotTag_).position();
160 
161  // loop over barrel + endcap
162  for (unsigned int i = 0; i < 2; i++) {
163  auto clusterRefs = filterClusters(beamSpotPosition, e.getHandle(superClusters_[i]), hcalCuts);
164  matcher_->run(e, clusterRefs, initialSeedCollections, *seeds);
165  }
166 
167  // store the accumulated result
168 #ifdef EDM_ML_DEBUG
169  for (auto const& seed : *seeds) {
170  SuperClusterRef superCluster = seed.caloCluster().castTo<SuperClusterRef>();
171  LogDebug("ElectronSeedProducer") << "new seed with " << seed.nHits() << " hits"
172  << ", charge " << seed.getCharge() << " and cluster energy "
173  << superCluster->energy() << " PID " << superCluster.id();
174  }
175 #endif
176  e.put(std::move(seeds));
177 }
178 
179 //===============================
180 // Filter the superclusters
181 // - with EtCut
182 // - with HoE using calo cone
183 //===============================
184 
186  math::XYZPoint const& beamSpotPosition,
188  HcalPFCuts const* hcalCuts) const {
189  SuperClusterRefVector sclRefs;
190 
191  for (unsigned int i = 0; i < superClusters->size(); ++i) {
192  auto const& scl = (*superClusters)[i];
193  double sclEta = EleRelPoint(scl.position(), beamSpotPosition).eta();
194  if (scl.energy() / cosh(sclEta) > SCEtCut_) {
195  if (applyHOverECut_) {
196  bool hoeVeto = false;
197  double had = hcalHelper_->hcalESum(scl, 0, hcalCuts);
198  double scle = scl.energy();
199  int det_group = scl.seed()->hitsAndFractions()[0].first.det();
200  int detector = scl.seed()->hitsAndFractions()[0].first.subdetId();
201  if (detector == EcalBarrel && had / scle < maxHOverEBarrel_)
202  hoeVeto = true;
203  else if (!allowHGCal_ && detector == EcalEndcap && had / scle < maxHOverEEndcaps_)
204  hoeVeto = true;
205  else if (allowHGCal_ && EcalTools::isHGCalDet((DetId::Detector)det_group)) {
206  float had_fraction = hgcClusterTools_->getClusterHadronFraction(*(scl.seed()));
207  hoeVeto = (had_fraction >= 0.f && had_fraction < maxHOverEEndcaps_);
208  }
209  if (hoeVeto) {
210  sclRefs.push_back({superClusters, i});
211  }
212  } else {
213  sclRefs.push_back({superClusters, i});
214  }
215  }
216  }
217  LogDebug("ElectronSeedProducer") << "Filtered out " << sclRefs.size() << " superclusters from "
218  << superClusters->size();
219 
220  return sclRefs;
221 }
222 
225 
226  // steering
227  desc.add<std::vector<edm::InputTag>>("initialSeedsVector", {});
228  desc.add<bool>("useRecoVertex", false);
229  desc.add<edm::InputTag>("vertices", {"offlinePrimaryVerticesWithBS"});
230  desc.add<edm::InputTag>("beamSpot", {"offlineBeamSpot"});
231  desc.add<bool>("dynamicPhiRoad", true);
232 
233  // SC filtering
234  desc.add<double>("SCEtCut", 0.0);
235 
236  // H/E
237  desc.add<bool>("applyHOverECut", true);
238  desc.add<double>("hOverEConeSize", 0.15);
239  desc.add<double>("maxHOverEBarrel", 0.15);
240  desc.add<double>("maxHOverEEndcaps", 0.15);
241  desc.add<edm::InputTag>("hbheRecHits", {"hbhereco"});
242  desc.add<std::vector<double>>("recHitEThresholdHB", {0., 0., 0., 0.});
243  desc.add<std::vector<double>>("recHitEThresholdHE", {0., 0., 0., 0., 0., 0., 0.});
244  desc.add<int>("maxHcalRecHitSeverity", 999999);
245  desc.add<bool>("usePFThresholdsFromDB", false);
246 
247  // H/E equivalent for HGCal
248  desc.add<bool>("allowHGCal", false);
250  psd4.add<edm::InputTag>("HGCEEInput", {"HGCalRecHit", "HGCEERecHits"});
251  psd4.add<edm::InputTag>("HGCFHInput", {"HGCalRecHit", "HGCHEFRecHits"});
252  psd4.add<edm::InputTag>("HGCBHInput", {"HGCalRecHit", "HGCHEBRecHits"});
253  psd4.add<edm::InputTag>("hgcalHitMap", {"recHitMapProducer", "hgcalRecHitMap"});
254  desc.add<edm::ParameterSetDescription>("HGCalConfig", psd4);
255 
256  // r/z windows
257  desc.add<double>("nSigmasDeltaZ1", 5.0); // in case beam spot is used for the matching
258  desc.add<double>("deltaZ1WithVertex", 25.0); // in case reco vertex is used for the matching
259  desc.add<double>("z2MaxB", 0.09);
260  desc.add<double>("r2MaxF", 0.15);
261  desc.add<double>("rMaxI", 0.2); // intermediate region SC in EB and 2nd hits in PXF
262 
263  // phi windows (dynamic)
264  desc.add<double>("LowPtThreshold", 5.0);
265  desc.add<double>("HighPtThreshold", 35.0);
266  desc.add<double>("SizeWindowENeg", 0.675);
267  desc.add<double>("DeltaPhi1Low", 0.23);
268  desc.add<double>("DeltaPhi1High", 0.08);
269  desc.add<double>("DeltaPhi2B", 0.008);
270  desc.add<double>("DeltaPhi2F", 0.012);
271 
272  // phi windows (non dynamic, overwritten in case dynamic is selected)
273  desc.add<double>("ePhiMin1", -0.125);
274  desc.add<double>("ePhiMax1", 0.075);
275  desc.add<double>("PhiMax2B", 0.002);
276  desc.add<double>("PhiMax2F", 0.003);
277 
278  desc.add<edm::InputTag>("barrelSuperClusters",
279  {"particleFlowSuperClusterECAL", "particleFlowSuperClusterECALBarrel"});
280  desc.add<edm::InputTag>("endcapSuperClusters",
281  {"particleFlowSuperClusterECAL", "particleFlowSuperClusterECALEndcapWithPreshower"});
282 
283  descriptions.add("ecalDrivenElectronSeedsDefault", desc);
284 }
285 
static bool isHGCalDet(DetId::Detector thedet)
identify HGCal cells
Definition: EcalTools.h:49
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
ProductID id() const
Accessor for product ID.
Definition: Ref.h:238
edm::EDGetTokenT< reco::BeamSpot > token_bs
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
edm::ESGetToken< HcalPFCuts, HcalPFCutsRcd > hcalCutsToken_
ParameterSet const & getParameterSet(std::string const &) const
std::unique_ptr< ElectronHcalHelper > hcalHelper_
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
ElectronSeedProducer(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< ElectronSeedGenerator > matcher_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Detector
Definition: DetId.h:24
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< reco::SuperClusterCollection > superClusters_[2]
fixed size matrix
void produce(edm::Event &, const edm::EventSetup &) final
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
edm::EDGetTokenT< reco::BeamSpot > beamSpotTag_
std::array< double, 4 > arrayHB
edm::EDGetTokenT< std::vector< reco::Vertex > > token_vtx
reco::SuperClusterRefVector filterClusters(math::XYZPoint const &beamSpotPosition, const edm::Handle< reco::SuperClusterCollection > &superClusters, HcalPFCuts const *hcalCuts) const
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr< hgcal::ClusterTools > hgcClusterTools_
std::vector< edm::EDGetTokenT< TrajectorySeedCollection > > initialSeeds_
#define LogDebug(id)
std::array< double, 7 > arrayHE