CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ggPFESClusters.cc
Go to the documentation of this file.
3 #include "TMath.h"
4 using namespace edm;
5 using namespace std;
6 using namespace reco;
7 /*
8 class by Rishi Patel rpatel@cern.ch
9 and Eleni Petrakou Eleni.Petrakou@cern.ch
10 */
13  const CaloSubdetectorGeometry* geomEnd
14  ):
15  ESRecHits_(ESRecHits),
16  geomEnd_(geomEnd)
17 {
18 
19 }
20 
22 
23 }
24 
25 // Returns ES clusters for a PF supercluster
26 vector<reco::PreshowerCluster> ggPFESClusters::getPFESClusters(
28  ){
29  std::vector<PreshowerCluster>PFPreShowerClust;
30  int jj = 0;
31  float energies[100];
33  if(jj>99)
34  cout << endl << "Attention! More than 100 ES clusters!" << endl;
35  else {
36  energies[jj] = (*ps)->energy();
37  bool doubl = false;
38  for(int kk=0; kk<jj; kk++){
39  if(fabs(energies[kk]-(*ps)->energy())<0.0000001){
40  //cout << endl << "Duplicate cluster";
41  doubl = true;
42  break;
43  }
44  }
45  jj++;
46  if(doubl) continue;
47  }
48 
49  std::vector< std::pair<DetId, float> > psCells=(*ps)->hitsAndFractions();
50  float PS1E=0;
51  float PS2E=0;
52  int plane=0;
53  for(unsigned int s=0; s<psCells.size(); ++s){
54  for(EcalRecHitCollection::const_iterator es=ESRecHits_->begin(); es!= ESRecHits_->end(); ++es){
55  if(es->id().rawId()==psCells[s].first.rawId()){
56  ESDetId id=ESDetId(psCells[s].first.rawId());
57  plane=id.plane();
58  if(id.plane()==1)PS1E=PS1E + es->energy() * psCells[s].second;
59  if(id.plane()==2)PS2E=PS2E + es->energy() * psCells[s].second;
60  break;
61  }
62  }
63  }
64  //make PreShower object storing plane PSEnergy and Position
65  if(plane==1){
66  PreshowerCluster PS1=PreshowerCluster(PS1E,(*ps)->position(),(*ps)->hitsAndFractions(),plane);
67  PFPreShowerClust.push_back(PS1);
68  }
69  if(plane==2){
70  PreshowerCluster PS2=PreshowerCluster(PS2E,(*ps)->position(),(*ps)->hitsAndFractions(),plane);
71  PFPreShowerClust.push_back(PS2);
72  }
73  }
74  return PFPreShowerClust;
75 }
76 
77 
78 // Maps each ES cluster to its closest linked EE cluster.
79 std::map<unsigned int,unsigned int> ggPFESClusters::getClosestEECls(vector<reco::PreshowerCluster> PFPS, vector<reco::CaloCluster> PF){
80  std::map<unsigned int,unsigned int> linkedIndices;
81  std::map<double, unsigned int> links;
82 
83  for(unsigned int j=0; j<PFPS.size(); ++j){
84  for(unsigned int i=0; i<PF.size(); ++i){
85  double link_ = getLinkDist(PFPS[j], PF[i]);
86  if(link_!=-1.)
87  links.insert(std::make_pair(link_,i));
88  }
89  std::map<double,unsigned int>::iterator itlinks = links.begin();
90  if((*itlinks).first>=0.)
91  linkedIndices.insert(std::make_pair(j, (*itlinks).second));
92  links.clear();
93  }
94 
95  return linkedIndices;
96 }
97 
98 
99 // Returns PF link distance between ES-EE clusters.
101 
102  static double resPSpitch = 0.19/sqrt(12.);
103  static double resPSlength = 6.1/sqrt(12.);
104 
105  // ECAL cluster position
106  double zECAL = clusterECAL.position().Z(); // cluster centroid position
107  double xECAL = clusterECAL.position().X();
108  double yECAL = clusterECAL.position().Y();
109 
110  // PS cluster position
111  double zPS = clusterPS.position().Z();
112  double xPS = clusterPS.position().X();
113  double yPS = clusterPS.position().Y();
114 
115  // Check that zEcal and zPs have the same sign
116  if (zECAL*zPS < 0.) return -1.;
117  double deltaX = 0.;
118  double deltaY = 0.;
119  double sqr12 = std::sqrt(12.);
120  switch (clusterPS.plane()) {
121  case 1:
122  // vertical strips, measure x with pitch precision
123  deltaX = resPSpitch * sqr12;
124  deltaY = resPSlength * sqr12;
125  break;
126  case 2:
127  // horizontal strips, measure y with pitch precision
128  deltaY = resPSpitch * sqr12;
129  deltaX = resPSlength * sqr12;
130  break;
131  default:
132  break;
133  }
134 
135  // Get the rechits
136  const std::vector< std::pair<DetId, float> > fracs = clusterECAL.hitsAndFractions();
137  bool linkedbyrechit = false;
138  //loop rechits
139  for(unsigned int rhit = 0; rhit < fracs.size(); rhit++){
140  double fraction = fracs[rhit].second;
141  if(fraction < 1E-4) continue;
142  if(fracs[rhit].first.null()) continue;
143 
144  //getting rechit center position
145  DetId eehitid=DetId(fracs[rhit].first.rawId());
146  const CaloCellGeometry *xtal = geomEnd_->getGeometry(eehitid);
147  if(!xtal) continue;
148 
149  //getting rechit corners
150  const CaloCellGeometry::CornersVec& corners_vec = xtal->getCorners();
151  math::XYZPoint corners[4];
152  // They have this order just for compatibility with the original function.
153  corners[0] = math::XYZPoint(corners_vec[3].x(), corners_vec[3].y(), corners_vec[3].z() );
154  corners[1] = math::XYZPoint(corners_vec[2].x(), corners_vec[2].y(), corners_vec[2].z() );
155  corners[2] = math::XYZPoint(corners_vec[1].x(), corners_vec[1].y(), corners_vec[1].z() );
156  corners[3] = math::XYZPoint(corners_vec[0].x(), corners_vec[0].y(), corners_vec[0].z() );
157  const GlobalPoint p = geomEnd_->getGeometry(eehitid)->getPosition();
158 
159  // Extrapolating from the xtal's surface (because of working with DetId's)
160  const math::XYZPoint& posxyz = math::XYZPoint(p.x()*zPS/p.z(), p.y()*zPS/p.z(), p.z()*zPS/p.z());
161 
162  double x[5];
163  double y[5];
164  for ( unsigned jc=0; jc<4; ++jc ) {
165  // corner position projected onto the preshower
166  math::XYZPoint cornerpos = corners[jc] * zPS/p.z();
167  // Inflate the size by the size of the PS strips, and by 5% to include ECAL cracks.
168  x[jc] = cornerpos.X() + (cornerpos.X()-posxyz.X()) * (0.05 +1.0/fabs((cornerpos.X()-posxyz.X()))*deltaX/2.);
169  y[jc] = cornerpos.Y() + (cornerpos.Y()-posxyz.Y()) * (0.05 +1.0/fabs((cornerpos.Y()-posxyz.Y()))*deltaY/2.);
170  }//loop corners
171 
172  //need to close the polygon in order to use the TMath::IsInside fonction from root lib
173  x[4] = x[0];
174  y[4] = y[0];
175 
176  //Check if the extrapolation point of the track falls within the rechit boundaries
177  bool isinside = TMath::IsInside(xPS,yPS,5,x,y);
178 
179  if( isinside ){
180  linkedbyrechit = true;
181  break;
182  }
183 
184  }//loop rechits
185 
186  if( linkedbyrechit ) {
187  double dist = std::sqrt( (xECAL/1000. - xPS/1000.)*(xECAL/1000. - xPS/1000.)
188  + (yECAL/1000. - yPS/1000.)*(yECAL/1000. - yPS/1000.) );
189  return dist;
190  } else {
191  return -1.;
192  }
193 
194 }
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:123
CaloCluster_iterator preshowerClustersBegin() const
fist iterator over PreshowerCluster constituents
Definition: SuperCluster.h:71
int i
Definition: DBlmapReader.cc:9
const CaloSubdetectorGeometry * geomEnd_
std::map< unsigned int, unsigned int > getClosestEECls(vector< reco::PreshowerCluster > PFPS, vector< reco::CaloCluster > PF)
ggPFESClusters(edm::Handle< EcalRecHitCollection > &ESRecHits, const CaloSubdetectorGeometry *geomEnd)
std::vector< EcalRecHit >::const_iterator const_iterator
T y() const
Definition: PV3DBase.h:62
int plane() const
Preshower plane.
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:189
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
double double double z
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
virtual ~ggPFESClusters()
T sqrt(T t)
Definition: SSEVec.h:46
T z() const
Definition: PV3DBase.h:63
int j
Definition: DBlmapReader.cc:9
bool first
Definition: L1TdeRCT.cc:94
Definition: DetId.h:20
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
virtual vector< reco::PreshowerCluster > getPFESClusters(reco::SuperCluster sc)
Handle< EcalRecHitCollection > ESRecHits_
int plane() const
Definition: ESDetId.h:35
tuple cout
Definition: gather_cfg.py:121
double getLinkDist(reco::PreshowerCluster clusterPS, reco::CaloCluster clusterECAL)
x
Definition: VDTMath.h:216
T x() const
Definition: PV3DBase.h:61
CaloCluster_iterator preshowerClustersEnd() const
last iterator over PreshowerCluster constituents
Definition: SuperCluster.h:74