[499] | 1 | #include <stdio.h>
|
---|
| 2 | #include <stdlib.h>
|
---|
| 3 | #include "math.h"
|
---|
| 4 | #include <iostream.h>
|
---|
| 5 | #include <string>
|
---|
| 6 |
|
---|
| 7 | // Pour le test
|
---|
| 8 | #include "cvector.h"
|
---|
| 9 | #include "matrix.h"
|
---|
| 10 | #include "histos.h"
|
---|
| 11 | #include "histos2.h"
|
---|
| 12 | #include "ntuple.h"
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | #include "fmath.h"
|
---|
| 16 | #include "nbrandom.h"
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | int main(int narg, char* arg[])
|
---|
| 20 | {
|
---|
| 21 |
|
---|
| 22 | POutPersist so("tobjio.ppf");
|
---|
| 23 |
|
---|
| 24 | cout << "Test Creation / PPersist Save NTuple, Histo, ..." << endl;
|
---|
| 25 | NTuple *nt;
|
---|
| 26 | float xnt[4];
|
---|
| 27 | char *ntn[4] = {"x","y","ex","ey"};
|
---|
| 28 | int nent,i;
|
---|
| 29 | nent = 1000;
|
---|
| 30 | nt = new NTuple(2,ntn); // Creation NTuple (AVEC new )
|
---|
| 31 | for(i=0; i<nent; i++) {
|
---|
| 32 | xnt[0] = i*50./nent; xnt[1] = 0.2*xnt[0]*xnt[0]+(NorRand()*xnt[0]/3.);
|
---|
| 33 | nt->Fill(xnt);
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | string nom = "nt21";
|
---|
| 37 | ObjFileIO<NTuple> oiont(*nt);
|
---|
| 38 | oiont.Write(so, nom);
|
---|
| 39 | cout << "Writing " << nom << endl;
|
---|
| 40 |
|
---|
| 41 | string nx, ny, nz;
|
---|
| 42 | string ex,ey,ez;
|
---|
| 43 | nx = "x"; ny = "y";
|
---|
| 44 | nent = 20;
|
---|
| 45 | nt = new NTuple(4,ntn); // Creation NTuple (AVEC new )
|
---|
| 46 | for(i=0; i<nent; i++) {
|
---|
| 47 | xnt[0] = i*50./nent; xnt[1] = 0.2*xnt[0]*xnt[0]+(NorRand()*xnt[0]/3.);
|
---|
| 48 | xnt[2] = sqrt((double) xnt[0]); xnt[3] = xnt[0]*2;
|
---|
| 49 | nt->Fill(xnt);
|
---|
| 50 | }
|
---|
| 51 | nom = "nt22";
|
---|
| 52 | ObjFileIO<NTuple> oiont2(*nt);
|
---|
| 53 | oiont2.Write(so, nom);
|
---|
| 54 | cout << "Writing " << nom << endl;
|
---|
| 55 |
|
---|
| 56 | { // Objet Histo-2D
|
---|
| 57 | float x,y,w;
|
---|
| 58 | int i,j;
|
---|
| 59 | Histo2D* h = new Histo2D(-10.,10.,25,-10.,10.,25);
|
---|
| 60 | for(i=0; i<25; i++) for(j=0; j<25; j++) {
|
---|
| 61 | h->BinCenter(i,j,x,y);
|
---|
| 62 | w = 100.*exp(-0.5*(x*x/9. + y*y/9.));
|
---|
| 63 | h->Add(x,y,w);
|
---|
| 64 | w = 50.*exp(-0.5*((x+10.)*(x+10.)/9. + (y+10.)*(y+10.)/9.));
|
---|
| 65 | h->Add(x,y,w);
|
---|
| 66 | }
|
---|
| 67 | nom = "h2d";
|
---|
| 68 | ObjFileIO<Histo2D> oioh(*h);
|
---|
| 69 | oioh.Write(so, nom);
|
---|
| 70 | cout << "Writing " << nom << endl;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | {
|
---|
| 74 | Histo *h;
|
---|
| 75 | float x;
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | h = new Histo(0., 200., 100); // Creation histo (AVEC new )
|
---|
| 79 | for(i=0; i<100; i++) // Remplissage d'histo
|
---|
| 80 | { x = (2*i+1.); h->Add(x, x*(200.-x)); }
|
---|
| 81 | nom = "h1d";
|
---|
| 82 | ObjFileIO<Histo> oioh(*h);
|
---|
| 83 | oioh.Write(so, nom);
|
---|
| 84 | cout << "Writing " << nom << endl;
|
---|
| 85 |
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | { // Vecteurs
|
---|
| 89 | Vector* vpx, *vpy;
|
---|
| 90 | vpx = new Vector(20); vpy = new Vector(20);
|
---|
| 91 | int i; double x;
|
---|
| 92 | for(i=0; i<20; i++) { x = 8.*i/20; (*vpx)(i) = x; (*vpy)(i) = 3*cos(x)+2*sin(x); }
|
---|
| 93 | nom = "vx1";
|
---|
[539] | 94 | FIO_TVector<double> oiov1(vpx);
|
---|
| 95 | oiov1.Write(so, nom);
|
---|
[499] | 96 | cout << "Writing " << nom << endl;
|
---|
| 97 | nom = "vy1";
|
---|
[539] | 98 | FIO_TVector<double> oiov2(vpy);
|
---|
| 99 | oiov2.Write(so, nom);
|
---|
[499] | 100 | cout << "Writing " << nom << endl;
|
---|
| 101 | vpx = new Vector(30);
|
---|
| 102 | for(i=0; i<30; i++) { x = 8.*i/30+0.1; (*vpx)(i) = sin(2.*x)/(2.*x); }
|
---|
| 103 | nom = "vx2";
|
---|
[539] | 104 | FIO_TVector<double> oiov3(vpy);
|
---|
| 105 | oiov3.Write(so, nom);
|
---|
[499] | 106 | cout << "Writing " << nom << endl;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | { // NTuple 3D
|
---|
| 111 | float xnt[6];
|
---|
| 112 | double ang;
|
---|
| 113 | char *ntn[6] = {"x","y","z","ex","ey","ez"};
|
---|
| 114 | int nent,i;
|
---|
| 115 |
|
---|
| 116 | NTuple* nt = new NTuple(6,ntn); // Creation NTuple (AVEC new )
|
---|
| 117 | nent = 3000;
|
---|
| 118 | for(i=0; i<nent; i++) {
|
---|
| 119 | ang = 5.*6.28*(double)i/(double)nent;
|
---|
| 120 | xnt[0] = cos(ang)*1.5+NorRand()*0.1; xnt[1] = sin(ang)*1.5+NorRand()*0.1;
|
---|
| 121 | xnt[2] = ang/8.+NorRand()*0.05; xnt[3] = xnt[4] = xnt[5] = 0.;
|
---|
| 122 | nt->Fill(xnt);
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | nom = "nt31";
|
---|
| 126 | ObjFileIO<NTuple> oiont(*nt);
|
---|
| 127 | oiont.Write(so, nom);
|
---|
| 128 | cout << "Writing " << nom << endl;
|
---|
| 129 |
|
---|
| 130 | nt = new NTuple(6,ntn); // Creation NTuple (AVEC new )
|
---|
| 131 | nent = 100;
|
---|
| 132 | for(i=0; i<nent; i++) {
|
---|
| 133 | ang = 5.*6.28*(double)i/(double)nent;
|
---|
| 134 | xnt[0] = cos(-ang)*1+NorRand()*0.0; xnt[1] = sin(-ang)*1.+NorRand()*0.0;
|
---|
| 135 | xnt[2] = ang/8.+NorRand()*0.0; xnt[3] = 0.1; xnt[4] = 0.15; xnt[5] = 0.07;
|
---|
| 136 | nt->Fill(xnt);
|
---|
| 137 | }
|
---|
| 138 | nom = "nt32";
|
---|
| 139 | ObjFileIO<NTuple> oiont2(*nt);
|
---|
| 140 | oiont2.Write(so, nom);
|
---|
| 141 | cout << "Writing " << nom << endl;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | { // Matrices
|
---|
| 145 | Matrix* mtx = new Matrix(50, 50);
|
---|
| 146 | int i,j;
|
---|
| 147 | double xp,yp,rp;
|
---|
| 148 | for(i=0; i<50; i++)
|
---|
| 149 | for(j=0; j<50; j++) {
|
---|
| 150 | xp = i-15; yp = j-25;
|
---|
| 151 | rp = (xp*xp)/16.+(yp*yp)/16.;
|
---|
| 152 | (*mtx)(j,i) = 11.*exp(-rp);
|
---|
| 153 | xp = i-35; yp = j-15;
|
---|
| 154 | rp = (xp*xp)/9.+(yp*yp)/9.;
|
---|
| 155 | (*mtx)(j,i) += 3.*exp(-rp);
|
---|
| 156 | xp = i-45; yp = j-40;
|
---|
| 157 | rp = (xp*xp)/10.+(yp*yp)/20.;
|
---|
| 158 | (*mtx)(j,i) += 6.*exp(-rp);
|
---|
| 159 | }
|
---|
| 160 | nom = "mtx1";
|
---|
[539] | 161 | FIO_TMatrix<double> oiom(mtx);
|
---|
| 162 | oiom.Write(so, nom);
|
---|
[499] | 163 | cout << "Writing " << nom << endl;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | cout << " End --- exit .... " << endl;
|
---|
| 167 | }
|
---|
| 168 |
|
---|