CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes

PFECALSuperClusterAlgo Class Reference

#include <PFECALSuperClusterAlgo.h>

List of all members.

Classes

class  CalibratedPFCluster

Public Types

typedef std::shared_ptr
< CalibratedPFCluster
CalibratedClusterPtr
typedef std::vector
< CalibratedClusterPtr
CalibratedClusterPtrVector
enum  clustering_type { kBOX = 1, kMustache = 2 }

Public Member Functions

std::auto_ptr
< reco::SuperClusterCollection
getEBOutputSCCollection ()
std::auto_ptr
< reco::SuperClusterCollection
getEEOutputSCCollection ()
void loadAndSortPFClusters (const edm::View< reco::PFCluster > &ecalclusters, const edm::View< reco::PFCluster > &psclusters)
 PFECALSuperClusterAlgo ()
 constructor
void run ()
void setClusteringType (clustering_type thetype)
void setCrackCorrections (bool applyCrackCorrections)
void setEtawidthSuperClusterBarrel (double etawidth)
void setEtawidthSuperClusterEndcap (double etawidth)
void setMajorityFraction (const double f)
void setPFClusterCalibration (const std::shared_ptr< PFEnergyCalibration > &)
void setPhiwidthSuperClusterBarrel (double phiwidth)
void setPhiwidthSuperClusterEndcap (double phiwidth)
void setSatelliteMerging (const bool doit)
void setSatelliteThreshold (const double t)
void setThreshPFClusterBarrel (double thresh)
void setThreshPFClusterEndcap (double thresh)
void setThreshPFClusterES (double thresh)
void setThreshPFClusterSeedBarrel (double thresh)
void setThreshPFClusterSeedEndcap (double thresh)
void setUseDynamicDPhi (bool useit)
void setUsePS (bool useit)
void setVerbosityLevel (bool verbose)

Private Member Functions

void buildAllSuperClusters (CalibratedClusterPtrVector &, double seedthresh)
void buildSuperCluster (CalibratedClusterPtr &, CalibratedClusterPtrVector &)

Private Attributes

CalibratedClusterPtrVector _clustersEB
CalibratedClusterPtrVector _clustersEE
clustering_type _clustype
std::shared_ptr
< PFEnergyCalibration
_pfEnergyCalibration
std::unordered_map< edm::Ptr
< reco::PFCluster >
, edm::PtrVector
< reco::PFCluster > > 
_psclustersforee
bool _useDynamicDPhi
bool applyCrackCorrections_
bool doSatelliteClusterMerge_
double etawidthSuperCluster_
double etawidthSuperClusterBarrel_
double etawidthSuperClusterEndcap_
double fractionForMajority_
double phiwidthSuperCluster_
double phiwidthSuperClusterBarrel_
double phiwidthSuperClusterEndcap_
double satelliteThreshold_
std::auto_ptr
< reco::SuperClusterCollection
superClustersEB_
std::auto_ptr
< reco::SuperClusterCollection
superClustersEE_
double threshPFCluster_
double threshPFClusterBarrel_
double threshPFClusterEndcap_
double threshPFClusterES_
double threshPFClusterSeed_
double threshPFClusterSeedBarrel_
double threshPFClusterSeedEndcap_
bool usePS
bool verbose_

Detailed Description

Definition at line 47 of file PFECALSuperClusterAlgo.h.


Member Typedef Documentation

Definition at line 70 of file PFECALSuperClusterAlgo.h.

Definition at line 71 of file PFECALSuperClusterAlgo.h.


Member Enumeration Documentation

Enumerator:
kBOX 
kMustache 

Definition at line 49 of file PFECALSuperClusterAlgo.h.

{kBOX=1, kMustache=2};

Constructor & Destructor Documentation

PFECALSuperClusterAlgo::PFECALSuperClusterAlgo ( )

constructor

Definition at line 172 of file PFECALSuperClusterAlgo.cc.

{ }

Member Function Documentation

