CMS 3D CMS Logo

PFECALHashNavigator.h
Go to the documentation of this file.
1 #ifndef RecoParticleFlow_PFClusterProducer_PFECALHashNavigator_h
2 #define RecoParticleFlow_PFClusterProducer_PFECALHashNavigator_h
3 
8 
12 
17 
19 
21 public:
23 
25  : PFRecHitNavigatorBase(iConfig, cc),
27  crossBarrelEndcapBorder_(iConfig.getParameter<bool>("crossBarrelEndcapBorder")),
28  geomToken_(cc.esConsumes<edm::Transition::BeginLuminosityBlock>()) {}
29 
30  void init(const edm::EventSetup& iSetup) override {
32 
35 
36  barrelGeometry_ = dynamic_cast<const EcalBarrelGeometry*>(ebTmp);
37  endcapGeometry_ = dynamic_cast<const EcalEndcapGeometry*>(eeTmp);
38 
39  // get the ecalBarrel topology
40  barrelTopology_ = std::make_unique<EcalBarrelTopology>(*geoHandle);
41  endcapTopology_ = std::make_unique<EcalEndcapTopology>(*geoHandle);
42 
44  }
45 
47  std::unique_ptr<reco::PFRecHitCollection>& hits,
48  edm::RefProd<reco::PFRecHitCollection>& refprod) override {
49  DetId center(rh.detId());
50 
51  DetId north = move(center, NORTH);
52  DetId northeast = move(center, NORTHEAST);
53  DetId northwest = move(center, NORTHWEST);
54  DetId south = move(center, SOUTH);
55  DetId southeast = move(center, SOUTHEAST);
56  DetId southwest = move(center, SOUTHWEST);
57  DetId east = move(center, EAST);
58  DetId west = move(center, WEST);
59 
60  associateNeighbour(north, rh, hits, refprod, 0, 1, 0);
61  associateNeighbour(northeast, rh, hits, refprod, 1, 1, 0);
62  associateNeighbour(south, rh, hits, refprod, 0, -1, 0);
63  associateNeighbour(southwest, rh, hits, refprod, -1, -1, 0);
64  associateNeighbour(east, rh, hits, refprod, 1, 0, 0);
65  associateNeighbour(southeast, rh, hits, refprod, 1, -1, 0);
66  associateNeighbour(west, rh, hits, refprod, -1, 0, 0);
67  associateNeighbour(northwest, rh, hits, refprod, -1, 1, 0);
68  }
69 
70 protected:
71  void ecalNeighbArray(const EcalBarrelGeometry& barrelGeom,
72  const CaloSubdetectorTopology& barrelTopo,
73  const EcalEndcapGeometry& endcapGeom,
74  const CaloSubdetectorTopology& endcapTopo) {
75  const unsigned nbarrel = 62000;
76  // Barrel first. The hashed index runs from 0 to 61199
77  neighboursEB_.resize(nbarrel);
78 
79  //std::cout << " Building the array of neighbours (barrel) " ;
80 
81  const std::vector<DetId>& vec(barrelGeom.getValidDetIds(DetId::Ecal, EcalBarrel));
82  unsigned size = vec.size();
83  for (unsigned ic = 0; ic < size; ++ic) {
84  // We get the 9 cells in a square.
85  std::vector<DetId> neighbours(barrelTopo.getWindow(vec[ic], 3, 3));
86  // std::cout << " Cell " << EBDetId(vec[ic]) << std::endl;
87  unsigned nneighbours = neighbours.size();
88 
89  unsigned hashedindex = EBDetId(vec[ic]).hashedIndex();
90  if (hashedindex >= nbarrel) {
91  LogDebug("CaloGeometryTools") << " Array overflow " << std::endl;
92  }
93 
94  // If there are 9 cells, it is easy, and this order is know:
95  // 6 7 8
96  // 3 4 5
97  // 0 1 2 (0 = SOUTHWEST)
98 
99  if (nneighbours == 9) {
100  neighboursEB_[hashedindex].reserve(8);
101  for (unsigned in = 0; in < nneighbours; ++in) {
102  // remove the centre
103  if (neighbours[in] != vec[ic]) {
104  neighboursEB_[hashedindex].push_back(neighbours[in]);
105  // std::cout << " Neighbour " << in << " " << EBDetId(neighbours[in]) << std::endl;
106  }
107  }
108  } else {
109  DetId central(vec[ic]);
110  neighboursEB_[hashedindex].resize(8, DetId(0));
111  for (unsigned idir = 0; idir < 8; ++idir) {
112  DetId testid = central;
113  bool status = stdmove(testid, orderedDir[idir], barrelTopo, endcapTopo, barrelGeom, endcapGeom);
114  if (status)
115  neighboursEB_[hashedindex][idir] = testid;
116  }
117  }
118  }
119 
120  // Moved to the endcap
121 
122  // std::cout << " done " << size << std::endl;
123  // std::cout << " Building the array of neighbours (endcap) " ;
124 
125  // vec.clear();
126  const std::vector<DetId>& vecee = endcapGeom.getValidDetIds(DetId::Ecal, EcalEndcap);
127  size = vecee.size();
128  // There are some holes in the hashedIndex for the EE. Hence the array is bigger than the number
129  // of crystals
130  const unsigned nendcap = 19960;
131 
132  neighboursEE_.resize(nendcap);
133  for (unsigned ic = 0; ic < size; ++ic) {
134  // We get the 9 cells in a square.
135  std::vector<DetId> neighbours(endcapTopo.getWindow(vecee[ic], 3, 3));
136  unsigned nneighbours = neighbours.size();
137  // remove the centre
138  unsigned hashedindex = EEDetId(vecee[ic]).hashedIndex();
139 
140  if (hashedindex >= nendcap) {
141  LogDebug("CaloGeometryTools") << " Array overflow " << std::endl;
142  }
143 
144  if (nneighbours == 9) {
145  neighboursEE_[hashedindex].reserve(8);
146  for (unsigned in = 0; in < nneighbours; ++in) {
147  // remove the centre
148  if (neighbours[in] != vecee[ic]) {
149  neighboursEE_[hashedindex].push_back(neighbours[in]);
150  }
151  }
152  } else {
153  DetId central(vecee[ic]);
154  neighboursEE_[hashedindex].resize(8, DetId(0));
155  for (unsigned idir = 0; idir < 8; ++idir) {
156  DetId testid = central;
157  bool status = stdmove(testid, orderedDir[idir], barrelTopo, endcapTopo, barrelGeom, endcapGeom);
158 
159  if (status)
160  neighboursEE_[hashedindex][idir] = testid;
161  }
162  }
163  }
164  // std::cout << " done " << size <<std::endl;
166  }
167 
168  bool stdsimplemove(DetId& cell,
169  const CaloDirection& dir,
170  const CaloSubdetectorTopology& barrelTopo,
171  const CaloSubdetectorTopology& endcapTopo,
172  const EcalBarrelGeometry& barrelGeom,
173  const EcalEndcapGeometry& endcapGeom) const {
174  std::vector<DetId> neighbours;
175 
176  // BARREL CASE
177  if (cell.subdetId() == EcalBarrel) {
178  EBDetId ebDetId = cell;
179 
180  neighbours = barrelTopo.getNeighbours(ebDetId, dir);
181 
182  // first try to move according to the standard navigation
183  if (!neighbours.empty() && !neighbours[0].null()) {
184  cell = neighbours[0];
185  return true;
186  }
187 
188  // failed.
189 
191  // are we on the outer ring ?
192  const int ietaAbs(ebDetId.ietaAbs()); // abs value of ieta
193  if (EBDetId::MAX_IETA == ietaAbs) {
194  // get ee nbrs for for end of barrel crystals
195 
196  // yes we are
197  const EcalBarrelGeometry::OrderedListOfEEDetId& ol(*barrelGeom.getClosestEndcapCells(ebDetId));
198 
199  // take closest neighbour on the other side, that is in the barrel.
200  cell = *(ol.begin());
201  return true;
202  }
203  }
204  }
205 
206  // ENDCAP CASE
207  else if (cell.subdetId() == EcalEndcap) {
208  EEDetId eeDetId = cell;
209 
210  neighbours = endcapTopo.getNeighbours(eeDetId, dir);
211 
212  if (!neighbours.empty() && !neighbours[0].null()) {
213  cell = neighbours[0];
214  return true;
215  }
216 
217  // failed.
218 
220  // are we on the outer ring ?
221  const int iphi(eeDetId.iPhiOuterRing());
222  if (iphi != 0) {
223  // yes we are
224  const EcalEndcapGeometry::OrderedListOfEBDetId& ol(*endcapGeom.getClosestBarrelCells(eeDetId));
225 
226  // take closest neighbour on the other side, that is in the barrel.
227  cell = *(ol.begin());
228  return true;
229  }
230  }
231  }
232 
233  // everything failed
234  cell = DetId(0);
235  return false;
236  }
237 
238  bool stdmove(DetId& cell,
239  const CaloDirection& dir,
240  const CaloSubdetectorTopology& barrelTopo,
241  const CaloSubdetectorTopology& endcapTopo,
242  const EcalBarrelGeometry& barrelGeom,
243  const EcalEndcapGeometry& endcapGeom)
244 
245  const {
246  bool result;
247 
248  if (dir == NORTH) {
249  result = stdsimplemove(cell, NORTH, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
250  return result;
251  } else if (dir == SOUTH) {
252  result = stdsimplemove(cell, SOUTH, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
253  return result;
254  } else if (dir == EAST) {
255  result = stdsimplemove(cell, EAST, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
256  return result;
257  } else if (dir == WEST) {
258  result = stdsimplemove(cell, WEST, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
259  return result;
260  }
261 
262  // One has to try both paths
263  else if (dir == NORTHEAST) {
264  result = stdsimplemove(cell, NORTH, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
265  if (result)
266  return stdsimplemove(cell, EAST, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
267  else {
268  result = stdsimplemove(cell, EAST, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
269  if (result)
270  return stdsimplemove(cell, NORTH, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
271  else
272  return false;
273  }
274  } else if (dir == NORTHWEST) {
275  result = stdsimplemove(cell, NORTH, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
276  if (result)
277  return stdsimplemove(cell, WEST, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
278  else {
279  result = stdsimplemove(cell, WEST, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
280  if (result)
281  return stdsimplemove(cell, NORTH, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
282  else
283  return false;
284  }
285  } else if (dir == SOUTHEAST) {
286  result = stdsimplemove(cell, SOUTH, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
287  if (result)
288  return stdsimplemove(cell, EAST, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
289  else {
290  result = stdsimplemove(cell, EAST, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
291  if (result)
292  return stdsimplemove(cell, SOUTH, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
293  else
294  return false;
295  }
296  } else if (dir == SOUTHWEST) {
297  result = stdsimplemove(cell, SOUTH, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
298  if (result)
299  return stdsimplemove(cell, WEST, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
300  else {
301  result = stdsimplemove(cell, SOUTH, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
302  if (result)
303  return stdsimplemove(cell, WEST, barrelTopo, endcapTopo, barrelGeom, endcapGeom);
304  else
305  return false;
306  }
307  }
308  cell = DetId(0);
309  return false;
310  }
311 
312  DetId move(DetId cell, const CaloDirection& dir) const {
313  DetId originalcell = cell;
314  if (dir == NONE || cell == DetId(0))
315  return false;
316 
317  // Conversion CaloDirection and index in the table
318  // CaloDirection :NONE,SOUTH,SOUTHEAST,SOUTHWEST,EAST,WEST, NORTHEAST,NORTHWEST,NORTH
319  // Table : SOUTHWEST,SOUTH,SOUTHEAST,WEST,EAST,NORTHWEST,NORTH, NORTHEAST
320  static const int calodirections[9] = {-1, 1, 2, 0, 4, 3, 7, 5, 6};
321 
323 
324  DetId result = (originalcell.subdetId() == EcalBarrel)
325  ? neighboursEB_[EBDetId(originalcell).hashedIndex()][calodirections[dir]]
326  : neighboursEE_[EEDetId(originalcell).hashedIndex()][calodirections[dir]];
327  return result;
328  }
329 
330  std::unique_ptr<EcalEndcapTopology> endcapTopology_;
331  std::unique_ptr<EcalBarrelTopology> barrelTopology_;
332 
335 
337  std::vector<std::vector<DetId> > neighboursEB_;
338 
340  std::vector<std::vector<DetId> > neighboursEE_;
341 
344 
347 
348 private:
350 };
351 
352 #endif
edm::RefProd
Definition: EDProductfwd.h:25
EBDetId::hashedIndex
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:82
CaloDirection
CaloDirection
Codes the local directions in the cell lattice.
Definition: CaloDirection.h:9
PFECALHashNavigator::endcapGeometry_
const EcalEndcapGeometry * endcapGeometry_
Definition: PFECALHashNavigator.h:333
electrons_cff.bool
bool
Definition: electrons_cff.py:366
EcalBarrelGeometry.h
CaloNavigator.h
EcalBarrelGeometry::getClosestEndcapCells
const OrderedListOfEEDetId * getClosestEndcapCells(EBDetId id) const
Definition: EcalBarrelGeometry.cc:338
PFECALHashNavigator::endcapTopology_
std::unique_ptr< EcalEndcapTopology > endcapTopology_
Definition: PFECALHashNavigator.h:330
funct::false
false
Definition: Factorize.h:29
PFRecHitNavigatorBase::associateNeighbour
void associateNeighbour(const DetId &id, reco::PFRecHit &hit, std::unique_ptr< reco::PFRecHitCollection > &hits, edm::RefProd< reco::PFRecHitCollection > &refProd, short eta, short phi, short depth)
Definition: PFRecHitNavigatorBase.h:40
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
EcalEndcapGeometry
Definition: EcalEndcapGeometry.h:20
east
Definition: EcalBoundaryInfoCalculator.h:24
mps_update.status
status
Definition: mps_update.py:68
PFECALHashNavigator::neighboursEE_
std::vector< std::vector< DetId > > neighboursEE_
for each ecal endcap rechit, keep track of the neighbours
Definition: PFECALHashNavigator.h:340
EBDetId
Definition: EBDetId.h:17
edm
HLT enums.
Definition: AlignableModifier.h:19
EBDetId.h
EEDetId.h
EcalBarrelTopology.h
CaloGeometry::getSubdetectorGeometry
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
cms::cuda::assert
assert(be >=bs)
EZArrayFL
Definition: EZArrayFL.h:20
EcalBarrel
Definition: EcalSubdetector.h:10
PFRecHitNavigatorBase.h
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
DetId
Definition: DetId.h:17
EAST
Definition: CaloDirection.h:14
NORTH
Definition: CaloDirection.h:18
PFECALHashNavigator::move
DetId move(DetId cell, const CaloDirection &dir) const
Definition: PFECALHashNavigator.h:312
orderedDir
static const CaloDirection orderedDir[8]
Definition: PFECALHashNavigator.h:18
SOUTHEAST
Definition: CaloDirection.h:12
edm::ESHandle< CaloGeometry >
south
Definition: EcalBoundaryInfoCalculator.h:24
PFECALHashNavigator::geomToken_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geomToken_
Definition: PFECALHashNavigator.h:349
PFECALHashNavigator::associateNeighbours
void associateNeighbours(reco::PFRecHit &rh, std::unique_ptr< reco::PFRecHitCollection > &hits, edm::RefProd< reco::PFRecHitCollection > &refprod) override
Definition: PFECALHashNavigator.h:46
PFECALHashNavigator::init
void init(const edm::EventSetup &iSetup) override
Definition: PFECALHashNavigator.h:30
CaloSubdetectorGeometry::getValidDetIds
virtual const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const
Get a list of valid detector ids (for the given subdetector)
Definition: CaloSubdetectorGeometry.cc:32
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
EEDetId
Definition: EEDetId.h:14
EcalEndcap
Definition: EcalSubdetector.h:10
PFECALHashNavigator::barrelTopology_
std::unique_ptr< EcalBarrelTopology > barrelTopology_
Definition: PFECALHashNavigator.h:331
PFECALHashNavigator::stdsimplemove
bool stdsimplemove(DetId &cell, const CaloDirection &dir, const CaloSubdetectorTopology &barrelTopo, const CaloSubdetectorTopology &endcapTopo, const EcalBarrelGeometry &barrelGeom, const EcalEndcapGeometry &endcapGeom) const
Definition: PFECALHashNavigator.h:168
CaloSubdetectorTopology::getNeighbours
virtual std::vector< DetId > getNeighbours(const DetId &id, const CaloDirection &dir) const
Definition: CaloSubdetectorTopology.h:77
PFECALHashNavigator::PFECALHashNavigator
PFECALHashNavigator()
Definition: PFECALHashNavigator.h:22
PFECALHashNavigator::stdmove
bool stdmove(DetId &cell, const CaloDirection &dir, const CaloSubdetectorTopology &barrelTopo, const CaloSubdetectorTopology &endcapTopo, const EcalBarrelGeometry &barrelGeom, const EcalEndcapGeometry &endcapGeom) const
Definition: PFECALHashNavigator.h:238
CaloSubdetectorGeometry.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
EcalBarrelGeometry
Definition: EcalBarrelGeometry.h:19
EcalEndcapGeometry.h
EcalEndcapTopology.h
PFRecHitNavigatorBase
Definition: PFRecHitNavigatorBase.h:25
recoMuon::in
Definition: RecoMuonEnumerators.h:6
PFECALHashNavigator::neighboursEB_
std::vector< std::vector< DetId > > neighboursEB_
for each ecal barrel rechit, keep track of the neighbours
Definition: PFECALHashNavigator.h:337
EEDetId::hashedIndex
int hashedIndex() const
Definition: EEDetId.h:183
PFECALHashNavigator::neighbourmapcalculated_
bool neighbourmapcalculated_
set to true in ecalNeighbArray
Definition: PFECALHashNavigator.h:343
SOUTHWEST
Definition: CaloDirection.h:13
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
edm::EventSetup
Definition: EventSetup.h:58
CaloSubdetectorTopology
Definition: CaloSubdetectorTopology.h:17
DetId::Ecal
Definition: DetId.h:27
cc
edm::ESGetToken< CaloGeometry, CaloGeometryRecord >
PFECALHashNavigator::PFECALHashNavigator
PFECALHashNavigator(const edm::ParameterSet &iConfig, edm::ConsumesCollector &cc)
Definition: PFECALHashNavigator.h:24
north
Definition: EcalBoundaryInfoCalculator.h:24
CaloSubdetectorTopology::getWindow
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
Definition: CaloSubdetectorTopology.cc:4
reco::PFRecHit::detId
unsigned detId() const
rechit detId
Definition: PFRecHit.h:93
central
Definition: L1PrefiringWeightProducer.cc:40
EcalEndcapGeometry::getClosestBarrelCells
const OrderedListOfEBDetId * getClosestBarrelCells(EEDetId id) const
Definition: EcalEndcapGeometry.cc:372
WEST
Definition: CaloDirection.h:15
CaloGeometry.h
NORTHWEST
Definition: CaloDirection.h:17
EBDetId::ietaAbs
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:47
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
NONE
Definition: TkAlStyle.cc:47
EEDetId::iPhiOuterRing
int iPhiOuterRing() const
Definition: EEDetId.cc:295
reco::PFRecHit
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:31
SOUTH
Definition: CaloDirection.h:11
mps_fire.result
result
Definition: mps_fire.py:311
ConsumesCollector.h
PFECALHashNavigator
Definition: PFECALHashNavigator.h:20
NORTHEAST
Definition: CaloDirection.h:16
west
Definition: EcalBoundaryInfoCalculator.h:24
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
PFECALHashNavigator::crossBarrelEndcapBorder_
bool crossBarrelEndcapBorder_
if true, navigation will cross the barrel-endcap border
Definition: PFECALHashNavigator.h:346
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
PFECALHashNavigator::barrelGeometry_
const EcalBarrelGeometry * barrelGeometry_
Definition: PFECALHashNavigator.h:334
EBDetId::MAX_IETA
static const int MAX_IETA
Definition: EBDetId.h:136
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
PFECALHashNavigator::ecalNeighbArray
void ecalNeighbArray(const EcalBarrelGeometry &barrelGeom, const CaloSubdetectorTopology &barrelTopo, const EcalEndcapGeometry &endcapGeom, const CaloSubdetectorTopology &endcapTopo)
Definition: PFECALHashNavigator.h:71