Logo ROOT   6.10/09
Reference Guide
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  * Web : http://tmva.sourceforge.net *
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  * (http://tmva.sourceforge.net/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 using namespace std;
42 
43 //#define SW2 std::setw(12)
44 
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Default constructor for streamer
49 
51 : TObject(),
52  fDim(0),
53  fCoords(0)
54 {
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// User constructor creating n-dimensional vector
59 /// and allocating dynamically array of components
60 
62  : TObject(),
63  fDim(n),
64  fCoords(0)
65 {
66  if (n>0) {
67  fCoords = new Double_t[fDim];
68  for (Int_t i=0; i<n; i++) *(fCoords+i)=0.0;
69  }
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Copy constructor
74 
76  : TObject(),
77  fDim(vect.fDim),
78  fCoords(vect.fCoords)
79 {
80  Error( "PDEFoamVect", "COPY CONSTRUCTOR NOT IMPLEMENTED" );
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Destructor
85 
87 {
88  delete [] fCoords; // free(fCoords)
89  fCoords=0;
90 }
91 
92 //////////////////////////////////////////////////////////////////////////////
93 // Overloading operators //
94 //////////////////////////////////////////////////////////////////////////////
95 
96 ////////////////////////////////////////////////////////////////////////////////
97 /// substitution operator
98 
100 {
101  if (&vect == this) return *this;
102  if (fDim != vect.fDim)
103  Error("PDEFoamVect", "operator=Dims. are different: %d and %d \n ", fDim, vect.fDim);
104  if (fDim != vect.fDim) { // cleanup
105  delete [] fCoords;
106  fCoords = new Double_t[fDim];
107  }
108  fDim = vect.fDim;
109  for(Int_t i=0; i<fDim; i++)
110  fCoords[i] = vect.fCoords[i];
111  return *this;
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// [] is for access to elements as in ordinary matrix like a[j]=b[j]
116 /// (Perhaps against some strict rules but rather practical.)
117 /// Range protection is built in, consequently for substitution
118 /// one should use rather use a=b than explicit loop!
119 
121 {
122  if ((n<0) || (n>=fDim)) {
123  Error( "PDEFoamVect","operator[], out of range \n");
124  }
125  return fCoords[n];
126 }
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// unary multiplication operator *=
130 
132 {
133  for(Int_t i=0;i<fDim;i++)
134  fCoords[i] = fCoords[i]*x;
135  return *this;
136 }
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// unary addition operator +=; adding vector c*=x,
140 
142 {
143  if(fDim != shift.fDim){
144  Error("PDEFoamVect", "operator+, different dimensions= %d %d \n", fDim, shift.fDim);
145  }
146  for(Int_t i=0;i<fDim;i++)
147  fCoords[i] = fCoords[i] + shift.fCoords[i];
148  return *this;
149 }
150 
151 ////////////////////////////////////////////////////////////////////////////////
152 /// unary subtraction operator -=
153 
155 {
156  if(fDim != shift.fDim) {
157  Error("PDEFoamVect", "operator+, different dimensions= %d %d \n", fDim, shift.fDim);
158  }
159  for(Int_t i=0;i<fDim;i++)
160  fCoords[i] = fCoords[i] - shift.fCoords[i];
161  return *this;
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// addition operator +; sum of 2 vectors: c=a+b, a=a+b,
166 /// NEVER USE IT, VERY SLOW!!!
167 
169 {
170  PDEFoamVect temp(fDim);
171  temp = (*this);
172  temp += p2;
173  return temp;
174 }
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// subtraction operator -; difference of 2 vectors; c=a-b, a=a-b,
178 /// NEVER USE IT, VERY SLOW!!!
179 
181 {
182  PDEFoamVect temp(fDim);
183  temp = (*this);
184  temp -= p2;
185  return temp;
186 }
187 
188 ////////////////////////////////////////////////////////////////////////////////
189 /// Loading in ordinary double prec. vector, sometimes can be useful
190 
192 {
193  for(Int_t i=0; i<fDim; i++)
194  fCoords[i] = Vect[i];
195  return *this;
196 }
197 
198 ////////////////////////////////////////////////////////////////////////////////
199 /// Loading in double prec. number, sometimes can be useful
200 
202 {
203  if(fCoords != 0) {
204  for(Int_t i=0; i<fDim; i++)
205  fCoords[i] = x;
206  }
207  return *this;
208 }
209 
210 //////////////////////////////////////////////////////////////////////////////
211 // OTHER METHODS //
212 //////////////////////////////////////////////////////////////////////////////
213 
214 ////////////////////////////////////////////////////////////////////////////////
215 /// Printout of all vector components
216 
218 {
219  streamsize wid = std::cout.width(); // saving current field width
220  if(!option) Error( "Print ", "No option set \n");
221  std::cout << "(";
222  for(Int_t i=0; i<fDim-1; i++)
223  std::cout << std::setw(12) << *(fCoords+i) << ",";
224  std::cout << std::setw(12) << *(fCoords+fDim-1);
225  std::cout << ")";
226  std::cout.width(wid);
227 }
PDEFoamVect & operator*=(const Double_t &)
unary multiplication operator *=
PDEFoamVect & operator-=(const PDEFoamVect &)
unary subtraction operator -=
PDEFoamVect & operator=(const PDEFoamVect &)
substitution operator
Definition: PDEFoamVect.cxx:99
const char Option_t
Definition: RtypesCore.h:62
void Print(Option_t *option) const
Printout of all vector components.
int Int_t
Definition: RtypesCore.h:41
STL namespace.
virtual ~PDEFoamVect()
Destructor.
Definition: PDEFoamVect.cxx:86
Double_t & operator[](Int_t)
[] is for access to elements as in ordinary matrix like a[j]=bj Range protection is built in...
Double_t x[n]
Definition: legend1.C:17
static double p2(double t, double a, double b, double c)
PDEFoamVect()
Default constructor for streamer.
Definition: PDEFoamVect.cxx:50
Double_t * fCoords
Definition: PDEFoamVect.h:40
PDEFoamVect & operator+=(const PDEFoamVect &)
unary addition operator +=; adding vector c*=x,
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:873
PDEFoamVect operator+(const PDEFoamVect &)
addition operator +; sum of 2 vectors: c=a+b, a=a+b, NEVER USE IT, VERY SLOW!!!
#define ClassImp(name)
Definition: Rtypes.h:336
double Double_t
Definition: RtypesCore.h:55
Mother of all ROOT objects.
Definition: TObject.h:37
Abstract ClassifierFactory template that handles arbitrary types.
PDEFoamVect operator-(const PDEFoamVect &)
subtraction operator -; difference of 2 vectors; c=a-b, a=a-b, NEVER USE IT, VERY SLOW!!! ...
const Int_t n
Definition: legend1.C:16