1 ///////////////////////////////////////////////////////////////////////////////
2 // File: momentum.cpp                                                        //
3 // Description: source file for 4-momentum class Cmomentum                   //
4 // This file is part of the SISCone project.                                 //
5 // WARNING: this is not the main SISCone trunk but                           //
6 //          an adaptation to spherical coordinates                           //
7 // For more details, see http://projects.hepforge.org/siscone                //
8 //                                                                           //
9 // Copyright (c) 2006-2008 Gavin Salam and Gregory Soyez                          //
10 //                                                                           //
11 // This program is free software; you can redistribute it and/or modify      //
12 // it under the terms of the GNU General Public License as published by      //
13 // the Free Software Foundation; either version 2 of the License, or         //
14 // (at your option) any later version.                                       //
15 //                                                                           //
16 // This program is distributed in the hope that it will be useful,           //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of            //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             //
19 // GNU General Public License for more details.                              //
20 //                                                                           //
21 // You should have received a copy of the GNU General Public License         //
22 // along with this program; if not, write to the Free Software               //
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
24 //                                                                           //
25 // $Revision:: 255                                                          $//
26 // $Date:: 2008-07-12 17:40:35 +0200 (Sat, 12 Jul 2008)                     $//
27 ///////////////////////////////////////////////////////////////////////////////
28 
29 #include "momentum.h"
30 #include <math.h>
31 #include <stdlib.h>
32 
33 namespace siscone_spherical{
34 
35 /*************************************************************************
36  * class CSph3vector                                                     *
37  * This class contains the information for particle or group of          *
38  * particles management.                                                 *
39  *************************************************************************/
40 
41 // default ctor
42 //--------------
CSph3vector()43 CSph3vector::CSph3vector(){
44   _theta = _phi = _norm = 0.0;
45   px = py = pz = 0.0;
46   ref = siscone::Creference();
47 }
48 
49 // ctor with initialisation
50 //--------------------------
CSph3vector(double _px,double _py,double _pz)51 CSph3vector::CSph3vector(double _px, double _py, double _pz){
52   px = _px;
53   py = _py;
54   pz = _pz;
55 
56   // compute the norm
57   build_norm();
58 
59   ref = siscone::Creference();
60 }
61 
62 // default dtor
63 //--------------
~CSph3vector()64 CSph3vector::~CSph3vector(){
65 
66 }
67 
68 
69 // assignment of vectors
70 //-----------------------
operator =(const CSph3vector & v)71 CSph3vector& CSph3vector::operator = (const CSph3vector &v){
72   px = v.px;
73   py = v.py;
74   pz = v.pz;
75 
76   _norm  = v._norm;
77   _theta = v._theta;
78   _phi   = v._phi;
79 
80   ref = v.ref;
81   return *this;
82 }
83 
84 // addition of vectors
85 //------------------------------------------------
operator +(const CSph3vector & v)86 const CSph3vector CSph3vector::operator + (const CSph3vector &v){
87   CSph3vector tmp = *this;
88   return tmp+=v;
89 }
90 
91 // subtraction of vectors
92 //------------------------------------------------
operator -(const CSph3vector & v)93 const CSph3vector CSph3vector::operator - (const CSph3vector &v){
94   CSph3vector tmp = *this;
95   return tmp-=v;
96 }
97 
98 // division by constant
99 //------------------------------------------------
operator /(const double & r)100 const CSph3vector CSph3vector::operator / (const double &r){
101   CSph3vector tmp = *this;
102   return tmp/=r;
103 }
104 
105 // incrementation
106 //------------------------------------------------
operator +=(const CSph3vector & v)107 CSph3vector& CSph3vector::operator += (const CSph3vector &v){
108   px+=v.px;
109   py+=v.py;
110   pz+=v.pz;
111 
112   return *this;
113 }
114 
115 // decrementation
116 //------------------------------------------------
operator -=(const CSph3vector & v)117 CSph3vector& CSph3vector::operator -= (const CSph3vector &v){
118   px-=v.px;
119   py-=v.py;
120   pz-=v.pz;
121 
122   return *this;
123 }
124 
125 // multiplication by a constant
126 //------------------------------------------------
operator *=(const double & r)127 CSph3vector& CSph3vector::operator *= (const double &r){
128   px*=r;
129   py*=r;
130   pz*=r;
131 
132   return *this;
133 }
134 
135 // division by a constant
136 //------------------------------------------------
operator /=(const double & r)137 CSph3vector& CSph3vector::operator /= (const double &r){
138   px/=r;
139   py/=r;
140   pz/=r;
141 
142   _norm/=r;
143 
144   return *this;
145 }
146 
147 // build norm from 3-momentum info
build_norm()148 void CSph3vector::build_norm(){
149   _norm = norm();
150 }
151 
152 // build norm from 3-momentum info
build_thetaphi()153 void CSph3vector::build_thetaphi(){
154   _theta = theta();
155   _phi = phi();
156 }
157 
158 
159 // for this direction, compute the two reference directions
160 // used to measure angles
get_angular_directions(CSph3vector & angular_dir1,CSph3vector & angular_dir2)161 void CSph3vector::get_angular_directions(CSph3vector &angular_dir1, CSph3vector &angular_dir2){
162   if (px < py){
163     if (pz < px){
164       // z smallest
165       angular_dir1 = CSph3vector(-py, px, 0.0);
166     } else {
167       // x smallest
168       angular_dir1 = CSph3vector(0.0, -pz, py);
169     }
170   } else {
171     if (pz < py){
172       // z smallest
173       angular_dir1 = CSph3vector(-py, px, 0.0);
174     } else {
175       // y smallest
176       angular_dir1 = CSph3vector(-pz, 0.0, px);
177     }
178   }
179   angular_dir2 = cross_product3(*this, angular_dir1);
180   // We'll simply take x & y so the reflection symmetry is not broken
181   //angular_dir1 = CSph3vector(0.0, -pz, py);
182   //angular_dir2 = CSph3vector(-pz, 0.0, -px);
183 }
184 
185 /*************************************************************************
186  * class CSphmomentum                                                    *
187  * This class contains the information for particle or group of          *
188  * particles management.                                                 *
189  * It includes all Lorentz properties as well as tools for summing them. *
190  *************************************************************************/
191 
192 // default ctor
193 //--------------
CSphmomentum()194 CSphmomentum::CSphmomentum(){
195   E=0.0;
196   index = -1;
197 }
198 
199 // ctor with initialisation
200 //--------------------------
CSphmomentum(double _px,double _py,double _pz,double _E)201 CSphmomentum::CSphmomentum(double _px, double _py, double _pz, double _E)
202   : CSph3vector(_px, _py, _pz) {
203   E  = _E;
204 
205   // compute the angles
206   build_thetaphi();
207 }
208 
209 // ctor with initialisation
210 //--------------------------
CSphmomentum(CSph3vector & _v,double _E)211 CSphmomentum::CSphmomentum(CSph3vector &_v, double _E)
212   : CSph3vector(_v.px, _v.py, _v.pz) {
213   E  = _E;
214 }
215 
216 // default dtor
217 //--------------
~CSphmomentum()218 CSphmomentum::~CSphmomentum(){
219 
220 }
221 
222 // assignment of vectors
223 //-----------------------
operator =(const CSphmomentum & v)224 CSphmomentum& CSphmomentum::operator = (const CSphmomentum &v){
225   px = v.px;
226   py = v.py;
227   pz = v.pz;
228   E  = v.E;
229 
230   _norm  = v._norm;
231   _theta = v._theta;
232   _phi   = v._phi;
233 
234   ref = v.ref;
235   return *this;
236 }
237 
238 // addition of vectors
239 // !!! WARNING !!! no updating of eta and phi !!!
240 //------------------------------------------------
operator +(const CSphmomentum & v)241 const CSphmomentum CSphmomentum::operator + (const CSphmomentum &v){
242   CSphmomentum tmp = *this;
243   return tmp+=v;
244 }
245 
246 // incrementation of vectors
247 // !!! WARNING !!! no updating of eta and phi !!!
248 //------------------------------------------------
operator +=(const CSphmomentum & v)249 CSphmomentum& CSphmomentum::operator += (const CSphmomentum &v){
250   px+=v.px;
251   py+=v.py;
252   pz+=v.pz;
253   E +=v.E;
254 
255   ref+=v.ref;
256 
257   return *this;
258 }
259 
260 // decrementation of vectors
261 // !!! WARNING !!! no updating of eta and phi !!!
262 //------------------------------------------------
operator -=(const CSphmomentum & v)263 CSphmomentum& CSphmomentum::operator -= (const CSphmomentum &v){
264   px-=v.px;
265   py-=v.py;
266   pz-=v.pz;
267   E -=v.E;
268 
269   ref-=v.ref;
270   return *this;
271 }
272 
273 
274 // ordering of two vectors
275 // the default ordering is w.r.t. their references
276 //-------------------------------------------------
operator <(const CSphmomentum & v1,const CSphmomentum & v2)277 bool operator < (const CSphmomentum &v1, const CSphmomentum &v2){
278   return v1.ref < v2.ref;
279 }
280 
281 // ordering of vectors in eta (e.g. used in collinear tests)
282 //-----------------------------------------------------------
momentum_theta_less(const CSphmomentum & v1,const CSphmomentum & v2)283 bool momentum_theta_less(const CSphmomentum &v1, const CSphmomentum &v2){
284   return v1._theta < v2._theta;
285 }
286 
287 // ordering of vectors in pt
288 //---------------------------
momentum_pt_less(const CSphmomentum & v1,const CSphmomentum & v2)289 bool momentum_pt_less(const CSphmomentum &v1, const CSphmomentum &v2){
290   return v1.perp2() < v2.perp2();
291 }
292 
293 }
294 
295