4 #include "ClusterAnalysis.h"
6 #include "matchOneToOne.hh"
18 m_nEvent = cs.n_particles();
21 if ( m_nEvent > m_nEventSize ) {
22 m_nEventSize = m_nEvent;
23 m_event.resize(m_nEvent);
24 m_partMap.resize(m_nEvent);
28 const Event & allJets = cs.jets();
29 const History &history = cs.history();
30 for (
unsigned jp=0; jp != m_nEvent; jp++ ) {
31 const int jpHistIndex = allJets[jp].cluster_sequence_history_index();
32 assert(jpHistIndex >= 0);
33 const int jpParent = history[jpHistIndex].parent1;
35 m_event[jp] = allJets[jp];
36 assert( m_event[jp].pt() > 0. );
41 const Event & cluJets = fastjet::sorted_by_pt(cs.exclusive_jets(m_dCut));
44 m_nJets=cluJets.size();
45 m_nJetsInCycle = m_nJets;
46 if ( m_nJetSize < m_nJets ) {
47 m_jets.resize(m_nJets);
48 m_jetCycleMap.resize(m_nJets);
51 const std::vector<int> & histMap = cs.particle_jet_indices(cluJets);
52 assert(m_nEvent == histMap.size());
53 for (
unsigned p=0; p != m_nEvent; p++ ) {
54 const int index = histMap[p];
55 if ( index >= 0 ) m_partMap[p] = index;
57 m_partMap[p] = UINT_MAX;
69 const Event & cluJets = fastjet::sorted_by_pt(cs.exclusive_jets(m_dCut));
70 m_nJetsInCycle = cluJets.size();
73 if ( m_nJetsInCycle > m_nJetSize ) {
74 m_nJetSize = m_nJetsInCycle;
75 m_jets.resize(m_nJetSize);
76 m_jetCycleMap.resize(m_nJetSize);
80 for (
unsigned j=0; j != m_nJetsInCycle; j++ )
84 std::vector<int> matchIndex;
86 matchOneToOne(cluJets,m_jets,m_nJetsInCycle,m_nJets,calc,&matchIndex);
88 for (
unsigned j=0; j != m_nJetsInCycle; j++ ) {
89 const int index = matchIndex[j];
90 if ( index >=0 ) m_jetCycleMap[j] = index;
92 if ( m_nJetSize == m_nJets ) m_jets.resize(++m_nJetSize);
93 m_jets[m_nJets] = cluJets[j];
94 m_jetCycleMap[j] = m_nJets++;
99 std::vector<unsigned> partMap(m_nEvent);
100 const std::vector<int> & histMap = cs.particle_jet_indices(cluJets);
101 assert(m_nEvent == histMap.size());
102 for (
unsigned p=0; p != m_nEvent; p++ ) {
103 const int index = histMap[p];
104 if ( index >= 0 ) partMap[p] = index;
105 else partMap[p] = UINT_MAX;
107 m_partMapVec.push_back(partMap);
112 assert( m_nJetsInCycle );
120 for (
unsigned p=0; p != m_nEventSize; p++ ) {
121 m_event[p] = PseudoJet();
125 m_partMapVec.clear();
127 for (
unsigned j=0; j != m_nJetSize; j++ ) {
128 m_jets[j] = PseudoJet();
129 m_jetCycleMap[j] = 0U;
142 stab = pairwiseStability(index);
145 stab = exhaustiveStability(index);
148 stab = unsmearedStability(index);
151 stab = resampledStability(index);
162 long double stab=0.L;
164 for (
unsigned c=0; c != m_nCycle-1; c++ ) {
165 std::vector<unsigned> & clustMap1 = m_partMapVec[c];
166 std::vector<unsigned> & clustMap2 = m_partMapVec[c+1U];
167 const double temp = index.index(&m_event[0],&clustMap1[0],&clustMap2[0],m_nEvent);
172 stab /= (m_nCycle-1);
179 double ClusterAnalysis::exhaustiveStability(
const ClusteringComparisonIndex &index)
184 for (
unsigned c1=0; c1 != m_nCycle-1U; c1++ ) {
185 std::vector<unsigned> & clustMap1 = m_partMapVec[c1];
186 for (
unsigned c2=c1+1; c2 != m_nCycle; c2++ ) {
187 std::vector<unsigned> & clustMap2 = m_partMapVec[c2];
188 stab += index.index(&m_event[0],&clustMap1[0],&clustMap2[0],m_nEvent);
192 stab /= (double)m_nCycle*((
double)m_nCycle-1.)/2.;
196 double ClusterAnalysis::unsmearedStability(
const ClusteringComparisonIndex &index)
200 for (
unsigned c=0; c != m_nCycle; c++ ) {
201 std::vector<unsigned> & clustMap = m_partMapVec[c];
202 stab += index.index(&m_event[0],&m_partMap[0],&clustMap[0],m_nEvent);
208 double ClusterAnalysis::resampledStability(
const ClusteringComparisonIndex &index)
217 const unsigned weightSize = m_nJets*m_nEvent;
218 double weights[weightSize];
220 for (
unsigned i=0; i != weightSize; i++ )
225 for (
unsigned i=0; i != m_nJets; i++ ) {
226 for (
unsigned j=0; j != m_nEvent; j++ ) {
228 for (
unsigned k=0; k != m_nCycle; k++ )
229 if ( m_partMapVec[k][j] == i ) count++;
230 weights[i*m_nEvent+j] = (double)count/(
double)m_nCycle;
231 assert( weights[i*m_nEvent+j] >= 0. );
235 bool lastFinalJetIsUnclustered=
false;
236 const unsigned lenJetFuzziness = m_nJets;
237 double jetFuzziness[lenJetFuzziness];
239 return fuzzyCalc.calculate(m_event, m_jets, weights, m_nJets, m_nEvent, lastFinalJetIsUnclustered,
240 jetFuzziness, lenJetFuzziness);
double doStability(const ClusteringComparisonIndex &, const StabilityCalcMethod method=PAIRWISE)
perform the stability calculation
double doFuzziness(const AbsFuzzinessCalculator &)
perform the fuzziness calculation
void fill(const fastjet::ClusterSequence &)
Add results of latest clustering to stability consideration.
void initialize(const fastjet::ClusterSequence &)
Initialize internal data from first clustering results.
void clear()
clear the contents