CMS 3D CMS Logo

CosmicClusterAlgo.cc
Go to the documentation of this file.
1 
3 
4 #include <vector> //TEMP JHAUPT 4-27
5 
6 // Geometry
13 
14 
15 // Return a vector of clusters from a collection of EcalRecHits:
16 //
17 std::vector<reco::BasicCluster> CosmicClusterAlgo::makeClusters(
19  const EcalUncalibratedRecHitCollection *uncalibhits,
20  const CaloSubdetectorGeometry *geometry_p,
21  const CaloSubdetectorTopology *topology_p,
22  const CaloSubdetectorGeometry *geometryES_p,
23  EcalPart ecalPart,
24  bool regional,
25  const std::vector<RectangularEtaPhiRegion>& regions)
26 {
27  seeds.clear();
28  used_s.clear();
29  canSeed_s.clear();
30  clusters_v.clear();
31 
32  recHits_ = hits;
33  uncalibRecHits_ = uncalibhits;
34 
35  inEB = true;
36  double threshold = 0;
37  std::string ecalPart_string;
38  if (ecalPart == endcap)
39  {
40  threshold = ecalEndcapSeedThreshold;
41  ecalPart_string = "EndCap";
42  inEB = false;
43  }
44  if (ecalPart == barrel)
45  {
46  threshold = ecalBarrelSeedThreshold;
47  ecalPart_string = "Barrel";
48  inEB = true;
49  }
50 
51  if (verbosity < pINFO)
52  {
53  std::cout << "-------------------------------------------------------------" << std::endl;
54  std::cout << "Island algorithm invoked for ECAL" << ecalPart_string << std::endl;
55  std::cout << "Looking for seeds, threshold used = " << threshold << " ADC" <<std::endl;
56  }
57 
58  int nregions=0;
59  if(regional) nregions=regions.size();
60 
61  if(!regional || nregions) {
62 
64  for(it = recHits_->begin(); it != recHits_->end(); it++)
65  {
66 
67  if (!uncalibRecHits_){
68  if (verbosity < pINFO)
69  {
70  std::cout << "-------------------------------------------------------------" << std::endl;
71  std::cout << "No Uncalibrated RecHits no Uncalibrated rec hit collection available" << std::endl;
72  }
73  continue;
74  }
75 
76  // if rechit affected by features other than these, do not allow if seeding
77  // features are hard coded, for now; add severity?
78  uint32_t rhFlag = (*it).recoFlag();
79  if (!(
80  rhFlag == EcalRecHit::kGood ||
81  rhFlag == EcalRecHit::kOutOfTime ||
82  rhFlag == EcalRecHit::kPoorCalib
83  )
84  ) continue;
85 
87 
88  if (itt == uncalibRecHits_->end()){
89  if (verbosity < pINFO)
90  {
91  std::cout << "-------------------------------------------------------------" << std::endl;
92  std::cout << "No Uncalibrated RecHit associated with the RecHit Probably no Uncalibrated rec hit collection available" << std::endl;
93  }
94  continue;
95  }
96 
97  EcalUncalibratedRecHit uhit_p = *itt;
98 
99  // looking for cluster seeds
100  if (uhit_p.amplitude() < (inEB ? ecalBarrelSeedThreshold : ecalEndcapSeedThreshold) ) continue; //
101 
102  auto thisCell = geometry_p->getGeometry(it->id());
103 
104  // Require that RecHit is within clustering region in case
105  // of regional reconstruction
106  bool withinRegion = false;
107  if (regional) {
108  std::vector<RectangularEtaPhiRegion>::const_iterator region;
109  for (region=regions.begin(); region!=regions.end(); region++) {
110  if (region->inRegion(thisCell->etaPos(),thisCell->phiPos())) {
111  withinRegion = true;
112  break;
113  }
114  }
115  }
116 
117  if (!regional || withinRegion) {
118  seeds.push_back(*it); // JHaupt 4-27-2008 Et -> energy, most likely not needed as there is already a threshold requirement.
119  }
120  }
121 
122  }
123 
124  sort(seeds.begin(), seeds.end(), [](auto const& x, auto const& y){return x.energy() > y.energy();});
125 
126  if (verbosity < pINFO)
127  {
128  std::cout << "JH Total number of seeds found in event = " << seeds.size() << std::endl;
129  for (EcalRecHitCollection::const_iterator ji = seeds.begin(); ji != seeds.end(); ++ji)
130  {
131  //std::cout << "JH Seed Energy " << ji->energy() << " hashed " << ((EBDetId)ji->id()).hashedIndex() << std::endl;
132 
133  }
134  }
135 
136  mainSearch(geometry_p,topology_p,geometryES_p,ecalPart );
137  std::sort(clusters_v.rbegin(), clusters_v.rend(),isClusterEtLess);
138 
139  if (verbosity < pINFO)
140  {
141  std::cout << "---------- end of main search. clusters have been sorted ----" << std::endl;
142  }
143 
144  return clusters_v;
145 
146 }
147 
148 // Search for clusters
149 //
151  const CaloSubdetectorTopology *topology_p,
152  const CaloSubdetectorGeometry *geometryES_p,
153  EcalPart ecalPart )
154 {
155 
156  if (verbosity < pINFO)
157  {
158  std::cout << "Building clusters............" << std::endl;
159  }
160 
161  // Loop over seeds:
162  std::vector<EcalRecHit>::iterator it;
163  for (it = seeds.begin(); it != seeds.end(); it++)
164  {
165 
166  // check if this crystal is able to seed
167  // (event though it is already used)
168  bool usedButCanSeed = false;
169  if (canSeed_s.find(it->id()) != canSeed_s.end()) usedButCanSeed = true;
170 
171  // make sure the current seed does not belong to a cluster already.
172  if ((used_s.find(it->id()) != used_s.end()) && (usedButCanSeed == false))
173  {
174  if (it == seeds.begin())
175  {
176  if (verbosity < pINFO)
177  {
178  std::cout << "##############################################################" << std::endl;
179  std::cout << "DEBUG ALERT: Highest energy seed already belongs to a cluster!" << std::endl;
180  std::cout << "##############################################################" << std::endl;
181  }
182  }
183 
184  // seed crystal is used or is used and cannot seed a cluster
185  // so continue to the next seed crystal...
186  continue;
187  }
188 
189  // clear the vector of hits in current clusterconst EcalRecHitCollection* hits,
190  current_v9.clear();
191  current_v25.clear();
192  current_v25Sup.clear();
193 
194  // Create a navigator at the seed
195  CaloNavigator<DetId> navigator(it->id(), topology_p);
196  DetId seedId = navigator.pos();
197  navigator.setHome(seedId);
198 
199  // Is the seed a local maximum?
200  bool localMaxima = checkMaxima(navigator);
201 
202  if (localMaxima)
203  {
204  // build the 5x5 taking care over which crystals //JHaupt 4-27-08 3x3 is a good option...
205  // can seed new clusters and which can't
206  prepareCluster(navigator, geometry_p);
207  }
208 
209  // If some crystals in the current vector then
210  // make them into a cluster
211  if (!current_v25.empty())
212  {
213  makeCluster(geometry_p, geometryES_p, seedId);
214  }
215 
216  } // End loop on seed crystals
217 
218 }
219 
222  const CaloSubdetectorGeometry *geometryES,
223  DetId seedId)
224 {
225 
226  double energy = 0;
227  double energySecond = 0.;//JHaupt 4-27-08 Added for the second crystal stream
228  double energyMax = 0.;//JHaupt 4-27-08 Added for the max crystal stream
229  DetId detFir;
230  DetId detSec;
231  //bool goodCluster = false; //JHaupt 4-27-08 Added so that some can be earased.. used another day Might not be needed as seeds are energy ordered...
232 
233 
234  std::vector<DetId>::iterator it;
235  for (it = current_v9.begin(); it != current_v9.end(); it++)
236  {
237  // Martina - check recoFlag for crystals sorrounding the good one
239  // double-check that iterator can be dereferenced
240  if(itt==recHits_->end()) continue;
241  // if rechit affected by features other than these, do not allow 2 crystal seeding either
242  // features are hard coded, for now; add severity?
243  uint32_t rhFlag = (*itt).recoFlag();
244  if (!(
245  rhFlag == EcalRecHit::kGood ||
246  rhFlag == EcalRecHit::kOutOfTime ||
247  rhFlag == EcalRecHit::kPoorCalib
248  )
249  ) continue;
250 
252 
254  EcalUncalibratedRecHit uhit_p = *ittu;
255 
256  if (uhit_p.amplitude() > energySecond ) {energySecond = uhit_p.amplitude(); detSec = uhit_p.id();}
257  if (energySecond > energyMax ) {std::swap(energySecond,energyMax); std::swap(detFir,detSec);}
258  }
259 
260  //if ((detFir.det() == DetId::Ecal) && (detFir.subdetId() == EcalEndcap)) inEB = false;
261  //We ignore the possiblity that the cluster may span into the EE
262 
263  if ((energyMax < (inEB ? ecalBarrelSingleThreshold : ecalEndcapSingleThreshold)) && (energySecond < (inEB ? ecalBarrelSecondThreshold : ecalEndcapSecondThreshold) )) return;
264 
265  for (it = current_v25.begin(); it != current_v25.end(); it++)
266  {
268  EcalRecHit hit_p = *itt;
269 
271  EcalUncalibratedRecHit uhit_p = *ittu;
272 
274  {
275  // energy fraction = 1
276  current_v25Sup.push_back( std::pair<DetId, float>( hit_p.id(), 1.) );
277  energy += hit_p.energy(); //Keep the fully corrected energy
278  }
279  }
280 
281  Point position;
282  position = posCalculator_.Calculate_Location(current_v25Sup,recHits_, geometry, geometryES);
283 
284  //don't write empty clusters
285  if (energy == 0 && position == Point(0,0,0)) return;
286 
287  if (verbosity < pINFO)
288  {
289  std::cout << "JH******** NEW CLUSTER ********" << std::endl;
290  std::cout << "JHNo. of crystals = " << current_v25Sup.size() << std::endl;
291  std::cout << "JH Energy = " << energy << std::endl;
292  std::cout << "JH Phi = " << position.phi() << std::endl;
293  std::cout << "JH Eta = " << position.eta() << std::endl;
294  std::cout << "JH*****************************" << std::endl;
295  // specialize this
296 // std::cout << "JH****Emax**** "<<energyMax << " ieta " <<detFir.ieta() <<" iphi "<<detFir.ieta() << std::endl;
297 // std::cout << "JH****Esec**** "<<energySecond << " ieta " <<detSec.ieta() <<" iphi "<<detSec.ieta() << std::endl;
298  }
299  clusters_v.push_back(reco::BasicCluster(energy, position, reco::CaloID(), current_v25Sup, reco::CaloCluster::multi5x5, seedId));
300 }
301 
303 {
304 
305  bool maxima = true;
307  EcalRecHitCollection::const_iterator seedHit = recHits_->find(navigator.pos());
308  double thisEnergy = 0.;
309  double seedEnergy = seedHit->energy();
310 
311  std::vector<DetId> swissCrossVec;
312  swissCrossVec.clear();
313 
314  swissCrossVec.push_back(navigator.west());
315  navigator.home();
316  swissCrossVec.push_back(navigator.east());
317  navigator.home();
318  swissCrossVec.push_back(navigator.north());
319  navigator.home();
320  swissCrossVec.push_back(navigator.south());
321  navigator.home();
322 
323  for (unsigned int i = 0; i < swissCrossVec.size(); ++i)
324  {
325  thisHit = recHits_->find(swissCrossVec[i]);
326  if ((swissCrossVec[i] == DetId(0)) || thisHit == recHits_->end()) thisEnergy = 0.0;
327  else thisEnergy = thisHit->energy();
328  if (thisEnergy > seedEnergy)
329  {
330  maxima = false;
331  break;
332  }
333  }
334 
335  return maxima;
336 
337 }
338 
341 {
342 
343  DetId thisDet;
344  std::set<DetId>::iterator setItr;
345 
346  // now add the 5x5 taking care to mark the edges
347  // as able to seed and where overlapping in the central
348  // region with crystals that were previously able to seed
349  // change their status so they are not able to seed
350  //std::cout << std::endl;
351  for (int dx = -2; dx < 3; ++dx) //for (int dx = -2; dx < 3; ++dx)
352  {
353  for (int dy = -2; dy < 3; ++ dy) //for (int dy = -2; dy < 3; ++ dy)
354  {
355 
356  // navigate in free steps forming
357  // a full 5x5
358  thisDet = navigator.offsetBy(dx, dy);
359  navigator.home();
360 
361  // add the current crystal
362  //std::cout << "adding " << dx << ", " << dy << std::endl;
363 
364 
365 
366  // now consider if we are in an edge (outer 16)
367  // or central (inner 9) region
368  if ((abs(dx) > 1) || (abs(dy) > 1))
369  {
370  // this is an "edge" so should be allowed to seed
371  // provided it is not already used
372  //std::cout << " setting can seed" << std::endl;
373  addCrystal(thisDet,false); //These are in the V25
374  canSeed_s.insert(thisDet);
375  } // end if "edge"
376  else
377  {
378  // or else we are in the central 3x3
379  // and must remove any of these crystals from the canSeed set
380  setItr = canSeed_s.find(thisDet);
381  addCrystal(thisDet,true); //These are in the V9
382  if (setItr != canSeed_s.end())
383  {
384  //std::cout << " unsetting can seed" << std::endl;
385  canSeed_s.erase(setItr);
386  }
387  } // end if "centre"
388 
389 
390  } // end loop on dy
391 
392  } // end loop on dx
393 
394  //std::cout << "*** " << std::endl;
395  //std::cout << " current_v contains " << current_v.size() << std::endl;
396  //std::cout << "*** " << std::endl;
397 }
398 
399 
400 void CosmicClusterAlgo::addCrystal(const DetId &det, const bool in9)
401 {
402 
404  if ((thisIt != recHits_->end()) && (thisIt->id() != DetId(0)))
405  {
406  if ((used_s.find(thisIt->id()) == used_s.end()))
407  {
409  used_s.insert(det);
410  if ((thisIt->energy() >= -1.) && !(thisItu->chi2() < -1.))
411  {
412  if (in9) current_v9.push_back(det);
413  current_v25.push_back(det);
414  }
415 
416  }
417  }
418 
419 }
const EcalUncalibratedRecHitCollection * uncalibRecHits_
double ecalBarrelSingleThreshold
std::vector< reco::BasicCluster > makeClusters(const EcalRecHitCollection *hits, const EcalUncalibratedRecHitCollection *uncalibhits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology_p, const CaloSubdetectorGeometry *geometryES_p, EcalPart ecalPart, bool regional=false, const std::vector< RectangularEtaPhiRegion > &regions=std::vector< RectangularEtaPhiRegion >())
std::vector< EcalRecHit >::const_iterator const_iterator
std::vector< DetId > current_v9
std::vector< reco::BasicCluster > clusters_v
void mainSearch(const CaloSubdetectorGeometry *geometry_p, const CaloSubdetectorTopology *topology_p, const CaloSubdetectorGeometry *geometryES_p, EcalPart ecalPart)
double ecalEndcapSingleThreshold
T offsetBy(int deltaX, int deltaY) const
Free movement of arbitray steps.
Definition: CaloNavigator.h:80
std::vector< std::pair< DetId, float > > current_v25Sup
T west() const
move the navigator west
Definition: CaloNavigator.h:59
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
double ecalBarrelSecondThreshold
const EcalRecHitCollection * recHits_
void prepareCluster(CaloNavigator< DetId > &navigator, const CaloSubdetectorGeometry *geometry)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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
const_iterator end() const
std::vector< EcalRecHit > seeds
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
double ecalEndcapSecondThreshold
DetId id() const
get the id
Definition: EcalRecHit.h:77
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.
void makeCluster(const CaloSubdetectorGeometry *geometry_p, const CaloSubdetectorGeometry *geometryES_p, DetId seedId)
std::vector< DetId > current_v25
VerbosityLevel verbosity
std::set< DetId > canSeed_s
void addCrystal(const DetId &det, const bool in9)
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
T north() const
move the navigator north
Definition: CaloNavigator.h:38
math::XYZPoint Point
point in the space
bool checkMaxima(CaloNavigator< DetId > &navigator)
PositionCalc posCalculator_
std::set< DetId > used_s
const_iterator begin() const