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