Fork me on GitHub

source: git/modules/FastJetFinder.cc@ 3b3d0ad

ImprovedOutputFile Timing llp
Last change on this file since 3b3d0ad was 3b3d0ad, checked in by Pavel Demin <pavel-demin@…>, 6 years ago

fix formatting in FastJetFinder

  • Property mode set to 100644
File size: 17.4 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/ExtraRecombiners.hh"
67
68#include "fastjet/contribs/ValenciaPlugin/ValenciaPlugin.hh"
69
70#include "fastjet/tools/Filter.hh"
71#include "fastjet/tools/Pruner.hh"
72#include "fastjet/contribs/RecursiveTools/SoftDrop.hh"
73
74using namespace std;
75using namespace fastjet;
76using namespace fastjet::contrib;
77
78
79//------------------------------------------------------------------------------
80
81FastJetFinder::FastJetFinder() :
82 fPlugin(0), fRecomb(0), fAxesDef(0), fMeasureDef(0), fNjettinessPlugin(0), fValenciaPlugin(0),
83 fDefinition(0), fAreaDefinition(0), fItInputArray(0)
84{
85
86}
87
88//------------------------------------------------------------------------------
89
90FastJetFinder::~FastJetFinder()
91{
92
93}
94
95//------------------------------------------------------------------------------
96
97void FastJetFinder::Init()
98{
99 JetDefinition::Plugin *plugin = 0;
100 JetDefinition::Recombiner *recomb = 0;
101 ExRootConfParam param;
102 Long_t i, size;
103 Double_t etaMin, etaMax;
104 TEstimatorStruct estimatorStruct;
105
106 // define algorithm
107
108 fJetAlgorithm = GetInt("JetAlgorithm", 6);
109 fParameterR = GetDouble("ParameterR", 0.5);
110
111 fConeRadius = GetDouble("ConeRadius", 0.5);
112 fSeedThreshold = GetDouble("SeedThreshold", 1.0);
113 fConeAreaFraction = GetDouble("ConeAreaFraction", 1.0);
114 fMaxIterations = GetInt("MaxIterations", 100);
115 fMaxPairSize = GetInt("MaxPairSize", 2);
116 fIratch = GetInt("Iratch", 1);
117 fAdjacencyCut = GetInt("AdjacencyCut", 2);
118 fOverlapThreshold = GetDouble("OverlapThreshold", 0.75);
119
120 fJetPTMin = GetDouble("JetPTMin", 10.0);
121
122 //-- N(sub)jettiness parameters --
123
124 fComputeNsubjettiness = GetBool("ComputeNsubjettiness", false);
125 fBeta = GetDouble("Beta", 1.0);
126 fAxisMode = GetInt("AxisMode", 1);
127 fRcutOff = GetDouble("RcutOff", 0.8); // used only if Njettiness is used as jet clustering algo (case 8)
128 fN = GetInt("N", 2); // used only if Njettiness is used as jet clustering algo (case 8)
129
130 //-- Exclusive clustering for e+e- collisions --
131
132 fNJets = GetInt("NJets",2);
133 fExclusiveClustering = GetBool("ExclusiveClustering", false);
134
135 //-- Valencia Linear Collider algorithm
136
137 fGamma = GetDouble("Gamma", 1.0);
138 //fBeta parameter see above
139
140 fMeasureDef = new NormalizedMeasure(fBeta, fParameterR);
141
142 switch(fAxisMode)
143 {
144 default:
145 case 1:
146 fAxesDef = new WTA_KT_Axes();
147 break;
148 case 2:
149 fAxesDef = new OnePass_WTA_KT_Axes();
150 break;
151 case 3:
152 fAxesDef = new KT_Axes();
153 break;
154 case 4:
155 fAxesDef = new OnePass_KT_Axes();
156 }
157
158 //-- Trimming parameters --
159
160 fComputeTrimming = GetBool("ComputeTrimming", false);
161 fRTrim = GetDouble("RTrim", 0.2);
162 fPtFracTrim = GetDouble("PtFracTrim", 0.05);
163
164
165 //-- Pruning parameters --
166
167 fComputePruning = GetBool("ComputePruning", false);
168 fZcutPrun = GetDouble("ZcutPrun", 0.1);
169 fRcutPrun = GetDouble("RcutPrun", 0.5);
170 fRPrun = GetDouble("RPrun", 0.8);
171
172 //-- SoftDrop parameters --
173
174 fComputeSoftDrop = GetBool("ComputeSoftDrop", false);
175 fBetaSoftDrop = GetDouble("BetaSoftDrop", 0.0);
176 fSymmetryCutSoftDrop = GetDouble("SymmetryCutSoftDrop", 0.1);
177 fR0SoftDrop= GetDouble("R0SoftDrop=", 0.8);
178
179 // --- Jet Area Parameters ---
180
181 fAreaAlgorithm = GetInt("AreaAlgorithm", 0);
182 fComputeRho = GetBool("ComputeRho", false);
183
184 // - ghost based areas -
185 fGhostEtaMax = GetDouble("GhostEtaMax", 5.0);
186 fRepeat = GetInt("Repeat", 1);
187 fGhostArea = GetDouble("GhostArea", 0.01);
188 fGridScatter = GetDouble("GridScatter", 1.0);
189 fPtScatter = GetDouble("PtScatter", 0.1);
190 fMeanGhostPt = GetDouble("MeanGhostPt", 1.0E-100);
191
192 // - voronoi based areas -
193 fEffectiveRfact = GetDouble("EffectiveRfact", 1.0);
194
195 switch(fAreaAlgorithm)
196 {
197 default:
198 case 0:
199 fAreaDefinition = 0;
200 break;
201 case 1:
202 fAreaDefinition = new AreaDefinition(active_area_explicit_ghosts, GhostedAreaSpec(fGhostEtaMax, fRepeat, fGhostArea, fGridScatter, fPtScatter, fMeanGhostPt));
203 break;
204 case 2:
205 fAreaDefinition = new AreaDefinition(one_ghost_passive_area, GhostedAreaSpec(fGhostEtaMax, fRepeat, fGhostArea, fGridScatter, fPtScatter, fMeanGhostPt));
206 break;
207 case 3:
208 fAreaDefinition = new AreaDefinition(passive_area, GhostedAreaSpec(fGhostEtaMax, fRepeat, fGhostArea, fGridScatter, fPtScatter, fMeanGhostPt));
209 break;
210 case 4:
211 fAreaDefinition = new AreaDefinition(VoronoiAreaSpec(fEffectiveRfact));
212 break;
213 case 5:
214 fAreaDefinition = new AreaDefinition(active_area, GhostedAreaSpec(fGhostEtaMax, fRepeat, fGhostArea, fGridScatter, fPtScatter, fMeanGhostPt));
215 break;
216 }
217
218 switch(fJetAlgorithm)
219 {
220 case 1:
221 plugin = new CDFJetCluPlugin(fSeedThreshold, fConeRadius, fAdjacencyCut, fMaxIterations, fIratch, fOverlapThreshold);
222 fDefinition = new JetDefinition(plugin);
223 break;
224 case 2:
225 plugin = new CDFMidPointPlugin(fSeedThreshold, fConeRadius, fConeAreaFraction, fMaxPairSize, fMaxIterations, fOverlapThreshold);
226 fDefinition = new JetDefinition(plugin);
227 break;
228 case 3:
229 plugin = new SISConePlugin(fConeRadius, fOverlapThreshold, fMaxIterations, fJetPTMin);
230 fDefinition = new JetDefinition(plugin);
231 break;
232 case 4:
233 fDefinition = new JetDefinition(kt_algorithm, fParameterR);
234 break;
235 case 5:
236 fDefinition = new JetDefinition(cambridge_algorithm, fParameterR);
237 break;
238 default:
239 case 6:
240 fDefinition = new JetDefinition(antikt_algorithm, fParameterR);
241 break;
242 case 7:
243 recomb = new WinnerTakeAllRecombiner();
244 fDefinition = new JetDefinition(antikt_algorithm, fParameterR, recomb, Best);
245 break;
246 case 8:
247 fNjettinessPlugin = new NjettinessPlugin(fN, Njettiness::wta_kt_axes, Njettiness::unnormalized_cutoff_measure, fBeta, fRcutOff);
248 fDefinition = new JetDefinition(fNjettinessPlugin);
249 break;
250 case 9:
251 fValenciaPlugin = new ValenciaPlugin(fParameterR, fBeta, fGamma);
252 fDefinition = new JetDefinition(fValenciaPlugin);
253 break;
254
255 }
256
257
258
259 fPlugin = plugin;
260 fRecomb = recomb;
261
262 ClusterSequence::print_banner();
263
264 if(fComputeRho && fAreaDefinition)
265 {
266 // read eta ranges
267
268 param = GetParam("RhoEtaRange");
269 size = param.GetSize();
270
271 fEstimators.clear();
272 for(i = 0; i < size/2; ++i)
273 {
274 etaMin = param[i*2].GetDouble();
275 etaMax = param[i*2 + 1].GetDouble();
276 estimatorStruct.estimator = new JetMedianBackgroundEstimator(SelectorRapRange(etaMin, etaMax), *fDefinition, *fAreaDefinition);
277 estimatorStruct.etaMin = etaMin;
278 estimatorStruct.etaMax = etaMax;
279 fEstimators.push_back(estimatorStruct);
280 }
281 }
282
283 // import input array
284
285 fInputArray = ImportArray(GetString("InputArray", "Calorimeter/towers"));
286 fItInputArray = fInputArray->MakeIterator();
287
288 // create output arrays
289
290 fOutputArray = ExportArray(GetString("OutputArray", "jets"));
291 fRhoOutputArray = ExportArray(GetString("RhoOutputArray", "rho"));
292}
293
294//------------------------------------------------------------------------------
295
296void FastJetFinder::Finish()
297{
298 vector< TEstimatorStruct >::iterator itEstimators;
299
300 for(itEstimators = fEstimators.begin(); itEstimators != fEstimators.end(); ++itEstimators)
301 {
302 if(itEstimators->estimator) delete itEstimators->estimator;
303 }
304
305 if(fItInputArray) delete fItInputArray;
306 if(fDefinition) delete fDefinition;
307 if(fAreaDefinition) delete fAreaDefinition;
308 if(fPlugin) delete static_cast<JetDefinition::Plugin*>(fPlugin);
309 if(fRecomb) delete static_cast<JetDefinition::Recombiner*>(fRecomb);
310 if(fNjettinessPlugin) delete static_cast<JetDefinition::Plugin*>(fNjettinessPlugin);
311 if(fAxesDef) delete fAxesDef;
312 if(fMeasureDef) delete fMeasureDef;
313 if(fValenciaPlugin) delete static_cast<JetDefinition::Plugin*>(fValenciaPlugin);
314
315}
316
317//------------------------------------------------------------------------------
318
319void FastJetFinder::Process()
320{
321 Candidate *candidate, *constituent;
322 TLorentzVector momentum;
323
324 Double_t deta, dphi, detaMax, dphiMax;
325 Double_t time, timeWeight;
326 Int_t number, ncharged, nneutrals;
327 Int_t charge;
328 Double_t rho = 0.0;
329 PseudoJet jet, area;
330 ClusterSequence *sequence;
331 vector< PseudoJet > inputList, outputList, subjets;
332 vector< PseudoJet >::iterator itInputList, itOutputList;
333 vector< TEstimatorStruct >::iterator itEstimators;
334 Double_t excl_ymerge23 = 0.0;
335 Double_t excl_ymerge34 = 0.0;
336 Double_t excl_ymerge45 = 0.0;
337 Double_t excl_ymerge56 = 0.0;
338
339 DelphesFactory *factory = GetFactory();
340
341 inputList.clear();
342
343 // loop over input objects
344 fItInputArray->Reset();
345 number = 0;
346 while((candidate = static_cast<Candidate*>(fItInputArray->Next())))
347 {
348 momentum = candidate->Momentum;
349 jet = PseudoJet(momentum.Px(), momentum.Py(), momentum.Pz(), momentum.E());
350 jet.set_user_index(number);
351 inputList.push_back(jet);
352 ++number;
353 }
354
355 // construct jets
356 if(fAreaDefinition)
357 {
358 sequence = new ClusterSequenceArea(inputList, *fDefinition, *fAreaDefinition);
359 }
360 else
361 {
362 sequence = new ClusterSequence(inputList, *fDefinition);
363 }
364
365 // compute rho and store it
366 if(fComputeRho && fAreaDefinition)
367 {
368 for(itEstimators = fEstimators.begin(); itEstimators != fEstimators.end(); ++itEstimators)
369 {
370 itEstimators->estimator->set_particles(inputList);
371 rho = itEstimators->estimator->rho();
372
373 candidate = factory->NewCandidate();
374 candidate->Momentum.SetPtEtaPhiE(rho, 0.0, 0.0, rho);
375 candidate->Edges[0] = itEstimators->etaMin;
376 candidate->Edges[1] = itEstimators->etaMax;
377 fRhoOutputArray->Add(candidate);
378 }
379 }
380
381 outputList.clear();
382
383 if(fExclusiveClustering)
384 {
385 try{
386 outputList = sorted_by_pt(sequence->exclusive_jets( fNJets ));
387 }
388 catch(fastjet::Error)
389 {
390 outputList.clear();
391 }
392
393 excl_ymerge23 = sequence->exclusive_ymerge( 2 );
394 excl_ymerge34 = sequence->exclusive_ymerge( 3 );
395 excl_ymerge45 = sequence->exclusive_ymerge( 4 );
396 excl_ymerge56 = sequence->exclusive_ymerge( 5 );
397 }
398 else
399 {
400 outputList = sorted_by_pt(sequence->inclusive_jets(fJetPTMin));
401 }
402
403 // loop over all jets and export them
404 detaMax = 0.0;
405 dphiMax = 0.0;
406
407 for(itOutputList = outputList.begin(); itOutputList != outputList.end(); ++itOutputList)
408 {
409 jet = *itOutputList;
410 if(fJetAlgorithm == 7) jet = join(jet.constituents());
411
412 momentum.SetPxPyPzE(jet.px(), jet.py(), jet.pz(), jet.E());
413
414 area.reset(0.0, 0.0, 0.0, 0.0);
415 if(fAreaDefinition) area = itOutputList->area_4vector();
416
417 candidate = factory->NewCandidate();
418
419 time = 0.0;
420 timeWeight = 0.0;
421
422 charge = 0;
423
424 ncharged = 0;
425 nneutrals = 0;
426
427 inputList.clear();
428 inputList = sequence->constituents(*itOutputList);
429
430 for(itInputList = inputList.begin(); itInputList != inputList.end(); ++itInputList)
431 {
432 if(itInputList->user_index() < 0) continue;
433 constituent = static_cast<Candidate*>(fInputArray->At(itInputList->user_index()));
434
435 deta = TMath::Abs(momentum.Eta() - constituent->Momentum.Eta());
436 dphi = TMath::Abs(momentum.DeltaPhi(constituent->Momentum));
437 if(deta > detaMax) detaMax = deta;
438 if(dphi > dphiMax) dphiMax = dphi;
439
440 if(constituent->Charge == 0) nneutrals++;
441 else ncharged++;
442
443 time += TMath::Sqrt(constituent->Momentum.E())*(constituent->Position.T());
444 timeWeight += TMath::Sqrt(constituent->Momentum.E());
445
446 charge += constituent->Charge;
447
448 candidate->AddCandidate(constituent);
449 }
450
451 candidate->Momentum = momentum;
452 candidate->Position.SetT(time/timeWeight);
453 candidate->Area.SetPxPyPzE(area.px(), area.py(), area.pz(), area.E());
454
455 candidate->DeltaEta = detaMax;
456 candidate->DeltaPhi = dphiMax;
457 candidate->Charge = charge;
458 candidate->NNeutrals = nneutrals;
459 candidate->NCharged = ncharged;
460
461
462 //for exclusive clustering, access y_n,n+1 as exclusive_ymerge (fNJets);
463 candidate->ExclYmerge23 = excl_ymerge23;
464 candidate->ExclYmerge34 = excl_ymerge34;
465 candidate->ExclYmerge45 = excl_ymerge45;
466 candidate->ExclYmerge56 = excl_ymerge56;
467
468 //------------------------------------
469 // Trimming
470 //------------------------------------
471
472 if(fComputeTrimming)
473 {
474
475 fastjet::Filter trimmer(fastjet::JetDefinition(fastjet::kt_algorithm,fRTrim),fastjet::SelectorPtFractionMin(fPtFracTrim));
476 fastjet::PseudoJet trimmed_jet = trimmer(*itOutputList);
477
478 trimmed_jet = join(trimmed_jet.constituents());
479
480 candidate->TrimmedP4[0].SetPtEtaPhiM(trimmed_jet.pt(), trimmed_jet.eta(), trimmed_jet.phi(), trimmed_jet.m());
481
482 // four hardest subjets
483 subjets.clear();
484 subjets = trimmed_jet.pieces();
485 subjets = sorted_by_pt(subjets);
486
487 candidate->NSubJetsTrimmed = subjets.size();
488
489 for (size_t i = 0; i < subjets.size() and i < 4; i++)
490 {
491 if(subjets.at(i).pt() < 0) continue ;
492 candidate->TrimmedP4[i+1].SetPtEtaPhiM(subjets.at(i).pt(), subjets.at(i).eta(), subjets.at(i).phi(), subjets.at(i).m());
493 }
494 }
495
496
497 //------------------------------------
498 // Pruning
499 //------------------------------------
500
501
502 if(fComputePruning)
503 {
504
505 fastjet::Pruner pruner(fastjet::JetDefinition(fastjet::cambridge_algorithm,fRPrun),fZcutPrun,fRcutPrun);
506 fastjet::PseudoJet pruned_jet = pruner(*itOutputList);
507
508 candidate->PrunedP4[0].SetPtEtaPhiM(pruned_jet.pt(), pruned_jet.eta(), pruned_jet.phi(), pruned_jet.m());
509
510 // four hardest subjet
511 subjets.clear();
512 subjets = pruned_jet.pieces();
513 subjets = sorted_by_pt(subjets);
514
515 candidate->NSubJetsPruned = subjets.size();
516
517 for (size_t i = 0; i < subjets.size() and i < 4; i++)
518 {
519 if(subjets.at(i).pt() < 0) continue ;
520 candidate->PrunedP4[i+1].SetPtEtaPhiM(subjets.at(i).pt(), subjets.at(i).eta(), subjets.at(i).phi(), subjets.at(i).m());
521 }
522
523 }
524
525 //------------------------------------
526 // SoftDrop
527 //------------------------------------
528
529 if(fComputeSoftDrop)
530 {
531
532 contrib::SoftDrop softDrop(fBetaSoftDrop,fSymmetryCutSoftDrop,fR0SoftDrop);
533 fastjet::PseudoJet softdrop_jet = softDrop(*itOutputList);
534
535 candidate->SoftDroppedP4[0].SetPtEtaPhiM(softdrop_jet.pt(), softdrop_jet.eta(), softdrop_jet.phi(), softdrop_jet.m());
536
537 // four hardest subjet
538
539 subjets.clear();
540 subjets = softdrop_jet.pieces();
541 subjets = sorted_by_pt(subjets);
542 candidate->NSubJetsSoftDropped = softdrop_jet.pieces().size();
543
544 candidate->SoftDroppedJet = candidate->SoftDroppedP4[0];
545
546 for (size_t i = 0; i < subjets.size() and i < 4; i++)
547 {
548 if(subjets.at(i).pt() < 0) continue ;
549 candidate->SoftDroppedP4[i+1].SetPtEtaPhiM(subjets.at(i).pt(), subjets.at(i).eta(), subjets.at(i).phi(), subjets.at(i).m());
550 if(i==0) candidate->SoftDroppedSubJet1 = candidate->SoftDroppedP4[i+1];
551 if(i==1) candidate->SoftDroppedSubJet2 = candidate->SoftDroppedP4[i+1];
552 }
553 }
554
555 // --- compute N-subjettiness with N = 1,2,3,4,5 ----
556
557 if(fComputeNsubjettiness)
558 {
559
560 Nsubjettiness nSub1(1, *fAxesDef, *fMeasureDef);
561 Nsubjettiness nSub2(2, *fAxesDef, *fMeasureDef);
562 Nsubjettiness nSub3(3, *fAxesDef, *fMeasureDef);
563 Nsubjettiness nSub4(4, *fAxesDef, *fMeasureDef);
564 Nsubjettiness nSub5(5, *fAxesDef, *fMeasureDef);
565
566 candidate->Tau[0] = nSub1(*itOutputList);
567 candidate->Tau[1] = nSub2(*itOutputList);
568 candidate->Tau[2] = nSub3(*itOutputList);
569 candidate->Tau[3] = nSub4(*itOutputList);
570 candidate->Tau[4] = nSub5(*itOutputList);
571
572 }
573
574 fOutputArray->Add(candidate);
575 }
576 delete sequence;
577}
Note: See TracBrowser for help on using the repository browser.