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