CMS 3D CMS Logo

Public Types | Public Member Functions | Protected Attributes

PileUpSubtractor Class Reference

#include <PileUpSubtractor.h>

Inheritance diagram for PileUpSubtractor:
JetOffsetCorrector MultipleAlgoIterator ParametrizedSubtractor

List of all members.

Public Types

typedef boost::shared_ptr
< fastjet::ActiveAreaSpec > 
ActiveAreaSpecPtr
typedef boost::shared_ptr
< fastjet::ClusterSequence > 
ClusterSequencePtr
typedef boost::shared_ptr
< fastjet::RangeDefinition > 
RangeDefPtr

Public Member Functions

virtual void calculateOrphanInput (std::vector< fastjet::PseudoJet > &orphanInput)
virtual void calculatePedestal (std::vector< fastjet::PseudoJet > const &coll)
virtual double getMeanAtTower (const reco::CandidatePtr &in) const
virtual double getPileUpAtTower (const reco::CandidatePtr &in) const
virtual double getPileUpEnergy (int ijet) const
virtual double getSigmaAtTower (const reco::CandidatePtr &in) const
int ieta (const reco::CandidatePtr &in) const
int iphi (const reco::CandidatePtr &in) const
virtual void offsetCorrectJets ()
 PileUpSubtractor (const edm::ParameterSet &iConfig)
virtual void reset (std::vector< edm::Ptr< reco::Candidate > > &input, std::vector< fastjet::PseudoJet > &towers, std::vector< fastjet::PseudoJet > &output)
virtual void setAlgorithm (ClusterSequencePtr &algorithm)
virtual void setupGeometryMap (edm::Event &iEvent, const edm::EventSetup &iSetup)
virtual void subtractPedestal (std::vector< fastjet::PseudoJet > &coll)
 ~PileUpSubtractor ()

Protected Attributes

std::vector< HcalDetIdallgeomid_
bool doAreaFastjet_
bool doRhoFastjet_
std::map< int, double > emean_
std::map< int, double > esigma_
ActiveAreaSpecPtr fjActiveArea_
ClusterSequencePtr fjClusterSeq_
std::vector< fastjet::PseudoJet > * fjInputs_
std::vector< fastjet::PseudoJet > * fjJets_
std::vector< fastjet::PseudoJet > fjOriginalInputs_
RangeDefPtr fjRangeDef_
CaloGeometry const * geo_
std::map< int, int > geomtowers_
int ietamax_
int ietamin_
std::vector< edm::Ptr
< reco::Candidate > > * 
inputs_
std::vector< double > jetOffset_
double jetPtMin_
double nSigmaPU_
std::map< int, int > ntowersWithJets_
double radiusPU_
bool reRunAlgo_

Detailed Description

Definition at line 19 of file PileUpSubtractor.h.


Member Typedef Documentation

typedef boost::shared_ptr<fastjet::ActiveAreaSpec> PileUpSubtractor::ActiveAreaSpecPtr

Definition at line 24 of file PileUpSubtractor.h.

typedef boost::shared_ptr<fastjet::ClusterSequence> PileUpSubtractor::ClusterSequencePtr

Definition at line 23 of file PileUpSubtractor.h.

typedef boost::shared_ptr<fastjet::RangeDefinition> PileUpSubtractor::RangeDefPtr

Definition at line 25 of file PileUpSubtractor.h.


Constructor & Destructor Documentation

PileUpSubtractor::PileUpSubtractor ( const edm::ParameterSet iConfig)

Definition at line 18 of file PileUpSubtractor.cc.

