Fork me on GitHub

source: svn/trunk/Utilities/Fastjet/src/ClusterSequenceAreaBase.cc@ 492

Last change on this file since 492 was 11, checked in by severine ovyn, 16 years ago

Fastjet added; CDFCones directory has been changed

File size: 10.2 KB
Line 
1
2//STARTHEADER
3// $Id: ClusterSequenceAreaBase.cc,v 1.1 2008-11-06 14:32:14 ovyn Exp $
4//
5// Copyright (c) 2005-2006, Matteo Cacciari and Gavin Salam
6//
7//----------------------------------------------------------------------
8// This file is part of FastJet.
9//
10// FastJet is free software; you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation; either version 2 of the License, or
13// (at your option) any later version.
14//
15// The algorithms that underlie FastJet have required considerable
16// development and are described in hep-ph/0512210. If you use
17// FastJet as part of work towards a scientific publication, please
18// include a citation to the FastJet paper.
19//
20// FastJet is distributed in the hope that it will be useful,
21// but WITHOUT ANY WARRANTY; without even the implied warranty of
22// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23// GNU General Public License for more details.
24//
25// You should have received a copy of the GNU General Public License
26// along with FastJet; if not, write to the Free Software
27// Foundation, Inc.:
28// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29//----------------------------------------------------------------------
30//ENDHEADER
31
32
33
34
35#include "../include/fastjet/ClusterSequenceAreaBase.hh"
36#include <algorithm>
37
38FASTJET_BEGIN_NAMESPACE
39
40using namespace std;
41
42
43/// allow for warnings
44LimitedWarning ClusterSequenceAreaBase::_warnings;
45
46//----------------------------------------------------------------------
47/// return the total area, within range, that is free of jets.
48///
49/// Calculate this as (range area) - \sum_{i in range} A_i
50///
51double ClusterSequenceAreaBase::empty_area(const RangeDefinition & range) const {
52 double empty = range.area();
53 vector<PseudoJet> incl_jets(inclusive_jets(0.0));
54 for (unsigned i = 0; i < incl_jets.size(); i++) {
55 if (range.is_in_range(incl_jets[i])) empty -= area(incl_jets[i]);
56 }
57 return empty;
58}
59
60double ClusterSequenceAreaBase::median_pt_per_unit_area(const RangeDefinition & range) const {
61 return median_pt_per_unit_something(range,false);
62}
63
64double ClusterSequenceAreaBase::median_pt_per_unit_area_4vector(const RangeDefinition & range) const {
65 return median_pt_per_unit_something(range,true);
66}
67
68
69//----------------------------------------------------------------------
70/// the median of (pt/area) for jets contained within range, counting
71/// the empty area as if it were made up of a collection of empty
72/// jets each of area (0.55 * pi R^2).
73double ClusterSequenceAreaBase::median_pt_per_unit_something(
74 const RangeDefinition & range, bool use_area_4vector) const {
75
76 double median, sigma, mean_area;
77 get_median_rho_and_sigma(range, use_area_4vector, median, sigma, mean_area);
78 return median;
79
80}
81
82
83//----------------------------------------------------------------------
84/// fits a form pt_per_unit_area(y) = a + b*y^2 for jets in range.
85/// exclude_above allows one to exclude large values of pt/area from fit.
86/// use_area_4vector = true uses the 4vector areas.
87void ClusterSequenceAreaBase::parabolic_pt_per_unit_area(
88 double & a, double & b, const RangeDefinition & range,
89 double exclude_above, bool use_area_4vector) const {
90
91 int n=0;
92 int n_excluded = 0;
93 double mean_f=0, mean_x2=0, mean_x4=0, mean_fx2=0;
94
95 vector<PseudoJet> incl_jets = inclusive_jets();
96
97 for (unsigned i = 0; i < incl_jets.size(); i++) {
98 if (range.is_in_range(incl_jets[i])) {
99 double this_area;
100 if ( use_area_4vector ) {
101 this_area = area_4vector(incl_jets[i]).perp();
102 } else {
103 this_area = area(incl_jets[i]);
104 }
105 double f = incl_jets[i].perp()/this_area;
106 if (exclude_above <= 0.0 || f < exclude_above) {
107 double x = incl_jets[i].rap(); double x2 = x*x;
108 mean_f += f;
109 mean_x2 += x2;
110 mean_x4 += x2*x2;
111 mean_fx2 += f*x2;
112 n++;
113 } else {
114 n_excluded++;
115 }
116 }
117 }
118
119 if (n <= 1) {
120 // meaningful results require at least two jets inside the
121 // area -- mind you if there are empty jets we should be in
122 // any case doing something special...
123 a = 0.0;
124 b = 0.0;
125 } else {
126 mean_f /= n;
127 mean_x2 /= n;
128 mean_x4 /= n;
129 mean_fx2 /= n;
130
131 b = (mean_f*mean_x2 - mean_fx2)/(mean_x2*mean_x2 - mean_x4);
132 a = mean_f - b*mean_x2;
133 }
134 //cerr << "n_excluded = "<< n_excluded << endl;
135}
136
137
138
139
140void ClusterSequenceAreaBase::get_median_rho_and_sigma(
141 const RangeDefinition & range, bool use_area_4vector,
142 double & median, double & sigma, double & mean_area) const {
143
144 _check_jet_alg_good_for_median();
145
146 vector<double> pt_over_areas;
147 vector<PseudoJet> incl_jets = inclusive_jets();
148 double total_area = 0.0;
149 double total_njets = 0;
150
151 for (unsigned i = 0; i < incl_jets.size(); i++) {
152 if (range.is_in_range(incl_jets[i])) {
153 double this_area;
154 if (use_area_4vector) {
155 this_area = area_4vector(incl_jets[i]).perp();
156 } else {
157 this_area = area(incl_jets[i]);
158 }
159 pt_over_areas.push_back(incl_jets[i].perp()/this_area);
160 total_area += this_area;
161 total_njets += 1.0;
162 }
163 }
164
165 // there is nothing inside our region, so answer will always be zero
166 if (pt_over_areas.size() == 0) {
167 median = 0.0;
168 sigma = 0.0;
169 mean_area = 0.0;
170 return;
171 }
172
173 // get median (pt/area) [this is the "old" median definition. It considers
174 // only the "real" jets in calculating the median, i.e. excluding the
175 // only-ghost ones]
176 sort(pt_over_areas.begin(), pt_over_areas.end());
177
178 // now get the median & error, accounting for empty jets
179 // define the fractions of distribution at median, median-1sigma
180 double posn[2] = {0.5, (1.0-0.6827)/2.0};
181 double res[2];
182
183 double n_empty = n_empty_jets(range);
184 total_njets += n_empty;
185 total_area += empty_area(range);
186
187 for (int i = 0; i < 2; i++) {
188 double nj_median_pos =
189 (pt_over_areas.size()-1 + n_empty)*posn[i] - n_empty;
190 double nj_median_ratio;
191 if (nj_median_pos >= 0 && pt_over_areas.size() > 1) {
192 int int_nj_median = int(nj_median_pos);
193 nj_median_ratio =
194 pt_over_areas[int_nj_median] * (int_nj_median+1-nj_median_pos)
195 + pt_over_areas[int_nj_median+1] * (nj_median_pos - int_nj_median);
196 } else {
197 nj_median_ratio = 0.0;
198 }
199 res[i] = nj_median_ratio;
200 }
201 median = res[0];
202 double error = res[0] - res[1];
203 mean_area = total_area / total_njets;
204 sigma = error * sqrt(mean_area);
205}
206
207
208/// return a vector of all subtracted jets, using area_4vector, given rho.
209/// Only inclusive_jets above ptmin are subtracted and returned.
210/// the ordering is the same as that of sorted_by_pt(cs.inclusive_jets()),
211/// i.e. not necessarily ordered in pt once subtracted
212vector<PseudoJet> ClusterSequenceAreaBase::subtracted_jets(const double rho,
213 const double ptmin)
214 const {
215 vector<PseudoJet> sub_jets;
216 vector<PseudoJet> jets = sorted_by_pt(inclusive_jets(ptmin));
217 for (unsigned i=0; i<jets.size(); i++) {
218 PseudoJet sub_jet = subtracted_jet(jets[i],rho);
219 sub_jets.push_back(sub_jet);
220 }
221 return sub_jets;
222}
223
224/// return a vector of subtracted jets, using area_4vector.
225/// Only inclusive_jets above ptmin are subtracted and returned.
226/// the ordering is the same as that of sorted_by_pt(cs.inclusive_jets()),
227/// i.e. not necessarily ordered in pt once subtracted
228vector<PseudoJet> ClusterSequenceAreaBase::subtracted_jets(
229 const RangeDefinition & range,
230 const double ptmin)
231 const {
232 double rho = median_pt_per_unit_area_4vector(range);
233 return subtracted_jets(rho,ptmin);
234}
235
236
237/// return a subtracted jet, using area_4vector, given rho
238PseudoJet ClusterSequenceAreaBase::subtracted_jet(const PseudoJet & jet,
239 const double rho) const {
240 PseudoJet area4vect = area_4vector(jet);
241 PseudoJet sub_jet;
242 // sanity check
243 if (rho*area4vect.perp() < jet.perp() ) {
244 sub_jet = jet - rho*area4vect;
245 } else { sub_jet = PseudoJet(0.0,0.0,0.0,0.0); }
246
247 // make sure the subtracted jet has the same index
248 // (i.e. "looks like") the original jet
249 sub_jet.set_cluster_hist_index(jet.cluster_hist_index());
250
251 return sub_jet;
252}
253
254
255/// return a subtracted jet, using area_4vector; note that this is
256/// potentially inefficient if repeatedly used for many different
257/// jets, because rho will be recalculated each time around.
258PseudoJet ClusterSequenceAreaBase::subtracted_jet(const PseudoJet & jet,
259 const RangeDefinition & range) const {
260 double rho = median_pt_per_unit_area_4vector(range);
261 PseudoJet sub_jet = subtracted_jet(jet, rho);
262 return sub_jet;
263}
264
265
266/// return the subtracted pt, given rho
267double ClusterSequenceAreaBase::subtracted_pt(const PseudoJet & jet,
268 const double rho,
269 bool use_area_4vector) const {
270 if ( use_area_4vector ) {
271 PseudoJet sub_jet = subtracted_jet(jet,rho);
272 return sub_jet.perp();
273 } else {
274 return jet.perp() - rho*area(jet);
275 }
276}
277
278
279/// return the subtracted pt; note that this is
280/// potentially inefficient if repeatedly used for many different
281/// jets, because rho will be recalculated each time around.
282double ClusterSequenceAreaBase::subtracted_pt(const PseudoJet & jet,
283 const RangeDefinition & range,
284 bool use_area_4vector) const {
285 if ( use_area_4vector ) {
286 PseudoJet sub_jet = subtracted_jet(jet,range);
287 return sub_jet.perp();
288 } else {
289 double rho = median_pt_per_unit_area(range);
290 return subtracted_pt(jet,rho,false);
291 }
292}
293
294
295/// check the jet algorithm is suitable (and if not issue a warning)
296void ClusterSequenceAreaBase::_check_jet_alg_good_for_median() const {
297 if (jet_def().jet_algorithm() != kt_algorithm
298 && jet_def().jet_algorithm() != cambridge_algorithm
299 && jet_def().jet_algorithm() != cambridge_for_passive_algorithm) {
300 _warnings.warn("ClusterSequenceAreaBase: jet_def being used may not be suitable for estimating diffuse backgrounds (good options are kt, cam)");
301 }
302}
303
304
305
306FASTJET_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.