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