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