9 #include "Math/GenVector/VectorUtil.h"
62 double numeratorEta = 0.0;
63 double numeratorPhi = 0.0;
68 const double clusterEnergy = cluster.
energy();
70 const std::vector <reco::PFRecHitFraction >& pfhitsandfracs = cluster.
recHitFractions();
71 for (std::vector<reco::PFRecHitFraction>::const_iterator it = pfhitsandfracs.begin(); it != pfhitsandfracs.end(); ++it) {
73 double hitEta = rechit->positionREP().Eta();
74 double hitPhi = rechit->positionREP().Phi();
78 double hitEnergy = rechit->energy();
79 const double w =
std::max(0.0, w0_ +
log(hitEnergy / clusterEnergy));
81 numeratorEta += w*hitEta;
82 numeratorPhi += w*hitPhi;
88 pair<double, double> posEtaPhi(posEta,posPhi);
96 double numeratorEtaEta = 0;
98 double numeratorPhiPhi = 0;
100 double widthEta = 0.0;
101 double widthPhi = 0.0;
107 const double clusterEnergy = cluster.
energy();
109 double hitEta, hitPhi, hitEnergy, dEta,
dPhi;
110 const std::vector< reco::PFRecHitFraction >& pfhitsandfracs = cluster.
recHitFractions();
111 for (std::vector<reco::PFRecHitFraction>::const_iterator it = pfhitsandfracs.begin(); it != pfhitsandfracs.end(); ++it) {
114 hitEta = rechit->positionREP().Eta();
115 hitPhi = rechit->positionREP().Phi();
116 hitEnergy = rechit->energy();
117 dEta = hitEta - clusterEta;
118 dPhi = hitPhi - clusterPhi;
124 const double w =
std::max(0.0, w0_ +
log(hitEnergy / clusterEnergy));
127 numeratorEtaEta += w * dEta * dEta;
129 numeratorPhiPhi += w * dPhi *
dPhi;
136 widthEta =
sqrt(
abs(covEtaEta));
137 widthPhi =
sqrt(
abs(covPhiPhi));
139 pair<double, double> widthEtaPhi(widthEta,widthPhi);
146 double dEtacut = 0.0;
147 double dPhicut = 0.0;
148 double etaScale = 1.0;
149 double phiScale = 0.5;
155 pfClusters_.reset(
new std::vector<reco::PFCluster> );
163 std::vector< unsigned > clusterdepth(clusters.size());
167 for (
unsigned short ic=0; ic<clusters.size();++ic) {
171 for (
unsigned short ic=0; ic<clusters.size();++ic)
176 const std::vector< std::pair<DetId, float> > & hitsandfracs =
177 clusters[ic].hitsAndFractions();
178 unsigned clusterdepthfirst=0;
179 for(
unsigned ihandf=0; ihandf<hitsandfracs.size(); ihandf++) {
182 clusterdepth[ic] = depth;
183 if( ihandf>0 && depth!=clusterdepthfirst)
cout <<
" Problem with cluster depth: " << depth <<
" not equal to " << clusterdepthfirst <<endl;
184 else if( ihandf==0 ) clusterdepthfirst = depth;
189 std::vector< unsigned > clusterdepthHO(clustersHO.size());
198 for (
unsigned short ic=0; ic<clustersHO.size();++ic)
202 const std::vector< std::pair<DetId, float> > & hitsandfracs =
203 clustersHO[ic].hitsAndFractions();
204 unsigned clusterdepthfirst=0;
205 for(
unsigned ihandf=0; ihandf<hitsandfracs.size(); ihandf++) {
208 clusterdepthHO[ic] = depth;
209 if( ihandf>0 && depth!=clusterdepthfirst)
cout <<
" Problem with HO cluster depth: " << depth <<
" not equal to " << clusterdepthfirst <<endl;
210 else if( ihandf==0 ) clusterdepthfirst = depth;
216 std::vector< unsigned > imerge(clusters.size());
217 std::vector< unsigned > imergeHO(clustersHO.size());
218 std::vector< bool > lmerge(clusters.size());
219 std::vector< bool > lmergeHO(clustersHO.size());
230 for (
unsigned short ic1=0; ic1<clusters.size();++ic1) {
233 for (
unsigned short ic1=0; ic1<clustersHO.size();++ic1) {
236 for (
unsigned short ic1=0; ic1<clusters.size();++ic1) {
237 if( clusterdepth[ic1]==1 ){
240 for (
unsigned short ic2=0; ic2<clusters.size();++ic2) {
243 dR =
deltaR( hcaleta1, hcalphi1, hcaleta2, hcalphi2 );
244 dEta =
abs(hcaleta1 - hcaleta2);
247 if (w1 == 0) w1 = 0.087;
249 if (w2 == 0) w2 = 0.087;
251 if (w3 < 0.087) w3 = 0.087;
253 if (w4 < 0.087) w4 = 0.087;
254 double etawidth =
sqrt(w1*w1 + w2*w2);
255 double phiwidth =
sqrt(w3*w3 + w4*w4);
256 dEtacut = etaScale*etawidth;
257 dPhicut = phiScale*phiwidth;
258 if( clusterdepth[ic2]==2 ){
260 if((dR<dRcut) || (dEta<dEtacut && dPhi<dPhicut)) {
264 }
else if( clusterdepth[ic2]==3 ){
266 if((dR<dRcut) || (dEta<dEtacut && dPhi<dPhicut) ) {
272 }
else if( clusterdepth[ic1]==2 ){
275 for (
unsigned short ic2=0; ic2<clusters.size();++ic2) {
278 dEta =
abs(hcaleta1 - hcaleta2);
280 dR =
deltaR( hcaleta1, hcalphi1, hcaleta2, hcalphi2 );
282 if (w1 == 0) w1 = 0.087;
284 if (w2 == 0) w2 = 0.087;
286 if (w3 < 0.087) w3 = 0.087;
288 if (w4 < 0.087) w4 = 0.087;
289 double etawidth =
sqrt(w1*w1+w2*w2);
290 double phiwidth =
sqrt(w3*w3+w4*w4);
291 dEtacut = etaScale*etawidth;
292 dPhicut = phiScale*phiwidth;
293 if( clusterdepth[ic2]==3 ){
294 if((dR<dRcut) || (dEta<dEtacut && dPhi<dPhicut)) {
298 }
else if( clusterdepth[ic2]==4 ){
300 if((dR<dRcut) || (dEta<dEtacut && dPhi<dPhicut)) {
306 }
else if( clusterdepth[ic1]==3 ){
309 for (
unsigned short ic2=0; ic2<clusters.size();++ic2) {
312 dEta =
abs(hcaleta1 - hcaleta2);
314 dR =
deltaR( hcaleta1, hcalphi1, hcaleta2, hcalphi2 );
316 if (w1 == 0) w1 = 0.087;
318 if (w2 == 0) w2 = 0.087;
320 if (w3 < 0.087) w3 = 0.087;
322 if (w4 < 0.087) w4 = 0.087;
323 double etawidth =
sqrt(w1*w1+w2*w2);
324 double phiwidth =
sqrt(w3*w3+w4*w4);
325 dEtacut = etaScale*etawidth;
326 dPhicut = phiScale*phiwidth;
327 if( clusterdepth[ic2]==4 ){
329 if((dR<dRcut) || (dEta<dEtacut && dPhi<dPhicut)) {
333 }
else if( clusterdepth[ic2]==5 ){
335 if((dR<dRcut) || (dEta<dEtacut && dPhi<dPhicut)) {
341 for (
unsigned short ic2=0; ic2<clustersHO.size();++ic2) {
344 dEta =
abs(hcaleta1 - hcaleta2);
346 dR =
deltaR( hcaleta1, hcalphi1, hcaleta2, hcalphi2 );
348 if (w1 == 0) w1 = 0.087;
350 if (w2 == 0) w2 = 0.087;
352 if (w3 < 0.087) w3 = 0.087;
354 if (w4 < 0.087) w4 = 0.087;
355 double etawidth =
sqrt(w1*w1+w2*w2);
356 double phiwidth =
sqrt(w3*w3+w4*w4);
357 dEtacut = etaScale*etawidth;
358 dPhicut = phiScale*phiwidth;
359 if( clusterdepthHO[ic2]==5 ){
361 if((dR<dRcut) || (dEta<dEtacut && dPhi<dPhicut)) {
367 }
else if( clusterdepth[ic1]==4 ){
370 for (
unsigned short ic2=0; ic2<clusters.size();++ic2) {
373 dEta =
abs(hcaleta1 - hcaleta2);
375 dR =
deltaR( hcaleta1, hcalphi1, hcaleta2, hcalphi2 );
377 if (w1 < 0.087) w1 = 0.087;
379 if (w2 < 0.087) w2 = 0.087;
381 if (w3 < 0.087) w3 = 0.087;
383 if (w4 < 0.087) w4 = 0.087;
384 double etawidth =
sqrt(w1*w1+w2*w2);
385 double phiwidth =
sqrt(w3*w3+w4*w4);
386 dEtacut = etaScale*etawidth;
387 dPhicut = phiScale*phiwidth;
388 if( clusterdepth[ic2]==5 ){
390 if((dR<dRcut) || (dEta<dEtacut && dPhi<dPhicut)) {
396 }
else if( clusterdepth[ic1]==5 ){
408 std::vector< bool > lmergeclusters(clusters.size());
409 for (
unsigned short id=0;
id<4;++id) {
411 for (
unsigned short ic1=0; ic1<clusters.size();++ic1) {
412 if( clusterdepth[ic1]==(
unsigned)(1+id) ){
414 for (
unsigned short ic=0; ic<clusters.size();++ic) {
415 lmergeclusters[ic]=
false;
418 for (
unsigned short ic2=0; ic2<clusters.size();++ic2) {
419 if( clusterdepth[ic2]==(
unsigned)(2+id) ){
420 if( imerge[ic2]==ic1 && lmerge[ic2] ) {
422 lmergeclusters[ic2]=
true;
423 for (
unsigned short ic3=0; ic3<clusters.size();++ic3) {
424 if( clusterdepth[ic3]==(
unsigned)(3+id) ){
425 if( imerge[ic3]==ic2 && lmerge[ic3] ) {
427 lmergeclusters[ic3]=
true;
428 for (
unsigned short ic4=0; ic4<clusters.size();++ic4) {
429 if( clusterdepth[ic4]==(
unsigned)(4+id) ){
430 if( imerge[ic4]==ic3 && lmerge[ic4] ) {
432 lmergeclusters[ic4]=
true;
433 for (
unsigned short ic5=0; ic5<clusters.size();++ic5) {
434 if( clusterdepth[ic5]==(
unsigned)(5+id) ){
436 if( imerge[ic5]==ic4 && lmerge[ic5] ) lmergeclusters[ic5]=
true;
439 }
else if( clusterdepth[ic4]==(
unsigned)(5+id) ){
441 if( imerge[ic4]==ic3 && lmerge[ic4] ) lmergeclusters[ic4]=
true;
445 }
else if( clusterdepth[ic3]==(
unsigned)(4+id) ){
446 if( imerge[ic3]==ic2 && lmerge[ic3] ) {
448 lmergeclusters[ic3]=
true;
449 for (
unsigned short ic4=0; ic4<clusters.size();++ic4) {
450 if( clusterdepth[ic4]==(
unsigned)(5+id) ){
452 if( imerge[ic4]==ic3 && lmerge[ic4] ) lmergeclusters[ic4]=
true;
457 }
if( clusterdepth[ic3]==(
unsigned)(5+id) ){
459 if( imerge[ic3]==ic2 && lmerge[ic3] ) lmergeclusters[ic3]=
true;
463 }
else if( clusterdepth[ic2]==(
unsigned)(3+id) ){
464 if( imerge[ic2]==ic1 && lmerge[ic2] ) {
466 lmergeclusters[ic2]=
true;
467 for (
unsigned short ic3=0; ic3<clusters.size();++ic3) {
468 if( clusterdepth[ic3]==(
unsigned)(4+id) ){
469 if( imerge[ic3]==ic2 && lmerge[ic3] ) {
471 lmergeclusters[ic3]=
true;
472 for (
unsigned short ic4=0; ic4<clusters.size();++ic4) {
473 if( clusterdepth[ic4]==(
unsigned)(5+id) ){
475 if( imerge[ic4]==ic3 && lmerge[ic4] ) lmergeclusters[ic4]=
true;
478 }
else if( clusterdepth[ic3]==(
unsigned)(5+id) ){
480 if( imerge[ic3]==ic2 && lmerge[ic3] ) lmergeclusters[ic3]=
true;
488 for (
unsigned short ic=0; ic<clusters.size();++ic) {
489 if(lmergeclusters[ic]) {
493 if(mergeclusters.
size()>0) {
500 mergeclusters.
clear();
519 clusterdepth.clear();
520 clusterdepthHO.clear();
525 mergeclusters.
clear();
530 out<<
"PFSuperClusterAlgo parameters : "<<endl;
531 out<<
"-----------------------------------------------------"<<endl;
size_type size() const
Size of the RefVector.
common ppss p3p6s2 common epss epspn46 common const1 w2
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
void push_back(Ptr< T > const &iPtr)
Particle flow cluster, see clustering algorithm in PFSuperClusterAlgo.
std::ostream & operator<<(std::ostream &out, const ALILine &li)
static unsigned prodNum_
product number
edm::PtrVector< reco::PFCluster > clusters_
common ppss p3p6s2 common epss epspn46 common const1 w4
double dPhi(double phi1, double phi2)
const T & max(const T &a, const T &b)
edm::Ptr< reco::PFCluster > PFClusterPtr
Abs< T >::type abs(const T &t)
void doClusteringWorker(const reco::PFClusterCollection &clusters, const reco::PFClusterCollection &clustersHO)
perform clustering
std::pair< double, double > calculateWidths(const reco::PFCluster &cluster)
calculate eta-phi widths of clusters
double energy() const
cluster energy
void initialize(reco::PFSuperCluster &supercluster, edm::PtrVector< reco::PFCluster > const &clusters)
double deltaR(double eta1, double eta2, double phi1, double phi2)
std::auto_ptr< std::vector< reco::PFCluster > > pfClusters_
particle flow clusters
std::pair< double, double > calculatePosition(const reco::PFCluster &cluster)
recalculate eta-phi position of clusters
common ppss p3p6s2 common epss epspn46 common const1 w3
void clear()
Clear the PtrVector.
PFClusterHandle clustersHOHandle_
Algorithm for particle flow superclustering.
PFHcalSuperClusterAlgo()
constructor
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
volatile std::atomic< bool > shutdown_flag false
const edm::PtrVector< reco::PFCluster > & clusters() const
void doClustering(const reco::PFClusterCollection &clusters, const reco::PFClusterCollection &clustersHO)
perform clustering
std::auto_ptr< std::vector< reco::PFSuperCluster > > pfSuperClusters_
particle flow superclusters
PFClusterHandle clustersHandle_