]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/stressTest/testSparse/testSparse.cxx
doxy: TPC/stressTest/testSparse converted
[u/mrichter/AliRoot.git] / TPC / stressTest / testSparse / testSparse.cxx
CommitLineData
30933baa 1/// \class testSparse
2/// \brief Test to check THnSparse - Layout example for TPC calibration
3///
4/// Tests categories:
5/// 1. CPU and memory consumption - using AliSysInfo class
6/// 2. Filling, reading and merging
7/// 3. Correctness of filling, and merging
8///
9///
10/// Functions:
11///
12/// 1. TestSparse(niter,nsize) -
13/// Fill the THnSparse in niter chunks
14/// for each chunks nsize entries filled
15/// The THnSparse is saved after each chunk
16/// Current momory and CPU information dumped to the text file
17/// 2. testRead(niter)
18/// Read THnSparses from disk
19/// Current momory and CPU information dumped to the text file
20///
21/// 3. testMerge(niter)
22/// Read THnSpares from disk
23/// Merge histograms
24/// Current momory and CPU information dumped to the text file
25
26
27
69ed8d29 28
29#include "THnSparse.h"
30#include "TRandom.h"
31#include "TFile.h"
32#include "TTree.h"
33#include "AliSysInfo.h"
34#include "TSystem.h"
35#include "TGraph.h"
36#include "TMath.h"
37
38void testSparse(Int_t niter, Int_t nsize){
30933baa 39 ///
40
69ed8d29 41 Double_t xminTrack[9], xmaxTrack[9];
42 Int_t binsTrack[9];
43 TString axisName[9],axisTitle[9];
44 //
45 // 0 - delta of interest
46 // 1 - global phi in sector number as float
47 // 2 - local x
48 // 3 - local ky
49 // 4 - local kz
50 //
51 axisName[0]="delta"; axisTitle[0]="#Delta (cm)";
52 binsTrack[0]=60; xminTrack[0]=-0.6; xmaxTrack[0]=0.6;
53 //
54 axisName[1]="sector"; axisTitle[1]="Sector Number";
55 binsTrack[1]=180; xminTrack[1]=0; xmaxTrack[1]=18;
56 //
57 axisName[2]="localX"; axisTitle[2]="x (cm)";
58 binsTrack[2]=53; xminTrack[2]=85.; xmaxTrack[2]=245.;
59 //
60 //
61 axisName[3]="kZ"; axisTitle[3]="dz/dx";
62 binsTrack[3]=36; xminTrack[3]=-1.8; xmaxTrack[3]=1.8;
63 //
64 THnSparse * fClusterDelta[2]={0,0};
65 fClusterDelta[0] = new THnSparseS("testFull","testFull", 4, binsTrack,xminTrack, xmaxTrack);
66 for (Int_t iter=0; iter<niter; iter++){
67 gRandom->SetSeed(0);
68 fClusterDelta[1] = new THnSparseS("testM","testM", 4, binsTrack,xminTrack, xmaxTrack);
69
70 for (Int_t ipoint=0; ipoint<nsize; ipoint++){
71 Double_t x[4]={0,0,0,0};
72 x[0]=gRandom->BreitWigner(0,0.2);
73 x[1]=gRandom->Rndm()*18;
74 x[2]=85+gRandom->Rndm()*(245.-85.);
75 x[3]=-1.8+gRandom->Rndm()*(3.6);
76 fClusterDelta[0]->Fill(x);
77 fClusterDelta[1]->Fill(x);
78 }
79 TFile f(Form("testSparse_%d.root",iter),"recreate");
80 fClusterDelta[0]->Write();
81 f.Close();
82 TFile f2(Form("testSparse2_%d.root",iter),"recreate");
83 fClusterDelta[1]->Write();
84 f2.Close();
85 Int_t bins0=fClusterDelta[0]->GetNbins()/1000;
86 Int_t bins1=fClusterDelta[1]->GetNbins()/1000;
87 Int_t n0=Int_t(fClusterDelta[0]->GetEntries()/1000);
88 Int_t n1=Int_t(fClusterDelta[1]->GetEntries()/1000);
89 printf("iter=%d\t%d\t%d\t%d\t%d\n",iter, bins0, bins1, n0,n1);
90 AliSysInfo::AddStamp(Form("iter%d",iter), iter,bins0,bins1);
91 delete fClusterDelta[1];
92 }
93 TTree * tree =AliSysInfo::MakeTree("syswatch.log");
94 gSystem->Exec("cp syswatch.log syswatchFill.log");
95 TFile f("syswatchFill.root","recreate");
96 tree->Write("sparse");
97 f.Close();
98}
99
100void testRead(Int_t nmax=100000){
30933baa 101 /// test read of THnSparse
102
69ed8d29 103 AliSysInfo::AddStamp("start", 0,0,0);
104 for (Int_t i=0; i<nmax; i++){
105 TFile f(Form("testSparse_%d.root",i));
106 AliSysInfo::AddStamp(Form("open%d",i), i,0,0);
107 THnSparse * his0 = (THnSparse*)f.Get("testFull");
108 if (!his0) break;
109 AliSysInfo::AddStamp(Form("read%d",i), i,1,0);
110 Int_t bins0=his0->GetNbins()/1000;
111 Int_t n0=Int_t(his0->GetEntries()/1000);
112 printf("iter=%d\t%d\t%d\n",i, bins0, n0);
113 AliSysInfo::AddStamp(Form("nbins%d",i), i,2,bins0);
114 AliSysInfo::AddStamp(Form("entries%d",i), i,3,n0);
115 delete his0;
116 AliSysInfo::AddStamp(Form("delete%d",i), i,4,0);
117 }
118 //
119 TTree * tree =AliSysInfo::MakeTree("syswatch.log");
120 gSystem->Exec("cp syswatch.log syswatchRead.log");
121 TFile f("syswatchRead.root","recreate");
122 tree->Write("sparse");
123 f.Close();
124}
125
126void testMerge(Int_t nmax,Int_t nmerge=1){
30933baa 127 /// test read of THnSparse
128
69ed8d29 129 THnSparse * hisM=0;
130 THnSparse * hisA[nmerge];
131 AliSysInfo::AddStamp("start", 0,0,0);
132 for (Int_t i=0; i<nmax; i++){
133 TFile f(Form("testSparse2_%d.root",i));
134 AliSysInfo::AddStamp(Form("open%d",i), i,0,0);
135 THnSparse * his0 = (THnSparse*)f.Get("testM");
136 if (!his0) break;
137 AliSysInfo::AddStamp(Form("read%d",i), i,1,0);
138 if (hisM==0) {
139 hisM=his0;
140 for (Int_t im=0; im<nmerge; im++) hisA[im]=(THnSparse*) hisM->Clone();
141 continue;
142 }
143 hisM->Add(his0);
144 for (Int_t im=0; im<nmerge; im++) hisA[im]->Add(hisM);
145 AliSysInfo::AddStamp(Form("merge%d",i), i,1,1); // stamp for merging - id1=1
146 Int_t bins0=hisM->GetNbins()/1000;
147 Int_t n0=Int_t(hisM->GetEntries()/1000);
148 printf("iter=%d\t%d\t%d\n",i, bins0, n0);
149 AliSysInfo::AddStamp(Form("nbins%d",i), i,2,bins0); // stamp for nbins id1=2
150 AliSysInfo::AddStamp(Form("entries%d",i), i,3,n0); // stamp for entries id1=3
151 delete his0;
152 AliSysInfo::AddStamp(Form("delete%d",i), i,4,0); // stamp for delete id1=4
153 }
154 //
155 TTree * tree =AliSysInfo::MakeTree("syswatch.log");
156 gSystem->Exec("cp syswatch.log syswatchMerge.log");
157 TFile f("syswatchMerge.root","recreate");
158 tree->Write("sparse");
159 f.Close();
160}
161
162
163void DrawDiff(){
30933baa 164 ///
165
69ed8d29 166 TTree * treeNew =AliSysInfo::MakeTree("testSparseNew/syswatch.log");
167 TTree * treeOld =AliSysInfo::MakeTree("testSparse/syswatch.log");
168 treeNew->SetMarkerStyle(25);
169 treeOld->SetMarkerStyle(27);
170 treeNew->SetMarkerColor(2);
171 treeOld->SetMarkerColor(4);
172
173 TGraph *grTime[2];
174 TGraph *grVM[2];
175 Int_t entries=0;
176 Double_t maxT=0, maxM=0;
177 entries=treeOld->Draw("deltaT:id0","","");
178 grTime[0] = new TGraph(entries, treeOld->GetV2(), treeOld->GetV1());
179 maxT=TMath::Max(maxT,TMath::MaxElement(entries, treeOld->GetV1()));
180 entries=treeNew->Draw("deltaT:id0","","");
181 grTime[1] = new TGraph(entries, treeNew->GetV2(), treeNew->GetV1());
182 maxT=TMath::Max(maxT,TMath::MaxElement(entries, treeNew->GetV1()));
183
184 entries=treeOld->Draw("VM:id0","","");
185 grVM[0] = new TGraph(entries, treeOld->GetV2(), treeOld->GetV1());
186 maxM=TMath::Max(maxM,TMath::MaxElement(entries, treeOld->GetV1()));
187 entries=treeNew->Draw("VM:id0","","");
188 grVM[1] = new TGraph(entries, treeNew->GetV2(), treeNew->GetV1());
189 maxM=TMath::Max(maxM,TMath::MaxElement(entries, treeNew->GetV1()));
190
191
192 grTime[0]->SetMarkerStyle(25);
193 grTime[1]->SetMarkerStyle(27);
194 grTime[0]->SetMarkerColor(2);
195 grTime[1]->SetMarkerColor(4);
196 grTime[0]->Draw("alp"); grTime[1]->Draw("alp");
197 grTime[1]->SetMaximum(maxT);
198 grTime[1]->Draw("alp");
199 grTime[0]->Draw("lp");
200
201
202
203}
204
205
206/*
207
208
209 aliroot -b -q /u/miranov/AliRoot/trunk/TPC/stressTest/testSparse/testSparse.cxx++\(150,1000000\)
210
211 counter=0
212 while [ $counter -lt 5 ] ; do
213 let counter=$counter+1
214 echo $counter
215 mkdir test$counter
216 cd test$counter
217 bsub -q alice-t3_8h -m batch_dgrid2 --oo out$counter.log aliroot -b -q /u/miranov/AliRoot/trunk/TPC/tmp/testSparse.cxx+\(100,2000000\)
218 cd ../
219 done;
220
221*/