CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
KDTreeLinkerPSEcal.cc
Go to the documentation of this file.
2 
4 #include "TMath.h"
5 
8  resPSpitch_ (0.19),
9  resPSlength_ (6.1),
10  ps1ToEcal_ (1.072),
11  ps2ToEcal_ (1.057)
12 {}
13 
15 {
16  clear();
17 }
18 
19 
20 void
22 {
23  reco::PFClusterRef clusterref = psCluster->clusterRef();
24 
25  // This test is more or less done in PFBlockAlgo.h. In others cases, it should be switch on.
26  // if (!((clusterref->layer() == PFLayer::PS1) ||
27  // (clusterref->layer() == PFLayer::PS2)))
28  // return;
29 
30  targetSet_.insert(psCluster);
31 }
32 
33 
34 void
36 {
37  reco::PFClusterRef clusterref = ecalCluster->clusterRef();
38 
39  if (clusterref->layer() != PFLayer::ECAL_ENDCAP)
40  return;
41 
42  const std::vector<reco::PFRecHitFraction> &fraction = clusterref->recHitFractions();
43 
44  // We create a list of cluster
45  fieldClusterSet_.insert(ecalCluster);
46 
47  double clusterz = clusterref->position().Z();
48  RecHitSet& rechitsSet = (clusterz < 0) ? rechitsNegSet_ : rechitsPosSet_;
49 
50  for(size_t rhit = 0; rhit < fraction.size(); ++rhit) {
51  const reco::PFRecHitRef& rh = fraction[rhit].recHitRef();
52  double fract = fraction[rhit].fraction();
53 
54  if ((rh.isNull()) || (fract < 1E-4))
55  continue;
56 
57  const reco::PFRecHit& rechit = *rh;
58 
59  // We save the links rechit to Clusters
60  rechit2ClusterLinks_[&rechit].insert(ecalCluster);
61 
62  // We create a liste of rechits
63  rechitsSet.insert(&rechit);
64  }
65 }
66 
67 void
69 {
72 }
73 
74 void
77 {
78  // List of pseudo-rechits that will be used to create the KDTree
79  std::vector<KDTreeNodeInfo> eltList;
80 
81  // Filling of this eltList
82  for(RecHitSet::const_iterator it = rechitsSet.begin();
83  it != rechitsSet.end(); it++) {
84 
85  const reco::PFRecHit* rh = *it;
86  const math::XYZPoint& posxyz = rh->position();
87 
88  KDTreeNodeInfo rhinfo (rh, posxyz.X(), posxyz.Y());
89  eltList.push_back(rhinfo);
90  }
91 
92  // xmin-xmax, ymain-ymax
93  KDTreeBox region(-150., 150., -150., 150.);
94 
95  // We may now build the KDTree
96  tree.build(eltList, region);
97 }
98 
99 void
101 {
102  // Must of the code has been taken from LinkByRecHit.cc
103 
104  // We iterate over the PS clusters.
105  for(BlockEltSet::iterator it = targetSet_.begin();
106  it != targetSet_.end(); it++) {
107 
108  (*it)->setIsValidMultilinks(true);
109 
110  reco::PFClusterRef clusterPSRef = (*it)->clusterRef();
111  const reco::PFCluster& clusterPS = *clusterPSRef;
112 
113  // PS cluster position, extrapolated to ECAL
114  double zPS = clusterPS.position().Z();
115  double xPS = clusterPS.position().X();
116  double yPS = clusterPS.position().Y();
117 
118  double etaPS = fabs(clusterPS.positionREP().eta());
119  double deltaX = 0.;
120  double deltaY = 0.;
121  double xPSonEcal = xPS;
122  double yPSonEcal = yPS;
123 
124  if (clusterPS.layer() == PFLayer::PS1) { // PS1
125 
126  // vertical strips, measure x with pitch precision
127  deltaX = resPSpitch_;
128  deltaY = resPSlength_;
129  xPSonEcal *= ps1ToEcal_;
130  yPSonEcal *= ps1ToEcal_;
131 
132  } else { // PS2
133 
134  // horizontal strips, measure y with pitch precision
135  deltaY = resPSpitch_;
136  deltaX = resPSlength_;
137  xPSonEcal *= ps2ToEcal_;
138  yPSonEcal *= ps2ToEcal_;
139 
140  }
141 
142 
143  // Estimate the maximal envelope in phi/eta that will be used to find rechit candidates.
144  // Same envelope for cap et barrel rechits.
145 
146 
147  double maxEcalRadius = getCristalXYMaxSize() / 2.;
148 
149  // The inflation factor includes the approximate projection from Preshower to ECAL
150  double inflation = 2.4 - (etaPS-1.6);
151  double rangeX = maxEcalRadius * (1 + (0.05 + 1.0 / maxEcalRadius * deltaX / 2.)) * inflation;
152  double rangeY = maxEcalRadius * (1 + (0.05 + 1.0 / maxEcalRadius * deltaY / 2.)) * inflation;
153 
154  // We search for all candidate recHits, ie all recHits contained in the maximal size envelope.
155  std::vector<KDTreeNodeInfo> recHits;
156  KDTreeBox trackBox(xPSonEcal - rangeX, xPSonEcal + rangeX,
157  yPSonEcal - rangeY, yPSonEcal + rangeY);
158 
159  if (zPS < 0)
160  treeNeg_.search(trackBox, recHits);
161  else
162  treePos_.search(trackBox, recHits);
163 
164 
165  for(std::vector<KDTreeNodeInfo>::const_iterator rhit = recHits.begin();
166  rhit != recHits.end(); ++rhit) {
167 
168  const std::vector< math::XYZPoint >& corners = rhit->ptr->getCornersXYZ();
169  if(corners.size() != 4) continue;
170 
171  // Find all clusters associated to given rechit
172  RecHit2BlockEltMap::iterator ret = rechit2ClusterLinks_.find(rhit->ptr);
173 
174  for(BlockEltSet::const_iterator clusterIt = ret->second.begin();
175  clusterIt != ret->second.end(); clusterIt++) {
176 
177  reco::PFClusterRef clusterref = (*clusterIt)->clusterRef();
178  double clusterz = clusterref->position().Z();
179 
180  const math::XYZPoint& posxyz = rhit->ptr->position() * zPS / clusterz;
181 
182  double x[5];
183  double y[5];
184  for ( unsigned jc=0; jc<4; ++jc ) {
185  math::XYZPoint cornerpos = corners[jc] * zPS / clusterz;
186  x[jc] = cornerpos.X() + (cornerpos.X()-posxyz.X()) * (0.05 +1.0/fabs((cornerpos.X()-posxyz.X()))*deltaX/2.);
187  y[jc] = cornerpos.Y() + (cornerpos.Y()-posxyz.Y()) * (0.05 +1.0/fabs((cornerpos.Y()-posxyz.Y()))*deltaY/2.);
188  }
189 
190  x[4] = x[0];
191  y[4] = y[0];
192 
193  bool isinside = TMath::IsInside(xPS,
194  yPS,
195  5,x,y);
196 
197  // Check if the track and the cluster are linked
198  if( isinside )
199  target2ClusterLinks_[*it].insert(*clusterIt);
200  }
201  }
202 
203  }
204 }
205 
206 void
208 {
209  //TODO YG : Check if cluster positionREP() is valid ?
210 
211  // Here we save in each track the list of phi/eta values of linked clusters.
212  for (BlockElt2BlockEltMap::iterator it = target2ClusterLinks_.begin();
213  it != target2ClusterLinks_.end(); ++it) {
214  reco::PFMultiLinksTC multitracks(true);
215 
216  for (BlockEltSet::iterator jt = it->second.begin();
217  jt != it->second.end(); ++jt) {
218 
219  double clusterPhi = (*jt)->clusterRef()->positionREP().Phi();
220  double clusterEta = (*jt)->clusterRef()->positionREP().Eta();
221 
222  multitracks.linkedClusters.push_back(std::make_pair(clusterPhi, clusterEta));
223  }
224 
225  it->first->setMultilinks(multitracks);
226  }
227 }
228 
229 void
231 {
232  targetSet_.clear();
233  fieldClusterSet_.clear();
234 
235  rechitsNegSet_.clear();
236  rechitsPosSet_.clear();
237 
238  rechit2ClusterLinks_.clear();
239  target2ClusterLinks_.clear();
240 
241  treeNeg_.clear();
242  treePos_.clear();
243 }
PFLayer::Layer layer() const
cluster layer, see PFLayer.h in this directory
Definition: PFCluster.cc:81
const double resPSlength_
Abstract base class for a PFBlock element (track, cluster...)
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:124
void build(std::vector< KDTreeNodeInfo > &eltList, const KDTreeBox &region)
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:43
BlockElt2BlockEltMap target2ClusterLinks_
void insertFieldClusterElt(reco::PFBlockElement *ecalCluster)
const double resPSpitch_
void search(const KDTreeBox &searchBox, std::vector< KDTreeNodeInfo > &resRecHitList)
bool isNull() const
Checks for null.
Definition: Ref.h:247
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:31
const REPPoint & positionREP() const
cluster position: rho, eta, phi
Definition: PFCluster.h:75
PFMultilinksType linkedClusters
float getCristalXYMaxSize() const
virtual PFClusterRef clusterRef() const
const Fraction< n, m >::type & fract()
Definition: Fraction.h:38
const math::XYZPoint & position() const
is seed ?
Definition: PFRecHit.h:141
std::set< const reco::PFRecHit * > RecHitSet
KDTreeLinkerAlgo treePos_
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
BlockEltSet fieldClusterSet_
void insertTargetElt(reco::PFBlockElement *psCluster)
Definition: DDAxes.h:10
KDTreeLinkerAlgo treeNeg_
RecHit2BlockEltMap rechit2ClusterLinks_