00001 #include "RecoEcal/EgammaClusterAlgos/interface/IslandClusterAlgo.h"
00002
00003
00004 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00005 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00006 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00007 #include "Geometry/CaloTopology/interface/EcalEndcapTopology.h"
00008 #include "Geometry/CaloTopology/interface/EcalBarrelTopology.h"
00009
00010 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00011 #include "RecoEcal/EgammaCoreTools/interface/ClusterEtLess.h"
00012
00013
00014
00015
00016 std::vector<reco::BasicCluster> IslandClusterAlgo::makeClusters(
00017 const EcalRecHitCollection* hits,
00018 const CaloSubdetectorGeometry *geometry_p,
00019 const CaloSubdetectorTopology *topology_p,
00020 const CaloSubdetectorGeometry *geometryES_p,
00021 EcalPart ecalPart,
00022 bool regional,
00023 const std::vector<EcalEtaPhiRegion>& regions)
00024 {
00025 seeds.clear();
00026 used_s.clear();
00027 clusters_v.clear();
00028
00029 recHits_ = hits;
00030
00031 double threshold = 0;
00032 std::string ecalPart_string;
00033 if (ecalPart == endcap)
00034 {
00035 threshold = ecalEndcapSeedThreshold;
00036 ecalPart_string = "EndCap";
00037 }
00038 if (ecalPart == barrel)
00039 {
00040 threshold = ecalBarrelSeedThreshold;
00041 ecalPart_string = "Barrel";
00042 }
00043
00044 if (verbosity < pINFO)
00045 {
00046 std::cout << "-------------------------------------------------------------" << std::endl;
00047 std::cout << "Island algorithm invoked for ECAL" << ecalPart_string << std::endl;
00048 std::cout << "Looking for seeds, energy threshold used = " << threshold << " GeV" <<std::endl;
00049 }
00050
00051 int nregions=0;
00052 if(regional) nregions=regions.size();
00053
00054 if(!regional || nregions) {
00055
00056 EcalRecHitCollection::const_iterator it;
00057 for(it = hits->begin(); it != hits->end(); it++)
00058 {
00059 double energy = it->energy();
00060 if (energy < threshold) continue;
00061
00062 const CaloCellGeometry *thisCell = geometry_p->getGeometry(it->id());
00063 GlobalPoint position = thisCell->getPosition();
00064
00065
00066
00067 bool withinRegion = false;
00068 if (regional) {
00069 std::vector<EcalEtaPhiRegion>::const_iterator region;
00070 for (region=regions.begin(); region!=regions.end(); region++) {
00071 if (region->inRegion(position)) {
00072 withinRegion = true;
00073 break;
00074 }
00075 }
00076 }
00077
00078 if (!regional || withinRegion) {
00079 float ET = it->energy() * sin(position.theta());
00080 if (ET > threshold) seeds.push_back(*it);
00081 }
00082 }
00083
00084 }
00085
00086 sort(seeds.begin(), seeds.end(), EcalRecHitLess());
00087
00088 if (verbosity < pINFO)
00089 {
00090 std::cout << "Total number of seeds found in event = " << seeds.size() << std::endl;
00091 }
00092
00093 mainSearch(hits,geometry_p,topology_p,geometryES_p,ecalPart);
00094 sort(clusters_v.rbegin(), clusters_v.rend(), ClusterEtLess());
00095
00096 if (verbosity < pINFO)
00097 {
00098 std::cout << "---------- end of main search. clusters have been sorted ----" << std::endl;
00099 }
00100
00101 return clusters_v;
00102 }
00103
00104
00105 void IslandClusterAlgo::mainSearch(const EcalRecHitCollection* hits,
00106 const CaloSubdetectorGeometry *geometry_p,
00107 const CaloSubdetectorTopology *topology_p,
00108 const CaloSubdetectorGeometry *geometryES_p,
00109 EcalPart ecalPart)
00110 {
00111 if (verbosity < pINFO)
00112 {
00113 std::cout << "Building clusters............" << std::endl;
00114 }
00115
00116
00117 std::vector<EcalRecHit>::iterator it;
00118 for (it = seeds.begin(); it != seeds.end(); it++)
00119 {
00120
00121 if (used_s.find(it->id()) != used_s.end())
00122 {
00123 if (it == seeds.begin())
00124 {
00125 if (verbosity < pINFO)
00126 {
00127 std::cout << "##############################################################" << std::endl;
00128 std::cout << "DEBUG ALERT: Highest energy seed already belongs to a cluster!" << std::endl;
00129 std::cout << "##############################################################" << std::endl;
00130 }
00131 }
00132 continue;
00133 }
00134
00135
00136 current_v.clear();
00137
00138 current_v.push_back(it->id());
00139 used_s.insert(it->id());
00140
00141
00142 CaloNavigator<DetId> navigator(it->id(), topology_p);
00143
00144 searchNorth(navigator);
00145 navigator.home();
00146 searchSouth(navigator);
00147 navigator.home();
00148 searchWest(navigator, topology_p);
00149 navigator.home();
00150 searchEast(navigator, topology_p);
00151
00152 makeCluster(hits,geometry_p,geometryES_p);
00153 }
00154 }
00155
00156
00157 void IslandClusterAlgo::searchNorth(const CaloNavigator<DetId> &navigator)
00158 {
00159 DetId southern = navigator.pos();
00160
00161 DetId northern = navigator.north();
00162 if (northern == DetId(0)) return;
00163
00164 if (used_s.find(northern) != used_s.end()) return;
00165
00166
00167 EcalRecHitCollection::const_iterator southern_it = recHits_->find(southern);
00168 EcalRecHitCollection::const_iterator northern_it = recHits_->find(northern);
00169
00170 if (shouldBeAdded(northern_it, southern_it))
00171 {
00172 current_v.push_back(northern);
00173 used_s.insert(northern);
00174 searchNorth(navigator);
00175 }
00176 }
00177
00178
00179 void IslandClusterAlgo::searchSouth(const CaloNavigator<DetId> &navigator)
00180 {
00181 DetId northern = navigator.pos();
00182
00183 DetId southern = navigator.south();
00184 if (southern == DetId(0)) return;
00185 if (used_s.find(southern) != used_s.end()) return;
00186
00187
00188 EcalRecHitCollection::const_iterator northern_it = recHits_->find(northern);
00189 EcalRecHitCollection::const_iterator southern_it = recHits_->find(southern);
00190
00191 if (shouldBeAdded(southern_it, northern_it))
00192 {
00193 current_v.push_back(southern);
00194 used_s.insert(southern);
00195 searchSouth(navigator);
00196 }
00197 }
00198
00199
00200 void IslandClusterAlgo::searchWest(const CaloNavigator<DetId> &navigator, const CaloSubdetectorTopology* topology)
00201 {
00202 DetId eastern = navigator.pos();
00203 EcalRecHitCollection::const_iterator eastern_it = recHits_->find(eastern);
00204
00205 DetId western = navigator.west();
00206 if (western == DetId(0)) return;
00207 EcalRecHitCollection::const_iterator western_it = recHits_->find(western);
00208
00209 if (shouldBeAdded(western_it, eastern_it))
00210 {
00211 CaloNavigator<DetId> nsNavigator(western, topology);
00212
00213 searchNorth(nsNavigator);
00214 nsNavigator.home();
00215 searchSouth(nsNavigator);
00216 nsNavigator.home();
00217 searchWest(navigator, topology);
00218
00219 current_v.push_back(western);
00220 used_s.insert(western);
00221 }
00222 }
00223
00224
00225 void IslandClusterAlgo::searchEast(const CaloNavigator<DetId> &navigator, const CaloSubdetectorTopology* topology)
00226 {
00227 DetId western = navigator.pos();
00228 EcalRecHitCollection::const_iterator western_it = recHits_->find(western);
00229
00230 DetId eastern = navigator.east();
00231 if (eastern == DetId(0)) return;
00232 EcalRecHitCollection::const_iterator eastern_it = recHits_->find(eastern);
00233
00234 if (shouldBeAdded(eastern_it, western_it))
00235 {
00236 CaloNavigator<DetId> nsNavigator(eastern, topology);
00237
00238 searchNorth(nsNavigator);
00239 nsNavigator.home();
00240 searchSouth(nsNavigator);
00241 nsNavigator.home();
00242 searchEast(navigator, topology);
00243
00244 current_v.push_back(eastern);
00245 used_s.insert(eastern);
00246 }
00247 }
00248
00249
00250
00251 bool IslandClusterAlgo::shouldBeAdded(EcalRecHitCollection::const_iterator candidate_it, EcalRecHitCollection::const_iterator previous_it)
00252 {
00253
00254 if ( (candidate_it == recHits_->end()) ||
00255 (used_s.find(candidate_it->id()) != used_s.end()) ||
00256 (candidate_it->energy() <= 0) ||
00257 (candidate_it->energy() > previous_it->energy()))
00258 {
00259 return false;
00260 }
00261 return true;
00262 }
00263
00264
00265 void IslandClusterAlgo::makeCluster(const EcalRecHitCollection* hits,
00266 const CaloSubdetectorGeometry *geometry,
00267 const CaloSubdetectorGeometry *geometryES)
00268 {
00269 double energy = 0;
00270 double chi2 = 0;
00271
00272 Point position;
00273 position = posCalculator_.Calculate_Location(current_v,hits,geometry,geometryES);
00274
00275 std::vector<DetId>::iterator it;
00276 for (it = current_v.begin(); it != current_v.end(); it++)
00277 {
00278 EcalRecHitCollection::const_iterator itt = hits->find(*it);
00279 EcalRecHit hit_p = *itt;
00280
00281
00282 energy += hit_p.energy();
00283
00284
00285
00286
00287
00288 chi2 += 0;
00289 }
00290 chi2 /= energy;
00291
00292 if (verbosity < pINFO)
00293 {
00294 std::cout << "******** NEW CLUSTER ********" << std::endl;
00295 std::cout << "No. of crystals = " << current_v.size() << std::endl;
00296 std::cout << " Energy = " << energy << std::endl;
00297 std::cout << " Phi = " << position.phi() << std::endl;
00298 std::cout << " Eta = " << position.eta() << std::endl;
00299 std::cout << "*****************************" << std::endl;
00300 }
00301
00302 clusters_v.push_back(reco::BasicCluster(energy, position, chi2, current_v, reco::island));
00303 }