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