Fork me on GitHub

source: git/modules/FastJetFinder.cc@ df35033

ImprovedOutputFile Timing dual_readout llp
Last change on this file since df35033 was cab38f6, checked in by Pavel Demin <pavel.demin@…>, 10 years ago

remove svn tags and fix formatting

  • Property mode set to 100644
File size: 12.0 KB
Line 
1/*
2 * Delphes: a framework for fast simulation of a generic collider experiment
3 * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20/** \class FastJetFinder
21 *
22 * Finds jets using FastJet library.
23 *
24 * \author P. Demin - UCL, Louvain-la-Neuve
25 *
26 */
27
28#include "modules/FastJetFinder.h"
29
30#include "classes/DelphesClasses.h"
31#include "classes/DelphesFactory.h"
32#include "classes/DelphesFormula.h"
33
34#include "ExRootAnalysis/ExRootResult.h"
35#include "ExRootAnalysis/ExRootFilter.h"
36#include "ExRootAnalysis/ExRootClassifier.h"
37
38#include "TMath.h"
39#include "TString.h"
40#include "TFormula.h"
41#include "TRandom3.h"
42#include "TObjArray.h"
43#include "TDatabasePDG.h"
44#include "TLorentzVector.h"
45
46#include <algorithm>
47#include <stdexcept>
48#include <iostream>
49#include <sstream>
50#include <vector>
51
52#include "fastjet/PseudoJet.hh"
53#include "fastjet/JetDefinition.hh"
54#include "fastjet/ClusterSequence.hh"
55#include "fastjet/Selector.hh"
56#include "fastjet/ClusterSequenceArea.hh"
57#include "fastjet/tools/JetMedianBackgroundEstimator.hh"
58
59#include "fastjet/plugins/SISCone/fastjet/SISConePlugin.hh"
60#include "fastjet/plugins/CDFCones/fastjet/CDFMidPointPlugin.hh"
61#include "fastjet/plugins/CDFCones/fastjet/CDFJetCluPlugin.hh"
62
63#include "fastjet/contribs/Nsubjettiness/Nsubjettiness.hh"
64#include "fastjet/contribs/Nsubjettiness/Njettiness.hh"
65#include "fastjet/contribs/Nsubjettiness/NjettinessPlugin.hh"
66#include "fastjet/contribs/Nsubjettiness/WinnerTakeAllRecombiner.hh"
67
68using namespace std;
69using namespace fastjet;
70using namespace fastjet::contrib;
71
72
73//------------------------------------------------------------------------------
74
75FastJetFinder::FastJetFinder() :
76 fPlugin(0), fRecomb(0), fNjettinessPlugin(0), fDefinition(0), fAreaDefinition(0), fItInputArray(0)
77{
78
79}
80
81//------------------------------------------------------------------------------
82
83FastJetFinder::~FastJetFinder()
84{
85
86}
87
88//------------------------------------------------------------------------------
89
90void FastJetFinder::Init()
91{
92 JetDefinition::Plugin *plugin = 0;
93 JetDefinition::Recombiner *recomb = 0;
94 NjettinessPlugin *njetPlugin = 0;
95
96 // read eta ranges
97
98 ExRootConfParam param = GetParam("RhoEtaRange");
99 Long_t i, size;
100
101 fEtaRangeMap.clear();
102 size = param.GetSize();
103 for(i = 0; i < size/2; ++i)
104 {
105 fEtaRangeMap[param[i*2].GetDouble()] = param[i*2 + 1].GetDouble();
106 }
107
108 // define algorithm
109
110 fJetAlgorithm = GetInt("JetAlgorithm", 6);
111 fParameterR = GetDouble("ParameterR", 0.5);
112
113 fConeRadius = GetDouble("ConeRadius", 0.5);
114 fSeedThreshold = GetDouble("SeedThreshold", 1.0);
115 fConeAreaFraction = GetDouble("ConeAreaFraction", 1.0);
116 fMaxIterations = GetInt("MaxIterations", 100);
117 fMaxPairSize = GetInt("MaxPairSize", 2);
118 fIratch = GetInt("Iratch", 1);
119 fAdjacencyCut = GetInt("AdjacencyCut", 2);
120 fOverlapThreshold = GetDouble("OverlapThreshold", 0.75);
121
122 fJetPTMin = GetDouble("JetPTMin", 10.0);
123
124 //-- N(sub)jettiness parameters --
125
126 fComputeNsubjettiness = GetBool("ComputeNsubjettiness", false);
127 fBeta = GetDouble("Beta", 1.0);
128 fAxisMode = GetInt("AxisMode", 1);
129 fRcutOff = GetDouble("RcutOff", 0.8); // used only if Njettiness is used as jet clustering algo (case 8)
130 fN = GetInt("N", 2); // used only if Njettiness is used as jet clustering algo (case 8)
131
132 // --- Jet Area Parameters ---
133 fAreaAlgorithm = GetInt("AreaAlgorithm", 0);
134 fComputeRho = GetBool("ComputeRho", false);
135
136 // - ghost based areas -
137 fGhostEtaMax = GetDouble("GhostEtaMax", 5.0);
138 fRepeat = GetInt("Repeat", 1);
139 fGhostArea = GetDouble("GhostArea", 0.01);
140 fGridScatter = GetDouble("GridScatter", 1.0);
141 fPtScatter = GetDouble("PtScatter", 0.1);
142 fMeanGhostPt = GetDouble("MeanGhostPt", 1.0E-100);
143
144 // - voronoi based areas -
145 fEffectiveRfact = GetDouble("EffectiveRfact", 1.0);
146
147 switch(fAreaAlgorithm)
148 {
149 case 1:
150 fAreaDefinition = new AreaDefinition(active_area_explicit_ghosts, GhostedAreaSpec(fGhostEtaMax, fRepeat, fGhostArea, fGridScatter, fPtScatter, fMeanGhostPt));
151 break;
152 case 2:
153 fAreaDefinition = new AreaDefinition(one_ghost_passive_area, GhostedAreaSpec(fGhostEtaMax, fRepeat, fGhostArea, fGridScatter, fPtScatter, fMeanGhostPt));
154 break;
155 case 3:
156 fAreaDefinition = new AreaDefinition(passive_area, GhostedAreaSpec(fGhostEtaMax, fRepeat, fGhostArea, fGridScatter, fPtScatter, fMeanGhostPt));
157 break;
158 case 4:
159 fAreaDefinition = new AreaDefinition(VoronoiAreaSpec(fEffectiveRfact));
160 break;
161 case 5:
162 fAreaDefinition = new AreaDefinition(active_area, GhostedAreaSpec(fGhostEtaMax, fRepeat, fGhostArea, fGridScatter, fPtScatter, fMeanGhostPt));
163 break;
164 default:
165 case 0:
166 fAreaDefinition = 0;
167 break;
168 }
169
170 switch(fJetAlgorithm)
171 {
172 case 1:
173 plugin = new CDFJetCluPlugin(fSeedThreshold, fConeRadius, fAdjacencyCut, fMaxIterations, fIratch, fOverlapThreshold);
174 fDefinition = new JetDefinition(plugin);
175 break;
176 case 2:
177 plugin = new CDFMidPointPlugin(fSeedThreshold, fConeRadius, fConeAreaFraction, fMaxPairSize, fMaxIterations, fOverlapThreshold);
178 fDefinition = new JetDefinition(plugin);
179 break;
180 case 3:
181 plugin = new SISConePlugin(fConeRadius, fOverlapThreshold, fMaxIterations, fJetPTMin);
182 fDefinition = new JetDefinition(plugin);
183 break;
184 case 4:
185 fDefinition = new JetDefinition(kt_algorithm, fParameterR);
186 break;
187 case 5:
188 fDefinition = new JetDefinition(cambridge_algorithm, fParameterR);
189 break;
190 default:
191 case 6:
192 fDefinition = new JetDefinition(antikt_algorithm, fParameterR);
193 break;
194 case 7:
195 recomb = new WinnerTakeAllRecombiner();
196 fDefinition = new JetDefinition(antikt_algorithm, fParameterR, recomb, Best);
197 break;
198 case 8:
199 njetPlugin = new NjettinessPlugin(fN, Njettiness::wta_kt_axes, Njettiness::unnormalized_cutoff_measure, fBeta, fRcutOff);
200 fDefinition = new JetDefinition(njetPlugin);
201 break;
202 }
203
204 fPlugin = plugin;
205 fRecomb = recomb;
206 fNjettinessPlugin = njetPlugin;
207
208 ClusterSequence::print_banner();
209
210 // import input array
211
212 fInputArray = ImportArray(GetString("InputArray", "Calorimeter/towers"));
213 fItInputArray = fInputArray->MakeIterator();
214
215 // create output arrays
216
217 fOutputArray = ExportArray(GetString("OutputArray", "jets"));
218 fRhoOutputArray = ExportArray(GetString("RhoOutputArray", "rho"));
219}
220
221//------------------------------------------------------------------------------
222
223void FastJetFinder::Finish()
224{
225 if(fItInputArray) delete fItInputArray;
226 if(fDefinition) delete fDefinition;
227 if(fAreaDefinition) delete fAreaDefinition;
228 if(fPlugin) delete static_cast<JetDefinition::Plugin*>(fPlugin);
229 if(fRecomb) delete static_cast<JetDefinition::Recombiner*>(fRecomb);
230 if(fNjettinessPlugin) delete static_cast<JetDefinition::Plugin*>(fNjettinessPlugin);
231}
232
233//------------------------------------------------------------------------------
234
235void FastJetFinder::Process()
236{
237 Candidate *candidate, *constituent;
238 TLorentzVector momentum;
239
240 TLorentzVector constmomentum;
241
242 Double_t deta, dphi, detaMax, dphiMax;
243 Double_t time, weightTime, avTime;
244 Int_t number;
245 Double_t rho = 0;
246 PseudoJet jet, area;
247 vector<PseudoJet> inputList, outputList;
248 ClusterSequence *sequence;
249 map< Double_t, Double_t >::iterator itEtaRangeMap;
250
251 DelphesFactory *factory = GetFactory();
252
253 inputList.clear();
254
255 // loop over input objects
256 fItInputArray->Reset();
257 number = 0;
258 while((candidate = static_cast<Candidate*>(fItInputArray->Next())))
259 {
260 momentum = candidate->Momentum;
261 jet = PseudoJet(momentum.Px(), momentum.Py(), momentum.Pz(), momentum.E());
262 jet.set_user_index(number);
263 inputList.push_back(jet);
264 ++number;
265 }
266
267 // construct jets
268 if(fAreaDefinition)
269 {
270 sequence = new ClusterSequenceArea(inputList, *fDefinition, *fAreaDefinition);
271 }
272 else
273 {
274 sequence = new ClusterSequence(inputList, *fDefinition);
275 }
276
277 // compute rho and store it
278 if(fComputeRho && fAreaDefinition)
279 {
280 for(itEtaRangeMap = fEtaRangeMap.begin(); itEtaRangeMap != fEtaRangeMap.end(); ++itEtaRangeMap)
281 {
282 Selector select_rapidity = SelectorAbsRapRange(itEtaRangeMap->first, itEtaRangeMap->second);
283 JetMedianBackgroundEstimator estimator(select_rapidity, *fDefinition, *fAreaDefinition);
284 estimator.set_particles(inputList);
285 rho = estimator.rho();
286
287 candidate = factory->NewCandidate();
288 candidate->Momentum.SetPtEtaPhiE(rho, 0.0, 0.0, rho);
289 candidate->Edges[0] = itEtaRangeMap->first;
290 candidate->Edges[1] = itEtaRangeMap->second;
291 fRhoOutputArray->Add(candidate);
292 }
293 }
294
295 outputList.clear();
296 outputList = sorted_by_pt(sequence->inclusive_jets(fJetPTMin));
297
298
299 // loop over all jets and export them
300 detaMax = 0.0;
301 dphiMax = 0.0;
302 vector<PseudoJet>::iterator itInputList, itOutputList;
303 for(itOutputList = outputList.begin(); itOutputList != outputList.end(); ++itOutputList)
304 {
305 jet = *itOutputList;
306 if(fJetAlgorithm == 7) jet = join(jet.constituents());
307
308 momentum.SetPxPyPzE(jet.px(), jet.py(), jet.pz(), jet.E());
309
310 area.reset(0.0, 0.0, 0.0, 0.0);
311 if(fAreaDefinition) area = itOutputList->area_4vector();
312
313 candidate = factory->NewCandidate();
314
315 time=0;
316 weightTime=0;
317
318 inputList.clear();
319 inputList = sequence->constituents(*itOutputList);
320
321 constmomentum.SetPxPyPzE(0.0,0.0,0.0,0.0);;
322
323 for(itInputList = inputList.begin(); itInputList != inputList.end(); ++itInputList)
324 {
325 constituent = static_cast<Candidate*>(fInputArray->At(itInputList->user_index()));
326
327 constmomentum += constituent->Momentum;
328
329 deta = TMath::Abs(momentum.Eta() - constituent->Momentum.Eta());
330 dphi = TMath::Abs(momentum.DeltaPhi(constituent->Momentum));
331 if(deta > detaMax) detaMax = deta;
332 if(dphi > dphiMax) dphiMax = dphi;
333
334 time += TMath::Sqrt(constituent->Momentum.E())*(constituent->Position.T());
335 weightTime += TMath::Sqrt(constituent->Momentum.E());
336
337 candidate->AddCandidate(constituent);
338 }
339
340 avTime = time/weightTime;
341
342 candidate->Momentum = momentum;
343 candidate->Position.SetT(avTime);
344 candidate->Area.SetPxPyPzE(area.px(), area.py(), area.pz(), area.E());
345
346 candidate->DeltaEta = detaMax;
347 candidate->DeltaPhi = dphiMax;
348
349 // --- compute N-subjettiness with N = 1,2,3,4,5 ----
350
351 if(fComputeNsubjettiness)
352 {
353 Njettiness::AxesMode axisMode;
354
355 switch(fAxisMode)
356 {
357 default:
358 case 1:
359 axisMode = Njettiness::wta_kt_axes;
360 break;
361 case 2:
362 axisMode = Njettiness::onepass_wta_kt_axes;
363 break;
364 case 3:
365 axisMode = Njettiness::kt_axes;
366 break;
367 case 4:
368 axisMode = Njettiness::onepass_kt_axes;
369 break;
370 }
371
372 Njettiness::MeasureMode measureMode = Njettiness::unnormalized_measure;
373
374 Nsubjettiness nSub1(1, axisMode, measureMode, fBeta);
375 Nsubjettiness nSub2(2, axisMode, measureMode, fBeta);
376 Nsubjettiness nSub3(3, axisMode, measureMode, fBeta);
377 Nsubjettiness nSub4(4, axisMode, measureMode, fBeta);
378 Nsubjettiness nSub5(5, axisMode, measureMode, fBeta);
379
380 candidate->Tau[0] = nSub1(*itOutputList);
381 candidate->Tau[1] = nSub2(*itOutputList);
382 candidate->Tau[2] = nSub3(*itOutputList);
383 candidate->Tau[3] = nSub4(*itOutputList);
384 candidate->Tau[4] = nSub5(*itOutputList);
385 }
386
387
388 fOutputArray->Add(candidate);
389 }
390 delete sequence;
391}
Note: See TracBrowser for help on using the repository browser.