StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StKtCluJetFinder.cxx
1 // -*- mode: c++;-*-
2 #include "StKtCluJetFinder.h"
3 
4 //std
5 #include <cmath>
6 #include <float.h>
7 
8 //root
9 #include "TObject.h"
10 
11 //JetFinder
12 #include "FourVec.h"
13 #include "StProtoJet.h"
14 #include "StProtoJetPair.h"
15 #include "StJetFinder.h"
16 
17 
18 using namespace std;
19 
20 
21 StKtCluJetFinder::StKtCluJetFinder(const StKtCluPars& pars) : mPars(pars)
22 {
23  cout <<"StKtCluJetFinder::StKtCluJetFinder()"<<endl;
24 }
25 
26 StKtCluJetFinder::~StKtCluJetFinder()
27 {
28  cout <<"StKtCluJetFinder::~StKtCluJetFinder()"<<endl;
29 }
30 
31 void StKtCluJetFinder::Init()
32 {
33 
34 }
35 
36 void StKtCluJetFinder::findJets(JetList& pj, const FourVecList& particleList)
37 {
38  pj.clear();
39 
40  for(FourVecList::const_iterator particle = particleList.begin(); particle != particleList.end(); ++particle) {
41  pj.push_back(StProtoJet(*particle));
42  }
43 
44  if (pj.size()<2) return; //nothing to be done!
45 
46  mJets.clear();
47  int nSteps = 0;
48 
49  while (pj.empty()==false) {
50 
51  if ( mPars.debug() ) {
52  cout <<"\n --- protojets after clustering "<<nSteps<<" steps"<<endl;
53  for (JetList::const_iterator it3=pj.begin(); it3!=pj.end(); ++it3) {
54  cout <<*it3<<endl;
55  }
56  cout <<" --- jets after clustering "<<nSteps<<" steps"<<endl;
57  for (JetList::const_iterator it4=mJets.begin(); it4!=mJets.end(); ++it4) {
58  cout <<*it4<<endl;
59  }
60 
61  }
62 
63  //Find the smallest d in protojets:
64  double d_min_pj = DBL_MAX;
65  JetList::iterator bestProto=pj.end();
66 
67  //Loop on protojets first:
68  for (JetList::iterator protoIt=pj.begin(); protoIt!=pj.end(); ++protoIt) {
69  double d = (*protoIt).d();
70  if (d<d_min_pj) {
71  bestProto = protoIt;
72  d_min_pj = d;
73  }
74  }
75 
76  //Find the smallest d in protojet pairs:
77  double d_min_jets = DBL_MAX;
78  JetList::iterator bestJet1=pj.end();
79  JetList::iterator bestJet2=pj.end();
80 
81  for (JetList::iterator jetIt1=pj.begin(); jetIt1!=pj.end(); ++jetIt1) {
82  for (JetList::iterator jetIt2=jetIt1; jetIt2!=pj.end(); ++jetIt2) {
83  if (jetIt1!=jetIt2) {
84  StProtoJetPair myPair(*jetIt1, *jetIt2, mPars.r());
85  double d = myPair.d();
86  if (d < d_min_jets) {
87  d_min_jets=d;
88  bestJet1 = jetIt1;
89  bestJet2 = jetIt2;
90  }
91  }
92  }
93  }
94 
95  //Now we choose what to do:
96 
97  if (d_min_pj < d_min_jets) {
98 
99  //this proto-jet is unmergable, move it into jet list
100 
101  if (bestProto==pj.end()) {
102  cout <<"StJetFinder::findJets(). ERROR:\t"
103  <<"Trying to use protojet iterator that doesn't exist"<<endl;
104  }
105  (*bestProto).update();
106  mJets.push_back(*bestProto);
107  pj.erase(bestProto);
108  }
109 
110  //else if (d_min_pj > d_min_jets) {
111  else {
112  //these two protojets should be merged
113 
114  if (bestJet1==pj.end() || bestJet2==pj.end()) {
115  cout <<"StJetFinder::findJets(). ERROR:\t"
116  <<"Trying to use 2 protojet iterators, one doesn't exist"<<endl;
117  }
118  (*bestJet1).merge(*bestJet2);
119  pj.erase(bestJet2);
120  }
121  /*
122  else {
123  cout <<"JetFinder::findJets(). ERROR:\t"
124  <<"No choice made"<<endl;
125  }
126  */
127  ++nSteps;
128  }
129 
130  //Now we're all done, copy the jets into the original container, return
131  for (JetList::iterator it=mJets.begin(); it!=mJets.end(); ++it) {
132  pj.push_back(*it);
133  }
134 
135 }