Fork me on GitHub

source: git/modules/FastJetFinder.cc@ 7b6aafa

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

replace map with vector< TEstimatorStruct > and replace SelectorAbsRapRange with SelectorEtaRange

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