Fork me on GitHub

source: git/modules/FastJetFinder.cc@ d244bc9

ImprovedOutputFile Timing dual_readout llp
Last change on this file since d244bc9 was d244bc9, checked in by Michele <michele.selvaggi@…>, 10 years ago

added exception in FastJetFinder when winner-take-all recombination scheme is used that prevents jets from having mass = 0

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