CMS 3D CMS Logo

EgammaHLTNxNClusterProducer.cc
Go to the documentation of this file.
1 
15 
20 
23 
24 #include <vector>
25 #include <memory>
26 #include <ctime>
27 
34 
43 
44 #include "TVector3.h"
45 
47 public:
50 
51  void produce(edm::Event &, const edm::EventSetup &) override;
52  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
53 
54 private:
55  void makeNxNClusters(edm::Event &evt,
56  const edm::EventSetup &es,
59 
60  bool checkStatusOfEcalRecHit(const EcalChannelStatus &channelStatus, const EcalRecHit &rh);
61 
62  //std::map<std::string,double> providedParameters;
63 
64  const bool doBarrel_;
65  const bool doEndcaps_;
70 
71  const int clusEtaSize_;
72  const int clusPhiSize_;
75  const double clusSeedThr_;
76  const double clusSeedThrEndCap_;
77 
78  const bool useRecoFlag_;
80  const bool useDBStatus_;
82 
83  const int maxNumberofSeeds_;
85 
86  const int debug_;
87 
88  PositionCalc posCalculator_; // position calculation algorithm
89 };
90 
92  : doBarrel_(ps.getParameter<bool>("doBarrel")),
93  doEndcaps_(ps.getParameter<bool>("doEndcaps")),
94  barrelHitProducer_(consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("barrelHitProducer"))),
95  endcapHitProducer_(consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("endcapHitProducer"))),
96  caloGeometryToken_{esConsumes()},
97  ecalChannelStatusToken_{esConsumes()},
98  clusEtaSize_(ps.getParameter<int>("clusEtaSize")),
99  clusPhiSize_(ps.getParameter<int>("clusPhiSize")),
100  barrelClusterCollection_(ps.getParameter<std::string>("barrelClusterCollection")),
101  endcapClusterCollection_(ps.getParameter<std::string>("endcapClusterCollection")),
102  clusSeedThr_(ps.getParameter<double>("clusSeedThr")),
103  clusSeedThrEndCap_(ps.getParameter<double>("clusSeedThrEndCap")),
104  useRecoFlag_(ps.getParameter<bool>("useRecoFlag")),
105  flagLevelRecHitsToUse_(ps.getParameter<int>("flagLevelRecHitsToUse")),
106  useDBStatus_(ps.getParameter<bool>("useDBStatus")),
107  statusLevelRecHitsToUse_(ps.getParameter<int>("statusLevelRecHitsToUse")),
108  maxNumberofSeeds_(ps.getParameter<int>("maxNumberofSeeds")),
109  maxNumberofClusters_(ps.getParameter<int>("maxNumberofClusters")),
110  debug_(ps.getParameter<int>("debugLevel")),
111  posCalculator_(PositionCalc(ps.getParameter<edm::ParameterSet>("posCalcParameters"))) {
112  produces<reco::BasicClusterCollection>(barrelClusterCollection_);
113  produces<reco::BasicClusterCollection>(endcapClusterCollection_);
114 }
115 
117 
120  desc.add<bool>(("doBarrel"), true);
121  desc.add<bool>(("doEndcaps"), true);
122  desc.add<edm::InputTag>(("barrelHitProducer"), edm::InputTag("hltEcalRegionalPi0EtaRecHit", "EcalRecHitsEB"));
123  desc.add<edm::InputTag>(("endcapHitProducer"), edm::InputTag("hltEcalRegionalPi0EtaRecHit", "EcalRecHitsEE"));
124  desc.add<int>(("clusEtaSize"), 3);
125  desc.add<int>(("clusPhiSize"), 3);
126  desc.add<std::string>(("barrelClusterCollection"), "Simple3x3ClustersBarrel");
127  desc.add<std::string>(("endcapClusterCollection"), "Simple3x3ClustersEndcap");
128  desc.add<double>(("clusSeedThr"), 0.5);
129  desc.add<double>(("clusSeedThrEndCap"), 1.0);
130  desc.add<bool>(("useRecoFlag"), false);
131  desc.add<int>(("flagLevelRecHitsToUse"), 1);
132  desc.add<bool>(("useDBStatus"), true);
133  desc.add<int>(("statusLevelRecHitsToUse"), 1);
134 
135  edm::ParameterSetDescription posCalcPSET;
136  posCalcPSET.add<double>("T0_barl", 7.4);
137  posCalcPSET.add<double>("T0_endc", 3.1);
138  posCalcPSET.add<double>("T0_endcPresh", 1.2);
139  posCalcPSET.add<double>("W0", 4.2);
140  posCalcPSET.add<double>("X0", 0.89);
141  posCalcPSET.add<bool>("LogWeighted", true);
142  desc.add<edm::ParameterSetDescription>("posCalcParameters", posCalcPSET);
143 
144  desc.add<int>(("maxNumberofSeeds"), 1000);
145  desc.add<int>(("maxNumberofClusters"), 200);
146  desc.add<int>(("debugLevel"), 0);
147  descriptions.add(("hltEgammaHLTNxNClusterProducer"), desc);
148 }
149 
151  if (doBarrel_) {
152  edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
153  evt.getByToken(barrelHitProducer_, barrelRecHitsHandle);
154  if (!barrelRecHitsHandle.isValid()) {
155  LogDebug("") << "EgammaHLTNxNClusterProducer Error! can't get product eb hit!" << std::endl;
156  }
157 
158  const EcalRecHitCollection *hits_eb = barrelRecHitsHandle.product();
159  if (debug_ >= 2)
160  LogDebug("") << "EgammaHLTNxNClusterProducer nEBrechits: " << evt.id().run() << " event " << evt.id().event()
161  << " " << hits_eb->size() << std::endl;
162 
164  }
165 
166  if (doEndcaps_) {
167  edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
168  evt.getByToken(endcapHitProducer_, endcapRecHitsHandle);
169  if (!endcapRecHitsHandle.isValid()) {
170  LogDebug("") << "EgammaHLTNxNClusterProducer Error! can't get product ee hit!" << std::endl;
171  }
172 
173  const EcalRecHitCollection *hits_ee = endcapRecHitsHandle.product();
174  if (debug_ >= 2)
175  LogDebug("") << "EgammaHLTNxNClusterProducer nEErechits: " << evt.id().run() << " event " << evt.id().event()
176  << " " << hits_ee->size() << std::endl;
178  }
179 }
180 
182  const EcalRecHit &rh) {
183  if (useRecoFlag_) {
184  int flag = rh.recoFlag();
185  if (flagLevelRecHitsToUse_ == 0) {
186  if (flag != 0)
187  return false;
188  } else if (flagLevelRecHitsToUse_ == 1) {
189  if (flag != 0 && flag != 4)
190  return false;
191  } else if (flagLevelRecHitsToUse_ == 2) {
192  if (flag != 0 && flag != 4 && flag != 6 && flag != 7)
193  return false;
194  }
195  }
196  if (useDBStatus_) {
197  int status = int(channelStatus[rh.id().rawId()].getStatusCode());
199  return false;
200  }
201 
202  return true;
203 }
204 
207  const EcalRecHitCollection &hits,
211  if (useDBStatus_) {
212  csHandle = eventSetup.getHandle(ecalChannelStatusToken_);
213  }
214  const EcalChannelStatus &channelStatus = *csHandle;
215 
216  std::vector<EcalRecHit> seeds;
217 
218  double clusterSeedThreshold;
220  clusterSeedThreshold = clusSeedThr_;
221  } else {
222  clusterSeedThreshold = clusSeedThrEndCap_;
223  }
224 
225  for (auto const itt : hits) {
226  double energy = itt.energy();
227  if (!checkStatusOfEcalRecHit(channelStatus, itt))
228  continue;
229  if (energy > clusterSeedThreshold)
230  seeds.push_back(itt);
231 
232  if (int(seeds.size()) > maxNumberofSeeds_) { //too many seeds, like beam splash events
233  seeds.clear();
234  break;
235  }
236  }
237 
238  // get the geometry and topology from the event setup:
239  auto const &caloGeometry = eventSetup.getData(caloGeometryToken_);
240 
241  const CaloSubdetectorGeometry *geometry_p;
242  std::unique_ptr<CaloSubdetectorTopology> topology_p;
244  geometry_p = caloGeometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
245  topology_p = std::make_unique<EcalBarrelTopology>(caloGeometry);
246  } else {
247  geometry_p = caloGeometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
248  topology_p = std::make_unique<EcalEndcapTopology>(caloGeometry);
249  }
250 
251  const CaloSubdetectorGeometry *geometryES_p;
252  geometryES_p = caloGeometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
253 
254  std::vector<reco::BasicCluster> clusters;
255  std::vector<DetId> usedXtals;
256 
257  // sort seed according to Energy
258  sort(seeds.begin(), seeds.end(), [](auto const &x, auto const &y) { return (x.energy() > y.energy()); });
259 
260  for (std::vector<EcalRecHit>::iterator itseed = seeds.begin(); itseed != seeds.end(); itseed++) {
261  DetId seed_id = itseed->id();
262 
263  std::vector<DetId>::iterator itdet = find(usedXtals.begin(), usedXtals.end(), seed_id);
264  if (itdet != usedXtals.end())
265  continue;
266 
267  std::vector<DetId> clus_v = topology_p->getWindow(seed_id, clusEtaSize_, clusPhiSize_);
268  std::vector<std::pair<DetId, float> > clus_used;
269 
270  float clus_energy = 0;
271 
272  for (auto const &detid : clus_v) {
273  //not yet used
274  std::vector<DetId>::iterator itdet = find(usedXtals.begin(), usedXtals.end(), detid);
275  if (itdet != usedXtals.end())
276  continue;
277  //inside the collection
279  if (hit == hits.end())
280  continue;
281 
282  if (!checkStatusOfEcalRecHit(channelStatus, *hit))
283  continue;
284 
285  usedXtals.push_back(detid);
286  clus_used.push_back(std::pair<DetId, float>(detid, 1.));
287  clus_energy += hit->energy();
288 
289  }
290 
291  if (clus_energy <= 0)
292  continue;
293 
294  math::XYZPoint clus_pos = posCalculator_.Calculate_Location(clus_used, &hits, geometry_p, geometryES_p);
295 
296  if (debug_ >= 2)
297  LogDebug("") << "nxn_cluster in run " << evt.id().run() << " event " << evt.id().event()
298  << " energy: " << clus_energy << " eta: " << clus_pos.Eta() << " phi: " << clus_pos.Phi()
299  << " nRecHits: " << clus_used.size() << std::endl;
300 
301  clusters.push_back(reco::BasicCluster(
302  clus_energy, clus_pos, reco::CaloID(detector), clus_used, reco::CaloCluster::island, seed_id));
303  if (int(clusters.size()) > maxNumberofClusters_) {
304  clusters.clear();
305  break;
306  }
307  }
308 
309  //Create empty output collections
310  auto clusters_p = std::make_unique<reco::BasicClusterCollection>();
311  clusters_p->assign(clusters.begin(), clusters.end());
313  if (debug_ >= 1)
314  LogDebug("") << "nxnclusterProducer: " << clusters_p->size() << " made in barrel" << std::endl;
315  evt.put(std::move(clusters_p), barrelClusterCollection_);
316  } else {
317  if (debug_ >= 1)
318  LogDebug("") << "nxnclusterProducer: " << clusters_p->size() << " made in endcap" << std::endl;
319  evt.put(std::move(clusters_p), endcapClusterCollection_);
320  }
321 }
322 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
size_type size() const
T const * product() const
Definition: Handle.h:70
std::vector< EcalRecHit >::const_iterator const_iterator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:536
Flags recoFlag() const
DEPRECATED provided for temporary backward compatibility.
Definition: EcalRecHit.h:208
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
EgammaHLTNxNClusterProducer(const edm::ParameterSet &ps)
const edm::EDGetTokenT< EcalRecHitCollection > endcapHitProducer_
math::XYZPoint Calculate_Location(const HitsAndFractions &iDetIds, const edm::SortedCollection< HitType > *iRecHits, const CaloSubdetectorGeometry *iSubGeom, const CaloSubdetectorGeometry *iESGeom=nullptr)
Definition: PositionCalc.h:65
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EventID id() const
Definition: EventBase.h:63
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void makeNxNClusters(edm::Event &evt, const edm::EventSetup &es, const EcalRecHitCollection &hits, const reco::CaloID::Detectors detector)
const edm::ESGetToken< EcalChannelStatus, EcalChannelStatusRcd > ecalChannelStatusToken_
RunNumber_t run() const
Definition: EventID.h:38
Definition: DetId.h:17
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
void add(std::string const &label, ParameterSetDescription const &psetDescription)
DetId id() const
get the id
Definition: EcalRecHit.h:78
bool isValid() const
Definition: HandleBase.h:70
void produce(edm::Event &, const edm::EventSetup &) override
HLT enums.
bool checkStatusOfEcalRecHit(const EcalChannelStatus &channelStatus, const EcalRecHit &rh)
const edm::EDGetTokenT< EcalRecHitCollection > barrelHitProducer_
def move(src, dest)
Definition: eostools.py:511
EventNumber_t event() const
Definition: EventID.h:40
#define LogDebug(id)