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 
163  makeNxNClusters(evt, eventSetup, *hits_eb, reco::CaloID::DET_ECAL_BARREL);
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;
177  makeNxNClusters(evt, eventSetup, *hits_ee, reco::CaloID::DET_ECAL_ENDCAP);
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 
206  const edm::EventSetup &eventSetup,
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 
ConfigurationDescriptions.h
DDAxes::y
EcalRecHit
Definition: EcalRecHit.h:15
electrons_cff.bool
bool
Definition: electrons_cff.py:366
PositionCalc.h
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
edm::SortedCollection< EcalRecHit >::const_iterator
std::vector< EcalRecHit >::const_iterator const_iterator
Definition: SortedCollection.h:80
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
EcalRecHit::id
DetId id() const
get the id
Definition: EcalRecHit.h:77
reco::CaloID::Detectors
Detectors
Definition: CaloID.h:19
EgammaHLTNxNClusterProducer::barrelHitProducer_
const edm::EDGetTokenT< EcalRecHitCollection > barrelHitProducer_
Definition: EgammaHLTNxNClusterProducer.cc:66
mps_update.status
status
Definition: mps_update.py:68
BasicCluster.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
reco::CaloID::DET_ECAL_ENDCAP
Definition: CaloID.h:21
edm
HLT enums.
Definition: AlignableModifier.h:19
EgammaHLTNxNClusterProducer::clusEtaSize_
const int clusEtaSize_
Definition: EgammaHLTNxNClusterProducer.cc:71
EBDetId.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EcalBarrelTopology.h
CaloID.h
EDProducer.h
edm::SortedCollection< EcalRecHit >
edm::SortedCollection::size
size_type size() const
Definition: SortedCollection.h:215
EgammaHLTNxNClusterProducer::clusSeedThr_
const double clusSeedThr_
Definition: EgammaHLTNxNClusterProducer.cc:75
EgammaHLTNxNClusterProducer::doEndcaps_
const bool doEndcaps_
Definition: EgammaHLTNxNClusterProducer.cc:65
DDAxes::x
EgammaHLTNxNClusterProducer::flagLevelRecHitsToUse_
const int flagLevelRecHitsToUse_
Definition: EgammaHLTNxNClusterProducer.cc:79
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
EcalCondObjectContainer
Definition: EcalCondObjectContainer.h:13
edm::Handle
Definition: AssociativeIterator.h:50
EcalBarrel
Definition: EcalSubdetector.h:10
EcalRecHitCollections.h
BasicClusterFwd.h
EgammaHLTNxNClusterProducer::doBarrel_
const bool doBarrel_
Definition: EgammaHLTNxNClusterProducer.cc:64
EgammaHLTNxNClusterProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: EgammaHLTNxNClusterProducer.cc:150
EgammaHLTNxNClusterProducer::clusPhiSize_
const int clusPhiSize_
Definition: EgammaHLTNxNClusterProducer.cc:72
EgammaHLTNxNClusterProducer
Definition: EgammaHLTNxNClusterProducer.cc:46
EgammaHLTNxNClusterProducer::maxNumberofSeeds_
const int maxNumberofSeeds_
Definition: EgammaHLTNxNClusterProducer.cc:83
DetId
Definition: DetId.h:17
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
EgammaHLTNxNClusterProducer::checkStatusOfEcalRecHit
bool checkStatusOfEcalRecHit(const EcalChannelStatus &channelStatus, const EcalRecHit &rh)
Definition: EgammaHLTNxNClusterProducer.cc:181
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
EgammaHLTNxNClusterProducer::useDBStatus_
const bool useDBStatus_
Definition: EgammaHLTNxNClusterProducer.cc:80
PositionCalc::Calculate_Location
math::XYZPoint Calculate_Location(const HitsAndFractions &iDetIds, const edm::SortedCollection< HitType > *iRecHits, const CaloSubdetectorGeometry *iSubGeom, const CaloSubdetectorGeometry *iESGeom=nullptr)
Definition: PositionCalc.h:65
reco::CaloCluster
Definition: CaloCluster.h:31
EgammaHLTNxNClusterProducer::debug_
const int debug_
Definition: EgammaHLTNxNClusterProducer.cc:86
edm::ESHandle
Definition: DTSurvey.h:22
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
EcalRecHit.h
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
ParameterSetDescription.h
edm::EventID::run
RunNumber_t run() const
Definition: EventID.h:38
CaloGeometryRecord.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
EcalEndcap
Definition: EcalSubdetector.h:10
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
CaloSubdetectorGeometry.h
EgammaHLTNxNClusterProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: EgammaHLTNxNClusterProducer.cc:118
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Event.h
EcalEndcapTopology.h
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
PositionCalc
Definition: PositionCalc.h:29
edm::EventID::event
EventNumber_t event() const
Definition: EventID.h:40
createfilelist.int
int
Definition: createfilelist.py:10
EgammaHLTNxNClusterProducer::ecalChannelStatusToken_
const edm::ESGetToken< EcalChannelStatus, EcalChannelStatusRcd > ecalChannelStatusToken_
Definition: EgammaHLTNxNClusterProducer.cc:69
EgammaHLTNxNClusterProducer::endcapClusterCollection_
const std::string endcapClusterCollection_
Definition: EgammaHLTNxNClusterProducer.cc:74
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
EgammaHLTNxNClusterProducer::makeNxNClusters
void makeNxNClusters(edm::Event &evt, const edm::EventSetup &es, const EcalRecHitCollection &hits, const reco::CaloID::Detectors detector)
Definition: EgammaHLTNxNClusterProducer.cc:205
edm::stream::EDProducer
Definition: EDProducer.h:36
EcalRecHit::recoFlag
Flags recoFlag() const
DEPRECATED provided for temporary backward compatibility.
Definition: EcalRecHit.h:207
edm::EventSetup
Definition: EventSetup.h:58
DetId::Ecal
Definition: DetId.h:27
EgammaHLTNxNClusterProducer::endcapHitProducer_
const edm::EDGetTokenT< EcalRecHitCollection > endcapHitProducer_
Definition: EgammaHLTNxNClusterProducer.cc:67
reco::CaloID
Definition: CaloID.h:17
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ESGetToken< CaloGeometry, CaloGeometryRecord >
reco::CaloCluster::island
Definition: CaloCluster.h:34
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
CaloTopology.h
EcalPreshower
Definition: EcalSubdetector.h:10
EgammaHLTNxNClusterProducer::~EgammaHLTNxNClusterProducer
~EgammaHLTNxNClusterProducer() override
Definition: EgammaHLTNxNClusterProducer.cc:116
CaloTopologyRecord.h
CaloCellGeometry.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
DetachedQuadStep_cff.seeds
seeds
Definition: DetachedQuadStep_cff.py:195
EgammaHLTNxNClusterProducer::clusSeedThrEndCap_
const double clusSeedThrEndCap_
Definition: EgammaHLTNxNClusterProducer.cc:76
Frameworkfwd.h
EgammaHLTNxNClusterProducer::useRecoFlag_
const bool useRecoFlag_
Definition: EgammaHLTNxNClusterProducer.cc:78
CaloGeometry.h
edm::EventBase::id
edm::EventID id() const
Definition: EventBase.h:59
EgammaHLTNxNClusterProducer::statusLevelRecHitsToUse_
const int statusLevelRecHitsToUse_
Definition: EgammaHLTNxNClusterProducer.cc:81
EgammaHLTNxNClusterProducer::barrelClusterCollection_
const std::string barrelClusterCollection_
Definition: EgammaHLTNxNClusterProducer.cc:73
EventSetup.h
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
EgammaHLTNxNClusterProducer::posCalculator_
PositionCalc posCalculator_
Definition: EgammaHLTNxNClusterProducer.cc:88
hgcalTestNeighbor_cfi.detector
detector
Definition: hgcalTestNeighbor_cfi.py:6
ParameterSet.h
EgammaHLTNxNClusterProducer::caloGeometryToken_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
Definition: EgammaHLTNxNClusterProducer.cc:68
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
EgammaHLTNxNClusterProducer::EgammaHLTNxNClusterProducer
EgammaHLTNxNClusterProducer(const edm::ParameterSet &ps)
Definition: EgammaHLTNxNClusterProducer.cc:91
EcalChannelStatus.h
edm::InputTag
Definition: InputTag.h:15
BasicClusterShapeAssociation.h
EgammaHLTNxNClusterProducer::maxNumberofClusters_
const int maxNumberofClusters_
Definition: EgammaHLTNxNClusterProducer.cc:84
EcalChannelStatusRcd.h
hit
Definition: SiStripHitEffFromCalibTree.cc:88
reco::CaloID::DET_ECAL_BARREL
Definition: CaloID.h:20
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:117