14 #ifndef RecoJets_FFTJetAlgorithms_clusteringTreeConverters_h
15 #define RecoJets_FFTJetAlgorithms_clusteringTreeConverters_h
19 #include "fftjet/Peak.hh"
20 #include "fftjet/AbsClusteringTree.hh"
21 #include "fftjet/SparseClusteringTree.hh"
32 const fftjet::SparseClusteringTree<fftjet::Peak,long>&
in,
33 bool writeOutScaleInfo,
44 const std::vector<double>* scaleSetIfNotAdaptive,
45 double completeEventScale,
46 fftjet::SparseClusteringTree<fftjet::Peak,long>*
out);
52 const fftjet::AbsClusteringTree<fftjet::Peak,long>&
in,
53 bool writeOutScaleInfo,
64 const std::vector<double>* scaleSetIfNotAdaptive,
65 double completeEventScale,
66 fftjet::AbsClusteringTree<fftjet::Peak,long>*
out);
80 const fftjet::SparseClusteringTree<fftjet::Peak,long>& sparseTree,
81 const bool writeOutScaleInfo,
84 typedef fftjet::SparseClusteringTree<fftjet::Peak,long> SparseTree;
92 tree->setSparse(
true);
94 const unsigned nNodes = sparseTree.size();
95 double hessian[3] = {0., 0., 0.};
98 tree->reserveNodes(nNodes - 1);
99 for (
unsigned i=1;
i<nNodes; ++
i)
102 const fftjet::Peak& peak(
node.getCluster());
103 peak.hessian(hessian);
104 StoredNode sn(StoredPeak(peak.eta(),
112 peak.nearestNeighborDistance(),
113 peak.clusterRadius(),
114 peak.clusterSeparation(),
117 node.originalLevel(),
128 if (writeOutScaleInfo)
131 const unsigned nScales = sparseTree.nLevels();
132 tree->reserveScales(nScales - 1);
133 for (
unsigned i=1;
i<nScales; ++
i)
134 tree->addScale(sparseTree.getScale(
i));
143 const std::vector<double>* scaleSetIfNotAdaptive,
144 const double completeEventScale,
145 fftjet::SparseClusteringTree<fftjet::Peak,long>*
out)
147 typedef fftjet::SparseClusteringTree<fftjet::Peak,long> SparseTree;
154 <<
"can't restore sparse clustering tree"
155 <<
" from densely stored record" << std::endl;
160 const std::vector<StoredNode>& nodes(
in.getNodes());
161 const unsigned n = nodes.size();
162 out->reserveNodes(n + 1U);
164 double hessian[3] = {0., 0., 0.};
166 for (
unsigned i=0;
i<
n; ++
i)
168 const StoredNode& snode(nodes[
i]);
169 const StoredPeak&
p(snode.getCluster());
171 fftjet::Peak peak(
p.eta(),
p.phi(),
p.magnitude(),
172 hessian,
p.driftSpeed(),
173 p.magSpeed(),
p.lifetime(),
174 p.scale(),
p.nearestNeighborDistance(),
176 p.clusterRadius(),
p.clusterSeparation());
177 peak.setSplitTime(
p.splitTime());
178 peak.setMergeTime(
p.mergeTime());
181 out->addNode(
node, snode.parent());
184 const std::vector<Real>& storedScales(
in.getScales());
185 if (!storedScales.empty())
187 const unsigned nsc = storedScales.size();
188 out->reserveScales(nsc + 1U);
189 out->addScale(DBL_MAX);
190 const Real* scales = &storedScales[0];
191 for (
unsigned i=0;
i<nsc; ++
i)
192 out->addScale(scales[
i]);
194 else if (scaleSetIfNotAdaptive && !scaleSetIfNotAdaptive->empty())
196 const unsigned nsc = scaleSetIfNotAdaptive->size();
200 if (completeEventScale)
201 out->reserveScales(nsc + 2U);
203 out->reserveScales(nsc + 1U);
204 out->addScale(DBL_MAX);
205 const double* scales = &(*scaleSetIfNotAdaptive)[0];
206 for (
unsigned i=0;
i<nsc; ++
i)
207 out->addScale(scales[
i]);
208 if (completeEventScale)
209 out->addScale(completeEventScale);
214 <<
"can't restore sparse clustering tree scales"
223 const fftjet::AbsClusteringTree<fftjet::Peak,long>&
in,
224 bool writeOutScaleInfo,
227 typedef fftjet::AbsClusteringTree<fftjet::Peak,long> DenseTree;
234 out->setSparse(
false);
236 const unsigned nLevels = in.nLevels();
237 double hessian[3] = {0., 0., 0.};
240 out->reserveNodes(in.nClusters() - 1);
242 for (
unsigned i=1;
i<nLevels; ++
i)
244 const unsigned int nclus = in.nClusters(
i);
245 DenseTree::NodeId id(
i,0);
246 for (;
id.second<nclus; ++
id.second)
248 const fftjet::Peak& peak(in.getCluster(
id));
249 peak.hessian(hessian);
250 StoredNode sn(StoredPeak(peak.eta(),
258 peak.nearestNeighborDistance(),
259 peak.clusterRadius(),
260 peak.clusterSeparation(),
275 if (writeOutScaleInfo)
278 const unsigned nScales = in.nLevels();
279 out->reserveScales(nScales - 1);
280 for (
unsigned i=1;
i<nScales; ++
i)
281 out->addScale(in.getScale(
i));
290 const std::vector<double>* scaleSetIfNotAdaptive,
291 const double completeEventScale,
292 fftjet::AbsClusteringTree<fftjet::Peak,long>*
out)
294 typedef fftjet::AbsClusteringTree<fftjet::Peak,long> DenseTree;
301 <<
"can't restore dense clustering tree"
302 <<
" from sparsely stored record" << std::endl;
307 const std::vector<StoredNode>& nodes(
in.getNodes());
308 const unsigned n = nodes.size();
309 double hessian[3] = {0., 0., 0.};
311 const std::vector<Real>& scales (
in.getScales());
312 unsigned int scnum = 0;
313 std::vector<fftjet::Peak> clusters;
314 const unsigned scsize1 = scales.size();
315 unsigned scsize2 = scaleSetIfNotAdaptive ? scaleSetIfNotAdaptive->size() : 0;
316 if (scsize2 && completeEventScale) ++scsize2;
317 const unsigned scsize = (scsize1==0?scsize2:scsize1);
321 <<
" No scales passed to the function densePeakTreeFromStorable()"
325 const double* sc_not_ad = scsize2 ? &(*scaleSetIfNotAdaptive)[0] : 0;
327 unsigned templevel = n ? nodes[0].originalLevel() : 1;
328 for (
unsigned i=0;
i<
n; ++
i)
330 const StoredNode& snode(nodes[
i]);
331 const StoredPeak&
p(snode.getCluster());
334 const unsigned levelNumber = snode.originalLevel();
336 if (templevel != levelNumber)
340 <<
"bad scales, please check the scales"
342 const double scale = ( (scsize1==0) ? sc_not_ad[scnum] : scales[scnum] );
343 out->insert(scale, clusters, 0
L);
345 templevel = levelNumber;
349 fftjet::Peak apeak(
p.eta(),
p.phi(),
p.magnitude(),
350 hessian,
p.driftSpeed(),
351 p.magSpeed(),
p.lifetime(),
352 p.scale(),
p.nearestNeighborDistance(),
354 p.clusterRadius(),
p.clusterSeparation());
355 apeak.setSplitTime(
p.splitTime());
356 apeak.setMergeTime(
p.mergeTime());
357 clusters.push_back(apeak);
359 if (i==(n-1) && levelNumber!=scsize)
361 <<
"bad scales, please check the scales"
365 const double scale = scsize1 ? scales[scnum] : completeEventScale ?
366 completeEventScale : sc_not_ad[scnum];
367 out->insert(scale, clusters, 0
L);
371 #endif // RecoJets_FFTJetAlgorithms_clusteringTreeConverters_h
Tree nodes for storing FFTJet preclusters.
Class for storing FFTJet sparse clustering trees.
Preclusters from FFTJet pattern recognition stage.
void sparsePeakTreeToStorable(const fftjet::SparseClusteringTree< fftjet::Peak, long > &in, bool writeOutScaleInfo, reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > *out)
void densePeakTreeToStorable(const fftjet::AbsClusteringTree< fftjet::Peak, long > &in, bool writeOutScaleInfo, reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > *out)
void sparsePeakTreeFromStorable(const reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > &in, const std::vector< double > *scaleSetIfNotAdaptive, double completeEventScale, fftjet::SparseClusteringTree< fftjet::Peak, long > *out)
void densePeakTreeFromStorable(const reco::PattRecoTree< Real, reco::PattRecoPeak< Real > > &in, const std::vector< double > *scaleSetIfNotAdaptive, double completeEventScale, fftjet::AbsClusteringTree< fftjet::Peak, long > *out)
edm::TrieNode< PDet > Node