void PFECALSuperClusterAlgo::buildAllSuperClusters ( CalibratedClusterPtrVector ,
double  seedthresh 
) [private]

Definition at line 259 of file PFECALSuperClusterAlgo.cc.

                                         {
  IsASeed seedable(seedthresh);
  // make sure only seeds appear at the front of the list of clusters
  std::stable_partition(clusters.begin(),clusters.end(),seedable);
  // in each iteration we are working on a list that is already sorted
  // in the cluster energy and remains so through each iteration
  // NB: since clusters is sorted in loadClusters any_of has O(1)
  //     timing until you run out of seeds!  
  while( std::any_of(clusters.cbegin(), clusters.cend(), seedable) ) {    
    buildSuperCluster(clusters.front(),clusters);
  }
}
void PFECALSuperClusterAlgo::buildSuperCluster ( CalibratedClusterPtr ,
CalibratedClusterPtrVector  
) [private]

Definition at line 274 of file PFECALSuperClusterAlgo.cc.

References reco::SuperCluster::addCluster(), reco::CaloCluster::addHitAndFraction(), reco::SuperCluster::addPreshowerCluster(), PFLayer::ECAL_BARREL, PFLayer::ECAL_ENDCAP, Exception, spr::find(), edm::Ptr< T >::get(), PFClusterWidthAlgo::pflowEtaWidth(), PFClusterWidthAlgo::pflowPhiWidth(), reco::SuperCluster::preshowerClustersBegin(), reco::SuperCluster::preshowerClustersEnd(), PFLayer::PS1, PFLayer::PS2, reco::SuperCluster::rawEnergy(), reco::SuperCluster::setEtaWidth(), reco::SuperCluster::setPhiWidth(), reco::SuperCluster::setPreshowerEnergy(), reco::SuperCluster::setPreshowerEnergyPlane1(), reco::SuperCluster::setPreshowerEnergyPlane2(), and reco::SuperCluster::setSeed().

                                                   {
  IsClustered IsClusteredWithSeed(seed,_clustype,_useDynamicDPhi);
  IsLinkedByRecHit MatchesSeedByRecHit(seed,satelliteThreshold_,
                                       fractionForMajority_,0.1,0.2);
  bool isEE = false;
  SumPSEnergy sumps1(PFLayer::PS1), sumps2(PFLayer::PS2);  
  switch( seed->the_ptr()->layer() ) {
  case PFLayer::ECAL_BARREL:
    IsClusteredWithSeed.phiwidthSuperCluster_ = phiwidthSuperClusterBarrel_;
    IsClusteredWithSeed.etawidthSuperCluster_ = etawidthSuperClusterBarrel_;
    edm::LogInfo("PFClustering") << "Building SC number "  
                                 << superClustersEB_->size() + 1
                                 << " in the ECAL barrel!";
    break;
  case PFLayer::ECAL_ENDCAP:    
    IsClusteredWithSeed.phiwidthSuperCluster_ = phiwidthSuperClusterEndcap_; 
    IsClusteredWithSeed.etawidthSuperCluster_ = etawidthSuperClusterEndcap_;
    edm::LogInfo("PFClustering") << "Building SC number "  
                                 << superClustersEE_->size() + 1
                                 << " in the ECAL endcap!" << std::endl;
    isEE = true;
    break;
  default:
    break;
  }
  
  // this function shuffles the list of clusters into a list
  // where all clustered sub-clusters are at the front 
  // and returns a pointer to the first unclustered cluster.
  // The relative ordering of clusters is preserved 
  // (i.e. both resulting sub-lists are sorted by energy).
  auto not_clustered = std::stable_partition(clusters.begin(),clusters.end(),
                                             IsClusteredWithSeed);
  // satellite cluster merging
  // it was found that large clusters can split!
  if( doSatelliteClusterMerge_ ) {    
    not_clustered = std::stable_partition(not_clustered,clusters.end(),
                                          MatchesSeedByRecHit);
  }

  if(verbose_) {
    edm::LogInfo("PFClustering") << "Dumping cluster detail";
    edm::LogVerbatim("PFClustering")
      << "\tPassed seed: e = " << seed->energy_nocalib() 
      << " eta = " << seed->eta() << " phi = " << seed->phi() 
      << std::endl;  
    for( auto clus = clusters.cbegin(); clus != not_clustered; ++clus ) {
      edm::LogVerbatim("PFClustering") 
        << "\t\tClustered cluster: e = " << (*clus)->energy_nocalib() 
        << " eta = " << (*clus)->eta() << " phi = " << (*clus)->phi() 
        << std::endl;
    }
    for( auto clus = not_clustered; clus != clusters.end(); ++clus ) {
      edm::LogVerbatim("PFClustering") 
        << "\tNon-Clustered cluster: e = " << (*clus)->energy_nocalib() 
        << " eta = " << (*clus)->eta() << " phi = " << (*clus)->phi() 
        << std::endl;
    }    
  }
  // move the clustered clusters out of available cluster list
  // and into a temporary vector for building the SC  
  CalibratedClusterPtrVector clustered(clusters.begin(),not_clustered);
  clusters.erase(clusters.begin(),not_clustered);    
  // need the vector of raw pointers for a PF width class
  std::vector<const reco::PFCluster*> bare_ptrs;
  // calculate necessary parameters and build the SC
  double posX(0), posY(0), posZ(0),
    rawSCEnergy(0), corrSCEnergy(0), clusterCorrEE(0), 
    PS1_clus_sum(0), PS2_clus_sum(0);  
  for( auto& clus : clustered ) {
    bare_ptrs.push_back(clus->the_ptr().get());
      
    const double cluseraw = clus->energy_nocalib();
    const math::XYZPoint& cluspos = clus->the_ptr()->position();
    posX += cluseraw * cluspos.X();
    posY += cluseraw * cluspos.Y();
    posZ += cluseraw * cluspos.Z();
    // update EE calibrated super cluster energies
    if( isEE ) {
      const auto& psclusters = _psclustersforee[clus->the_ptr()];
      PS1_clus_sum = std::accumulate(psclusters.begin(),psclusters.end(),
                                     0.0,sumps1);
      PS2_clus_sum = std::accumulate(psclusters.begin(),psclusters.end(),
                                     0.0,sumps2);
      clusterCorrEE = 
        _pfEnergyCalibration->energyEm(*(clus->the_ptr()),
                                       PS1_clus_sum,PS2_clus_sum,
                                       applyCrackCorrections_);
      clus->resetCalibratedEnergy(clusterCorrEE);
    }

    rawSCEnergy  += cluseraw;
    corrSCEnergy += clus->energy();    
  }
  posX /= rawSCEnergy;
  posY /= rawSCEnergy;
  posZ /= rawSCEnergy;    
  
  // now build the supercluster
  reco::SuperCluster new_sc(corrSCEnergy,math::XYZPoint(posX,posY,posZ)); 
  double ps1_energy(0.0), ps2_energy(0.0), ps_energy(0.0);
  new_sc.setSeed(clustered.front()->the_ptr());
  for( const auto& clus : clustered ) {
    new_sc.addCluster(clus->the_ptr());
    auto& hits_and_fractions = clus->the_ptr()->hitsAndFractions();
    for( auto& hit_and_fraction : hits_and_fractions ) {
      new_sc.addHitAndFraction(hit_and_fraction.first,hit_and_fraction.second);
    }
    const auto& cluspsassociation = _psclustersforee[clus->the_ptr()];     
    // EE rechits should be uniquely matched to sets of pre-shower
    // clusters at this point, so we throw an exception if otherwise
    for( const auto& psclus : cluspsassociation ) {
      auto found_pscluster = std::find(new_sc.preshowerClustersBegin(),
                                       new_sc.preshowerClustersEnd(),
                                       reco::CaloClusterPtr(psclus));
      if( found_pscluster == new_sc.preshowerClustersEnd() ) {
        const double psenergy = psclus->energy();
        new_sc.addPreshowerCluster(psclus);
        ps1_energy += (PFLayer::PS1 == psclus->layer())*psenergy;
        ps2_energy += (PFLayer::PS2 == psclus->layer())*psenergy;
        ps_energy  += psenergy;
      } else {
        throw cms::Exception("PFECALSuperClusterAlgo::buildSuperCluster")
          << "Found a PS cluster matched to more than one EE cluster!" 
          << std::endl << std::hex << psclus.get() << " == " 
          << found_pscluster->get() << std::dec << std::endl;
      }
    }
  }
  new_sc.setPreshowerEnergy(ps_energy); 
  new_sc.setPreshowerEnergyPlane1(ps1_energy);
  new_sc.setPreshowerEnergyPlane2(ps2_energy);
  
  // calculate linearly weighted cluster widths
  PFClusterWidthAlgo pfwidth(bare_ptrs);
  new_sc.setEtaWidth(pfwidth.pflowEtaWidth());
  new_sc.setPhiWidth(pfwidth.pflowPhiWidth());
  
  // cache the value of the raw energy  
  new_sc.rawEnergy();

  // save the super cluster to the appropriate list
  switch( seed->the_ptr()->layer() ) {
  case PFLayer::ECAL_BARREL:
    superClustersEB_->push_back(new_sc);
    break;
  case PFLayer::ECAL_ENDCAP:    
    superClustersEE_->push_back(new_sc);
    break;
  default:
    break;
  }
}
std::auto_ptr<reco::SuperClusterCollection> PFECALSuperClusterAlgo::getEBOutputSCCollection ( ) [inline]

