CMS 3D CMS Logo

PFHCALDenseIdNavigator.h
Go to the documentation of this file.
1 #ifndef RecoParticleFlow_PFClusterProducer_PFHCALDenseIdNavigator_h
2 #define RecoParticleFlow_PFClusterProducer_PFHCALDenseIdNavigator_h
3 
5 
9 
15 
20 
23 
24 template <typename DET, typename TOPO, bool ownsTopo = true>
26 public:
28  if (!ownsTopo) {
29  topology_.release();
30  }
31  }
32 
34  vhcalEnum_ = iConfig.getParameter<std::vector<int>>("hcalEnums");
35  }
36 
37  void init(const edm::EventSetup& iSetup) override {
38  bool check = theRecNumberWatcher_.check(iSetup);
39  if (!check)
40  return;
41 
42  edm::ESHandle<HcalTopology> hcalTopology;
43  iSetup.get<HcalRecNumberingRecord>().get(hcalTopology);
44  topology_.release();
45  topology_.reset(hcalTopology.product());
46 
47  // Fill a vector of valid denseid's
49  iSetup.get<CaloGeometryRecord>().get(hGeom);
50  const CaloGeometry& caloGeom = *hGeom;
51 
52  std::vector<DetId> vecHcal;
53  std::vector<unsigned int> vDenseIdHcal;
54  neighboursHcal_.clear();
55  for (auto hcalSubdet : vhcalEnum_) {
56  std::vector<DetId> vecDetIds(caloGeom.getValidDetIds(DetId::Hcal, hcalSubdet));
57  vecHcal.insert(vecHcal.end(), vecDetIds.begin(), vecDetIds.end());
58  }
59  for (auto hDetId : vecHcal) {
60  vDenseIdHcal.push_back(topology_.get()->detId2denseId(hDetId));
61  }
62  std::sort(vDenseIdHcal.begin(), vDenseIdHcal.end());
63 
64  // Fill a vector of cell neighbours
65  denseIdHcalMax_ = *max_element(vDenseIdHcal.begin(), vDenseIdHcal.end());
66  denseIdHcalMin_ = *min_element(vDenseIdHcal.begin(), vDenseIdHcal.end());
68 
69  for (auto denseid : vDenseIdHcal) {
70  DetId N(0);
71  DetId E(0);
72  DetId S(0);
73  DetId W(0);
74  DetId NW(0);
75  DetId NE(0);
76  DetId SW(0);
77  DetId SE(0);
78  std::vector<DetId> neighbours(9, DetId(0));
79 
80  // the centre
81  unsigned denseid_c = denseid;
82  DetId detid_c = topology_.get()->denseId2detId(denseid_c);
83  CaloNavigator<DET> navigator(detid_c, topology_.get());
84 
85  // Using enum in Geometry/CaloTopology/interface/CaloDirection.h
86  // Order: CENTER(NONE),SOUTH,SOUTHEAST,SOUTHWEST,EAST,WEST,NORTHEAST,NORTHWEST,NORTH
87  neighbours.at(NONE) = detid_c;
88 
89  navigator.home();
90  N = navigator.north();
91  neighbours.at(NORTH) = N;
92  if (N != DetId(0)) {
93  NE = navigator.east();
94  } else {
95  navigator.home();
96  E = navigator.east();
97  NE = navigator.north();
98  }
99  neighbours.at(NORTHEAST) = NE;
100 
101  navigator.home();
102  S = navigator.south();
103  neighbours.at(SOUTH) = S;
104  if (S != DetId(0)) {
105  SW = navigator.west();
106  } else {
107  navigator.home();
108  W = navigator.west();
109  SW = navigator.south();
110  }
111  neighbours.at(SOUTHWEST) = SW;
112 
113  navigator.home();
114  E = navigator.east();
115  neighbours.at(EAST) = E;
116  if (E != DetId(0)) {
117  SE = navigator.south();
118  } else {
119  navigator.home();
120  S = navigator.south();
121  SE = navigator.east();
122  }
123  neighbours.at(SOUTHEAST) = SE;
124 
125  navigator.home();
126  W = navigator.west();
127  neighbours.at(WEST) = W;
128  if (W != DetId(0)) {
129  NW = navigator.north();
130  } else {
131  navigator.home();
132  N = navigator.north();
133  NW = navigator.west();
134  }
135  neighbours.at(NORTHWEST) = NW;
136 
137  unsigned index = getIdx(denseid_c);
138  neighboursHcal_[index] = neighbours;
139  }
140  }
141 
143  std::unique_ptr<reco::PFRecHitCollection>& hits,
144  edm::RefProd<reco::PFRecHitCollection>& refProd) override {
145  DetId detid(hit.detId());
146  unsigned denseid = topology_.get()->detId2denseId(detid);
147 
148  std::vector<DetId> neighbours(9, DetId(0));
149 
150  if (denseid < denseIdHcalMin_ || denseid > denseIdHcalMax_) {
151  edm::LogWarning("PFRecHitHCALCachedNavigator") << " DenseId for this cell is out of the range." << std::endl;
152  } else if (!validNeighbours(denseid)) {
153  edm::LogWarning("PFRecHitHCALCachedNavigator")
154  << " DenseId for this cell does not have the neighbour information." << std::endl;
155  } else {
156  unsigned index = getIdx(denseid);
157  neighbours = neighboursHcal_.at(index);
158  }
159 
160  associateNeighbour(neighbours.at(NORTH), hit, hits, refProd, 0, 1, 0); // N
161  associateNeighbour(neighbours.at(NORTHEAST), hit, hits, refProd, 1, 1, 0); // NE
162  associateNeighbour(neighbours.at(SOUTH), hit, hits, refProd, 0, -1, 0); // S
163  associateNeighbour(neighbours.at(SOUTHWEST), hit, hits, refProd, -1, -1, 0); // SW
164  associateNeighbour(neighbours.at(EAST), hit, hits, refProd, 1, 0, 0); // E
165  associateNeighbour(neighbours.at(SOUTHEAST), hit, hits, refProd, 1, -1, 0); // SE
166  associateNeighbour(neighbours.at(WEST), hit, hits, refProd, -1, 0, 0); // W
167  associateNeighbour(neighbours.at(NORTHWEST), hit, hits, refProd, -1, 1, 0); // NW
168  }
169 
170  bool validNeighbours(const unsigned int denseid) const {
171  bool ok = true;
172  unsigned index = getIdx(denseid);
173  if (neighboursHcal_.at(index).size() != 9)
174  ok = false; // the neighbour vector size should be 3x3
175  return ok;
176  }
177 
178  unsigned int getIdx(const unsigned int denseid) const {
179  unsigned index = denseid - denseIdHcalMin_;
180  return index;
181  }
182 
183 protected:
185  std::unique_ptr<const TOPO> topology_;
186  std::vector<int> vhcalEnum_;
187  std::vector<std::vector<DetId>> neighboursHcal_;
188  unsigned int denseIdHcalMax_;
189  unsigned int denseIdHcalMin_;
190 };
191 
192 #endif
edm::RefProd
Definition: EDProductfwd.h:25
EcalPreshowerTopology.h
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
CaloNavigator.h
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:41
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
edm::ESWatcher< HcalRecNumberingRecord >
HLT_FULL_cff.navigator
navigator
Definition: HLT_FULL_cff.py:13189
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
EBDetId.h
EEDetId.h
DetId::Hcal
Definition: DetId.h:28
EcalBarrelTopology.h
PFHCALDenseIdNavigator::vhcalEnum_
std::vector< int > vhcalEnum_
Definition: PFHCALDenseIdNavigator.h:186
PFHCALDenseIdNavigator::validNeighbours
bool validNeighbours(const unsigned int denseid) const
Definition: PFHCALDenseIdNavigator.h:170
PFHCALDenseIdNavigator::denseIdHcalMin_
unsigned int denseIdHcalMin_
Definition: PFHCALDenseIdNavigator.h:189
ESDetId.h
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
PFHCALDenseIdNavigator::PFHCALDenseIdNavigator
PFHCALDenseIdNavigator(const edm::ParameterSet &iConfig)
Definition: PFHCALDenseIdNavigator.h:33
PFRecHitNavigatorBase.h
PFHCALDenseIdNavigator::denseIdHcalMax_
unsigned int denseIdHcalMax_
Definition: PFHCALDenseIdNavigator.h:188
DetId
Definition: DetId.h:17
CaloGeometry
Definition: CaloGeometry.h:21
RPCNoise_example.check
check
Definition: RPCNoise_example.py:71
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
EAST
Definition: CaloDirection.h:14
NORTH
Definition: CaloDirection.h:18
SOUTHEAST
Definition: CaloDirection.h:12
edm::ESHandle< HcalTopology >
N
#define N
Definition: blowfish.cc:9
PFHCALDenseIdNavigator
Definition: PFHCALDenseIdNavigator.h:25
PFHCALDenseIdNavigator::~PFHCALDenseIdNavigator
~PFHCALDenseIdNavigator() override
Definition: PFHCALDenseIdNavigator.h:27
CaloTowerTopology.h
PFHCALDenseIdNavigator::associateNeighbours
void associateNeighbours(reco::PFRecHit &hit, std::unique_ptr< reco::PFRecHitCollection > &hits, edm::RefProd< reco::PFRecHitCollection > &refProd) override
Definition: PFHCALDenseIdNavigator.h:142
HcalRecNumberingRecord
Definition: HcalRecNumberingRecord.h:23
S
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:97
CaloSubdetectorGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
PFHCALDenseIdNavigator::init
void init(const edm::EventSetup &iSetup) override
Definition: PFHCALDenseIdNavigator.h:37
EcalEndcapTopology.h
HcalDetId.h
PFRecHitNavigatorBase
Definition: PFRecHitNavigatorBase.h:26
PFHCALDenseIdNavigator::getIdx
unsigned int getIdx(const unsigned int denseid) const
Definition: PFHCALDenseIdNavigator.h:178
SOUTHWEST
Definition: CaloDirection.h:13
PFHCALDenseIdNavigator::theRecNumberWatcher_
edm::ESWatcher< HcalRecNumberingRecord > theRecNumberWatcher_
Definition: PFHCALDenseIdNavigator.h:184
CaloTowerDetId.h
edm::EventSetup
Definition: EventSetup.h:57
PFHCALDenseIdNavigator::topology_
std::unique_ptr< const TOPO > topology_
Definition: PFHCALDenseIdNavigator.h:185
get
#define get
HcalTopology.h
CaloNavigator
Definition: CaloNavigator.h:7
CaloGeometry::getValidDetIds
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:75
WEST
Definition: CaloDirection.h:15
ESWatcher.h
CaloGeometry.h
NORTHWEST
Definition: CaloDirection.h:17
NONE
Definition: TkAlStyle.cc:47
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
S
Definition: CSCDBL1TPParametersExtended.h:16
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
reco::PFRecHit
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:31
SOUTH
Definition: CaloDirection.h:11
NORTHEAST
Definition: CaloDirection.h:16
PFHCALDenseIdNavigator::neighboursHcal_
std::vector< std::vector< DetId > > neighboursHcal_
Definition: PFHCALDenseIdNavigator.h:187
hit
Definition: SiStripHitEffFromCalibTree.cc:88