References doAreaFastjet_, doRhoFastjet_, fjActiveArea_, fjRangeDef_, and edm::ParameterSet::getParameter().

                                                                 :
  reRunAlgo_ (iConfig.getUntrackedParameter<bool>("reRunAlgo",false)),
  doAreaFastjet_ (iConfig.getParameter<bool>         ("doAreaFastjet")),
  doRhoFastjet_  (iConfig.getParameter<bool>         ("doRhoFastjet")),
  jetPtMin_(iConfig.getParameter<double>       ("jetPtMin")),
  nSigmaPU_(iConfig.getParameter<double>("nSigmaPU")),
  radiusPU_(iConfig.getParameter<double>("radiusPU")),
  geo_(0)
{
   if ( doAreaFastjet_ || doRhoFastjet_ ) {
      // default Ghost_EtaMax should be 5
      double ghostEtaMax = iConfig.getParameter<double>("Ghost_EtaMax");
      // default Active_Area_Repeats 1
      int    activeAreaRepeats = iConfig.getParameter<int> ("Active_Area_Repeats");
      // default GhostArea 0.01
      double ghostArea = iConfig.getParameter<double> ("GhostArea");
      fjActiveArea_ =  ActiveAreaSpecPtr(new fastjet::ActiveAreaSpec(ghostEtaMax,
                                                                     activeAreaRepeats,
                                                                     ghostArea));
      fjRangeDef_ = RangeDefPtr( new fastjet::RangeDefinition(ghostEtaMax) );
   } 
}
PileUpSubtractor::~PileUpSubtractor ( ) [inline]

Definition at line 28 of file PileUpSubtractor.h.

{;}

Member Function Documentation

void PileUpSubtractor::calculateOrphanInput ( std::vector< fastjet::PseudoJet > &  orphanInput) [virtual]

Reimplemented in ParametrizedSubtractor.

Definition at line 148 of file ParametrizedSubtractor.cc.

References fjInputs_.

{
   orphanInput = *fjInputs_;
}
void PileUpSubtractor::calculatePedestal ( std::vector< fastjet::PseudoJet > const &  coll) [virtual]

Reimplemented in MultipleAlgoIterator, and ParametrizedSubtractor.

Definition at line 112 of file MultipleAlgoIterator.cc.

References gt, i, LogDebug, nt, edm::second(), and mathSSE::sqrt().

{
   LogDebug("PileUpSubtractor")<<"The subtractor calculating pedestals...\n";

   map<int,double> emean2;
   map<int,int> ntowers;
    
   int ietaold = -10000;
   int ieta0 = -100;
   
   // Initial values for emean_, emean2, esigma_, ntowers

   for(int i = ietamin_; i < ietamax_+1; i++)
      {
         emean_[i] = 0.;
         emean2[i] = 0.;
         esigma_[i] = 0.;
         ntowers[i] = 0;
      }
    
   for (vector<fastjet::PseudoJet>::const_iterator input_object = coll.begin (),
           fjInputsEnd = coll.end();  
        input_object != fjInputsEnd; ++input_object) {

      const reco::CandidatePtr & originalTower=(*inputs_)[ input_object->user_index()];
      ieta0 = ieta( originalTower );
      double Original_Et = originalTower->et();
      if(sumRecHits_){
         Original_Et = getEt(originalTower);
      }

      if( ieta0-ietaold != 0 )
         {
            emean_[ieta0] = emean_[ieta0]+Original_Et;
            emean2[ieta0] = emean2[ieta0]+Original_Et*Original_Et;
            ntowers[ieta0] = 1;
            ietaold = ieta0;
         }
      else
         {
            emean_[ieta0] = emean_[ieta0]+Original_Et;
            emean2[ieta0] = emean2[ieta0]+Original_Et*Original_Et;
            ntowers[ieta0]++;
         }

   }

   for(map<int,int>::const_iterator gt = geomtowers_.begin(); gt != geomtowers_.end(); gt++)    
      {

         int it = (*gt).first;
       
         double e1 = (*(emean_.find(it))).second;
         double e2 = (*emean2.find(it)).second;
         int nt = (*gt).second - (*(ntowersWithJets_.find(it))).second;

         LogDebug("PileUpSubtractor")<<" ieta : "<<it<<" number of towers : "<<nt<<" e1 : "<<e1<<" e2 : "<<e2<<"\n";
        
         if(nt > 0) {
            emean_[it] = e1/nt;
            double eee = e2/nt - e1*e1/(nt*nt);    
            if(eee<0.) eee = 0.;
            esigma_[it] = nSigmaPU_*sqrt(eee);
         }
         else
            {
               emean_[it] = 0.;
               esigma_[it] = 0.;
            }
         LogDebug("PileUpSubtractor")<<" ieta : "<<it<<" Pedestals : "<<emean_[it]<<"  "<<esigma_[it]<<"\n";
      }
}
double PileUpSubtractor::getMeanAtTower ( const reco::CandidatePtr in) const [virtual]

