CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/RecoHI/HiEgammaAlgos/src/HiBremRecoveryClusterAlgo.cc

Go to the documentation of this file.
00001 #include "RecoHI/HiEgammaAlgos/interface/HiBremRecoveryClusterAlgo.h"
00002 #include "DataFormats/Math/interface/Vector3D.h"
00003 #include "DataFormats/CaloRecHit/interface/CaloCluster.h"
00004 
00005 reco::SuperClusterCollection HiBremRecoveryClusterAlgo::makeSuperClusters(reco::CaloClusterPtrVector & clustersCollection)
00006 {
00007   const float etaBorder = 1.479;
00008 
00009   superclusters_v.clear();
00010 
00011   // create vectors of references to clusters of a specific origin...
00012   reco::CaloClusterPtrVector islandClustersBarrel_v;
00013   reco::CaloClusterPtrVector islandClustersEndCap_v;
00014 
00015   // ...and populate them:
00016   for (reco::CaloCluster_iterator it = clustersCollection.begin(); it != clustersCollection.end(); it++)
00017   {
00018     
00019      reco::CaloClusterPtr cluster_p = *it;
00020      if (cluster_p->algo() == reco::CaloCluster::island) 
00021      {
00022         if (verbosity <= pINFO)
00023         {
00024            std::cout <<"Basic Cluster: (eta,phi,energy) = "<<cluster_p->position().eta()<<" "<<cluster_p->position().phi()<<" "
00025                                                           <<cluster_p->energy()<<std::endl;
00026         }
00027 
00028         // if the basic cluster pass the energy threshold -> fill it into the list
00029         if (fabs(cluster_p->position().eta()) < etaBorder)
00030         {
00031            if (cluster_p->energy() > BarrelBremEnergyThreshold) islandClustersBarrel_v.push_back(cluster_p);
00032         } else {
00033            if (cluster_p->energy() > EndcapBremEnergyThreshold) islandClustersEndCap_v.push_back(cluster_p);
00034         }
00035      }
00036   }
00037 
00038   // make the superclusters from the Barrel clusters - Island
00039   makeIslandSuperClusters(islandClustersBarrel_v, eb_rdeta_, eb_rdphi_);
00040   
00041   // make the superclusters from the EndCap clusters - Island
00042   makeIslandSuperClusters(islandClustersEndCap_v, ec_rdeta_, ec_rdphi_);
00043 
00044   return superclusters_v;
00045 }
00046 
00047 void HiBremRecoveryClusterAlgo::makeIslandSuperClusters(reco::CaloClusterPtrVector &clusters_v, 
00048                                                       double etaRoad, double phiRoad)
00049 {
00050   // Vector of usedSeedEnergy, use the seed energy to check if this cluster is used.
00051   std::vector<double> usedSeedEnergy;
00052   usedSeedEnergy.clear();
00053 
00054   // Main brem recovery loop
00055   for ( reco::CaloCluster_iterator currentSeed = clusters_v.begin(); currentSeed != clusters_v.end(); ++currentSeed)
00056   {
00057      if (verbosity <= pINFO) {
00058         std::cout <<"Current Cluster: "<<(*currentSeed)->energy()<<" "<<(std::find(usedSeedEnergy.begin(), usedSeedEnergy.end(), (*currentSeed)->energy()) 
00059              != usedSeedEnergy.end())<<std::endl;
00060      }
00061 
00062      // check this seed was not already used
00063      if (std::find(usedSeedEnergy.begin(), usedSeedEnergy.end(), (*currentSeed)->energy()) 
00064              != usedSeedEnergy.end()) continue;
00065 
00066      // Does our highest energy cluster have high enough energy? If not, continue instead of break to be robust
00067      if ((*currentSeed)->energy() * sin((*currentSeed)->position().theta()) < seedTransverseEnergyThreshold) continue;
00068 
00069      // if yes, make it a seed for a new SuperCluster, the position of the SC is calculated by energy weighted sum:
00070      double energy_ = (*currentSeed)->energy();
00071      math::XYZVector position_((*currentSeed)->position().X(), 
00072                                (*currentSeed)->position().Y(), 
00073                                (*currentSeed)->position().Z());
00074      position_ *= energy_;
00075      usedSeedEnergy.push_back((*currentSeed)->energy());
00076 
00077      // Printout if verbose
00078      if (verbosity <= pINFO)
00079      {
00080        std::cout << "*****************************" << std::endl;
00081        std::cout << "******NEW SUPERCLUSTER*******" << std::endl;
00082        std::cout << "Seed R = " << (*currentSeed)->position().Rho() << std::endl;
00083        std::cout << "Seed Et = " << (*currentSeed)->energy()* sin((*currentSeed)->position().theta()) << std::endl;
00084      }
00085 
00086      // and add the matching clusters:
00087      reco::CaloClusterPtrVector constituentClusters;
00088      constituentClusters.push_back( *currentSeed );
00089      reco::CaloCluster_iterator currentCluster = currentSeed + 1;
00090 
00091      // loop over the clusters
00092      while (currentCluster != clusters_v.end())
00093      {
00094         // Print out the basic clusters
00095         if (verbosity <= pINFO) {
00096            std::cout <<"->Cluster: "<<(*currentCluster)->energy()
00097                      <<" Used = "<<(std::find(usedSeedEnergy.begin(), usedSeedEnergy.end(), (*currentCluster)->energy()) != usedSeedEnergy.end())
00098                      <<" Matched = "<<match(*currentSeed, *currentCluster, etaRoad, phiRoad)<<std::endl;
00099         }
00100 
00101         // if it's in the search window, and unused
00102         if (match(*currentSeed, *currentCluster, etaRoad, phiRoad)
00103             && (std::find(usedSeedEnergy.begin(), usedSeedEnergy.end(), (*currentCluster)->energy()) == usedSeedEnergy.end()))
00104         {
00105            // Add basic cluster
00106            constituentClusters.push_back(*currentCluster);
00107            energy_   += (*currentCluster)->energy();
00108            position_ += (*currentCluster)->energy() * math::XYZVector((*currentCluster)->position().X(), 
00109                                                                       (*currentCluster)->position().Y(), 
00110                                                                       (*currentCluster)->position().Z()); 
00111            // Add the cluster to the used list
00112            usedSeedEnergy.push_back((*currentCluster)->energy());
00113 
00114            if (verbosity <= pINFO) 
00115            {
00116               std::cout << "Cluster R = " << (*currentCluster)->position().Rho() << std::endl;
00117            }
00118 
00119         }
00120         ++currentCluster;
00121      }
00122 
00123      // Calculate the final position
00124      position_ /= energy_;
00125 
00126      if (verbosity <= pINFO)
00127      {
00128        std::cout << "Final SuperCluster R = " << position_.Rho() << std::endl;
00129      }
00130 
00131      // Add the supercluster to the new collection
00132      reco::SuperCluster newSuperCluster(energy_, 
00133                                         math::XYZPoint(position_.X(), position_.Y(), position_.Z()), 
00134                                         (*currentSeed), 
00135                                         constituentClusters);
00136 
00137      superclusters_v.push_back(newSuperCluster);
00138 
00139      if (verbosity <= pINFO)
00140        {
00141          std::cout << "created a new supercluster of: " << std::endl;
00142          std::cout << "Energy = " << newSuperCluster.energy() << std::endl;
00143          std::cout << "Position in (R, phi, theta, eta) = (" 
00144                    << newSuperCluster.position().Rho() << ", " 
00145                    << newSuperCluster.position().phi() << ", "
00146                    << newSuperCluster.position().theta() << ", "
00147                    << newSuperCluster.position().eta() << ")" << std::endl;
00148        }
00149   }
00150   clusters_v.clear();
00151   usedSeedEnergy.clear();
00152 }
00153 
00154 
00155 bool HiBremRecoveryClusterAlgo::match(reco::CaloClusterPtr seed_p, 
00156                                     reco::CaloClusterPtr cluster_p,
00157                                     double dEtaMax, double dPhiMax)
00158 {
00159   math::XYZPoint clusterPosition = cluster_p->position();
00160   math::XYZPoint seedPosition = seed_p->position();
00161 
00162   double dPhi = acos(cos(seedPosition.phi() - clusterPosition.phi()));
00163  
00164   double dEta = fabs(seedPosition.eta() - clusterPosition.eta());
00165   if (verbosity <= pINFO) {
00166      std::cout <<"seed phi: "<<seedPosition.phi()<<" cluster phi: "<<clusterPosition.phi()<<" dphi = "<<dPhi<<" dphiMax = "<<dPhiMax<<std::endl;
00167      std::cout <<"seed eta: "<<seedPosition.eta()<<" cluster eta: "<<clusterPosition.eta()<<" deta = "<<dEta<<" detaMax = "<<dEtaMax<<std::endl;
00168   }
00169   if (dEta > dEtaMax) return false;
00170   if (dPhi > dPhiMax) return false;
00171 
00172   return true;
00173 }