00001 #include <vector>
00002 #include <map>
00003
00004 #include "RecoEcal/EgammaClusterAlgos/interface/PreshowerClusterAlgo.h"
00005 #include "RecoCaloTools/Navigation/interface/EcalPreshowerNavigator.h"
00006 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00007 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00008
00009 #include "TH1.h"
00010
00011 reco::PreshowerCluster PreshowerClusterAlgo::makeOneCluster(ESDetId strip,
00012 HitsID *used_strips,
00013 RecHitsMap *the_rechitsMap_p,
00014 const CaloSubdetectorGeometry*& geometry_p,
00015 CaloSubdetectorTopology*& topology_p)
00016 {
00017 road_2d.clear();
00018
00019 rechits_map = the_rechitsMap_p;
00020
00021 used_s = used_strips;
00022
00023 int plane = strip.plane();
00024
00025 if ( debugLevel_ <= pINFO ) {
00026 std::cout << "Preshower Seeded Algorithm - looking for clusters" << std::endl;
00027 std::cout << "Preshower is intersected at strip " << strip.strip() << ", at plane " << plane << std::endl;
00028 }
00029
00030
00031 std::vector<DetId> dummy;
00032 Point posi(0,0,0);
00033 if ( debugLevel_ <= pINFO ) std::cout << " Creating a null-cluster" << std::endl;
00034 reco::PreshowerCluster nullcluster=reco::PreshowerCluster(0.,posi,dummy,plane);
00035
00036 if ( strip == ESDetId(0) ) return nullcluster;
00037
00038
00039 EcalRecHitCollection clusterRecHits;
00040
00041 RecHitsMap recHits_pos;
00042
00043
00044 EcalPreshowerNavigator navigator(strip, topology_p);
00045 navigator.setHome(strip);
00046
00047 findRoad(strip,navigator,plane);
00048 if ( debugLevel_ <= pINFO ) std::cout << "Total number of strips in the central road: " << road_2d.size() << std::endl;
00049
00050 if ( plane == 1 ) {
00051 ESDetId strip_north = navigator.north();
00052 findRoad(strip_north,navigator,plane);
00053 navigator.home();
00054 ESDetId strip_south = navigator.south();
00055 findRoad(strip_south,navigator,plane);
00056 navigator.home();
00057 }
00058 if ( plane == 2 ) {
00059 ESDetId strip_east = navigator.east();
00060 findRoad(strip_east,navigator,plane);
00061 navigator.home();
00062 ESDetId strip_west = navigator.west();
00063 findRoad(strip_west,navigator,plane);
00064 navigator.home();
00065 }
00066
00067 if ( debugLevel_ <= pINFO ) std::cout << "Total number of strips in all three roads: " << road_2d.size() << std::endl;
00068
00069
00070 float E_max = 0.;
00071 bool found = false;
00072 RecHitsMap::iterator max_it;
00073
00074 std::vector<ESDetId>::iterator itID;
00075 for (itID = road_2d.begin(); itID != road_2d.end(); itID++) {
00076 if ( debugLevel_ == pDEBUG ) std::cout << " ID = " << *itID << std::endl;
00077 RecHitsMap::iterator strip_it = rechits_map->find(*itID);
00078
00079 if(!goodStrip(strip_it)) continue;
00080 if ( debugLevel_ == pDEBUG ) std::cout << " strip is " << ESDetId(strip_it->first) <<" E = " << strip_it->second.energy() <<std::endl;
00081 float E = strip_it->second.energy();
00082 if ( E > E_max) {
00083 E_max = E;
00084 found = true;
00085 max_it = strip_it;
00086 }
00087 }
00088
00089 if ( !found ) return nullcluster;
00090
00091
00092 clusterRecHits.push_back(max_it->second);
00093 recHits_pos.insert(std::make_pair(max_it->first, max_it->second));
00094 used_s->insert(max_it->first);
00095 if ( debugLevel_ <= pINFO ) {
00096 std::cout << " Central hottest strip " << ESDetId(max_it->first) << " is saved " << std::endl;
00097 std::cout << " with energy E = " << E_max << std::endl;
00098 }
00099
00100
00101 ESDetId next, strip_1, strip_2;
00102 navigator.setHome(max_it->first);
00103 ESDetId startES = max_it->first;
00104
00105 if (plane == 1) {
00106
00107 int nadjacents_east = 0;
00108 while ( (next=navigator.east()) != ESDetId(0) && next != startES && nadjacents_east < 2 ) {
00109 ++nadjacents_east;
00110 if ( debugLevel_ == pDEBUG ) std::cout << " Adjacent east #" << nadjacents_east <<": "<< next << std::endl;
00111 RecHitsMap::iterator strip_it = rechits_map->find(next);
00112
00113 if(!goodStrip(strip_it)) continue;
00114
00115 clusterRecHits.push_back(strip_it->second);
00116
00117 if ( nadjacents_east==1 ) strip_1 = next;
00118 used_s->insert(strip_it->first);
00119 if ( debugLevel_ == pDEBUG ) std::cout << " East adjacent strip # " << nadjacents_east << " is saved with energy E = "
00120 << strip_it->second.energy() << std::endl;
00121 }
00122
00123 navigator.home();
00124 int nadjacents_west = 0;
00125 while ( (next=navigator.west()) != ESDetId(0) && next != startES && nadjacents_west < 2 ) {
00126 ++nadjacents_west;
00127 if ( debugLevel_ == pDEBUG ) std::cout << " Adjacent west #" << nadjacents_west <<": "<< next << std::endl;
00128 RecHitsMap::iterator strip_it = rechits_map->find(next);
00129 if(!goodStrip(strip_it)) continue;
00130 clusterRecHits.push_back(strip_it->second);
00131 if ( nadjacents_west==1 ) strip_2 = next;
00132 used_s->insert(strip_it->first);
00133 if ( debugLevel_ == pDEBUG ) std::cout << " West adjacent strip # " << nadjacents_west << " is saved with energy E = "
00134 << strip_it->second.energy() << std::endl;
00135 }
00136 }
00137 else if (plane == 2) {
00138
00139
00140 int nadjacents_north = 0;
00141 while ( (next=navigator.north()) != ESDetId(0) && next != startES && nadjacents_north < 2 ) {
00142 ++nadjacents_north;
00143 if ( debugLevel_ == pDEBUG ) std::cout << " Adjacent north #" << nadjacents_north <<": "<< next << std::endl;
00144 RecHitsMap::iterator strip_it = rechits_map->find(next);
00145 if(!goodStrip(strip_it)) continue;
00146 clusterRecHits.push_back(strip_it->second);
00147 if ( nadjacents_north==1 ) strip_1 = next;
00148 used_s->insert(strip_it->first);
00149 if ( debugLevel_ == pDEBUG ) std::cout << " North adjacent strip # " << nadjacents_north << " is saved with energy E = "
00150 << strip_it->second.energy() << std::endl;
00151 }
00152
00153 navigator.home();
00154 int nadjacents_south = 0;
00155 while ( (next=navigator.south()) != ESDetId(0) && next != startES && nadjacents_south < 2 ) {
00156 ++nadjacents_south;
00157 if ( debugLevel_ == pDEBUG ) std::cout << " Adjacent south #" << nadjacents_south <<": "<< next << std::endl;
00158 RecHitsMap::iterator strip_it = rechits_map->find(next);
00159 if(!goodStrip(strip_it)) continue;
00160 clusterRecHits.push_back(strip_it->second);
00161 if ( nadjacents_south==1 ) strip_2 = next;
00162 used_s->insert(strip_it->first);
00163 if ( debugLevel_ == pDEBUG ) std::cout << " South adjacent strip # " << nadjacents_south << " is saved with energy E = "
00164 << strip_it->second.energy() << std::endl;
00165 }
00166 }
00167 else {
00168 std::cout << " Wrong plane number" << plane <<", null cluster will be returned! " << std::endl;
00169 return nullcluster;
00170 }
00171 if ( debugLevel_ <=pINFO ) std::cout << " Total size of clusterRecHits is " << clusterRecHits.size() << std::endl;
00172 if ( debugLevel_ <=pINFO ) std::cout << " Two adjacent strips for position calculation are: "
00173 << strip_1 <<" and " << strip_2 << std::endl;
00174
00175
00176 RecHitsMap::iterator strip_it1, strip_it2;
00177 if ( strip_1 != ESDetId(0)) {
00178 strip_it1 = rechits_map->find(strip_1);
00179 recHits_pos.insert(std::make_pair(strip_it1->first, strip_it1->second));
00180 }
00181 if ( strip_2 != ESDetId(0) ) {
00182 strip_it2 = rechits_map->find(strip_2);
00183 recHits_pos.insert(std::make_pair(strip_it2->first, strip_it2->second));
00184 }
00185
00186 RecHitsMap::iterator cp;
00187 double energy_pos = 0;
00188 double x_pos = 0;
00189 double y_pos = 0;
00190 double z_pos = 0;
00191 for (cp = recHits_pos.begin(); cp!=recHits_pos.end(); cp++ ) {
00192 double E = cp->second.energy();
00193 energy_pos += E;
00194 const CaloCellGeometry *thisCell = geometry_p->getGeometry(cp->first);
00195 GlobalPoint position = thisCell->getPosition();
00196 x_pos += E * position.x();
00197 y_pos += E * position.y();
00198 z_pos += E * position.z();
00199 }
00200 if(energy_pos>0.) {
00201 x_pos /= energy_pos;
00202 y_pos /= energy_pos;
00203 z_pos /= energy_pos;
00204 }
00205 Point pos(x_pos,y_pos,z_pos);
00206 if ( debugLevel_ == pDEBUG ) std::cout << " ES Cluster position = " << "(" << x_pos <<","<< y_pos <<","<< z_pos <<")"<< std::endl;
00207
00208 EcalRecHitCollection::iterator it;
00209 double Eclust = 0;
00210
00211 if ( debugLevel_ == pINFO ) std::cout << "The found ES cluster strips: " << std::endl;
00212 std::vector<DetId> usedHits;
00213 for (it=clusterRecHits.begin(); it != clusterRecHits.end(); it++) {
00214 Eclust += it->energy();
00215 usedHits.push_back(it->id());
00216 if ( debugLevel_ == pINFO ) std::cout << ESDetId(it->id()) <<", E = " << it->energy()<<"; ";
00217 }
00218 if ( debugLevel_ == pINFO ) std::cout << std::endl;
00219
00220
00221
00222 reco::PreshowerCluster cluster=reco::PreshowerCluster(Eclust,pos,usedHits,plane);
00223
00224 if ( debugLevel_ <= pINFO ) {
00225 std::cout << " ES Cluster is created with " << std::endl;
00226 std::cout << " energy = " << cluster.energy() << std::endl;
00227 std::cout << " (eta,phi) = " << "("<<cluster.eta()<<", "<<cluster.phi()<<")"<< std::endl;
00228 std::cout << " nhits = " << cluster.nhits() << std::endl;
00229 std::cout << " radius = " << cluster.position().r() << std::endl;
00230 std::cout << " (x,y,z) = " << "(" << cluster.x() <<", "<< cluster.y() <<", "<< cluster.z()<<")"<< std::endl;
00231 }
00232
00233 used_strips = used_s;
00234
00235
00236 if( cluster.energy() > preshClusterEnergyCut_ )
00237 return cluster;
00238 else
00239 return nullcluster;
00240
00241 }
00242
00243
00244 bool PreshowerClusterAlgo::goodStrip(RecHitsMap::iterator candidate_it)
00245 {
00246 if ( debugLevel_ == pDEBUG ) {
00247 if ( used_s->find(candidate_it->first) != used_s->end())
00248 std::cout << " This strip is in use " << std::endl;
00249 if (candidate_it == rechits_map->end() )
00250 std::cout << " No such a strip in rechits_map " << std::endl;
00251 if (candidate_it->second.energy() <= preshStripEnergyCut_)
00252 std::cout << " Strip energy " << candidate_it->second.energy() <<" is below threshold " << std::endl;
00253 }
00254
00255 if ( (used_s->find(candidate_it->first) != used_s->end()) ||
00256 (candidate_it == rechits_map->end() ) ||
00257 (candidate_it->second.energy() <= preshStripEnergyCut_ ) )
00258 {
00259 return false;
00260 }
00261
00262 return true;
00263 }
00264
00265
00266
00267 void PreshowerClusterAlgo::findRoad(ESDetId strip, EcalPreshowerNavigator theESNav, int plane) {
00268
00269 if ( strip == ESDetId(0) ) return;
00270
00271 ESDetId next;
00272 theESNav.setHome(strip);
00273
00274 road_2d.push_back(strip);
00275
00276 if ( debugLevel_ <= pINFO ) std::cout << "findRoad starts from strip " << strip << std::endl;
00277 if (plane == 1) {
00278
00279 int n_east= 0;
00280 if ( debugLevel_ == pDEBUG ) std::cout << " Go to the East " << std::endl;
00281 while ( ((next=theESNav.east()) != ESDetId(0) && next != strip) ) {
00282 if ( debugLevel_ == pDEBUG ) std::cout << "East: " << n_east << " current strip is " << next << std::endl;
00283 road_2d.push_back(next);
00284 ++n_east;
00285 if (n_east == preshSeededNstr_) break;
00286 }
00287
00288 int n_west= 0;
00289 if ( debugLevel_ == pDEBUG ) std::cout << " Go to the West " << std::endl;
00290 theESNav.home();
00291 while ( ((next=theESNav.west()) != ESDetId(0) && next != strip )) {
00292 if ( debugLevel_ == pDEBUG ) std::cout << "West: " << n_west << " current strip is " << next << std::endl;
00293 road_2d.push_back(next);
00294 ++n_west;
00295 if (n_west == preshSeededNstr_) break;
00296 }
00297 if ( debugLevel_ == pDEBUG ) std::cout << "Total number of strips found in the road at 1-st plane is " << n_east+n_west << std::endl;
00298 }
00299 else if (plane == 2) {
00300
00301 int n_north= 0;
00302 if ( debugLevel_ == pDEBUG ) std::cout << " Go to the North " << std::endl;
00303 while ( ((next=theESNav.north()) != ESDetId(0) && next != strip) ) {
00304 if ( debugLevel_ == pDEBUG ) std::cout << "North: " << n_north << " current strip is " << next << std::endl;
00305 road_2d.push_back(next);
00306 ++n_north;
00307 if (n_north == preshSeededNstr_) break;
00308 }
00309
00310 int n_south= 0;
00311 if ( debugLevel_ == pDEBUG ) std::cout << " Go to the South " << std::endl;
00312 theESNav.home();
00313 while ( ((next=theESNav.south()) != ESDetId(0) && next != strip) ) {
00314 if ( debugLevel_ == pDEBUG ) std::cout << "South: " << n_south << " current strip is " << next << std::endl;
00315 road_2d.push_back(next);
00316 ++n_south;
00317 if (n_south == preshSeededNstr_) break;
00318 }
00319 if ( debugLevel_ == pDEBUG ) std::cout << "Total number of strips found in the road at 2-nd plane is " << n_south+n_north << std::endl;
00320 }
00321 else {
00322 if ( debugLevel_ == pDEBUG ) std::cout << " Wrong plane number, null cluster will be returned! " << std::endl;
00323 }
00324
00325 theESNav.home();
00326 }
00327
00328
00329