CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Attributes
PreshowerClusterAlgo Class Reference

#include <PreshowerClusterAlgo.h>

Public Types

enum  DebugLevel { pDEBUG = 0, pINFO = 1, pERROR = 2 }
 
typedef std::set< DetIdHitsID
 
typedef math::XYZPoint Point
 
typedef std::map< DetId,
EcalRecHit
RecHitsMap
 

Public Member Functions

void findRoad (ESDetId strip, EcalPreshowerNavigator theESNav, int plane)
 
bool goodStrip (RecHitsMap::iterator candidate_it)
 
reco::PreshowerCluster makeOneCluster (ESDetId strip, HitsID *used_strips, RecHitsMap *rechits_map, const CaloSubdetectorGeometry *&geometry_p, CaloSubdetectorTopology *&topology_p)
 
 PreshowerClusterAlgo ()
 
 PreshowerClusterAlgo (double stripEnergyCut, double clusterEnergyCut, int nStripCut, DebugLevel debugLevel=pINFO)
 
 ~PreshowerClusterAlgo ()
 

Private Attributes

int debugLevel_
 
double preshClusterEnergyCut_
 
int preshSeededNstr_
 
double preshStripEnergyCut_
 
RecHitsMaprechits_map
 
std::vector< ESDetIdroad_2d
 
HitsIDused_s
 

Detailed Description

Definition at line 24 of file PreshowerClusterAlgo.h.

Member Typedef Documentation

Definition at line 34 of file PreshowerClusterAlgo.h.

Definition at line 31 of file PreshowerClusterAlgo.h.

Definition at line 33 of file PreshowerClusterAlgo.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

PreshowerClusterAlgo::PreshowerClusterAlgo ( )
inline
PreshowerClusterAlgo::PreshowerClusterAlgo ( double  stripEnergyCut,
double  clusterEnergyCut,
int  nStripCut,
DebugLevel  debugLevel = pINFO 
)
inline

Definition at line 40 of file PreshowerClusterAlgo.h.

40  :
41  preshStripEnergyCut_(stripEnergyCut), preshClusterEnergyCut_(clusterEnergyCut), preshSeededNstr_(nStripCut), debugLevel_(debugLevel)
42  {}
PreshowerClusterAlgo::~PreshowerClusterAlgo ( )
inline

Definition at line 44 of file PreshowerClusterAlgo.h.

44 {};

Member Function Documentation

void PreshowerClusterAlgo::findRoad ( ESDetId  strip,
EcalPreshowerNavigator  theESNav,
int  plane 
)

Definition at line 268 of file PreshowerClusterAlgo.cc.

References gather_cfg::cout, debugLevel_, CaloNavigator< T >::east(), CaloNavigator< T >::home(), CaloNavigator< T >::north(), pDEBUG, pINFO, preshSeededNstr_, road_2d, CaloNavigator< T >::setHome(), CaloNavigator< T >::south(), strip(), and CaloNavigator< T >::west().

Referenced by makeOneCluster().

