CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoParticleFlow/PFClusterProducer/src/PFHcalSuperClusterInit.cc

Go to the documentation of this file.
00001 #include "RecoParticleFlow/PFClusterProducer/interface/PFHcalSuperClusterInit.h"
00002 #include "DataFormats/GeometryVector/interface/Pi.h"
00003 #include "DataFormats/Common/interface/PtrVector.h"
00004 #include "DataFormats/ParticleFlowReco/interface/PFSuperCluster.h"
00005 #include "RecoParticleFlow/PFClusterProducer/interface/PFHcalSuperClusterAlgo.h"
00006 
00007 using namespace std;
00008 using namespace reco;
00009 
00010 void PFHcalSuperClusterInit::initialize( PFSuperCluster & supercluster,  edm::PtrVector<reco::PFCluster> const & clusters){
00011   
00012 //  std::vector< unsigned>  recHitDetId;
00013   std::vector< double>  recHitEnergy;
00014   std::vector< PFRecHitRef>  recHitRef;
00015   double superClusterEnergy = 0.0;
00016 //  unsigned maxHitDetId = 0;
00017   double maxHitEnergy = 0.0;
00018   CaloID maxClusterCaloId;
00019   PFLayer::Layer maxClusterLayer=PFLayer::HCAL_BARREL1;
00020   double maxClusterEnergy = 0.0;
00021   int maxClusterColor=2;
00022 //  cout << " Supercluster clusters: " << clusters.size() <<endl;
00023   for (unsigned short ic=0; ic<clusters.size();++ic) {
00024 //    const std::vector< std::pair<DetId, float> > & hitsandfracs =
00025 //          clusters[ic].hitsAndFractions();
00026     const std::vector< reco::PFRecHitFraction >& pfhitsandfracs = clusters[ic]->recHitFractions();
00027     double clusterEnergy = clusters[ic]->energy();
00028     superClusterEnergy+=clusterEnergy;
00029     if (clusterEnergy>=maxClusterEnergy) {
00030       maxClusterLayer=clusters[ic]->layer();
00031       maxClusterColor=clusters[ic]->color();
00032       maxClusterCaloId=clusters[ic]->caloID();
00033       maxClusterEnergy=clusterEnergy;
00034     }
00035     for (unsigned ihandf=0; ihandf<pfhitsandfracs.size(); ihandf++) {
00036 //      unsigned hitDetId = pfhitsandfracs[ihandf].recHitRef()->detId();
00037       double hitEnergy = pfhitsandfracs[ihandf].fraction()*clusterEnergy;
00038 //      recHitDetId.push_back(hitDetId);
00039       recHitEnergy.push_back(hitEnergy);
00040       recHitRef.push_back(pfhitsandfracs[ihandf].recHitRef());
00041       if(hitEnergy>=maxHitEnergy) {
00042 //        maxHitDetId=hitDetId;
00043         maxHitEnergy=hitEnergy;
00044       }
00045     }
00046 //    delete hitsandfracs;
00047   }
00048 
00049   for (unsigned short ir=0; ir<recHitEnergy.size();++ir) {
00050     double fraction=1.0;
00051     if( superClusterEnergy >0.0) {
00052       fraction  = recHitEnergy[ir]/superClusterEnergy;
00053     }
00054     reco::PFRecHitFraction frac(recHitRef[ir],fraction);
00055 
00056     supercluster.addRecHitFraction( frac ); 
00057 
00058 //    addHitAndFraction( recHitDetId[ir], fraction );
00059 //    cout << " Supercluster rechits detid/fraction: " << recHitDetId[ir] << " / " << fraction <<endl;
00060   }
00061 //  recHitDetId.clear();
00062   recHitEnergy.clear();
00063   recHitRef.clear();
00064 
00065   supercluster.setLayer( maxClusterLayer );
00066   supercluster.setEnergy( superClusterEnergy );
00067   supercluster.setCaloId( maxClusterCaloId );
00068   supercluster.setSeed( maxHitEnergy );
00069   supercluster.setAlgoId( CaloCluster::particleFlow );
00070   supercluster.setColor( maxClusterColor );
00071 
00072   double numeratorEta = 0.0;
00073   double numeratorPhi = 0.0;
00074   double numeratorRho = 0.0;
00075   double denominator = 0.0;
00076   double posEta = 0.0;
00077   double posPhi = 0.0;
00078   double posRho = 1.0;
00079   double w0_ = 4.2;
00080   if (superClusterEnergy>0.0 && supercluster.recHitFractions().size()>0) {
00081     const std::vector <reco::PFRecHitFraction >& pfhitsandfracs = supercluster.recHitFractions();
00082     for (std::vector<reco::PFRecHitFraction>::const_iterator it = pfhitsandfracs.begin(); it != pfhitsandfracs.end(); ++it) {
00083       const reco::PFRecHitRef rechit = it->recHitRef();
00084       double hitEta = rechit->positionREP().Eta();
00085       double hitPhi = rechit->positionREP().Phi();
00086       while (hitPhi > +Geom::pi()) { hitPhi -= Geom::twoPi(); }
00087       while (hitPhi < -Geom::pi()) { hitPhi += Geom::twoPi(); }
00088       double hitRho = rechit->positionREP().Rho();
00089       double hitEnergy = rechit->energy();
00090       const double w = std::max(0.0, w0_ + log(hitEnergy / superClusterEnergy));
00091       denominator += w;
00092       numeratorEta += w*hitEta;
00093       numeratorPhi += w*hitPhi;
00094       numeratorRho += w*hitRho;
00095     }
00096     posEta = numeratorEta/denominator;
00097     posPhi = numeratorPhi/denominator;
00098     posRho = numeratorRho/denominator;
00099   }
00100 
00101   PFCluster::REPPoint posEtaPhiRho(posRho,posEta,posPhi);
00102 
00103   math::XYZPoint superClusterPosition(posEtaPhiRho.X(),posEtaPhiRho.Y(),posEtaPhiRho.Z());
00104 
00105   supercluster.setPosition( superClusterPosition );
00106   supercluster.calculatePositionREP();
00107 
00108  return;
00109 }
00110