CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFHcalSuperClusterInit.cc
Go to the documentation of this file.
6 
7 using namespace std;
8 using namespace reco;
9 
10 void PFHcalSuperClusterInit::initialize( PFSuperCluster & supercluster, edm::PtrVector<reco::PFCluster> const & clusters){
11 
12 // std::vector< unsigned> recHitDetId;
13  std::vector< double> recHitEnergy;
14  std::vector< PFRecHitRef> recHitRef;
15  double superClusterEnergy = 0.0;
16 // unsigned maxHitDetId = 0;
17  double maxHitEnergy = 0.0;
18  CaloID maxClusterCaloId;
19  PFLayer::Layer maxClusterLayer=PFLayer::HCAL_BARREL1;
20  double maxClusterEnergy = 0.0;
21  int maxClusterColor=2;
22 // cout << " Supercluster clusters: " << clusters.size() <<endl;
23  for (unsigned short ic=0; ic<clusters.size();++ic) {
24 // const std::vector< std::pair<DetId, float> > & hitsandfracs =
25 // clusters[ic].hitsAndFractions();
26  const std::vector< reco::PFRecHitFraction >& pfhitsandfracs = clusters[ic]->recHitFractions();
27  double clusterEnergy = clusters[ic]->energy();
28  superClusterEnergy+=clusterEnergy;
29  if (clusterEnergy>=maxClusterEnergy) {
30  maxClusterLayer=clusters[ic]->layer();
31  maxClusterColor=clusters[ic]->color();
32  maxClusterCaloId=clusters[ic]->caloID();
33  maxClusterEnergy=clusterEnergy;
34  }
35  for (unsigned ihandf=0; ihandf<pfhitsandfracs.size(); ihandf++) {
36 // unsigned hitDetId = pfhitsandfracs[ihandf].recHitRef()->detId();
37  double hitEnergy = pfhitsandfracs[ihandf].fraction()*clusterEnergy;
38 // recHitDetId.push_back(hitDetId);
39  recHitEnergy.push_back(hitEnergy);
40  recHitRef.push_back(pfhitsandfracs[ihandf].recHitRef());
41  if(hitEnergy>=maxHitEnergy) {
42 // maxHitDetId=hitDetId;
43  maxHitEnergy=hitEnergy;
44  }
45  }
46 // delete hitsandfracs;
47  }
48 
49  for (unsigned short ir=0; ir<recHitEnergy.size();++ir) {
50  double fraction=1.0;
51  if( superClusterEnergy >0.0) {
52  fraction = recHitEnergy[ir]/superClusterEnergy;
53  }
54  reco::PFRecHitFraction frac(recHitRef[ir],fraction);
55 
56  supercluster.addRecHitFraction( frac );
57 
58 // addHitAndFraction( recHitDetId[ir], fraction );
59 // cout << " Supercluster rechits detid/fraction: " << recHitDetId[ir] << " / " << fraction <<endl;
60  }
61 // recHitDetId.clear();
62  recHitEnergy.clear();
63  recHitRef.clear();
64 
65  supercluster.setLayer( maxClusterLayer );
66  supercluster.setEnergy( superClusterEnergy );
67  supercluster.setCaloId( maxClusterCaloId );
68  supercluster.setSeed( maxHitEnergy );
69  supercluster.setAlgoId( CaloCluster::particleFlow );
70  supercluster.setColor( maxClusterColor );
71 
72  double numeratorEta = 0.0;
73  double numeratorPhi = 0.0;
74  double numeratorRho = 0.0;
75  double denominator = 0.0;
76  double posEta = 0.0;
77  double posPhi = 0.0;
78  double posRho = 1.0;
79  double w0_ = 4.2;
80  if (superClusterEnergy>0.0 && supercluster.recHitFractions().size()>0) {
81  const std::vector <reco::PFRecHitFraction >& pfhitsandfracs = supercluster.recHitFractions();
82  for (std::vector<reco::PFRecHitFraction>::const_iterator it = pfhitsandfracs.begin(); it != pfhitsandfracs.end(); ++it) {
83  const reco::PFRecHitRef rechit = it->recHitRef();
84  double hitEta = rechit->positionREP().Eta();
85  double hitPhi = rechit->positionREP().Phi();
86  while (hitPhi > +Geom::pi()) { hitPhi -= Geom::twoPi(); }
87  while (hitPhi < -Geom::pi()) { hitPhi += Geom::twoPi(); }
88  double hitRho = rechit->positionREP().Rho();
89  double hitEnergy = rechit->energy();
90  const double w = std::max(0.0, w0_ + log(hitEnergy / superClusterEnergy));
91  denominator += w;
92  numeratorEta += w*hitEta;
93  numeratorPhi += w*hitPhi;
94  numeratorRho += w*hitRho;
95  }
96  posEta = numeratorEta/denominator;
97  posPhi = numeratorPhi/denominator;
98  posRho = numeratorRho/denominator;
99  }
100 
101  PFCluster::REPPoint posEtaPhiRho(posRho,posEta,posPhi);
102 
103  math::XYZPoint superClusterPosition(posEtaPhiRho.X(),posEtaPhiRho.Y(),posEtaPhiRho.Z());
104 
105  supercluster.setPosition( superClusterPosition );
106  supercluster.calculatePositionREP();
107 
108  return;
109 }
110 
void setLayer(PFLayer::Layer layer)
set layer
Definition: PFCluster.cc:74
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:73
void setColor(int color)
set cluster color (for the PFRootEventManager display)
Definition: PFCluster.h:90
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:137
ROOT::Math::PositionVector3D< ROOT::Math::CylindricalEta3D< Double32_t > > REPPoint
Definition: PFCluster.h:46
void setPosition(const math::XYZPoint &p)
Definition: CaloCluster.h:111
Particle flow cluster, see clustering algorithm in PFSuperClusterAlgo.
Fraction of a PFRecHit (rechits can be shared between several PFCluster&#39;s)
void setEnergy(double energy)
Definition: CaloCluster.h:109
tuple particleFlow
Definition: pfLinker_cff.py:5
void setSeed(const DetId &id)
Definition: CaloCluster.h:117
void setCaloId(const CaloID &id)
Definition: CaloCluster.h:113
list denominator
Definition: cuy.py:484
const T & max(const T &a, const T &b)
void calculatePositionREP()
computes posrep_ once and for all
Definition: PFCluster.h:79
Layer
layer definition
Definition: PFLayer.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
void setAlgoId(const AlgoId &id)
Definition: CaloCluster.h:115
void addRecHitFraction(const reco::PFRecHitFraction &frac)
add a given fraction of the rechit
Definition: PFCluster.cc:40
double pi()
Definition: Pi.h:31
double twoPi()
Definition: Pi.h:32
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
Definition: PFCluster.h:63
T w() const