Index: contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_jet_by_jet.cc =================================================================== --- contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_jet_by_jet.cc (revision 0) +++ contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_jet_by_jet.cc (revision 1352) @@ -0,0 +1,136 @@ +// $Id$ +// +//---------------------------------------------------------------------- +// Example on how to use this contribution +// +// run it with +// ./example_jet_by_jet < ../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 . +//---------------------------------------------------------------------- + + +#include "fastjet/ClusterSequenceArea.hh" +#include "fastjet/Selector.hh" +#include "fastjet/tools/JetMedianBackgroundEstimator.hh" +#include "ConstituentSubtractor.hh" // In external code, this should be fastjet/contrib/ConstituentSubtractor.hh + +#include "functions.hh" + + +//---------------------------------------------------------------------- +int main(){ + + // It is highly recommended to use the ICS method instead of the jet-by-jet CS method since the ICS method has much better performance. The jet-by-jet CS is not developed anymore and this example may be out-of-date. If you still think the jet-by-jet CS is useful for you, please, contact the authors. + + + //---------------------------------------------------------- + // read in input particles + vector hard_event, full_event; + read_event(hard_event, full_event); + + // keep the particles up to 4 units in rapidity + hard_event = SelectorAbsRapMax(4.0)(hard_event); + full_event = SelectorAbsRapMax(4.0)(full_event); + + cout << "# read an event with " << hard_event.size() << " signal particles and " << full_event.size() - hard_event.size() << " background particles with rapidity |y|<4" << endl; + + + // do the clustering with ghosts and get the jets + //---------------------------------------------------------- + JetDefinition jet_def(antikt_algorithm, 0.7); + double ghost_area=0.01; // the density of ghosts can be changed through this variable + AreaDefinition area_def(active_area_explicit_ghosts,GhostedAreaSpec(4.0,1,ghost_area)); // in this step, the ghosts are added among the constituents of the 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(2) * SelectorAbsRapMax(3.0); + + vector hard_jets = sel_jets(clust_seq_hard.inclusive_jets()); + vector 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 = SelectorAbsRapMax(3.0); + 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. + bge_rho.set_particles(full_event); + + // subtractor: + //---------------------------------------------------------- + contrib::ConstituentSubtractor subtractor(&bge_rho); + + // by default, the masses of all particles are set to zero. + // 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(); + cout << subtractor.description() << endl; + + + + // shape variables: + //---------------------------------------------------------- + JetWidth width; + + // subtract and print the result + //---------------------------------------------------------- + cout << setprecision(4); + cout << "# original hard jets" << endl; + for (unsigned int i=0; i. +//---------------------------------------------------------------------- + +#ifndef __FASTJET_CONTRIB_CONSTITUENTSUBTRACTOR_RESCALINGCLASSES_HH__ +#define __FASTJET_CONTRIB_CONSTITUENTSUBTRACTOR_RESCALINGCLASSES_HH__ + + + +#include +#include +#include + +FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh + +namespace contrib{ + + + template + class BackgroundRescalingYFromRoot : public FunctionOfPseudoJet { + public: + /// + /// construct a background rescaling function using ROOT TH1 histogram bin contents (rapidity binning) + 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){ + throw Error("BackgroundRescalingYFromRoot (from ConstituentSubtractor) The histogram for rescaling not defined! "); + } + double rap = particle.rap(); + if (rap<_hist->GetXaxis()->GetBinLowEdge(1)) return _hist->GetBinContent(1); + if (rap>=_hist->GetXaxis()->GetBinUpEdge(_hist->GetNbinsX())) return _hist->GetBinContent(_hist->GetNbinsX()); + int bin=_hist->FindBin(rap); + return _hist->GetBinContent(bin); + } + + private: + T* _hist; + }; + + + + template + class BackgroundRescalingYPhiFromRoot : public FunctionOfPseudoJet { + public: + /// + /// construct a background rescaling function using ROOT TH2 histogram bin contents (rapidity vs azimuth binning) + BackgroundRescalingYPhiFromRoot(): _hist(0) {} + BackgroundRescalingYPhiFromRoot(T* hist=0) {_hist = hist;} + + // return the rescaling factor associated with this jet + virtual double result(const PseudoJet & particle) const { + if (!_hist){ + throw Error("BackgroundRescalingYPhiFromRoot (from ConstituentSubtractor) The histogram for rescaling not defined! "); + } + double rap = particle.rap(); + double phi = particle.phi(); + int xbin=1; + if (rap<_hist->GetXaxis()->GetBinLowEdge(1)) xbin=1; + else if (rap>=_hist->GetXaxis()->GetBinUpEdge(_hist->GetNbinsX())) xbin=_hist->GetNbinsX(); + else xbin=_hist->GetXaxis()->FindBin(rap); + int ybin=1; + if (phi<_hist->GetYaxis()->GetBinLowEdge(1) || phi>_hist->GetYaxis()->GetBinUpEdge(_hist->GetNbinsY())){ + throw Error("BackgroundRescalingYPhiFromRoot (from ConstituentSubtractor) The phi range of the histogram does not correspond to the phi range of the particles! Change the phi range of the histogram."); + } + else ybin=_hist->GetYaxis()->FindBin(phi); + return _hist->GetBinContent(xbin,ybin); + } + + private: + T* _hist; + }; + + + + + + template + class BackgroundRescalingYFromRootPhi : public FunctionOfPseudoJet { + 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){ + throw Error("BackgroundRescalingYFromRootPhi (from ConstituentSubtractor) Requested rapidity rescaling, but the histogram for rescaling is not defined!"); + } + } + + /// + /// 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 { + 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; + }; + + + + class BackgroundRescalingYPhiUsingVectorForY : public FunctionOfPseudoJet { + 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) = provided in a vector. + /// + /// The size of the input vector "values" for rapidity dependence is N bins and the corresponding binning should be specified in a separate input vector "rap_binning" of size (N+1). The bin boundaries must be in increasing order. + /// + /// 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). + + BackgroundRescalingYPhiUsingVectorForY(): _v2(0), _v3(0), _v4(0), _psi(0), _values(0), _rap_binning(0), _use_rap(false), _use_phi(false) {} + BackgroundRescalingYPhiUsingVectorForY(double v2, double v3, double v4, double psi, std::vector values, std::vector rap_binning); + + 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; + std::vector _values; + std::vector _rap_binning; + bool _use_rap, _use_phi; + }; + + + + class BackgroundRescalingYPhiUsingVectors : public FunctionOfPseudoJet { + public: + /// + /// Construct background rescaling function in rapidity and azimuth using dependence recorded in input object vector > values. Its size is N bins for rapidity and M bins for azimuth. The binning of the rapidity should be specified in a separate vector "rap_binning" of size (N+1), and similarly the binning of the azimuth should be specified in a separate vector "phi_binning" of size (M+1). The bin boundaries must be in increasing order. + /// + + BackgroundRescalingYPhiUsingVectors(): _values(0), _rap_binning(0), _phi_binning(0) {} + BackgroundRescalingYPhiUsingVectors(std::vector > values, std::vector rap_binning, std::vector phi_binning); + + void use_rap_term(bool use_rap); + void use_phi_term(bool use_phi); + + /// return the rescaling factor associate + virtual double result(const PseudoJet & particle) const; + private: + std::vector > _values; + std::vector _rap_binning; + std::vector _phi_binning; + bool _use_rap, _use_phi; + }; + + + +} // namespace contrib + +FASTJET_END_NAMESPACE + + +#endif //__FASTJET_CONTRIB_CONSTITUENTSUBTRACTOR_RESCALINGCLASSES_HH__ Index: contrib/contribs/ConstituentSubtractor/tags/1.4.6/AUTHORS =================================================================== --- contrib/contribs/ConstituentSubtractor/tags/1.4.6/AUTHORS (revision 0) +++ contrib/contribs/ConstituentSubtractor/tags/1.4.6/AUTHORS (revision 1352) @@ -0,0 +1,11 @@ +The ConstituentSubtractor FastJet contrib was written and is maintained and developed by + +Peter Berta +Martin Spousta +David W. Miller +Rupert Leitner + +See http://arxiv.org/abs/1403.3108 for all the details about the physics. + +For any questions or comments, please, contact: +peter.berta@cern.ch, Martin.Spousta@cern.ch, David.W.Miller@uchicago.edu Index: contrib/contribs/ConstituentSubtractor/tags/1.4.6/VERSION =================================================================== --- contrib/contribs/ConstituentSubtractor/tags/1.4.6/VERSION (revision 0) +++ contrib/contribs/ConstituentSubtractor/tags/1.4.6/VERSION (revision 1352) @@ -0,0 +1,2 @@ +1.4.6 + Index: contrib/contribs/ConstituentSubtractor/tags/1.4.6/ConstituentSubtractor.hh =================================================================== --- contrib/contribs/ConstituentSubtractor/tags/1.4.6/ConstituentSubtractor.hh (revision 0) +++ contrib/contribs/ConstituentSubtractor/tags/1.4.6/ConstituentSubtractor.hh (revision 1352) @@ -0,0 +1,329 @@ +// $Id$ +// +// ConstituentSubtractor package +// Questions/comments: berta@ipnp.troja.mff.cuni.cz, Martin.Spousta@cern.ch, David.W.Miller@uchicago.edu +// +// 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 . +//---------------------------------------------------------------------- + +#ifndef __FASTJET_CONTRIB_CONSTITUENTSUBTRACTOR_HH__ +#define __FASTJET_CONTRIB_CONSTITUENTSUBTRACTOR_HH__ + + +#include +#include +#include +#include +#include +#include +#include +#include "fastjet/tools/Transformer.hh" // to derive Subtractor from Transformer +#include "fastjet/LimitedWarning.hh" + +#include + +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_jet_by_jet.cc +/// For whole event background subtraction before jet clustering, see example_event_wide.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 to get the maximal performance. +/// +/// +/// For the treatment of massive particles, choose one of the following options (currently the default option is 3 which seems to be one of the most optimal in our studies): +/// 1. Keep the original mass and rapidity. Not recommended since jet mass is wrongly reconstructed. One can use it by adding before initialization: +/// subtractor.set_keep_original_masses(); +/// 2. Keep the original mass and pseudo-rapidity. Not recommended since jet mass is wrongly reconstructed. Use these two functions for this option: +/// subtractor.set_keep_original_masses(); +/// subtractor.set_fix_pseudorapidity(); +/// 3. Set all masses to zero. Keep rapidity unchanged. This is recommended and is the default option, since observed the best performance for high pt large-R jets. +/// Nothing needs to be specified. +/// 4. Set all masses to zero. Keep pseudo-rapidity unchanged. Also recommended, almost the same performance as for option 3. Use function: +/// subtractor.set_fix_pseudorapidity(); +/// 5. Do correction of m_delta=sqrt(p_T^2+m^2)-p_t. Not recommended. One can use it by adding before initialization: +/// subtractor.set_do_mass_subtraction(); +/// One must additionally provide option for the rho_m background estimation. There are several possibilities: +/// a) Same background estimator as for rho. Use this function: +/// subtractor.set_common_bge_for_rho_and_rhom(); // this must be used after set_background_estimator function. +/// b) Use a separate background estimator - you need to specify it as an additional parameter in function set_background_estimator +/// c) Use scalar background density using function set_scalar_background_density(double rho, double rhom). +/// 6. Same as 5 just keep pseudo-rapidity unchanged. Not recommended. Additionally to what is written for option 5, use: +/// subtractor.set_fix_pseudorapidity(); +/// 7. Keep rapidity and pseudo-rapidity fixed (scale fourmomentum). Recommended - observed better performance than the mass correction. Use: +/// subtractor.set_scale_fourmomentum(); + + + + namespace ConstituentSubtractorConstants{ + const double zero_pt=1e-50; // This pt value is considered as zero. It is used for corrected particles with zero pt. + const double zero_mass=1e-50; // This mass value is considered as zero. It is used for corrected particles with zero mass. + // By default particles with zero mass and pt are discarded in case their corrected pt and mass are zero. The user can use the function "set_remove_zero_pt_and_mass_particles(false)" to keep such partiles. + } + + + 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(); + + /// + /// 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(){} + + /// + /// initialization. use it before event loop. + virtual void initialize(); + + /// + /// Common description for jet-by-jet, event-wide, and iterative CS + void description_common(std::ostringstream &descr) const; + + /// + /// 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 and mass are removed by default. The user can modify this behaviour by using functions set_remove_particles_with_zero_pt_and_mass. + std::vector do_subtraction(std::vector const &particles, std::vector const &backgroundProxies,std::vector *remaining_backgroundProxies=0) const; + + + /// + /// this version should be not used. Use the version below. + virtual std::vector subtract_event(std::vector const &particles, double max_eta); + + /// + /// 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. + virtual std::vector subtract_event(std::vector const &particles, std::vector const *hard_proxies=0); + + /// + /// 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. The particles with |eta|>max_eta are discarded at the beginning, i.e. they are not used, nor returned. + std::vector subtract_event_using_charged_info(std::vector const &particles, double charged_background_scale, std::vector const &charged_background, double charged_signal_scale, std::vector const &charged_signal, double max_eta); + + + void set_rescaling(fastjet::FunctionOfPseudoJet *rescaling); + + /// + /// set the grid size (not area) for the background estimation with GridMedianBackgroundEstimator when using charged info + void set_grid_size_background_estimator(double const &grid_size_background_estimator); + + + /// + /// 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(); + + /// + /// This function should not be used anymore (instead the function above should be used without any parameter). When used with "true", then it has the same behaviour as set_common_bge_for_rho_and_rhom() above. By default, no mass subtraction is done, so it makes no sense to use this function with "false". + void set_common_bge_for_rho_and_rhom(bool value); + + + /// + /// By using this function, the original masses of particles are kept. By default, the masses of all particles are set to zero. If you do not want to set the masses to zero but you want to do the subtraction for the mass part, use the function set_common_bge_for_rho_and_rhom or specify background estimator for rho_m. + void set_keep_original_masses(); + + /// + /// 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); + + /// + /// With this function, the user specifies 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(); + + /// + /// set to true, if you want to remove particles which have zero both, pt and mass. By default, these particles are removed. + void set_remove_particles_with_zero_pt_and_mass(bool value=true); + + /// + /// set to true, if you want to remove all zero pt particles - this means removing also particles with zero delta_m (massive particles with zero pt). By default, the zero pt particles with non-zero delta_m are not removed. + void set_remove_all_zero_pt_particles(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. It is the same as the set_max_distance function. It is added back for backward-comptibility (since it was replaced in ConstituentSubtractor version 1.1.3 with function set_max_distance). It should be not used. + void set_max_standardDeltaR(double max_distance); + + /// + /// 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 > const &i,std::pair > const &j); + + /// + /// function used for sorting of Pseudojets according to eta + static bool _rapidity_sorting(fastjet::PseudoJet const &i,fastjet::PseudoJet const &j); + + /// + /// 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 get_ghosts(); + + /// + /// Function to set the maximal eta value for subraction + void set_max_eta(double max_eta); + + /// + /// Function to return vector of areas associated to ghosts + std::vector get_ghosts_area(); + + + /// + /// Set ghost selector - this allows to perform Constituent Subtraction in certain phase space when using the event-wide correction. Only ghosts which pass the selector are used in the correction. No selection is done on particles (i.e. the user needs to perform the selection before applying ConstituentSubtractor if he/she wishes). The default behaviour is to not use any selector. The user should remember that the max_eta restriction is applied in any case, e.g. when using the function "subtract_event(particles)", then ghosts are distributed to maximal eta max_eta and particles outside this region are discarded. + void set_ghost_selector(fastjet::Selector* selector); + + /// + /// Set particle selector - if specified, only particles which pass this selector are corrected. The other particles are copied to the final corrected vector without modification + void set_particle_selector(fastjet::Selector* selector); + + /// + /// Use this function if you want to use the information about hard particle proxies in the subtraction procedure (typically the charged tracks from primary vertex and/or high pt calorimeter clusters). The parameters of this function are the "nearby_hard_radius" and "nearby_hard_factor". If there is at least one hard particle proxy within Distance specified by the nearby_hard_radius parameter, then the CS distance is multiplied by nearby_hard_factor. + void set_use_nearby_hard(double const &nearby_hard_radius, double const &nearby_hard_factor); + + /// + /// Use this function, if you want to fix the pseudo-rapidity instead of rapidity for the corrected particles. By default, the rapidity is fixed. + void set_fix_pseudorapidity(); + + /// + /// Use this function if you want to fix both, pseudo-rapidity and rapidity. By default, rapidity is fixed and the mass is set to zero. + void set_scale_fourmomentum(); + + + protected: + std::vector get_background_proxies_from_ghosts(std::vector const &ghosts,std::vector const &ghosts_area) const; + void clear_ghosts(); + + /// + /// common function to initialize for Iterative and standard CS + void _initialize_common(); + + /// + /// helper functions to find the minimal and maximal indeces for the vector of particles - useful to make the CS procedure faster + unsigned int _find_index_after(double const &value, std::vector const &vec) const; + unsigned int _find_index_before(double const &value, std::vector const &vec) const; + + /// + /// function to get the trabsformed distance + double _get_transformed_distance(double const &distance) 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; + bool _remove_particles_with_zero_pt_and_mass; + bool _remove_all_zero_pt_particles; + bool _use_max_distance; + double _ghost_area; + double _grid_size_phi; + double _grid_size_rap; + bool _ghosts_constructed; + bool _ghosts_rapidity_sorted; + int _n_ghosts_phi; + double _max_eta; + bool _masses_to_zero; + bool _use_nearby_hard; + double _nearby_hard_radius; + double _nearby_hard_factor; + bool _fix_pseudorapidity; + bool _scale_fourmomentum; + std::vector const *_hard_proxies; + + std::vector _ghosts; + std::vector _ghosts_area; + std::vector _ghosts_rapidities; // used for uniform grid + double _grid_size_background_estimator; + fastjet::Selector *_ghost_selector; + fastjet::Selector *_particle_selector; + fastjet::FunctionOfPseudoJet *_rescaling; + static LimitedWarning _warning_unused_rhom; + }; + + + +} // namespace contrib + +FASTJET_END_NAMESPACE + +#endif // __FASTJET_CONTRIB_CONSTITUENTSUBTRACTOR_HH__ Property changes on: contrib/contribs/ConstituentSubtractor/tags/1.4.6/ConstituentSubtractor.hh ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_jet_by_jet.hh =================================================================== --- contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_jet_by_jet.hh (revision 0) +++ contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_jet_by_jet.hh (revision 1352) @@ -0,0 +1,2 @@ +// empty file +// This file was removed from svn which caused problems to release a new vesion. Now it is svn added back. Index: contrib/contribs/ConstituentSubtractor/tags/1.4.6/ChangeLog =================================================================== --- contrib/contribs/ConstituentSubtractor/tags/1.4.6/ChangeLog (revision 0) +++ contrib/contribs/ConstituentSubtractor/tags/1.4.6/ChangeLog (revision 1352) @@ -0,0 +1,540 @@ +2023-05-11 Peter Berta + + * VERSION: + - Set version number to 1.4.6 + + * ConstituentSubtractor.cc + - Fixed a bug for jet-by-jet Constituent Subtractor when using particle selector + - Copying also user_info for the corrected jet and corrected constituents + - Initializing previously not initialized variables (_nearby_hard_radius, _nearby_hard_factor) + +2020-02-23 Peter Berta + + * VERSION: + - Set version number to 1.4.5 + + * ConstituentSubtractor.cc + * IterativeConstituentSubtractor.cc + - Further removal of C++11 extensions which were missed previously (std::end and std::begin) + + +2019-07-15 Peter Berta + + * VERSION: + - Set version number to 1.4.4 + + * ConstituentSubtractor.hh + * IterativeConstituentSubtractor.hh + - Removed C++11 extensions + + + + + +2019-07-09 Peter Berta + + * VERSION: + - Set version number to 1.4.3 + + * ConstituentSubtractor.cc + * ConstituentSubtractor.hh + * IterativeConstituentSubtractor.cc + * IterativeConstituentSubtractor.hh + - Removed C++11 extensions + - Changed the way how the user should specify that he/she wants to do delta_m correction. Now, additionally the "set_do_mass_correction" function must be called + - Updated information about the treatment of massive inputs. + + + * example_event_wide.cc + * example_iterative.cc + - Updated information about the treatment of massive inputs. No changes in the code + + + * example_jet_by_jet.cc + - small updates to the commented lines + + + +2019-07-04 Peter Berta + + * VERSION: + - Set version number to 1.4.2 + + * example_event_wide.cc + * example_iterative.cc + * ConstituentSubtractor.hh + - Updated information about the treatment of massive inputs. No changes in the code + + + +2019-06-21 Peter Berta + + * VERSION: + - Set version number to 1.4.1 + + * ConstituentSubtractor.cc + * ConstituentSubtractor.hh + - Updated the treatment of additional background estimator for rho_m. Currently in ConstituentSubtractor, only such rho_m background estimators are supported which have member function rho_m(), i.e. the result from member function has_rho_m() is true (which is available since fastjet version 30100). + + + + +2019-06-19 Peter Berta + + * VERSION: + - Set version number to 1.4.0 + + * ConstituentSubtractor.cc + * ConstituentSubtractor.hh + - Added more possibilities for treatment of massive particles and information about them + - Using value _zero_pt=1e-40 for particles with corrected pt of 0 and value _zero_mass=1e-50 for particles with corrected mass of 0. + - Added possibility to use particle selector - all particles which pass the particle selector are corrected, while the particles which do not pass, are returned unmodified + - Updated description + + * IterativeConstituentSubtractor.cc + - Updated description + - Added possibility to use particle selector + + * example_event_wide.ref + * example_event_wide.cc + - Renamed from example_whole_event.cc(ref) + - Now setting the masses to zero + - Added example to use particle selector + - Added detailed explanation what options are available for massive particles + + * example_iterative.ref + * example_iterative.cc + - Added detailed explanation what options are available for massive particles + - Now setting the masses to zero in the ICS correction + - Added example how to use particle selector + + * example_jet_by_jet.ref + * example_jet_by_jet.cc + - Renamed from example.cc(ref) + - Now setting the masses to zero + + +2019-03-28 Peter Berta + + * VERSION: + - Set version number to 1.3.2 + + * ConstituentSubtractor.cc + * ConstituentSubtractor.hh + - Added functions for possible usage of information about hard proxies + - Added function to set if the user wants to keep the original masses (i.e. no mass subtraction and no setting to zero). By default, the masses are set to zero. + - Added instructions, how can the masses be treated, at the beggining of ConstituentSubtractor.hh + - Added new function set_common_bge_for_rho_and_rhom() which should be used when the user wants to do mass subtraction with the same background estimator as for pt subtraction. This replaces the set_common_bge_for_rho_and_rhom(bool value=true) function which should be not used anymore. Currently both function give the same results. The function set_common_bge_for_rho_and_rhom(bool value=true) will be removed in the future. + - Updated ConstituentSubtractor::description + - Speed optimization + + + + * IterativeConstituentSubtractor.cc + * IterativeConstituentSubtractor.hh + - Added functions for possible usage of information about hard proxies + + + * example_whole_event_iterative.cc + * example_whole_event.cc + - Added information how can the masses be treated and examples + - Added examples how to use the information about hard proxies + + + * example.cc + * example_background_rescaling.cc + * example_whole_event_using_charged_info.cc + - Usage of new function set_common_bge_for_rho_and_rhom() + + + * example_whole_event.ref + * example.ref + * example_whole_event_using_charged_info.ref + - Updated references because the ConstituentSubtractor::description was updated + + + +2018-06-28 Peter Berta + + * VERSION: + - Set version number to 1.3.1 + + * example_whole_event_iterative.cc + * example_whole_event.cc + * example_background_rescaling.cc + * example_background_rescaling.ref + - updated comments + + + + +2018-06-25 Peter Berta + + * VERSION: + - Set version number to 1.3.0 + + * ConstituentSubtractor.cc + * ConstituentSubtractor.hh + - Removed the functions related to the so-called "sequential" correction (renamed and put it in IterativeConstituentSubtractor.hh/.cc) + - Added function with name "initialize" and "set_max_eta" which should be used for the whole event correction, see example example_whole_event.cc + + * example_whole_event.cc + - Updated usage of the whole event correction. The users are encouraged to update to this new usage. So far the old and new usage have the same behaviour. + + * example_whole_event_sequential.cc + * example_whole_event_sequential.ref + - Removed. + + * IterativeConstituentSubtractor.cc + * IterativeConstituentSubtractor.hh + * example_whole_event_iterative.cc + * example_whole_event_iterative.ref + - New files + + * Makefile + - Added the compilation of the two new files and updated name for the example + + + +2018-06-12 Peter Berta + + * VERSION: + - Set version number to 1.2.8 + + * ConstituentSubtractor.cc + * ConstituentSubtractor.hh + - Added new function: clean_ghosts. Now when setting new selector, the current ghosts are removed - then when doing subtraction, new ghosts are constructed. + - Updated sequential CS: + - Added possibility to perform CS procedure any number of times (previously only twice). Now, the maximal distance and alphas should be specified as vectors using function "set_sequential_parameters" + - Added possibility to remove the unsubtracted ghosts (proxies) from the previous CS procedure for the next application of CS procedure + + + * example_whole_event_sequential.cc + * example_whole_event_sequential.ref + * Makefile + - Added example for the sequential CS + + + + +2018-05-04 Peter Berta + + * VERSION: + - Set version number to 1.2.7 + + * ConstituentSubtractor.cc + * ConstituentSubtractor.hh + - Added possibility to perform whole event correction in a certain phase space defined by input Selector + - Added possibity to change the grid size for GridMedianBackgroundEstimator when using charged info - the default value is now 0.5 + - Faster correction in case the distance is ConstituentSubtractor::angle + + * example_whole_event.cc + * example_whole_event_using_charged_info.cc + - Updated examples + + * example_whole_event.ref + * example_whole_event_using_charged_info.ref + - Updated references to correspond to updated examples + + + + +2018-05-03 Peter Berta + + * VERSION: + - Set version number to 1.2.6 + + * example.cc + * example_whole_event.cc + * example_background_rescaling.cc + * example_whole_event_using_charged_info.cc + * functions.hh + - Updated examples and added more comments + + * example.ref + * example_whole_event.ref + * example_background_rescaling.ref + * example_whole_event_using_charged_info.ref + - Updated references to correspond to updated examples + + + +2018-04-11 Peter Berta + + * VERSION: + - Set version number to 1.2.5 + + * ConstituentSubtractor.cc + - Fixed bug causing seg fault in ATLAS. The seg fault happened very rarely for events in which the particle with minimal or maximal rapidity had had rapidity of special value (dependent on the parameters of ConstituentSubtractor). + + * functions.hh + - In read_event added possibility to read event in format (pt, rap, phi, pid, charge) assuming zero masses. + +2017-12-18 Peter Berta + + * VERSION: + - Set version number to 1.2.4 + + * ConstituentSubtractor.cc + * ConstituentSubtractor.hh + - Added function set_remove_zero_pt_and_mtMinusPt_particles. When set to true, all particles are kept in the output. If set to false (default), the particles with zero pt and zero mtMinusPt are removed. + + * Makefile + - Added back the test example_whole_event_using_charged_info. + + * example_whole_event_using_charged_info.cc + * example_whole_event_using_charged_info.ref + - using set_remove_zero_pt_and_mtMinusPt_particles(false), printing more digits for the output, and changed the reference. Now this test is successful also for Gavin Salam. + + +2017-09-08 Peter Berta + + * VERSION: + - Set version number to 1.2.3 + + * ConstituentSubtractor.cc + - In the previous version the zero pt massive corrected particles had pt set to 1e-200. This caused a warning when the active area was used during clustering. Now, the zero pt is set to 1e-50, which removed the warning. + + * Makefile + - Temporarily removed the test example_whole_event_using_charged_info. The reason is that it gives different output particles when running on MacOS 10.12.6, Apple LLVM version 8.1.0 (clang-802.0.42) as Gavin Salam found. The difference is tiny: one zero pt and zero mass particle appears additionally when running on MAC, which has no impact on the performance of the correction. + + +2017-08-21 Peter Berta + + * VERSION: + - Set version number to 1.2.2 + + * ConstituentSubtractor.cc + * ConstituentSubtractor.hh + - Added function set_max_standardDeltaR for backward compatibility. It was replaced in version 1.1.3 by function set_max_distance. In this version, it does the same as the function set_max_distance. + - Further speed improvement for whole event subtraction (especially for small _max_distance parameters, such as 0.25) + + + + +2017-08-07 Peter Berta + + * VERSION: + - Set version number to 1.2.1 + + * ConstituentSubtractor.cc + - Fixed bug for the distance enum ConstituentSubtractor::angle. Previously, the optimized rapidity ranges were used also for this distance type which was wrong. Now, the whole rapidity range is used (without optimization). + - Checking if ghosts are constructed for the jet-by-jet subtraction. In case they are constructed, error is thrown since such ConstituentSubtractor should be used only for whole event subtraction, and not jet-by-jet. + + + +2017-07-20 Peter Berta + + * VERSION: + - Set version number to 1.2.0 + + * ConstituentSubtractor.cc + * ConstituentSubtractor.hh + - Important change for the output corrected particles in case of correction of massive particles. The corrected zero pt particles with non-zero corrected delta_m (massive particles in rest) are now included in the output. Previously, all the zero pt corrected particles were discarded. Now, only the zero pt and zero delta_m corrected particles are discarded. The corrected particles with zero pt and non-zero delta_m are kept (their pt is set to very small value (1e-200 GeV)). This should have better performance for jet energy and jet mass. If the user wants, he/she can still discard those zero pt particles in his/her own code, e.g. by requiring particles with pt > 1e-100 GeV. + - Implemented changes to significantly increase the speed of the CS algorithm for the whole event subtraction. The performance is exactly the same. Only the speed is much higher. For small values of _max_distance parameter, the speed is now ~10-times higher. For larger values of the _max_distance parameter, the speed is ~2-times higher. + + * RescalingClasses.cc + * RescalingClasses.hh: + - Added new rescaling classes: + - BackgroundRescalingYPhiFromRoot - rescaling of background using Root TH2 histogram binned in rapidity vs azimuth + - BackgroundRescalingYPhiUsingVectorForY - rescaling of background for heavy ions - using eliptic flow parameters and rapidity dependence recorded in a vector + - BackgroundRescalingYPhiUsingVectors - rescaling of background using objcet vector > containing the rapidity vs azimuth dependence + + * example_background_rescaling.cc + - Added more examples for usage of rescaling classes + + * example_background_rescaling.ref + * example.ref + * example_whole_event.ref + * example_whole_event_using_charged_info.ref + - Updated example outputs due to the inclusion of massive zero pt corrected particles in the output. + + + + +2017-07-11 Peter Berta + + * 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 + + * 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 + + * 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 + + * 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 + + * 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 + + * 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 + + * 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 + + * VERSION + Release of version 1.0.0 Index: contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_event_wide.cc =================================================================== --- contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_event_wide.cc (revision 0) +++ contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_event_wide.cc (revision 1352) @@ -0,0 +1,188 @@ +// $Id$ +// +//---------------------------------------------------------------------- +// Example on how to do pileup correction on the whole event +// +// run it with +// ./example_whole_event < ../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 . +//---------------------------------------------------------------------- + + +#include "fastjet/ClusterSequence.hh" +#include "fastjet/Selector.hh" +#include "fastjet/tools/GridMedianBackgroundEstimator.hh" +#include "ConstituentSubtractor.hh" // In external code, this should be fastjet/contrib/ConstituentSubtractor.hh + +#include "functions.hh" + + +using namespace std; +using namespace fastjet; + +//---------------------------------------------------------------------- +int main(){ + // set up before event loop: + double max_eta=4; // specify the maximal pseudorapidity for the input particles. It is used for the subtraction. Particles with eta>|max_eta| are removed and not used during the subtraction (they are not returned). The same parameter should be used for the GridMedianBackgroundEstimator as it is demonstrated in this example. If JetMedianBackgroundEstimator is used, then lower parameter should be used (to avoid including particles outside this range). + double max_eta_jet=3; // the maximal pseudorapidity for selected jets. Not used for the subtraction - just for the final output jets in this example. + + // background estimator + GridMedianBackgroundEstimator bge_rho(max_eta,0.5); // Maximal pseudo-rapidity cut max_eta is used inside ConstituentSubtraction, but in GridMedianBackgroundEstimator, the range is specified by maximal rapidity cut. Therefore, it is important to apply the same pseudo-rapidity cut also for particles used for background estimation (specified by function "set_particles") and also derive the rho dependence on rapidity using this max pseudo-rapidity cut to get the correct rescaling function! + + 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(0.3); // free parameter for the maximal allowed distance between particle i and ghost k + subtractor.set_alpha(1); // 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. + subtractor.set_max_eta(max_eta); // parameter for the maximal eta cut + subtractor.set_background_estimator(&bge_rho); // specify the background estimator to estimate rho. + + + /// For the treatment of massive particles, choose one of the following options (currently the default option is 3 which seems to be one of the most optimal in our studies): + /// 1. Keep the original mass and rapidity. Not recommended since jet mass is wrongly reconstructed. One can use it by adding before initialization: + /// subtractor.set_keep_original_masses(); + /// 2. Keep the original mass and pseudo-rapidity. Not recommended since jet mass is wrongly reconstructed. Use these two functions for this option: + /// subtractor.set_keep_original_masses(); + /// subtractor.set_fix_pseudorapidity(); + /// 3. Set all masses to zero. Keep rapidity unchanged. This is recommended and is the default option, since observed the best performance for high pt large-R jets. + /// Nothing needs to be specified. + /// 4. Set all masses to zero. Keep pseudo-rapidity unchanged. Also recommended, almost the same performance as for option 3. Use function: + /// subtractor.set_fix_pseudorapidity(); + /// 5. Do correction of m_delta=sqrt(p_T^2+m^2)-p_t. Not recommended. One can use it by adding before initialization: + /// subtractor.set_do_mass_subtraction(); + /// One must additionally provide option for the rho_m background estimation. There are several possibilities: + /// a) Same background estimator as for rho. Use this function: + /// subtractor.set_common_bge_for_rho_and_rhom(); // this must be used after set_background_estimator function. + /// b) Use a separate background estimator - you need to specify it as an additional parameter in function set_background_estimator + /// c) Use scalar background density using function set_scalar_background_density(double rho, double rhom). + /// 6. Same as 5 just keep pseudo-rapidity unchanged. Not recommended. Additionally to what is written for option 5, use: + /// subtractor.set_fix_pseudorapidity(); + /// 7. Keep rapidity and pseudo-rapidity fixed (scale fourmomentum). Recommended - observed better performance than the mass correction. Use: + /// subtractor.set_scale_fourmomentum(); + + + // example selector for ConstituentSubtractor: + //Selector sel_CS_correction = SelectorPhiRange(0,3) * SelectorEtaMin(-1.5) * SelectorEtaMax(0); + // subtractor.set_ghost_selector(&sel_CS_correction); // uncomment in case you want to use ghost selector. Only ghosts fulfilling this selector will be constructed. No selection on input particles is done. The selection on input particles is the responsibility of the user, or the user can use the "set_particle_selector" function. However, the maximal eta cut (specified with "set_max_eta" function) is done always for both, ghosts and input particles. + // subtractor.set_particle_selector(&sel_CS_correction); // uncomment in case you want to use particle selector. Only particles fulfilling this selector will be corrected. The other particles will be unchanged. However, the maximal eta cut (specified with "set_max_eta" function) is done always for both, ghosts and input particles. + + Selector sel_max_pt = SelectorPtMax(15); + subtractor.set_particle_selector(&sel_max_pt); // only particles with pt<15 will be corrected - the other particles will be copied without any changes. + + // If you want to use the information about hard proxies (typically charged tracks from primary vertex and/or high pt calorimeter clusters), then use this line: + //subtractor.set_use_nearby_hard(0.2,2); // In this example, if there is a hard proxy within deltaR distance of 0.2, then the CS distance is multiplied by factor of 2, i.e. such particle is less favoured in the subtraction procedure. If you uncomment this line, then also uncomment line 106. + + subtractor.initialize(); + // print info (optional) + cout << subtractor.description() << endl; + + + + + // in event loop: + // read in input particles + vector hard_event, full_event; + vector *hard_event_charged=new vector; + vector *background_event_charged=new vector; + read_event(hard_event, full_event, hard_event_charged, background_event_charged); + + hard_event = SelectorAbsEtaMax(max_eta)(hard_event); + full_event = SelectorAbsEtaMax(max_eta)(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; + + + // jet definition and selector for jets + JetDefinition jet_def(antikt_algorithm, 0.7); + Selector sel_jets = SelectorNHardest(3) * SelectorAbsEtaMax(max_eta_jet); + + // clustering of the hard-scatter event and uncorrected event + ClusterSequence clust_seq_hard(hard_event, jet_def); + ClusterSequence clust_seq_full(full_event, jet_def); + vector hard_jets = sel_jets(clust_seq_hard.inclusive_jets()); + vector full_jets = sel_jets(clust_seq_full.inclusive_jets()); + + bge_rho.set_particles(full_event); + + // the correction of the whole event with ConstituentSubtractor + vector corrected_event=subtractor.subtract_event(full_event); + // if you want to use the information about hard proxies, use this version: + // vector corrected_event=subtractor.subtract_event(full_event,hard_event_charged); // here all charged hard particles are used for hard proxies. In real experiment, this corresponds to charged tracks from primary vertex. Optionally, one can add among the hard proxies also high pt calorimeter clusters after some basic pileup correction. + + // clustering of the corrected event + ClusterSequence clust_seq_corr(corrected_event, jet_def); + vector corrected_jets = sel_jets(clust_seq_corr.inclusive_jets()); + + + ios::fmtflags f( cout.flags() ); + cout << setprecision(4) << fixed; + cout << endl << "Corrected particles in the whole event:" << endl; + for (unsigned int i=0; i_initialize_common(); + } + + + + std::vector IterativeConstituentSubtractor::subtract_event(std::vector const &particles, double max_eta){ + throw Error("IterativeConstituentSubtractor::subtract_event(): This version of subtract_event should not be used. Use the version subtract_event(std::vector const &particles)"); + std::vector subtracted_particles; + return subtracted_particles; + } + + + + std::vector IterativeConstituentSubtractor::subtract_event(std::vector const &particles, std::vector const *hard_proxies){ + bool original_value_of_ghosts_rapidity_sorted=_ghosts_rapidity_sorted; + if (_use_nearby_hard_iterative){ + if (hard_proxies) _hard_proxies=hard_proxies; + else throw Error("IterativeConstituentSubtractor::subtract_event: It was requested to use closeby hard proxies but they were not provided in this function!"); + } + else if (hard_proxies) throw Error("IterativeConstituentSubtractor::subtract_event: Hard proxies were provided but the set_use_hard_proxies function was not used before initialization. It needs to be called before initialization!"); + + std::vector backgroundProxies=this->get_background_proxies_from_ghosts(_ghosts,_ghosts_area); + std::vector subtracted_particles,unselected_particles; + for (unsigned int iparticle=0;iparticle_max_eta) continue; + if (particles[iparticle].pt()pass(particles[iparticle])) subtracted_particles.push_back(particles[iparticle]); + else unselected_particles.push_back(particles[iparticle]); + } + else subtracted_particles.push_back(particles[iparticle]); + } + for (unsigned int iteration=0;iteration<_max_distances.size();++iteration){ + this->set_max_distance(_max_distances[iteration]); + this->set_alpha(_alphas[iteration]); + if (_use_nearby_hard_iterative) this->set_use_nearby_hard(_nearby_hard_radii[iteration],_nearby_hard_factors[iteration]); + std::vector *remaining_backgroundProxies=0; + if (iteration!=_max_distances.size()-1) remaining_backgroundProxies=new std::vector; // do not need to estimate the remaining background for the last iteration + subtracted_particles=this->do_subtraction(subtracted_particles,backgroundProxies,remaining_backgroundProxies); + + if (iteration==_max_distances.size()-1){ + continue; // do not need to estimate the remaining background for the last iteration + } + + double background_pt=0,background_mt=0, remaining_background_pt=0,remaining_background_mt=0; + int backgroundProxies_original_size=backgroundProxies.size(); + for (int i=backgroundProxies_original_size-1;i>=0;--i){ + remaining_background_pt+=(remaining_backgroundProxies->at(i)).pt(); + remaining_background_mt+=(remaining_backgroundProxies->at(i)).mt(); + if (_ghost_removal && (remaining_backgroundProxies->at(i)).pt()>1e-10){ + backgroundProxies[i]=backgroundProxies[backgroundProxies.size()-1]; + backgroundProxies.pop_back(); + } + else{ + background_pt+=backgroundProxies[i].pt(); + background_mt+=backgroundProxies[i].mt(); + } + } + delete remaining_backgroundProxies; + if (_ghost_removal) _ghosts_rapidity_sorted=false; // After erasing some elements from vector backgroundProxies, we cannot use the speed optimization in do_subtraction function, therefore setting _ghosts_rapidity_sorted to false. + for (unsigned int i=0;ibackground_pt+1e-20) mtMinusPt=(backgroundProxies[i].mt()-backgroundProxies[i].pt())*(remaining_background_mt-remaining_background_pt)/(background_mt-background_pt); + double mass=0; + if (mtMinusPt>1e-20) mass=sqrt(pow(mtMinusPt+pt,2)-pow(pt,2)); + backgroundProxies[i].reset_momentum_PtYPhiM(pt,backgroundProxies[i].rap(),backgroundProxies[i].phi(),mass); + } + } + _ghosts_rapidity_sorted=original_value_of_ghosts_rapidity_sorted; // Setting _ghosts_rapidity_sorted to its original value + if (_particle_selector) subtracted_particles.insert(subtracted_particles.end(), unselected_particles.begin(), unselected_particles.end()); + return subtracted_particles; + } + + + std::string IterativeConstituentSubtractor::description() const{ + std::ostringstream descr; + descr << std::endl << "Description of fastjet::IterativeConstituentSubtractor:" << std::endl; + this->description_common(descr); + descr << " IterativeConstituentSubtractor parameters: " << std::endl; + for (unsigned int iteration=0;iteration<_max_distances.size();++iteration){ + descr << " Iteration " << iteration+1 << ": max_distance = " << _max_distances[iteration] << " alpha = " << _alphas[iteration] << std::endl; + } + return descr.str(); + } + + + + void IterativeConstituentSubtractor::set_parameters(std::vector const &max_distances, std::vector const &alphas){ + if (max_distances.size()!=alphas.size()) throw Error("IterativeConstituentSubtractor::set_parameters(): the provided vectors have different size. They should have the same size."); + if (max_distances.size()==0 || alphas.size()==0) throw Error("IterativeConstituentSubtractor::set_parameters(): One of the provided vectors is empty. They should be not empty."); + _max_distances=max_distances; + _alphas=alphas; + } + + + void IterativeConstituentSubtractor::set_nearby_hard_parameters(std::vector const &nearby_hard_radii, std::vector const &nearby_hard_factors){ + if (nearby_hard_radii.size()!=nearby_hard_factors.size()) throw Error("IterativeConstituentSubtractor::set_use_nearby_hard(): the provided vectors have different size. They should have the same size."); + if (nearby_hard_radii.size()==0 || nearby_hard_factors.size()==0) throw Error("IterativeConstituentSubtractor::set_use_nearby_hard(): One of the provided vectors is empty. They should be not empty."); + _nearby_hard_radii=nearby_hard_radii; + _nearby_hard_factors=nearby_hard_factors; + _use_nearby_hard_iterative=true; + } + + + + void IterativeConstituentSubtractor::set_ghost_removal(bool ghost_removal){ + _ghost_removal=ghost_removal; + } + + + +} // namespace contrib + + +FASTJET_END_NAMESPACE Index: contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_iterative.cc =================================================================== --- contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_iterative.cc (revision 0) +++ contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_iterative.cc (revision 1352) @@ -0,0 +1,202 @@ +// +//---------------------------------------------------------------------- +// Example on how to do pileup correction on the whole event +// +// run it with +// ./example_whole_event_iterative < ../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 . +//---------------------------------------------------------------------- + + +#include "fastjet/ClusterSequence.hh" +#include "fastjet/Selector.hh" +#include "fastjet/tools/GridMedianBackgroundEstimator.hh" +#include "IterativeConstituentSubtractor.hh" // In external code, this should be fastjet/contrib/IterativeConstituentSubtractor.hh + +#include "functions.hh" + + +using namespace std; +using namespace fastjet; + +//---------------------------------------------------------------------- +int main(){ + // This should be set up before event loop: + double max_eta=4; // specify the maximal pseudorapidity for the input particles. It is used for the subtraction. Particles with eta>|max_eta| are removed and not used during the subtraction (they are not returned). The same parameter should be used for the GridMedianBackgroundEstimator as it is demonstrated in this example. If JetMedianBackgroundEstimator is used, then lower parameter should be used (to avoid including particles outside this range). + double max_eta_jet=3; // the maximal pseudorapidity for selected jets. Not important for the subtraction. + + // background estimator + GridMedianBackgroundEstimator bge_rho(max_eta,0.5); // maximal pseudo-rapidity cut is used inside ConstituentSubtraction, but in GridMedianBackgroundEstimator, the range is specified by maximal rapidity cut. Therefore, it is important to apply the same pseudo-rapidity cut also for particles used for background estimation (using function "set_particles") and also derive the rho dependence on rapidity using this max pseudo-rapidity cut to get the correct rescaling function! + + contrib::IterativeConstituentSubtractor 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 + vector max_distances; + max_distances.push_back(0.15); + max_distances.push_back(0.2); + vector alphas; + alphas.push_back(1); + alphas.push_back(1); + subtractor.set_parameters(max_distances,alphas); // in this example, 2 CS corrections will be performed: 1. correction with max_distance of 0.1 and alpha of 0, 2. correction with max_distance of 0.15 and alpha of 0. After the first correction, the scalar sum of pt from remaining ghosts is evaluated and redistributed uniformly accross the event. + subtractor.set_ghost_removal(true); // set to true if the ghosts (proxies) which were not used in the previous CS procedure should be removed for the next CS procedure + subtractor.set_ghost_area(0.004); // parameter for the density of ghosts. The smaller, the better - but also the computation is slower. + subtractor.set_max_eta(max_eta); // parameter for maximal |eta| cut. It is specified above. + subtractor.set_background_estimator(&bge_rho); // specify the background estimator to estimate rho. You can use also specify background estimator for the mass term as an additional parameter + + + /// For the treatment of massive particles, choose one of the following options (currently the default option is 3 which seems to be one of the most optimal in our s tudies): +/// 1. Keep the original mass and rapidity. Not recommended since jet mass is wrongly reconstructed. One can use it by adding before initialization: +/// subtractor.set_keep_original_masses(); +/// 2. Keep the original mass and pseudo-rapidity. Not recommended since jet mass is wrongly reconstructed. Use these two functions for this option: +/// subtractor.set_keep_original_masses(); +/// subtractor.set_fix_pseudorapidity(); +/// 3. Set all masses to zero. Keep rapidity unchanged. This is recommended and is the default option, since observed the best performance for high pt large-R jets. +/// Nothing needs to be specified. +/// 4. Set all masses to zero. Keep pseudo-rapidity unchanged. Also recommended, almost the same performance as for option 3. Use function: +/// subtractor.set_fix_pseudorapidity(); +/// 5. Do correction of m_delta=sqrt(p_T^2+m^2)-p_t. Not recommended. One can use it by adding before initialization: +/// subtractor.set_do_mass_subtraction(); +/// One must additionally provide option for the rho_m background estimation. There are several possibilities: +/// a) Same background estimator as for rho. Use this function: +/// subtractor.set_common_bge_for_rho_and_rhom(); // this must be used after set_background_estimator function. +/// b) Use a separate background estimator - you need to specify it as an additional parameter in function set_background_estimator +/// c) Use scalar background density using function set_scalar_background_density(double rho, double rhom). +/// 6. Same as 5 just keep pseudo-rapidity unchanged. Not recommended. Additionally to what is written for option 5, use: +/// subtractor.set_fix_pseudorapidity(); +/// 7. Keep rapidity and pseudo-rapidity fixed (scale fourmomentum). Recommended - observed better performance than the mass correction. Use: +/// subtractor.set_scale_fourmomentum(); + + + // Example selector for ConstituentSubtractor: + //Selector sel_CS_correction = SelectorPhiRange(0,3) * SelectorEtaMin(-1.5) * SelectorEtaMax(0); + // subtractor.set_ghost_selector(&sel_CS_correction); // uncomment in case you want to use ghost selector. Only ghosts fulfilling this selector will be constructed. No selection on input particles is done. The selection on input particles is the responsibility of the user, or the user can use the "set_particle_selector" function. However, the maximal eta cut (specified with "set_max_eta" function) is done always for both, ghosts and input particles. + // subtractor.set_particle_selector(&sel_CS_correction); // uncomment in case you want to use particle selector. Only particles fulfilling this selector will be corrected. The other particles will be unchanged. However, the maximal eta cut (specified with "set_max_eta" function) is done always for both, ghosts and input particles. + Selector sel_max_pt = SelectorPtMax(15); + subtractor.set_particle_selector(&sel_max_pt); // only particles with pt<15 will be corrected - the other particles will be copied without any changes. + + + // If you want to use the information about hard proxies (typically charged tracks from primary vertex and/or high pt calorimeter clusters), then use the following lines: + /*vector nearby_hard_radii; + nearby_hard_radii.push_back(0.2); + nearby_hard_radii.push_back(0.2); + vector nearby_hard_factors; + nearby_hard_factors.push_back(2); + nearby_hard_factors.push_back(5); + subtractor.set_nearby_hard_parameters(nearby_hard_radii,nearby_hard_factors); // In this example, during the first iteration, if there is a hard proxy within deltaR distance of 0.2, then the CS distance is multiplied by factor of 2, i.e. such particle is less favoured in the subtraction procedure. Similarly in the second iteration. If you uncomment these lines, then also uncomment line 120. + */ + + subtractor.initialize(); // this is new compared to previous usages of ConstituentSubtractor! It should be used after specifying all the parameters and before event loop. + // print info (optional) + cout << subtractor.description() << endl; + + + + + // in event loop + // read in input particles + vector hard_event, full_event; + vector *hard_event_charged=new vector; + vector *background_event_charged=new vector; + read_event(hard_event, full_event, hard_event_charged, background_event_charged); + + hard_event = SelectorAbsEtaMax(max_eta)(hard_event); + full_event = SelectorAbsEtaMax(max_eta)(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; + + + // jet definition and selector for jets + JetDefinition jet_def(antikt_algorithm, 0.7); + Selector sel_jets = SelectorNHardest(3) * SelectorAbsEtaMax(max_eta_jet); + + // clustering of the hard-scatter event and uncorrected event + ClusterSequence clust_seq_hard(hard_event, jet_def); + ClusterSequence clust_seq_full(full_event, jet_def); + vector hard_jets = sel_jets(clust_seq_hard.inclusive_jets()); + vector full_jets = sel_jets(clust_seq_full.inclusive_jets()); + + + bge_rho.set_particles(full_event); + + // the correction of the whole event with ConstituentSubtractor + vector corrected_event=subtractor.subtract_event(full_event); // Do not use max_eta parameter here!!! It makes nothing and this parameter will be removed from here. + // if you want to use the information about hard proxies, use this version: + // vector corrected_event=subtractor.subtract_event(full_event,hard_event_charged); // here all charged hard particles are used for hard proxies. In real experiment, this corresponds to charged tracks from primary vertex. Optionally, one can add among the hard proxies also high pt calorimeter clusters after some basic pileup correction. + + + // clustering of the corrected event + ClusterSequence clust_seq_corr(corrected_event, jet_def); + vector corrected_jets = sel_jets(clust_seq_corr.inclusive_jets()); + + + ios::fmtflags f( cout.flags() ); + cout << setprecision(4) << fixed; + cout << endl << "Corrected particles in the whole event:" << endl; + for (unsigned int i=0; imax_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. + virtual std::vector subtract_event(std::vector const &particles, std::vector const *hard_proxies=0); + + /// + /// this should be not used + virtual std::vector subtract_event(std::vector const &particles, double max_eta); + + /// + /// function to set the _ghost_removal member. If set to true, then the proxies with non-zero remaining pt are discarded for the next iteration + void set_ghost_removal(bool ghost_removal); + + /// + /// Set maximal distance and alpha parameters for the iterative CS + void set_parameters(std::vector const &max_distances, std::vector const &alphas); + + void set_nearby_hard_parameters(std::vector const &nearby_hard_radii, std::vector const &nearby_hard_factors); + + + protected: + std::vector _max_distances; + std::vector _alphas; + std::vector _nearby_hard_radii; + std::vector _nearby_hard_factors; + bool _use_nearby_hard_iterative; + bool _ghost_removal; + }; + + +} // namespace contrib + +FASTJET_END_NAMESPACE + +#endif // __FASTJET_CONTRIB_ITERATIVECONSTITUENTSUBTRACTOR_HH__ Index: contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_jet_by_jet.ref =================================================================== --- contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_jet_by_jet.ref (revision 0) +++ contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_jet_by_jet.ref (revision 1352) @@ -0,0 +1,35 @@ +# 20 pileup events on top of the hard event +# read an event with 207 signal particles and 1783 background particles with rapidity |y|<4 +#-------------------------------------------------------------------------- +# FastJet release 3.3.1 +# M. Cacciari, G.P. Salam and G. Soyez +# A software package for jet finding and analysis at colliders +# http://fastjet.fr +# +# Please cite EPJC72(2012)1896 [arXiv:1111.6097] if you use this package +# for scientific work and optionally PLB641(2006)57 [hep-ph/0512210]. +# +# FastJet is provided without warranty under the terms of the GNU GPLv2. +# It uses T. Chan's closest pair algorithm, S. Fortune's Voronoi code +# and 3rd party plugin jet algorithms. See COPYING file for details. +#-------------------------------------------------------------------------- + +Description of fastjet::ConstituentSubtractor which can be used for event-wide or jet-by-jet correction: + Using rho estimation: JetMedianBackgroundEstimator, using Longitudinally invariant kt algorithm with R = 0.4 and E scheme recombination with Active area (explicit ghosts) with ghosts of area 0.00997331 (had requested 0.01), placed up to y = 4, scattered wrt to perfect grid by (rel) 1, mean_ghost_pt = 1e-100, rel pt_scatter = 0.1, n repetitions of ghost distributions = 1 and selecting jets with |rap| <= 3 + The masses of all particles will be set to zero. + The rapidity of the particles will be kept unchanged (not pseudo-rapidity). + The information about nearby hard proxies will not be used. + Using parameters: max_distance = -1 alpha = 0 + +# original hard jets +pt = 144.5, rap = 0.6689, mass = 19.34, width = 0.06909 +pt = 220.1, rap = -1.068, mass = 18.09, width = 0.0337 + +# unsubtracted full jets +pt = 167.3, rap = 0.6891, mass = 58.31, width = 0.1268 +pt = 230.5, rap = -1.065, mass = 46.2, width = 0.05647 + +# subtracted full jets +pt = 146.1, rap = 0.6793, mass = 18.98, width = 0.07776 +pt = 208.7, rap = -1.072, mass = 7.278, width = 0.02319 + Index: contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_background_rescaling.cc =================================================================== --- contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_background_rescaling.cc (revision 0) +++ contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_background_rescaling.cc (revision 1352) @@ -0,0 +1,253 @@ +// +//---------------------------------------------------------------------- +// Example on how to do pileup correction on the whole event +// +// run it with +// ./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 . +//---------------------------------------------------------------------- + + +#include "fastjet/Selector.hh" +#include "fastjet/tools/GridMedianBackgroundEstimator.hh" +#include "fastjet/ClusterSequence.hh" +#include "IterativeConstituentSubtractor.hh" // In external code, this should be fastjet/contrib/IterativeConstituentSubtractor.hh +#include "RescalingClasses.hh" // In external code, this should be fastjet/contrib/RescalingClasses.hh + + +#include "functions.hh" +//#include "TH1D.h" +//#include "TH2D.h" +//#include "TF1.h" + + +using namespace std; +using namespace fastjet; + +//---------------------------------------------------------------------- +int main(){ + /// first several examples for rescaling classes are listed. Then the non-commented example is used with the Iterative CS. + + + ///**** rescaling in heavy ion events using rapidity dependence from TH1 histogram: **** + /// Set the five 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;iGetNbinsX()+1;i++){ + hist->SetBinContent(i,polynom(hist->GetBinCenter(i))); + } + contrib::BackgroundRescalingYFromRootPhi 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 rapidity dependence stored in vector: **** + /// Set the six parameters for rescaling using function + /// BackgroundRescalingYPhiUsingVectorForY(double v2, double v3, double v4, double psi, std::vector values, std::vector rap_binning); + /// 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 vector at position y + /// + /// The user must set the parameters event-by-event. Example: + vector values; + vector binning; + values.push_back(5); + values.push_back(6); + values.push_back(5.5); + values.push_back(5); + binning.push_back(-4); + binning.push_back(-2); + binning.push_back(0); + binning.push_back(2); + binning.push_back(4); + contrib::BackgroundRescalingYPhiUsingVectorForY rescaling(0.1,0.1,0.001,0,values,binning); + rescaling.use_rap_term(true); // this is useful to check if the vectors with rapidity dependence have good sizes, if one wants to use also 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;iGetNbinsX()+1;i++){ + hist->SetBinContent(i,polynom(hist->GetBinCenter(i))); + } + + contrib::BackgroundRescalingYFromRoot rescaling(hist); +*/ + + + ///**** rescaling using rapidity and azimuth dependence stored in root TH2 object: **** + // find the rapidity and azimuth distribution of pileup particles from minimum bias events in a separate run. Fill a root TH2 histogram with this distribution. + // Here as an example where the TH2 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. + /* TH2D* hist=new TH2D("hist","",100,-5,5,100,0,6.28319); + TF1 polynom("polynom","1+0.03*x*x-0.003*x*x*x*x",-5,5); + for (int i=1;iGetNbinsX()+1;i++){ + for (int j=1;jGetNbinsY()+1;j++){ + hist->SetBinContent(i,j,polynom(hist->GetXaxis()->GetBinCenter(i))); + } + } + + contrib::BackgroundRescalingYFromRoot rescaling(hist); + */ + + + + // This should be set up before event loop: + double max_eta=4; // specify the maximal pseudorapidity for the input particles. It is used for the subtraction. Particles with eta>|max_eta| are removed and not used during the subtraction (they are not returned). The same parameter should be used for the GridMedianBackgroundEstimator as it is demonstrated in this example. If JetMedianBackgroundEstimator is used, then lower parameter should be used (to avoid including particles outside this range). + double max_eta_jet=3; // the maximal pseudorapidity for selected jets. Not important for the subtraction. + // background estimation + + GridMedianBackgroundEstimator bge_rho(max_eta,0.5); // maximal pseudo-rapidity cut is used inside ConstituentSubtraction, but in GridMedianBackgroundEstimator, the range is specified by maximal rapidity cut. Therefore, it is important to apply the same pseudo-rapidity cut also for particles used for background estimation (using function "set_particles") and also derive the rho dependence on rapidity using this max pseudo-rapidity cut to get the correct rescaling function! + + contrib::IterativeConstituentSubtractor 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 + vector max_distances; + max_distances.push_back(0.1); + max_distances.push_back(0.2); + vector alphas; + alphas.push_back(0); + alphas.push_back(0); + subtractor.set_parameters(max_distances,alphas); // in this example, 2 CS corrections will be performed: 1. correction with max_distance of 0.1 and alpha of 0, 2. correction with max_distance of 0.15 and alpha of 0. After the first correction, the scalar sum of pt from remaining ghosts is evaluated and redistributed uniformly accross the event. + subtractor.set_ghost_removal(true); // set to true if the ghosts (proxies) which were not used in the previous CS procedure should be removed for the next CS procedure + subtractor.set_ghost_area(0.004); // parameter for the density of ghosts. The smaller, the better - but also the computation is slower. + subtractor.set_max_eta(max_eta); // parameter for maximal |eta| cut. It is pspecified above. + + subtractor.set_background_estimator(&bge_rho); + + + // For examples how to treat massive particles or how to use Selector, see example_event_wide.cc and example_iterative.cc + + + subtractor.initialize(); // this is new compared to previous usages of ConstituentSubtractor! It should be used after specifying all the parameters and before event loop. + + + + + + // in event loop + // read in input particles + vector hard_event, full_event; + read_event(hard_event, full_event); + + // keep the particles up to 4 units in rapidity + hard_event = SelectorAbsEtaMax(max_eta)(hard_event); + full_event = SelectorAbsEtaMax(max_eta)(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; + + + // jet definition and jet selector + JetDefinition jet_def(antikt_algorithm, 0.7); + Selector sel_jets = SelectorNHardest(3) * SelectorAbsEtaMax(max_eta_jet); + + // jet clustering + ClusterSequence clust_seq_hard(hard_event, jet_def); + ClusterSequence clust_seq_full(full_event, jet_def); + vector hard_jets = sel_jets(clust_seq_hard.inclusive_jets()); + vector full_jets = sel_jets(clust_seq_full.inclusive_jets()); + + + // setting the rescaling: + bge_rho.set_rescaling_class(&rescaling); + bge_rho.set_particles(full_event); + + // print info (optional) + cout << subtractor.description() << endl; + + + // correction of the whole event with ConstituentSubtractor + vector corrected_event=subtractor.subtract_event(full_event); + + ClusterSequence clust_seq_corr(corrected_event, jet_def); + vector 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{ +public: + + // action of the function + double result(const fastjet::PseudoJet &jet) const{ + if (!jet.has_constituents()){ + return -0.1; + } + double width = 1e-6; + double ptSum = 0; + + if (jet.constituents().size() < 2) return width; + + std::vector constituents = jet.constituents(); + + for (unsigned int iconst=0; iconst &hard_event, vector &full_event, vector *hard_event_charged=0, vector *pileup_event_charged=0){ + string line; + int nsub = 0; // counter to keep track of which sub-event we're reading + bool format_ptRapPhi=false; + while (getline(cin, line)) { + istringstream linestream(line); + // take substrings to avoid problems when there are extra "pollution" + // characters (e.g. line-feed). + + if (line.substr(0,9) == "#PTRAPPHI") format_ptRapPhi=true; + + if (line.substr(0,4) == "#END") {break;} + if (line.substr(0,9) == "#SUBSTART") { + // if more sub events follow, make copy of first one (the hard one) here + if (nsub == 1) hard_event = full_event; + nsub += 1; + } + if (line.substr(0,1) == "#") {continue;} + PseudoJet particle(0,0,1,1); + double charge,pid; + + if (format_ptRapPhi){ + double pt,y,phi; + linestream >> pt >> y >> phi >> pid >> charge; + particle.reset_PtYPhiM(pt,y,phi); + } + else{ + double px,py,pz,E; + linestream >> px >> py >> pz >> E >> pid >> charge; + particle.reset(px,py,pz,E); + } + + // push event onto back of full_event vector + + if ( nsub <= 1 ) { + if (hard_event_charged && fabs(charge)>0.99) hard_event_charged->push_back(particle); + } + else { + if (pileup_event_charged && fabs(charge)>0.99) pileup_event_charged->push_back(particle); + } + + full_event.push_back(particle); + } + + // if we have read in only one event, copy it across here... + if (nsub == 1) hard_event = full_event; + + // if there was nothing in the event + if (nsub == 0) { + cerr << "Error: read empty event\n"; + exit(-1); + } + + cout << "# " << nsub-1 << " pileup events on top of the hard event" << endl; +} Property changes on: contrib/contribs/ConstituentSubtractor/tags/1.4.6/functions.hh ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: contrib/contribs/ConstituentSubtractor/tags/1.4.6/COPYING =================================================================== --- contrib/contribs/ConstituentSubtractor/tags/1.4.6/COPYING (revision 0) +++ contrib/contribs/ConstituentSubtractor/tags/1.4.6/COPYING (revision 1352) @@ -0,0 +1,363 @@ +The ConstituentSubtractor contrib to FastJet is released under the terms +of the GNU General Public License v2 (GPLv2). + +A copy of the GPLv2 is to be found at the end of this file. + +While the GPL license grants you considerable freedom, please bear in +mind that this code's use falls under guidelines similar to those that +are standard for Monte Carlo event generators +(http://www.montecarlonet.org/GUIDELINES). In particular, if you use +this code as part of work towards a scientific publication, whether +directly or contained within another program you should include a +citation to + + JHEP 1406 (2014) 092, arXiv:1403.3108 + +and in case you use Iterative Constituent Subtraction (class IterativeConstituentSubtractor), additionally citation to + + arXiv:1905.03470 + + +====================================================================== +====================================================================== +====================================================================== + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program 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. + + This program 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 program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. Index: contrib/contribs/ConstituentSubtractor/tags/1.4.6/RescalingClasses.cc =================================================================== --- contrib/contribs/ConstituentSubtractor/tags/1.4.6/RescalingClasses.cc (revision 0) +++ contrib/contribs/ConstituentSubtractor/tags/1.4.6/RescalingClasses.cc (revision 1352) @@ -0,0 +1,189 @@ +// 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 . +//---------------------------------------------------------------------- + + +#include "RescalingClasses.hh" + +FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh + + +namespace contrib{ + + ///----------------------------------------------------- + /// BackgroundRescalingYPhi + BackgroundRescalingYPhi::BackgroundRescalingYPhi(double v2, double v3, double v4, double psi, double a1, double sigma1, double a2, double sigma2){ + _v2=v2; + _v3=v3; + _v4=v4; + _psi=psi; + _a1=a1; + _sigma1=sigma1; + _a2=a2; + _sigma2=sigma2; + _use_rap=true; + _use_phi=true; + } + + void BackgroundRescalingYPhi::use_rap_term(bool use_rap){ + _use_rap=use_rap; + } + + void BackgroundRescalingYPhi::use_phi_term(bool use_phi){ + _use_phi=use_phi; + } + + double BackgroundRescalingYPhi::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(); + rap_term=_a1*exp(-y*y/(2*_sigma1*_sigma1)) + _a2*exp(-y*y/(2*_sigma2*_sigma2)); + } + + return phi_term*rap_term; + } + + + + + + + ///---------------------------------------------------- + /// BackgroundRescalingYPhiUsingVectorForY + BackgroundRescalingYPhiUsingVectorForY::BackgroundRescalingYPhiUsingVectorForY(double v2, double v3, double v4, double psi, std::vector values, std::vector rap_binning){ + _v2=v2; + _v3=v3; + _v4=v4; + _psi=psi; + _values=values; + _rap_binning=rap_binning; + _use_phi=true; + if (_rap_binning.size()>=2){ + _use_rap=true; + if (_values.size()!=_rap_binning.size()-1) throw Error("BackgroundRescalingYPhiUsingVectorForY (from ConstituentSubtractor) The input vectors have wrong dimension. The vector with binning shuld have the size by one higher than the vector with values."); + } + else _use_rap=false; + } + + void BackgroundRescalingYPhiUsingVectorForY::use_rap_term(bool use_rap){ + _use_rap=use_rap; + if (use_rap && _rap_binning.size()<2) throw Error("BackgroundRescalingYPhiUsingVectorForY (from ConstituentSubtractor) Requested rapidity rescaling, but the vector with binning has less than two elements!"); + } + + void BackgroundRescalingYPhiUsingVectorForY::use_phi_term(bool use_phi){ + _use_phi=use_phi; + } + + double BackgroundRescalingYPhiUsingVectorForY::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){ + int rap_index=0; + double rap=particle.rap(); + if (rap<_rap_binning[0]) rap_index=0; // take the lowest rapidity bin in this case + else if (rap>=_rap_binning[_rap_binning.size()-1]) rap_index=_rap_binning.size()-2; // take the highest rapidity bin in this case + else{ + for (unsigned int i=1;i<_rap_binning.size();++i){ + if (rap<_rap_binning[i]){ + rap_index=i-1; + break; + } + } + } + rap_term=_values[rap_index]; + } + + return phi_term*rap_term; + } + + + + + ///--------------------------------------------------------- + ///BackgroundRescalingYPhiUsingVectors + BackgroundRescalingYPhiUsingVectors::BackgroundRescalingYPhiUsingVectors(std::vector > values, std::vector rap_binning, std::vector phi_binning){ + _values=values; + _rap_binning=rap_binning; + _phi_binning=phi_binning; + if (_rap_binning.size()>=2) _use_rap=true; + else _use_rap=false; + if (_phi_binning.size()>=2) _use_phi=true; + else _use_phi=false; + } + + void BackgroundRescalingYPhiUsingVectors::use_rap_term(bool use_rap){ + _use_rap=use_rap; + if (use_rap && _rap_binning.size()<2) throw Error("BackgroundRescalingYPhiUsingVectors (from ConstituentSubtractor) Requested rapidity rescaling, but the vector with binning has less than two elements!"); + } + + void BackgroundRescalingYPhiUsingVectors::use_phi_term(bool use_phi){ + _use_phi=use_phi; + if (use_phi && _phi_binning.size()<2) throw Error("BackgroundRescalingYPhiUsingVectors (from ConstituentSubtractor) Requested azimuth rescaling, but the vector with binning has less than two elements!"); + } + + double BackgroundRescalingYPhiUsingVectors::result(const PseudoJet & particle) const { + unsigned int phi_index=0; + if (_use_phi){ + double phi=particle.phi(); + if (phi<_phi_binning[0] || phi>=_phi_binning[_phi_binning.size()-1]) throw Error("BackgroundRescalingYPhiUsingVectors (from ConstituentSubtractor) The phi binning does not correspond to the phi binning of the particles."); + for (unsigned int i=1;i<_phi_binning.size();++i){ + if (phi<_phi_binning[i]){ + phi_index=i-1; + break; + } + } + } + unsigned int rap_index=0; + if (_use_rap){ + double rap=particle.rap(); + if (rap<_rap_binning[0]) rap_index=0; // take the lowest rapidity bin in this case + else if (rap>=_rap_binning[_rap_binning.size()-1]) rap_index=_rap_binning.size()-2; // take the highest rapidity bin in this case + else{ + for (unsigned int i=1;i<_rap_binning.size();++i){ + if (rap<_rap_binning[i]){ + rap_index=i-1; + break; + } + } + } + } + if (_values.size()<=rap_index) throw Error("BackgroundRescalingYPhiUsingVectors (from ConstituentSubtractor) The input vector > with values has wrong size."); + else if (_values[rap_index].size()<=phi_index) throw Error("BackgroundRescalingYPhiUsingVectors (from ConstituentSubtractor) The input vector > with values has wrong size."); + + return _values[rap_index][phi_index]; + } + + +} // namespace contrib + + +FASTJET_END_NAMESPACE + + + Index: contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_whole_event_using_charged_info.cc =================================================================== --- contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_whole_event_using_charged_info.cc (revision 0) +++ contrib/contribs/ConstituentSubtractor/tags/1.4.6/example_whole_event_using_charged_info.cc (revision 1352) @@ -0,0 +1,149 @@ +// $Id$ +// +//---------------------------------------------------------------------- +// Example on how to do pileup correction on the whole event +// +// run it with +// ./example_whole_event < ../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 . +//---------------------------------------------------------------------- + + +#include "fastjet/Selector.hh" +#include "fastjet/tools/GridMedianBackgroundEstimator.hh" +#include "fastjet/ClusterSequence.hh" +#include "ConstituentSubtractor.hh" // In external code, this should be fastjet/contrib/ConstituentSubtractor.hh + +#include "functions.hh" + + +using namespace std; +using namespace fastjet; + +//---------------------------------------------------------------------- +int main(){ + // set up before event loop: + contrib::ConstituentSubtractor subtractor; // no need to provide background estimator in this case + 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(0.3); // free parameter for the maximal allowed distance between particle i and ghost k + subtractor.set_alpha(1); // 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. + subtractor.set_do_mass_subtraction(); // use this line if also the mass term sqrt(pT^2+m^2)-pT should be corrected or not. It is necessary to specify it like this because the function set_common_bge_for_rho_and_rhom cannot be used in this case. + double CBS=1.0; // choose the scale for scaling the background charged particles + double CSS=1.0; // choose the scale for scaling the signal charged particles + subtractor.set_remove_particles_with_zero_pt_and_mass(false); // set to false if you want to have also the zero pt and mtMinuspt particles in the output. Set to true, if not. The choice has no effect on the performance. By deafult, these particles are removed - this is the recommended way since then the output contains much less particles, and therefore the next step (e.g. clustering) is faster. In this example, it is set to false to make sure that this test is successful on all systems (mac, linux). + subtractor.set_grid_size_background_estimator(0.6); // set the grid size (not area) for the background estimation with GridMedianBackgroundEstimation which is used within CS correction using charged info + cout << subtractor.description() << endl; + + + + // EVENT LOOP + + // read in input particles + vector hard_event, full_event; + vector *hard_event_charged=new vector; + vector *background_event_charged=new vector; + + read_event(hard_event, full_event, hard_event_charged, background_event_charged); + + double max_eta=4; // specify the maximal pseudorapidity for the particles used in the subtraction + double max_eta_jet=3; // the maximal pseudorapidity for selected jets + + // keep the particles up to 4 units in rapidity + hard_event = SelectorAbsEtaMax(max_eta)(hard_event); + full_event = SelectorAbsEtaMax(max_eta)(full_event); + *hard_event_charged = SelectorAbsEtaMax(max_eta)(*hard_event_charged); + *background_event_charged = SelectorAbsEtaMax(max_eta)(*background_event_charged); + + cout << "# read an event with " << hard_event.size() << " signal particles, " << full_event.size() - hard_event.size() << " background particles, " << hard_event_charged->size() << " signal charged particles, and " << background_event_charged->size() << " background charged particles" << " with pseudo-rapidity |eta|<4" << endl; + + + // do the clustering with ghosts and get the jets + //---------------------------------------------------------- + JetDefinition jet_def(antikt_algorithm, 0.7); + Selector sel_jets = SelectorNHardest(3) * SelectorAbsEtaMax(max_eta_jet); + + ClusterSequence clust_seq_hard(hard_event, jet_def); + ClusterSequence clust_seq_full(full_event, jet_def); + vector hard_jets = sel_jets(clust_seq_hard.inclusive_jets()); + vector full_jets = sel_jets(clust_seq_full.inclusive_jets()); + + // correction of the whole event using charged info + vector corrected_event=subtractor.subtract_event_using_charged_info(full_event,CBS,*background_event_charged,CSS,*hard_event_charged,max_eta); + + ios::fmtflags f( cout.flags() ); + cout << setprecision(7) << fixed; + cout << endl << "Corrected particles in the whole event:" << endl; + for (unsigned int i=0; i0) _use_max_distance=true; + else _use_max_distance=false; + _polarAngleExp=0; + _ghost_area=0.01; + _remove_particles_with_zero_pt_and_mass=true; + _remove_all_zero_pt_particles=false; + _max_eta=-1; + _ghosts_constructed=false; + _ghosts_rapidity_sorted=false; + _n_ghosts_phi=-1; + _do_mass_subtraction=false; + _masses_to_zero=true; + _use_nearby_hard=false; + _fix_pseudorapidity=false; + _scale_fourmomentum=false; + _hard_proxies=0; + _ghost_selector=0; + _particle_selector=0; + _nearby_hard_radius=-1; + _nearby_hard_factor=-1; + } + + + /// + /// 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); + + _do_mass_subtraction=false; + _masses_to_zero=true; + _polarAngleExp=0; + _ghost_area=0.01; + _remove_particles_with_zero_pt_and_mass=true; + _remove_all_zero_pt_particles=false; + _ghosts_constructed=false; + _ghosts_rapidity_sorted=false; + _n_ghosts_phi=-1; + _max_eta=-1; + _use_nearby_hard=false; + _fix_pseudorapidity=false; + _scale_fourmomentum=false; + _hard_proxies=0; + _ghost_selector=0; + _particle_selector=0; + _nearby_hard_radius=-1; + _nearby_hard_factor=-1; + } + + + void ConstituentSubtractor::_initialize_common(){ + if (_max_eta<=0) throw Error("ConstituentSubtractor::initialize_common: The value for eta cut was not set or it is negative. It needs to be set before using the function initialize"); + if (_masses_to_zero && _do_mass_subtraction) throw Error("ConstituentSubtractor::initialize_common: It is specified to do mass subtraction and also to keep the masses at zero. Something is wrong."); + if (_masses_to_zero && _scale_fourmomentum) throw Error("ConstituentSubtractor::initialize_common: It is specified to do scaling of fourmomenta and also to keep the masses at zero. Something is wrong."); + if (_do_mass_subtraction && _scale_fourmomentum) throw Error("ConstituentSubtractor::initialize_common: It is specified to do mass subtraction and also to do scaling of fourmomenta. Something is wrong."); + this->construct_ghosts_uniformly(_max_eta); + } + + + void ConstituentSubtractor::initialize(){ + this->_initialize_common(); + } + + + + void ConstituentSubtractor::set_background_estimator(fastjet::BackgroundEstimatorBase *bge_rho, fastjet::BackgroundEstimatorBase *bge_rhom){ + _bge_rho=bge_rho; + _bge_rhom=bge_rhom; + } + + + 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; + } + + ///---------------------------------------------------------------------- + /// 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."); + } + if (_ghosts_constructed) throw Error("ConstituentSubtractor::result() The ghosts are constructed, but they are not needed when using this function. When you want to perform jet-by-jet correction, initialize a new ConstituentSubtractor without construction of ghosts."); + + ///---------------------------------------------------------------------- + /// sift ghosts and particles in the input jet + std::vector particles, ghosts; + SelectorIsPureGhost().sift(jet.constituents(), ghosts, particles); + + std::vector selected_particles,unselected_particles; + if (_particle_selector) _particle_selector->sift(particles, selected_particles, unselected_particles); + else selected_particles=particles; + + + std::vector ghosts_area; + unsigned long nGhosts=ghosts.size(); + for (unsigned int j=0;j backgroundProxies=this->get_background_proxies_from_ghosts(ghosts,ghosts_area); + std::vector subtracted_particles=this->do_subtraction(selected_particles,backgroundProxies); + if (_particle_selector) subtracted_particles.insert(subtracted_particles.end(), unselected_particles.begin(), unselected_particles.end()); + fastjet::PseudoJet subtracted_jet=join(subtracted_particles); + subtracted_jet.set_user_index(jet.user_index()); + subtracted_jet.user_info_shared_ptr() = jet.user_info_shared_ptr(); + + return subtracted_jet; + } + + + + + std::vector ConstituentSubtractor::subtract_event(std::vector const &particles, double max_eta){ + if (fabs(_max_eta/max_eta-1)>1e-5 && max_eta>0){ + _ghosts_constructed=false; + _max_eta=max_eta; + } + if (!_ghosts_constructed) this->construct_ghosts_uniformly(_max_eta); + return subtract_event(particles); + } + + + std::vector ConstituentSubtractor::subtract_event(std::vector const &particles, std::vector const *hard_proxies){ + std::vector backgroundProxies=this->get_background_proxies_from_ghosts(_ghosts,_ghosts_area); + std::vector selected_particles,unselected_particles; + for (unsigned int iparticle=0;iparticle_max_eta) continue; + if (particles[iparticle].pt()pass(particles[iparticle])) selected_particles.push_back(particles[iparticle]); + else unselected_particles.push_back(particles[iparticle]); + } + else selected_particles.push_back(particles[iparticle]); + } + if (_use_nearby_hard){ + if (hard_proxies) _hard_proxies=hard_proxies; + else throw Error("ConstituentSubtractor::subtract_event: It was requested to use closeby hard proxies but they were not provided in this function!"); + } + else if (hard_proxies) throw Error("ConstituentSubtractor::subtract_event: Hard proxies were provided but the set_use_hard_proxies function was not used before initialization. It needs to be called before initialization!"); + std::vector subtracted_particles=this->do_subtraction(selected_particles,backgroundProxies); + if (_particle_selector) subtracted_particles.insert(subtracted_particles.end(), unselected_particles.begin(), unselected_particles.end()); + return subtracted_particles; + } + + + + + std::vector ConstituentSubtractor::get_background_proxies_from_ghosts(std::vector const &ghosts,std::vector const &ghosts_area) const{ + unsigned long nGhosts=ghosts.size(); + std::vector proxies; + std::vector pt; + std::vector mtMinusPt; + proxies.reserve(nGhosts); + pt.reserve(nGhosts); + mtMinusPt.reserve(nGhosts); + if (_externally_supplied_rho_rhom){ + for (unsigned int j=0;jrho(ghosts[j])*ghosts_area[j]); + if (_bge_rhom){ + /* if (_rhom_from_bge_rhom){ +#if FASTJET_VERSION_NUMBER >= 30100 + for (unsigned int j=0;jrho_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;jrho(ghosts[j])*ghosts_area[j]); + }*/ + + + // 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_rhom->has_rho_m()){ + for (unsigned int j=0;jrho_m(ghosts[j])*ghosts_area[j]); + } else { + throw Error("ConstituentSubtractor: The provided background estimator for rho_m has no support to compute rho_m, and other option to get it is not available in ConstituentSubtractor."); + } +#endif // end of code specific to FJ >= 3.1 +#if FASTJET_VERSION_NUMBER < 30100 + throw Error("ConstituentSubtractor: You provided a background estimator for rho_m, but this is not supported in ConstituentSubtractor when using fastjet version smaller than 30100."); +#endif + } + 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;jrho_m(ghosts[j])*ghosts_area[j]); + } else { +#endif // end of code specific to FJ >= 3.1 + BackgroundJetPtMDensity m_density; + JetMedianBackgroundEstimator *jmbge = dynamic_cast(_bge_rho); + const FunctionOfPseudoJet * orig_density = jmbge->jet_density_class(); + jmbge->set_jet_density_class(&m_density); + for (unsigned int j=0;jrho(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= 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() && !_masses_to_zero && !_scale_fourmomentum){ + _warning_unused_rhom.warn("ConstituentSubtractor:: Background estimator indicates non-zero rho_m, but the ConstituentSubtractor does not use rho_m information, nor the masses are set to zero, nor the 4-momentum is scaled. Consider calling set_common_bge_for_rho_and_rhom() to include the rho_m information; or call set_keep_original_masses(false) to set masses for all particles to zero; or call set_scale_fourmomentum to scale the fourmomentum."); + } +#endif + } + } + + + fastjet::PseudoJet proxy(0,0,0,1); + for (unsigned int j=0;j0) mass=sqrt(mass_squared); + proxy.reset_momentum_PtYPhiM(pt[j],ghosts[j].rap(),ghosts[j].phi(),mass); + proxies.push_back(proxy); + } + return proxies; + } + + + + + double ConstituentSubtractor::_get_transformed_distance(double const &distance) const{ + double max_distance_transformed=-1; + if (_distance==ConstituentSubtractor::deltaR) max_distance_transformed=pow(distance,2); + if (_distance==ConstituentSubtractor::angle) max_distance_transformed=-cos(distance); + return max_distance_transformed; + } + + + + std::vector ConstituentSubtractor::do_subtraction(std::vector const &particles, std::vector const &backgroundProxies,std::vector *remaining_backgroundProxies) const{ + unsigned int nBackgroundProxies=backgroundProxies.size(); + unsigned int nParticles=particles.size(); + double max_distance_transformed=this->_get_transformed_distance(_max_distance); + + // sort particles according to rapidity to achieve faster performance for the whole event subtraction + std::vector particles_sorted=particles; + std::sort(particles_sorted.begin(),particles_sorted.end(),ConstituentSubtractor::_rapidity_sorting); + + // get the kinematic variables for particles and background proxies in advance to achieve faster performance + std::vector particles_phi,particles_rap,particles_pt,particles_mt,particles_factor,particles_px_normalized,particles_py_normalized,particles_pz_normalized; + particles_phi.reserve(nParticles); + particles_rap.reserve(nParticles); + particles_pt.reserve(nParticles); + particles_mt.reserve(nParticles); + particles_factor.reserve(nParticles); + particles_px_normalized.reserve(nParticles); + particles_py_normalized.reserve(nParticles); + particles_pz_normalized.reserve(nParticles); + + double pt_factor=1; + double polarAngle_factor=1; + double nearby_hard_factor=1; + double max_distance_from_hard_transformed=this->_get_transformed_distance(_nearby_hard_radius); + for (unsigned int i=0;i1e-5) pt_factor=pow(particles_pt[i],_alpha); + double momentum=sqrt(particles_sorted[i].pt2()+particles_sorted[i].pz()*particles_sorted[i].pz()); + if (fabs(_polarAngleExp)>1e-5) polarAngle_factor=pow(particles_pt[i]/momentum,_polarAngleExp); + if (_distance==ConstituentSubtractor::angle){ + particles_px_normalized.push_back(particles_sorted[i].px()/momentum); + particles_py_normalized.push_back(particles_sorted[i].py()/momentum); + particles_pz_normalized.push_back(particles_sorted[i].pz()/momentum); + } + if (_use_nearby_hard){ + nearby_hard_factor=1; + double distance_from_hard_transformed=-1; + for (unsigned int ihard=0;ihard<_hard_proxies->size();++ihard){ + if (_distance==ConstituentSubtractor::deltaR){ + double deltaPhi=fabs(_hard_proxies->at(ihard).phi()-particles_phi[i]); + if (deltaPhi>pi) deltaPhi=twopi-deltaPhi; + double deltaRap=_hard_proxies->at(ihard).rap()-particles_rap[i]; + distance_from_hard_transformed = deltaPhi*deltaPhi+deltaRap*deltaRap; + } + if (_distance==ConstituentSubtractor::angle){ + distance_from_hard_transformed=-(particles_px_normalized[i]*_hard_proxies->at(ihard).px()+particles_py_normalized[i]*_hard_proxies->at(ihard).py()+particles_pz_normalized[i]*_hard_proxies->at(ihard).pz())/sqrt(_hard_proxies->at(ihard).pt2()*_hard_proxies->at(ihard).pt2()+_hard_proxies->at(ihard).pz()*_hard_proxies->at(ihard).pz()); + } + if (distance_from_hard_transformed<=max_distance_from_hard_transformed){ + nearby_hard_factor=_nearby_hard_factor; + break; + } + } + } + particles_factor.push_back(pt_factor*polarAngle_factor*nearby_hard_factor); + } + + std::vector backgroundProxies_phi,backgroundProxies_rap,backgroundProxies_pt,backgroundProxies_mt,backgroundProxies_px_normalized,backgroundProxies_py_normalized,backgroundProxies_pz_normalized; + backgroundProxies_phi.reserve(nBackgroundProxies); + backgroundProxies_rap.reserve(nBackgroundProxies); + backgroundProxies_pt.reserve(nBackgroundProxies); + backgroundProxies_mt.reserve(nBackgroundProxies); + backgroundProxies_px_normalized.reserve(nBackgroundProxies); + backgroundProxies_py_normalized.reserve(nBackgroundProxies); + backgroundProxies_pz_normalized.reserve(nBackgroundProxies); + for (unsigned int j=0;j backgroundProxies_minParticleIndex,backgroundProxies_maxParticleIndex; + if (_use_max_distance && _distance==ConstituentSubtractor::deltaR && _ghosts_rapidity_sorted && !_ghost_selector){ + for (unsigned int j=0;j<_ghosts_rapidities.size();++j){ + unsigned int min=this->_find_index_after(_ghosts_rapidities[j]-_max_distance,particles_rap); + unsigned int max=this->_find_index_before(_ghosts_rapidities[j]+_max_distance,particles_rap); + for (int k=0;k<_n_ghosts_phi;++k){ + backgroundProxies_minParticleIndex.push_back(min); + backgroundProxies_maxParticleIndex.push_back(max); + } + max_number_pairs+=max-min; + } + max_number_pairs=max_number_pairs*_n_ghosts_phi*_max_distance/3.1415; + } + else{ + for (unsigned int j=0;j > > CS_distances; // storing three elements: the CS distance, and corresponding particle and proxy indexes + CS_distances.reserve(max_number_pairs); + + bool skip_particles_outside_phi_range=false; // used for speed optimization + if (_distance==ConstituentSubtractor::deltaR && _use_max_distance && _max_distancetwopi){ + particle_phi_min=particle_phi_max-twopi; + particle_phi_max=backgroundProxies_phi[j]-_max_distance; + switched=true; + } + if (particle_phi_min<0){ + particle_phi_max=particle_phi_min+twopi; + particle_phi_min=backgroundProxies_phi[j]+_max_distance; + switched=true; + } + } + for (unsigned int i=backgroundProxies_minParticleIndex[j];iparticle_phi_min && particles_phi[i]particle_phi_max))) continue; // speed optimization only, this line has no effect on the subtraction performance + 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){ + distance_transformed=-(particles_px_normalized[i]*backgroundProxies_px_normalized[j]+particles_py_normalized[i]*backgroundProxies_py_normalized[j]+particles_pz_normalized[i]*backgroundProxies_pz_normalized[j]); + } + if (!_use_max_distance || distance_transformed<=max_distance_transformed){ + double CS_distance = distance_transformed*particles_factor[i]; + CS_distances.push_back(std::make_pair(CS_distance,std::make_pair(i,j))); // have tried to use emplace_back and tuple here - did not lead to any speed improvement + } + } + } + + + // Sorting of the CS distances + std::sort(CS_distances.begin(),CS_distances.end(),ConstituentSubtractor::_function_used_for_sorting); + + + // The iterative process. Here, only finding the fractions of pt or delta_m=mt-pt to be corrected. The actual correction of particles is done later. + unsigned long nStoredPairs=CS_distances.size(); + + std::vector backgroundProxies_fraction_of_pt(nBackgroundProxies,1.); + std::vector particles_fraction_of_pt(nParticles,1.); + std::vector backgroundProxies_fraction_of_mtMinusPt(nBackgroundProxies,1.); + std::vector particles_fraction_of_mtMinusPt(nParticles,1.); + for (unsigned long iindices=0;iindices0 && particles_fraction_of_pt[particle_index]>0 && particles_pt[particle_index]>0 && backgroundProxies[proxy_index].pt()>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 subtracted_particles; + PseudoJet subtracted_const; + for (unsigned int i=0;i0) corrected_pt=particles_pt[i]*particles_fraction_of_pt[i]; + + if (corrected_pt<=ConstituentSubtractorConstants::zero_pt){ + if (_remove_all_zero_pt_particles) continue; + else{ + corrected_pt=ConstituentSubtractorConstants::zero_pt; + particle_pt_larger_than_zero=false; + } + } + + + if (_scale_fourmomentum){ + if (particle_pt_larger_than_zero) subtracted_const=particles_sorted[i]*particles_fraction_of_pt[i]; + else{ + double scale=1; + if (corrected_ptConstituentSubtractorConstants::zero_mass); + if (!particle_pt_larger_than_zero && !particle_mass_larger_than_zero && _remove_particles_with_zero_pt_and_mass) continue; + + double new_mass=ConstituentSubtractorConstants::zero_mass; + if (_do_mass_subtraction){ + if (particles_fraction_of_mtMinusPt[i]>0){ + double subtracted_mtMinusPt=(particles_mt[i]-particles_pt[i])*particles_fraction_of_mtMinusPt[i]; + double mass_squared=pow(corrected_pt+subtracted_mtMinusPt,2)-pow(corrected_pt,2); + if (mass_squared>0) new_mass=sqrt(mass_squared); + } + } + else if (!_masses_to_zero) new_mass=particles_sorted[i].m(); + + if (new_mass<=ConstituentSubtractorConstants::zero_mass){ + if (!particle_pt_larger_than_zero && _remove_particles_with_zero_pt_and_mass) continue; + else new_mass=ConstituentSubtractorConstants::zero_mass; + } + + + // std::cout << "before correction: " << particles_sorted[i].pt() << " " << particles_sorted[i].eta() << " " << particles_sorted[i].rap() << " " << particles_sorted[i].m() << std::endl; + if (_fix_pseudorapidity){ + double scale=corrected_pt/particles_pt[i]; + subtracted_const.reset(particles_sorted[i].px()*scale,particles_sorted[i].py()*scale,particles_sorted[i].pz()*scale,sqrt(pow(corrected_pt,2)+pow(scale,2)*pow(particles_sorted[i].pz(),2)+pow(new_mass,2))); + } + else subtracted_const.reset_PtYPhiM(corrected_pt,particles_rap[i],particles_phi[i],new_mass); + // std::cout << "after correction: " << subtracted_const.pt() << " " << subtracted_const.eta() << " " << subtracted_const.rap() << " " << subtracted_const.m() << std::endl; + } + subtracted_const.set_user_index(particles_sorted[i].user_index()); + subtracted_const.user_info_shared_ptr() = particles_sorted[i].user_info_shared_ptr(); + + subtracted_particles.push_back(subtracted_const); + } + + // get the remaining background proxies if requested: + if (remaining_backgroundProxies){ + PseudoJet subtracted_proxy; + for (unsigned int i=0;i0 && backgroundProxies_pt[i]>0); + bool proxy_mtMinusPt_larger_than_zero=(!_masses_to_zero && backgroundProxies_fraction_of_mtMinusPt[i]>0 && backgroundProxies_mt[i]>backgroundProxies_pt[i]); + + double scale=1e-100; + if (proxy_pt_larger_than_zero) scale=backgroundProxies_fraction_of_pt[i]; + if (_scale_fourmomentum) subtracted_proxy=backgroundProxies[i]*scale; + else{ + double new_mass=1e-150; + if (proxy_mtMinusPt_larger_than_zero){ + if (_do_mass_subtraction){ + double subtracted_mtMinusPt=(backgroundProxies_mt[i]-backgroundProxies_pt[i])*backgroundProxies_fraction_of_mtMinusPt[i]; + double mass_squared=pow(scale*backgroundProxies_pt[i]+subtracted_mtMinusPt,2)-pow(scale*backgroundProxies_pt[i],2); + if (mass_squared>0) new_mass=sqrt(mass_squared); + } + else new_mass=backgroundProxies[i].m(); + } + if (_fix_pseudorapidity) subtracted_proxy.reset(backgroundProxies[i].px()*scale,backgroundProxies[i].py()*scale,backgroundProxies[i].pz()*scale,sqrt(pow(scale,2)*(backgroundProxies[i].pt2()+pow(backgroundProxies[i].pz(),2))+pow(new_mass,2))); + else subtracted_proxy.reset_PtYPhiM(scale*backgroundProxies_pt[i],backgroundProxies_rap[i],backgroundProxies_phi[i],new_mass); + } + remaining_backgroundProxies->push_back(subtracted_proxy); + } + } + + return subtracted_particles; + } + + + + void ConstituentSubtractor::set_keep_original_masses(){ + _masses_to_zero=false; + } + + + + + std::vector ConstituentSubtractor::subtract_event_using_charged_info(std::vector const &particles, double charged_background_scale, std::vector const &charged_background, double charged_signal_scale, std::vector const &charged_signal, double max_eta){ + if (fabs(_max_eta/max_eta-1)>1e-5) _ghosts_constructed=false; + if (!_ghosts_constructed) this->construct_ghosts_uniformly(max_eta); + _ghosts_rapidity_sorted=false; // no speed optimization implemented for this function yet + + std::vector scaled_charged_all; + std::vector scaled_charged_signal; + std::vector scaled_charged_background; + for (unsigned int i=0;imax_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;imax_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 selected_particles; + for (unsigned int i=0;i *remaining_charged_background= new std::vector; + double maxDeltaR=this->get_max_distance(); + if (maxDeltaR<=0) maxDeltaR=0.5; + this->set_max_distance(0.2); + std::vector subtracted_particles_using_scaled_charged_signal=this->do_subtraction(selected_particles,scaled_charged_signal); + std::vector 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 scaled_charged_background_used_for_subtraction=this->do_subtraction(scaled_charged_background,*remaining_charged_background); + _bge_rho= new fastjet::GridMedianBackgroundEstimator(max_eta, _grid_size_background_estimator); + if (_do_mass_subtraction) this->set_common_bge_for_rho_and_rhom(); + _bge_rho->set_rescaling_class(_rescaling); + _bge_rho->set_particles(subtracted_particles_using_scaled_charged_all); + + std::vector 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 subtracted_particles=this->do_subtraction(selected_particles,backgroundProxies); + delete remaining_charged_background; + delete _bge_rho; + return subtracted_particles; + } + + + + void ConstituentSubtractor::set_grid_size_background_estimator(double const &grid_size_background_estimator){ + _grid_size_background_estimator=grid_size_background_estimator; + } + + + + void ConstituentSubtractor::set_common_bge_for_rho_and_rhom(bool value){ + if (value) this->set_common_bge_for_rho_and_rhom(); + else throw Error("ConstituentSubtractor::set_common_bge_for_rho_and_rhom: This function should be not used with false! Read the instructions for mass subtraction in the header file."); + } + + + void ConstituentSubtractor::set_common_bge_for_rho_and_rhom(){ + if (!_bge_rho) throw Error("ConstituentSubtractor::set_common_bge_for_rho_and_rhom() is not allowed when _bge_rho is not set!"); + 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(_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=true; + } + + + // 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(){ + _do_mass_subtraction=true; + _masses_to_zero=false; + } + + + + void ConstituentSubtractor::description_common(std::ostringstream &descr) const{ + if ( _externally_supplied_rho_rhom){ + descr << " Using externally supplied rho = " << _rho << " and rho_m = " << _rhom << std::endl; + } else { + if (_bge_rhom && _bge_rho) { + descr << " Using rho estimation: " << _bge_rho->description() << std::endl; + descr << " Using rho_m estimation: " << _bge_rhom->description() << std::endl; + } else { + if (_bge_rho) descr << " Using rho estimation: " << _bge_rho->description() << std::endl; + else descr << " No externally supplied rho, nor background estimator" << std::endl; + } + } + + if (_do_mass_subtraction){ + descr << " The mass part (delta_m) will be also corrected." << std::endl; + if (_common_bge) descr << " using the same background estimator for rho_m as for rho" << std::endl; + else descr << " using different background estimator for rho_m as for rho" << std::endl; + } + else if (_masses_to_zero) descr << " The masses of all particles will be set to zero." << std::endl; + else if (_scale_fourmomentum) descr << " The masses will be corrected by scaling the whole 4-momentum." << std::endl; + else descr << " The original mass of the particles will be kept." << std::endl; + + if (!_scale_fourmomentum){ + if (_fix_pseudorapidity) descr << " The pseudo-rapidity of the particles will be kept unchanged (not rapidity)." << std::endl; + else descr << " The rapidity of the particles will be kept unchanged (not pseudo-rapidity)." << std::endl; + } + + if (_use_nearby_hard) descr << " Using information about nearby hard proxies with parameters _nearby_hard_radius=" << _nearby_hard_radius << " and _nearby_hard_factor=" << _nearby_hard_factor << std::endl; + else descr << " The information about nearby hard proxies will not be used." << std::endl; + } + + + + + + std::string ConstituentSubtractor::description() const{ + std::ostringstream descr; + descr << std::endl << "Description of fastjet::ConstituentSubtractor which can be used for event-wide or jet-by-jet correction:" << std::endl; + this->description_common(descr); + descr << " Using parameters: max_distance = " << _max_distance << " alpha = " << _alpha << 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_standardDeltaR(double max_distance){ + this->set_max_distance(max_distance); + } + + + + 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; + this->clear_ghosts(); + } + + + void ConstituentSubtractor::set_max_eta(double max_eta){ + _max_eta=max_eta; + } + + + void ConstituentSubtractor::set_fix_pseudorapidity(){ + _fix_pseudorapidity=true; + } + + + void ConstituentSubtractor::set_scale_fourmomentum(){ + _scale_fourmomentum=true; + _masses_to_zero=false; + } + + + void ConstituentSubtractor::set_remove_particles_with_zero_pt_and_mass(bool value){ + _remove_particles_with_zero_pt_and_mass=value; + } + + + void ConstituentSubtractor::set_remove_all_zero_pt_particles(bool value){ + _remove_all_zero_pt_particles=value; + } + + + bool ConstituentSubtractor::_function_used_for_sorting(std::pair > const &i,std::pair > const &j){ + return (i.first < j.first); + } + + bool ConstituentSubtractor::_rapidity_sorting(fastjet::PseudoJet const &i,fastjet::PseudoJet const &j){ + return (i.rap() < j.rap()); + } + + unsigned int ConstituentSubtractor::_find_index_after(double const &value, std::vector const &vec) const{ + int size=vec.size(); + if (size==0) return -1; + int nIterations=log(size)/log(2)+2; + unsigned int lowerBound=0; + unsigned int upperBound=size-1; + if (value<=vec[0]) return 0; + if (value>vec[size-1]) return size; // if the value is larger than the maximal possible rapidity, than setting min to size - then also max is set to size, and nothing will be run in the loop + for (int i=0;ivec[test]){ + if (value<=vec[test+1]) return test+1; + lowerBound=test; + } + else{ + if (value>vec[test-1]) return test; + upperBound=test; + } + } + return lowerBound; + } + + + unsigned int ConstituentSubtractor::_find_index_before(double const &value, std::vector const &vec) const{ + int size=vec.size(); + if (size==0) return -1; + int nIterations=log(size)/log(2)+1; + unsigned int lowerBound=0; + unsigned int upperBound=size-1; + if (value=vec[size-1]) return size; // it is higher by one to account for the "<" comparison in the for loop + for (int i=0;i=vec[test]){ + if (value=vec[test-1]) return test; // it is higher by one to account for the "<" comparison in the for loop + upperBound=test; + } + } + return upperBound+1; + } + + + + + void ConstituentSubtractor::clear_ghosts(){ + _ghosts.clear(); + _ghosts_rapidities.clear(); + _ghosts_area.clear(); + _ghosts_rapidity_sorted=false; + _ghosts_constructed=false; + } + + + void ConstituentSubtractor::construct_ghosts_uniformly(double max_eta){ + this->clear_ghosts(); + _max_eta=max_eta; + double a=sqrt(_ghost_area); + _n_ghosts_phi=(2*3.14159265/a+0.5); // rounding + int n_ghosts_rap=(2*max_eta/a+0.5); // rounding + _grid_size_phi=2*3.14159265/(double)_n_ghosts_phi; + _grid_size_rap=2*max_eta/(double)n_ghosts_rap; + double used_ghost_area=_grid_size_phi*_grid_size_rap; + fastjet::PseudoJet ghost(0,0,0,1); + for (int iRap=0;iRappass(ghost)) continue; + } + _ghosts.push_back(ghost); + _ghosts_area.push_back(used_ghost_area); + } + } + _ghosts_rapidity_sorted=true; // the ghosts are now sorted according to rapidity. This variable needs to be set to true to be able to use faster algorithm in "do_subtraction". + _ghosts_constructed=true; + } + + + std::vector ConstituentSubtractor::get_ghosts(){ + return _ghosts; + } + + + std::vector ConstituentSubtractor::get_ghosts_area(){ + return _ghosts_area; + } + + + + void ConstituentSubtractor::set_ghost_selector(fastjet::Selector* selector){ + _ghost_selector=selector; + this->clear_ghosts(); + } + + void ConstituentSubtractor::set_particle_selector(fastjet::Selector* selector){ + _particle_selector=selector; + } + + void ConstituentSubtractor::set_rescaling(fastjet::FunctionOfPseudoJet *rescaling){ + _rescaling=rescaling; + } + + + void ConstituentSubtractor::set_use_nearby_hard(double const &nearby_hard_radius, double const &nearby_hard_factor){ + _nearby_hard_radius=nearby_hard_radius; + _nearby_hard_factor=nearby_hard_factor; + if (_nearby_hard_radius>0) _use_nearby_hard=true; + else _use_nearby_hard=false; + } + +} // namespace contrib + + +FASTJET_END_NAMESPACE Property changes on: contrib/contribs/ConstituentSubtractor/tags/1.4.6/ConstituentSubtractor.cc ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: contrib/contribs/ConstituentSubtractor/tags/1.4.6/NEWS =================================================================== --- contrib/contribs/ConstituentSubtractor/tags/1.4.6/NEWS (revision 0) +++ contrib/contribs/ConstituentSubtractor/tags/1.4.6/NEWS (revision 1352) @@ -0,0 +1,117 @@ +2023/05/11: release of version 1.4.6: + - Fixed a bug for jet-by-jet Constituent Subtractor when using particle selector + - Copying also user_info for the corrected jet and corrected constituents + - Initializing previously not initialized variables (caused a FPE warning in ATLAS) + +2020/02/23: release of version 1.4.5: + - Further removal of C++11 extensions which were missed previously + + +2019/07/15: release of version 1.4.4: + - Removed two more C++11 extensions + + +2019/07/09: release of version 1.4.3: + - Removed C++11 extensions + - Changed the way how the user should specify that he/she wants to do delta_m correction. Now, additionally the "set_do_mass_correction" function must be called + - Updated information about the options for the treatment of massive inputs. + + + +2019/07/04: release of version 1.4.2: + - Updated information about the treatment of massive inputs. No changes in the code. + + +2019/06/21: release of version 1.4.1: + - Updated the treatment of additional background estimator for rho_m. Currently in ConstituentSubtractor, only such rho_m background estimators are supported which have member function rho_m(), i.e. the result from member function has_rho_m() is true (which is available since fastjet version 30100). + + +2019/06/19: release of version 1.4.0: + - Updated naming of functions and examples to be consistent with arXiv:1905.03470 + - Updated treatment of massive inputs - added new options and clarification in the examples + - Updated values of pt and mass for particles with zero pt and mass + - Added possibility to use selector for particles - only particles passing the selector are corrected, the other particles are unchanged + - Updated COPYING + + +2019/03/28: release of version 1.3.2: + - Started to use C++11 features + - Added possibility to keep the masses unchanged. The possible options how to treat masses are explained at the beggining of ConstituentSubtractor.hh + - Added possibility to use information about hard particles (e.g. charged tracks from primary vertex) in the definition of the CS distance used for the correction procedure. + - Updated examples + + +2018/06/28: release of version 1.3.1: + - Updated examples + + +2018/06/25: release of version 1.3.0: + - Replaced the "sequential" CS by "iterative CS". Besides the change of name, also the usage changed, see example file example_whole_event_iterative.cc. + - The usage of the ConstituentSubtractor for whole event correction is changes, see updated example file example_whole_event.cc. Currently the new and old usage give the same behaviour, but it will change in the future. + + +2018/06/12: release of version 1.2.8: + - Now removing all ghosts when setting new selector + - Updated sequential CS - possibility to do more iterations than 2 and possibility to remove ghosts which were not used. + +2018/05/04: release of version 1.2.7: + - Added possibility to correct only certain phase space defined by an input fastjet::Selector + - Added possibility to change the grid size for background estimation when using function subtract_event_using_charged_info + - Update example for whole event correction. + + +2018/05/03: release of version 1.2.6: + - Updated examples to be more clear. + + +2018/04/11: release of version 1.2.5: + - Fixed bug causing seg fault in ATLAS. + + +2017/12/18: release of version 1.2.4: + - Added back the test example_whole_event_using_charged_info. The problem with this test was fixed by printing all the output particles (also with zero pt and zeo mtMinusPt values). + + +2017/09/08: release of version 1.2.3: + - Fixed warning for too low pt particles in case of active area computation + - Temporarily removed the test example_whole_event_using_charged_info + +2017/08/21: release of version 1.2.2: + - Added function set_max_standardDeltaR for backward compatibility. It was replaced in version 1.1.3 by function set_max_distance. In this version, it does the same as the function set_max_distance. + - Further speed improvement for whole event subtraction (especially for small _max_distance parameters, such as 0.25) + + +2017/08/07: release of version 1.2.1: + - Fixed bug for distance enum ConstituentSubtractor::angle + - Added check for the jet-by-jet correction to not use the speed optimization + +2017/07/20: release of version 1.2.0: + - Important change for the output corrected particles in case of correction of massive particles. The corrected zero pt particles with non-zero corrected delta_m (massive particles in rest) are now included in the output by default. This is the recommended usage. The user can change this behaviour by using function "set_remove_all_zero_pt_particles". By using argument true, all the zero pt corrected particles are removed. + - Significant change in the speed of the whole event CS procedure. For small values of the _max_distance parameter (~0.25), the speed is now ~10-times greater. + - Added new rescaling classes: rapidity vs azimuth dependence in TH2 Root histogram or in vector >, and rapidity vs azimuth dependence for heavy ions where the rapidity dependence is taken from a vector. + +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 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