CMS 3D CMS Logo

IslandClusterAlgo.cc
Go to the documentation of this file.
2 
3 // Geometry
9 
12 
13 //
15 
16 // Return a vector of clusters from a collection of EcalRecHits:
17 std::vector<reco::BasicCluster> IslandClusterAlgo::makeClusters(const EcalRecHitCollection *hits,
18  const CaloSubdetectorGeometry *geometry_p,
19  const CaloSubdetectorTopology *topology_p,
20  const CaloSubdetectorGeometry *geometryES_p,
21  EcalPart ecalPart,
22  bool regional,
23  const std::vector<RectangularEtaPhiRegion> &regions) {
24  seeds.clear();
25  used_s.clear();
26  clusters_v.clear();
27 
28  recHits_ = hits;
29 
30  double threshold = 0;
31  std::string ecalPart_string;
32  if (ecalPart == endcap) {
34  ecalPart_string = "EndCap";
37  }
38  if (ecalPart == barrel) {
40  ecalPart_string = "Barrel";
43  }
44 
45  if (verbosity < pINFO) {
46  std::cout << "-------------------------------------------------------------" << std::endl;
47  std::cout << "Island algorithm invoked for ECAL" << ecalPart_string << std::endl;
48  std::cout << "Looking for seeds, energy threshold used = " << threshold << " GeV" << std::endl;
49  }
50 
51  int nregions = 0;
52  if (regional)
53  nregions = regions.size();
54 
55  if (!regional || nregions) {
57  for (it = hits->begin(); it != hits->end(); it++) {
58  double energy = it->energy();
59  if (energy < threshold)
60  continue; // need to check to see if this line is useful!
61 
62  // avoid seeding for anomalous channels
63  if (!it->checkFlag(EcalRecHit::kGood)) { // if rechit is good, no need for further checks
64  if (it->checkFlags(v_chstatus_) || it->checkFlags(v_chstatusSeed_)) {
65  continue; // the recHit has to be excluded from seeding
66  }
67  }
68 
69  auto thisCell = geometry_p->getGeometry(it->id());
70  auto const &position = thisCell->getPosition();
71 
72  // Require that RecHit is within clustering region in case
73  // of regional reconstruction
74  bool withinRegion = false;
75  if (regional) {
76  std::vector<RectangularEtaPhiRegion>::const_iterator region;
77  for (region = regions.begin(); region != regions.end(); region++) {
78  if (region->inRegion(thisCell->etaPos(), thisCell->phiPos())) {
79  withinRegion = true;
80  break;
81  }
82  }
83  }
84 
85  if (!regional || withinRegion) {
86  float ET = it->energy() * position.basicVector().unit().perp();
87  if (ET > threshold)
88  seeds.push_back(*it);
89  }
90  }
91  }
92 
93  sort(seeds.begin(), seeds.end(), [](auto const &x, auto const &y) { return x.energy() > y.energy(); });
94 
95  if (verbosity < pINFO) {
96  std::cout << "Total number of seeds found in event = " << seeds.size() << std::endl;
97  }
98 
99  mainSearch(hits, geometry_p, topology_p, geometryES_p, ecalPart);
100  sort(clusters_v.rbegin(), clusters_v.rend(), isClusterEtLess);
101 
102  if (verbosity < pINFO) {
103  std::cout << "---------- end of main search. clusters have been sorted ----" << std::endl;
104  }
105 
106  return clusters_v;
107 }
108 
110  const CaloSubdetectorGeometry *geometry_p,
111  const CaloSubdetectorTopology *topology_p,
112  const CaloSubdetectorGeometry *geometryES_p,
113  EcalPart ecalPart) {
114  if (verbosity < pINFO) {
115  std::cout << "Building clusters............" << std::endl;
116  }
117 
118  // Loop over seeds:
119  std::vector<EcalRecHit>::iterator it;
120  for (it = seeds.begin(); it != seeds.end(); it++) {
121  // make sure the current seed does not belong to a cluster already.
122  if (used_s.find(it->id()) != used_s.end()) {
123  if (it == seeds.begin()) {
124  if (verbosity < pINFO) {
125  std::cout << "##############################################################" << std::endl;
126  std::cout << "DEBUG ALERT: Highest energy seed already belongs to a cluster!" << std::endl;
127  std::cout << "##############################################################" << std::endl;
128  }
129  }
130  continue;
131  }
132 
133  // clear the vector of hits in current cluster
134  current_v.clear();
135 
136  current_v.push_back(std::pair<DetId, float>(it->id(), 1.)); // by default hit energy fractions are set at 1.
137  used_s.insert(it->id());
138 
139  // Create a navigator at the seed
140  CaloNavigator<DetId> navigator(it->id(), topology_p);
141 
143  navigator.home();
145  navigator.home();
146  searchWest(navigator, topology_p);
147  navigator.home();
148  searchEast(navigator, topology_p);
149 
150  makeCluster(hits, geometry_p, geometryES_p);
151  }
152 }
153 
155  DetId southern = navigator.pos();
156 
157  DetId northern = navigator.north();
158  if (northern == DetId(0))
159  return; // This means that we went off the ECAL!
160  // if the crystal to the north belongs to another cluster return
161  if (used_s.find(northern) != used_s.end())
162  return;
163 
164  EcalRecHitCollection::const_iterator southern_it = recHits_->find(southern);
165  EcalRecHitCollection::const_iterator northern_it = recHits_->find(northern);
166 
167  if (shouldBeAdded(northern_it, southern_it)) {
168  current_v.push_back(std::pair<DetId, float>(northern, 1.)); // by default hit energy fractions are set at 1.
169  used_s.insert(northern);
171  }
172 }
173 
175  DetId northern = navigator.pos();
176 
177  DetId southern = navigator.south();
178  if (southern == DetId(0))
179  return; // This means that we went off the ECAL!
180  if (used_s.find(southern) != used_s.end())
181  return;
182 
183  EcalRecHitCollection::const_iterator northern_it = recHits_->find(northern);
184  EcalRecHitCollection::const_iterator southern_it = recHits_->find(southern);
185 
186  if (shouldBeAdded(southern_it, northern_it)) {
187  current_v.push_back(std::pair<DetId, float>(southern, 1.)); // by default hit energy fractions are set at 1.
188  used_s.insert(southern);
190  }
191 }
192 
194  DetId eastern = navigator.pos();
195  EcalRecHitCollection::const_iterator eastern_it = recHits_->find(eastern);
196 
197  DetId western = navigator.west();
198  if (western == DetId(0))
199  return; // This means that we went off the ECAL!
200  EcalRecHitCollection::const_iterator western_it = recHits_->find(western);
201 
202  if (shouldBeAdded(western_it, eastern_it)) {
203  CaloNavigator<DetId> nsNavigator(western, topology);
204 
205  searchNorth(nsNavigator);
206  nsNavigator.home();
207  searchSouth(nsNavigator);
208  nsNavigator.home();
209  searchWest(navigator, topology);
210 
211  current_v.push_back(std::pair<DetId, float>(western, 1.)); // by default hit energy fractions are set at 1.
212  used_s.insert(western);
213  }
214 }
215 
217  DetId western = navigator.pos();
218  EcalRecHitCollection::const_iterator western_it = recHits_->find(western);
219 
220  DetId eastern = navigator.east();
221  if (eastern == DetId(0))
222  return; // This means that we went off the ECAL!
223  EcalRecHitCollection::const_iterator eastern_it = recHits_->find(eastern);
224 
225  if (shouldBeAdded(eastern_it, western_it)) {
226  CaloNavigator<DetId> nsNavigator(eastern, topology);
227 
228  searchNorth(nsNavigator);
229  nsNavigator.home();
230  searchSouth(nsNavigator);
231  nsNavigator.home();
232  searchEast(navigator, topology);
233 
234  current_v.push_back(std::pair<DetId, float>(eastern, 1.)); // by default hit energy fractions are set at 1.
235  used_s.insert(eastern);
236  }
237 }
238 
239 // returns true if the candidate crystal fulfills the requirements to be added to the cluster:
242  // crystal should not be included...
243  if ((candidate_it == recHits_->end()) || // ...if it does not correspond to a hit
244  (used_s.find(candidate_it->id()) != used_s.end()) || // ...if it already belongs to a cluster
245  (candidate_it->energy() <= 0) || // ...if it has a negative or zero energy
246  (candidate_it->energy() > previous_it->energy()) || // ...or if the previous crystal had lower E
247  (!(candidate_it->checkFlag(EcalRecHit::kGood)) && candidate_it->checkFlags(v_chstatus_))) {
248  return false;
249  }
250  return true;
251 }
252 
255  const CaloSubdetectorGeometry *geometryES) {
256  double energy = 0;
257  reco::CaloID caloID;
258 
259  Point position;
261 
262  std::vector<std::pair<DetId, float> >::iterator it;
263  for (it = current_v.begin(); it != current_v.end(); it++) {
264  EcalRecHitCollection::const_iterator itt = hits->find((*it).first);
265  EcalRecHit hit_p = *itt;
266  if ((*it).first.subdetId() == EcalBarrel) {
268  } else {
270  }
271  // if (hit_p != 0)
272  // {
273  energy += hit_p.energy();
274  // }
275  // else
276  // {
277  // std::cout << "DEBUG ALERT: Requested rechit has gone missing from rechits map! :-S" << std::endl;
278  // }
279  }
280 
281  if (verbosity < pINFO) {
282  std::cout << "******** NEW CLUSTER ********" << std::endl;
283  std::cout << "No. of crystals = " << current_v.size() << std::endl;
284  std::cout << " Energy = " << energy << std::endl;
285  std::cout << " Phi = " << position.phi() << std::endl;
286  std::cout << " Eta = " << position.eta() << std::endl;
287  std::cout << "*****************************" << std::endl;
288  }
290 }
IslandClusterAlgo::v_chstatusSeed_Barrel_
std::vector< int > v_chstatusSeed_Barrel_
Definition: IslandClusterAlgo.h:92
IslandClusterAlgo::searchWest
void searchWest(const CaloNavigator< DetId > &navigator, const CaloSubdetectorTopology *topology)
Definition: IslandClusterAlgo.cc:193
DDAxes::y
EcalRecHit
Definition: EcalRecHit.h:15
PositionCalc.h
edm::SortedCollection< EcalRecHit >::const_iterator
std::vector< EcalRecHit >::const_iterator const_iterator
Definition: SortedCollection.h:80
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
IslandClusterAlgo::endcap
Definition: IslandClusterAlgo.h:28
IslandClusterAlgo::ecalEndcapSeedThreshold
double ecalEndcapSeedThreshold
Definition: IslandClusterAlgo.h:74
IslandClusterAlgo::v_chstatusSeed_Endcap_
std::vector< int > v_chstatusSeed_Endcap_
Definition: IslandClusterAlgo.h:93
HLT_FULL_cff.navigator
navigator
Definition: HLT_FULL_cff.py:13126
IslandClusterAlgo::v_chstatus_
std::vector< int > v_chstatus_
Definition: IslandClusterAlgo.h:100
reco::CaloID::DET_ECAL_ENDCAP
Definition: CaloID.h:21
geometry
Definition: geometry.py:1
gather_cfg.cout
cout
Definition: gather_cfg.py:144
IslandClusterAlgo::posCalculator_
PositionCalc posCalculator_
Definition: IslandClusterAlgo.h:70
IslandClusterAlgo::EcalPart
EcalPart
Definition: IslandClusterAlgo.h:28
EcalBarrelTopology.h
IslandClusterAlgo.h
CaloID.h
edm::SortedCollection< EcalRecHit >
IslandClusterAlgo::mainSearch
void mainSearch(const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry_p, const CaloSubdetectorTopology *topology_p, const CaloSubdetectorGeometry *geometryES_p, EcalPart ecalPart)
Definition: IslandClusterAlgo.cc:109
DDAxes::x
EcalRecHit::energy
float energy() const
Definition: EcalRecHit.h:68
EcalBarrel
Definition: EcalSubdetector.h:10
DetId
Definition: DetId.h:17
IslandClusterAlgo::searchNorth
void searchNorth(const CaloNavigator< DetId > &navigator)
Definition: IslandClusterAlgo.cc:154
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
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
EcalRecHit::kGood
Definition: EcalRecHit.h:21
IslandClusterAlgo::barrel
Definition: IslandClusterAlgo.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ET
#define ET
Definition: GenericBenchmark.cc:27
Point
Structure Point Contains parameters of Gaussian fits to DMRs.
Definition: DMRtrends.cc:57
CaloSubdetectorGeometry.h
CaloNavigator::home
void home() const
move the navigator back to the starting point
Definition: CaloNavigator.h:96
EcalEndcapTopology.h
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
IslandClusterAlgo::makeCluster
void makeCluster(const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry_p, const CaloSubdetectorGeometry *geometryES_p)
Definition: IslandClusterAlgo.cc:253
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
HLT_FULL_cff.region
region
Definition: HLT_FULL_cff.py:88271
IdealGeometryRecord.h
CaloSubdetectorGeometry::getGeometry
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
Definition: CaloSubdetectorGeometry.cc:36
CaloSubdetectorTopology
Definition: CaloSubdetectorTopology.h:17
IslandClusterAlgo::verbosity
VerbosityLevel verbosity
Definition: IslandClusterAlgo.h:103
IslandClusterAlgo::recHits_
const EcalRecHitCollection * recHits_
Definition: IslandClusterAlgo.h:77
reco::CaloID
Definition: CaloID.h:17
reco::CaloCluster::island
Definition: CaloCluster.h:34
IslandClusterAlgo::seeds
std::vector< EcalRecHit > seeds
Definition: IslandClusterAlgo.h:80
isClusterEtLess
bool isClusterEtLess(const reco::CaloCluster &x, const reco::CaloCluster &y)
Definition: ClusterEtLess.h:7
edm::SortedCollection::find
iterator find(key_type k)
Definition: SortedCollection.h:240
CaloCellGeometry.h
CaloNavigator
Definition: CaloNavigator.h:7
IslandClusterAlgo::used_s
std::set< DetId > used_s
Definition: IslandClusterAlgo.h:83
IslandClusterAlgo::searchSouth
void searchSouth(const CaloNavigator< DetId > &navigator)
Definition: IslandClusterAlgo.cc:174
IslandClusterAlgo::makeClusters
std::vector< reco::BasicCluster > makeClusters(const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology_p, const CaloSubdetectorGeometry *geometryES_p, EcalPart ecalPart, bool regional=false, const std::vector< RectangularEtaPhiRegion > &regions=std::vector< RectangularEtaPhiRegion >())
Definition: IslandClusterAlgo.cc:17
IslandClusterAlgo::v_chstatus_Barrel_
std::vector< int > v_chstatus_Barrel_
Definition: IslandClusterAlgo.h:96
IslandClusterAlgo::pINFO
Definition: IslandClusterAlgo.h:29
IslandClusterAlgo::current_v
std::vector< std::pair< DetId, float > > current_v
Definition: IslandClusterAlgo.h:86
ClusterEtLess.h
IslandClusterAlgo::searchEast
void searchEast(const CaloNavigator< DetId > &navigator, const CaloSubdetectorTopology *topology)
Definition: IslandClusterAlgo.cc:216
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
AlignmentPI::regions
regions
Definition: AlignmentPayloadInspectorHelper.h:76
IslandClusterAlgo::clusters_v
std::vector< reco::BasicCluster > clusters_v
Definition: IslandClusterAlgo.h:89
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:430
IslandClusterAlgo::v_chstatus_Endcap_
std::vector< int > v_chstatus_Endcap_
Definition: IslandClusterAlgo.h:97
IslandClusterAlgo::v_chstatusSeed_
std::vector< int > v_chstatusSeed_
Definition: IslandClusterAlgo.h:99
IslandClusterAlgo::shouldBeAdded
bool shouldBeAdded(EcalRecHitCollection::const_iterator candidate_it, EcalRecHitCollection::const_iterator previous_it)
Definition: IslandClusterAlgo.cc:240
reco::CaloID::DET_ECAL_BARREL
Definition: CaloID.h:20
IslandClusterAlgo::ecalBarrelSeedThreshold
double ecalBarrelSeedThreshold
Definition: IslandClusterAlgo.h:73