Fork me on GitHub

source: git/modules/FastJetFinder.cc@ 8624f58

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

fix GPLv3 header

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