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