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()),
115 node.originalLevel(),
126 if (writeOutScaleInfo)
129 const unsigned nScales = sparseTree.nLevels();
130 tree->reserveScales(nScales - 1);
131 for (
unsigned i=1;
i<nScales; ++
i)
132 tree->addScale(sparseTree.getScale(
i));
141 const std::vector<double>* scaleSetIfNotAdaptive,
142 const double completeEventScale,
143 fftjet::SparseClusteringTree<fftjet::Peak,long>*
out)
145 typedef fftjet::SparseClusteringTree<fftjet::Peak,long> SparseTree;
152 <<
"can't restore sparse clustering tree"
153 <<
" from densely stored record" << std::endl;
158 const std::vector<StoredNode>& nodes(
in.getNodes());
159 const unsigned n = nodes.size();
160 out->reserveNodes(n + 1U);
162 double hessian[3] = {0., 0., 0.};
164 for (
unsigned i=0;
i<
n; ++
i)
166 const StoredNode& snode(nodes[
i]);
167 const StoredPeak&
p(snode.getCluster());
170 fftjet::Peak(
p.eta(),
p.phi(),
p.magnitude(),
171 hessian,
p.driftSpeed(),
172 p.magSpeed(),
p.lifetime(),
173 p.scale(),
p.nearestNeighborDistance(),
175 p.clusterRadius(),
p.clusterSeparation()),
176 snode.originalLevel(),
178 out->addNode(
node, snode.parent());
181 const std::vector<Real>& storedScales(
in.getScales());
182 if (!storedScales.empty())
184 const unsigned nsc = storedScales.size();
185 out->reserveScales(nsc + 1U);
186 out->addScale(DBL_MAX);
187 const Real* scales = &storedScales[0];
188 for (
unsigned i=0;
i<nsc; ++
i)
189 out->addScale(scales[
i]);
191 else if (scaleSetIfNotAdaptive && !scaleSetIfNotAdaptive->empty())
193 const unsigned nsc = scaleSetIfNotAdaptive->size();
197 if (completeEventScale)
198 out->reserveScales(nsc + 2U);
200 out->reserveScales(nsc + 1U);
201 out->addScale(DBL_MAX);
202 const double* scales = &(*scaleSetIfNotAdaptive)[0];
203 for (
unsigned i=0;
i<nsc; ++
i)
204 out->addScale(scales[
i]);
205 if (completeEventScale)
206 out->addScale(completeEventScale);
211 <<
"can't restore sparse clustering tree scales"
220 const fftjet::AbsClusteringTree<fftjet::Peak,long>&
in,
221 bool writeOutScaleInfo,
224 typedef fftjet::AbsClusteringTree<fftjet::Peak,long> DenseTree;
232 out->setSparse(
false);
235 const unsigned nLevels = in.nLevels();
236 double hessian[3] = {0., 0., 0.};
240 out->reserveNodes(in.nClusters() - 1);
243 for (
unsigned i=1;
i<nLevels; ++
i)
246 const unsigned int nclus = in.nClusters(
i);
247 DenseTree::NodeId id(
i,0);
248 for (;
id.second<nclus; ++
id.second)
252 const fftjet::Peak& peak(in.getCluster(
id));
253 peak.hessian(hessian);
254 StoredNode sn(StoredPeak(peak.eta(),
262 peak.nearestNeighborDistance(),
263 peak.clusterRadius(),
264 peak.clusterSeparation()),
281 if (writeOutScaleInfo)
284 const unsigned nScales = in.nLevels();
286 out->reserveScales(nScales - 1);
288 for (
unsigned i=1;
i<nScales; ++
i)
289 out->addScale(in.getScale(
i));
299 const std::vector<double>* scaleSetIfNotAdaptive,
300 const double completeEventScale,
301 fftjet::AbsClusteringTree<fftjet::Peak,long>*
out)
303 typedef fftjet::AbsClusteringTree<fftjet::Peak,long> DenseTree;
310 <<
"can't restore dense clustering tree"
311 <<
" from sparsely stored record" << std::endl;
316 const std::vector<StoredNode>& nodes(
in.getNodes());
317 const unsigned n = nodes.size();
318 double hessian[3] = {0., 0., 0.};
320 const std::vector<Real>& scales (
in.getScales());
321 unsigned int scnum = 0;
322 std::vector<fftjet::Peak> clusters;
323 const unsigned scsize1 = scales.size();
324 unsigned scsize2 = scaleSetIfNotAdaptive ? scaleSetIfNotAdaptive->size() : 0;
325 if (scsize2 && completeEventScale) ++scsize2;
326 const unsigned scsize = (scsize1==0?scsize2:scsize1);
330 <<
" No scales passed to the function densePeakTreeFromStorable()"
334 const double* sc_not_ad = scsize2 ? &(*scaleSetIfNotAdaptive)[0] : 0;
336 unsigned templevel = n ? nodes[0].originalLevel() : 1;
337 for (
unsigned i=0;
i<
n; ++
i)
339 const StoredNode& snode(nodes[
i]);
340 const StoredPeak&
p(snode.getCluster());
343 const unsigned levelNumber = snode.originalLevel();
345 if (templevel != levelNumber)
349 <<
"bad scales, please check the scales"
351 const double scale = ( (scsize1==0) ? sc_not_ad[scnum] : scales[scnum] );
352 out->insert(scale, clusters, 0
L);
354 templevel = levelNumber;
358 fftjet::Peak apeak(
p.eta(),
p.phi(),
p.magnitude(),
359 hessian,
p.driftSpeed(),
360 p.magSpeed(),
p.lifetime(),
361 p.scale(),
p.nearestNeighborDistance(),
363 p.clusterRadius(),
p.clusterSeparation());
364 clusters.push_back(apeak);
366 if (i==(n-1) && levelNumber!=scsize)
368 <<
"bad scales, please check the scales"
372 const double scale = scsize1 ? scales[scnum] : completeEventScale ?
373 completeEventScale : sc_not_ad[scnum];
374 out->insert(scale, clusters, 0
L);
378 #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