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