00001 00002 // File: momentum.cpp // 00003 // Description: source file for 4-momentum class Cmomentum // 00004 // This file is part of the SISCone project. // 00005 // For more details, see http://projects.hepforge.org/siscone // 00006 // // 00007 // Copyright (c) 2006 Gavin Salam and Gregory Soyez // 00008 // // 00009 // This program is free software; you can redistribute it and/or modify // 00010 // it under the terms of the GNU General Public License as published by // 00011 // the Free Software Foundation; either version 2 of the License, or // 00012 // (at your option) any later version. // 00013 // // 00014 // This program is distributed in the hope that it will be useful, // 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00017 // GNU General Public License for more details. // 00018 // // 00019 // You should have received a copy of the GNU General Public License // 00020 // along with this program; if not, write to the Free Software // 00021 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA // 00022 // // 00023 // $Revision:: 123 $// 00024 // $Date:: 2007-02-28 20:52:16 -0500 (Wed, 28 Feb 2007) $// 00026 00027 #include "momentum.h" 00028 #include <math.h> 00029 #include <stdlib.h> 00030 00031 namespace siscone{ 00032 00033 /************************************************************************* 00034 * class Cmomentum * 00035 * This class contains the information for particle or group of * 00036 * particles management. * 00037 * It includes all Lorentz properties as well as tools for summing them. * 00038 *************************************************************************/ 00039 00040 // default ctor 00041 //-------------- 00042 Cmomentum::Cmomentum(){ 00043 eta = 0.0; 00044 phi = 0.0; 00045 px = py = pz = E = 0.0; 00046 ref = Creference(); 00047 index = -1; 00048 } 00049 00050 // ctor with initialisation 00051 //-------------------------- 00052 Cmomentum::Cmomentum(double _px, double _py, double _pz, double _E){ 00053 px = _px; 00054 py = _py; 00055 pz = _pz; 00056 E = _E; 00057 00058 // compute eta and phi 00059 build_etaphi(); 00060 ref = Creference(); 00061 } 00062 00063 // ctor with detailed initialisation 00064 //----------------------------------- 00065 Cmomentum::Cmomentum(double _eta, double _phi, Creference _ref){ 00066 eta = _eta; 00067 phi = _phi; 00068 00069 ref = _ref; 00070 } 00071 00072 // default dtor 00073 //-------------- 00074 Cmomentum::~Cmomentum(){ 00075 00076 } 00077 00078 // assignment of vectors 00079 //----------------------- 00080 Cmomentum& Cmomentum::operator = (const Cmomentum &v){ 00081 px = v.px; 00082 py = v.py; 00083 pz = v.pz; 00084 E = v.E; 00085 00086 eta = v.eta; 00087 phi = v.phi; 00088 00089 ref = v.ref; 00090 return *this; 00091 } 00092 00093 // addition of vectors 00094 // !!! WARNING !!! no updating of eta and phi !!! 00095 //------------------------------------------------ 00096 const Cmomentum Cmomentum::operator + (const Cmomentum &v){ 00097 Cmomentum tmp = *this; 00098 return tmp+=v; 00099 } 00100 00101 // incrementation of vectors 00102 // !!! WARNING !!! no updating of eta and phi !!! 00103 //------------------------------------------------ 00104 Cmomentum& Cmomentum::operator += (const Cmomentum &v){ 00105 px+=v.px; 00106 py+=v.py; 00107 pz+=v.pz; 00108 E +=v.E; 00109 00110 ref+=v.ref; 00111 00112 return *this; 00113 } 00114 00115 // incrementation of vectors 00116 // !!! WARNING !!! no updating of eta and phi !!! 00117 //------------------------------------------------ 00118 Cmomentum& Cmomentum::operator -= (const Cmomentum &v){ 00119 px-=v.px; 00120 py-=v.py; 00121 pz-=v.pz; 00122 E -=v.E; 00123 00124 ref-=v.ref; 00125 return *this; 00126 } 00127 00128 // build eta-phi from 4-momentum info 00129 // !!! WARNING !!! 00130 // !!! computing eta and phi is time-consuming !!! 00131 // !!! use this whenever you need eta or phi !!! 00132 // !!! automatically called for single-particle !!! 00133 //-------------------------------------------------- 00134 void Cmomentum::build_etaphi(){ 00135 // note: the factor n (ref.nb) cancels in all expressions !! 00136 eta = 0.5*log((E+pz)/(E-pz)); 00137 phi = atan2(py,px); 00138 } 00139 00140 00141 // ordering of two vectors 00142 // the default ordering is w.r.t. their references 00143 //------------------------------------------------- 00144 bool operator < (const Cmomentum &v1, const Cmomentum &v2){ 00145 return v1.ref < v2.ref; 00146 } 00147 00148 // ordering of vectors in eta (e.g. used in collinear tests) 00149 //----------------------------------------------------------- 00150 bool momentum_eta_less(const Cmomentum &v1, const Cmomentum &v2){ 00151 return v1.eta < v2.eta; 00152 } 00153 00154 // ordering of vectors in pt 00155 //--------------------------- 00156 bool momentum_pt_less(const Cmomentum &v1, const Cmomentum &v2){ 00157 return v1.perp2() < v2.perp2(); 00158 } 00159 00160 } 00161