NCFS-Pack
A generic (astro)particle physics analysis framework
Loading...
Searching...
No Matches
NcSample.cxx
Go to the documentation of this file.
1
31
33
84
85#include "NcSample.h"
86#include "Riostream.h"
87
88ClassImp(NcSample); // Class implementation to enable ROOT I/O
89
91NcSample::NcSample(const char* name,const char* title) : TNamed(name,title)
92{
99
101 fN=0;
102 fRemove=0;
103 fStore=0;
104 fNmax=0;
106 fX=0;
107 fY=0;
108 fZ=0;
109 fT=0;
110 fArr=0;
111 fIndices=0;
112 fOrdered=0;
113 fGraphT=0;
114 fCanvas=0;
115 fAnimObject=0;
116 Reset();
117 SetNames();
118}
119
121{
127
128 if (fX)
129 {
130 delete fX;
131 fX=0;
132 }
133 if (fY)
134 {
135 delete fY;
136 fY=0;
137 }
138 if (fZ)
139 {
140 delete fZ;
141 fZ=0;
142 }
143 if (fT)
144 {
145 delete fT;
146 fT=0;
147 }
148 if (fArr)
149 {
150 delete fArr;
151 fArr=0;
152 }
153 if (fIndices)
154 {
155 delete fIndices;
156 fIndices=0;
157 }
158 if (fGraphT)
159 {
160 delete fGraphT;
161 fGraphT=0;
162 }
163 if (fCanvas)
164 {
165 delete fCanvas;
166 fCanvas=0;
167 }
168 if (fAnimObject)
169 {
170 delete fAnimObject;
171 fAnimObject=0;
172 }
173}
174
175NcSample::NcSample(const NcSample& s) : TNamed(s)
176{
182
183 for (Int_t i=0; i<s.fMaxdim; i++)
184 {
185 fNames[i]=s.fNames[i];
186 }
187
188 fDim=s.fDim;
189 fStore=s.fStore;
190 fNmax=s.fNmax;
192 fN=s.fN;
194
195 fX=0;
196 fY=0;
197 fZ=0;
198 fT=0;
199 fArr=0;
200 fIndices=0;
201 fOrdered=0;
202 fGraphT=0;
203 fCanvas=0;
204 fAnimObject=0;
205
206 if (s.fX) fX=new TArrayD(fN);
207 if (s.fY) fY=new TArrayD(fN);
208 if (s.fZ) fZ=new TArrayD(fN);
209 if (s.fT) fT=new TArrayD(fN);
210
211 Double_t val=0;
212 for (Int_t i=0; i<fDim; i++)
213 {
214 fSum[i]=s.fSum[i];
215 fMean[i]=s.fMean[i];
216 fRMSdev[i]=s.fRMSdev[i];
217 fSigma[i]=s.fSigma[i];
218 fMin[i]=s.fMin[i];
219 fMax[i]=s.fMax[i];
220 for (Int_t j=0; j<fDim; j++)
221 {
222 fSum2[i][j]=s.fSum2[i][j];
223 fCov[i][j]=s.fCov[i][j];
224 fCor[i][j]=s.fCor[i][j];
225 }
226 }
227
228 if (!fStore) return;
229
230 for (Int_t i=0; i<fN; i++)
231 {
232 if (fX)
233 {
234 val=s.fX->At(i);
235 fX->AddAt(val,i);
236 }
237 if (fY)
238 {
239 val=s.fY->At(i);
240 fY->AddAt(val,i);
241 }
242 if (fZ)
243 {
244 val=s.fZ->At(i);
245 fZ->AddAt(val,i);
246 }
247 if (fT)
248 {
249 val=s.fT->At(i);
250 fT->AddAt(val,i);
251 }
252 }
253}
254
256{
264
265 fN=0;
266 fRemove=0;
267 fOrdered=0;
268 for (Int_t i=0; i<fDim; i++)
269 {
270 fSum[i]=0;
271 fMean[i]=0;
272 fRMSdev[i]=0;
273 fSigma[i]=0;
274 fMin[i]=0;
275 fMax[i]=0;
276 for (Int_t j=0; j<fDim; j++)
277 {
278 fSum2[i][j]=0;
279 fCov[i][j]=0;
280 fCor[i][j]=0;
281 }
282 }
283
284 // Set storage arrays to initial size
285 if (fStore)
286 {
287 if (fX) fX->Set(fStore);
288 if (fY) fY->Set(fStore);
289 if (fZ) fZ->Set(fStore);
290 if (fT) fT->Set(fStore);
291 }
292
293 // Resetting the variable names to their defaults
294 SetNames();
295
296 // Delete the temp. storage arrays for ordering
297 if (fArr)
298 {
299 delete fArr;
300 fArr=0;
301 }
302 if (fIndices)
303 {
304 delete fIndices;
305 fIndices=0;
306 }
307
308 // Delete the temp. TGraphTime pointer
309 if (fGraphT)
310 {
311 delete fGraphT;
312 fGraphT=0;
313 }
314
315 // Delete the multi-purpose canvas
316 if (fCanvas)
317 {
318 delete fCanvas;
319 fCanvas=0;
320 }
321
322 // Delete the multi-purpose animation object
323 if (fAnimObject)
324 {
325 delete fAnimObject;
326 fAnimObject=0;
327 }
328}
329
330void NcSample::SetNames(TString name1,TString name2,TString name3,TString name4)
331{
346
347 if (!fN)
348 {
349 fNames[0]=name1;
350 fNames[1]=name2;
351 fNames[2]=name3;
352 fNames[3]=name4;
353 }
354 else
355 {
356 cout << " *NcSample::SetNames* Names not modified, since data were already present." << endl;
357 }
358}
359
360void NcSample::Enter(Double_t x)
361{
368
369 if (!fN)
370 {
371 fDim=1;
372 fNames[1]="";
373 fNames[2]="";
374 fNames[3]="";
375 }
376
377 if (fDim != 1)
378 {
379 cout << " *NcSample::Enter* Error : Not a 1-dim sample." << endl;
380 return;
381 }
382
383 // Remove (after re-ordering) the first entry if needed
385
386 fN+=1;
387 fSum[0]+=x;
388 fSum2[0][0]+=x*x;
389
390 if (fN==1)
391 {
392 fMin[0]=x;
393 fMax[0]=x;
394 }
395 else
396 {
397 if (x<fMin[0]) fMin[0]=x;
398 if (x>fMax[0]) fMax[0]=x;
399 }
400
401 // Store all entered data when storage mode has been selected
402 if (fStore)
403 {
404 if (!fX) fX=new TArrayD(fStore);
405 if (fX->GetSize() < fN) fX->Set(2*fN);
406 fX->AddAt(x,fN-1);
407 }
408
409 // Compute the various statistics
410 Compute();
411}
412
413void NcSample::Remove(Double_t x)
414{
420
421 if (!fN) return;
422
423 if (fDim != 1)
424 {
425 cout << " *NcSample::Remove* Error : Not a 1-dim sample." << endl;
426 return;
427 }
428
429 fRemove=1;
430 fN-=1;
431 fSum[0]-=x;
432 fSum2[0][0]-=x*x;
433
434 // Remove data entry from the storage
435 if (fStore && fX)
436 {
437 Double_t val=0;
438 for (Int_t i=0; i<=fN; i++)
439 {
440 val=fX->At(i);
441 if (fabs(x-val)>1.e-10) continue;
442
443 for (Int_t j=i+1; j<=fN; j++)
444 {
445 val=fX->At(j);
446 fX->AddAt(val,j-1);
447 }
448 }
449 }
450
451 // Compute the various statistics
452 Compute();
453}
454
455void NcSample::Enter(Double_t x,Double_t y)
456{
463
464 if (!fN)
465 {
466 fDim=2;
467 fNames[2]="";
468 fNames[3]="";
469 }
470
471 if (fDim != 2)
472 {
473 cout << " *NcSample::Enter* Error : Not a 2-dim sample." << endl;
474 return;
475 }
476
477 // Remove (after re-ordering) the first entry if needed
479
480 fN+=1;
481 fSum[0]+=x;
482 fSum[1]+=y;
483 fSum2[0][0]+=x*x;
484 fSum2[0][1]+=x*y;
485 fSum2[1][0]+=y*x;
486 fSum2[1][1]+=y*y;
487
488 if (fN==1)
489 {
490 fMin[0]=x;
491 fMax[0]=x;
492 fMin[1]=y;
493 fMax[1]=y;
494 }
495 else
496 {
497 if (x<fMin[0]) fMin[0]=x;
498 if (x>fMax[0]) fMax[0]=x;
499 if (y<fMin[1]) fMin[1]=y;
500 if (y>fMax[1]) fMax[1]=y;
501 }
502
503 // Store all entered data when storage mode has been selected
504 if (fStore)
505 {
506 if (!fX) fX=new TArrayD(fStore);
507 if (fX->GetSize() < fN) fX->Set(2*fN);
508 fX->AddAt(x,fN-1);
509 if (!fY) fY=new TArrayD(fStore);
510 if (fY->GetSize() < fN) fY->Set(2*fN);
511 fY->AddAt(y,fN-1);
512 }
513
514 // Compute the various statistics
515 Compute();
516}
517
518void NcSample::Remove(Double_t x,Double_t y)
519{
525
526 if (!fN) return;
527
528 if (fDim != 2)
529 {
530 cout << " *NcSample::Remove* Error : Not a 2-dim sample." << endl;
531 return;
532 }
533
534 fRemove=1;
535 fN-=1;
536 fSum[0]-=x;
537 fSum[1]-=y;
538 fSum2[0][0]-=x*x;
539 fSum2[0][1]-=x*y;
540 fSum2[1][0]-=y*x;
541 fSum2[1][1]-=y*y;
542
543 // Remove data entry from the storage
544 if (fStore && fX && fY)
545 {
546 Double_t val=0;
547 for (Int_t i=0; i<=fN; i++)
548 {
549 val=fX->At(i);
550 if (fabs(x-val)>1.e-10) continue;
551 val=fY->At(i);
552 if (fabs(y-val)>1.e-10) continue;
553
554 for (Int_t j=i+1; j<=fN; j++)
555 {
556 val=fX->At(j);
557 fX->AddAt(val,j-1);
558 val=fY->At(j);
559 fY->AddAt(val,j-1);
560 }
561 }
562 }
563
564 // Compute the various statistics
565 Compute();
566}
567
568void NcSample::Enter(Double_t x,Double_t y,Double_t z)
569{
576
577 if (!fN)
578 {
579 fDim=3;
580 fNames[3]="";
581 }
582
583 if (fDim != 3)
584 {
585 cout << " *NcSample::Enter* Error : Not a 3-dim sample." << endl;
586 return;
587 }
588
589 // Remove (after re-ordering) the first entry if needed
591
592 fN+=1;
593 fSum[0]+=x;
594 fSum[1]+=y;
595 fSum[2]+=z;
596 fSum2[0][0]+=x*x;
597 fSum2[0][1]+=x*y;
598 fSum2[0][2]+=x*z;
599 fSum2[1][0]+=y*x;
600 fSum2[1][1]+=y*y;
601 fSum2[1][2]+=y*z;
602 fSum2[2][0]+=z*x;
603 fSum2[2][1]+=z*y;
604 fSum2[2][2]+=z*z;
605
606 if (fN==1)
607 {
608 fMin[0]=x;
609 fMax[0]=x;
610 fMin[1]=y;
611 fMax[1]=y;
612 fMin[2]=z;
613 fMax[2]=z;
614 }
615 else
616 {
617 if (x<fMin[0]) fMin[0]=x;
618 if (x>fMax[0]) fMax[0]=x;
619 if (y<fMin[1]) fMin[1]=y;
620 if (y>fMax[1]) fMax[1]=y;
621 if (z<fMin[2]) fMin[2]=z;
622 if (z>fMax[2]) fMax[2]=z;
623 }
624
625 // Store all entered data when storage mode has been selected
626 if (fStore)
627 {
628 if (!fX) fX=new TArrayD(fStore);
629 if (fX->GetSize() < fN) fX->Set(2*fN);
630 fX->AddAt(x,fN-1);
631 if (!fY) fY=new TArrayD(fStore);
632 if (fY->GetSize() < fN) fY->Set(2*fN);
633 fY->AddAt(y,fN-1);
634 if (!fZ) fZ=new TArrayD(fStore);
635 if (fZ->GetSize() < fN) fZ->Set(2*fN);
636 fZ->AddAt(z,fN-1);
637 }
638
639 // Compute the various statistics
640 Compute();
641}
642
643void NcSample::Remove(Double_t x,Double_t y,Double_t z)
644{
650
651 if (!fN) return;
652
653 if (fDim != 3)
654 {
655 cout << " *NcSample::Remove* Error : Not a 3-dim sample." << endl;
656 return;
657 }
658
659 fRemove=1;
660 fN-=1;
661 fSum[0]-=x;
662 fSum[1]-=y;
663 fSum[2]-=z;
664 fSum2[0][0]-=x*x;
665 fSum2[0][1]-=x*y;
666 fSum2[0][2]-=x*z;
667 fSum2[1][0]-=y*x;
668 fSum2[1][1]-=y*y;
669 fSum2[1][2]-=y*z;
670 fSum2[2][0]-=z*x;
671 fSum2[2][1]-=z*y;
672 fSum2[2][2]-=z*z;
673
674 // Remove data entry from the storage
675 if (fStore && fX && fY && fZ)
676 {
677 Double_t val=0;
678 for (Int_t i=0; i<=fN; i++)
679 {
680 val=fX->At(i);
681 if (fabs(x-val)>1.e-10) continue;
682 val=fY->At(i);
683 if (fabs(y-val)>1.e-10) continue;
684 val=fZ->At(i);
685 if (fabs(z-val)>1.e-10) continue;
686
687 for (Int_t j=i+1; j<=fN; j++)
688 {
689 val=fX->At(j);
690 fX->AddAt(val,j-1);
691 val=fY->At(j);
692 fY->AddAt(val,j-1);
693 val=fZ->At(j);
694 fZ->AddAt(val,j-1);
695 }
696 }
697 }
698
699 // Compute the various statistics
700 Compute();
701}
702
703void NcSample::Enter(Double_t x,Double_t y,Double_t z,Double_t t)
704{
711
712 if (!fN) fDim=4;
713
714 if (fDim != 4)
715 {
716 cout << " *NcSample::Enter* Error : Not a 4-dim sample." << endl;
717 return;
718 }
719
720 // Remove (after re-ordering) the first entry if needed
722
723 fN+=1;
724 fSum[0]+=x;
725 fSum[1]+=y;
726 fSum[2]+=z;
727 fSum[3]+=t;
728 fSum2[0][0]+=x*x;
729 fSum2[0][1]+=x*y;
730 fSum2[0][2]+=x*z;
731 fSum2[0][3]+=x*t;
732 fSum2[1][0]+=y*x;
733 fSum2[1][1]+=y*y;
734 fSum2[1][2]+=y*z;
735 fSum2[1][3]+=y*t;
736 fSum2[2][0]+=z*x;
737 fSum2[2][1]+=z*y;
738 fSum2[2][2]+=z*z;
739 fSum2[2][3]+=z*t;
740 fSum2[3][0]+=t*x;
741 fSum2[3][1]+=t*y;
742 fSum2[3][2]+=t*z;
743 fSum2[3][3]+=t*t;
744
745 if (fN==1)
746 {
747 fMin[0]=x;
748 fMax[0]=x;
749 fMin[1]=y;
750 fMax[1]=y;
751 fMin[2]=z;
752 fMax[2]=z;
753 fMin[3]=t;
754 fMax[3]=t;
755 }
756 else
757 {
758 if (x<fMin[0]) fMin[0]=x;
759 if (x>fMax[0]) fMax[0]=x;
760 if (y<fMin[1]) fMin[1]=y;
761 if (y>fMax[1]) fMax[1]=y;
762 if (z<fMin[2]) fMin[2]=z;
763 if (z>fMax[2]) fMax[2]=z;
764 if (t<fMin[3]) fMin[3]=t;
765 if (t>fMax[3]) fMax[3]=t;
766 }
767
768 // Store all entered data when storage mode has been selected
769 if (fStore)
770 {
771 if (!fX) fX=new TArrayD(fStore);
772 if (fX->GetSize() < fN) fX->Set(2*fN);
773 fX->AddAt(x,fN-1);
774 if (!fY) fY=new TArrayD(fStore);
775 if (fY->GetSize() < fN) fY->Set(2*fN);
776 fY->AddAt(y,fN-1);
777 if (!fZ) fZ=new TArrayD(fStore);
778 if (fZ->GetSize() < fN) fZ->Set(2*fN);
779 fZ->AddAt(z,fN-1);
780 if (!fT) fT=new TArrayD(fStore);
781 if (fT->GetSize() < fN) fT->Set(2*fN);
782 fT->AddAt(t,fN-1);
783 }
784
785 // Compute the various statistics
786 Compute();
787}
788
789void NcSample::Remove(Double_t x,Double_t y,Double_t z,Double_t t)
790{
796
797 if (!fN) return;
798
799 if (fDim != 4)
800 {
801 cout << " *NcSample::Remove* Error : Not a 4-dim sample." << endl;
802 return;
803 }
804
805 fRemove=1;
806 fN-=1;
807 fSum[0]-=x;
808 fSum[1]-=y;
809 fSum[2]-=z;
810 fSum[3]-=t;
811 fSum2[0][0]-=x*x;
812 fSum2[0][1]-=x*y;
813 fSum2[0][2]-=x*z;
814 fSum2[0][3]-=x*t;
815 fSum2[1][0]-=y*x;
816 fSum2[1][1]-=y*y;
817 fSum2[1][2]-=y*z;
818 fSum2[1][3]-=y*t;
819 fSum2[2][0]-=z*x;
820 fSum2[2][1]-=z*y;
821 fSum2[2][2]-=z*z;
822 fSum2[2][3]-=z*t;
823 fSum2[3][0]-=t*x;
824 fSum2[3][1]-=t*y;
825 fSum2[3][2]-=t*z;
826 fSum2[3][3]-=t*t;
827
828 // Remove data entry from the storage
829 if (fStore && fX && fY && fZ && fT)
830 {
831 Double_t val=0;
832 for (Int_t i=0; i<=fN; i++)
833 {
834 val=fX->At(i);
835 if (fabs(x-val)>1.e-10) continue;
836 val=fY->At(i);
837 if (fabs(y-val)>1.e-10) continue;
838 val=fZ->At(i);
839 if (fabs(z-val)>1.e-10) continue;
840 val=fT->At(i);
841 if (fabs(t-val)>1.e-10) continue;
842
843 for (Int_t j=i+1; j<=fN; j++)
844 {
845 val=fX->At(j);
846 fX->AddAt(val,j-1);
847 val=fY->At(j);
848 fY->AddAt(val,j-1);
849 val=fZ->At(j);
850 fZ->AddAt(val,j-1);
851 val=fT->At(j);
852 fT->AddAt(val,j-1);
853 }
854 }
855 }
856
857 // Compute the various statistics
858 Compute();
859}
860
861void NcSample::RemoveEntry(Int_t i,Int_t mode,Int_t j)
862{
884
885 if (fDim<1 || fN<=0 || i<1 || i>fN) return;
886
887 if (mode && (j<1 || j>fDim))
888 {
889 cout << " *NcSample::RemoveEntry* Error : Invalide argument j=" << j << endl;
890 return;
891 }
892
893 if (!fStore)
894 {
895 cout << " *NcSample::RemoveEntry* Error : Storage of data entries was not activated." << endl;
896 return;
897 }
898
899 Order(mode,j);
900
901 // Get the corresponding original entry index
902 Int_t idx=fIndices->At(i-1);
903
904 Double_t x=0;
905 Double_t y=0;
906 Double_t z=0;
907 Double_t t=0;
908
909 if (fX) x=GetEntry(idx+1,1);
910 if (fY) y=GetEntry(idx+1,2);
911 if (fZ) z=GetEntry(idx+1,3);
912 if (fT) t=GetEntry(idx+1,4);
913
914 if (fDim==1) Remove(x);
915 if (fDim==2) Remove(x,y);
916 if (fDim==3) Remove(x,y,z);
917 if (fDim==4) Remove(x,y,z,t);
918}
919
920void NcSample::RemoveEntry(Int_t i,Int_t mode,TString name)
921{
943
944 Int_t j=GetIndex(name);
945 RemoveEntry(i,mode,j);
946}
947
948void NcSample::RemoveEntry(Int_t i,Int_t j,Int_t mode,Int_t k)
949{
964
965 for (Int_t m=i; m<=j; m++)
966 {
967 RemoveEntry(i,mode,k);
968 }
969}
970
971void NcSample::RemoveEntry(Int_t i,Int_t j,Int_t mode,TString name)
972{
987
988 for (Int_t m=i; m<=j; m++)
989 {
990 RemoveEntry(i,mode,name);
991 }
992}
993
994void NcSample::Order(Int_t mode,Int_t i)
995{
1010
1011 if (mode && (i<1 || i>fDim))
1012 {
1013 cout << " *NcSample::Order* Error : Invalide argument i=" << i << endl;
1014 return;
1015 }
1016
1017 if (fDim<1)
1018 {
1019 cout << " *NcSample::Order* Error : Dimension less than 1." << endl;
1020 return;
1021 }
1022
1023 if (!fStore)
1024 {
1025 cout << " *NcSample::Order* Error : Storage of data entries was not activated." << endl;
1026 return;
1027 }
1028
1029 if (fN<=0)
1030 {
1031 fOrdered=0;
1032 return;
1033 }
1034
1035 // Use i=1 for mode=0 to obtain a correct setting of the ordering status word.
1036 if (!mode) i=1;
1037
1038 // Set the corresponding ordering status word
1039 Int_t iword=10*abs(mode)+i;
1040 if (mode<0) iword*=-1;
1041
1042 // No new ordering needed if the ordering status word hasn't changed
1043 if (iword==fOrdered) return;
1044
1045 // Store the new ordering status word
1046 fOrdered=iword;
1047
1048 // Prepare temp. array to hold the ordered values
1049 if (!fArr)
1050 {
1051 fArr=new TArrayD(fN);
1052 }
1053 else
1054 {
1055 if (fArr->GetSize() < fN) fArr->Set(fN);
1056 }
1057
1058 // Prepare temp. array to hold the ordered indices
1059 if (!fIndices)
1060 {
1061 fIndices=new TArrayI(fN);
1062 }
1063 else
1064 {
1065 if (fIndices->GetSize() < fN) fIndices->Set(fN);
1066 }
1067
1068 Double_t val=0;
1069
1070 // Just the order in which the entries were entered
1071 if (!mode)
1072 {
1073 for (Int_t j=0; j<fN; j++)
1074 {
1075 if (i==1) val=fX->At(j);
1076 if (i==2) val=fY->At(j);
1077 if (i==3) val=fZ->At(j);
1078 if (i==4) val=fT->At(j);
1079 fArr->AddAt(val,j);
1080 fIndices->AddAt(j,j);
1081 }
1082 return;
1083 }
1084
1085 // Order the values of the specified variable
1086 Int_t iadd=0;
1087 for (Int_t j=0; j<fN; j++)
1088 {
1089 if (i==1) val=fX->At(j);
1090 if (i==2) val=fY->At(j);
1091 if (i==3) val=fZ->At(j);
1092 if (i==4) val=fT->At(j);
1093
1094 iadd=0;
1095 if (j==0)
1096 {
1097 fArr->AddAt(val,j);
1098 fIndices->AddAt(j,j);
1099 iadd=1;
1100 }
1101 else
1102 {
1103 for (Int_t k=0; k<j; k++)
1104 {
1105 if (mode>0 && val>=fArr->At(k)) continue; // Increasing ordering
1106 if (mode<0 && val<=fArr->At(k)) continue; // Decreasing ordering
1107 // Put value in between the existing ones
1108 for (Int_t m=j-1; m>=k; m--)
1109 {
1110 fArr->AddAt(fArr->At(m),m+1);
1111 fIndices->AddAt(fIndices->At(m),m+1);
1112 }
1113 fArr->AddAt(val,k);
1114 fIndices->AddAt(j,k);
1115 iadd=1;
1116 break;
1117 }
1118
1119 if (!iadd)
1120 {
1121 fArr->AddAt(val,j);
1122 fIndices->AddAt(j,j);
1123 }
1124 }
1125 }
1126}
1127
1128Int_t NcSample::GetIndex(TString name) const
1129{
1136
1137 Int_t idx=0;
1138
1139 for (Int_t i=0; i<fMaxdim; i++)
1140 {
1141 if (fNames[i]==name) idx=i+1;
1142 }
1143
1144 return idx;
1145}
1146
1148{
1155
1156 // Reset the ordering status word
1157 fOrdered=0;
1158
1159 if (fN<=0) return;
1160
1161 Double_t rn=fN;
1162 Double_t rn1=fN-1;
1163 Double_t var=0;
1164 Double_t rmsij;
1165 for (Int_t k=0; k<fDim; k++)
1166 {
1167 fMean[k]=fSum[k]/rn;
1168 var=(fSum2[k][k]/rn)-(fMean[k]*fMean[k]);
1169 if (var<0) var=0;
1170 fRMSdev[k]=sqrt(var);
1171 var=0;
1172 if (rn1)
1173 {
1174 var=(fSum2[k][k]-(rn*fMean[k]*fMean[k]))/rn1;
1175 if (var<0) var=0;
1176 }
1177 fSigma[k]=sqrt(var);
1178 }
1179 for (Int_t i=0; i<fDim; i++)
1180 {
1181 for (Int_t j=0; j<fDim; j++)
1182 {
1183 fCov[i][j]=(fSum2[i][j]/rn)-(fMean[i]*fMean[j]);
1184 fCor[i][j]=0;
1185 rmsij=fRMSdev[i]*fRMSdev[j];
1186 if (rmsij != 0) fCor[i][j]=fCov[i][j]/rmsij;
1187 }
1188 }
1189}
1190
1192{
1198
1199 return fDim;
1200}
1201
1202Int_t NcSample::GetN() const
1203{
1209
1210 return fN;
1211}
1212
1213TString NcSample::GetVariableName(Int_t i) const
1214{
1220
1221 TString name="";
1222
1223 if (i<1 || i>fDim)
1224 {
1225 cout << " *NcSample::GetVariableName* Error : Invalid index " << i << endl;
1226 }
1227 else
1228 {
1229 name=fNames[i-1];
1230 }
1231
1232 return name;
1233}
1234
1235Double_t NcSample::GetSum(Int_t i) const
1236{
1242
1243 if (i<1 || i>fDim)
1244 {
1245 cout << " *NcSample::GetSum* Error : Invalid index " << i << endl;
1246 return 0;
1247 }
1248 else
1249 {
1250 return fSum[i-1];
1251 }
1252}
1253
1254Double_t NcSample::GetSum(TString name) const
1255{
1261
1262 Int_t i=GetIndex(name);
1263 return GetSum(i);
1264}
1265
1266Double_t NcSample::GetMean(Int_t i) const
1267{
1273
1274 if (i<1 || i>fDim)
1275 {
1276 cout << " *NcSample::GetMean* Error : Invalid index " << i << endl;
1277 return 0;
1278 }
1279
1280 return fMean[i-1];
1281}
1282
1283Double_t NcSample::GetMean(TString name) const
1284{
1290
1291 Int_t i=GetIndex(name);
1292 return GetMean(i);
1293}
1294
1295Double_t NcSample::GetRMS(Int_t i) const
1296{
1307
1308 if (i<1 || i>fDim)
1309 {
1310 cout << " *NcSample::GetRMS* Error : Invalid index " << i << endl;
1311 return 0;
1312 }
1313
1314 Double_t rms=0;
1315 Double_t val=fSum2[i-1][i-1]/float(fN);
1316 if (val>=0) rms=sqrt(val);
1317
1318 return rms;
1319}
1320
1321Double_t NcSample::GetRMS(TString name) const
1322{
1333
1334 Int_t i=GetIndex(name);
1335 return GetRMS(i);
1336}
1337
1338Double_t NcSample::GetVar(Int_t i,Int_t model) const
1339{
1348
1349 if (i<1 || i>fDim)
1350 {
1351 cout << " *NcSample::GetVar* Error : Invalid index " << i << endl;
1352 return 0;
1353 }
1354
1355 Double_t var=fRMSdev[i-1]*fRMSdev[i-1];
1356 if (model) var=fSigma[i-1]*fSigma[i-1];
1357
1358 return var;
1359}
1360
1361Double_t NcSample::GetVar(TString name,Int_t model) const
1362{
1371
1372 Int_t i=GetIndex(name);
1373 return GetVar(i);
1374}
1375
1376Double_t NcSample::GetSigma(Int_t i,Int_t model) const
1377{
1387
1388 if (i<1 || i>fDim)
1389 {
1390 cout << " *NcSample::GetSigma* Error : Invalid index " << i << endl;
1391 return 0;
1392 }
1393
1394 Double_t val=fRMSdev[i-1];
1395 if (model) val=fSigma[i-1];
1396
1397 return val;
1398}
1399
1400Double_t NcSample::GetSigma(TString name,Int_t model) const
1401{
1410
1411 Int_t i=GetIndex(name);
1412 return GetSigma(i,model);
1413}
1414
1415Double_t NcSample::GetCov(Int_t i,Int_t j) const
1416{
1423
1424 if (i<1 || i>fDim || j<1 || j>fDim)
1425 {
1426 cout << " *NcSample::GetCov* Error : Invalid index encountered i=" << i << " j=" << j << endl;
1427 return 0;
1428 }
1429
1430 return fCov[i-1][j-1];
1431}
1432
1433Double_t NcSample::GetCov(TString nameA, TString nameB) const
1434{
1440
1441 Int_t i=GetIndex(nameA);
1442 Int_t j=GetIndex(nameB);
1443 return GetCov(i,j);
1444}
1445
1446Double_t NcSample::GetCor(Int_t i,Int_t j) const
1447{
1454
1455 if (i<1 || i>fDim || j<1 || j>fDim)
1456 {
1457 cout << " *NcSample::GetCor* Error : Invalid index encountered i=" << i << " j=" << j << endl;
1458 return 0;
1459 }
1460
1461 return fCor[i-1][j-1];
1462}
1463
1464Double_t NcSample::GetCor(TString nameA, TString nameB) const
1465{
1471
1472 Int_t i=GetIndex(nameA);
1473 Int_t j=GetIndex(nameB);
1474 return GetCor(i,j);
1475}
1476
1477void NcSample::Data(Int_t i,Int_t j)
1478{
1494
1495 const char* name=GetName();
1496 const char* title=GetTitle();
1497
1498 cout << " *" << ClassName() << "::Data*";
1499 if (strlen(name)) cout << " Info for sample Name : " << name;
1500 if (strlen(title)) cout << " Title : " << title;
1501 cout << endl;
1502 cout << " Access to the individual data entries is";
1503 if (!fStore) cout << " not";
1504 cout << " possible (StoreMode=" << fStore << ")" << endl;
1505
1506 if (fStore && fNmax)
1507 {
1508 if (fNmax==fN && fRemove)
1509 {
1510 cout << " *** At entering data the dynamic FIFO storage was limited to " << fNmax << " entries";
1511 }
1512 else
1513 {
1514 cout << " *** At entering new data the dynamic FIFO storage will be limited to " << fNmax << " entries";
1515 }
1516 if (!fMoveVariable) cout << " using the order of original entering.";
1517 if (fMoveVariable>0) cout << " after increasing";
1518 if (fMoveVariable<0) cout << " after decreasing";
1519 if (fMoveVariable) cout << " ordering w.r.t. variable " << abs(fMoveVariable);
1520 cout << endl;
1521 }
1522
1523 if (i<0 || i>fDim || j<0 || j>fDim)
1524 {
1525 cout << " Inconsistent input i=" << i << " and j=" << j << " for dimension " << fDim << endl;
1526 return;
1527 }
1528 if (!i && !j) cout << " Statistics and correlations of all variables";
1529 if (i && !j) cout << " Statistics of variable " << i;
1530 if (!i && j) cout << " Statistics of variable " << j;
1531 if (i && j) cout << " Correlation statistics of the variables " << i << " and " << j;
1532 cout << endl;
1533
1534 if (!fN)
1535 {
1536 cout << " No data has been entered." << endl;
1537 return;
1538 }
1539
1540 // Statistics and correlations of all variables
1541 if (!i && !j)
1542 {
1543 // Statistics of individual variables
1544 for (Int_t iv=1; iv<=fDim; iv++)
1545 {
1546 List(iv);
1547 }
1548
1549 if (fDim<2) return;
1550
1551 // Covariance(s) and correlation coefficient(s)
1552 for (Int_t iv=1; iv<=fDim; iv++)
1553 {
1554 for (Int_t jv=iv+1;jv<=fDim; jv++)
1555 {
1556 List(iv,jv);
1557 }
1558 }
1559 }
1560
1561 // Statistics of the i-th variable
1562 if (i && !j) List(i);
1563
1564 // Statistics of the j-th variable
1565 if (!i && j) List(j);
1566
1567 // Correlation statistics of the variables i and j
1568 if (i && j) List(i,j);
1569}
1570
1571void NcSample::Data(TString nameA,TString nameB)
1572{
1598
1599 Int_t i=GetIndex(nameA);
1600 Int_t j=GetIndex(nameB);
1601 Data(i,j);
1602}
1603
1604void NcSample::ListOrdered(Int_t mode,Int_t i)
1605{
1620
1621 if (!fStore)
1622 {
1623 cout << " *NcSample::ListOrdered* Error : Storage of data entries was not activated." << endl;
1624 return;
1625 }
1626
1627 if (fN<=0)
1628 {
1629 cout << " *NcSample::ListOrdered* No entries were stored." << endl;
1630 return;
1631 }
1632
1633 if (fDim<1)
1634 {
1635 cout << " *NcSample::ListOrdered* Error : Dimension less than 1." << endl;
1636 return;
1637 }
1638
1639 if (mode && (i<1 || i>fDim))
1640 {
1641 cout << " *NcSample::ListOrdered* Error : Invalid argument i=" << i << endl;
1642 return;
1643 }
1644
1645 Order(mode,i);
1646
1647 const char* name=GetName();
1648 const char* title=GetTitle();
1649
1650 cout << " *NcSample::ListOrdered* Ordered listing for the sample";
1651 if (strlen(name)) cout << " Name : " << name;
1652 if (strlen(title)) cout << " Title : " << title;
1653 cout << endl;
1654 if (fNmax==fN && fRemove)
1655 {
1656 cout << " *** At entering data the dynamic FIFO storage was limited to " << fNmax << " entries";
1657 if (!fMoveVariable) cout << " using the order of original entering.";
1658 if (fMoveVariable>0) cout << " after increasing";
1659 if (fMoveVariable<0) cout << " after decreasing";
1660 if (fMoveVariable) cout << " ordering w.r.t. variable " << abs(fMoveVariable);
1661 cout << endl;
1662 }
1663 cout << " Listing of the stored entries in";
1664 if (!mode) cout << " order of original entering." << endl;
1665 if (mode<0) cout << " decreasing order of variable : " << i << " (" << fNames[i-1] << ")" << endl;
1666 if (mode>0) cout << " increasing order of variable : " << i << " (" << fNames[i-1] << ")" << endl;
1667 if (mode) cout << " The number between brackets indicates the original data entry number." << endl;
1668
1669 Int_t index=0;
1670 for (Int_t j=0; j<fN; j++)
1671 {
1672 index=fIndices->At(j);
1673
1674 if (index<0 || index>=fN) continue;
1675
1676 cout << " Index : " << (j+1);
1677 if (mode) cout << " (" << (index+1) << ") ";
1678 cout << " " << fNames[0] << "=" << fX->At(index);
1679 if (fDim>1) cout << " " << fNames[1] << "=" << fY->At(index);
1680 if (fDim>2) cout << " " << fNames[2] << "=" << fZ->At(index);
1681 if (fDim>3) cout << " " << fNames[3] << "=" << fT->At(index);
1682 cout << endl;
1683 }
1684}
1685
1686void NcSample::ListOrdered(Int_t mode,TString name)
1687{
1702
1703 Int_t i=GetIndex(name);
1704 ListOrdered(mode,i);
1705}
1706
1707void NcSample::List(Int_t i)
1708{
1715
1716 if (i<1 || i>fDim)
1717 {
1718 cout << " *NcSample::List(i)* Error : Invalid index " << i << endl;
1719 }
1720 else
1721 {
1722 cout << " Variable " << fNames[i-1] << " : N=" << fN;
1723 cout << " Sum=" << fSum[i-1] << " Mean=" << fMean[i-1];
1724 cout << " Deviation(rms)=" << fRMSdev[i-1] << " Sigma=" << fSigma[i-1];
1725 if (!fRemove || fStore)
1726 {
1727 cout << endl;
1728 cout << " Minimum=" << GetMinimum(i) << " Maximum=" << GetMaximum(i);
1729 }
1730 if (fStore)
1731 {
1732 cout << " Median=" << GetMedian(i);
1733 cout << " Spread(w.r.t. median)=" << GetSpread(i,0) << " Spread(w.r.t. mean)=" << GetSpread(i,1);
1734 }
1735 cout << endl;
1736 }
1737}
1738
1739void NcSample::List(Int_t i,Int_t j) const
1740{
1747
1748 if (i<1 || i>fDim || j<1 || j>fDim)
1749 {
1750 cout << " *NcSample::List(i,j)* Error : Invalid index encountered i=" << i << " j=" << j << endl;
1751 }
1752 else
1753 {
1754 cout << " " << fNames[i-1] << "-" << fNames[j-1];
1755 cout << " Correlation(coefficient)=" << fCor[i-1][j-1] << " Covariance=" << fCov[i-1][j-1] << endl;
1756 }
1757}
1758
1759void NcSample::SetStoreMode(Int_t mode,Int_t nmax,Int_t i)
1760{
1799
1800 if (fN)
1801 {
1802 cout << " Storage mode can only be set before first data." << endl;
1803 }
1804 else if ((!mode && nmax) || mode<0 || nmax<0 || abs(i)>fDim)
1805 {
1806 cout << " Inconsistent input : mode=" << mode << " nmax=" << nmax << " i=" << i << endl;
1807 fNmax=0;
1808 fMoveVariable=0;
1809 }
1810 else
1811 {
1812 if (mode==1) mode=100; // Backward compatibility
1813 fStore=mode;
1814 fNmax=nmax;
1815 fMoveVariable=i;
1816
1817 if (fStore) // Set storage arrays to the requested size
1818 {
1819 if (fX) fX->Set(fStore);
1820 if (fY) fY->Set(fStore);
1821 if (fZ) fZ->Set(fStore);
1822 if (fT) fT->Set(fStore);
1823 }
1824 else // Delete the storage arrays
1825 {
1826 if (fX)
1827 {
1828 delete fX;
1829 fX=0;
1830 }
1831 if (fY)
1832 {
1833 delete fY;
1834 fY=0;
1835 }
1836 if (fZ)
1837 {
1838 delete fZ;
1839 fZ=0;
1840 }
1841 if (fT)
1842 {
1843 delete fT;
1844 fT=0;
1845 }
1846 }
1847 }
1848}
1849
1851{
1857
1858 return fStore;
1859}
1860
1862{
1868
1869 return fNmax;
1870}
1871
1872Double_t NcSample::GetQuantile(Double_t f,Int_t i)
1873{
1890
1891 if (i<1 || i>fDim)
1892 {
1893 cout << " *NcSample::GetQuantile* Error : Invalid index " << i << endl;
1894 return 0;
1895 }
1896
1897 if (!fStore)
1898 {
1899 cout << " *NcSample::GetQuantile* Error : Storage of data entries was not activated." << endl;
1900 return 0;
1901 }
1902
1903 if (fN<=0) return 0;
1904
1905 if (f<0 || f>1) return 0;
1906
1907 Double_t quantile=0;
1908
1909 if (fN==1)
1910 {
1911 if (i==1) quantile=fX->At(0);
1912 if (i==2) quantile=fY->At(0);
1913 if (i==3) quantile=fZ->At(0);
1914 if (i==4) quantile=fT->At(0);
1915 return quantile;
1916 }
1917
1918 if (f==0) return GetMinimum(i);
1919 if (f==1) return GetMaximum(i);
1920
1921 // Order the values of the i-th variable in increasing order
1922 Order(1,i);
1923
1924 quantile=0;
1925 Double_t rindex=double(fN)*f;
1926 Int_t index=int(rindex);
1927 if (fN%2) // Odd number of entries
1928 {
1929 quantile=fArr->At(index);
1930 }
1931 else // Even number of entries
1932 {
1933 quantile=(fArr->At(index-1)+fArr->At(index))/2.;
1934 }
1935 return quantile;
1936}
1937
1938Double_t NcSample::GetQuantile(Double_t f,TString name)
1939{
1956
1957 Int_t i=GetIndex(name);
1958 return GetQuantile(f,i);
1959}
1960
1961Double_t NcSample::GetMedian(Int_t i)
1962{
1979
1980 Double_t median=GetQuantile(0.5,i);
1981 return median;
1982}
1983
1984Double_t NcSample::GetMedian(TString name)
1985{
2002
2003 Double_t median=GetQuantile(0.5,name);
2004 return median;
2005}
2006
2007Double_t NcSample::GetSpread(Int_t i,Int_t model,Double_t vref)
2008{
2028
2029 if (model<0 || model>2)
2030 {
2031 cout << " *NcSample::GetSpread* Error : Unsupported parameter model=" << model << endl;
2032 return -1;
2033 }
2034
2035 if (i<1 || i>fDim)
2036 {
2037 cout << " *NcSample::GetSpread* Error : Invalid index " << i << endl;
2038 return -1;
2039 }
2040
2041 if (!fStore)
2042 {
2043 cout << " *NcSample::GetSpread* Error : Storage of data entries was not activated." << endl;
2044 return -1;
2045 }
2046
2047 if (fN<=1) return -1;
2048
2049 Double_t central=GetMedian(i);
2050 if (model==1) central=GetMean(i);
2051 if (model==2) central=vref;
2052
2053 Double_t spread=0;
2054 for (Int_t j=0; j<fN; j++)
2055 {
2056 spread+=fabs(central-(fArr->At(j)));
2057 }
2058
2059 spread=spread/float(fN);
2060
2061 return spread;
2062}
2063
2064Double_t NcSample::GetSpread(TString name,Int_t model,Double_t vref)
2065{
2085
2086 Int_t i=GetIndex(name);
2087 return GetSpread(i,model,vref);
2088}
2089
2090Double_t NcSample::GetMinimum(Int_t i) const
2091{
2099
2100 if (i<1 || i>fDim)
2101 {
2102 cout << " *NcSample::GetMinimum* Error : Invalid index " << i << endl;
2103 return 0;
2104 }
2105
2106 if (!fRemove) return fMin[i-1];
2107
2108 if (!fStore)
2109 {
2110 cout << " *NcSample::GetMinimum* Error : Storage of data entries was not activated." << endl;
2111 return 0;
2112 }
2113
2114 if (fN<=0) return 0;
2115
2116 Double_t min=0;
2117
2118 if (i==1) min=fX->At(0);
2119 if (i==2) min=fY->At(0);
2120 if (i==3) min=fZ->At(0);
2121
2122 for (Int_t k=1; k<fN; k++)
2123 {
2124 if (i==1 && fX->At(k)<min) min=fX->At(k);
2125 if (i==2 && fY->At(k)<min) min=fY->At(k);
2126 if (i==3 && fZ->At(k)<min) min=fZ->At(k);
2127 }
2128
2129 return min;
2130}
2131
2132Double_t NcSample::GetMinimum(TString name) const
2133{
2141
2142 Int_t i=GetIndex(name);
2143 return GetMinimum(i);
2144}
2145
2146Double_t NcSample::GetMaximum(Int_t i) const
2147{
2155
2156 if (i<1 || i>fDim)
2157 {
2158 cout << " *NcSample::GetMaximum* Error : Invalid index " << i << endl;
2159 return 0;
2160 }
2161
2162 if (!fRemove) return fMax[i-1];
2163
2164 if (!fStore)
2165 {
2166 cout << " *NcSample::GetMaximum* Error : Storage of data entries was not activated." << endl;
2167 return 0;
2168 }
2169
2170 if (fN<=0) return 0;
2171
2172 Double_t max=0;
2173
2174 if (i==1) max=fX->At(0);
2175 if (i==2) max=fY->At(0);
2176 if (i==3) max=fZ->At(0);
2177
2178 for (Int_t k=1; k<fN; k++)
2179 {
2180 if (i==1 && fX->At(k)>max) max=fX->At(k);
2181 if (i==2 && fY->At(k)>max) max=fY->At(k);
2182 if (i==3 && fZ->At(k)>max) max=fZ->At(k);
2183 }
2184
2185 return max;
2186}
2187
2188Double_t NcSample::GetMaximum(TString name) const
2189{
2197
2198 Int_t i=GetIndex(name);
2199 return GetMaximum(i);
2200}
2201
2202Double_t NcSample::GetQuantile(Double_t f,TH1* histo,Int_t mode) const
2203{
2226
2227 if (!histo) return 0;
2228
2229 if (f<0 || f>1) return 0;
2230
2231 Double_t xlow=0;
2232 Double_t xup=0;
2233 Double_t quantile=0;
2234
2235 if (mode==2) // Quantile of Y values
2236 {
2237 NcSample temp;
2238 temp.SetStoreMode(1);
2239 Double_t val=0;
2240 for (Int_t i=1; i<=histo->GetNbinsX(); i++)
2241 {
2242 val=histo->GetBinContent(i);
2243 temp.Enter(val);
2244 }
2245 quantile=temp.GetQuantile(f,1);
2246 }
2247 else // Quantile of X values
2248 {
2249 // Take the average of two quantiles closely around f
2250 // This will enhance the precision for low statistics
2251 Double_t q[2];
2252 Double_t p[2];
2253 p[0]=f-0.01;
2254 p[1]=f+0.01;
2255 if (p[0]<0) p[0]=0;
2256 if (p[0]>1) p[0]=1;
2257 histo->ComputeIntegral();
2258 Int_t nq=histo->GetQuantiles(2,q,p);
2259
2260 if (!nq) return 0;
2261
2262 xlow=q[0];
2263 xup=q[1];
2264 if (mode==1)
2265 {
2266 Int_t mbin=histo->FindBin(q[0]);
2267 xlow=histo->GetBinCenter(mbin);
2268 mbin=histo->FindBin(q[1]);
2269 xup=histo->GetBinCenter(mbin);
2270 }
2271 }
2272
2273 quantile=(xlow+xup)/2.;
2274
2275 return quantile;
2276}
2277
2278Double_t NcSample::GetMedian(TH1* histo,Int_t mode) const
2279{
2292
2293 Double_t median=GetQuantile(0.5,histo,mode);
2294 return median;
2295}
2296
2297Double_t NcSample::GetSpread(TH1* histo,Int_t mode,Int_t model,Double_t vref) const
2298{
2325
2326 if (model<0 || model>2)
2327 {
2328 cout << " *NcSample::GetSpread* Error : Unsupported parameter model=" << model << endl;
2329 return -1;
2330 }
2331
2332 if (!histo) return -1;
2333
2334 Int_t nbins=histo->GetNbinsX();
2335
2336 if (nbins<1) return -1;
2337
2338 Double_t spread=0;
2339
2340 if (mode==2) // Spread in Y values
2341 {
2342 NcSample temp;
2343 temp.SetStoreMode(1);
2344 Double_t val=0;
2345 for (Int_t i=1; i<=nbins; i++)
2346 {
2347 val=histo->GetBinContent(i);
2348 temp.Enter(val);
2349 }
2350 spread=temp.GetSpread(1,model,vref);
2351 }
2352 else // Spread in X values
2353 {
2354 Double_t central=GetMedian(histo,mode);
2355 if (model==1) central=histo->GetMean();
2356 if (model==2) central=vref;
2357 Double_t x=0;
2358 Double_t y=0;
2359 Double_t ysum=0;
2360 for (Int_t jbin=1; jbin<=nbins; jbin++)
2361 {
2362 x=histo->GetBinCenter(jbin);
2363 y=histo->GetBinContent(jbin);
2364 if (y>0)
2365 {
2366 spread+=fabs(x-central)*y;
2367 ysum+=y;
2368 }
2369 }
2370 if (ysum>0) spread=spread/ysum;
2371 }
2372
2373 return spread;
2374}
2375
2376Double_t NcSample::GetEntry(Int_t i,Int_t j,Int_t mode,Int_t k)
2377{
2395
2396 TString name=GetName();
2397
2398 if (!fStore)
2399 {
2400 cout << " *NcSample::GetEntry* Error : Storage mode not activated." << endl;
2401 return 0;
2402 }
2403
2404 if (i<1 || i>fN)
2405 {
2406 cout << " *NcSample::GetEntry* Error : Invalid index number i=" << i;
2407 if (name!="") printf(" for NcSample %-s",name.Data());
2408 printf("\n");
2409 return 0;
2410 }
2411
2412 if (j<1 || j>fDim)
2413 {
2414 cout << " *NcSample::GetEntry* Error : Invalid variable number j=" << j;
2415 if (name!="") printf(" for NcSample %-s",name.Data());
2416 printf("\n");
2417 return 0;
2418 }
2419
2420 if (mode && (k<1 || k>fDim))
2421 {
2422 cout << " *NcSample::GetEntry* Error : Invalid argument k=" << k;
2423 if (name!="") printf(" for NcSample %-s",name.Data());
2424 printf("\n");
2425 return 0;
2426 }
2427
2428 Double_t value=0;
2429
2430 // Determine the entry index in the main arrays.
2431 Int_t index=i-1;
2432
2433 if (mode)
2434 {
2435 Order(mode,k);
2436 index=fIndices->At(i-1);
2437 }
2438
2439 if (j==1) value=fX->At(index);
2440 if (j==2) value=fY->At(index);
2441 if (j==3) value=fZ->At(index);
2442 if (j==4) value=fT->At(index);
2443
2444 return value;
2445}
2446
2447Double_t NcSample::GetEntry(Int_t i,TString nameA,Int_t mode,TString nameB)
2448{
2466
2467 Int_t j=GetIndex(nameA);
2468 Int_t k=GetIndex(nameB);
2469 return GetEntry(i,j,mode,k);
2470}
2471
2472void NcSample::GetSubset(NcSample* s,Int_t ifirst,Int_t ilast,Int_t mode,Int_t k)
2473{
2492
2493 if (!s)
2494 {
2495 cout << " *NcSample::GetSubset* Error : Pointer for output NcSample object is zero." << endl;
2496 return;
2497 }
2498
2499 s->Reset();
2500
2501 if (!fStore)
2502 {
2503 cout << " *NcSample::GetSubset* Error : Storage mode not activated." << endl;
2504 return;
2505 }
2506
2507 if (ifirst<1 || ifirst>fN || ilast>fN || ilast<ifirst)
2508 {
2509 cout << " *NcSample::GetSubset* Error : Invalid input ifirst=" << ifirst << " ilast=" << ilast << endl;
2510 return;
2511 }
2512
2513 if (mode && (k<1 || k>fDim))
2514 {
2515 cout << " *NcSample::GetSubset* Error : Invalid argument k=" << k << endl;
2516 return;
2517 }
2518
2519 s->SetStoreMode();
2520 s->SetNames(fNames[0],fNames[1],fNames[2],fNames[3]);
2521
2522 Double_t* values=new Double_t[fDim];
2523 for (Int_t i=ifirst; i<=ilast; i++)
2524 {
2525 for (Int_t j=1; j<=fDim; j++)
2526 {
2527 values[j-1]=GetEntry(i,j,mode,k);
2528 }
2529 if (fDim==1) s->Enter(values[0]);
2530 if (fDim==2) s->Enter(values[0],values[1]);
2531 if (fDim==3) s->Enter(values[0],values[1],values[2]);
2532 if (fDim==4) s->Enter(values[0],values[1],values[2],values[3]);
2533 }
2534
2535 delete [] values;
2536}
2537
2538NcSample NcSample::GetDtSample(Int_t i,Int_t nc,Int_t store,Int_t nmax,Int_t order)
2539{
2588
2589 // Make "order" value to comply with a single variable sample
2590 if (order>0) order=1;
2591 if (order<0) order=-1;
2592
2593 NcSample sdt;
2594 sdt.SetStoreMode(store,nmax,order);
2595 sdt.SetName("DtSample");
2596 sdt.SetNames("Dt");
2597
2598 if (i<1 || i>GetDimension()) return sdt;
2599
2600 if (nc<1) return sdt;
2601
2602 Int_t nen=GetN();
2603 if (nen<=nc) return sdt;
2604
2605 TString varname=GetVariableName(i);
2606 TString str;
2607 str.Form("Interval sampling for variable %-s between %-i consecutive entries (nc=%-i)",varname.Data(),nc+1,nc);
2608 sdt.SetNameTitle("DtSample",str);
2609
2610 // Fill the dt sample
2611 Double_t t1=0;
2612 Double_t t2=0;
2613 Double_t deltat=0;
2614 for (Int_t ien=1; ien<=nen; ien++)
2615 {
2616 if (ien+nc>nen) break;
2617
2618 t1=GetEntry(ien,i,1,i);
2619 t2=GetEntry(ien+nc,i,1,i);
2620 deltat=fabs(t2-t1);
2621
2622 sdt.Enter(deltat);
2623 }
2624
2625 return sdt;
2626}
2627
2628NcSample NcSample::GetDtSample(TString name,Int_t nc,Int_t store,Int_t nmax,Int_t order)
2629{
2678
2679 Int_t i=GetIndex(name);
2680 NcSample sdt=GetDtSample(i,nc,store,nmax,order);
2681
2682 return sdt;
2683}
2684
2686{
2699
2700 TString s="Sampling Histogram for NcSample ";
2701 s+=GetName();
2702 s+=";Sampling number;";
2703 if (f)
2704 {
2705 TString sf=f->GetExpFormula("p");
2706 sf.ReplaceAll("x",fNames[i-1]);
2707 s+=sf;
2708 }
2709 else
2710 {
2711 s+=fNames[i-1];
2712 }
2713
2714 TH1D hist("",s,fN,0,fN);
2715
2716 if (!fStore)
2717 {
2718 cout << " *NcSample::GetSamplingHistogram* Error : Storage mode has not been activated." << endl;
2719 return hist;
2720 }
2721
2722 if (i<1 || i>fDim)
2723 {
2724 cout << " *NcSample::GetSamplingHistogram* Error : Invalid index encountered i=" << i << endl;
2725 return hist;
2726 }
2727
2728 Double_t y=0;
2729 for (Int_t ip=1; ip<=fN; ip++)
2730 {
2731 y=GetEntry(ip,i);
2732 if (f) y=f->Eval(y);
2733 hist.SetBinContent(ip,y);
2734 }
2735
2736 return hist;
2737}
2738
2739TH1D NcSample::GetSamplingHistogram(Int_t i,TString f)
2740{
2750
2751 TF1 func("func",f);
2752
2753 return GetSamplingHistogram(i,&func);
2754}
2755
2756TH1D NcSample::GetSamplingHistogram(TString nameA,TF1* f)
2757{
2769
2770 Int_t i=GetIndex(nameA);
2771 return GetSamplingHistogram(i,f);
2772}
2773
2774TH1D NcSample::GetSamplingHistogram(TString nameA,TString f)
2775{
2785
2786 TF1 func("func",f);
2787
2788 return GetSamplingHistogram(nameA,&func);
2789}
2790
2791TH1D NcSample::Get1DHistogram(Int_t i,Int_t j,Bool_t sumw2,Int_t nbx,TF1* f)
2792{
2808
2809 TString s="1D Histogram for NcSample ";
2810 s+=GetName();
2811 s+=";";
2812 s+=fNames[i-1];
2813 s+=";Counts";
2814 if (j>0)
2815 {
2816 s+=" weighted by : ";
2817 if (f)
2818 {
2819 TString sf=f->GetExpFormula("p");
2820 sf.ReplaceAll("x",fNames[j-1]);
2821 s+=sf;
2822 }
2823 else
2824 {
2825 s+=fNames[j-1];
2826 }
2827 }
2828
2829 Double_t xlow=GetMinimum(i);
2830 Double_t xup=GetMaximum(i);
2831
2832 Double_t dx=0;
2833 if (nbx) dx=(xup-xlow)/double(nbx);
2834
2835 // Extension to include the maximum value
2836 xup+=1e-6*fabs(dx);
2837
2838 TH1D hist("",s.Data(),nbx,xlow,xup);
2839 hist.Sumw2(sumw2);
2840
2841 if (!fStore)
2842 {
2843 cout << " *NcSample::Get1DHistogram* Error : Storage mode has not been activated." << endl;
2844 return hist;
2845 }
2846
2847 if (i<1 || i>fDim || j>fDim)
2848 {
2849 cout << " *NcSample::Get1DHistogram* Error : Invalid index encountered i=" << i << " j=" << j << endl;
2850 return hist;
2851 }
2852
2853 Double_t x=0;
2854 Double_t y=0;
2855 for (Int_t ip=1; ip<=fN; ip++)
2856 {
2857 x=GetEntry(ip,i);
2858 if (j>0)
2859 {
2860 y=GetEntry(ip,j);
2861 if (f) y=f->Eval(y);
2862 hist.Fill(x,y);
2863 }
2864 else
2865 {
2866 hist.Fill(x);
2867 }
2868 }
2869
2870 return hist;
2871}
2872
2873TH1D NcSample::Get1DHistogram(TString nameA,TString nameB,Bool_t sumw2,Int_t nbx,TF1* f)
2874{
2889
2890 Int_t i=GetIndex(nameA);
2891 Int_t j=GetIndex(nameB);
2892 return Get1DHistogram(i,j,sumw2,nbx,f);
2893}
2894
2895TH2D NcSample::Get2DHistogram(Int_t i,Int_t j,Int_t k,Bool_t sumw2,Int_t nbx,Int_t nby,TF1* f)
2896{
2913
2914 TString s="2D Histogram for NcSample ";
2915 s+=GetName();
2916 s+=";";
2917 s+=fNames[i-1];
2918 s+=";";
2919 s+=fNames[j-1];
2920 s+=";Counts";
2921 if (k>0)
2922 {
2923 s+=" weighted by : ";
2924 if (f)
2925 {
2926 TString sf=f->GetExpFormula("p");
2927 sf.ReplaceAll("x",fNames[k-1]);
2928 s+=sf;
2929 }
2930 else
2931 {
2932 s+=fNames[k-1];
2933 }
2934 }
2935
2936 Double_t xlow=GetMinimum(i);
2937 Double_t xup=GetMaximum(i);
2938 Double_t ylow=GetMinimum(j);
2939 Double_t yup=GetMaximum(j);
2940
2941 Double_t dx=0;
2942 if (nbx) dx=(xup-xlow)/double(nbx);
2943 Double_t dy=0;
2944 if (nby) dy=(yup-ylow)/double(nby);
2945
2946 // Extension to include the maximum values
2947 xup+=1e-6*fabs(dx);
2948 yup+=1e-6*fabs(dy);
2949
2950 TH2D hist("",s.Data(),nbx,xlow,xup,nby,ylow,yup);
2951 hist.Sumw2(sumw2);
2952 hist.SetMarkerStyle(20);
2953 hist.SetMarkerSize(1);
2954
2955 if (!fStore)
2956 {
2957 cout << " *NcSample::Get2DHistogram* Error : Storage mode has not been activated." << endl;
2958 return hist;
2959 }
2960
2961 if (i<1 || i>fDim || j<1 || j>fDim || k>fDim)
2962 {
2963 cout << " *NcSample::Get2DHistogram* Error : Invalid index encountered i=" << i << " j=" << j << " k=" << k << endl;
2964 return hist;
2965 }
2966
2967 Double_t x=0;
2968 Double_t y=0;
2969 Double_t z=0;
2970 for (Int_t ip=1; ip<=fN; ip++)
2971 {
2972 x=GetEntry(ip,i);
2973 y=GetEntry(ip,j);
2974 if (k>0)
2975 {
2976 z=GetEntry(ip,k);
2977 if (f) z=f->Eval(z);
2978 hist.Fill(x,y,z);
2979 }
2980 else
2981 {
2982 hist.Fill(x,y);
2983 }
2984 }
2985
2986 return hist;
2987}
2988
2989TH2D NcSample::Get2DHistogram(TString nameA,TString nameB,TString nameC,Bool_t sumw2,Int_t nbx,Int_t nby,TF1* f)
2990{
3006
3007 Int_t i=GetIndex(nameA);
3008 Int_t j=GetIndex(nameB);
3009 Int_t k=GetIndex(nameC);
3010 return Get2DHistogram(i,j,k,sumw2,nbx,nby,f);
3011}
3012
3013TH3D NcSample::Get3DHistogram(Int_t i,Int_t j,Int_t k,Int_t m,Bool_t sumw2,Int_t nbx,Int_t nby,Int_t nbz,TF1* f)
3014{
3031
3032 TString s="3D Histogram for NcSample ";
3033 s+=GetName();
3034 if (m>0)
3035 {
3036 s+=" with ";
3037 if (f)
3038 {
3039 TString sf=f->GetExpFormula("p");
3040 sf.ReplaceAll("x",fNames[m-1]);
3041 s+=sf;
3042 }
3043 else
3044 {
3045 s+=fNames[m-1];
3046 }
3047 s+=" as weight";
3048 }
3049 s+=";";
3050 s+=fNames[i-1];
3051 s+=";";
3052 s+=fNames[j-1];
3053 s+=";";
3054 s+=fNames[k-1];
3055
3056 Double_t xlow=GetMinimum(i);
3057 Double_t xup=GetMaximum(i);
3058 Double_t ylow=GetMinimum(j);
3059 Double_t yup=GetMaximum(j);
3060 Double_t zlow=GetMinimum(k);
3061 Double_t zup=GetMaximum(k);
3062
3063 Double_t dx=0;
3064 if (nbx) dx=(xup-xlow)/double(nbx);
3065 Double_t dy=0;
3066 if (nby) dy=(yup-ylow)/double(nby);
3067 Double_t dz=0;
3068 if (nbz) dz=(zup-zlow)/double(nbz);
3069
3070 // Extension to include the maximum values
3071 xup+=1e-6*fabs(dx);
3072 yup+=1e-6*fabs(dy);
3073 zup+=1e-6*fabs(dz);
3074
3075 TH3D hist("",s.Data(),nbx,xlow,xup,nby,ylow,yup,nbz,zlow,zup);
3076 hist.Sumw2(sumw2);
3077 hist.SetMarkerStyle(20);
3078 hist.SetMarkerSize(1);
3079
3080 if (!fStore)
3081 {
3082 cout << " *NcSample::Get3DHistogram* Error : Storage mode has not been activated." << endl;
3083 return hist;
3084 }
3085
3086 if (i<1 || i>fDim || j<1 || j>fDim || k<1 || k>fDim || m>fDim)
3087 {
3088 cout << " *NcSample::Get2DHistogram* Error : Invalid index encountered i=" << i << " j=" << j << " k=" << k << " m=" << m << endl;
3089 return hist;
3090 }
3091
3092 Double_t x=0;
3093 Double_t y=0;
3094 Double_t z=0;
3095 Double_t t=0;
3096 for (Int_t ip=1; ip<=fN; ip++)
3097 {
3098 x=GetEntry(ip,i);
3099 y=GetEntry(ip,j);
3100 z=GetEntry(ip,k);
3101 if (m>0)
3102 {
3103 t=GetEntry(ip,m);
3104 if (f) t=f->Eval(t);
3105 hist.Fill(x,y,z,t);
3106 }
3107 else
3108 {
3109 hist.Fill(x,y,z);
3110 }
3111 }
3112
3113 return hist;
3114}
3115
3116TH3D NcSample::Get3DHistogram(TString nameA,TString nameB,TString nameC,TString nameD,Bool_t sumw2,Int_t nbx,Int_t nby,Int_t nbz,TF1* f)
3117{
3133
3134 Int_t i=GetIndex(nameA);
3135 Int_t j=GetIndex(nameB);
3136 Int_t k=GetIndex(nameC);
3137 Int_t m=GetIndex(nameD);
3138 return Get3DHistogram(i,j,k,m,sumw2,nbx,nby,nbz,f);
3139}
3140
3141TGraph NcSample::GetGraph(Int_t i,TF1* f)
3142{
3155
3156 TGraph gr;
3157 gr.SetName("NcSample");
3158
3159 if (!fStore)
3160 {
3161 cout << " *NcSample::GetGraph* Error : Storage mode has not been activated." << endl;
3162 return gr;
3163 }
3164
3165 if (i<1 || i>fDim)
3166 {
3167 cout << " *NcSample::GetGraph* Error : Invalid index encountered i=" << i << endl;
3168 return gr;
3169 }
3170
3171 Double_t x=0;
3172 Double_t y=0;
3173 for (Int_t ip=0; ip<fN; ip++)
3174 {
3175 x=ip+1;
3176 y=GetEntry(ip+1,i);
3177 if (f) y=f->Eval(y);
3178 gr.SetPoint(ip,x,y);
3179 }
3180
3181 TString s="TGraph for NcSample ";
3182 s+=GetName();
3183 s+=" : X-axis=Sampling number ";
3184 s+=" Y-axis=";
3185 TString sf=fNames[i-1];
3186 if (f)
3187 {
3188 sf=f->GetExpFormula("p");
3189 sf.ReplaceAll("x",fNames[i-1]);
3190 }
3191 s+=sf;
3192 s+=";Sampling number;";
3193 s+=sf;
3194
3195 gr.SetTitle(s.Data());
3196
3197 gr.SetMarkerStyle(20);
3198 gr.SetMarkerSize(1);
3199 gr.SetDrawOption("AP");
3200
3201 return gr;
3202}
3203
3204TGraph NcSample::GetGraph(Int_t i,TString f)
3205{
3215
3216 TF1 func("func",f);
3217
3218 return GetGraph(i,&func);
3219}
3220
3221TGraph NcSample::GetGraph(TString nameA,TF1* f)
3222{
3234
3235 Int_t i=GetIndex(nameA);
3236 return GetGraph(i,f);
3237}
3238
3239TGraph NcSample::GetGraph(Int_t i,Int_t j,TF1* f)
3240{
3253
3254 TGraph gr;
3255 gr.SetName("NcSample");
3256
3257 if (!fStore)
3258 {
3259 cout << " *NcSample::GetGraph* Error : Storage mode has not been activated." << endl;
3260 return gr;
3261 }
3262
3263 if (i<1 || i>fDim || j<1 || j>fDim)
3264 {
3265 cout << " *NcSample::GetGraph* Error : Invalid index encountered i=" << i << " j=" << j << endl;
3266 return gr;
3267 }
3268
3269 Double_t x=0;
3270 Double_t y=0;
3271 for (Int_t ip=0; ip<fN; ip++)
3272 {
3273 x=GetEntry(ip+1,i);
3274 y=GetEntry(ip+1,j);
3275 if (f) y=f->Eval(y);
3276 gr.SetPoint(ip,x,y);
3277 }
3278
3279 TString s="TGraph for NcSample ";
3280 s+=GetName();
3281 s+=" : X-axis=";
3282 s+=fNames[i-1];
3283 s+=" Y-axis=";
3284 TString sf=fNames[j-1];
3285 if (f)
3286 {
3287 sf=f->GetExpFormula("p");
3288 sf.ReplaceAll("x",fNames[j-1]);
3289 }
3290 s+=sf;
3291 s+=";";
3292 s+=fNames[i-1];
3293 s+=";";
3294 s+=sf;
3295
3296 gr.SetTitle(s.Data());
3297
3298 gr.SetMarkerStyle(20);
3299 gr.SetMarkerSize(1);
3300 gr.SetDrawOption("AP");
3301
3302 return gr;
3303}
3304
3305TGraph NcSample::GetGraph(Int_t i,Int_t j,TString f)
3306{
3316
3317 TF1 func("func",f);
3318
3319 return GetGraph(i,j,&func);
3320}
3321
3322TGraph NcSample::GetGraph(TString nameA,TString nameB,TF1* f)
3323{
3335
3336 Int_t i=GetIndex(nameA);
3337 Int_t j=GetIndex(nameB);
3338 return GetGraph(i,j,f);
3339}
3340
3341TGraphErrors NcSample::GetGraphErrors(TGraph* gr,Int_t ix,Int_t iy,TF1* fx,TF1* fy)
3342{
3384
3385 TGraphErrors gre;
3386
3387 if (!gr)
3388 {
3389 cout << " *NcSample::GetGraphErrors* Error : No input Graph is specified." << endl;
3390 return gre;
3391 }
3392
3393 TString name=gr->GetName();
3394 name+=".E";
3395
3396 gre.SetName(name);
3397
3398 if ((ix || iy) && !fStore)
3399 {
3400 cout << " *NcSample::GetGraphErrors* Error : Storage mode has not been activated." << endl;
3401 return gre;
3402 }
3403
3404 if (ix<0 || ix>fDim || iy<0 || iy>fDim)
3405 {
3406 cout << " *NcSample::GetGraphErros* Error : Invalid index encountered ix=" << ix << " iy=" << iy << endl;
3407 return gre;
3408 }
3409
3410 // The number of data points of the input Graph
3411 Int_t np=gr->GetN();
3412
3413 if (!np)
3414 {
3415 cout << " *NcSample::GetGraphErrors* Error : Input Graph does not contain any data points." << endl;
3416 return gre;
3417 }
3418
3419 if ((ix || iy) && np!=fN)
3420 {
3421 cout << " *NcSample::GetGraphErrors* Error : Entries don't match Nsample=" << fN << " Ngraph=" << np << endl;
3422 return gre;
3423 }
3424
3425 Double_t x=0;
3426 Double_t y=0;
3427 Double_t ex=0;
3428 Double_t ey=0;
3429 for (Int_t ip=0; ip<np; ip++)
3430 {
3431 gr->GetPoint(ip,x,y);
3432 if (ix) ex=GetEntry(ip+1,ix);
3433 if (fx)
3434 {
3435 if (!ix)
3436 {
3437 ex=fx->Eval(x);
3438 }
3439 else
3440 {
3441 ex=fx->Eval(ex);
3442 }
3443 }
3444 if (iy) ey=GetEntry(ip+1,iy);
3445 if (fy)
3446 {
3447 if (!iy)
3448 {
3449 ey=fy->Eval(y);
3450 }
3451 else
3452 {
3453 ey=fy->Eval(ey);
3454 }
3455 }
3456 ex=fabs(ex);
3457 ey=fabs(ey);
3458 gre.SetPoint(ip,x,y);
3459 gre.SetPointError(ip,ex,ey);
3460 }
3461
3462 TString sfx="0";
3463 if (ix || fx)
3464 {
3465 sfx="|";
3466 if (!fx)
3467 {
3468 sfx+=fNames[ix-1];
3469 }
3470 else
3471 {
3472 sfx+=fx->GetExpFormula("p");
3473 if (ix) sfx.ReplaceAll("x",fNames[ix-1]);
3474 }
3475 sfx+="|";
3476 }
3477
3478 TString sfy="0";
3479 if (iy || fy)
3480 {
3481 sfy="|";
3482 if (!fy)
3483 {
3484 sfy+=fNames[iy-1];
3485 }
3486 else
3487 {
3488 sfy+=fy->GetExpFormula("p");
3489 if (iy)
3490 {
3491 sfy.ReplaceAll("x",fNames[iy-1]);
3492 }
3493 else
3494 {
3495 sfy.ReplaceAll("x","y");
3496 }
3497 }
3498 sfy+="|";
3499 }
3500
3501 TString s="TGraphErrors for Graph : ";
3502 s+=gr->GetName();
3503 s+=" X-error=";
3504 s+=sfx;
3505 s+=" Y-error=";
3506 s+=sfy;
3507
3508 // Copy the axes titles of the input Graph (if present)
3509 TAxis* axis=0;
3510 axis=gr->GetXaxis();
3511 if (axis)
3512 {
3513 s+=";";
3514 s+=axis->GetTitle();
3515 }
3516 axis=gr->GetYaxis();
3517 if (axis)
3518 {
3519 s+=";";
3520 s+=axis->GetTitle();
3521 }
3522
3523 gre.SetTitle(s.Data());
3524
3525 gre.SetMarkerStyle(20);
3526 gre.SetMarkerSize(0.5);
3527 gre.SetDrawOption("AP");
3528
3529 return gre;
3530}
3531
3532TGraphErrors NcSample::GetGraphErrors(TGraph* gr,TString nameA,TString nameB,TF1* fx,TF1* fy)
3533{
3575
3576 Int_t ix=GetIndex(nameA);
3577 Int_t iy=GetIndex(nameB);
3578
3579 return GetGraphErrors(gr,ix,iy,fx,fy);
3580}
3581
3582TGraphTime* NcSample::GetGraph(Int_t i,Int_t j,Int_t mode,Int_t k,Bool_t smp)
3583{
3623
3624 if (!fStore)
3625 {
3626 cout << " *NcSample::GetGraph* Error : Storage mode has not been activated." << endl;
3627 return 0;
3628 }
3629
3630 if (fN<1)
3631 {
3632 cout << " *NcSample::GetGraph* Error : No data entries are stored." << endl;
3633 return 0;
3634 }
3635
3636 if (i<1 || i>fDim || j<1 || j>fDim || (mode && (k<1 || k>fDim)))
3637 {
3638 cout << " *NcSample::GetGraph* Error : Invalid index encountered i=" << i << " j=" << j << " k=" << k << endl;
3639 return 0;
3640 }
3641
3642 Double_t xlow=GetMinimum(i);
3643 Double_t xup=GetMaximum(i);
3644 Double_t ylow=GetMinimum(j);
3645 Double_t yup=GetMaximum(j);
3646
3647 // Extensions to display the points well within the frame
3648 xlow-=0.1*fabs(xlow);
3649 xup+=0.1*fabs(xup);
3650 ylow-=0.1*fabs(ylow);
3651 yup+=0.1*fabs(yup);
3652
3653 if (fGraphT)
3654 {
3655 delete fGraphT;
3656 fGraphT=0;
3657 }
3658
3659 fGraphT=new TGraphTime(fN,xlow,ylow,xup,yup);
3660 fGraphT->SetName("NcSample");
3661
3662 Double_t x=0;
3663 Double_t y=0;
3664 TMarker* m=0;
3665 Int_t jpstart=0;
3666 for (Int_t istep=0; istep<fN; istep++)
3667 {
3668 if (!smp) jpstart=istep;
3669 for (Int_t jp=jpstart; jp<=istep; jp++)
3670 {
3671 x=GetEntry(jp+1,i,mode,k);
3672 y=GetEntry(jp+1,j,mode,k);
3673 m=new TMarker(x,y,20);
3674 m->SetMarkerSize(1);
3675 fGraphT->Add(m,istep);
3676 }
3677 }
3678
3679 TString s="TGraphTime for NcSample ";
3680 s+=GetName();
3681 s+=";";
3682 s+=fNames[i-1];
3683 s+=";";
3684 s+=fNames[j-1];
3685 fGraphT->SetNameTitle("",s.Data());
3686
3687 return fGraphT;
3688}
3689
3690TGraphTime* NcSample::GetGraph(TString nameA,TString nameB,Int_t mode,TString nameC,Bool_t smp)
3691{
3730
3731 Int_t i=GetIndex(nameA);
3732 Int_t j=GetIndex(nameB);
3733 Int_t k=GetIndex(nameC);
3734 return GetGraph(i,j,mode,k,smp);
3735}
3736
3737TGraph2D NcSample::GetGraph(Int_t i,Int_t j,Int_t k,TF1* f)
3738{
3751
3752 TGraph2D gr;
3753 gr.SetName("NcSample");
3754
3755 if (!fStore)
3756 {
3757 cout << " *NcSample::GetGraph* Error : Storage mode has not been activated." << endl;
3758 return gr;
3759 }
3760
3761 if (fN<1)
3762 {
3763 cout << " *NcSample::GetGraph* Error : No data entries are stored." << endl;
3764 return gr;
3765 }
3766
3767 if (i<1 || i>fDim || j<1 || j>fDim || k<1 || k>fDim)
3768 {
3769 cout << " *NcSample::GetGraph* Error : Invalid index encountered i=" << i << " j=" << j << " k=" << k << endl;
3770 return gr;
3771 }
3772
3773 Double_t x=0;
3774 Double_t y=0;
3775 Double_t z=0;
3776 for (Int_t ip=0; ip<fN; ip++)
3777 {
3778 x=GetEntry(ip+1,i);
3779 y=GetEntry(ip+1,j);
3780 z=GetEntry(ip+1,k);
3781 if (f) z=f->Eval(z);
3782 gr.SetPoint(ip,x,y,z);
3783 }
3784
3785 TString s="TGraph2D for NcSample ";
3786 s+=GetName();
3787 s+=" : X-axis=";
3788 s+=fNames[i-1];
3789 s+=" Y-axis=";
3790 s+=fNames[j-1];
3791 s+=" Z-axis=";
3792 TString sf=fNames[k-1];
3793 if (f)
3794 {
3795 sf=f->GetExpFormula("p");
3796 sf.ReplaceAll("x",fNames[k-1]);
3797 }
3798 s+=sf;
3799 s+=";";
3800 s+=fNames[i-1];
3801 s+=";";
3802 s+=fNames[j-1];
3803 s+=";";
3804 s+=sf;
3805
3806 gr.SetTitle(s.Data());
3807
3808 gr.SetMarkerStyle(20);
3809 gr.SetMarkerSize(1);
3810 gr.SetDrawOption("P");
3811
3812 return gr;
3813}
3814
3815TGraph2D NcSample::GetGraph(Int_t i,Int_t j,Int_t k,TString f)
3816{
3826
3827 TF1 func("func",f);
3828
3829 return GetGraph(i,j,k,&func);
3830}
3831
3832TGraph2D NcSample::GetGraph(TString nameA,TString nameB,TString nameC,TF1* f)
3833{
3845
3846 Int_t i=GetIndex(nameA);
3847 Int_t j=GetIndex(nameB);
3848 Int_t k=GetIndex(nameC);
3849 return GetGraph(i,j,k,f);
3850}
3851
3852TGraph2D NcSample::GetGraph(TString nameA,TString nameB,TString nameC,TString f)
3853{
3862
3863 TF1 func("func",f);
3864
3865 return GetGraph(nameA,nameB,nameC,&func);
3866}
3867
3868TGraph2DErrors NcSample::GetGraph2DErrors(TGraph2D* gr,Int_t ix,Int_t iy,Int_t iz,TF1* fx,TF1* fy,TF1* fz)
3869{
3916
3917 TGraph2DErrors gre;
3918
3919 if (!gr)
3920 {
3921 cout << " *NcSample::GetGraph2DErrors* Error : No input Graph is specified." << endl;
3922 return gre;
3923 }
3924
3925 TString name=gr->GetName();
3926 name+=".E";
3927
3928 gre.SetName(name);
3929
3930 if ((ix || iy || iz) && !fStore)
3931 {
3932 cout << " *NcSample::GetGraph2DErrors* Error : Storage mode has not been activated." << endl;
3933 return gre;
3934 }
3935
3936 if (ix<0 || ix>fDim || iy<0 || iy>fDim || iz<0 || iz>fDim)
3937 {
3938 cout << " *NcSample::GetGraph2DErrors* Error : Invalid index encountered ix=" << ix << " iy=" << iy << " iz=" << iz << endl;
3939 return gre;
3940 }
3941
3942 // The number of data points of the input Graph
3943 Int_t np=gr->GetN();
3944
3945 if (!np)
3946 {
3947 cout << " *NcSample::GetGraph2DErrors* Error : Input Graph does not contain any data points." << endl;
3948 return gre;
3949 }
3950
3951 if ((ix || iy || iz) && np!=fN)
3952 {
3953 cout << " *NcSample::GetGraph2DErrors* Error : Entries don't match Nsample=" << fN << " Ngraph=" << np << endl;
3954 return gre;
3955 }
3956
3957 Double_t* xarr=gr->GetX();
3958 Double_t* yarr=gr->GetY();
3959 Double_t* zarr=gr->GetZ();
3960 Double_t x=0;
3961 Double_t y=0;
3962 Double_t z=0;
3963 Double_t ex=0;
3964 Double_t ey=0;
3965 Double_t ez=0;
3966 for (Int_t ip=0; ip<np; ip++)
3967 {
3968 x=xarr[ip];
3969 y=yarr[ip];
3970 z=zarr[ip];
3971 if (ix) ex=GetEntry(ip+1,ix);
3972 if (fx)
3973 {
3974 if (!ix)
3975 {
3976 ex=fx->Eval(x);
3977 }
3978 else
3979 {
3980 ex=fx->Eval(ex);
3981 }
3982 }
3983 if (iy) ey=GetEntry(ip+1,iy);
3984 if (fy)
3985 {
3986 if (!iy)
3987 {
3988 ey=fy->Eval(y);
3989 }
3990 else
3991 {
3992 ey=fy->Eval(ey);
3993 }
3994 }
3995 if (iz) ez=GetEntry(ip+1,iz);
3996 if (fz)
3997 {
3998 if (!iz)
3999 {
4000 ez=fz->Eval(z);
4001 }
4002 else
4003 {
4004 ez=fz->Eval(ez);
4005 }
4006 }
4007 ex=fabs(ex);
4008 ey=fabs(ey);
4009 ez=fabs(ez);
4010 gre.SetPoint(ip,x,y,z);
4011 gre.SetPointError(ip,ex,ey,ez);
4012 }
4013
4014 TString sfx="0";
4015 if (ix || fx)
4016 {
4017 sfx="|";
4018 if (!fx)
4019 {
4020 sfx+=fNames[ix-1];
4021 }
4022 else
4023 {
4024 sfx+=fx->GetExpFormula("p");
4025 if (ix) sfx.ReplaceAll("x",fNames[ix-1]);
4026 }
4027 sfx+="|";
4028 }
4029
4030 TString sfy="0";
4031 if (iy || fy)
4032 {
4033 sfy="|";
4034 if (!fy)
4035 {
4036 sfy+=fNames[iy-1];
4037 }
4038 else
4039 {
4040 sfy+=fy->GetExpFormula("p");
4041 if (iy)
4042 {
4043 sfy.ReplaceAll("x",fNames[iy-1]);
4044 }
4045 else
4046 {
4047 sfy.ReplaceAll("x","y");
4048 }
4049 }
4050 sfy+="|";
4051 }
4052
4053 TString sfz="0";
4054 if (iz || fz)
4055 {
4056 sfz="|";
4057 if (!fz)
4058 {
4059 sfz+=fNames[iz-1];
4060 }
4061 else
4062 {
4063 sfz+=fz->GetExpFormula("p");
4064 if (iz)
4065 {
4066 sfz.ReplaceAll("x",fNames[iz-1]);
4067 }
4068 else
4069 {
4070 sfz.ReplaceAll("x","z");
4071 }
4072 }
4073 sfz+="|";
4074 }
4075
4076 TString s="TGraphErrors for Graph : ";
4077 s+=gr->GetName();
4078 s+=" X-error=";
4079 s+=sfx;
4080 s+=" Y-error=";
4081 s+=sfy;
4082 s+=" Z-error=";
4083 s+=sfz;
4084
4085 // Copy the axes titles of the input Graph (if present)
4086 TAxis* axis=0;
4087 axis=gr->GetXaxis();
4088 if (axis)
4089 {
4090 s+=";";
4091 s+=axis->GetTitle();
4092 }
4093 axis=gr->GetYaxis();
4094 if (axis)
4095 {
4096 s+=";";
4097 s+=axis->GetTitle();
4098 }
4099 axis=gr->GetZaxis();
4100 if (axis)
4101 {
4102 s+=";";
4103 s+=axis->GetTitle();
4104 }
4105
4106 gre.SetTitle(s.Data());
4107
4108 gre.SetMarkerStyle(20);
4109 gre.SetMarkerSize(0.5);
4110 gre.SetDrawOption("err P");
4111
4112 return gre;
4113}
4114
4115TGraph2DErrors NcSample::GetGraph2DErrors(TGraph2D* gr,TString nameA,TString nameB,TString nameC,TF1* fx,TF1* fy,TF1* fz)
4116{
4163
4164 Int_t ix=GetIndex(nameA);
4165 Int_t iy=GetIndex(nameB);
4166 Int_t iz=GetIndex(nameC);
4167
4168 return GetGraph2DErrors(gr,ix,iy,iz,fx,fy,fz);
4169}
4170
4171TGraphQQ NcSample::GetQQplot(Int_t i,Int_t j,TF1* f)
4172{
4185
4186 TGraphQQ gr;
4187 gr.SetName("NcSample");
4188
4189 if (!f && (j<1 || j>fDim)) return gr;
4190
4191 if (!fStore)
4192 {
4193 cout << " *NcSample::GetQQplot* Error : Storage mode has not been activated." << endl;
4194 return gr;
4195 }
4196
4197 if (fN<1)
4198 {
4199 cout << " *NcSample::GetQQplot* Error : No data entries are stored." << endl;
4200 return gr;
4201 }
4202
4203 if (i<1 || i>fDim || (!f && (j<1 || j>fDim)))
4204 {
4205 cout << " *NcSample::GetQQplot* Error : Invalid index encountered i=" << i << " j=" << j << endl;
4206 return gr;
4207 }
4208
4209 Double_t* arri=0;
4210 if (i==1) arri=fX->GetArray();
4211 if (i==2) arri=fY->GetArray();
4212 if (i==3) arri=fZ->GetArray();
4213 if (i==4) arri=fT->GetArray();
4214
4215 if (!f)
4216 {
4217 Double_t* arrj=0;
4218 if (j==1) arrj=fX->GetArray();
4219 if (j==2) arrj=fY->GetArray();
4220 if (j==3) arrj=fZ->GetArray();
4221 if (j==4) arrj=fT->GetArray();
4222
4223 if (arri && arrj) gr=TGraphQQ(fN,arri,fN,arrj);
4224 }
4225 else
4226 {
4227 if (arri) gr=TGraphQQ(fN,arri,f);
4228 }
4229
4230 TString s="QQ-plot (TGraphQQ) for NcSample ";
4231 s+=GetName();
4232 if (f)
4233 {
4234 s+=" of ";
4235 s+=fNames[i-1];
4236 s+=" versus f(a)=";
4237 TString sf=f->GetExpFormula("p");
4238 sf.ReplaceAll("x","a");
4239 s+=sf;
4240 }
4241 else
4242 {
4243 s+=";";
4244 s+=fNames[i-1];
4245 s+=";";
4246 s+=fNames[j-1];
4247 }
4248
4249 gr.SetTitle(s.Data());
4250
4251 gr.SetMarkerStyle(20);
4252 gr.SetMarkerSize(1);
4253
4254 return gr;
4255}
4256
4257TGraphQQ NcSample::GetQQplot(TString nameA,TString nameB,TF1* f)
4258{
4270
4271 Int_t i=GetIndex(nameA);
4272 Int_t j=GetIndex(nameB);
4273 return GetQQplot(i,j,f);
4274}
4275
4276void NcSample::Load(TGraph* g,Int_t clr)
4277{
4290
4291 if (!g)
4292 {
4293 printf(" *%-s::Load* Error : No TGraph specified ==> No action taken. \n",ClassName());
4294 return;
4295 }
4296
4297 if (!clr && fDim!=2)
4298 {
4299 printf(" *%-s::Load* Error : Dimension %-i does not match a TGraph. \n",ClassName(),fDim);
4300 return;
4301 }
4302
4303 if (clr) Reset();
4304
4305 Int_t npoints=g->GetN();
4306 Double_t* x=g->GetX();
4307 Double_t* y=g->GetY();
4308
4309 if (!x || !y || npoints<1) return;
4310
4311 for (Int_t i=0; i<npoints; i++)
4312 {
4313 Enter(x[i],y[i]);
4314 }
4315}
4316
4317void NcSample::Load(TGraph2D* g,Int_t clr)
4318{
4331
4332 if (!g)
4333 {
4334 printf(" *%-s::Load* Error : No TGraph2D specified ==> No action taken. \n",ClassName());
4335 return;
4336 }
4337
4338 if (!clr && fDim!=3)
4339 {
4340 printf(" *%-s::Load* Error : Dimension %-i does not match a TGraph2D. \n",ClassName(),fDim);
4341 return;
4342 }
4343
4344 if (clr) Reset();
4345
4346 Int_t npoints=g->GetN();
4347 Double_t* x=g->GetX();
4348 Double_t* y=g->GetY();
4349 Double_t* z=g->GetZ();
4350
4351 if (!x || !y || !z || npoints<1) return;
4352
4353 for (Int_t i=0; i<npoints; i++)
4354 {
4355 Enter(x[i],y[i],z[i]);
4356 }
4357}
4358
4359void NcSample::Load(TH1* h,Int_t clr)
4360{
4373
4374 if (!h)
4375 {
4376 printf(" *%-s::Load* Error : No histogram specified ==> No action taken. \n",ClassName());
4377 return;
4378 }
4379
4380 Int_t hdim=h->GetDimension();
4381
4382 if (hdim!=1)
4383 {
4384 printf(" *%-s::Load* Error : Histograms of dimension %-i are not supported. \n",ClassName(),hdim);
4385 return;
4386 }
4387
4388 if (!clr && fDim!=1)
4389 {
4390 printf(" *%-s::Load* Error : Dimension %-i does not match a 1-dimensional histogram. \n",ClassName(),fDim);
4391 return;
4392 }
4393
4394 if (clr) Reset();
4395
4396 Int_t nbins=h->GetNbinsX();
4397
4398 Double_t val=0;
4399 for (Int_t i=1; i<=nbins; i++)
4400 {
4401 val=h->GetBinContent(i);
4402 Enter(val);
4403 }
4404}
4405
4406void NcSample::Load(TArray* arr,Int_t clr)
4407{
4420
4421 if (!arr)
4422 {
4423 printf(" *%-s::Load* Error : No data array specified ==> No action taken. \n",ClassName());
4424 return;
4425 }
4426
4427 if (!clr && fDim!=1)
4428 {
4429 printf(" *%-s::Load* Error : Dimension %-i does not match a 1-dimensional data array. \n",ClassName(),fDim);
4430 return;
4431 }
4432
4433 if (clr) Reset();
4434
4435 Int_t n=arr->GetSize();
4436
4437 Double_t val=0;
4438 for (Int_t i=0; i<n; i++)
4439 {
4440 val=arr->GetAt(i);
4441 Enter(val);
4442 }
4443}
4444
4445Double_t NcSample::GetSNR(Int_t i,Int_t mode,Bool_t dB) const
4446{
4524
4525 if (i<1 || i>fDim || !mode || abs(mode)>4) return -9999;
4526
4527 Double_t snr=-1;
4528 Double_t ymax=GetMaximum(i);
4529 Double_t ymin=GetMinimum(i);
4530 Double_t mean=GetMean(i);
4531 Double_t var=GetVar(i);
4532 Double_t rmsdev=sqrt(var);
4533 Double_t sigma=GetSigma(i,1);
4534 Double_t stdev=rmsdev;
4535 if (mode<0) stdev=sigma;
4536
4537 if (stdev<=0) return -9999;
4538
4540 // SNR of a transient signal //
4542
4543 if (abs(mode)>2)
4544 {
4545 if (abs(mode)==3) // Data are power or RMS amplitudes
4546 {
4547 snr=(ymax-ymin)/stdev;
4548 }
4549 if (abs(mode)==4) // Data are bipolar amplitudes
4550 {
4551 snr=(ymax-ymin)/(2.*stdev);
4552 }
4553
4554 if (dB && snr>0) snr=10.*log10(snr);
4555
4556 return snr;
4557 }
4558
4560 // SNR of a continuous signal //
4562
4563 // Treat the values as observed amplitudes and work in dB scale
4564 Double_t psignal=mean*mean;
4565 Double_t pnoise=stdev*stdev;
4566
4567 if (psignal>0 && pnoise>0)
4568 {
4569 snr=10.*(log10(psignal)-log10(pnoise));
4570 if (abs(mode)==1) snr=snr/2.; // Treat values as observed power
4571 if (!dB) // Convert to the straight ratio
4572 {
4573 snr=snr/10.;
4574 snr=pow(10,snr);
4575 }
4576 }
4577
4578 return snr;
4579}
4580
4581Double_t NcSample::GetSNR(TString name,Int_t mode,Bool_t dB) const
4582{
4659
4660 Int_t i=GetIndex(name);
4661 return GetSNR(i,mode,dB);
4662}
4663
4664Double_t NcSample::GetCV(Int_t i,Int_t mode) const
4665{
4690
4691 if (i<1 || i>fDim || abs(mode)<1 || abs(mode)>2) return -1;
4692
4693 Double_t vmax=GetMaximum(i);
4694 Double_t vmin=GetMinimum(i);
4695 Double_t value=GetMean(i);
4696 if (abs(mode)==2) value=(vmax-vmin)/2.;
4697 Double_t stdev=GetSigma(i,0);
4698 if (mode<0) stdev=GetSigma(i,1);
4699
4700 Double_t cv=-1;
4701
4702 if (value) cv=fabs(stdev/value);
4703
4704 return cv;
4705}
4706
4707Double_t NcSample::GetCV(TString name,Int_t mode) const
4708{
4732
4733 Int_t i=GetIndex(name);
4734 return GetCV(i,mode);
4735}
4736
4737void NcSample::Animation(Int_t i,Int_t j,Int_t mode,Int_t k,Int_t delay,TString opt)
4738{
4764
4765 if (!fStore || fN<1 || i<1 || i>fDim || j<1 || j>fDim || (mode && (k<1 || k>fDim)) || delay<0)
4766 {
4767 cout << " *NcSample::Animation* Inconsistent input data." << endl;
4768 return;
4769 }
4770
4771 if (fCanvas)
4772 {
4773 delete fCanvas;
4774 fCanvas=0;
4775 }
4776
4777 if (fAnimObject)
4778 {
4779 delete fAnimObject;
4780 fAnimObject=0;
4781 }
4782
4783 fCanvas=new TCanvas("fCanvas","Sampling animation");
4784
4785 TGraph* gr=new TGraph();
4786 fAnimObject=gr;
4787
4788 TString s="Sampling animation for NcSample ";
4789 s+=GetName();
4790 gr->SetTitle(s.Data());
4791 gr->SetMarkerStyle(20);
4792 gr->SetMarkerSize(1);
4793
4794 Double_t x=0;
4795 Double_t y=0;
4796 for (Int_t ip=0; ip<fN; ip++)
4797 {
4798 x=GetEntry(ip+1,i,mode,k);
4799 y=GetEntry(ip+1,j,mode,k);
4800 gr->SetPoint(ip,x,y);
4801
4802 if (!ip) gr->Draw(opt.Data());
4803
4804 s="Variable ";
4805 s+=fNames[i-1];
4806 gr->GetXaxis()->SetTitle(s.Data());
4807 s="Variable ";
4808 s+=fNames[j-1];
4809 gr->GetYaxis()->SetTitle(s.Data());
4810
4811 fCanvas->Modified();
4812 fCanvas->Update();
4813
4814 gSystem->Sleep(delay);
4815 }
4816}
4817
4818void NcSample::Animation(TString nameA,TString nameB,Int_t mode,TString nameC,Int_t delay,TString opt)
4819{
4844
4845 Int_t i=GetIndex(nameA);
4846 Int_t j=GetIndex(nameB);
4847 Int_t k=GetIndex(nameC);
4848 Animation(i,j,mode,k,delay,opt);
4849}
4850
4851void NcSample::Animation(Int_t i,Int_t j,Int_t k,Int_t mode,Int_t m,Int_t delay,TString opt)
4852{
4878
4879 if (!fStore || fN<1 || i<1 || i>fDim || j<1 || j>fDim || k<1 || k>fDim || (mode && (m<1 || m>fDim)) || delay<0)
4880 {
4881 cout << " *NcSample::Animation* Inconsistent input data." << endl;
4882 return;
4883 }
4884
4885 if (fCanvas)
4886 {
4887 delete fCanvas;
4888 fCanvas=0;
4889 }
4890
4891 if (fAnimObject)
4892 {
4893 delete fAnimObject;
4894 fAnimObject=0;
4895 }
4896
4897 fCanvas=new TCanvas("fCanvas","Sampling animation");
4898
4899 TGraph2D* gr=new TGraph2D(fN);
4900 fAnimObject=gr;
4901
4902 TString s="Sampling animation for NcSample ";
4903 s+=GetName();
4904 gr->SetTitle(s.Data());
4905 gr->SetMarkerStyle(20);
4906 gr->SetMarkerSize(1);
4907
4908 Double_t x=0;
4909 Double_t y=0;
4910 Double_t z=0;
4911 for (Int_t ip=0; ip<fN; ip++)
4912 {
4913 x=GetEntry(ip+1,i,mode,m);
4914 y=GetEntry(ip+1,j,mode,m);
4915 z=GetEntry(ip+1,k,mode,m);
4916 gr->SetPoint(ip,x,y,z);
4917
4918 if (!ip) gr->Draw(opt.Data());
4919
4920 s="Variable ";
4921 s+=fNames[i-1];
4922 gr->GetXaxis()->SetTitle(s.Data());
4923 s="Variable ";
4924 s+=fNames[j-1];
4925 gr->GetYaxis()->SetTitle(s.Data());
4926 s="Variable ";
4927 s+=fNames[k-1];
4928 gr->GetZaxis()->SetTitle(s.Data());
4929
4930 fCanvas->Modified();
4931 fCanvas->Update();
4932
4933 gSystem->Sleep(delay);
4934 }
4935}
4936
4937void NcSample::Animation(TString nameA,TString nameB,TString nameC,Int_t mode,TString nameD,Int_t delay,TString opt)
4938{
4963
4964 Int_t i=GetIndex(nameA);
4965 Int_t j=GetIndex(nameB);
4966 Int_t k=GetIndex(nameC);
4967 Int_t m=GetIndex(nameD);
4968 Animation(i,j,k,mode,m,delay,opt);
4969}
4970
4971Double_t NcSample::Digitize(Int_t i,Int_t nbits,Double_t vcal,Int_t mode)
4972{
5035
5036 if (mode<0 || mode>3)
5037 {
5038 cout << " *NcSample::Digitize* Inconsistent input mode=" << mode << endl;
5039 return 0;
5040 }
5041
5042 if (!nbits || nbits>60 || nbits<-60 || fabs(vcal)<=0)
5043 {
5044 cout << " *NcSample::Digitize* Inconsistent input nbits=" << nbits << " vcal=" << vcal << endl;
5045 return 0;
5046 }
5047
5048 if ((mode==1 || mode==3) && nbits==1)
5049 {
5050 cout << " *NcSample::Digitize* Inconsistent input nbits=" << nbits << " mode=" << mode << endl;
5051 return 0;
5052 }
5053
5054 Bool_t logmode=kFALSE;
5055 if (nbits<0) logmode=kTRUE;
5056
5057 nbits=abs(nbits);
5058
5059 Long_t nlevels=pow(2,nbits);
5060 Double_t range=fabs(vcal);
5061 if (mode==1 || mode==3) range*=2.;
5062 Double_t step=fabs(vcal);
5063 if (mode==0) step=range/double(nlevels-1);
5064 if (mode==1) step=range/double(nlevels-2);
5065
5066 if (step<=0) return 0;
5067
5068 Long_t nstepsmin=0;
5069 Long_t nstepsmax=nlevels-1;
5070 if ((mode==0 || mode==2) && vcal<0)
5071 {
5072 nstepsmin=-nlevels+1;
5073 nstepsmax=0;
5074 }
5075 if (mode==1 || mode==3)
5076 {
5077 nstepsmin=-nlevels/2;
5078 nstepsmax=nlevels/2-1;
5079 }
5080
5081 Double_t digvalmin=double(nstepsmin)*step;
5082 Double_t digvalmax=double(nstepsmax)*step;
5083
5084 cout << " *NcSample::Digitize* Parameters of the " << nbits << "-bits";
5085 if (logmode) cout << " Log10";
5086 cout << " ADC digitization";
5087 if (i>0 && i<=fDim) cout << " of variable : " << i << " (" << fNames[i-1] << ")";
5088 cout << endl;
5089 TString s="linear";
5090 if (logmode) s="Log10";
5091 if (mode==0 || mode==2)
5092 {
5093 cout << " Digitized " << s << " full scale range : [" << digvalmin << "," << digvalmax << "] Step size : " << step << endl;
5094 }
5095 if (mode==1 || mode==3)
5096 {
5097 cout << " Digitized " << s << " full scale range : [" << (digvalmin+step) << "," << digvalmax << "] Step size : " << step;
5098 cout << " Actual range : [" << digvalmin << "," << digvalmax << "]" << endl;
5099 }
5100
5101 if (logmode)
5102 {
5103 Double_t linvalmin=pow(10,digvalmin);
5104 Double_t linvalmax=pow(10,digvalmax);
5105 if (mode==0 || mode==2)
5106 {
5107 cout << " Digitized linear full scale range : [" << linvalmin << "," << linvalmax << "]" << endl;
5108 }
5109 if (mode==1 || mode==3)
5110 {
5111 cout << " Digitized linear full scale range : [" << (linvalmin*pow(10,step)) << "," << linvalmax << "]";
5112 cout << " Actual range : [" << linvalmin << "," << linvalmax << "]" << endl;
5113 }
5114 }
5115
5116 Double_t retval=step;
5117 if (mode==2)
5118 {
5119 if (vcal<0) retval=digvalmin;
5120 if (vcal>0) retval=digvalmax;
5121 }
5122 if (mode==3) retval=digvalmax;
5123
5124 if (!fStore)
5125 {
5126 cout << endl;
5127 cout << " *NcSample::Digitize* Error : Storage mode has not been activated." << endl;
5128 return retval;
5129 }
5130
5131 Double_t minval=1;
5132 if (i>0 && i<=fDim) minval=GetMinimum(i);
5133
5134 if (logmode && minval<=0)
5135 {
5136 cout << endl;
5137 cout << " *NcSample::Digitize* Non-positive input value(s) for Log10 ADC i=" << i << " minimum=" << minval << endl;
5138 return retval;
5139 }
5140
5141 if (i<1 || i>fDim)
5142 {
5143 cout << endl;
5144 cout << " *NcSample::Digitize* Value i=" << i << " is outside range. Only listing of ADC specs." << endl;
5145 return retval;
5146 }
5147
5148 Double_t val=0;
5149 Long_t nsteps=0;
5150 Double_t digval=0;
5151 for (Int_t j=1; j<=fN; j++)
5152 {
5153 val=GetEntry(j,i);
5154
5155 if (logmode) val=log10(val);
5156
5157 nsteps=val/step;
5158
5159 if (nsteps<nstepsmin) nsteps=nstepsmin;
5160 if (nsteps>nstepsmax) nsteps=nstepsmax;
5161
5162 digval=double(nsteps)*step;
5163
5164 if (logmode) digval=pow(10,digval);
5165
5166 if (i==1) fX->AddAt(digval,j-1);
5167 if (i==2) fY->AddAt(digval,j-1);
5168 if (i==3) fZ->AddAt(digval,j-1);
5169 if (i==4) fT->AddAt(digval,j-1);
5170 }
5171
5172 return retval;
5173}
5174
5175Double_t NcSample::Digitize(TString name,Int_t nbits,Double_t vcal,Int_t mode)
5176{
5239
5240 Int_t i=GetIndex(name);
5241
5242 return Digitize(i,nbits,vcal,mode);
5243}
5244
5245TArrayL64 NcSample::ADC(Int_t nbits,Double_t range,Double_t Vbias,TArray* Vsig,TH1* hist,Int_t B,Int_t C) const
5246{
5329
5330 TArrayL64 arradc(0);
5331 if (hist) hist->Reset();
5332
5333 Int_t nVsig=0;
5334 if (Vsig) nVsig=Vsig->GetSize();
5335
5336 if (nbits<=0 || nbits>60 || !range || fabs(Vbias)>fabs(range) || B<0 || (B && C<1))
5337 {
5338 printf("\n *%-s::ADC* Inconsistent input nbits=%-i range=%-g Vbias=%-g B=%-i C=%-i \n",ClassName(),nbits,range,Vbias,B,C);
5339 return arradc;
5340 }
5341
5342 NcMath math;
5343
5344 Long64_t N=pow(2,nbits); // The number of quantization levels
5345 Long64_t adcmin=0;
5346 Long64_t adcmax=N-1;
5347 Double_t Vref=0;
5348 Double_t Vfs=0;
5349 Double_t LSB=0;
5350
5351 // Floating point version of some parameters
5352 Double_t rN=N;
5353 Double_t rB=B;
5354 if (B==1) rB=exp(1);
5355 Double_t rC=C;
5356 Double_t radcmax=adcmax;
5357
5358 if (range<0) // |range| represents Vref
5359 {
5360 Vref=fabs(range);
5361 LSB=Vref/rN;
5362 Vfs=Vref-LSB;
5363 }
5364 else // range represents Vfs
5365 {
5366 Vfs=range;
5367 LSB=Vfs/radcmax;
5368 Vref=Vfs+LSB;
5369 }
5370
5371 Long64_t ped=0;
5372 Double_t frac=0;
5373 if (B) // Log ADC
5374 {
5375 if (range<0) Vfs=pow(rB,-rC)*pow(rB,radcmax*rC/rN)*Vref;
5376 if (range>0) Vref=pow(rB,rC)*pow(rB,-radcmax*rC/rN)*Vfs;
5377 LSB=Vref*pow(rB,-rC)*(pow(rB,rC/rN)-1.);
5378 frac=Vbias/Vref;
5379 ped=0;
5380 if (frac>0) ped=Long64_t(rN*(math.Log(rB,frac)+rC)/rC);
5381 }
5382
5383 if (LSB<=0 || Vfs<=0)
5384 {
5385 printf("\n *%-s::ADC* Inconsistent parameters : LSB=%-g Vfs=%-g \n",ClassName(),LSB,Vfs);
5386 return arradc;
5387 }
5388
5389 if (!B) ped=Vbias/LSB; // Pedestal value for a linear ADC
5390
5391 Double_t DR=20.*log10(Vfs/LSB);
5392
5393 TString mode="linear";
5394 if (B==1) mode="Log_e";
5395 if (B>1)
5396 {
5397 mode="Log_";
5398 mode+=B;
5399 }
5400
5401 if (!nVsig)
5402 {
5403 printf(" *%-s::ADC* No input data have been provided --> Only the value of adc(Vbias) is returned. \n",ClassName());
5404 if (!B)
5405 {
5406 printf(" Parameters for a %-i-bits %-s ADC with adc=[%-lli,%-lli] : \n",nbits,mode.Data(),adcmin,adcmax);
5407 printf(" Vref=%-g Vfs=%-g LSB=%-g DR=%-g (dB) Vbias=%-g adc(Vbias)=%-lli \n",Vref,Vfs,LSB,DR,Vbias,ped);
5408 }
5409 else
5410 {
5411 printf(" Parameters for a %-i-bits %-s ADC with adc=[%-lli,%-lli] and a code efficiency factor of %-i: \n",nbits,mode.Data(),adcmin,adcmax,C);
5412 printf(" Vref=%-g Vfs=%-g LSB=%-g DR=%-g (dB) Vbias=%-g adc(Vbias)=%-lli \n",Vref,Vfs,LSB,DR,Vbias,ped);
5413 }
5414 arradc.Set(1);
5415 arradc[0]=ped;
5416 return arradc;
5417 }
5418
5419 arradc.Set(nVsig);
5420
5421 if (hist)
5422 {
5423 TString title;
5424 title.Form("%-s %-i-bits %-s ADC with Vfs=%-g LSB=%-g;Sample number;ADC counts",ClassName(),nbits,mode.Data(),Vfs,LSB);
5425 hist->SetBins(nVsig,0,nVsig);
5426 hist->SetMarkerStyle(20);
5427 hist->SetTitle(title);
5428 }
5429
5430 Double_t val=0;
5431 Double_t radcval=0;
5432 Long64_t adcval=0;
5433 for (Int_t j=0; j<nVsig; j++)
5434 {
5435 val=Vbias+Vsig->GetAt(j);
5436
5437 if (B) // Log ADC
5438 {
5439 radcval=0;
5440 frac=val/Vref;
5441 if (frac>0) radcval=(rN/rC)*(math.Log(rB,frac)+rC);
5442 }
5443 else // Linear ADC
5444 {
5445 radcval=val/LSB;
5446 }
5447
5448 adcval=Long64_t(radcval);
5449
5450 // Check for saturation
5451 if (adcval<adcmin) adcval=adcmin;
5452 if (adcval>adcmax) adcval=adcmax;
5453
5454 arradc[j]=adcval;
5455
5456 if (hist) hist->SetBinContent(j+1,adcval);
5457 }
5458
5459 return arradc;
5460}
5461
5462TArrayD NcSample::DAC(Int_t nbits,Double_t range,Double_t Vbias,TArray* adcs,TArray* peds,TH1* hist,Int_t B,Int_t C) const
5463{
5550
5551 TArrayD arrdac(0);
5552 if (hist) hist->Reset();
5553
5554 Int_t nadcs=0;
5555 if (adcs) nadcs=adcs->GetSize();
5556
5557 Int_t npeds=0;
5558 if (peds) npeds=peds->GetSize();
5559
5560 if (nbits<=0 || nbits>60 || !range || fabs(Vbias)>fabs(range) || (peds && npeds<nadcs) || B<0 || (B && C<1))
5561 {
5562 printf("\n *%-s::DAC* Inconsistent input nbits=%-i range=%-g Vbias=%-g nadcs=%-i npeds=%-i B=%-i C=%-i \n",ClassName(),nbits,range,Vbias,nadcs,npeds,B,C);
5563 return arrdac;
5564 }
5565
5566 NcMath math;
5567
5568 Long64_t N=pow(2,nbits); // The number of quantization levels
5569 Long64_t adcmin=0;
5570 Long64_t adcmax=N-1;
5571 Double_t Vref=0;
5572 Double_t Vfs=0;
5573 Double_t LSB=0;
5574
5575 // Floating point version of some parameters
5576 Double_t rN=N;
5577 Double_t rB=B;
5578 if (B==1) rB=exp(1);
5579 Double_t rC=C;
5580 Double_t radcmax=adcmax;
5581
5582 if (range<0) // |range| represents Vref
5583 {
5584 Vref=fabs(range);
5585 LSB=Vref/rN;
5586 Vfs=Vref-LSB;
5587 }
5588 else // range represents Vfs
5589 {
5590 Vfs=range;
5591 LSB=Vfs/radcmax;
5592 Vref=Vfs+LSB;
5593 }
5594
5595 Long64_t ped=0;
5596 Double_t frac=0;
5597 if (B) // Log DAC
5598 {
5599 if (range<0) Vfs=pow(rB,-rC)*pow(rB,radcmax*rC/rN)*Vref;
5600 if (range>0) Vref=pow(rB,rC)*pow(rB,-radcmax*rC/rN)*Vfs;
5601 LSB=Vref*pow(rB,-rC)*(pow(rB,rC/rN)-1.);
5602 frac=Vbias/Vref;
5603 ped=0;
5604 if (frac>0) ped=Long64_t(rN*(math.Log(rB,frac)+rC)/rC);
5605 }
5606
5607 if (LSB<=0 || Vfs<=0)
5608 {
5609 printf("\n *%-s::DAC* Inconsistent parameters : LSB=%-g Vfs=%-g \n",ClassName(),LSB,Vfs);
5610 return arrdac;
5611 }
5612
5613 if (!B) ped=Vbias/LSB; // Pedestal value for a linear DAC
5614
5615 Double_t DR=20.*log10(Vfs/LSB);
5616
5617 TString mode="linear";
5618 if (B==1) mode="Log_e";
5619 if (B>1)
5620 {
5621 mode="Log_";
5622 mode+=B;
5623 }
5624
5625 if (!nadcs)
5626 {
5627 printf(" *%-s::DAC* No input data have been provided --> Only the value of adc(Vbias) is returned. \n",ClassName());
5628 if (!B)
5629 {
5630 printf(" Parameters for a %-i-bits %-s DAC with adc=[%-lli,%-lli] : \n",nbits,mode.Data(),adcmin,adcmax);
5631 printf(" Vref=%-g Vfs=%-g LSB=%-g DR=%-g (dB) Vbias=%-g adc(Vbias)=%-lli \n",Vref,Vfs,LSB,DR,Vbias,ped);
5632 }
5633 else
5634 {
5635 printf(" Parameters for a %-i-bits %-s DAC with adc=[%-lli,%-lli] and a code efficiency factor of %-i: \n",nbits,mode.Data(),adcmin,adcmax,C);
5636 printf(" Vref=%-g Vfs=%-g LSB=%-g DR=%-g (dB) Vbias=%-g adc(Vbias)=%-lli \n",Vref,Vfs,LSB,DR,Vbias,ped);
5637 }
5638 arrdac.Set(1);
5639 arrdac[0]=ped;
5640 return arrdac;
5641 }
5642
5643 arrdac.Set(nadcs);
5644
5645 if (hist)
5646 {
5647 TString title;
5648 title.Form("%-s %-i-bits %-s DAC with Vfs=%-g LSB=%-g;Sample number;Amplitude",ClassName(),nbits,mode.Data(),Vfs,LSB);
5649 hist->SetBins(nadcs,0,nadcs);
5650 hist->SetMarkerStyle(20);
5651 hist->SetTitle(title);
5652 }
5653
5654 Long64_t adc=0;
5655 Double_t radc=0;
5656 Double_t dacval=0;
5657 for (Int_t j=0; j<nadcs; j++)
5658 {
5659 adc=adcs->GetAt(j);
5660 radc=adc;
5661
5662 if (B) // Log DAC
5663 {
5664 dacval=Vref*pow(rB,-rC)*pow(rB,radc*rC/rN);
5665 }
5666 else // Linear DAC
5667 {
5668 if (peds)
5669 {
5670 ped=peds->GetAt(j);
5671 adc=adc-ped;
5672 radc=adc;
5673 }
5674 dacval=radc*LSB;
5675 }
5676
5677 // Correct for bias voltage
5678 if (B || (!B && !peds))
5679 {
5680 dacval=dacval-Vbias;
5681 }
5682
5683 arrdac[j]=dacval;
5684
5685 if (hist) hist->SetBinContent(j+1,dacval);
5686 }
5687
5688 return arrdac;
5689}
5690
5691Long64_t NcSample::Transmit(Int_t i,Int_t nbits,Double_t range,Double_t Vbias,TArray* peds,TH1* hist,Int_t B,Int_t C)
5692{
5765
5766 TArrayL64 adcarr;
5767 TArrayD dacarr;
5768 if (hist) hist->Reset();
5769
5770 if (!fStore)
5771 {
5772 printf("\n *%-s::Transmit* Error : Storage mode has not been activated. \n",ClassName());
5773 printf(" No digitization is performed. \n");
5774 return -1;
5775 }
5776
5777 if (i<1 || i>fDim)
5778 {
5779 printf("\n *%-s::Transmit* Invalid variable name or index (i=%-i) --> Only listing of ADC specs. \n",ClassName(),i);
5780 adcarr=ADC(nbits,range,Vbias,0,0,B,C);
5781 return adcarr[0];
5782 }
5783
5784 if (!fN)
5785 {
5786 printf("\n *%-s::Transmit* No data available for variable %-s (index=%-i) --> Only listing of ADC specs. \n",ClassName(),fNames[i-1].Data(),i);
5787 adcarr=ADC(nbits,range,Vbias,0,0,B,C);
5788 return adcarr[0];
5789 }
5790
5791 Double_t minval=GetMinimum(i);
5792 Double_t Vin=minval+Vbias;
5793
5794 if (B && Vin<=0)
5795 {
5796 TString mode="Log_e";
5797 if (B>1)
5798 {
5799 mode="Log_";
5800 mode+=B;
5801 }
5802 printf("\n *%-s::Transmit* Non-positive input value(s) for %-s ADC --> No digitization is performed. \n",ClassName(),mode.Data());
5803 printf(" Minimum+Vbias=%-g+%-g=%-g for variable with name %-s (index i=%-i). \n",minval,Vbias,Vin,fNames[i-1].Data(),i);
5804 return -1;
5805 }
5806
5807 // Get the corresponding data array
5808 TArrayD* arrin=0;
5809 if (i==1) arrin=fX;
5810 if (i==2) arrin=fY;
5811 if (i==3) arrin=fZ;
5812 if (i==4) arrin=fT;
5813
5814 // Perform the digitization via the ADC processeor
5815 adcarr=ADC(nbits,range,Vbias,arrin,0,B,C);
5816
5817 // Convert the digital data into analog signals via the DAC processor
5818 dacarr=DAC(nbits,range,Vbias,&adcarr,peds,hist,B,C);
5819
5820 if (hist)
5821 {
5822 TString title=hist->GetTitle();
5823 title.ReplaceAll("DAC","ADC-DAC (Transmit)");
5824 hist->SetTitle(title);
5825 }
5826
5827 Int_t ndac=dacarr.GetSize();
5828 if (ndac<fN)
5829 {
5830 printf("\n *%-s::Transmit* Inconsistent number of entries : Nsamplings=%-i Ndac=%-i --> No digitization is performed. \n",ClassName(),fN,ndac);
5831 return -1;
5832 }
5833
5834 // Replace the values of the i-th variable
5835 Double_t val=0;
5836 for (Int_t j=0; j<fN; j++)
5837 {
5838 val=dacarr[j];
5839 arrin->AddAt(val,j);
5840 }
5841
5842 return -1;
5843}
5844
5845Long64_t NcSample::Transmit(TString name,Int_t nbits,Double_t range,Double_t Vbias,TArray* peds,TH1* hist,Int_t B,Int_t C)
5846{
5920
5921 Int_t i=GetIndex(name);
5922
5923 return Transmit(i,nbits,range,Vbias,peds,hist,B,C);
5924}
5925
5926NcSample NcSample::SampleAndHold(TF1 f,Double_t step,Double_t vmin,Double_t vmax,Int_t loc) const
5927{
5946
5947 NcSample s("SampleAndHold","Error occurred in SampleAndHold");
5948 s.SetStoreMode(1);
5949
5950 if (step<=0 || vmax<=vmin)
5951 {
5952 cout << " *NcSample::SampleAndHold* Error : Invalid input step=" << step << " vmin=" << vmin << " vmax=" << vmax << endl;
5953 return s;
5954 }
5955
5956 TString str="For Function ";
5957 str+=f.GetExpFormula("p");
5958 str+=" with step=%-10.3g";
5959 TString str2=str.Format(str.Data(),step);
5960 s.SetTitle(str2.Data());
5961
5962 // Enter the sampled data into the new sample
5963 Double_t xlow=vmin;
5964 Double_t xval=0;
5965 Double_t yval=0;
5966 while (xlow<=vmax)
5967 {
5968 yval=f.Eval(xlow);
5969 if (loc<0) xval=xlow;
5970 if (!loc) xval=xlow+step/2.;
5971 if (loc>0) xval=xlow+step;
5972 if (xval>vmax) xval=vmax;
5973 s.Enter(xval,yval);
5974
5975 xlow+=step;
5976 }
5977
5978 return s;
5979}
5980
5981NcSample NcSample::SampleAndSum(Int_t i,Double_t step,Int_t loc,Int_t j,Double_t vmin,Double_t vmax)
5982{
6009
6010 NcSample s("SampleAndSum","Error occurred in SampleAndSum");
6011 s.SetStoreMode(1);
6012
6013 if (!fStore)
6014 {
6015 cout << " *NcSample::SampleAndSum* Error : Storage mode has not been activated." << endl;
6016 return s;
6017 }
6018
6019 if (i<1 || i>fDim || j>fDim)
6020 {
6021 cout << " *NcSample::SampleAndSum* Error : Invalid index encountered i=" << i << " j=" << j << endl;
6022 return s;
6023 }
6024
6025 if (step<=0)
6026 {
6027 cout << " *NcSample::SampleAndSum* Error : Invalid step size step=" << step << endl;
6028 return s;
6029 }
6030
6031 TString xname=fNames[i-1];
6032 TString yname="Counts";
6033 if (j>0) yname=fNames[j-1];
6034
6035 s.SetNames(xname,yname);
6036
6037 TString str="For Variable ";
6038 str+=xname;
6039 str+=" with step=%-10.3g";
6040 TString str2=str.Format(str.Data(),step);
6041 s.SetTitle(str2.Data());
6042
6043 // Define a histogram with "step" as binsize
6044 Double_t xmin=GetMinimum(i);
6045 Double_t xmax=GetMaximum(i);
6046
6047 if (vmax>vmin)
6048 {
6049 xmin=vmin;
6050 xmax=vmax;
6051 }
6052
6053 Int_t nbx=(xmax-xmin)/step;
6054 nbx++;
6055
6056 Double_t* bins=new Double_t[nbx+1];
6057 Double_t xlow=xmin;
6058 for (Int_t idx=0; idx<=nbx; idx++)
6059 {
6060 bins[idx]=xlow;
6061 xlow+=step;
6062 }
6063
6064 TH1D hist("","",nbx,bins);
6065
6066 // Fill the histogram with data of the original sample
6067 Double_t xval=0;
6068 Double_t yval=1;
6069 for (Int_t ient=1; ient<=fN; ient++)
6070 {
6071 xval=GetEntry(ient,i);
6072 if (j>0) yval=GetEntry(ient,j);
6073 hist.Fill(xval,yval);
6074 }
6075
6076 // Enter the histgram data into the new sample
6077 Int_t nbins=hist.GetNbinsX();
6078 Double_t binwidth=hist.GetBinWidth(1);
6079 for (Int_t k=1; k<=nbins; k++)
6080 {
6081 if (loc) xval=hist.GetBinLowEdge(k);
6082 if (!loc) xval=hist.GetBinCenter(k);
6083 if (loc>0) xval+=binwidth;
6084 yval=hist.GetBinContent(k);
6085 s.Enter(xval,yval);
6086 }
6087
6088 delete [] bins;
6089 return s;
6090}
6091
6092NcSample NcSample::SampleAndSum(TString nameA,Double_t step,Int_t loc,TString nameB,Double_t vmin,Double_t vmax)
6093{
6119
6120 Int_t i=GetIndex(nameA);
6121 Int_t j=GetIndex(nameB);
6122
6123 return SampleAndSum(i,step,loc,j,vmin,vmax);
6124}
6125
6126TObject* NcSample::Clone(const char* name) const
6127{
6137
6138 NcSample* q=new NcSample(*this);
6139 if (name)
6140 {
6141 if (strlen(name)) q->SetName(name);
6142 }
6143 return q;
6144}
6145
ClassImp(NcSample)
Various mathematical tools for scientific analysis.
Definition NcMath.h:26
Double_t Log(Double_t B, Double_t x) const
Definition NcMath.cxx:2613
Sampling and statistics tools for various multi-dimensional data samples.
Definition NcSample.h:28
Long64_t Transmit(Int_t i, Int_t nbits, Double_t range, Double_t Vbias=0, TArray *peds=0, TH1 *hist=0, Int_t B=0, Int_t C=3)
TGraphQQ GetQQplot(Int_t i, Int_t j, TF1 *f=0)
void Order(Int_t mode, Int_t i)
Definition NcSample.cxx:994
Double_t GetSNR(Int_t i, Int_t mode=2, Bool_t db=kTRUE) const
TCanvas * fCanvas
! Multi-purpose canvas for e.g. animation displays
Definition NcSample.h:165
Int_t fRemove
Definition NcSample.h:153
Int_t GetStoreMode() const
Double_t fRMSdev[fMaxdim]
Definition NcSample.h:147
TH3D Get3DHistogram(Int_t i, Int_t j, Int_t k, Int_t m=0, Bool_t sumw2=kFALSE, Int_t nbx=100, Int_t nby=100, Int_t nbz=100, TF1 *f=0)
void Data(Int_t i=0, Int_t j=0)
Double_t GetCov(Int_t i, Int_t j) const
virtual TObject * Clone(const char *name="") const
TObject * fAnimObject
! Multi-purpose pointer for animation objects
Definition NcSample.h:166
void GetSubset(NcSample *s, Int_t ifirst, Int_t ilast, Int_t mode=0, Int_t k=0)
Int_t GetN() const
TArrayD * fX
Definition NcSample.h:157
Double_t GetMinimum(Int_t i) const
TArrayL64 ADC(Int_t nbits, Double_t range, Double_t Vbias=0, TArray *Vsig=0, TH1 *hist=0, Int_t B=0, Int_t C=3) const
Double_t fMin[fMaxdim]
Definition NcSample.h:151
virtual ~NcSample()
Definition NcSample.cxx:120
Int_t GetIndex(TString name) const
Double_t fSum[fMaxdim]
Definition NcSample.h:144
TH1D Get1DHistogram(Int_t i, Int_t j=0, Bool_t sumw2=kFALSE, Int_t nbx=100, TF1 *f=0)
Double_t GetCor(Int_t i, Int_t j) const
TArrayD * fArr
! Temp. storage array for ordered values
Definition NcSample.h:161
Double_t fCor[fMaxdim][fMaxdim]
Definition NcSample.h:150
TString fNames[fMaxdim]
Definition NcSample.h:143
Double_t fSum2[fMaxdim][fMaxdim]
Definition NcSample.h:145
Int_t fN
Definition NcSample.h:141
void List(Int_t i)
Double_t GetSigma(Int_t i, Int_t model=0) const
void Compute()
TGraphTime * fGraphT
! Temp. pointer to return a TGraphTime object
Definition NcSample.h:164
Double_t GetMedian(Int_t i)
void Animation(Int_t i, Int_t j, Int_t mode, Int_t k, Int_t delay, TString opt="AP")
TGraphErrors GetGraphErrors(TGraph *g, Int_t ix=0, Int_t iy=0, TF1 *fx=0, TF1 *fy=0)
TArrayD * fT
Definition NcSample.h:160
TH1D GetSamplingHistogram(Int_t i, TF1 *f=0)
Int_t fNmax
Definition NcSample.h:155
Int_t fDim
Definition NcSample.h:140
Int_t GetStoreNmax() const
void Reset()
Definition NcSample.cxx:255
NcSample SampleAndHold(TF1 f, Double_t step, Double_t vmin, Double_t vmax, Int_t loc=-1) const
Int_t fOrdered
! Indicator of the status of the current ordering
Definition NcSample.h:163
Double_t GetRMS(Int_t i) const
void Enter(Double_t x)
Definition NcSample.cxx:360
void SetNames(TString name1="X", TString name2="Y", TString name3="Z", TString name4="T")
Definition NcSample.cxx:330
Int_t fStore
Definition NcSample.h:154
Double_t Digitize(Int_t i, Int_t nbits, Double_t vcal, Int_t mode)
NcSample GetDtSample(Int_t i, Int_t nc, Int_t store=1, Int_t nmax=0, Int_t order=0)
TArrayD * fY
Definition NcSample.h:158
Double_t fCov[fMaxdim][fMaxdim]
Definition NcSample.h:149
TArrayD * fZ
Definition NcSample.h:159
Double_t fMax[fMaxdim]
Definition NcSample.h:152
Double_t GetMean(Int_t i) const
TArrayD DAC(Int_t nbits, Double_t range, Double_t Vbias=0, TArray *adcs=0, TArray *peds=0, TH1 *hist=0, Int_t B=0, Int_t C=3) const
void RemoveEntry(Int_t i, Int_t mode, Int_t j)
Definition NcSample.cxx:861
void ListOrdered(Int_t mode, Int_t i)
Double_t fMean[fMaxdim]
Definition NcSample.h:146
void SetStoreMode(Int_t mode=100, Int_t nmax=0, Int_t i=0)
Double_t fSigma[fMaxdim]
Definition NcSample.h:148
TString GetVariableName(Int_t i) const
TArrayI * fIndices
! Temp. storage array for the indices of the ordered entries
Definition NcSample.h:162
Int_t GetDimension() const
TGraph GetGraph(Int_t i, TF1 *f=0)
Double_t GetVar(Int_t i, Int_t model=0) const
Double_t GetMaximum(Int_t i) const
void Load(TGraph *g, Int_t clr=1)
Double_t GetCV(Int_t i, Int_t mode=1) const
Double_t GetSpread(Int_t i, Int_t model=0, Double_t vref=0)
Double_t GetQuantile(Double_t f, Int_t i)
Double_t GetEntry(Int_t i, Int_t j, Int_t mode=0, Int_t k=0)
TGraph2DErrors GetGraph2DErrors(TGraph2D *g, Int_t ix=0, Int_t iy=0, Int_t iz=0, TF1 *fx=0, TF1 *fy=0, TF1 *fz=0)
void Remove(Double_t x)
Definition NcSample.cxx:413
NcSample(const char *name="", const char *title="")
Definition NcSample.cxx:91
TH2D Get2DHistogram(Int_t i, Int_t j, Int_t k=0, Bool_t sumw2=kFALSE, Int_t nbx=100, Int_t nby=100, TF1 *f=0)
Double_t GetSum(Int_t i) const
NcSample SampleAndSum(Int_t i, Double_t step, Int_t loc=0, Int_t j=0, Double_t vmin=0, Double_t vmax=-1)
Int_t fMoveVariable
Definition NcSample.h:156