Definition at line 107 of file PFECALSuperClusterAlgo.h.

References superClustersEB_.

{ return superClustersEB_; }
std::auto_ptr<reco::SuperClusterCollection> PFECALSuperClusterAlgo::getEEOutputSCCollection ( ) [inline]

Definition at line 109 of file PFECALSuperClusterAlgo.h.

References superClustersEE_.

{ return superClustersEE_; }  
void PFECALSuperClusterAlgo::loadAndSortPFClusters ( const edm::View< reco::PFCluster > &  ecalclusters,
const edm::View< reco::PFCluster > &  psclusters 
)

Definition at line 180 of file PFECALSuperClusterAlgo.cc.

References PFLayer::ECAL_BARREL, PFLayer::ECAL_ENDCAP, edm::Ptr< T >::isNonnull(), LogDebug, PFLayer::PS1, PFLayer::PS2, and python::multivaluedict::sort().

                                                       { 
  // reset the system for running
  superClustersEB_.reset(new reco::SuperClusterCollection);
  _clustersEB.clear();
  superClustersEE_.reset(new reco::SuperClusterCollection);  
  _clustersEE.clear();
  _psclustersforee.clear();
  
  auto clusterPtrs = clusters.ptrVector(); 
  //Select PF clusters available for the clustering
  for ( auto& cluster : clusterPtrs ){
    LogDebug("PFClustering") 
      << "Loading PFCluster i="<<cluster.key()
      <<" energy="<<cluster->energy()<<std::endl;
    
    double Ecorr = _pfEnergyCalibration->energyEm(*cluster,
                                                  0.0,0.0,
                                                  applyCrackCorrections_);
    CalibratedClusterPtr calib_cluster(new CalibratedPFCluster(cluster,Ecorr));
    switch( cluster->layer() ) {
    case PFLayer::ECAL_BARREL:
      if( calib_cluster->energy() > threshPFClusterBarrel_ ) {
        _clustersEB.push_back(calib_cluster);   
      }
      break;
    case PFLayer::ECAL_ENDCAP:
      if( calib_cluster->energy() > threshPFClusterEndcap_ ) {
        _clustersEE.push_back(calib_cluster);
        _psclustersforee.emplace(calib_cluster->the_ptr(),
                                 edm::PtrVector<reco::PFCluster>());
      }
      break;
    default:
      break;
    }
  }
  // make the association map of ECAL clusters to preshower clusters  
  edm::PtrVector<reco::PFCluster> clusterPtrsPS = psclusters.ptrVector();
  double dist = -1.0, min_dist = -1.0;
  // match PS clusters to EE clusters, minimum distance to EE is ensured
  // since the inner loop is over the EE clusters
  for( const auto& psclus : clusterPtrsPS ) {   
    if( psclus->energy() < threshPFClusterES_ ) continue;        
    switch( psclus->layer() ) { // just in case this isn't the ES...
    case PFLayer::PS1:
    case PFLayer::PS2:
      break;
    default:
      continue;
    }    
    edm::Ptr<reco::PFCluster> eematch;
    dist = min_dist = -1.0; // reset
    for( const auto& eeclus : _clustersEE ) {
      dist = testPreshowerDistance(eeclus->the_ptr(),psclus);      
      if( dist == -1.0 || (min_dist != -1.0 && dist > min_dist) ) continue;
      if( dist < min_dist || min_dist == -1.0 ) {
        eematch = eeclus->the_ptr();
        min_dist = dist;
      }
    } // loop on EE clusters      
    if( eematch.isNonnull() ) _psclustersforee[eematch].push_back(psclus);
  } // loop on PS clusters

  // sort full cluster collections by their calibrated energy
  // this will put all the seeds first by construction
  GreaterByEt greater;
  std::sort(_clustersEB.begin(), _clustersEB.end(), greater);
  std::sort(_clustersEE.begin(), _clustersEE.end(), greater);  
}
void PFECALSuperClusterAlgo::run ( void  )
void PFECALSuperClusterAlgo::setClusteringType ( clustering_type  thetype) [inline]

