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) {
33  threshold = ecalEndcapSeedThreshold;
34  ecalPart_string = "EndCap";
37  }
38  if (ecalPart == barrel) {
39  threshold = ecalBarrelSeedThreshold;
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);
170  searchNorth(navigator);
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);
189  searchSouth(navigator);
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;
260  position = posCalculator_.Calculate_Location(current_v, hits, geometry, geometryES);
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  }
289  clusters_v.push_back(reco::BasicCluster(energy, position, caloID, current_v, reco::CaloCluster::island));
290 }
void searchEast(const CaloNavigator< DetId > &navigator, const CaloSubdetectorTopology *topology)
CaloTopology const * topology(0)
void searchWest(const CaloNavigator< DetId > &navigator, const CaloSubdetectorTopology *topology)
std::vector< EcalRecHit >::const_iterator const_iterator
std::vector< int > v_chstatusSeed_Endcap_
PositionCalc posCalculator_
T west() const
move the navigator west
Definition: CaloNavigator.h:49
std::set< DetId > used_s
VerbosityLevel verbosity
float energy() const
Definition: EcalRecHit.h:68
T south() const
move the navigator south
Definition: CaloNavigator.h:37
std::vector< std::pair< DetId, float > > current_v
bool isClusterEtLess(const reco::CaloCluster &x, const reco::CaloCluster &y)
Definition: ClusterEtLess.h:7
T pos() const
get the current position
Definition: CaloNavigator.h:25
std::vector< EcalRecHit > seeds
const_iterator end() const
std::vector< int > v_chstatus_Endcap_
T east() const
move the navigator east
Definition: CaloNavigator.h:43
void home() const
move the navigator back to the starting point
Definition: CaloNavigator.h:97
Definition: DetId.h:17
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 >())
void searchNorth(const CaloNavigator< DetId > &navigator)
bool shouldBeAdded(EcalRecHitCollection::const_iterator candidate_it, EcalRecHitCollection::const_iterator previous_it)
std::vector< int > v_chstatusSeed_
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.
std::vector< reco::BasicCluster > clusters_v
void makeCluster(const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry_p, const CaloSubdetectorGeometry *geometryES_p)
iterator find(key_type k)
math::XYZPoint Calculate_Location(const HitsAndFractions &iDetIds, const edm::SortedCollection< HitType > *iRecHits, const CaloSubdetectorGeometry *iSubGeom, const CaloSubdetectorGeometry *iESGeom=0)
Definition: PositionCalc.h:65
Structure Point Contains parameters of Gaussian fits to DMRs.
Definition: DMRtrends.cc:57
static int position[264][3]
Definition: ReadPGInfo.cc:289
T north() const
move the navigator north
Definition: CaloNavigator.h:31
#define ET
std::vector< int > v_chstatusSeed_Barrel_
const EcalRecHitCollection * recHits_
std::vector< int > v_chstatus_
void searchSouth(const CaloNavigator< DetId > &navigator)
const_iterator begin() const
std::vector< int > v_chstatus_Barrel_
void mainSearch(const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry_p, const CaloSubdetectorTopology *topology_p, const CaloSubdetectorGeometry *geometryES_p, EcalPart ecalPart)