Fork me on GitHub

source: git/modules/FastJetFinder.cc@ 5be77b9

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 5be77b9 was 58dcd2e, checked in by Michele Selvaggi <michele.selvaggi@…>, 9 years ago

ensure bwd compatibility (for real this time?)

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