Reimplemented in ParametrizedSubtractor.

Definition at line 324 of file PileUpSubtractor.cc.

References emean_, ieta(), and edm::second().

                                                                        {
  int it = ieta(in);
  return (*emean_.find(it)).second;
}
double PileUpSubtractor::getPileUpAtTower ( const reco::CandidatePtr in) const [virtual]

Reimplemented in ParametrizedSubtractor.

Definition at line 334 of file PileUpSubtractor.cc.

References emean_, esigma_, ieta(), and edm::second().

                                                                           {
  int it = ieta(in);
  return (*emean_.find(it)).second + (*esigma_.find(it)).second;
}
virtual double PileUpSubtractor::getPileUpEnergy ( int  ijet) const [inline, virtual]

Definition at line 42 of file PileUpSubtractor.h.

References jetOffset_.

{return jetOffset_[ijet];}
double PileUpSubtractor::getSigmaAtTower ( const reco::CandidatePtr in) const [virtual]

Reimplemented in ParametrizedSubtractor.

Definition at line 329 of file PileUpSubtractor.cc.

References esigma_, ieta(), and edm::second().

                                                                          {
   int it = ieta(in);
   return (*esigma_.find(it)).second;
}
int PileUpSubtractor::ieta ( const reco::CandidatePtr in) const
int PileUpSubtractor::iphi ( const reco::CandidatePtr in) const

Definition at line 351 of file PileUpSubtractor.cc.

References Exception, edm::Ptr< T >::get(), CaloTower::id(), and CaloTowerDetId::iphi().

                                                            {
  int it = 0;
  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
  if(ctc){
    it = ctc->id().iphi();
  } else
    {
      throw cms::Exception("Invalid Constituent") << "CaloJet constituent is not of CaloTower type";
    }
  return it;
}
void PileUpSubtractor::offsetCorrectJets ( ) [virtual]

Reimplemented in MultipleAlgoIterator, and ParametrizedSubtractor.

Definition at line 271 of file PileUpSubtractor.cc.

References emean_, esigma_, fjClusterSeq_, fjJets_, ieta(), jetOffset_, LogDebug, dt_dqm_sourceclient_common_cff::reco, and edm::second().