Definition at line 79 of file PFECALSuperClusterAlgo.h.

References _clustype.

{ _clustype = thetype; } 
void PFECALSuperClusterAlgo::setCrackCorrections ( bool  applyCrackCorrections) [inline]

Definition at line 104 of file PFECALSuperClusterAlgo.h.

References applyCrackCorrections_.

{ applyCrackCorrections_ = applyCrackCorrections;}
void PFECALSuperClusterAlgo::setEtawidthSuperClusterBarrel ( double  etawidth) [inline]

Definition at line 89 of file PFECALSuperClusterAlgo.h.

References etawidthSuperClusterBarrel_.

void PFECALSuperClusterAlgo::setEtawidthSuperClusterEndcap ( double  etawidth) [inline]

Definition at line 91 of file PFECALSuperClusterAlgo.h.

References etawidthSuperClusterEndcap_.

void PFECALSuperClusterAlgo::setMajorityFraction ( const double  f) [inline]

Definition at line 100 of file PFECALSuperClusterAlgo.h.

References f, and fractionForMajority_.

void PFECALSuperClusterAlgo::setPFClusterCalibration ( const std::shared_ptr< PFEnergyCalibration > &  calib)

Definition at line 175 of file PFECALSuperClusterAlgo.cc.

References calib.

void PFECALSuperClusterAlgo::setPhiwidthSuperClusterBarrel ( double  phiwidth) [inline]