268  {
269 
270  if ( strip == ESDetId(0) ) return;
271 
272  ESDetId next;
273  theESNav.setHome(strip);
274 // First, add a central strip to the road
275  road_2d.push_back(strip);
276 
277  if ( debugLevel_ <= pINFO ) std::cout << "findRoad starts from strip " << strip << std::endl;
278  if (plane == 1) {
279  // east road
280  int n_east= 0;
281  if ( debugLevel_ == pDEBUG ) std::cout << " Go to the East " << std::endl;
282  while ( ((next=theESNav.east()) != ESDetId(0) && next != strip) ) {
283  if ( debugLevel_ == pDEBUG ) std::cout << "East: " << n_east << " current strip is " << next << std::endl;
284  road_2d.push_back(next);
285  ++n_east;
286  if (n_east == preshSeededNstr_) break;
287  }
288  // west road
289  int n_west= 0;
290  if ( debugLevel_ == pDEBUG ) std::cout << " Go to the West " << std::endl;
291  theESNav.home();
292  while ( ((next=theESNav.west()) != ESDetId(0) && next != strip )) {
293  if ( debugLevel_ == pDEBUG ) std::cout << "West: " << n_west << " current strip is " << next << std::endl;
294  road_2d.push_back(next);
295  ++n_west;
296  if (n_west == preshSeededNstr_) break;
297  }
298  if ( debugLevel_ == pDEBUG ) std::cout << "Total number of strips found in the road at 1-st plane is " << n_east+n_west << std::endl;
299  }
300  else if (plane == 2) {
301  // north road
302  int n_north= 0;
303  if ( debugLevel_ == pDEBUG ) std::cout << " Go to the North " << std::endl;
304  while ( ((next=theESNav.north()) != ESDetId(0) && next != strip) ) {
305  if ( debugLevel_ == pDEBUG ) std::cout << "North: " << n_north << " current strip is " << next << std::endl;
306  road_2d.push_back(next);
307  ++n_north;
308  if (n_north == preshSeededNstr_) break;
309  }
310  // south road
311  int n_south= 0;
312  if ( debugLevel_ == pDEBUG ) std::cout << " Go to the South " << std::endl;
313  theESNav.home();
314  while ( ((next=theESNav.south()) != ESDetId(0) && next != strip) ) {
315  if ( debugLevel_ == pDEBUG ) std::cout << "South: " << n_south << " current strip is " << next << std::endl;
316  road_2d.push_back(next);
317  ++n_south;
318  if (n_south == preshSeededNstr_) break;
319  }
320  if ( debugLevel_ == pDEBUG ) std::cout << "Total number of strips found in the road at 2-nd plane is " << n_south+n_north << std::endl;
321  }
322  else {
323  if ( debugLevel_ == pDEBUG ) std::cout << " Wrong plane number, null cluster will be returned! " << std::endl;
324  } // end of if
325 
326  theESNav.home();
327 }
void setHome(const T &startingPoint)
set the starting position
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
void home() const
move the navigator back to the starting point
virtual T west() const
move the navigator west
Definition: CaloNavigator.h:81
virtual T north() const
move the navigator north
Definition: CaloNavigator.h:51
virtual T east() const
move the navigator east
Definition: CaloNavigator.h:71
std::vector< ESDetId > road_2d
tuple cout
Definition: gather_cfg.py:41
virtual T south() const
move the navigator south
Definition: CaloNavigator.h:61
bool PreshowerClusterAlgo::goodStrip ( RecHitsMap::iterator  candidate_it)

Definition at line 245 of file PreshowerClusterAlgo.cc.

References gather_cfg::cout, debugLevel_, pDEBUG, preshStripEnergyCut_, rechits_map, and used_s.

Referenced by makeOneCluster().

246 {
247  if ( debugLevel_ == pDEBUG ) {
248  if ( used_s->find(candidate_it->first) != used_s->end())
249  std::cout << " This strip is in use " << std::endl;
250  if (candidate_it == rechits_map->end() )
251  std::cout << " No such a strip in rechits_map " << std::endl;
252  if (candidate_it->second.energy() <= preshStripEnergyCut_)
253  std::cout << " Strip energy " << candidate_it->second.energy() <<" is below threshold " << std::endl;
254  }
255  // crystal should not be included...
256  if ( (used_s->find(candidate_it->first) != used_s->end()) || // ...if it already belongs to a cluster
257  (candidate_it == rechits_map->end() ) || // ...if it corresponds to a hit
258  (candidate_it->second.energy() <= preshStripEnergyCut_ ) ) // ...if it has a negative or zero energy
259  {
260  return false;
261  }
262 
263  return true;
264 }
tuple cout
Definition: gather_cfg.py:41
reco::PreshowerCluster PreshowerClusterAlgo::makeOneCluster ( ESDetId  strip,
HitsID used_strips,
RecHitsMap rechits_map,
const CaloSubdetectorGeometry *&  geometry_p,
CaloSubdetectorTopology *&  topology_p 
)