{

  LogDebug("PileUpSubtractor")<<"The subtractor correcting jets...\n";
  jetOffset_.clear();
  using namespace reco;
  
  //    
  // Reestimate energy of jet (energy of jet with initial map)
  //

  jetOffset_.reserve(fjJets_->size());
  
  vector<fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin (),
    jetsEnd = fjJets_->end();
  for (; pseudojetTMP != jetsEnd; ++pseudojetTMP) {
    
    int ijet = pseudojetTMP - fjJets_->begin();
    jetOffset_[ijet] = 0;
    
    std::vector<fastjet::PseudoJet> towers =
      sorted_by_pt(fjClusterSeq_->constituents(*pseudojetTMP));
    
    double newjetet = 0.;       
    for(vector<fastjet::PseudoJet>::const_iterator ito = towers.begin(),
          towEnd = towers.end(); 
        ito != towEnd; 
        ++ito)
      {
        const reco::CandidatePtr& originalTower = (*inputs_)[ito->user_index()];
        int it = ieta( originalTower );
        double Original_Et = originalTower->et();
        double etnew = Original_Et - (*emean_.find(it)).second - (*esigma_.find(it)).second; 
        if(etnew < 0.) etnew = 0;
        newjetet = newjetet + etnew;
        jetOffset_[ijet] += Original_Et - etnew;
      }
    
    double mScale = newjetet/pseudojetTMP->Et();
    LogDebug("PileUpSubtractor")<<"pseudojetTMP->Et() : "<<pseudojetTMP->Et()<<"\n";
    LogDebug("PileUpSubtractor")<<"newjetet : "<<newjetet<<"\n";
    LogDebug("PileUpSubtractor")<<"jetOffset_[ijet] : "<<jetOffset_[ijet]<<"\n";
    LogDebug("PileUpSubtractor")<<"pseudojetTMP->Et() - jetOffset_[ijet] : "<<pseudojetTMP->Et() - jetOffset_[ijet]<<"\n";
    LogDebug("PileUpSubtractor")<<"Scale is : "<<mScale<<"\n";
    
    int cshist = pseudojetTMP->cluster_hist_index();
    pseudojetTMP->reset(pseudojetTMP->px()*mScale, pseudojetTMP->py()*mScale,
                        pseudojetTMP->pz()*mScale, pseudojetTMP->e()*mScale);
    pseudojetTMP->set_cluster_hist_index(cshist);
    
  }
}
void PileUpSubtractor::reset ( std::vector< edm::Ptr< reco::Candidate > > &  input,
std::vector< fastjet::PseudoJet > &  towers,
std::vector< fastjet::PseudoJet > &  output 
) [virtual]

Definition at line 41 of file PileUpSubtractor.cc.

References fjInputs_, fjJets_, fjOriginalInputs_, i, collect_tpl::input, inputs_, and convertSQLitetoXML_cfg::output.

                                                                 {
  
  inputs_ = &input;
  fjInputs_ = &towers;
  fjJets_ = &output;
  fjOriginalInputs_ = (*fjInputs_);
  for (unsigned int i = 0; i < fjInputs_->size(); ++i){
    fjOriginalInputs_[i].set_user_index((*fjInputs_)[i].user_index());
  }
  
}
void PileUpSubtractor::setAlgorithm ( ClusterSequencePtr algorithm) [virtual]

Definition at line 55 of file PileUpSubtractor.cc.

References algorithm(), and fjClusterSeq_.

void PileUpSubtractor::setupGeometryMap ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Reimplemented in ParametrizedSubtractor.

Definition at line 59 of file PileUpSubtractor.cc.

References allgeomid_, geo_, geomtowers_, edm::EventSetup::get(), CaloGeometry::getValidDetIds(), DetId::Hcal, i, ieta(), ietamax_, ietamin_, LogDebug, ntowersWithJets_, and edm::ESHandle< T >::product().

{

  LogDebug("PileUpSubtractor")<<"The subtractor setting up geometry...\n";

  if(geo_ == 0) {
    edm::ESHandle<CaloGeometry> pG;
    iSetup.get<CaloGeometryRecord>().get(pG);
    geo_ = pG.product();
    std::vector<DetId> alldid =  geo_->getValidDetIds();

    int ietaold = -10000;
    ietamax_ = -10000;
    ietamin_ = 10000;
    for(std::vector<DetId>::const_iterator did=alldid.begin(); did != alldid.end(); did++){
      if( (*did).det() == DetId::Hcal ){
        HcalDetId hid = HcalDetId(*did);
        if( (hid).depth() == 1 ) {
          allgeomid_.push_back(*did);

          if((hid).ieta() != ietaold){
            ietaold = (hid).ieta();
            geomtowers_[(hid).ieta()] = 1;
            if((hid).ieta() > ietamax_) ietamax_ = (hid).ieta();
            if((hid).ieta() < ietamin_) ietamin_ = (hid).ieta();
          }
          else{
            geomtowers_[(hid).ieta()]++;
          }
        }
      }
    }
  }

  for (int i = ietamin_; i<ietamax_+1; i++) {
    ntowersWithJets_[i] = 0;
  }
}
void PileUpSubtractor::subtractPedestal ( std::vector< fastjet::PseudoJet > &  coll) [virtual]