Definition at line 88 of file PFECALSuperClusterAlgo.h.

References phiwidthSuperClusterBarrel_.

void PFECALSuperClusterAlgo::setPhiwidthSuperClusterEndcap ( double  phiwidth) [inline]

Definition at line 90 of file PFECALSuperClusterAlgo.h.

References phiwidthSuperClusterEndcap_.

void PFECALSuperClusterAlgo::setSatelliteMerging ( const bool  doit) [inline]

Definition at line 98 of file PFECALSuperClusterAlgo.h.

References doSatelliteClusterMerge_.

void PFECALSuperClusterAlgo::setSatelliteThreshold ( const double  t) [inline]

Definition at line 99 of file PFECALSuperClusterAlgo.h.

References satelliteThreshold_, and lumiQTWidget::t.

void PFECALSuperClusterAlgo::setThreshPFClusterBarrel ( double  thresh) [inline]
void PFECALSuperClusterAlgo::setThreshPFClusterEndcap ( double  thresh) [inline]
void PFECALSuperClusterAlgo::setThreshPFClusterES ( double  thresh) [inline]
void PFECALSuperClusterAlgo::setThreshPFClusterSeedBarrel ( double  thresh) [inline]
void PFECALSuperClusterAlgo::setThreshPFClusterSeedEndcap ( double  thresh) [inline]
void PFECALSuperClusterAlgo::setUseDynamicDPhi ( bool  useit) [inline]

