FastJet  3.1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
ProtoJet.hpp
1 #ifndef D0RunIIconeJets_PROTOJET
2 #define D0RunIIconeJets_PROTOJET
3 // ---------------------------------------------------------------------------
4 // ProtoJet.hpp
5 //
6 // Created: 28-JUL-2000 Francois Touze (+ Laurent Duflot)
7 //
8 // Purpose: Implements a proto-jet object that is used as input by the
9 // Improved Legacy Cone Algorithm split/merge algo.
10 //
11 // Modified:
12 // 9-Aug-2000 Laurent Duflot
13 // + save the initial stable cone ET before split/merge
14 // 1-May-2007 Lars Sonnenschein
15 // extracted from D0 software framework and modified to remove subsequent dependencies
16 //
17 //
18 // This file is distributed with FastJet under the terms of the GNU
19 // General Public License (v2). Permission to do so has been granted
20 // by Lars Sonnenschein and the D0 collaboration (see COPYING for
21 // details)
22 //
23 // History of changes in FastJet compared tothe original version of
24 // ProtoJet.hpp
25 //
26 // 2011-12-13 Gregory Soyez <soyez@fastjet.fr>
27 //
28 // * added license information
29 //
30 // 2011-11-14 Gregory Soyez <soyez@fastjet.fr>
31 //
32 // * changed the name of a few parameters to avoid a gcc
33 // -Wshadow warning
34 //
35 // 2009-01-17 Gregory Soyez <soyez@fastjet.fr>
36 //
37 // * put the code in the fastjet::d0 namespace
38 //
39 // 2007-12-14 Gavin Salam <salam@lpthe.jussieu.fr>
40 //
41 // * replaced make_pair by std::make_pair
42 //
43 // ---------------------------------------------------------------------------
44 
45 //#include "kinem_util/AnglesUtil.hpp"
46 //#include "energycluster/ConeJetInfo.hpp"
47 #include "ConeJetInfo.hpp"
48 #include <list>
49 #include <cmath>
50 
51 #include "inline_maths.h" //ls
52 
53 #include <fastjet/internal/base.hh>
54 
55 FASTJET_BEGIN_NAMESPACE
56 
57 namespace d0{
58 
59 using namespace inline_maths;
60 using namespace D0RunIIconeJets_CONEJETINFO;
61 
62 
63 inline float RD2(float y1,float phi1,float y2,float phi2)
64 {
65  float dphi= delta_phi(phi1,phi2);
66  return (y1-y2)*(y1-y2)+dphi*dphi;
67 }
68 
69 inline float RDelta(float y1,float phi1,float y2,float phi2)
70 {
71  float dphi= delta_phi(phi1,phi2);
72  return sqrt((y1-y2)*(y1-y2)+dphi*dphi);
73 }
74 
75 inline float P2y(float* p4vec) {
76  return y(p4vec[3],p4vec[2]);
77 }
78 
79 inline float P2phi(float* p4vec) {
80  return phi(p4vec[0],p4vec[1]);
81 }
82 
83 ///////////////////////////////////////////////////////////////////////////////
84 template <class Item>
85 class ProtoJet {
86 
87 public :
88 
89  ProtoJet(float seedET);
90  ProtoJet(float seedET,float y,float phi);
91  ProtoJet(const ProtoJet<Item>& pj);
92  ~ProtoJet() {;}
93 
94  void addItem(const Item* tw);
95  void setJet(float y,float phi,float pT);
96  void updateJet();
97  void erase();
98 
99  float y() const;
100  float phi() const;
101  float pT() const;
102  const ConeJetInfo & info() const;
103  const std::list<const Item*>& LItems() const;
104 
105  void print(std::ostream &os) const;
106 
107  // actions to be taken when the jet is a stable cone
108  void NowStable();
109  // declare the jet to have been splitted
110  void splitted(){_info.splitted();};
111  // declare the jet to have been merged
112  void merged(){_info.merged();};
113 protected :
114 
115  std::list<const Item*> _LItems;
116  float _y;
117  float _phi;
118  float _pT;
119  ConeJetInfo _info;
120 
121 };
122 ///////////////////////////////////////////////////////////////////////////////
123 template<class Item>
124 ProtoJet<Item>::ProtoJet(float seedET) : _LItems(), _info(seedET) {
125  _y = 0.0;
126  _phi= 0.0;
127  _pT = 0.0;
128 }
129 
130 template<class Item>
131 ProtoJet<Item>::ProtoJet(float seedET,float y_in,float phi_in) : _LItems(), _info(seedET) {
132  _y = y_in;
133  _phi= phi_in;
134  _pT = 0.0;
135 }
136 
137 template<class Item>
138 ProtoJet<Item>::ProtoJet(const ProtoJet<Item>& pj): _y(pj._y),
139  _phi(pj._phi), _pT(pj._pT),
140  _info(pj._info)
141 {
142  typename std::list<const Item*>::const_iterator it;
143  for(it = pj._LItems.begin(); it != pj._LItems.end(); ++it) {
144  _LItems.push_back(*it);
145  }
146 }
147 
148 template<class Item>
149 void ProtoJet<Item>::addItem(const Item* tw) {
150  _LItems.push_back(tw);
151 }
152 
153 template<class Item>
154 void ProtoJet<Item>::setJet(float y_in,float phi_in,float pT_in) {
155  _y = y_in;
156  _phi= phi_in;
157  _pT = pT_in;
158 }
159 
160 template<class Item>
161 void ProtoJet<Item>::updateJet() {
162  //float ETsum = 0.0;
163  //float ysum = 0.0;
164  //float PHIsum= 0.0;
165  float p[4] = {0.,0.,0.,0.};
166  typename std::list<const Item*>::iterator it;
167  for(it = _LItems.begin(); it != _LItems.end(); ++it)
168  {
169  float pk[4];
170  (*it)->p4vec(pk);
171  //cout << "updateJet: px=" << pk[0] << " py=" << pk[1] << " pz=" << pk[2] << " E=" << pk[3] << endl;
172  for ( int i = 0; i < 4 ; ++i) p[i] += pk[i];
173  }
174  _y = P2y(p);
175  _phi = P2phi(p);
176  _pT = sqrt(p[0]*p[0] + p[1]*p[1]);
177  if ( p[3] < 0. ) _pT = - _pT;
178 
179 }
180 
181 template<class Item>
182 void ProtoJet<Item>::erase() {
183  _LItems.erase(_LItems.begin(),_LItems.end());
184  _y = 0.0;
185  _phi= 0.0;
186  _pT = 0.0;
187  // _info is not modified in order to keep split/merge history
188 }
189 
190 // actions to be taken when the jet is a stable cone
191 template<class Item>
192 void ProtoJet<Item>::NowStable() {
193  _info.initialET(_pT);
194 }
195 
196 template<class Item>
197 void ProtoJet<Item>::print(std::ostream& os) const {
198  os<<"y phi Et = ("<<_y<<", "<<_phi<<", "<<this->_Et<<")"<<std::endl;
199  os<< " members= " << std::endl;
200  typename std::list<const Item*>::const_iterator i;
201  for(i = _LItems.begin(); i != _LItems.end(); ++i)
202  (*i)->print(os);
203  os << std::endl;
204 }
205 
206 template<class Item>
207 inline float ProtoJet<Item>::y() const{
208  return _y;
209 }
210 
211 template<class Item>
212 inline float ProtoJet<Item>::phi() const{
213  return _phi;
214 }
215 
216 template<class Item>
217 inline float ProtoJet<Item>::pT() const{
218  return _pT;
219 }
220 template<class Item>
221 inline const ConeJetInfo & ProtoJet<Item>::info() const{
222  return _info;
223 }
224 
225 template<class Item>
226 inline const std::list<const Item*>& ProtoJet<Item>::LItems() const{
227  return _LItems;
228 }
229 ///////////////////////////////////////////////////////////////////////////////
230 
231 } // namespace d0
232 
233 FASTJET_END_NAMESPACE
234 
235 #endif