Definition at line 12 of file PreshowerClusterAlgo.cc.

References edm::SortedCollection< T, SORT >::begin(), gather_cfg::cout, CommonMethods::cp(), debugLevel_, CaloNavigator< T >::east(), edm::SortedCollection< T, SORT >::end(), reco::CaloCluster::energy(), reco::CaloCluster::eta(), findRoad(), newFWLiteAna::found, CaloSubdetectorGeometry::getGeometry(), CaloCellGeometry::getPosition(), goodStrip(), CaloNavigator< T >::home(), reco::PreshowerCluster::nhits(), CaloNavigator< T >::north(), pDEBUG, reco::CaloCluster::phi(), pINFO, ESDetId::plane(), pos, reco::CaloCluster::position(), position, preshClusterEnergyCut_, edm::SortedCollection< T, SORT >::push_back(), rechits_map, road_2d, CaloNavigator< T >::setHome(), edm::SortedCollection< T, SORT >::size(), CaloNavigator< T >::south(), ESDetId::strip(), used_s, CaloNavigator< T >::west(), PV3DBase< T, PVType, FrameType >::x(), reco::CaloCluster::x(), PV3DBase< T, PVType, FrameType >::y(), reco::CaloCluster::y(), PV3DBase< T, PVType, FrameType >::z(), and reco::CaloCluster::z().

