Page MenuHomeHEPForge

No OneTemporary

Index: contrib/contribs/ConstituentSubtractor/trunk/ConstituentSubtractor.cc
===================================================================
--- contrib/contribs/ConstituentSubtractor/trunk/ConstituentSubtractor.cc (revision 1021)
+++ contrib/contribs/ConstituentSubtractor/trunk/ConstituentSubtractor.cc (revision 1022)
@@ -1,567 +1,577 @@
// $Id$
//
// ConstituentSubtractor package
// Questions/comments: berta@ipnp.troja.mff.cuni.cz, Martin.Spousta@cern.ch, David.W.Miller@uchicago.edu, Rupert.Leitner@mff.cuni.cz
//
// Copyright (c) 2014-, Peter Berta, Martin Spousta, David W. Miller, Rupert Leitner
//
//----------------------------------------------------------------------
// This file is part of FastJet contrib.
//
// It is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at
// your option) any later version.
//
// It is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this code. If not, see <http://www.gnu.org/licenses/>.
//----------------------------------------------------------------------
#include "ConstituentSubtractor.hh"
//#include <ctime>
FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
namespace contrib{
LimitedWarning ConstituentSubtractor::_warning_unused_rhom;
/// Constructor that takes a pointer to a background estimator for
/// rho and optionally a pointer to a background estimator for
/// rho_m.
ConstituentSubtractor::ConstituentSubtractor(fastjet::BackgroundEstimatorBase *bge_rho, fastjet::BackgroundEstimatorBase *bge_rhom, double alpha, double max_distance, Distance distance) :
_bge_rho(bge_rho), _bge_rhom(bge_rhom), _common_bge(false), _rhom_from_bge_rhom(false), _externally_supplied_rho_rhom(false), _distance(distance), _alpha(alpha), _max_distance(max_distance){
if (_max_distance>0) _use_max_distance=true;
else _use_max_distance=false;
_polarAngleExp=0;
_ghost_area=0.01;
_max_eta=0;
_ghosts_constructed=false;
_do_mass_subtraction=false;
if (_common_bge || bge_rhom) _do_mass_subtraction=true;
}
// Constructor that takes an externally supplied value for rho and, optionally, for rho_m.
ConstituentSubtractor::ConstituentSubtractor(double rho, double rhom, double alpha, double max_distance, Distance distance) :
_bge_rho(0), _bge_rhom(0), _common_bge(false), _rhom_from_bge_rhom(false), _rho(rho), _rhom(rhom), _externally_supplied_rho_rhom(true), _distance(distance), _alpha(alpha), _max_distance(max_distance) {
if (_max_distance>0) _use_max_distance=true;
else _use_max_distance=false;
assert(_rho >= 0);
assert(_rhom >= 0);
_polarAngleExp=0;
_ghost_area=0.01;
_ghosts_constructed=false;
_do_mass_subtraction=true;
_max_eta=0;
}
void ConstituentSubtractor::set_background_estimator(fastjet::BackgroundEstimatorBase *bge_rho, fastjet::BackgroundEstimatorBase *bge_rhom){
_bge_rho=bge_rho;
_bge_rhom=bge_rhom;
if (_common_bge || bge_rhom) _do_mass_subtraction=true;
}
void ConstituentSubtractor::set_scalar_background_density(double rho, double rhom){
_rho=rho;
_rhom=rhom;
assert(_rho >= 0);
assert(_rhom >= 0);
_externally_supplied_rho_rhom=true;
_common_bge=false;
_do_mass_subtraction=true;
}
// the action on a given jet
fastjet::PseudoJet ConstituentSubtractor::result(const PseudoJet &jet) const{
// make sure we have a BGE or a rho value
if (!_bge_rho && !_externally_supplied_rho_rhom){
throw Error("ConstituentSubtractor::result() constituent subtraction needs a BackgroundEstimator or a value for rho.");
}
//----------------------------------------------------------------------
// sift ghosts and particles in the input jet
std::vector<fastjet::PseudoJet> particles, ghosts;
SelectorIsPureGhost().sift(jet.constituents(), ghosts, particles);
std::vector<double> ghosts_area;
unsigned long nGhosts=ghosts.size();
for (unsigned int j=0;j<nGhosts; j++){
ghosts_area.push_back(ghosts[j].area());
}
std::vector<fastjet::PseudoJet> backgroundProxies=this->get_background_proxies_from_ghosts(ghosts,ghosts_area);
std::vector<fastjet::PseudoJet> subtracted_particles=this->do_subtraction(particles,backgroundProxies);
fastjet::PseudoJet subtracted_jet=join(subtracted_particles);
subtracted_jet.set_user_index(jet.user_index());
return subtracted_jet;
}
std::vector<fastjet::PseudoJet> ConstituentSubtractor::get_background_proxies_from_ghosts(std::vector<fastjet::PseudoJet> const &ghosts,std::vector<double> const &ghosts_area) const{
std::vector<fastjet::PseudoJet> proxies;
unsigned long nGhosts=ghosts.size();
std::vector<double> pt;
std::vector<double> mtMinusPt;
if (_externally_supplied_rho_rhom){
for (unsigned int j=0;j<nGhosts; j++){
pt.push_back(_rho*ghosts_area[j]);
mtMinusPt.push_back(_rhom*ghosts_area[j]);
}
}
else{
for (unsigned int j=0;j<nGhosts; j++) pt.push_back(_bge_rho->rho(ghosts[j])*ghosts_area[j]);
if (_bge_rhom){
if (_rhom_from_bge_rhom){
#if FASTJET_VERSION_NUMBER >= 30100
for (unsigned int j=0;j<nGhosts; j++) mtMinusPt.push_back(_bge_rhom->rho_m(ghosts[j])*ghosts_area[j]);
#else
throw(Error("ConstituentSubtractor:: _rhom_from_bge_rhom not allowed for FJ<3.1"));
#endif // end of code specific to FJ >= 3.1
} else {
for (unsigned int j=0;j<nGhosts; j++) mtMinusPt.push_back(_bge_rhom->rho(ghosts[j])*ghosts_area[j]);
}
}
else if (_common_bge){
// since FJ 3.1.0, some background estimators have an automatic internal calculation of rho_m
#if FASTJET_VERSION_NUMBER >= 30100
// check if the BGE has internal support for rho_m
if (_bge_rho->has_rho_m()){
for (unsigned int j=0;j<nGhosts; j++) mtMinusPt.push_back(_bge_rho->rho_m(ghosts[j])*ghosts_area[j]);
} else {
#endif // end of code specific to FJ >= 3.1
BackgroundJetPtMDensity m_density;
JetMedianBackgroundEstimator *jmbge = dynamic_cast<JetMedianBackgroundEstimator*>(_bge_rho);
const FunctionOfPseudoJet<double> * orig_density = jmbge->jet_density_class();
jmbge->set_jet_density_class(&m_density);
for (unsigned int j=0;j<nGhosts; j++) mtMinusPt.push_back(jmbge->rho(ghosts[j])*ghosts_area[j]);
jmbge->set_jet_density_class(orig_density);
#if FASTJET_VERSION_NUMBER >= 30100
}
#endif
}
else { // a single bge, only rho requested
for (unsigned int j=0;j<nGhosts; j++) mtMinusPt.push_back(1e-200);
#if FASTJET_VERSION_NUMBER >= 30100
// In FJ3.1 and BGE with rho_m support, add a warning, similar to that in Subtractor
double const rho_m_warning_threshold = 1e-5;
if (_bge_rho->has_rho_m() && _bge_rho->rho_m()>rho_m_warning_threshold*_bge_rho->rho()){
_warning_unused_rhom.warn("ConstituentSubtractor:: Background estimator indicates non-zero rho_m, but the constituent subtractor does not use rho_m information; consider calling set_common_bge_for_rho_and_rhom(true) to include the rho_m information");
}
#endif
}
}
fastjet::PseudoJet proxy(0,0,0,1);
for (unsigned int j=0;j<nGhosts; j++){
double mass_squared=pow(mtMinusPt[j]+pt[j],2)-pow(pt[j],2);
double mass=0;
if (mass_squared>0) mass=sqrt(mass_squared);
proxy.reset_momentum_PtYPhiM(pt[j],ghosts[j].rap(),ghosts[j].phi(),mass);
proxies.push_back(proxy);
}
return proxies;
}
std::vector<fastjet::PseudoJet> ConstituentSubtractor::do_subtraction(std::vector<fastjet::PseudoJet> const &particles, std::vector<fastjet::PseudoJet> const &backgroundProxies,std::vector<fastjet::PseudoJet> *remaining_backgroundProxies) const{
unsigned int nBackgroundProxies=backgroundProxies.size();
unsigned int nParticles=particles.size();
/* std::cout << "number of particles: " << nParticles << std::endl;
for (unsigned int i=0;i<nParticles;++i){
std::cout << i << " " << particles[i].eta() << " " << particles[i].rap() << " " << particles[i].phi() << " " << particles[i].pt() << std::endl;
}
std::cout << std::endl << std::endl;*/
/* std::cout << "number of backgroundProxies: " << nBackgroundProxies << std::endl;
for (unsigned int i=0;i<nBackgroundProxies;++i){
std::cout << i << " " << backgroundProxies[i].eta()<< " " << backgroundProxies[i].rap() << " " << backgroundProxies[i].phi() << " " << backgroundProxies[i].pt() << " " << backgroundProxies[i].m() << std::endl;
}
std::cout << std::endl << std::endl;*/
// computing and sorting the CS distances
double max_distance_transformed=-1;
if (_distance==ConstituentSubtractor::deltaR) max_distance_transformed=pow(_max_distance,2);
if (_distance==ConstituentSubtractor::angle) max_distance_transformed=-cos(_max_distance);
std::vector<std::pair<double,int> > CS_distances; // the first element is the distance, the second element is only the index in the vector used for sorting
std::vector<int> particle_indices_unsorted, proxy_indices_unsorted;
particle_indices_unsorted.resize(nBackgroundProxies*nParticles);
proxy_indices_unsorted.resize(nBackgroundProxies*nParticles);
CS_distances.resize(nBackgroundProxies*nParticles);
std::vector<fastjet::PseudoJet> backgroundProxies_sorted=backgroundProxies;
std::vector<fastjet::PseudoJet> particles_sorted=particles;
//std::sort(backgroundProxies_sorted.begin(),backgroundProxies_sorted.end(),ConstituentSubtractor::_rap_sorting);
//std::sort(particles_sorted.begin(),particles_sorted.end(),ConstituentSubtractor::_rap_sorting);
std::vector<double> backgroundProxies_phi,backgroundProxies_rap,backgroundProxies_pt,backgroundProxies_mt;
for (unsigned int j=0;j<nBackgroundProxies; j++){
backgroundProxies_phi.push_back(backgroundProxies_sorted[j].phi());
backgroundProxies_rap.push_back(backgroundProxies_sorted[j].rap());
backgroundProxies_pt.push_back(backgroundProxies_sorted[j].pt());
backgroundProxies_mt.push_back(backgroundProxies_sorted[j].mt());
}
std::vector<double> particles_phi,particles_rap,particles_pt,particles_mt;
for (unsigned int j=0;j<nParticles; j++){
particles_phi.push_back(particles_sorted[j].phi());
particles_rap.push_back(particles_sorted[j].rap());
particles_pt.push_back(particles_sorted[j].pt());
particles_mt.push_back(particles_sorted[j].mt());
}
unsigned long nStoredPairs=0;
for (unsigned int i=0;i<nParticles; i++){
double pt_factor=1.;
if (fabs(_alpha)>1e-5) pt_factor=pow(particles_pt[i],_alpha);
double polarAngle_factor=1.;
if (fabs(_polarAngleExp)>1e-5) polarAngle_factor=pow(particles_pt[i]/sqrt(particles_sorted[i].pt2()+particles_sorted[i].pz()*particles_sorted[i].pz()),_polarAngleExp);
for (unsigned int j=0;j<nBackgroundProxies; j++){
double distance_transformed = 0;
if (_distance==ConstituentSubtractor::deltaR){
double deltaPhi=fabs(backgroundProxies_phi[j]-particles_phi[i]);
if (deltaPhi>pi) deltaPhi=twopi-deltaPhi;
double deltaRap=backgroundProxies_rap[j]-particles_rap[i];
distance_transformed = deltaPhi*deltaPhi+deltaRap*deltaRap;
}
if (_distance==ConstituentSubtractor::angle){
double particle_magnitude=sqrt(particles_sorted[i].pt2()+particles_sorted[i].pz()*particles_sorted[i].pz());
double backgroundProxy_magnitude=sqrt(backgroundProxies_sorted[j].pt2()+backgroundProxies_sorted[j].pz()*backgroundProxies_sorted[j].pz());
double scalar_product = particles_sorted[i].px()*backgroundProxies_sorted[j].px() + particles_sorted[i].py()*backgroundProxies_sorted[j].py() + particles_sorted[i].pz()*backgroundProxies_sorted[j].pz();
distance_transformed = -scalar_product/particle_magnitude/backgroundProxy_magnitude;
}
if (!_use_max_distance || distance_transformed<=max_distance_transformed){
double CS_distance = distance_transformed*pt_factor*polarAngle_factor;
particle_indices_unsorted[nStoredPairs]=i;
proxy_indices_unsorted[nStoredPairs]=j;
CS_distances[nStoredPairs]=std::make_pair(CS_distance,nStoredPairs);
nStoredPairs++;
}
}
}
particle_indices_unsorted.resize(nStoredPairs);
proxy_indices_unsorted.resize(nStoredPairs);
CS_distances.resize(nStoredPairs);
std::sort(CS_distances.begin(),CS_distances.end(),ConstituentSubtractor::_function_used_for_sorting);
//----------------------------------------------------------------------
// the iterative process. Here, only finding the fractions of pt or deltaM to be corrected. The actual correction of particles is done later.
std::vector<double> backgroundProxies_fraction_of_pt(nBackgroundProxies,1.);
std::vector<double> particles_fraction_of_pt(nParticles,1.);
std::vector<double> backgroundProxies_fraction_of_mtMinusPt(nBackgroundProxies,1.);
std::vector<double> particles_fraction_of_mtMinusPt(nParticles,1.);
for (unsigned long iindices=0;iindices<nStoredPairs;++iindices){
int particle_index=particle_indices_unsorted[CS_distances[iindices].second];
int proxy_index=proxy_indices_unsorted[CS_distances[iindices].second];
if (backgroundProxies_fraction_of_pt[proxy_index]>0 && particles_fraction_of_pt[particle_index]>0 && particles_pt[particle_index]>0 && backgroundProxies_pt[proxy_index]>0){
double ratio_pt=particles_pt[particle_index]*particles_fraction_of_pt[particle_index]/backgroundProxies_pt[proxy_index]/backgroundProxies_fraction_of_pt[proxy_index];
if (ratio_pt>1){
particles_fraction_of_pt[particle_index]*=1-1./ratio_pt;
backgroundProxies_fraction_of_pt[proxy_index]=-1;
}
else {
backgroundProxies_fraction_of_pt[proxy_index]*=1-ratio_pt;
particles_fraction_of_pt[particle_index]=-1;
}
}
if (_do_mass_subtraction && backgroundProxies_fraction_of_mtMinusPt[proxy_index]>0 && particles_fraction_of_mtMinusPt[particle_index]>0 && particles_mt[particle_index]>particles_pt[particle_index] && backgroundProxies_mt[proxy_index]>backgroundProxies_pt[proxy_index]){
double ratio_mtMinusPt=(particles_mt[particle_index]-particles_pt[particle_index])*particles_fraction_of_mtMinusPt[particle_index]/(backgroundProxies_mt[proxy_index]-backgroundProxies_pt[proxy_index])/backgroundProxies_fraction_of_mtMinusPt[proxy_index];
if (ratio_mtMinusPt>1){
particles_fraction_of_mtMinusPt[particle_index]*=1-1./ratio_mtMinusPt;
backgroundProxies_fraction_of_mtMinusPt[proxy_index]=-1;
}
else{
backgroundProxies_fraction_of_mtMinusPt[proxy_index]*=1-ratio_mtMinusPt;
particles_fraction_of_mtMinusPt[particle_index]=-1;
}
}
}
//----------------------------------------------------------------------
// do the actual correction for particles:
std::vector<fastjet::PseudoJet> subtracted_particles;
for (unsigned int i=0;i<nParticles; i++){
if (particles_fraction_of_pt[i]<=0) continue; // particles with zero pt are not used (but particles with zero mtMinusPt are used)
double rapidity=particles_rap[i];
double azimuth=particles_phi[i];
double subtracted_pt=particles_pt[i]*particles_fraction_of_pt[i];
double subtracted_mtMinusPt=0;
if (particles_fraction_of_mtMinusPt[i]>0) subtracted_mtMinusPt=(particles_mt[i]-particles_pt[i])*particles_fraction_of_mtMinusPt[i];
// PseudoJet subtracted_const(subtracted_pt*cos(azimuth),subtracted_pt*sin(azimuth),(subtracted_pt+subtracted_mtMinusPt)*sinh(rapidity),(subtracted_pt+subtracted_mtMinusPt)*cosh(rapidity));
PseudoJet subtracted_const(0,0,0,1);
double mass_squared=pow(subtracted_pt+subtracted_mtMinusPt,2)-pow(subtracted_pt,2);
if (mass_squared<0) mass_squared=0;
subtracted_const.reset_momentum_PtYPhiM(subtracted_pt,rapidity,azimuth,sqrt(mass_squared));
subtracted_const.set_user_index(particles_sorted[i].user_index());
subtracted_particles.push_back(subtracted_const);
}
if (remaining_backgroundProxies){
for (unsigned int i=0;i<nBackgroundProxies; i++){
double rapidity=backgroundProxies_rap[i];
double azimuth=backgroundProxies_phi[i];
double subtracted_pt=0;
if (backgroundProxies_fraction_of_pt[i]>0) subtracted_pt=backgroundProxies_pt[i]*backgroundProxies_fraction_of_pt[i];
double subtracted_mtMinusPt=0;
if (backgroundProxies_fraction_of_mtMinusPt[i]>0) subtracted_mtMinusPt=(backgroundProxies_mt[i]-backgroundProxies_pt[i])*backgroundProxies_fraction_of_mtMinusPt[i];
// PseudoJet subtracted_const(subtracted_pt*cos(azimuth),subtracted_pt*sin(azimuth),(subtracted_pt+subtracted_mtMinusPt)*sinh(rapidity),(subtracted_pt+subtracted_mtMinusPt)*cosh(rapidity));
PseudoJet subtracted_const(0,0,0,1);
double mass_squared=pow(subtracted_pt+subtracted_mtMinusPt,2)-pow(subtracted_pt,2);
if (mass_squared<0) mass_squared=0;
subtracted_const.reset_momentum_PtYPhiM(subtracted_pt,rapidity,azimuth,sqrt(mass_squared));
remaining_backgroundProxies->push_back(subtracted_const);
}
}
return subtracted_particles;
}
std::vector<fastjet::PseudoJet> ConstituentSubtractor::sequential_subtraction(std::vector<fastjet::PseudoJet> const &particles, double max_eta){
if (fabs(_max_eta/max_eta-1)>1e-5) _ghosts_constructed=false;
if (!_ghosts_constructed) this->construct_ghosts_uniformly(max_eta);
std::vector<fastjet::PseudoJet> backgroundProxies=this->get_background_proxies_from_ghosts(_ghosts,_ghosts_area);
std::vector<fastjet::PseudoJet> selected_particles;
for (unsigned int i=0;i<particles.size();++i){
if (fabs(particles[i].eta())<max_eta) selected_particles.push_back(particles[i]);
}
double total_background_pt=0,total_background_mt=0;
for (unsigned int i=0;i<backgroundProxies.size();++i){
total_background_pt+=backgroundProxies[i].pt();
total_background_mt+=backgroundProxies[i].mt();
}
this->set_max_distance(_max_distance_sequential);
std::vector<fastjet::PseudoJet> *remaining_backgroundProxies=new std::vector<fastjet::PseudoJet>;
std::vector<fastjet::PseudoJet> subtracted_particles=this->do_subtraction(selected_particles,backgroundProxies,remaining_backgroundProxies);
double remaining_background_pt=0,remaining_background_mt=0;
for (unsigned int i=0;i<remaining_backgroundProxies->size();++i){
remaining_background_pt+=(remaining_backgroundProxies->at(i)).pt();
remaining_background_mt+=(remaining_backgroundProxies->at(i)).mt();
}
std::vector<fastjet::PseudoJet> backgroundProxies2;
for (unsigned int i=0;i<backgroundProxies.size();++i){
double rapidity=backgroundProxies[i].rap();
double azimuth=backgroundProxies[i].phi();
double pt= backgroundProxies[i].pt()*remaining_background_pt/total_background_pt;
double mtMinusPt= (backgroundProxies[i].mt()-backgroundProxies[i].pt())*(remaining_background_mt-remaining_background_pt)/(total_background_mt-total_background_pt);
PseudoJet proxy(pt*cos(azimuth),pt*sin(azimuth),(pt+mtMinusPt)*sinh(rapidity),(pt+mtMinusPt)*cosh(rapidity));
backgroundProxies2.push_back(proxy);
}
delete remaining_backgroundProxies;
this->set_max_distance(_max_distance);
std::vector<fastjet::PseudoJet> subtracted_particles2=this->do_subtraction(subtracted_particles,backgroundProxies2);
return subtracted_particles2;
}
void ConstituentSubtractor::set_common_bge_for_rho_and_rhom(bool value){
if (!_bge_rho) throw Error("ConstituentSubtractor::set_common_bge_for_rho_and_rhom() is not allowed when _bge_rho is not set!");
if (value){
if (_bge_rhom) throw Error("ConstituentSubtractor::set_common_bge_for_rho_and_rhom() is not allowed in the presence of an existing background estimator for rho_m.");
if (_externally_supplied_rho_rhom) throw Error("ConstituentSubtractor::set_common_bge_for_rho_and_rhom() is not allowed when supplying externally the values for rho and rho_m.");
}
#if FASTJET_VERSION_NUMBER >= 30100
if (!_bge_rho->has_rho_m()){
#endif
JetMedianBackgroundEstimator *jmbge = dynamic_cast<JetMedianBackgroundEstimator*>(_bge_rho);
if (!jmbge) throw Error("ConstituentSubtractor::set_common_bge_for_rho_and_rhom() is currently only allowed for background estimators of JetMedianBackgroundEstimator type.");
#if FASTJET_VERSION_NUMBER >= 30100
}
#endif
_common_bge=value;
_do_mass_subtraction=value;
}
// setting this to true will result in rho_m being estimated using bge_rhom->rho_m() instead of bge_rhom->rho()
void ConstituentSubtractor::set_use_bge_rhom_rhom(bool value){
if (!value){
_rhom_from_bge_rhom=false;
return;
}
#if FASTJET_VERSION_NUMBER < 30100
throw Error("ConnstituentSubtractor::use_rhom_from_bge_rhom() can only be used with FastJet >=3.1.");
#else
if (!_bge_rhom) throw Error("ConstituentSubtractor::use_rhom_from_bge_rhom() requires a background estimator for rho_m.");
if (!(_bge_rhom->has_rho_m())) throw Error("ConstituentSubtractor::use_rhom_from_bge_rhom() requires rho_m support for the background estimator for rho_m.");
#endif
_rhom_from_bge_rhom=true;
_do_mass_subtraction=true;
}
void ConstituentSubtractor::set_do_mass_subtraction(bool do_mass_subtraction){
_do_mass_subtraction=do_mass_subtraction;
}
std::string ConstituentSubtractor::description() const{
std::ostringstream descr;
if ( _externally_supplied_rho_rhom){
descr << "ConstituentSubtractor using externally supplied rho = " << _rho << " and rho_m = " << _rhom << " to describe the background";
} else {
if (_bge_rhom && _bge_rho) {
descr << "ConstituentSubtractor using [" << _bge_rho->description() << "] and [" << _bge_rhom->description() << "] to estimate the background";
} else {
if (_bge_rho) descr << "ConstituentSubtractor using [" << _bge_rho->description() << "] to estimate the background";
else descr << "ConstituentSubtractor: no externally supplied rho, nor background estimator";
}
}
descr << std::endl << "perform mass subtraction: " << _do_mass_subtraction << std::endl;
return descr.str();
}
void ConstituentSubtractor::set_distance_type(Distance distance){
_distance=distance;
}
void ConstituentSubtractor::set_max_distance(double max_distance){
if (max_distance>0){
_use_max_distance=true;
_max_distance=max_distance;
}
else _use_max_distance=false;
}
void ConstituentSubtractor::set_max_distance_sequential(double max_distance_sequential){
_max_distance_sequential=max_distance_sequential;
}
double ConstituentSubtractor::get_max_distance(){
return _max_distance;
}
void ConstituentSubtractor::set_alpha(double alpha){
_alpha=alpha;
}
void ConstituentSubtractor::set_polarAngleExp(double polarAngleExp){
_polarAngleExp=polarAngleExp;
}
void ConstituentSubtractor::set_ghost_area(double ghost_area){
_ghost_area=ghost_area;
_ghosts_constructed=false;
}
bool ConstituentSubtractor::_function_used_for_sorting(std::pair<double,int> i,std::pair<double, int> j){
return (i.first < j.first);
}
std::vector<fastjet::PseudoJet> ConstituentSubtractor::subtract_event(std::vector<fastjet::PseudoJet> const &particles, double max_eta){
if (fabs(_max_eta/max_eta-1)>1e-5) _ghosts_constructed=false;
if (!_ghosts_constructed) this->construct_ghosts_uniformly(max_eta);
std::vector<fastjet::PseudoJet> backgroundProxies=this->get_background_proxies_from_ghosts(_ghosts,_ghosts_area);
std::vector<fastjet::PseudoJet> selected_particles;
for (unsigned int i=0;i<particles.size();++i){
if (fabs(particles[i].eta())<max_eta) selected_particles.push_back(particles[i]);
}
std::vector<fastjet::PseudoJet> subtracted_particles=this->do_subtraction(selected_particles,backgroundProxies);
return subtracted_particles;
}
std::vector<fastjet::PseudoJet> ConstituentSubtractor::subtract_event_using_charged_info(std::vector<fastjet::PseudoJet> const &particles, double charged_background_scale, std::vector<fastjet::PseudoJet> const &charged_background, double charged_signal_scale, std::vector<fastjet::PseudoJet> const &charged_signal, double max_eta, fastjet::FunctionOfPseudoJet<double> *rescaling){
if (fabs(_max_eta/max_eta-1)>1e-5) _ghosts_constructed=false;
if (!_ghosts_constructed) this->construct_ghosts_uniformly(max_eta);
std::vector<fastjet::PseudoJet> scaled_charged_all;
std::vector<fastjet::PseudoJet> scaled_charged_signal;
std::vector<fastjet::PseudoJet> scaled_charged_background;
for (unsigned int i=0;i<charged_background.size();++i){
if (fabs(charged_background[i].eta())>max_eta) continue;
scaled_charged_background.push_back(charged_background_scale*charged_background[i]);
scaled_charged_all.push_back(scaled_charged_background[scaled_charged_background.size()-1]);
}
for (unsigned int i=0;i<charged_signal.size();++i){
if (fabs(charged_signal[i].eta())>max_eta) continue;
scaled_charged_signal.push_back(charged_signal_scale*charged_signal[i]);
scaled_charged_all.push_back(scaled_charged_signal[scaled_charged_signal.size()-1]);
}
std::vector<fastjet::PseudoJet> selected_particles;
for (unsigned int i=0;i<particles.size();++i){
if (fabs(particles[i].eta())<max_eta) selected_particles.push_back(particles[i]);
}
std::vector<fastjet::PseudoJet> *remaining_charged_background= new std::vector<fastjet::PseudoJet>;
double maxDeltaR=this->get_max_distance();
if (maxDeltaR<=0) maxDeltaR=0.5;
this->set_max_distance(0.2);
std::vector<fastjet::PseudoJet> subtracted_particles_using_scaled_charged_signal=this->do_subtraction(selected_particles,scaled_charged_signal);
std::vector<fastjet::PseudoJet> subtracted_particles_using_scaled_charged_all=this->do_subtraction(subtracted_particles_using_scaled_charged_signal,scaled_charged_background,remaining_charged_background); // remaining neutral background particles
std::vector<fastjet::PseudoJet> scaled_charged_background_used_for_subtraction=this->do_subtraction(scaled_charged_background,*remaining_charged_background);
_bge_rho= new fastjet::GridMedianBackgroundEstimator(max_eta, 0.6);
if (_do_mass_subtraction) this->set_common_bge_for_rho_and_rhom(true);
_bge_rho->set_rescaling_class(rescaling);
_bge_rho->set_particles(subtracted_particles_using_scaled_charged_all);
std::vector<fastjet::PseudoJet> backgroundProxies=this->get_background_proxies_from_ghosts(_ghosts,_ghosts_area);
backgroundProxies.insert(backgroundProxies.end(), scaled_charged_background_used_for_subtraction.begin(), scaled_charged_background_used_for_subtraction.end());
this->set_max_distance(maxDeltaR);
std::vector<fastjet::PseudoJet> subtracted_particles=this->do_subtraction(selected_particles,backgroundProxies);
delete remaining_charged_background;
delete _bge_rho;
return subtracted_particles;
}
void ConstituentSubtractor::construct_ghosts_uniformly(double max_eta){
_ghosts.clear();
_ghosts_area.clear();
_max_eta=max_eta;
double a=sqrt(_ghost_area);
int nPhi=(2*3.14159265/a+0.5); // rounding
int nRap=(2*max_eta/a+0.5); // rounding
double sizePhi=2*3.14159265/(double)nPhi;
double sizeRap=2*max_eta/(double)nRap;
double used_ghost_area=sizePhi*sizeRap;
fastjet::PseudoJet ghost(0,0,0,1);
for (int iPhi=0;iPhi<nPhi;++iPhi){
for (int iRap=0;iRap<nRap;++iRap){
ghost.reset_momentum_PtYPhiM(1,sizeRap*(iRap+0.5)-max_eta,sizePhi*(iPhi+0.5),1e-200);
_ghosts.push_back(ghost);
_ghosts_area.push_back(used_ghost_area);
}
}
_ghosts_constructed=true;
}
+
+ std::vector<fastjet::PseudoJet> ConstituentSubtractor::get_ghosts(){
+ return _ghosts;
+ }
+
+
+ std::vector<double> ConstituentSubtractor::get_ghosts_area(){
+ return _ghosts_area;
+ }
+
} // namespace contrib
FASTJET_END_NAMESPACE
Index: contrib/contribs/ConstituentSubtractor/trunk/NEWS
===================================================================
--- contrib/contribs/ConstituentSubtractor/trunk/NEWS (revision 1021)
+++ contrib/contribs/ConstituentSubtractor/trunk/NEWS (revision 1022)
@@ -1,20 +1,25 @@
+2017/07/11: release of version 1.1.6:
+ - added new functions "get_ghosts" and "get_ghosts_area".
+ - now the user can modify the ghosts outside the CS after constructing them with function "construct_ghosts_uniformly" and getting them with "get_ghosts" and "get_ghosts_area"
+ - added new rescaling class useful for heavy ion events. Now the rapidity dependence can be taken from a Root TH1 object.
+
2017/01/20: release of version 1.1.4:
- fixed few bugs concerning the correction of masses
2016/11/14: release of version 1.1.3:
- updated rho rescaling functions
- new function for pileup subtraction: sequential_subtraction
- possibility to change the computation of distance between particles and background proxies
2016/03/11: release of version 1.1.2:
- added two FunctionOfPseudojet<object> classes for rho rescaling: one using root TH1 rapidity parametrization, and the other for heavy ions rapidity-azimuth parametrization
2016/02/09: release of version 1.1.1:
- faster algortihm for subtraction
- added new function for Constituent Subtraction using tracking information
2015/11/05: release of version 1.1.0:
- added FastJet v3.1 rho_m support
- simplified way for Constituent Subtraction of the whole event
- updated the meaning of parameter max_deltaR
- added new parameter to the definition of the distance
- added examples for the whole event subtraction
2014/04/06: release of version 1.0.0
Index: contrib/contribs/ConstituentSubtractor/trunk/RescalingClasses.hh
===================================================================
--- contrib/contribs/ConstituentSubtractor/trunk/RescalingClasses.hh (revision 1021)
+++ contrib/contribs/ConstituentSubtractor/trunk/RescalingClasses.hh (revision 1022)
@@ -1,105 +1,171 @@
// ConstituentSubtractor package
// Questions/comments: berta@ipnp.troja.mff.cuni.cz, Martin.Spousta@cern.ch, David.W.Miller@uchicago.edu, Rupert.Leitner@mff.cuni.cz
//
// Copyright (c) 2014-, Peter Berta, Martin Spousta, David W. Miller, Rupert Leitner
//
//----------------------------------------------------------------------
// This file is part of FastJet contrib.
//
// It is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at
// your option) any later version.
//
// It is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this code. If not, see <http://www.gnu.org/licenses/>.
//----------------------------------------------------------------------
#ifndef __FASTJET_CONTRIB_CONSTITUENTSUBTRACTOR_RESCALINGCLASSES_HH__
#define __FASTJET_CONTRIB_CONSTITUENTSUBTRACTOR_RESCALINGCLASSES_HH__
#include <fastjet/FunctionOfPseudoJet.hh>
#include <iostream>
//#include "TH1.h"
FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
namespace contrib{
template<class T>
class BackgroundRescalingYFromRoot : public FunctionOfPseudoJet<double> {
public:
/// construct a background rescaling function using ROOT TH1 histogram bin contents
BackgroundRescalingYFromRoot(): _hist(0) {}
BackgroundRescalingYFromRoot(T* hist=0) {_hist = hist;}
// return the rescaling factor associated with this jet
virtual double result(const PseudoJet & particle) const {
if (!_hist){
std::cout << "histogram for rescaling not defined!!!" << std::endl;
throw;
}
double y = particle.rap();
int bin=_hist->FindBin(y);
return _hist->GetBinContent(bin);
}
private:
T* _hist;
};
-class BackgroundRescalingYPhi : public FunctionOfPseudoJet<double> {
-public:
- /// Construct background rescaling function in rapidity and azimuth using this parameterization:
-
- /// f(y,phi) = phi_term(phi) * rap_term(y)
- /// where
-
- /// phi_term(phi) = 1 + 2 * v2^2 * cos(2*(phi-psi)) + 2 * v3^2 * cos(3*(phi-psi)) + 2 * v4^2 * cos(4*(phi-psi))
- /// with four parameters v2, v3, v4, and psi.
-
- /// rap_term(y) = a1*exp(-pow(y,2)/(2*sigma1^2)) + a2*exp(-pow(y,2)/(2*sigma2^2))
- /// with four parameters sigma1, sigma2, a1, and a2.
-
- /// This function is used to rescale the background which is subtracted such that one can correctly account
- /// for the modulation of the UE due to rapidity dependence of the particle production
- /// and/or due to the modulation in the azimuthal angle which is characteristic for heavy ion collisions.
- /// The overall normalization of function f is arbitrary since it divides out in the calculation of position dependent rho (background is first demodulated to obtain unbiased position independent rho, and then it is modulated to obtain position dependent rho, see fastjet classes GridMedianBackgroundEstimator and JetMedianBackgroundEstimator for detailed calculation).
-
- BackgroundRescalingYPhi(): _v2(0), _v3(0), _v4(0), _psi(0), _a1(1), _sigma1(1000), _a2(0), _sigma2(1000), _use_rap(false), _use_phi(false) {}
- BackgroundRescalingYPhi(double v2, double v3, double v4, double psi, double a1, double sigma1, double a2, double sigma2);
-
- void use_rap_term(bool use_rap);
- void use_phi_term(bool use_phi);
-
- /// return the rescaling factor associated with this jet
- virtual double result(const PseudoJet & jet) const;
-private:
- double _v2, _v3, _v4, _psi, _a1, _sigma1, _a2, _sigma2;
- bool _use_rap, _use_phi;
-};
+ template<class T>
+ class BackgroundRescalingYFromRootPhi : public FunctionOfPseudoJet<double> {
+ public:
+ /// Construct background rescaling function in rapidity and azimuth using ROOT TH1 histogram bin contents for the rapidity dependence and this parametrization for the azimuth:
+
+ /// phi_term(phi) = 1 + 2 * v2^2 * cos(2*(phi-psi)) + 2 * v3^2 * cos(3*(phi-psi)) + 2 * v4^2 * cos(4*(phi-psi))
+ /// with four parameters v2, v3, v4, and psi.
+
+ /// This product of the TH1 histogram and function is used to rescale the background which is subtracted such that one can correctly account
+ /// for the modulation of the UE due to rapidity dependence of the particle production
+ /// and/or due to the modulation in the azimuthal angle which is characteristic for heavy ion collisions.
+ /// The overall normalization of the rescaling function is arbitrary since it divides out in the calculation of position dependent rho (background is first demodulated to obtain unbiased position independent rho, and then it is modulated to obtain position dependent rho, see fastjet classes GridMedianBackgroundEstimator and JetMedianBackgroundEstimator for detailed calculation).
+
+ BackgroundRescalingYFromRootPhi(): _v2(0), _v3(0), _v4(0), _psi(0), _use_rap(false), _use_phi(false), _hist(0) {}
+ BackgroundRescalingYFromRootPhi(double v2, double v3, double v4, double psi, T* hist=0){
+ _v2=v2;
+ _v3=v3;
+ _v4=v4;
+ _psi=psi;
+ _hist=hist;
+ _use_phi=true;
+ if (!_hist){
+ std::cout << std::endl << std::endl << "ConstituentSubtractor::BackgroundRescalingYFromRootPhi WARNING: The histogram for rapidity rescaling is not defined!!! Not performing rapidity rescaling." << std::endl << std::endl << std::endl;
+ _use_rap=false;
+ }
+ else _use_rap=true;
+ }
+
+ /// Turn on or off the rapidity rescaling. Throwing in case true is set and no histogram is provided.
+ void use_rap_term(bool use_rap){
+ _use_rap=use_rap;
+ if (!_hist && _use_rap){
+ std::cout << "ConstituentSubtractor::BackgroundRescalingYFromRootPhi ERROR: Requested rapidity rescaling, but the histogram for rescaling is not defined!!! Throwing." << std::endl;
+ throw;
+ }
+ }
+
+ /// Turn on or off the azimuth rescaling.
+ void use_phi_term(bool use_phi){
+ _use_phi=use_phi;
+ }
+
+ /// Return the rescaling factor associated with this particle
+ virtual double result(const PseudoJet & particle) const{
+ double phi_term=1;
+ if (_use_phi){
+ double phi=particle.phi();
+ phi_term=1 + 2*_v2*_v2*cos(2*(phi-_psi)) + 2*_v3*_v3*cos(3*(phi-_psi)) + 2*_v4*_v4*cos(4*(phi-_psi));
+ }
+ double rap_term=1;
+ if (_use_rap){
+ double y=particle.rap();
+ int bin=_hist->FindBin(y);
+ rap_term=_hist->GetBinContent(bin);
+ }
+
+ return phi_term*rap_term;
+ }
+
+ private:
+ double _v2, _v3, _v4, _psi;
+ bool _use_rap, _use_phi;
+ T* _hist;
+ };
+
+ class BackgroundRescalingYPhi : public FunctionOfPseudoJet<double> {
+ public:
+ /// Construct background rescaling function in rapidity and azimuth using this parameterization:
+
+ /// f(y,phi) = phi_term(phi) * rap_term(y)
+ /// where
+
+ /// phi_term(phi) = 1 + 2 * v2^2 * cos(2*(phi-psi)) + 2 * v3^2 * cos(3*(phi-psi)) + 2 * v4^2 * cos(4*(phi-psi))
+ /// with four parameters v2, v3, v4, and psi.
+
+ /// rap_term(y) = a1*exp(-pow(y,2)/(2*sigma1^2)) + a2*exp(-pow(y,2)/(2*sigma2^2))
+ /// with four parameters sigma1, sigma2, a1, and a2.
+
+ /// This function is used to rescale the background which is subtracted such that one can correctly account
+ /// for the modulation of the UE due to rapidity dependence of the particle production
+ /// and/or due to the modulation in the azimuthal angle which is characteristic for heavy ion collisions.
+ /// The overall normalization of function f is arbitrary since it divides out in the calculation of position dependent rho (background is first demodulated to obtain unbiased position independent rho, and then it is modulated to obtain position dependent rho, see fastjet classes GridMedianBackgroundEstimator and JetMedianBackgroundEstimator for detailed calculation).
+
+ BackgroundRescalingYPhi(): _v2(0), _v3(0), _v4(0), _psi(0), _a1(1), _sigma1(1000), _a2(0), _sigma2(1000), _use_rap(false), _use_phi(false) {}
+ BackgroundRescalingYPhi(double v2, double v3, double v4, double psi, double a1, double sigma1, double a2, double sigma2);
+
+ void use_rap_term(bool use_rap);
+ void use_phi_term(bool use_phi);
+
+ /// return the rescaling factor associated with this jet
+ virtual double result(const PseudoJet & particle) const;
+ private:
+ double _v2, _v3, _v4, _psi, _a1, _sigma1, _a2, _sigma2;
+ bool _use_rap, _use_phi;
+ };
+
} // namespace contrib
FASTJET_END_NAMESPACE
#endif //__FASTJET_CONTRIB_CONSTITUENTSUBTRACTOR_RESCALINGCLASSES_HH__
Index: contrib/contribs/ConstituentSubtractor/trunk/VERSION
===================================================================
--- contrib/contribs/ConstituentSubtractor/trunk/VERSION (revision 1021)
+++ contrib/contribs/ConstituentSubtractor/trunk/VERSION (revision 1022)
@@ -1,2 +1,2 @@
-1.1.5
+1.1.6
Index: contrib/contribs/ConstituentSubtractor/trunk/ConstituentSubtractor.hh
===================================================================
--- contrib/contribs/ConstituentSubtractor/trunk/ConstituentSubtractor.hh (revision 1021)
+++ contrib/contribs/ConstituentSubtractor/trunk/ConstituentSubtractor.hh (revision 1022)
@@ -1,179 +1,191 @@
// $Id$
//
// ConstituentSubtractor package
// Questions/comments: berta@ipnp.troja.mff.cuni.cz, Martin.Spousta@cern.ch, David.W.Miller@uchicago.edu, Rupert.Leitner@mff.cuni.cz
//
// Copyright (c) 2014-, Peter Berta, Martin Spousta, David W. Miller, Rupert Leitner
//
//----------------------------------------------------------------------
// This file is part of FastJet contrib.
//
// It is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at
// your option) any later version.
//
// It is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this code. If not, see <http://www.gnu.org/licenses/>.
//----------------------------------------------------------------------
#ifndef __FASTJET_CONTRIB_CONSTITUENTSUBTRACTOR_HH__
#define __FASTJET_CONTRIB_CONSTITUENTSUBTRACTOR_HH__
#include <fastjet/internal/base.hh>
#include <fastjet/ClusterSequenceAreaBase.hh>
#include <fastjet/tools/JetMedianBackgroundEstimator.hh>
#include <fastjet/tools/GridMedianBackgroundEstimator.hh>
#include <fastjet/PseudoJet.hh>
#include <fastjet/tools/BackgroundEstimatorBase.hh>
#include "fastjet/tools/Transformer.hh" // to derive Subtractor from Transformer
#include "fastjet/LimitedWarning.hh"
#include <algorithm>
FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
namespace contrib{
//------------------------------------------------------------------------
/// \class ConstituentSubtractor
/// A class to perform subtraction of background, e.g. pileup, from a set of particles at particle-level. The output is a jet or the whole event with corrected constituents.
///
/// This class corrects the input particles for background contamination with the algorithm described in:
/// Peter Berta, Martin Spousta, David W. Miller, Rupert Leitner [arXiv:1403.3108]
///
/// For individual jet background subtraction, see example.cc
/// For whole event background subtraction before jet clustering, see example_whole_event.cc
///
/// The distance used for matching between particle i and ghost k is defined as:
/// deltaR_{i,k}=pT_i * sin(theta_i)^polarAngleExp * sqrt((y_i-y_k)^2 + (phi_i-phi_k)^2)
///
/// The class accounts for position-dependent (in rapidity-azimuth plane) background densities, rho and rho_m. The user is encouraged to use them.
///
class ConstituentSubtractor : public fastjet::Transformer{
public:
enum Distance {
deltaR, /// deltaR=sqrt((y_i-y_j)^2+(phi_i-phi_j)^2)), longitudinal Lorentz invariant
angle /// angle between two momenta in Euclidean space
};
/// default ctor
ConstituentSubtractor() :
_bge_rho(0), _bge_rhom(0), _common_bge(false), _rhom_from_bge_rhom(false), _externally_supplied_rho_rhom(false), _do_mass_subtraction(false), _distance(deltaR), _alpha(0), _polarAngleExp(0), _max_distance(-1), _use_max_distance(false),_ghost_area(0.01),_ghosts_constructed(false),_max_eta(0),_ghosts(0),_ghosts_area(0){}
/// Constructor that takes a pointer to a background estimator for rho and optionally a pointer to a background estimator for rho_m. If the latter is not supplied, rho_m is assumed to always be zero (this behaviour can be changed by calling use_common_bge_for_rho_and_rhom).
ConstituentSubtractor(fastjet::BackgroundEstimatorBase *bge_rho, fastjet::BackgroundEstimatorBase *bge_rhom=0, double alpha=0, double max_distance=-1, Distance distance=deltaR);
/// Constructor that takes an externally supplied value for rho and rho_m.
ConstituentSubtractor(double rho, double rhom=0, double alpha=0, double max_distance=-1, Distance distance=deltaR);
/// default dtor
virtual ~ConstituentSubtractor(){}
/// a description of what this class does
virtual std::string description() const;
/// action of the correction on a given jet. The output is PseudoJet object with subtracted constituents
virtual fastjet::PseudoJet result(const fastjet::PseudoJet &jet) const;
/// do the constituent subtraction for the input particles using the provided background proxies. The output is a vector with corrected particles - particles with zero corrected pt are removed.
std::vector<fastjet::PseudoJet> do_subtraction(std::vector<fastjet::PseudoJet> const &particles, std::vector<fastjet::PseudoJet> const &backgroundProxies,std::vector<fastjet::PseudoJet> *remaining_backgroundProxies=0) const;
/// do the subtraction of the whole event - more user-friendly approach. The particles with |eta|>max_eta are discarded at the beginning, i.e. they are not used, nor returned. The ghosts are added automatically inside this function up to max_eta.
std::vector<fastjet::PseudoJet> subtract_event(std::vector<fastjet::PseudoJet> const &particles, double max_eta);
/// do the subtraction of the whole event using the tracking information for charged particles, i.e. the 4-momenta of charged particles from signal vertex, and 4-momenta of charged particles from background. The user can set the scaling of charged particles from background and signal using parameters charged_background_scale (CBS) and charged_signal_scale (CSS). These scales are useful if one assumes correlation between charged and neutral particles or in case the inputs from calorimeter are miscalibrated wrt tracks. In case CBS=CSS=0, the input charged particles are not used. In case CBS=CSS=1, the input charged particles are not scaled. Recommending to try several combinations for CBS and CSS from range [0.8, 1.5]. It is no more necessary to provide background estimator. The GridMedianBackgroundEstimator is used - probably more flexibility will be added in the future. The rescaling function for background estimator can be also provided - the rescaling function will be used for the event after subtracting charged scaled particles.
std::vector<fastjet::PseudoJet> subtract_event_using_charged_info(std::vector<fastjet::PseudoJet> const &particles, double charged_background_scale, std::vector<fastjet::PseudoJet> const &charged_background, double charged_signal_scale, std::vector<fastjet::PseudoJet> const &charged_signal, double max_eta, fastjet::FunctionOfPseudoJet<double> *rescaling=0);
/// do the subtraction of the whole event in two steps: in the first step, very small max_distance is used (0.1), and in the second step larger max_distance is used (1) to subtract the remaining background proxies
std::vector<fastjet::PseudoJet> sequential_subtraction(std::vector<fastjet::PseudoJet> const &particles, double max_eta);
/// Set the pointer to a background estimator for rho and optionally a pointer to a background estimator for rho_m. If the latter is not supplied, rho_m is assumed to always be zero (this behaviour can be changed by calling use_common_bge_for_rho_and_rhom).
void set_background_estimator(fastjet::BackgroundEstimatorBase *bge_rho, fastjet::BackgroundEstimatorBase *bge_rhom=0);
/// Set the scalar background densities rho and rho_m.
void set_scalar_background_density(double rho, double rhom=0);
/// when only one background estimator, bge_rho, is specified, calling this function with argument true, causes rho_m to be calculated from the same background estimator as rho, instead of being set to zero. Currently this only works if the estimator is a JetMedianBackgroundEstimator or other estimator which has such function.
void set_common_bge_for_rho_and_rhom(bool value=true);
/// when two background estimators are used (one for rho, the second for rho_m), setting this to true will result in rho_m being estimated using bge_rhom->rho_m() instead of bge_rhom->rho().
void set_use_bge_rhom_rhom(bool value=true);
/// specify if also the mass term sqrt(pT^2+m^2)-pT should be corrected during the subtraction procedure. This is automatically set when calling functions set_common_bge_for_rho_and_rhom, set_scalar_background_density or set_use_bge_rhom_rhom
void set_do_mass_subtraction(bool value=true);
/// function to change the alpha-parameter figuring in the distance measure deltaR. The larger the alpha, the more are preferred to be corrected the low pt particles. The default value is 0, i.e. by default the standard deltaR definition is used: deltaR=sqrt(deltay^2 + deltaphi^2)
void set_alpha(double alpha);
/// function to change the parameter polarAngleExp
void set_polarAngleExp(double polarAngleExp);
/// function to change the parameter ghost_area
void set_ghost_area(double ghost_area);
/// function to change the distance type
void set_distance_type(Distance distance);
/// function to change the free parameter max_distance. The distance is defined by enum Distance. The particle-ghost pairs with distance>max_distance are not used. When max_distance<=0, the max_distance parameter is not used (no upper limit on distance). The default value is -1, i.e. by default there is no upper limit for possible distance values.
void set_max_distance(double max_distance);
/// function to change the free parameter max_distance_sequential for sequantial subtraction. This is the smaller maximal deltaR distance used in the first subtraction.
void set_max_distance_sequential(double max_distance_sequential);
/// function to return the maximal deltaR distance used in the subtraction
double get_max_distance();
/// This function returns true if the first argument is smaller than the second argument, otherwise returns false. The comparison is done only on the first element in the two pairs. This function is used to sort in ascending order the deltaR values for each pair particle-ghost while keeping track of particles and ghosts
static bool _function_used_for_sorting(std::pair<double,int> i,std::pair<double, int> j);
- protected:
+ /// Function to construct massless ghosts in the whole eta-phi space up to max_eta
void construct_ghosts_uniformly(double max_eta);
+
+
+ /// Function to return vector of ghosts
+ std::vector<fastjet::PseudoJet> get_ghosts();
+
+
+ /// Function to return vector of areas associated to ghosts
+ std::vector<double> get_ghosts_area();
+
+
+
+ protected:
std::vector<fastjet::PseudoJet> get_background_proxies_from_ghosts(std::vector<fastjet::PseudoJet> const &ghosts,std::vector<double> const &ghosts_area) const;
fastjet::BackgroundEstimatorBase *_bge_rho, *_bge_rhom;
bool _common_bge, _rhom_from_bge_rhom;
double _rho, _rhom;
bool _externally_supplied_rho_rhom, _do_mass_subtraction;
Distance _distance;
double _alpha;
double _polarAngleExp;
double _max_distance;
double _max_distance_sequential;
bool _use_max_distance;
double _ghost_area;
bool _ghosts_constructed;
double _max_eta;
std::vector<fastjet::PseudoJet> _ghosts;
std::vector<double> _ghosts_area;
static LimitedWarning _warning_unused_rhom;
};
} // namespace contrib
FASTJET_END_NAMESPACE
#endif // __FASTJET_CONTRIB_CONSTITUENTSUBTRACTOR_HH__
Index: contrib/contribs/ConstituentSubtractor/trunk/ChangeLog
===================================================================
--- contrib/contribs/ConstituentSubtractor/trunk/ChangeLog (revision 1021)
+++ contrib/contribs/ConstituentSubtractor/trunk/ChangeLog (revision 1022)
@@ -1,159 +1,186 @@
+2017-07-11 Peter Berta <berta@ipnp.troja.mff.cuni.cz>
+
+ * VERSION:
+ - Set version number to 1.1.6
+
+ * ConstituentSubtractor.cc
+ * ConstituentSubtractor.hh
+ - Implemented suggestion from Marta Verweij:
+ - Added new functions: "get_ghosts" and "get_ghosts_area". They return the vector of ghosts and the corresponding ghost areas used for whole event subtraction.
+ - Changed the function "construct_ghosts_uniformly" to be public
+ - Now the user does not need to provide the BackgroundEstimator to CS, but he/she can do background estimation independently and then assign the estimated background to ghosts. The procedure is the following:
+ - construct the ghosts with function "construct_ghosts_uniformly"
+ - get them with functions "get_ghosts" and "get_ghosts_area"
+ - do background estimation independently and assign the corresponding background estimates to ghosts
+ - use the function "do_subtraction" to subtract the modified ghosts from real particles.
+
+
+ * RescalingClasses.cc
+ * RescalingClasses.hh:
+ - Added new rescaling class template BackgroundRescalingYFromRootPhi - useful mainly for heavy ion events. The rapidity dependance is taken from a Root TH1 object provided by the user. The next parameters are used to parametrize the eliptic flow.
+
+
+ * example_background_rescaling.cc
+ - Added example for usage of the new rescaling class BackgroundRescalingYFromRootPhi (commented at the beginning of the macro).
+
+
+
2017-01-25 Gavin Salam <gavin.salam@cern.ch>
* VERSION:
updated VERSION to 1.1.5
* Makefile:
- resolved issue with make fragile-shared, caused by repeated
SRCS lines in the Makefile. Also removed other duplicates.
2017-01-20 Peter Berta <berta@ipnp.troja.mff.cuni.cz>
* VERSION:
- Set version number to 1.1.4
* ConstituentSubtractor.cc
- fixed rounding issues for zero masses, when doing the correction of term mtMinusPt
- more precise evaluation of corrected 4-momenta, which affected the mass of corrected particles with low masses
- added new function set_do_mass_subtraction
* ConstituentSubtractor.hh
- fixed initialization of member variable "_do_mass_subtraction"
- added new function set_do_mass_subtraction
* example_whole_event.ref, example_whole_event.cc:
- updated reference file. Added also all corrected particles.
* example_whole_event_using_charged_info.ref, example_whole_event_using_charged_info.cc:
- updated reference file. Added also all corrected particles.
2016-11-14 Peter Berta <berta@ipnp.troja.mff.cuni.cz>
* VERSION:
- Set version number to 1.1.3
* ConstituentSubtractor.cc
* ConstituentSubtractor.hh:
- Fixed bug in "do_subtraction" function for the unsubtracted background proxies.
- Added new function "sequential_subtraction" - for testing purposes so far, example will be added later. The ConstituentSubtraction is performed twice: first with small maximal allowed deltaR distance, then the background proxies are again uniformly redistributed and the ConstituentSubtraction runs second time with higher allowed maximal deltaR
- Added new function "set_distance_type". With this function, the user can change the definition of distance between particles and background proxies. There are two possibilities using enums Distance: deltaR (longitudinal Lorentz invariant distance in rapidity vs. phi) or angle (in Euclidean space). The default distance is deltaR, i.e. the same definition of distance as in previous versions.
* Makefile:
- Removed dependence on Root. Using template in RescalingClasses now.
* RescalingClasses.cc
* RescalingClasses.hh:
- Removed dependence on Root for the rescaling using TH1 histogram. Using template now. Also the name of the class changed. Old name: BackgroundRescalingYTH1. New name: BackgroundRescalingYFromRoot
- Changed the name of the rescaling class for heavy ion events. Old name: BackgroundRescalingYPhiHeavyIon. New name: BackgroundRescalingYPhi. Also the description of the rescaling function is updated.
* example_rescaling_using_TH1.cc
* example_rescaling_using_TH1.ref:
- Removed
* example_background_rescaling.cc
* example_background_rescaling.ref:
- Added new example for usage of Heavy Ion background rescaling function
- The file example_background_rescaling.cc contains also commented example for usage of rapidity rescaling according to root's TH1 distribution
* example_whole_event.cc:
- Updated this example with usage of the "set_distance_type" function.
2016-03-11 Peter Berta <berta@ipnp.troja.mff.cuni.cz>
* VERSION:
set version number to 1.1.2
* Makefile:
- added CXXFLAGS and LDFLAGS in case the "ROOTSYS" variable is defined from ROOT. In case it is not defined, the standard usage still works, just the RescalingClasses are not compiled.
* RescalingClasses.cc:
* RescalingClasses.hh:
- New files: contain classes for rho estimation rescaling. Two classes were added:
- BackgroundRescalingYTH1 - input is a TH1 object (stabdard histogram in ROOT) containg the actual rapidity dependence of backgound pt
- BackgroundRescalingYPhiHeavyIon - input are 8 parameters. The first four parameters parametrize the elliptic flow. The next four parameters parametrize the rapidity dependence using two Gaussian distributions
* example_rescaling_using_TH1.cc:
* example_rescaling_using_TH1.ref:
- New files: example in which the ConstituentSubtractor is used for the whole event subtraction using rapidity rescaling for the rho estimation. The input for rapidity rescaling is a TH1 object
2016-02-09 Peter Berta <berta@ipnp.troja.mff.cuni.cz>
* VERSION:
set version number to 1.1.1
* ConstituentSubtractor.hh:
* ConstituentSubtractor.cc:
- Faster algorithm for subtraction in the "do_subtraction" member function.
- New member function: subtract_event_using_charged_info
- whole event subtraction
- 4 additional inputs: two vectors of PseudoJets for charged background and charged signal, and two doubles, charged background scale (CBS) and charged signal scale (CSS)
- the scales CBS and CSS scale the input charged particles. Useful if one assumes correlation between charged and neutral particles or in case the inputs from calorimeter are miscalibrated wrt tracks. In case CBS=CSS=0, the input charged particles are not used. In case CBS=CSS=1, the input charged particles are not scaled. Recommending to try several combinations for CBS and CSS from range [0.8, 1.5].
- the background estimation is built in this function using GridMedianBackgroundEstimator with possibility to rescale
- see example file "example_whole_event_using_charged_info.cc" for usage
* example_whole_event_using_charged_info.cc:
* example_whole_event_using_charged_info.ref:
- New files: example in which the ConstituentSubtractor is used for the whole event subtraction using tracking information for charged particles
* functions.h:
- Updated function "read_event". Now, obtaining also the vectors of charged particles originating from signal and background.
2015-11-05 Peter Berta <berta@ipnp.troja.mff.cuni.cz>
* VERSION:
set version number to 1.1.0
* Makefile:
- added "-fPIC" CXX flag
* ConstituentSubtractor.hh:
* ConstituentSubtractor.cc:
- updated output for result(PseudoJet): copying the "user_index" from the input jet and its constituents to the output corrected jet and its constituents
- discarded the original max_deltaR parameter, and replaced it by parameter max_standardDeltaR defined as standardDeltaR=sqrt(deltay^2 + deltaphi^2). This new parameter restricts the usage of ghost-particle pairs which have too large distance standardDeltaR, i.e. not the distance deltaR which is the standardDeltaR multiplied by other factors as in the previous version.
- added a new multiplicative factor (sin(theta_i))^polarAngleExp into the definition of distance for a ghost-particle pair. Angle theta_i is the polar angle of partile i. The polarAngleExp is a free parameter with default value polarAngleExp=0, i.e. the default definition of deltaR has not changed wrt previous version. It can be changed using set_polarAngleExp member function
- changed the structure of the package and its member functions
- the standard usage with result(PseudoJet) is the same and it gives the same results as in previous version
- new member functions are available to simplify the whole event subtraction: subtract_event, set_background_estimator, set_scalar_background_density, see example file example_whole_event.cc
- similar changes as in GenericSubtractor due to FJ>=3.1:
- added set_common_bge_for_rho_and_rhom() and removed use_common_bge_for_rho_and_rhom()
- added set_use_bge_rhom_rhom() to tweak how rho_m is obtained when ConstituentSubtractor has been constructed with two estimators
- altered common_bge_for_rho_and_rhom() and added use_bge_rhom_rhom() to retrieve the behaviour
- added a warning when rhom is non-zero and unused
- Updated the terminology:
- ghosts - soft particles distributed with high density
- background proxies - particles used in the "do_subtraction" member function. They can be obtained from ghosts or in other way. Previously, these particles were also called "ghosts"
* example_whole_event.cc:
* example_whole_event.ref:
-new files: example in which the ConstituentSubtractor is used for the whole event
* functions.h:
-new file: contains useful functions for the example files
* example.hh:
-removed. Content moved to file functions.h
2014-04-06 Peter Berta <berta@ipnp.troja.mff.cuni.cz>
* VERSION
Release of version 1.0.0
Index: contrib/contribs/ConstituentSubtractor/trunk/example_background_rescaling.cc
===================================================================
--- contrib/contribs/ConstituentSubtractor/trunk/example_background_rescaling.cc (revision 1021)
+++ contrib/contribs/ConstituentSubtractor/trunk/example_background_rescaling.cc (revision 1022)
@@ -1,173 +1,194 @@
//
//----------------------------------------------------------------------
// Example on how to do pileup correction on the whole event
//
// run it with
-// ./example_rescaling_TH1 < ../data/Pythia-Zp2jets-lhc-pileup-1ev.dat
+// ./example_background_rescaling < ../data/Pythia-Zp2jets-lhc-pileup-1ev.dat
//----------------------------------------------------------------------
//
//----------------------------------------------------------------------
// This file is part of FastJet contrib.
//
// It is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at
// your option) any later version.
//
// It is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this code. If not, see <http://www.gnu.org/licenses/>.
//----------------------------------------------------------------------
#include "functions.hh"
#include "RescalingClasses.hh"
//#include "TH1D.h"
//#include "TF1.h"
using namespace std;
using namespace fastjet;
//----------------------------------------------------------------------
int main(){
- ///**** rescaling in heavy ion events: ****
+ ///**** rescaling in heavy ion events using rapidity dependence from TH1 histogram: ****
+ /// Set the seven parameters for rescaling using function
+ /// BackgroundRescalingYFromRootPhi(double v2, double v3, double v4, double psi, T* hist);
+ /// which is parametrized as
+ /// f(y,phi) = phi_term(phi) * rap_term(y)
+ /// where
+ /// phi_term(phi) = 1 + 2 * v2^2 * cos(2*(phi-psi)) + 2 * v3^2 * cos(3*(phi-psi)) + 2 * v4^2 * cos(4*(phi-psi))
+ /// with four parameters v2, v3, v4, and psi.
+ /// rap_term(y) = bin content of the histogram at position y
+ ///
+ /// You need to set the parameters event-by-event. Example where the TH1 histogram is filled with a random distribution. Do not use this histogram!!! Fill your own histogram with all particles (topoclusters) weighted by their pt using minimum bias events.
+ /*TH1D* hist=new TH1D("hist","",100,-5,5);
+ TF1 polynom("polynom","1+0.03*x*x-0.003*x*x*x*x",-5,5);
+ for (int i=1;i<hist->GetNbinsX()+1;i++){
+ hist->SetBinContent(i,polynom(hist->GetBinCenter(i)));
+ }
+ contrib::BackgroundRescalingYFromRootPhi<TH1D> rescaling(0.1,0.1,0.001,0,hist);
+ rescaling.use_rap_term(true); // this is useful to make sure that the histogram with rapidity dependence is defined. Set to false, if you do not want to use the rapidity rescaling
+ */
+
+
+ ///**** rescaling in heavy ion events using parametrized rapidity dependence: ****
// Set the seven parameters for rescaling using function
// BackgroundRescalingYPhi(double v2, double v3, double v4, double psi, double a1, double sigma1, double a2, double sigma2)
/// which is parametrized as
/// f(y,phi) = phi_term(phi) * rap_term(y)
/// where
/// phi_term(phi) = 1 + 2 * v2^2 * cos(2*(phi-psi)) + 2 * v3^2 * cos(3*(phi-psi)) + 2 * v4^2 * cos(4*(phi-psi))
/// with four parameters v2, v3, v4, and psi.
/// rap_term(y) = a1*exp(-pow(y,2)/(2*sigma1^2)) + a2*exp(-pow(y,2)/(2*sigma2^2))
/// with four parameters sigma1, sigma2, 1a, and a2.
///
/// You need to set the parameters event-by-event. Example:
contrib::BackgroundRescalingYPhi rescaling(0.1,0.1,0.001,0,1,5,0,10);
rescaling.use_rap_term(false); // set to true, if you have derived also the rapidity terms for the rescaling
///**** rescaling using rapidity dependence stored in root TH1 object: ****
// find the rapidity distribution of pileup particles from minimum bias events in a separate run. Fill a root TH1 histogram with this distribution.
// Here as an example where the TH1 histogram is filled with a random distribution. Do not use this!!! Fill it with all particles (topoclusters) weighted by their pt using minimum bias events.
/* TH1D* hist=new TH1D("hist","",100,-5,5);
TF1 polynom("polynom","1+0.03*x*x-0.003*x*x*x*x",-5,5);
for (int i=1;i<hist->GetNbinsX()+1;i++){
hist->SetBinContent(i,polynom(hist->GetBinCenter(i)));
}
contrib::BackgroundRescalingYFromRoot<TH1D> rescaling(hist);
*/
// set up before event loop:
contrib::ConstituentSubtractor subtractor;
subtractor.set_distance_type(contrib::ConstituentSubtractor::deltaR); // free parameter for the type of distance between particle i and ghost k. There are two options: "deltaR" or "angle" which are defined as deltaR=sqrt((y_i-y_k)^2+(phi_i-phi_k)^2) or Euclidean angle between the momenta
subtractor.set_max_distance(1); // free parameter for the maximal allowed distance between particle i and ghost k
subtractor.set_alpha(2); // free parameter for the distance measure (the exponent of particle pt). The larger the parameter alpha, the more are favoured the lower pt particles in the subtraction process
subtractor.set_ghost_area(0.01); // free parameter for the density of ghosts. The smaller, the better - but also the computation is slower.
// event loop
// read in input particles
vector<PseudoJet> hard_event, full_event;
read_event(hard_event, full_event);
double maxEta=4; // specify the maximal rapidity for the particles used in the subtraction
double maxEta_jet=3; // the maximal rapidity for selected jets
// keep the particles up to 4 units in rapidity
hard_event = SelectorAbsEtaMax(maxEta)(hard_event);
full_event = SelectorAbsEtaMax(maxEta)(full_event);
cout << "# read an event with " << hard_event.size() << " signal particles and " << full_event.size() - hard_event.size() << " background particles with pseudo-rapidity |eta|<4" << endl;
// do the clustering with ghosts and get the jets
//----------------------------------------------------------
JetDefinition jet_def(antikt_algorithm, 0.7);
AreaDefinition area_def(active_area_explicit_ghosts,GhostedAreaSpec(maxEta,1)); // the area definiton is used only for the jet backgroud estimator. It is not important for the ConstituentSubtractor when subtracting the whole event - this is not true when subtracting the individual jets
ClusterSequenceArea clust_seq_hard(hard_event, jet_def, area_def);
ClusterSequenceArea clust_seq_full(full_event, jet_def, area_def);
Selector sel_jets = SelectorNHardest(3) * SelectorAbsRapMax(maxEta_jet);
vector<PseudoJet> hard_jets = sel_jets(clust_seq_hard.inclusive_jets());
vector<PseudoJet> full_jets = sel_jets(clust_seq_full.inclusive_jets());
// create what we need for the background estimation
//----------------------------------------------------------
JetDefinition jet_def_for_rho(kt_algorithm, 0.4);
Selector rho_range = SelectorAbsEtaMax(maxEta-0.4);
// ClusterSequenceArea clust_seq_rho(full_event, jet_def, area_def);
JetMedianBackgroundEstimator bge_rho(rho_range, jet_def_for_rho, area_def);
BackgroundJetScalarPtDensity *scalarPtDensity=new BackgroundJetScalarPtDensity();
bge_rho.set_jet_density_class(scalarPtDensity); // this changes the computation of pt of patches from vector sum to scalar sum. The scalar sum seems more reasonable.
// setting the TH1 rescaling:
bge_rho.set_rescaling_class(&rescaling);
bge_rho.set_particles(full_event);
subtractor.set_background_estimator(&bge_rho);
// this sets the same background estimator to be used for deltaMass density, rho_m, as for pt density, rho:
subtractor.set_common_bge_for_rho_and_rhom(true); // for massless input particles it does not make any difference (rho_m is always zero)
cout << subtractor.description() << endl;
vector<PseudoJet> corrected_event=subtractor.subtract_event(full_event,maxEta);
ClusterSequenceArea clust_seq_corr(corrected_event, jet_def, area_def);
vector<PseudoJet> corrected_jets = sel_jets(clust_seq_corr.inclusive_jets());
// shape variables:
//----------------------------------------------------------
JetWidth width;
// subtract and print the result
//----------------------------------------------------------
cout << setprecision(4);
cout << "# original hard jets" << endl;
for (unsigned int i=0; i<hard_jets.size(); i++){
const PseudoJet &jet = hard_jets[i];
cout << "pt = " << jet.pt()
<< ", rap = " << jet.rap()
<< ", mass = " << jet.m()
<< ", width = " << width(jet) << endl;
}
cout << endl;
cout << "# unsubtracted full jets" << endl;
for (unsigned int i=0; i<full_jets.size(); i++){
const PseudoJet &jet = full_jets[i];
cout << "pt = " << jet.pt()
<< ", rap = " << jet.rap()
<< ", mass = " << jet.m()
<< ", width = " << width(jet) << endl;
}
cout << endl;
cout << "# subtracted full jets" << endl;
for (unsigned int i=0; i<corrected_jets.size(); i++){
const PseudoJet &jet = corrected_jets[i];
cout << "pt = " << jet.pt()
<< ", rap = " << jet.rap()
<< ", mass = " << jet.m()
<< ", width = " << width(jet) << endl;
}
cout << endl;
return 0;
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Nov 19, 6:18 PM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3805559
Default Alt Text
(73 KB)

Event Timeline