Fork me on GitHub

source: git/modules/FastJetFinder.cc@ db8adea

ImprovedOutputFile Timing dual_readout llp
Last change on this file since db8adea was c6321ad, checked in by pavel <pavel@…>, 11 years ago

fix namespace usage

  • Property mode set to 100644
File size: 11.0 KB
RevLine 
[d7d2da3]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
[8336b6e]32#include <algorithm>
[d7d2da3]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
[e4c3fef]49#include "fastjet/contribs/Nsubjettiness/Nsubjettiness.hh"
[9687203]50#include "fastjet/contribs/Nsubjettiness/Njettiness.hh"
51#include "fastjet/contribs/Nsubjettiness/NjettinessPlugin.hh"
52#include "fastjet/contribs/Nsubjettiness/WinnerTakeAllRecombiner.hh"
53
[d7d2da3]54using namespace std;
55using namespace fastjet;
[9687203]56using namespace fastjet::contrib;
57
[d7d2da3]58
59//------------------------------------------------------------------------------
60
61FastJetFinder::FastJetFinder() :
[c6321ad]62 fPlugin(0), fRecomb(0), fNjettinessPlugin(0), fDefinition(0), fAreaDefinition(0), fItInputArray(0)
[d7d2da3]63{
64
65}
66
67//------------------------------------------------------------------------------
68
69FastJetFinder::~FastJetFinder()
70{
71
72}
73
74//------------------------------------------------------------------------------
75
76void FastJetFinder::Init()
77{
[c6321ad]78 JetDefinition::Plugin *plugin = 0;
79 JetDefinition::Recombiner *recomb = 0;
80 NjettinessPlugin *njetPlugin = 0;
[e4c3fef]81
[8336b6e]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
[d7d2da3]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);
[3ccc8586]105 fAdjacencyCut = GetInt("AdjacencyCut", 2);
[d7d2da3]106 fOverlapThreshold = GetDouble("OverlapThreshold", 0.75);
107
108 fJetPTMin = GetDouble("JetPTMin", 10.0);
109
[9687203]110 //-- N(sub)jettiness parameters --
[e4c3fef]111
[9687203]112 fComputeNsubjettiness = GetBool("ComputeNsubjettiness", false);
113 fBeta = GetDouble("Beta", 1.0);
114 fAxisMode = GetInt("AxisMode", 1);
[e4c3fef]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
[d7d2da3]118 // --- Jet Area Parameters ---
119 fAreaAlgorithm = GetInt("AreaAlgorithm", 0);
120 fComputeRho = GetBool("ComputeRho", false);
[e4c3fef]121
[d7d2da3]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);
[e4c3fef]129
[d7d2da3]130 // - voronoi based areas -
131 fEffectiveRfact = GetDouble("EffectiveRfact", 1.0);
132
133 switch(fAreaAlgorithm)
134 {
135 case 1:
[c6321ad]136 fAreaDefinition = new AreaDefinition(active_area_explicit_ghosts, GhostedAreaSpec(fGhostEtaMax, fRepeat, fGhostArea, fGridScatter, fPtScatter, fMeanGhostPt));
[d7d2da3]137 break;
138 case 2:
[c6321ad]139 fAreaDefinition = new AreaDefinition(one_ghost_passive_area, GhostedAreaSpec(fGhostEtaMax, fRepeat, fGhostArea, fGridScatter, fPtScatter, fMeanGhostPt));
[d7d2da3]140 break;
141 case 3:
[c6321ad]142 fAreaDefinition = new AreaDefinition(passive_area, GhostedAreaSpec(fGhostEtaMax, fRepeat, fGhostArea, fGridScatter, fPtScatter, fMeanGhostPt));
[d7d2da3]143 break;
144 case 4:
[c6321ad]145 fAreaDefinition = new AreaDefinition(VoronoiAreaSpec(fEffectiveRfact));
[d7d2da3]146 break;
147 case 5:
[c6321ad]148 fAreaDefinition = new AreaDefinition(active_area, GhostedAreaSpec(fGhostEtaMax, fRepeat, fGhostArea, fGridScatter, fPtScatter, fMeanGhostPt));
[d7d2da3]149 break;
150 default:
151 case 0:
152 fAreaDefinition = 0;
153 break;
154 }
155
156 switch(fJetAlgorithm)
157 {
[8336b6e]158 case 1:
[c6321ad]159 plugin = new CDFJetCluPlugin(fSeedThreshold, fConeRadius, fAdjacencyCut, fMaxIterations, fIratch, fOverlapThreshold);
160 fDefinition = new JetDefinition(plugin);
[d7d2da3]161 break;
162 case 2:
[c6321ad]163 plugin = new CDFMidPointPlugin(fSeedThreshold, fConeRadius, fConeAreaFraction, fMaxPairSize, fMaxIterations, fOverlapThreshold);
164 fDefinition = new JetDefinition(plugin);
[d7d2da3]165 break;
166 case 3:
[c6321ad]167 plugin = new SISConePlugin(fConeRadius, fOverlapThreshold, fMaxIterations, fJetPTMin);
168 fDefinition = new JetDefinition(plugin);
[d7d2da3]169 break;
170 case 4:
[c6321ad]171 fDefinition = new JetDefinition(kt_algorithm, fParameterR);
[d7d2da3]172 break;
173 case 5:
[c6321ad]174 fDefinition = new JetDefinition(cambridge_algorithm, fParameterR);
[d7d2da3]175 break;
176 default:
177 case 6:
[c6321ad]178 fDefinition = new JetDefinition(antikt_algorithm, fParameterR);
[d7d2da3]179 break;
[9687203]180 case 7:
[c6321ad]181 recomb = new WinnerTakeAllRecombiner();
182 fDefinition = new JetDefinition(antikt_algorithm, fParameterR, recomb, Best);
[9687203]183 break;
184 case 8:
[c6321ad]185 njetPlugin = new NjettinessPlugin(fN, Njettiness::wta_kt_axes, Njettiness::unnormalized_cutoff_measure, fBeta, fRcutOff);
186 fDefinition = new JetDefinition(njetPlugin);
[9687203]187 break;
[d7d2da3]188 }
[8336b6e]189
[d7d2da3]190 fPlugin = plugin;
[9687203]191 fRecomb = recomb;
[c6321ad]192 fNjettinessPlugin = njetPlugin;
[e4c3fef]193
[d7d2da3]194 ClusterSequence::print_banner();
[8336b6e]195
[d7d2da3]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);
[9687203]215 if(fRecomb) delete static_cast<JetDefinition::Recombiner*>(fRecomb);
216 if(fNjettinessPlugin) delete static_cast<JetDefinition::Plugin*>(fNjettinessPlugin);
[d7d2da3]217}
218
219//------------------------------------------------------------------------------
220
221void FastJetFinder::Process()
222{
223 Candidate *candidate, *constituent;
224 TLorentzVector momentum;
225 Double_t deta, dphi, detaMax, dphiMax;
[22dc7fd]226 Double_t time, weightTime, avTime;
[d7d2da3]227 Int_t number;
228 Double_t rho = 0;
229 PseudoJet jet, area;
230 vector<PseudoJet> inputList, outputList;
231 ClusterSequence *sequence;
[8336b6e]232 map< Double_t, Double_t >::iterator itEtaRangeMap;
[d7d2da3]233
234 DelphesFactory *factory = GetFactory();
235
236 inputList.clear();
237
238 // loop over input objects
239 fItInputArray->Reset();
240 number = 0;
241 while((candidate = static_cast<Candidate*>(fItInputArray->Next())))
[8336b6e]242 {
[d7d2da3]243 momentum = candidate->Momentum;
244 jet = PseudoJet(momentum.Px(), momentum.Py(), momentum.Pz(), momentum.E());
245 jet.set_user_index(number);
246 inputList.push_back(jet);
247 ++number;
248 }
[8336b6e]249
250 // construct jets
[d7d2da3]251 if(fAreaDefinition)
252 {
253 sequence = new ClusterSequenceArea(inputList, *fDefinition, *fAreaDefinition);
254 }
255 else
256 {
257 sequence = new ClusterSequence(inputList, *fDefinition);
[8336b6e]258 }
[d7d2da3]259
260 // compute rho and store it
261 if(fComputeRho && fAreaDefinition)
262 {
[8336b6e]263 for(itEtaRangeMap = fEtaRangeMap.begin(); itEtaRangeMap != fEtaRangeMap.end(); ++itEtaRangeMap)
264 {
265 Selector select_rapidity = SelectorAbsRapRange(itEtaRangeMap->first, itEtaRangeMap->second);
266 JetMedianBackgroundEstimator estimator(select_rapidity, *fDefinition, *fAreaDefinition);
267 estimator.set_particles(inputList);
268 rho = estimator.rho();
269
270 candidate = factory->NewCandidate();
271 candidate->Momentum.SetPtEtaPhiE(rho, 0.0, 0.0, rho);
272 candidate->Edges[0] = itEtaRangeMap->first;
273 candidate->Edges[1] = itEtaRangeMap->second;
274 fRhoOutputArray->Add(candidate);
275 }
[d7d2da3]276 }
[8336b6e]277
[d7d2da3]278 outputList.clear();
279 outputList = sorted_by_pt(sequence->inclusive_jets(fJetPTMin));
280
[9687203]281
[d7d2da3]282 // loop over all jets and export them
283 detaMax = 0.0;
284 dphiMax = 0.0;
285 vector<PseudoJet>::iterator itInputList, itOutputList;
286 for(itOutputList = outputList.begin(); itOutputList != outputList.end(); ++itOutputList)
287 {
288 momentum.SetPxPyPzE(itOutputList->px(), itOutputList->py(), itOutputList->pz(), itOutputList->E());
289 area.reset(0.0, 0.0, 0.0, 0.0);
290 if(fAreaDefinition) area = itOutputList->area_4vector();
291
292 candidate = factory->NewCandidate();
293
[22dc7fd]294 time=0;
295 weightTime=0;
296
[d7d2da3]297 inputList.clear();
298 inputList = sequence->constituents(*itOutputList);
[e4c3fef]299
[d7d2da3]300 for(itInputList = inputList.begin(); itInputList != inputList.end(); ++itInputList)
301 {
302 constituent = static_cast<Candidate*>(fInputArray->At(itInputList->user_index()));
303
304 deta = TMath::Abs(momentum.Eta() - constituent->Momentum.Eta());
305 dphi = TMath::Abs(momentum.DeltaPhi(constituent->Momentum));
306 if(deta > detaMax) detaMax = deta;
307 if(dphi > dphiMax) dphiMax = dphi;
[e4c3fef]308
[22dc7fd]309 time += TMath::Sqrt(constituent->Momentum.E())*(constituent->Position.T());
310 weightTime += TMath::Sqrt(constituent->Momentum.E());
[e4c3fef]311
[d7d2da3]312 candidate->AddCandidate(constituent);
313 }
[e4c3fef]314
[22dc7fd]315 avTime = time/weightTime;
[d7d2da3]316
317 candidate->Momentum = momentum;
[22dc7fd]318 candidate->Position.SetT(avTime);
[d7d2da3]319 candidate->Area.SetPxPyPzE(area.px(), area.py(), area.pz(), area.E());
320
321 candidate->DeltaEta = detaMax;
322 candidate->DeltaPhi = dphiMax;
323
[9687203]324 // --- compute N-subjettiness with N = 1,2,3,4,5 ----
[e4c3fef]325
[9687203]326 if(fComputeNsubjettiness)
327 {
328 Njettiness::AxesMode axisMode;
[e4c3fef]329
330 switch(fAxisMode)
331 {
332 default:
333 case 1:
334 axisMode = Njettiness::wta_kt_axes;
335 break;
336 case 2:
337 axisMode = Njettiness::onepass_wta_kt_axes;
338 break;
339 case 3:
340 axisMode = Njettiness::kt_axes;
341 break;
342 case 4:
343 axisMode = Njettiness::onepass_kt_axes;
344 break;
345 }
346
[9687203]347 Njettiness::MeasureMode measureMode = Njettiness::unnormalized_measure;
[e4c3fef]348
[9687203]349 Nsubjettiness nSub1(1, axisMode, measureMode, fBeta);
350 Nsubjettiness nSub2(2, axisMode, measureMode, fBeta);
[e4c3fef]351 Nsubjettiness nSub3(3, axisMode, measureMode, fBeta);
352 Nsubjettiness nSub4(4, axisMode, measureMode, fBeta);
353 Nsubjettiness nSub5(5, axisMode, measureMode, fBeta);
354
355 candidate->Tau[0] = nSub1(*itOutputList);
356 candidate->Tau[1] = nSub2(*itOutputList);
357 candidate->Tau[2] = nSub3(*itOutputList);
358 candidate->Tau[3] = nSub4(*itOutputList);
359 candidate->Tau[4] = nSub5(*itOutputList);
[9687203]360 }
361
362
[d7d2da3]363 fOutputArray->Add(candidate);
364 }
365 delete sequence;
366}
Note: See TracBrowser for help on using the repository browser.