CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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(
18  const EcalRecHitCollection* hits,
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<EcalEtaPhiRegion>& 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";
38  }
39  if (ecalPart == barrel)
40  {
41  threshold = ecalBarrelSeedThreshold;
42  ecalPart_string = "Barrel";
43  }
44 
45  if (verbosity < pINFO)
46  {
47  std::cout << "-------------------------------------------------------------" << std::endl;
48  std::cout << "Island algorithm invoked for ECAL" << ecalPart_string << std::endl;
49  std::cout << "Looking for seeds, energy threshold used = " << threshold << " GeV" <<std::endl;
50  }
51 
52  int nregions=0;
53  if(regional) nregions=regions.size();
54 
55  if(!regional || nregions) {
56 
58  for(it = hits->begin(); it != hits->end(); it++)
59  {
60  double energy = it->energy();
61  if (energy < threshold) continue; // need to check to see if this line is useful!
62 
63  const CaloCellGeometry *thisCell = geometry_p->getGeometry(it->id());
64  GlobalPoint position = thisCell->getPosition();
65 
66  // Require that RecHit is within clustering region in case
67  // of regional reconstruction
68  bool withinRegion = false;
69  if (regional) {
70  std::vector<EcalEtaPhiRegion>::const_iterator region;
71  for (region=regions.begin(); region!=regions.end(); region++) {
72  if (region->inRegion(position)) {
73  withinRegion = true;
74  break;
75  }
76  }
77  }
78 
79  if (!regional || withinRegion) {
80  float ET = it->energy() * sin(position.theta());
81  if (ET > threshold) seeds.push_back(*it);
82  }
83  }
84 
85  }
86 
87  sort(seeds.begin(), seeds.end(), EcalRecHitLess());
88 
89  if (verbosity < pINFO)
90  {
91  std::cout << "Total number of seeds found in event = " << seeds.size() << std::endl;
92  }
93 
94  mainSearch(hits,geometry_p,topology_p,geometryES_p,ecalPart);
95  sort(clusters_v.rbegin(), clusters_v.rend(), ClusterEtLess());
96 
97  if (verbosity < pINFO)
98  {
99  std::cout << "---------- end of main search. clusters have been sorted ----" << std::endl;
100  }
101 
102  return clusters_v;
103 }
104 
105 
107  const CaloSubdetectorGeometry *geometry_p,
108  const CaloSubdetectorTopology *topology_p,
109  const CaloSubdetectorGeometry *geometryES_p,
110  EcalPart ecalPart)
111 {
112  if (verbosity < pINFO)
113  {
114  std::cout << "Building clusters............" << std::endl;
115  }
116 
117  // Loop over seeds:
118  std::vector<EcalRecHit>::iterator it;
119  for (it = seeds.begin(); it != seeds.end(); it++)
120  {
121  // make sure the current seed does not belong to a cluster already.
122  if (used_s.find(it->id()) != used_s.end())
123  {
124  if (it == seeds.begin())
125  {
126  if (verbosity < pINFO)
127  {
128  std::cout << "##############################################################" << std::endl;
129  std::cout << "DEBUG ALERT: Highest energy seed already belongs to a cluster!" << std::endl;
130  std::cout << "##############################################################" << std::endl;
131  }
132  }
133  continue;
134  }
135 
136  // clear the vector of hits in current cluster
137  current_v.clear();
138 
139  current_v.push_back( std::pair<DetId, float>(it->id(), 1.) ); // by default hit energy fractions are set at 1.
140  used_s.insert(it->id());
141 
142  // Create a navigator at the seed
143  CaloNavigator<DetId> navigator(it->id(), topology_p);
144 
145  searchNorth(navigator);
146  navigator.home();
147  searchSouth(navigator);
148  navigator.home();
149  searchWest(navigator, topology_p);
150  navigator.home();
151  searchEast(navigator, topology_p);
152 
153  makeCluster(hits,geometry_p,geometryES_p);
154  }
155 }
156 
157 
159 {
160  DetId southern = navigator.pos();
161 
162  DetId northern = navigator.north();
163  if (northern == DetId(0)) return; // This means that we went off the ECAL!
164  // if the crystal to the north belongs to another cluster return
165  if (used_s.find(northern) != used_s.end()) return;
166 
167 
168  EcalRecHitCollection::const_iterator southern_it = recHits_->find(southern);
169  EcalRecHitCollection::const_iterator northern_it = recHits_->find(northern);
170 
171  if (shouldBeAdded(northern_it, southern_it))
172  {
173  current_v.push_back( std::pair<DetId, float>(northern, 1.)); // by default hit energy fractions are set at 1.
174  used_s.insert(northern);
175  searchNorth(navigator);
176  }
177 }
178 
179 
181 {
182  DetId northern = navigator.pos();
183 
184  DetId southern = navigator.south();
185  if (southern == DetId(0)) return; // This means that we went off the ECAL!
186  if (used_s.find(southern) != used_s.end()) return;
187 
188 
189  EcalRecHitCollection::const_iterator northern_it = recHits_->find(northern);
190  EcalRecHitCollection::const_iterator southern_it = recHits_->find(southern);
191 
192  if (shouldBeAdded(southern_it, northern_it))
193  {
194  current_v.push_back( std::pair<DetId, float>(southern, 1.)); // by default hit energy fractions are set at 1.
195  used_s.insert(southern);
196  searchSouth(navigator);
197  }
198 }
199 
200 
202 {
203  DetId eastern = navigator.pos();
204  EcalRecHitCollection::const_iterator eastern_it = recHits_->find(eastern);
205 
206  DetId western = navigator.west();
207  if (western == DetId(0)) return; // This means that we went off the ECAL!
208  EcalRecHitCollection::const_iterator western_it = recHits_->find(western);
209 
210  if (shouldBeAdded(western_it, eastern_it))
211  {
212  CaloNavigator<DetId> nsNavigator(western, topology);
213 
214  searchNorth(nsNavigator);
215  nsNavigator.home();
216  searchSouth(nsNavigator);
217  nsNavigator.home();
218  searchWest(navigator, topology);
219 
220  current_v.push_back( std::pair<DetId, float>(western, 1.)); // by default hit energy fractions are set at 1.
221  used_s.insert(western);
222  }
223 }
224 
225 
227 {
228  DetId western = navigator.pos();
229  EcalRecHitCollection::const_iterator western_it = recHits_->find(western);
230 
231  DetId eastern = navigator.east();
232  if (eastern == DetId(0)) return; // This means that we went off the ECAL!
233  EcalRecHitCollection::const_iterator eastern_it = recHits_->find(eastern);
234 
235  if (shouldBeAdded(eastern_it, western_it))
236  {
237  CaloNavigator<DetId> nsNavigator(eastern, topology);
238 
239  searchNorth(nsNavigator);
240  nsNavigator.home();
241  searchSouth(nsNavigator);
242  nsNavigator.home();
243  searchEast(navigator, topology);
244 
245  current_v.push_back( std::pair<DetId, float>(eastern, 1.)); // by default hit energy fractions are set at 1.
246  used_s.insert(eastern);
247  }
248 }
249 
250 
251 // returns true if the candidate crystal fulfills the requirements to be added to the cluster:
253 {
254  // crystal should not be included...
255  if ( (candidate_it == recHits_->end()) || // ...if it does not correspond to a hit
256  (used_s.find(candidate_it->id()) != used_s.end()) || // ...if it already belongs to a cluster
257  (candidate_it->energy() <= 0) || // ...if it has a negative or zero energy
258  (candidate_it->energy() > previous_it->energy())) // ...or if the previous crystal had lower E
259  {
260  return false;
261  }
262  return true;
263 }
264 
265 
268  const CaloSubdetectorGeometry *geometryES)
269 {
270  double energy = 0;
271  reco::CaloID caloID;
272 
273  Point position;
274  position = posCalculator_.Calculate_Location(current_v,hits,geometry,geometryES);
275 
276  std::vector< std::pair<DetId, float> >::iterator it;
277  for (it = current_v.begin(); it != current_v.end(); it++)
278  {
279  EcalRecHitCollection::const_iterator itt = hits->find( (*it).first );
280  EcalRecHit hit_p = *itt;
281  if ( (*it).first.subdetId() == EcalBarrel ) {
283  } else {
285  }
286  // if (hit_p != 0)
287  // {
288  energy += hit_p.energy();
289  // }
290  // else
291  // {
292  // std::cout << "DEBUG ALERT: Requested rechit has gone missing from rechits map! :-S" << std::endl;
293  // }
294  }
295 
296  if (verbosity < pINFO)
297  {
298  std::cout << "******** NEW CLUSTER ********" << std::endl;
299  std::cout << "No. of crystals = " << current_v.size() << std::endl;
300  std::cout << " Energy = " << energy << std::endl;
301  std::cout << " Phi = " << position.phi() << std::endl;
302  std::cout << " Eta = " << position.eta() << std::endl;
303  std::cout << "*****************************" << std::endl;
304  }
305  clusters_v.push_back(reco::BasicCluster(energy, position, caloID, current_v, reco::CaloCluster::island));
306 }
307 
void searchEast(const CaloNavigator< DetId > &navigator, const CaloSubdetectorTopology *topology)
CaloTopology const * topology(0)
void searchWest(const CaloNavigator< DetId > &navigator, const CaloSubdetectorTopology *topology)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< EcalRecHit >::const_iterator const_iterator
math::XYZPoint Point
point in the space
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
PositionCalc posCalculator_
T west() const
move the navigator west
Definition: CaloNavigator.h:59
std::set< DetId > used_s
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< EcalEtaPhiRegion > &regions=std::vector< EcalEtaPhiRegion >())
VerbosityLevel verbosity
float energy() const
Definition: EcalRecHit.h:68
T south() const
move the navigator south
Definition: CaloNavigator.h:45
T pos() const
get the current position
Definition: CaloNavigator.h:32
std::vector< EcalRecHit > seeds
const_iterator end() const
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
void searchNorth(const CaloNavigator< DetId > &navigator)
bool shouldBeAdded(EcalRecHitCollection::const_iterator candidate_it, EcalRecHitCollection::const_iterator previous_it)
std::vector< reco::BasicCluster > clusters_v
void makeCluster(const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry_p, const CaloSubdetectorGeometry *geometryES_p)
ESHandle< TrackerGeometry > geometry
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
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
tuple cout
Definition: gather_cfg.py:121
#define ET
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
const EcalRecHitCollection * recHits_
void searchSouth(const CaloNavigator< DetId > &navigator)
const_iterator begin() const
void mainSearch(const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry_p, const CaloSubdetectorTopology *topology_p, const CaloSubdetectorGeometry *geometryES_p, EcalPart ecalPart)