Definition at line 81 of file PFECALSuperClusterAlgo.h.

References _useDynamicDPhi.

{ _useDynamicDPhi = useit; } 
void PFECALSuperClusterAlgo::setUsePS ( bool  useit) [inline]

Definition at line 92 of file PFECALSuperClusterAlgo.h.

References usePS.

{ usePS = useit; }
void PFECALSuperClusterAlgo::setVerbosityLevel ( bool  verbose) [inline]

Member Data Documentation

Definition at line 118 of file PFECALSuperClusterAlgo.h.

Definition at line 119 of file PFECALSuperClusterAlgo.h.

Definition at line 125 of file PFECALSuperClusterAlgo.h.

Referenced by setClusteringType().

Definition at line 124 of file PFECALSuperClusterAlgo.h.

Definition at line 121 of file PFECALSuperClusterAlgo.h.

Definition at line 152 of file PFECALSuperClusterAlgo.h.

Referenced by setUseDynamicDPhi().

Definition at line 154 of file PFECALSuperClusterAlgo.h.

Referenced by setCrackCorrections().

Definition at line 149 of file PFECALSuperClusterAlgo.h.

Referenced by setSatelliteMerging().

Definition at line 135 of file PFECALSuperClusterAlgo.h.

Definition at line 145 of file PFECALSuperClusterAlgo.h.

Referenced by setEtawidthSuperClusterBarrel().

Definition at line 147 of file PFECALSuperClusterAlgo.h.

Referenced by setEtawidthSuperClusterEndcap().

Definition at line 150 of file PFECALSuperClusterAlgo.h.

Referenced by setMajorityFraction().

Definition at line 136 of file PFECALSuperClusterAlgo.h.

Definition at line 144 of file PFECALSuperClusterAlgo.h.

Referenced by setPhiwidthSuperClusterBarrel().

Definition at line 146 of file PFECALSuperClusterAlgo.h.

Referenced by setPhiwidthSuperClusterEndcap().

Definition at line 150 of file PFECALSuperClusterAlgo.h.

Referenced by setSatelliteThreshold().

Definition at line 122 of file PFECALSuperClusterAlgo.h.

Referenced by getEBOutputSCCollection().

Definition at line 123 of file PFECALSuperClusterAlgo.h.

Referenced by getEEOutputSCCollection().

Definition at line 134 of file PFECALSuperClusterAlgo.h.

Definition at line 139 of file PFECALSuperClusterAlgo.h.

Referenced by setThreshPFClusterBarrel().

Definition at line 141 of file PFECALSuperClusterAlgo.h.

Referenced by setThreshPFClusterEndcap().

Definition at line 142 of file PFECALSuperClusterAlgo.h.

Referenced by setThreshPFClusterES().

Definition at line 133 of file PFECALSuperClusterAlgo.h.

Definition at line 138 of file PFECALSuperClusterAlgo.h.

Referenced by setThreshPFClusterSeedBarrel().

Definition at line 140 of file PFECALSuperClusterAlgo.h.

Referenced by setThreshPFClusterSeedEndcap().

Definition at line 156 of file PFECALSuperClusterAlgo.h.

Referenced by setUsePS().

Definition at line 131 of file PFECALSuperClusterAlgo.h.

Referenced by setVerbosityLevel().