17 {
18  road_2d.clear();
19 
20  rechits_map = the_rechitsMap_p;
21 
22  used_s = used_strips;
23 
24  int plane = strip.plane();
25 
26  if ( debugLevel_ <= pINFO ) {
27  std::cout << "Preshower Seeded Algorithm - looking for clusters" << std::endl;
28  std::cout << "Preshower is intersected at strip " << strip.strip() << ", at plane " << plane << std::endl;
29  }
30 
31  // create null-cluster
32  std::vector< std::pair<DetId,float> > dummy;
33  Point posi(0,0,0);
34  if ( debugLevel_ <= pINFO ) std::cout << " Creating a null-cluster" << std::endl;
35  reco::PreshowerCluster nullcluster=reco::PreshowerCluster(0.,posi,dummy,plane);
36 
37  if ( strip == ESDetId(0) ) return nullcluster; //works in case of no intersected strip found (e.g. in the Barrel)
38 
39  // Collection of cluster strips
40  EcalRecHitCollection clusterRecHits;
41  // Map of strips for position calculation
42  RecHitsMap recHits_pos;
43 
44  //Make a navigator, and set it to the strip cell.
45  EcalPreshowerNavigator navigator(strip, topology_p);
46  navigator.setHome(strip);
47  //search for neighbours in the central road
48  findRoad(strip,navigator,plane);
49  if ( debugLevel_ <= pINFO ) std::cout << "Total number of strips in the central road: " << road_2d.size() << std::endl;
50 
51  if ( plane == 1 ) {
52  ESDetId strip_north = navigator.north();
53  findRoad(strip_north,navigator,plane);
54  navigator.home();
55  ESDetId strip_south = navigator.south();
56  findRoad(strip_south,navigator,plane);
57  navigator.home();
58  }
59  if ( plane == 2 ) {
60  ESDetId strip_east = navigator.east();
61  findRoad(strip_east,navigator,plane);
62  navigator.home();
63  ESDetId strip_west = navigator.west();
64  findRoad(strip_west,navigator,plane);
65  navigator.home();
66  }
67 
68  if ( debugLevel_ <= pINFO ) std::cout << "Total number of strips in all three roads: " << road_2d.size() << std::endl;
69 
70  // Start clustering from strip with max Energy in the road
71  float E_max = 0.;
72  bool found = false;
73  RecHitsMap::iterator max_it;
74  // Loop over strips:
75  std::vector<ESDetId>::iterator itID;
76  for (itID = road_2d.begin(); itID != road_2d.end(); itID++) {
77  if ( debugLevel_ == pDEBUG ) std::cout << " ID = " << *itID << std::endl;
78  RecHitsMap::iterator strip_it = rechits_map->find(*itID);
79  //if ( strip_it->second.energy() < 0 ) std::cout << " ##### E = " << strip_it->second.energy() << std::endl;
80  if(!goodStrip(strip_it)) continue;
81  if ( debugLevel_ == pDEBUG ) std::cout << " strip is " << ESDetId(strip_it->first) <<" E = " << strip_it->second.energy() <<std::endl;
82  float E = strip_it->second.energy();
83  if ( E > E_max) {
84  E_max = E;
85  found = true;
86  max_it = strip_it;
87  }
88  }
89  // no hottest strip found ==> null cluster will be returned
90  if ( !found ) return nullcluster;
91 
92  // First, save the hottest strip
93  clusterRecHits.push_back(max_it->second);
94  recHits_pos.insert(std::make_pair(max_it->first, max_it->second));
95  used_s->insert(max_it->first);
96  if ( debugLevel_ <= pINFO ) {
97  std::cout << " Central hottest strip " << ESDetId(max_it->first) << " is saved " << std::endl;
98  std::cout << " with energy E = " << E_max << std::endl;
99  }
100 
101  // Find positions of adjacent strips:
102  ESDetId next, strip_1, strip_2;
103  navigator.setHome(max_it->first);
104  ESDetId startES = max_it->first;
105 
106  if (plane == 1) {
107  // Save two neighbouring strips to the east
108  int nadjacents_east = 0;
109  while ( (next=navigator.east()) != ESDetId(0) && next != startES && nadjacents_east < 2 ) {
110  ++nadjacents_east;
111  if ( debugLevel_ == pDEBUG ) std::cout << " Adjacent east #" << nadjacents_east <<": "<< next << std::endl;
112  RecHitsMap::iterator strip_it = rechits_map->find(next);
113 
114  if(!goodStrip(strip_it)) continue;
115  // Save strip for clustering if it exists, not already in use, and satisfies an energy threshold
116  clusterRecHits.push_back(strip_it->second);
117  // save strip for position calculation
118  if ( nadjacents_east==1 ) strip_1 = next;
119  used_s->insert(strip_it->first);
120  if ( debugLevel_ == pDEBUG ) std::cout << " East adjacent strip # " << nadjacents_east << " is saved with energy E = "
121  << strip_it->second.energy() << std::endl;
122  }
123  // Save two neighbouring strips to the west
124  navigator.home();
125  int nadjacents_west = 0;
126  while ( (next=navigator.west()) != ESDetId(0) && next != startES && nadjacents_west < 2 ) {
127  ++nadjacents_west;
128  if ( debugLevel_ == pDEBUG ) std::cout << " Adjacent west #" << nadjacents_west <<": "<< next << std::endl;
129  RecHitsMap::iterator strip_it = rechits_map->find(next);
130  if(!goodStrip(strip_it)) continue;
131  clusterRecHits.push_back(strip_it->second);
132  if ( nadjacents_west==1 ) strip_2 = next;
133  used_s->insert(strip_it->first);
134  if ( debugLevel_ == pDEBUG ) std::cout << " West adjacent strip # " << nadjacents_west << " is saved with energy E = "
135  << strip_it->second.energy() << std::endl;
136  }
137  }
138  else if (plane == 2) {
139 
140  // Save two neighbouring strips to the north
141  int nadjacents_north = 0;
142  while ( (next=navigator.north()) != ESDetId(0) && next != startES && nadjacents_north < 2 ) {
143  ++nadjacents_north;
144  if ( debugLevel_ == pDEBUG ) std::cout << " Adjacent north #" << nadjacents_north <<": "<< next << std::endl;
145  RecHitsMap::iterator strip_it = rechits_map->find(next);
146  if(!goodStrip(strip_it)) continue;
147  clusterRecHits.push_back(strip_it->second);
148  if ( nadjacents_north==1 ) strip_1 = next;
149  used_s->insert(strip_it->first);
150  if ( debugLevel_ == pDEBUG ) std::cout << " North adjacent strip # " << nadjacents_north << " is saved with energy E = "
151  << strip_it->second.energy() << std::endl;
152  }
153  // Save two neighbouring strips to the south
154  navigator.home();
155  int nadjacents_south = 0;
156  while ( (next=navigator.south()) != ESDetId(0) && next != startES && nadjacents_south < 2 ) {
157  ++nadjacents_south;
158  if ( debugLevel_ == pDEBUG ) std::cout << " Adjacent south #" << nadjacents_south <<": "<< next << std::endl;
159  RecHitsMap::iterator strip_it = rechits_map->find(next);
160  if(!goodStrip(strip_it)) continue;
161  clusterRecHits.push_back(strip_it->second);
162  if ( nadjacents_south==1 ) strip_2 = next;
163  used_s->insert(strip_it->first);
164  if ( debugLevel_ == pDEBUG ) std::cout << " South adjacent strip # " << nadjacents_south << " is saved with energy E = "
165  << strip_it->second.energy() << std::endl;
166  }
167  }
168  else {
169  std::cout << " Wrong plane number" << plane <<", null cluster will be returned! " << std::endl;
170  return nullcluster;
171  } // end of if
172  if ( debugLevel_ <=pINFO ) std::cout << " Total size of clusterRecHits is " << clusterRecHits.size() << std::endl;
173  if ( debugLevel_ <=pINFO ) std::cout << " Two adjacent strips for position calculation are: "
174  << strip_1 <<" and " << strip_2 << std::endl;
175 
176  // strips for position calculation
177  RecHitsMap::iterator strip_it1, strip_it2;
178  if ( strip_1 != ESDetId(0)) {
179  strip_it1 = rechits_map->find(strip_1);
180  recHits_pos.insert(std::make_pair(strip_it1->first, strip_it1->second));
181  }
182  if ( strip_2 != ESDetId(0) ) {
183  strip_it2 = rechits_map->find(strip_2);
184  recHits_pos.insert(std::make_pair(strip_it2->first, strip_it2->second));
185  }
186 
187  RecHitsMap::iterator cp;
188  double energy_pos = 0;
189  double x_pos = 0;
190  double y_pos = 0;
191  double z_pos = 0;
192  for (cp = recHits_pos.begin(); cp!=recHits_pos.end(); cp++ ) {
193  double E = cp->second.energy();
194  energy_pos += E;
195  const CaloCellGeometry *thisCell = geometry_p->getGeometry(cp->first);
196  GlobalPoint position = thisCell->getPosition();
197  x_pos += E * position.x();
198  y_pos += E * position.y();
199  z_pos += E * position.z();
200  }
201  if(energy_pos>0.) {
202  x_pos /= energy_pos;
203  y_pos /= energy_pos;
204  z_pos /= energy_pos;
205  }
206  Point pos(x_pos,y_pos,z_pos);
207  if ( debugLevel_ == pDEBUG ) std::cout << " ES Cluster position = " << "(" << x_pos <<","<< y_pos <<","<< z_pos <<")"<< std::endl;
208 
210  double Eclust = 0;
211 
212  if ( debugLevel_ == pINFO ) std::cout << "The found ES cluster strips: " << std::endl;
213  std::vector<std::pair<DetId,float > > usedHits;
214  for (it=clusterRecHits.begin(); it != clusterRecHits.end(); it++) {
215  Eclust += it->energy();
216  usedHits.push_back(std::pair<DetId,float > (it->id(),1.));
217  if ( debugLevel_ == pINFO ) std::cout << ESDetId(it->id()) <<", E = " << it->energy()<<"; ";
218  }
219  if ( debugLevel_ == pINFO ) std::cout << std::endl;
220 
221 
222  // ES cluster is created from vector clusterRecHits
223  reco::PreshowerCluster cluster=reco::PreshowerCluster(Eclust,pos,usedHits,plane);
224 
225  if ( debugLevel_ <= pINFO ) {
226  std::cout << " ES Cluster is created with " << std::endl;
227  std::cout << " energy = " << cluster.energy() << std::endl;
228  std::cout << " (eta,phi) = " << "("<<cluster.eta()<<", "<<cluster.phi()<<")"<< std::endl;
229  std::cout << " nhits = " << cluster.nhits() << std::endl;
230  std::cout << " radius = " << cluster.position().r() << std::endl;
231  std::cout << " (x,y,z) = " << "(" << cluster.x() <<", "<< cluster.y() <<", "<< cluster.z()<<")"<< std::endl;
232  }
233 
234  used_strips = used_s;
235 
236  // return the cluster if its energy is greater a threshold
237  if( cluster.energy() > preshClusterEnergyCut_ )
238  return cluster;
239  else
240  return nullcluster;
241 
242 }
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:123
int strip() const
Definition: ESDetId.h:41
void findRoad(ESDetId strip, EcalPreshowerNavigator theESNav, int plane)
T y() const
Definition: PV3DBase.h:57
void push_back(T const &t)
double z() const
z coordinate of cluster centroid
Definition: CaloCluster.h:157
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:160
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
std::map< DetId, EcalRecHit > RecHitsMap
Definition: HLTAlCaMonPi0.h:24
T z() const
Definition: PV3DBase.h:58
math::XYZPoint Point
bool goodStrip(RecHitsMap::iterator candidate_it)
double x() const
x coordinate of cluster centroid
Definition: CaloCluster.h:151
double energy() const
cluster energy
Definition: CaloCluster.h:120
int nhits() const
Number of RecHits the cluster.
std::vector< ESDetId > road_2d
std::vector< T >::iterator iterator
const_iterator end() const
size_type size() const
int plane() const
Definition: ESDetId.h:35
tuple cout
Definition: gather_cfg.py:41
double y() const
y coordinate of cluster centroid
Definition: CaloCluster.h:154
double phi() const
azimuthal angle of cluster centroid
Definition: CaloCluster.h:163
const GlobalPoint & getPosition() const
T x() const
Definition: PV3DBase.h:56
const_iterator begin() const

Member Data Documentation

int PreshowerClusterAlgo::debugLevel_
private

Definition at line 61 of file PreshowerClusterAlgo.h.

Referenced by findRoad(), goodStrip(), and makeOneCluster().

double PreshowerClusterAlgo::preshClusterEnergyCut_
private

Definition at line 59 of file PreshowerClusterAlgo.h.

Referenced by makeOneCluster().

int PreshowerClusterAlgo::preshSeededNstr_
private

Definition at line 60 of file PreshowerClusterAlgo.h.

Referenced by findRoad().

double PreshowerClusterAlgo::preshStripEnergyCut_
private

Definition at line 58 of file PreshowerClusterAlgo.h.

Referenced by goodStrip().

RecHitsMap* PreshowerClusterAlgo::rechits_map
private

Definition at line 66 of file PreshowerClusterAlgo.h.

Referenced by goodStrip(), and makeOneCluster().

std::vector<ESDetId> PreshowerClusterAlgo::road_2d
private

Definition at line 63 of file PreshowerClusterAlgo.h.

Referenced by findRoad(), and makeOneCluster().

HitsID* PreshowerClusterAlgo::used_s
private

Definition at line 69 of file PreshowerClusterAlgo.h.

Referenced by goodStrip(), and makeOneCluster().