CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BackgroundEstimator.cc
Go to the documentation of this file.
2 #include <fastjet/ClusterSequenceAreaBase.hh>
3 #include <iostream>
4 
5 using namespace fastjet;
6 using namespace std;
7 
8 //---------------------------------------------------------------------
9 // \class BackgroundEstimator
10 // Class to estimate the density of the background per unit area
11 //
12 // The default behaviour of this class is to compute the global
13 // properties of the background as it is done in ClusterSequenceArea.
14 // On top of that, we provide methods to specify an explicit set of
15 // jets to use or a list of jets to exclude.
16 // We also provide all sorts of additional information regarding
17 // the background estimation like the jets that have been used or
18 // the number of pure-ghost jets.
19 //---------------------------------------------------------------------
20 
21 // default ctor
22 // - csa the ClusterSequenceArea to use
23 // - range the range over which jets will be considered
24 BackgroundEstimator::BackgroundEstimator(const ClusterSequenceAreaBase &csa, const RangeDefinition &range)
25  : _csa(csa), _range(range){
26  reset();
27 }
28 
29 // default dtor
31 
32 }
33 
34 // reset to default values
35 // set the list of included jets to the inclusive jets and clear the excluded ones
37  // set the list of included jets to the inclusive jets
38  _included_jets = _csa.inclusive_jets();
39  _all_from_inclusive = true;
40  //set_included_jets(_csa.inclusive_jets());
41 
42  // clear the list of explicitly excluded jets
43  _excluded_jets.clear();
44  //set_excluded_jets(vector<PseudoJet>());
45 
46  // set the remaining default parameters
47  set_use_area_4vector(); // true by default
48 
49  // reset the computed values
50  _median_rho = _sigma = _mean_area = 0.0;
52  _empty_area = 0.0;
53  _uptodate = false;
54 }
55 
56 
57 // do the actual job
59  //TODO: check that the alg is OK for median computation
60  //_check_jet_alg_good_for_median();
61 
62  // fill the vector of pt/area with the jets
63  // - in included_jets
64  // - not in excluded_jets
65  // - in the range
66  vector<double> pt_over_areas;
67  double total_area = 0.0;
68 
69  _n_jets_used = 0;
70  _n_jets_excluded = 0;
71 
72  for (unsigned i = 0; i < _included_jets.size(); i++) {
73  const PseudoJet & current_jet = _included_jets[i];
74 
75  // check that the jet is not explicitly excluded
76  // we'll compare them using their cluster_history_index
77  bool excluded = false;
78  int ref_idx = current_jet.cluster_hist_index();
79  for (unsigned int j = 0; j < _excluded_jets.size(); j++)
80  excluded |= (_excluded_jets[j].cluster_hist_index() == ref_idx);
81 
82  // check if the jet is in the range
83  if (_range.is_in_range(current_jet)){
84  if (excluded){
85  // keep track of the explicitly excluded jets
87  } else {
88  double this_area = (_use_area_4vector)
89  ? _csa.area_4vector(current_jet).perp()
90  : _csa.area(current_jet);
91 
92  pt_over_areas.push_back(current_jet.perp()/this_area);
93  total_area += this_area;
94  _n_jets_used++;
95  }
96  }
97  }
98 
99  // there is nothing inside our region, so answer will always be zero
100  if (pt_over_areas.size() == 0) {
101  _median_rho = 0.0;
102  _sigma = 0.0;
103  _mean_area = 0.0;
104  return;
105  }
106 
107  // get median (pt/area) [this is the "old" median definition. It considers
108  // only the "real" jets in calculating the median, i.e. excluding the
109  // only-ghost ones; it will be supplemented with more info below]
110  sort(pt_over_areas.begin(), pt_over_areas.end());
111 
112  // determine the number of empty jets
113  _empty_area = 0.0;
114  _n_empty_jets = 0.0;
115  if (_csa.has_explicit_ghosts()) {
116  _empty_area = 0.0;
117  _n_empty_jets = 0;
118  } else if (_all_from_inclusive) {
119  _empty_area = _csa.empty_area(_range);
120  _n_empty_jets = _csa.n_empty_jets(_range);
121  } else {
122  _empty_area = _csa.empty_area_from_jets(_included_jets, _range);
123  _mean_area = total_area / _n_jets_used; // temporary value
124  _n_empty_jets = _empty_area / _mean_area;
125  }
126 
127  double total_njets = _n_jets_used + _n_empty_jets;
128  total_area += _empty_area;
129 
130 
131  // now get the median & error, accounting for empty jets
132  // define the fractions of distribution at median, median-1sigma
133  double posn[2] = {0.5, (1.0-0.6827)/2.0};
134  double res[2];
135 
136  for (int i = 0; i < 2; i++) {
137  double nj_median_pos = (total_njets-1)*posn[i] - _n_empty_jets;
138  double nj_median_ratio;
139  if (nj_median_pos >= 0 && pt_over_areas.size() > 1) {
140  int int_nj_median = int(nj_median_pos);
141  nj_median_ratio =
142  pt_over_areas[int_nj_median] * (int_nj_median+1-nj_median_pos)
143  + pt_over_areas[int_nj_median+1] * (nj_median_pos - int_nj_median);
144  } else {
145  nj_median_ratio = 0.0;
146  }
147  res[i] = nj_median_ratio;
148  }
149 
150  // store the results
151  double error = res[0] - res[1];
152  _median_rho = res[0];
153  _mean_area = total_area / total_njets;
154  _sigma = error * sqrt(_mean_area);
155 
156  // record that the computation has been performed
157  _uptodate = true;
158 }
159 
160 
161 
162 
int i
Definition: DBlmapReader.cc:9
double _median_rho
background estimated density per unit area
void _compute()
do the actual job
unsigned int _n_jets_excluded
number of jets that have explicitly been excluded
double _empty_area
the empty (pure-ghost/unclustered) area!
const RangeDefinition & _range
range to compute the background in
unsigned int _n_jets_used
number of jets used to estimate the background
bool _uptodate
true when the background computation is up-to-date
T sqrt(T t)
Definition: SSEVec.h:46
int j
Definition: DBlmapReader.cc:9
std::vector< PseudoJet > _excluded_jets
jets to be excluded
bool _all_from_inclusive
when true, we&#39;ll assume that the incl jets are the complete set
BackgroundEstimator(const ClusterSequenceAreaBase &csa, const RangeDefinition &range)
double _sigma
background estimated fluctuations
double _mean_area
mean area of the jets used to estimate the background
const ClusterSequenceAreaBase & _csa
cluster sequence to get jets and areas from
std::vector< PseudoJet > _included_jets
jets to be used
void set_use_area_4vector(bool use_it=true)
double _n_empty_jets
number of empty (pure-ghost) jets