Reimplemented in MultipleAlgoIterator, and ParametrizedSubtractor.

Definition at line 67 of file MultipleAlgoIterator.cc.

References getHLTprescales::index, and LogDebug.

{

   LogDebug("PileUpSubtractor")<<"The subtractor subtracting pedestals...\n";

   int it = -100;
   int ip = -100;

   vector<fastjet::PseudoJet> newcoll;

   for (vector<fastjet::PseudoJet>::iterator input_object = coll.begin (),
           fjInputsEnd = coll.end(); 
        input_object != fjInputsEnd; ++input_object) {
    
      reco::CandidatePtr const & itow =  (*inputs_)[ input_object->user_index() ];
    
      it = ieta( itow );
      ip = iphi( itow );
    
      double Original_Et = itow->et();
      if(sumRecHits_){
         Original_Et = getEt(itow);
      }

      double etnew = Original_Et - (*(emean_.find(it))).second - (*(esigma_.find(it))).second;
      float mScale = etnew/input_object->Et(); 
      if(etnew < 0.) mScale = 0.;
    
      math::XYZTLorentzVectorD towP4(input_object->px()*mScale, input_object->py()*mScale,
                                     input_object->pz()*mScale, input_object->e()*mScale);
    
      int index = input_object->user_index();
      input_object->reset ( towP4.px(),
                            towP4.py(),
                            towP4.pz(),
                            towP4.energy() );
      input_object->set_user_index(index);

      if(etnew > 0. && dropZeroTowers_) newcoll.push_back(*input_object);
   }

   if(dropZeroTowers_) coll = newcoll;

}

Member Data Documentation

std::vector<HcalDetId> PileUpSubtractor::allgeomid_ [protected]
std::map<int,double> PileUpSubtractor::emean_ [protected]
std::map<int,double> PileUpSubtractor::esigma_ [protected]
std::vector<fastjet::PseudoJet>* PileUpSubtractor::fjInputs_ [protected]
std::vector<fastjet::PseudoJet>* PileUpSubtractor::fjJets_ [protected]
std::vector<fastjet::PseudoJet> PileUpSubtractor::fjOriginalInputs_ [protected]

Definition at line 53 of file PileUpSubtractor.h.

Referenced by ParametrizedSubtractor::offsetCorrectJets(), and reset().

Definition at line 63 of file PileUpSubtractor.h.

Referenced by PileUpSubtractor().

std::map<int,int> PileUpSubtractor::geomtowers_ [protected]
int PileUpSubtractor::ietamax_ [protected]
int PileUpSubtractor::ietamin_ [protected]
std::vector<edm::Ptr<reco::Candidate> >* PileUpSubtractor::inputs_ [protected]

Definition at line 50 of file PileUpSubtractor.h.

Referenced by reset().

std::vector<double> PileUpSubtractor::jetOffset_ [protected]
double PileUpSubtractor::jetPtMin_ [protected]

Definition at line 59 of file PileUpSubtractor.h.

Referenced by ParametrizedSubtractor::offsetCorrectJets().

double PileUpSubtractor::nSigmaPU_ [protected]
std::map<int,int> PileUpSubtractor::ntowersWithJets_ [protected]
double PileUpSubtractor::radiusPU_ [protected]

Definition at line 61 of file PileUpSubtractor.h.

bool PileUpSubtractor::reRunAlgo_ [protected]

Definition at line 56 of file PileUpSubtractor.h.