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