Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
PDEFoamVect.cxx
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: S. Jadach, Tancredi Carli, Dominik Dannheim, Alexander Voigt
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Classes: PDEFoamVect *
8 * *
9 * *
10 * Description: *
11 * Auxiliary class PDEFoamVect of n-dimensional vector, with dynamic *
12 * allocation used for the cartesian geometry of the PDEFoam cells *
13 * *
14 * Authors (alphabetical): *
15 * S. Jadach - Institute of Nuclear Physics, Cracow, Poland *
16 * Tancredi Carli - CERN, Switzerland *
17 * Dominik Dannheim - CERN, Switzerland *
18 * Alexander Voigt - TU Dresden, Germany *
19 * *
20 * Copyright (c) 2008: *
21 * CERN, Switzerland *
22 * MPI-K Heidelberg, Germany *
23 * *
24 * Redistribution and use in source and binary forms, with or without *
25 * modification, are permitted according to the terms listed in LICENSE *
26 * (see tmva/doc/LICENSE) *
27 **********************************************************************************/
28
29/*! \class TMVA::PDEFoamVect
30\ingroup TMVA
31
32*/
33#include "TMVA/PDEFoamVect.h"
34
35#include "Rtypes.h"
36#include "TObject.h"
37
38#include <iostream>
39#include <iomanip>
40
41//#define SW2 std::setw(12)
42
43using std::streamsize;
44
45
46////////////////////////////////////////////////////////////////////////////////
47/// Default constructor for streamer
48
50: TObject(),
51 fDim(0),
52 fCoords(0)
53{
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// User constructor creating n-dimensional vector
58/// and allocating dynamically array of components
59
61 : TObject(),
62 fDim(n),
63 fCoords(0)
64{
65 if (n>0) {
66 fCoords = new Double_t[fDim];
67 for (Int_t i=0; i<n; i++) *(fCoords+i)=0.0;
68 }
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Copy constructor
73
75 : TObject(),
76 fDim(vect.fDim),
77 fCoords(vect.fCoords)
78{
79 Error( "PDEFoamVect", "COPY CONSTRUCTOR NOT IMPLEMENTED" );
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Destructor
84
86{
87 delete [] fCoords; // free(fCoords)
88 fCoords=0;
89}
90
91//////////////////////////////////////////////////////////////////////////////
92// Overloading operators //
93//////////////////////////////////////////////////////////////////////////////
94
95////////////////////////////////////////////////////////////////////////////////
96/// substitution operator
97
99{
100 if (&vect == this) return *this;
101 if (fDim != vect.fDim)
102 Error("PDEFoamVect", "operator=Dims. are different: %d and %d \n ", fDim, vect.fDim);
103 if (fDim != vect.fDim) { // cleanup
104 delete [] fCoords;
105 fCoords = new Double_t[fDim];
106 }
107 fDim = vect.fDim;
108 for(Int_t i=0; i<fDim; i++)
109 fCoords[i] = vect.fCoords[i];
110 return *this;
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// [] is for access to elements as in ordinary matrix like a[j]=b[j]
115/// (Perhaps against some strict rules but rather practical.)
116/// Range protection is built in, consequently for substitution
117/// one should use rather use a=b than explicit loop!
118
120{
121 if ((n<0) || (n>=fDim)) {
122 Error( "PDEFoamVect","operator[], out of range \n");
123 }
124 return fCoords[n];
125}
126
127////////////////////////////////////////////////////////////////////////////////
128/// unary multiplication operator *=
129
131{
132 for(Int_t i=0;i<fDim;i++)
133 fCoords[i] = fCoords[i]*x;
134 return *this;
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// unary addition operator +=; adding vector c*=x,
139
141{
142 if(fDim != shift.fDim){
143 Error("PDEFoamVect", "operator+, different dimensions= %d %d \n", fDim, shift.fDim);
144 }
145 for(Int_t i=0;i<fDim;i++)
146 fCoords[i] = fCoords[i] + shift.fCoords[i];
147 return *this;
148}
149
150////////////////////////////////////////////////////////////////////////////////
151/// unary subtraction operator -=
152
154{
155 if(fDim != shift.fDim) {
156 Error("PDEFoamVect", "operator+, different dimensions= %d %d \n", fDim, shift.fDim);
157 }
158 for(Int_t i=0;i<fDim;i++)
159 fCoords[i] = fCoords[i] - shift.fCoords[i];
160 return *this;
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// addition operator +; sum of 2 vectors: c=a+b, a=a+b,
165/// NEVER USE IT, VERY SLOW!!!
166
168{
169 PDEFoamVect temp(fDim);
170 temp = (*this);
171 temp += p2;
172 return temp;
173}
174
175////////////////////////////////////////////////////////////////////////////////
176/// subtraction operator -; difference of 2 vectors; c=a-b, a=a-b,
177/// NEVER USE IT, VERY SLOW!!!
178
180{
181 PDEFoamVect temp(fDim);
182 temp = (*this);
183 temp -= p2;
184 return temp;
185}
186
187////////////////////////////////////////////////////////////////////////////////
188/// Loading in ordinary double prec. vector, sometimes can be useful
189
191{
192 for(Int_t i=0; i<fDim; i++)
193 fCoords[i] = Vect[i];
194 return *this;
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Loading in double prec. number, sometimes can be useful
199
201{
202 if(fCoords != 0) {
203 for(Int_t i=0; i<fDim; i++)
204 fCoords[i] = x;
205 }
206 return *this;
207}
208
209//////////////////////////////////////////////////////////////////////////////
210// OTHER METHODS //
211//////////////////////////////////////////////////////////////////////////////
212
213////////////////////////////////////////////////////////////////////////////////
214/// Printout of all vector components
215
217{
218 streamsize wid = std::cout.width(); // saving current field width
219 if(!option) Error( "Print ", "No option set \n");
220 std::cout << "(";
221 for(Int_t i=0; i<fDim-1; i++)
222 std::cout << std::setw(12) << *(fCoords+i) << ",";
223 std::cout << std::setw(12) << *(fCoords+fDim-1);
224 std::cout << ")";
225 std::cout.width(wid);
226}
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize wid
PDEFoamVect operator-(const PDEFoamVect &)
subtraction operator -; difference of 2 vectors; c=a-b, a=a-b, NEVER USE IT, VERY SLOW!...
PDEFoamVect & operator=(const PDEFoamVect &)
substitution operator
void Print(Option_t *option) const override
Printout of all vector components.
PDEFoamVect & operator+=(const PDEFoamVect &)
unary addition operator +=; adding vector c*=x,
PDEFoamVect operator+(const PDEFoamVect &)
addition operator +; sum of 2 vectors: c=a+b, a=a+b, NEVER USE IT, VERY SLOW!!!
virtual ~PDEFoamVect()
Destructor.
Double_t & operator[](Int_t)
[] is for access to elements as in ordinary matrix like a[j]=b[j] (Perhaps against some strict rules ...
PDEFoamVect & operator*=(const Double_t &)
unary multiplication operator *=
PDEFoamVect()
Constructor.
PDEFoamVect & operator-=(const PDEFoamVect &)
unary subtraction operator -=
Int_t fDim
Dimension.
Definition PDEFoamVect.h:39
Double_t * fCoords
[fDim] Coordinates
Definition PDEFoamVect.h:40
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16