Fork me on GitHub

Ignore:
Timestamp:
Dec 9, 2014, 1:27:13 PM (10 years ago)
Author:
Michele <michele.selvaggi@…>
Branches:
ImprovedOutputFile, Timing, dual_readout, llp, master
Children:
37deb3b, 9e991f8
Parents:
f6b6ee7 (diff), e7e90df (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'TestFastJet310b1'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • external/fastjet/tools/Subtractor.cc

    rf6b6ee7 r49234af  
    1 //STARTHEADER
    2 // $Id$
    3 //
    4 // Copyright (c) 2005-2011, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
     1//FJSTARTHEADER
     2// $Id: Subtractor.cc 3670 2014-09-08 14:17:59Z soyez $
     3//
     4// Copyright (c) 2005-2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
    55//
    66//----------------------------------------------------------------------
     
    1313//
    1414//  The algorithms that underlie FastJet have required considerable
    15 //  development and are described in hep-ph/0512210. If you use
     15//  development. They are described in the original FastJet paper,
     16//  hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
    1617//  FastJet as part of work towards a scientific publication, please
    17 //  include a citation to the FastJet paper.
     18//  quote the version you use and include a citation to the manual and
     19//  optionally also to hep-ph/0512210.
    1820//
    1921//  FastJet is distributed in the hope that it will be useful,
     
    2527//  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
    2628//----------------------------------------------------------------------
    27 //ENDHEADER
     29//FJENDHEADER
    2830
    2931#include "fastjet/tools/Subtractor.hh"
     
    3840
    3941
     42//----------------------------------------------------------------------
     43// ctor
    4044Subtractor::Subtractor(double rho) : _bge(0), _rho(rho) {
    41   assert(_rho>0.0);
    42 }
    43 
     45  if (_rho<0.0) throw Error("Subtractor(rho) was passed a negative rho value; rho should be >= 0");
     46  set_defaults();
     47}
     48
     49//----------------------------------------------------------------------
     50// ctor
     51Subtractor::Subtractor(double rho, double rho_m) : _bge(0), _rho(rho) {
     52  if (_rho<0.0) throw Error("Subtractor(rho, rho_m) was passed a negative rho value; rho should be >= 0");
     53  if (rho_m<0.0) throw Error("Subtractor(rho, rho_m) was passed a negative rho_m value; rho_m should be >= 0");
     54  set_defaults();
     55  _rho_m = rho_m;
     56  set_use_rho_m(true);
     57}
     58
     59//----------------------------------------------------------------------
     60void Subtractor::set_defaults(){
     61  _rho_m = _invalid_rho;
     62  _use_rho_m = false; // likely to change in future releases!!
     63  _safe_mass = false; // likely to change in future releases!!
     64
     65  _sel_known_vertex = Selector();
     66  _sel_leading_vertex = Selector();
     67}
     68
     69//----------------------------------------------------------------------
     70// perform the subtraction of a given jet
    4471PseudoJet Subtractor::result(const PseudoJet & jet) const {
    4572  if (!jet.has_area()){
    46     throw Error("Trying to subtract a jet without area support");
    47   }
    48  
     73    throw Error("Subtractor::result(...): Trying to subtract a jet without area support");
     74  }
     75
     76  PseudoJet known_lv, known_pu;
     77  PseudoJet unknown = jet;
     78  if (_sel_known_vertex.worker()){
     79    // separate the jet constituents in 3 groups:
     80    //   unknown vertex
     81    //   known vertex, leading vertex
     82    //   known vertex, non-leading vertex (PU)
     83    vector<PseudoJet> constits_unknown, constits_known;
     84    _sel_known_vertex.sift(jet.constituents(),
     85                           constits_known,
     86                           constits_unknown);
     87    vector<PseudoJet> constits_known_lv, constits_known_pu;
     88    _sel_leading_vertex.sift(constits_known,
     89                             constits_known_lv,
     90                             constits_known_pu);
     91
     92    // For the parts related to the known vertices (LV or PU), we just
     93    // sum the 4-momenta. For the unknown part, we assign it the full
     94    // jet area.
     95    known_lv = (constits_known_lv.size()!=0)
     96      ? SelectorIdentity().sum(constits_known_lv) : 0.0*jet;
     97    known_pu = (constits_known_pu.size()!=0)
     98      ? SelectorIdentity().sum(constits_known_pu) : 0.0*jet;
     99    if (constits_unknown.size()==0){
     100      // no need for any form of subtraction!
     101      PseudoJet subtracted_jet = jet;
     102      subtracted_jet.reset_momentum(known_lv);
     103      return subtracted_jet;
     104    }
     105    unknown = jet; // that keeps all info including area
     106    unknown.reset_momentum(SelectorIdentity().sum(constits_unknown));
     107  } else {
     108    known_lv = jet; // ensures correct rap-phi!
     109    known_lv *= 0.0;
     110    known_pu = known_lv;
     111  }
     112
     113  // prepare for the subtraction and compute the 4-vector to be
     114  // subtracted
     115  PseudoJet subtracted_jet = jet;
     116  PseudoJet to_subtract = known_pu + _amount_to_subtract(unknown);
     117
     118  // sanity check for the transverse momentum
     119  if (to_subtract.pt2() < jet.pt2() ) {
     120    // this subtraction should retain the jet's structural
     121    // information
     122    subtracted_jet -= to_subtract;
     123  } else {
     124    // this sets the jet's momentum while maintaining all of the jet's
     125    // structural information
     126    subtracted_jet.reset_momentum(known_lv);
     127    return subtracted_jet;
     128  }
     129
     130  // make sure that in the end the pt is at least the one known to
     131  // come from the leading vertex
     132  if (subtracted_jet.pt2() < known_lv.pt2()){
     133    subtracted_jet.reset_momentum(known_lv);
     134    return subtracted_jet;
     135  }
     136
     137  // sanity check for the mass (if needed)
     138  if ((_safe_mass) && (subtracted_jet.m2() < known_lv.m2())){
     139    // in this case, we keep pt and phi as obtained from the
     140    // subtraction above and take rap and m from the part that comes
     141    // from the leading vertex (or the original jet if nothing comes
     142    // from the leading vertex)
     143    subtracted_jet.reset_momentum(PtYPhiM(subtracted_jet.pt(),
     144                                          known_lv.rap(),
     145                                          subtracted_jet.phi(),
     146                                          known_lv.m()));
     147  }
     148
     149  return subtracted_jet;
     150}
     151
     152//----------------------------------------------------------------------
     153std::string Subtractor::description() const{
     154  if (_bge != 0) {
     155    string desc = "Subtractor that uses the following background estimator to determine rho: "+_bge->description();
     156    if (use_rho_m()) desc += "; including the rho_m correction";
     157    if (safe_mass()) desc += "; including mass safety tests";
     158    if (_sel_known_vertex.worker()){
     159      desc += "; using known vertex selection: "+_sel_known_vertex.description()+" and leading vertex selection: "+_sel_leading_vertex.description();
     160    }
     161    return desc;
     162  } else if (_rho != _invalid_rho) {
     163    ostringstream ostr;
     164    ostr << "Subtractor that uses a fixed value of rho = " << _rho;
     165    if (use_rho_m()) ostr << " and rho_m = " << _rho_m;
     166    return ostr.str();
     167  } else {
     168    return "Uninitialised subtractor";
     169  }
     170}
     171
     172//----------------------------------------------------------------------
     173// compute the 4-vector that should be subtracted from the given
     174// jet
     175PseudoJet Subtractor::_amount_to_subtract(const PseudoJet &jet) const{
     176  // the "transverse momentum" part
    49177  double rho;
    50178  if (_bge != 0) {
     
    53181    rho = _rho;
    54182  } else {
    55     throw Error("default Subtractor does not have any information about the background, which is needed to perform the subtraction");
    56   }
    57 
    58   PseudoJet subtracted_jet = jet;
    59   PseudoJet area4vect = jet.area_4vector();
    60   // sanity check
    61   if (rho*area4vect.perp() < jet.perp() ) {
    62     // this subtraction should retain the jet's structural
    63     // information
    64     subtracted_jet -= rho*area4vect;
    65   } else {
    66     // this sets the jet's momentum to zero while
    67     // maintaining all of the jet's structural information
    68     subtracted_jet *= 0;
    69   }
    70   return subtracted_jet;
    71 }
    72 
    73 //----------------------------------------------------------------------
    74 std::string Subtractor::description() const{
    75   if (_bge != 0) {
    76     return "Subtractor that uses the following background estimator to determine rho: "+_bge->description();
    77   } else if (_rho != _invalid_rho) {
    78     ostringstream ostr;
    79     ostr << "Subtractor that uses a fixed value of rho = " << _rho;
    80     return ostr.str();
    81   } else {
    82     return "Uninitialised subtractor";
    83   }
    84 }
     183    throw Error("Subtractor::_amount_to_subtract(...): default Subtractor does not have any information about the background, needed to perform the subtraction");
     184  }
     185
     186  PseudoJet area = jet.area_4vector();
     187  PseudoJet to_subtract = rho*area;
     188
     189  double const rho_m_warning_threshold = 1e-5;
     190
     191  // add an optional contribution from the unknown particles masses
     192  if (_use_rho_m) {
     193    double rho_m;
     194   
     195    if (_bge != 0) {
     196      if (!_bge->has_rho_m()) throw Error("Subtractor::_amount_to_subtract(...): requested subtraction with rho_m from a background estimator, but the estimator does not have rho_m support");
     197      rho_m = _bge->rho_m(jet);
     198    } else if (_rho_m != _invalid_rho) {
     199      rho_m = _rho_m;
     200    } else {
     201      throw Error("Subtractor::_amount_to_subtract(...): default Subtractor does not have any information about the background rho_m, needed to perform the rho_m subtraction");
     202    }
     203    to_subtract += rho_m * PseudoJet(0.0, 0.0, area.pz(), area.E());
     204  } else if (_bge &&
     205             _bge->has_rho_m() &&
     206             _bge->rho_m(jet) > rho_m_warning_threshold * rho) {
     207    _unused_rho_m_warning.warn("Subtractor::_amount_to_subtract(...): Background estimator indicates non-zero rho_m, but use_rho_m()==false in subtractor; consider calling set_use_rho_m(true) to include the rho_m information");
     208  }
     209
     210  return to_subtract;
     211}
     212
    85213
    86214FASTJET_END_NAMESPACE
Note: See TracChangeset for help on using the changeset viewer.