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 (fX) fX->Set(10);
286 if (fY) fY->Set(10);
287 if (fZ) fZ->Set(10);
288 if (fT) fT->Set(10);
289
290 // Resetting the variable names to their defaults
291 SetNames();
292
293 // Delete the temp. storage arrays for ordering
294 if (fArr)
295 {
296 delete fArr;
297 fArr=0;
298 }
299 if (fIndices)
300 {
301 delete fIndices;
302 fIndices=0;
303 }
304
305 // Delete the temp. TGraphTime pointer
306 if (fGraphT)
307 {
308 delete fGraphT;
309 fGraphT=0;
310 }
311
312 // Delete the multi-purpose canvas
313 if (fCanvas)
314 {
315 delete fCanvas;
316 fCanvas=0;
317 }
318
319 // Delete the multi-purpose animation object
320 if (fAnimObject)
321 {
322 delete fAnimObject;
323 fAnimObject=0;
324 }
325}
326
327void NcSample::SetNames(TString name1,TString name2,TString name3,TString name4)
328{
343
344 if (!fN)
345 {
346 fNames[0]=name1;
347 fNames[1]=name2;
348 fNames[2]=name3;
349 fNames[3]=name4;
350 }
351 else
352 {
353 cout << " *NcSample::SetNames* Names not modified, since data were already present." << endl;
354 }
355}
356
357void NcSample::Enter(Double_t x)
358{
365
366 if (!fN)
367 {
368 fDim=1;
369 fNames[1]="";
370 fNames[2]="";
371 fNames[3]="";
372 }
373
374 if (fDim != 1)
375 {
376 cout << " *NcSample::Enter* Error : Not a 1-dim sample." << endl;
377 return;
378 }
379
380 // Remove (after re-ordering) the first entry if needed
382
383 fN+=1;
384 fSum[0]+=x;
385 fSum2[0][0]+=x*x;
386
387 if (fN==1)
388 {
389 fMin[0]=x;
390 fMax[0]=x;
391 }
392 else
393 {
394 if (x<fMin[0]) fMin[0]=x;
395 if (x>fMax[0]) fMax[0]=x;
396 }
397
398 // Store all entered data when storage mode has been selected
399 if (fStore)
400 {
401 if (!fX) fX=new TArrayD(10);
402 if (fX->GetSize() < fN) fX->Set(fN+10);
403 fX->AddAt(x,fN-1);
404 }
405
406 // Compute the various statistics
407 Compute();
408}
409
410void NcSample::Remove(Double_t x)
411{
417
418 if (!fN) return;
419
420 if (fDim != 1)
421 {
422 cout << " *NcSample::Remove* Error : Not a 1-dim sample." << endl;
423 return;
424 }
425
426 fRemove=1;
427 fN-=1;
428 fSum[0]-=x;
429 fSum2[0][0]-=x*x;
430
431 // Remove data entry from the storage
432 if (fStore && fX)
433 {
434 Double_t val=0;
435 for (Int_t i=0; i<=fN; i++)
436 {
437 val=fX->At(i);
438 if (fabs(x-val)>1.e-10) continue;
439
440 for (Int_t j=i+1; j<=fN; j++)
441 {
442 val=fX->At(j);
443 fX->AddAt(val,j-1);
444 }
445 }
446 }
447
448 // Compute the various statistics
449 Compute();
450}
451
452void NcSample::Enter(Double_t x,Double_t y)
453{
460
461 if (!fN)
462 {
463 fDim=2;
464 fNames[2]="";
465 fNames[3]="";
466 }
467
468 if (fDim != 2)
469 {
470 cout << " *NcSample::Enter* Error : Not a 2-dim sample." << endl;
471 return;
472 }
473
474 // Remove (after re-ordering) the first entry if needed
476
477 fN+=1;
478 fSum[0]+=x;
479 fSum[1]+=y;
480 fSum2[0][0]+=x*x;
481 fSum2[0][1]+=x*y;
482 fSum2[1][0]+=y*x;
483 fSum2[1][1]+=y*y;
484
485 if (fN==1)
486 {
487 fMin[0]=x;
488 fMax[0]=x;
489 fMin[1]=y;
490 fMax[1]=y;
491 }
492 else
493 {
494 if (x<fMin[0]) fMin[0]=x;
495 if (x>fMax[0]) fMax[0]=x;
496 if (y<fMin[1]) fMin[1]=y;
497 if (y>fMax[1]) fMax[1]=y;
498 }
499
500 // Store all entered data when storage mode has been selected
501 if (fStore)
502 {
503 if (!fX) fX=new TArrayD(10);
504 if (fX->GetSize() < fN) fX->Set(fN+10);
505 fX->AddAt(x,fN-1);
506 if (!fY) fY=new TArrayD(10);
507 if (fY->GetSize() < fN) fY->Set(fN+10);
508 fY->AddAt(y,fN-1);
509 }
510
511 // Compute the various statistics
512 Compute();
513}
514
515void NcSample::Remove(Double_t x,Double_t y)
516{
522
523 if (!fN) return;
524
525 if (fDim != 2)
526 {
527 cout << " *NcSample::Remove* Error : Not a 2-dim sample." << endl;
528 return;
529 }
530
531 fRemove=1;
532 fN-=1;
533 fSum[0]-=x;
534 fSum[1]-=y;
535 fSum2[0][0]-=x*x;
536 fSum2[0][1]-=x*y;
537 fSum2[1][0]-=y*x;
538 fSum2[1][1]-=y*y;
539
540 // Remove data entry from the storage
541 if (fStore && fX && fY)
542 {
543 Double_t val=0;
544 for (Int_t i=0; i<=fN; i++)
545 {
546 val=fX->At(i);
547 if (fabs(x-val)>1.e-10) continue;
548 val=fY->At(i);
549 if (fabs(y-val)>1.e-10) continue;
550
551 for (Int_t j=i+1; j<=fN; j++)
552 {
553 val=fX->At(j);
554 fX->AddAt(val,j-1);
555 val=fY->At(j);
556 fY->AddAt(val,j-1);
557 }
558 }
559 }
560
561 // Compute the various statistics
562 Compute();
563}
564
565void NcSample::Enter(Double_t x,Double_t y,Double_t z)
566{
573
574 if (!fN)
575 {
576 fDim=3;
577 fNames[3]="";
578 }
579
580 if (fDim != 3)
581 {
582 cout << " *NcSample::Enter* Error : Not a 3-dim sample." << endl;
583 return;
584 }
585
586 // Remove (after re-ordering) the first entry if needed
588
589 fN+=1;
590 fSum[0]+=x;
591 fSum[1]+=y;
592 fSum[2]+=z;
593 fSum2[0][0]+=x*x;
594 fSum2[0][1]+=x*y;
595 fSum2[0][2]+=x*z;
596 fSum2[1][0]+=y*x;
597 fSum2[1][1]+=y*y;
598 fSum2[1][2]+=y*z;
599 fSum2[2][0]+=z*x;
600 fSum2[2][1]+=z*y;
601 fSum2[2][2]+=z*z;
602
603 if (fN==1)
604 {
605 fMin[0]=x;
606 fMax[0]=x;
607 fMin[1]=y;
608 fMax[1]=y;
609 fMin[2]=z;
610 fMax[2]=z;
611 }
612 else
613 {
614 if (x<fMin[0]) fMin[0]=x;
615 if (x>fMax[0]) fMax[0]=x;
616 if (y<fMin[1]) fMin[1]=y;
617 if (y>fMax[1]) fMax[1]=y;
618 if (z<fMin[2]) fMin[2]=z;
619 if (z>fMax[2]) fMax[2]=z;
620 }
621
622 // Store all entered data when storage mode has been selected
623 if (fStore)
624 {
625 if (!fX) fX=new TArrayD(10);
626 if (fX->GetSize() < fN) fX->Set(fN+10);
627 fX->AddAt(x,fN-1);
628 if (!fY) fY=new TArrayD(10);
629 if (fY->GetSize() < fN) fY->Set(fN+10);
630 fY->AddAt(y,fN-1);
631 if (!fZ) fZ=new TArrayD(10);
632 if (fZ->GetSize() < fN) fZ->Set(fN+10);
633 fZ->AddAt(z,fN-1);
634 }
635
636 // Compute the various statistics
637 Compute();
638}
639
640void NcSample::Remove(Double_t x,Double_t y,Double_t z)
641{
647
648 if (!fN) return;
649
650 if (fDim != 3)
651 {
652 cout << " *NcSample::Remove* Error : Not a 3-dim sample." << endl;
653 return;
654 }
655
656 fRemove=1;
657 fN-=1;
658 fSum[0]-=x;
659 fSum[1]-=y;
660 fSum[2]-=z;
661 fSum2[0][0]-=x*x;
662 fSum2[0][1]-=x*y;
663 fSum2[0][2]-=x*z;
664 fSum2[1][0]-=y*x;
665 fSum2[1][1]-=y*y;
666 fSum2[1][2]-=y*z;
667 fSum2[2][0]-=z*x;
668 fSum2[2][1]-=z*y;
669 fSum2[2][2]-=z*z;
670
671 // Remove data entry from the storage
672 if (fStore && fX && fY && fZ)
673 {
674 Double_t val=0;
675 for (Int_t i=0; i<=fN; i++)
676 {
677 val=fX->At(i);
678 if (fabs(x-val)>1.e-10) continue;
679 val=fY->At(i);
680 if (fabs(y-val)>1.e-10) continue;
681 val=fZ->At(i);
682 if (fabs(z-val)>1.e-10) continue;
683
684 for (Int_t j=i+1; j<=fN; j++)
685 {
686 val=fX->At(j);
687 fX->AddAt(val,j-1);
688 val=fY->At(j);
689 fY->AddAt(val,j-1);
690 val=fZ->At(j);
691 fZ->AddAt(val,j-1);
692 }
693 }
694 }
695
696 // Compute the various statistics
697 Compute();
698}
699
700void NcSample::Enter(Double_t x,Double_t y,Double_t z,Double_t t)
701{
708
709 if (!fN) fDim=4;
710
711 if (fDim != 4)
712 {
713 cout << " *NcSample::Enter* Error : Not a 4-dim sample." << endl;
714 return;
715 }
716
717 // Remove (after re-ordering) the first entry if needed
719
720 fN+=1;
721 fSum[0]+=x;
722 fSum[1]+=y;
723 fSum[2]+=z;
724 fSum[3]+=t;
725 fSum2[0][0]+=x*x;
726 fSum2[0][1]+=x*y;
727 fSum2[0][2]+=x*z;
728 fSum2[0][3]+=x*t;
729 fSum2[1][0]+=y*x;
730 fSum2[1][1]+=y*y;
731 fSum2[1][2]+=y*z;
732 fSum2[1][3]+=y*t;
733 fSum2[2][0]+=z*x;
734 fSum2[2][1]+=z*y;
735 fSum2[2][2]+=z*z;
736 fSum2[2][3]+=z*t;
737 fSum2[3][0]+=t*x;
738 fSum2[3][1]+=t*y;
739 fSum2[3][2]+=t*z;
740 fSum2[3][3]+=t*t;
741
742 if (fN==1)
743 {
744 fMin[0]=x;
745 fMax[0]=x;
746 fMin[1]=y;
747 fMax[1]=y;
748 fMin[2]=z;
749 fMax[2]=z;
750 fMin[3]=t;
751 fMax[3]=t;
752 }
753 else
754 {
755 if (x<fMin[0]) fMin[0]=x;
756 if (x>fMax[0]) fMax[0]=x;
757 if (y<fMin[1]) fMin[1]=y;
758 if (y>fMax[1]) fMax[1]=y;
759 if (z<fMin[2]) fMin[2]=z;
760 if (z>fMax[2]) fMax[2]=z;
761 if (t<fMin[3]) fMin[3]=t;
762 if (t>fMax[3]) fMax[3]=t;
763 }
764
765 // Store all entered data when storage mode has been selected
766 if (fStore)
767 {
768 if (!fX) fX=new TArrayD(10);
769 if (fX->GetSize() < fN) fX->Set(fN+10);
770 fX->AddAt(x,fN-1);
771 if (!fY) fY=new TArrayD(10);
772 if (fY->GetSize() < fN) fY->Set(fN+10);
773 fY->AddAt(y,fN-1);
774 if (!fZ) fZ=new TArrayD(10);
775 if (fZ->GetSize() < fN) fZ->Set(fN+10);
776 fZ->AddAt(z,fN-1);
777 if (!fT) fT=new TArrayD(10);
778 if (fT->GetSize() < fN) fT->Set(fN+10);
779 fT->AddAt(t,fN-1);
780 }
781
782 // Compute the various statistics
783 Compute();
784}
785
786void NcSample::Remove(Double_t x,Double_t y,Double_t z,Double_t t)
787{
793
794 if (!fN) return;
795
796 if (fDim != 4)
797 {
798 cout << " *NcSample::Remove* Error : Not a 4-dim sample." << endl;
799 return;
800 }
801
802 fRemove=1;
803 fN-=1;
804 fSum[0]-=x;
805 fSum[1]-=y;
806 fSum[2]-=z;
807 fSum[3]-=t;
808 fSum2[0][0]-=x*x;
809 fSum2[0][1]-=x*y;
810 fSum2[0][2]-=x*z;
811 fSum2[0][3]-=x*t;
812 fSum2[1][0]-=y*x;
813 fSum2[1][1]-=y*y;
814 fSum2[1][2]-=y*z;
815 fSum2[1][3]-=y*t;
816 fSum2[2][0]-=z*x;
817 fSum2[2][1]-=z*y;
818 fSum2[2][2]-=z*z;
819 fSum2[2][3]-=z*t;
820 fSum2[3][0]-=t*x;
821 fSum2[3][1]-=t*y;
822 fSum2[3][2]-=t*z;
823 fSum2[3][3]-=t*t;
824
825 // Remove data entry from the storage
826 if (fStore && fX && fY && fZ && fT)
827 {
828 Double_t val=0;
829 for (Int_t i=0; i<=fN; i++)
830 {
831 val=fX->At(i);
832 if (fabs(x-val)>1.e-10) continue;
833 val=fY->At(i);
834 if (fabs(y-val)>1.e-10) continue;
835 val=fZ->At(i);
836 if (fabs(z-val)>1.e-10) continue;
837 val=fT->At(i);
838 if (fabs(t-val)>1.e-10) continue;
839
840 for (Int_t j=i+1; j<=fN; j++)
841 {
842 val=fX->At(j);
843 fX->AddAt(val,j-1);
844 val=fY->At(j);
845 fY->AddAt(val,j-1);
846 val=fZ->At(j);
847 fZ->AddAt(val,j-1);
848 val=fT->At(j);
849 fT->AddAt(val,j-1);
850 }
851 }
852 }
853
854 // Compute the various statistics
855 Compute();
856}
857
858void NcSample::RemoveEntry(Int_t i,Int_t mode,Int_t j)
859{
881
882 if (fDim<1 || fN<=0 || i<1 || i>fN) return;
883
884 if (mode && (j<1 || j>fDim))
885 {
886 cout << " *NcSample::RemoveEntry* Error : Invalide argument j=" << j << endl;
887 return;
888 }
889
890 if (!fStore)
891 {
892 cout << " *NcSample::RemoveEntry* Error : Storage of data entries was not activated." << endl;
893 return;
894 }
895
896 Order(mode,j);
897
898 // Get the corresponding original entry index
899 Int_t idx=fIndices->At(i-1);
900
901 Double_t x=0;
902 Double_t y=0;
903 Double_t z=0;
904 Double_t t=0;
905
906 if (fX) x=GetEntry(idx+1,1);
907 if (fY) y=GetEntry(idx+1,2);
908 if (fZ) z=GetEntry(idx+1,3);
909 if (fT) t=GetEntry(idx+1,4);
910
911 if (fDim==1) Remove(x);
912 if (fDim==2) Remove(x,y);
913 if (fDim==3) Remove(x,y,z);
914 if (fDim==4) Remove(x,y,z,t);
915}
916
917void NcSample::RemoveEntry(Int_t i,Int_t mode,TString name)
918{
940
941 Int_t j=GetIndex(name);
942 RemoveEntry(i,mode,j);
943}
944
945void NcSample::RemoveEntry(Int_t i,Int_t j,Int_t mode,Int_t k)
946{
961
962 for (Int_t m=i; m<=j; m++)
963 {
964 RemoveEntry(i,mode,k);
965 }
966}
967
968void NcSample::RemoveEntry(Int_t i,Int_t j,Int_t mode,TString name)
969{
984
985 for (Int_t m=i; m<=j; m++)
986 {
987 RemoveEntry(i,mode,name);
988 }
989}
990
991void NcSample::Order(Int_t mode,Int_t i)
992{
1007
1008 if (mode && (i<1 || i>fDim))
1009 {
1010 cout << " *NcSample::Order* Error : Invalide argument i=" << i << endl;
1011 return;
1012 }
1013
1014 if (fDim<1)
1015 {
1016 cout << " *NcSample::Order* Error : Dimension less than 1." << endl;
1017 return;
1018 }
1019
1020 if (!fStore)
1021 {
1022 cout << " *NcSample::Order* Error : Storage of data entries was not activated." << endl;
1023 return;
1024 }
1025
1026 if (fN<=0)
1027 {
1028 fOrdered=0;
1029 return;
1030 }
1031
1032 // Use i=1 for mode=0 to obtain a correct setting of the ordering status word.
1033 if (!mode) i=1;
1034
1035 // Set the corresponding ordering status word
1036 Int_t iword=10*abs(mode)+i;
1037 if (mode<0) iword*=-1;
1038
1039 // No new ordering needed if the ordering status word hasn't changed
1040 if (iword==fOrdered) return;
1041
1042 // Store the new ordering status word
1043 fOrdered=iword;
1044
1045 // Prepare temp. array to hold the ordered values
1046 if (!fArr)
1047 {
1048 fArr=new TArrayD(fN);
1049 }
1050 else
1051 {
1052 if (fArr->GetSize() < fN) fArr->Set(fN);
1053 }
1054
1055 // Prepare temp. array to hold the ordered indices
1056 if (!fIndices)
1057 {
1058 fIndices=new TArrayI(fN);
1059 }
1060 else
1061 {
1062 if (fIndices->GetSize() < fN) fIndices->Set(fN);
1063 }
1064
1065 Double_t val=0;
1066
1067 // Just the order in which the entries were entered
1068 if (!mode)
1069 {
1070 for (Int_t j=0; j<fN; j++)
1071 {
1072 if (i==1) val=fX->At(j);
1073 if (i==2) val=fY->At(j);
1074 if (i==3) val=fZ->At(j);
1075 if (i==4) val=fT->At(j);
1076 fArr->AddAt(val,j);
1077 fIndices->AddAt(j,j);
1078 }
1079 return;
1080 }
1081
1082 // Order the values of the specified variable
1083 Int_t iadd=0;
1084 for (Int_t j=0; j<fN; j++)
1085 {
1086 if (i==1) val=fX->At(j);
1087 if (i==2) val=fY->At(j);
1088 if (i==3) val=fZ->At(j);
1089 if (i==4) val=fT->At(j);
1090
1091 iadd=0;
1092 if (j==0)
1093 {
1094 fArr->AddAt(val,j);
1095 fIndices->AddAt(j,j);
1096 iadd=1;
1097 }
1098 else
1099 {
1100 for (Int_t k=0; k<j; k++)
1101 {
1102 if (mode>0 && val>=fArr->At(k)) continue; // Increasing ordering
1103 if (mode<0 && val<=fArr->At(k)) continue; // Decreasing ordering
1104 // Put value in between the existing ones
1105 for (Int_t m=j-1; m>=k; m--)
1106 {
1107 fArr->AddAt(fArr->At(m),m+1);
1108 fIndices->AddAt(fIndices->At(m),m+1);
1109 }
1110 fArr->AddAt(val,k);
1111 fIndices->AddAt(j,k);
1112 iadd=1;
1113 break;
1114 }
1115
1116 if (!iadd)
1117 {
1118 fArr->AddAt(val,j);
1119 fIndices->AddAt(j,j);
1120 }
1121 }
1122 }
1123}
1124
1125Int_t NcSample::GetIndex(TString name) const
1126{
1133
1134 Int_t idx=0;
1135
1136 for (Int_t i=0; i<fMaxdim; i++)
1137 {
1138 if (fNames[i]==name) idx=i+1;
1139 }
1140
1141 return idx;
1142}
1143
1145{
1152
1153 // Reset the ordering status word
1154 fOrdered=0;
1155
1156 if (fN<=0) return;
1157
1158 Double_t rn=fN;
1159 Double_t rn1=fN-1;
1160 Double_t var=0;
1161 Double_t rmsij;
1162 for (Int_t k=0; k<fDim; k++)
1163 {
1164 fMean[k]=fSum[k]/rn;
1165 var=(fSum2[k][k]/rn)-(fMean[k]*fMean[k]);
1166 if (var<0) var=0;
1167 fRMSdev[k]=sqrt(var);
1168 var=0;
1169 if (rn1)
1170 {
1171 var=(fSum2[k][k]-(rn*fMean[k]*fMean[k]))/rn1;
1172 if (var<0) var=0;
1173 }
1174 fSigma[k]=sqrt(var);
1175 }
1176 for (Int_t i=0; i<fDim; i++)
1177 {
1178 for (Int_t j=0; j<fDim; j++)
1179 {
1180 fCov[i][j]=(fSum2[i][j]/rn)-(fMean[i]*fMean[j]);
1181 fCor[i][j]=0;
1182 rmsij=fRMSdev[i]*fRMSdev[j];
1183 if (rmsij != 0) fCor[i][j]=fCov[i][j]/rmsij;
1184 }
1185 }
1186}
1187
1189{
1195
1196 return fDim;
1197}
1198
1199Int_t NcSample::GetN() const
1200{
1206
1207 return fN;
1208}
1209
1210TString NcSample::GetVariableName(Int_t i) const
1211{
1217
1218 TString name="";
1219
1220 if (i<1 || i>fDim)
1221 {
1222 cout << " *NcSample::GetVariableName* Error : Invalid index " << i << endl;
1223 }
1224 else
1225 {
1226 name=fNames[i-1];
1227 }
1228
1229 return name;
1230}
1231
1232Double_t NcSample::GetSum(Int_t i) const
1233{
1239
1240 if (i<1 || i>fDim)
1241 {
1242 cout << " *NcSample::GetSum* Error : Invalid index " << i << endl;
1243 return 0;
1244 }
1245 else
1246 {
1247 return fSum[i-1];
1248 }
1249}
1250
1251Double_t NcSample::GetSum(TString name) const
1252{
1258
1259 Int_t i=GetIndex(name);
1260 return GetSum(i);
1261}
1262
1263Double_t NcSample::GetMean(Int_t i) const
1264{
1270
1271 if (i<1 || i>fDim)
1272 {
1273 cout << " *NcSample::GetMean* Error : Invalid index " << i << endl;
1274 return 0;
1275 }
1276
1277 return fMean[i-1];
1278}
1279
1280Double_t NcSample::GetMean(TString name) const
1281{
1287
1288 Int_t i=GetIndex(name);
1289 return GetMean(i);
1290}
1291
1292Double_t NcSample::GetRMS(Int_t i) const
1293{
1304
1305 if (i<1 || i>fDim)
1306 {
1307 cout << " *NcSample::GetRMS* Error : Invalid index " << i << endl;
1308 return 0;
1309 }
1310
1311 Double_t rms=0;
1312 Double_t val=fSum2[i-1][i-1]/float(fN);
1313 if (val>=0) rms=sqrt(val);
1314
1315 return rms;
1316}
1317
1318Double_t NcSample::GetRMS(TString name) const
1319{
1330
1331 Int_t i=GetIndex(name);
1332 return GetRMS(i);
1333}
1334
1335Double_t NcSample::GetVar(Int_t i,Int_t model) const
1336{
1345
1346 if (i<1 || i>fDim)
1347 {
1348 cout << " *NcSample::GetVar* Error : Invalid index " << i << endl;
1349 return 0;
1350 }
1351
1352 Double_t var=fRMSdev[i-1]*fRMSdev[i-1];
1353 if (model) var=fSigma[i-1]*fSigma[i-1];
1354
1355 return var;
1356}
1357
1358Double_t NcSample::GetVar(TString name,Int_t model) const
1359{
1368
1369 Int_t i=GetIndex(name);
1370 return GetVar(i);
1371}
1372
1373Double_t NcSample::GetSigma(Int_t i,Int_t model) const
1374{
1384
1385 if (i<1 || i>fDim)
1386 {
1387 cout << " *NcSample::GetSigma* Error : Invalid index " << i << endl;
1388 return 0;
1389 }
1390
1391 Double_t val=fRMSdev[i-1];
1392 if (model) val=fSigma[i-1];
1393
1394 return val;
1395}
1396
1397Double_t NcSample::GetSigma(TString name,Int_t model) const
1398{
1407
1408 Int_t i=GetIndex(name);
1409 return GetSigma(i,model);
1410}
1411
1412Double_t NcSample::GetCov(Int_t i,Int_t j) const
1413{
1420
1421 if (i<1 || i>fDim || j<1 || j>fDim)
1422 {
1423 cout << " *NcSample::GetCov* Error : Invalid index encountered i=" << i << " j=" << j << endl;
1424 return 0;
1425 }
1426
1427 return fCov[i-1][j-1];
1428}
1429
1430Double_t NcSample::GetCov(TString nameA, TString nameB) const
1431{
1437
1438 Int_t i=GetIndex(nameA);
1439 Int_t j=GetIndex(nameB);
1440 return GetCov(i,j);
1441}
1442
1443Double_t NcSample::GetCor(Int_t i,Int_t j) const
1444{
1451
1452 if (i<1 || i>fDim || j<1 || j>fDim)
1453 {
1454 cout << " *NcSample::GetCor* Error : Invalid index encountered i=" << i << " j=" << j << endl;
1455 return 0;
1456 }
1457
1458 return fCor[i-1][j-1];
1459}
1460
1461Double_t NcSample::GetCor(TString nameA, TString nameB) const
1462{
1468
1469 Int_t i=GetIndex(nameA);
1470 Int_t j=GetIndex(nameB);
1471 return GetCor(i,j);
1472}
1473
1474void NcSample::Data(Int_t i,Int_t j)
1475{
1491
1492 const char* name=GetName();
1493 const char* title=GetTitle();
1494
1495 cout << " *" << ClassName() << "::Data*";
1496 if (strlen(name)) cout << " Info for sample Name : " << name;
1497 if (strlen(title)) cout << " Title : " << title;
1498 cout << endl;
1499 cout << " Access to the individual data entries is";
1500 if (!fStore) cout << " not";
1501 cout << " possible (StoreMode=" << fStore << ")" << endl;
1502
1503 if (fStore && fNmax)
1504 {
1505 if (fNmax==fN && fRemove)
1506 {
1507 cout << " *** At entering data the dynamic FIFO storage was limited to " << fNmax << " entries";
1508 }
1509 else
1510 {
1511 cout << " *** At entering new data the dynamic FIFO storage will be limited to " << fNmax << " entries";
1512 }
1513 if (!fMoveVariable) cout << " using the order of original entering.";
1514 if (fMoveVariable>0) cout << " after increasing";
1515 if (fMoveVariable<0) cout << " after decreasing";
1516 if (fMoveVariable) cout << " ordering w.r.t. variable " << abs(fMoveVariable);
1517 cout << endl;
1518 }
1519
1520 if (i<0 || i>fDim || j<0 || j>fDim)
1521 {
1522 cout << " Inconsistent input i=" << i << " and j=" << j << " for dimension " << fDim << endl;
1523 return;
1524 }
1525 if (!i && !j) cout << " Statistics and correlations of all variables";
1526 if (i && !j) cout << " Statistics of variable " << i;
1527 if (!i && j) cout << " Statistics of variable " << j;
1528 if (i && j) cout << " Correlation statistics of the variables " << i << " and " << j;
1529 cout << endl;
1530
1531 if (!fN)
1532 {
1533 cout << " No data has been entered." << endl;
1534 return;
1535 }
1536
1537 // Statistics and correlations of all variables
1538 if (!i && !j)
1539 {
1540 // Statistics of individual variables
1541 for (Int_t iv=1; iv<=fDim; iv++)
1542 {
1543 List(iv);
1544 }
1545
1546 if (fDim<2) return;
1547
1548 // Covariance(s) and correlation coefficient(s)
1549 for (Int_t iv=1; iv<=fDim; iv++)
1550 {
1551 for (Int_t jv=iv+1;jv<=fDim; jv++)
1552 {
1553 List(iv,jv);
1554 }
1555 }
1556 }
1557
1558 // Statistics of the i-th variable
1559 if (i && !j) List(i);
1560
1561 // Statistics of the j-th variable
1562 if (!i && j) List(j);
1563
1564 // Correlation statistics of the variables i and j
1565 if (i && j) List(i,j);
1566}
1567
1568void NcSample::Data(TString nameA,TString nameB)
1569{
1595
1596 Int_t i=GetIndex(nameA);
1597 Int_t j=GetIndex(nameB);
1598 Data(i,j);
1599}
1600
1601void NcSample::ListOrdered(Int_t mode,Int_t i)
1602{
1617
1618 if (!fStore)
1619 {
1620 cout << " *NcSample::ListOrdered* Error : Storage of data entries was not activated." << endl;
1621 return;
1622 }
1623
1624 if (fN<=0)
1625 {
1626 cout << " *NcSample::ListOrdered* No entries were stored." << endl;
1627 return;
1628 }
1629
1630 if (fDim<1)
1631 {
1632 cout << " *NcSample::ListOrdered* Error : Dimension less than 1." << endl;
1633 return;
1634 }
1635
1636 if (mode && (i<1 || i>fDim))
1637 {
1638 cout << " *NcSample::ListOrdered* Error : Invalid argument i=" << i << endl;
1639 return;
1640 }
1641
1642 Order(mode,i);
1643
1644 const char* name=GetName();
1645 const char* title=GetTitle();
1646
1647 cout << " *NcSample::ListOrdered* Ordered listing for the sample";
1648 if (strlen(name)) cout << " Name : " << name;
1649 if (strlen(title)) cout << " Title : " << title;
1650 cout << endl;
1651 if (fNmax==fN && fRemove)
1652 {
1653 cout << " *** At entering data the dynamic FIFO storage was limited to " << fNmax << " entries";
1654 if (!fMoveVariable) cout << " using the order of original entering.";
1655 if (fMoveVariable>0) cout << " after increasing";
1656 if (fMoveVariable<0) cout << " after decreasing";
1657 if (fMoveVariable) cout << " ordering w.r.t. variable " << abs(fMoveVariable);
1658 cout << endl;
1659 }
1660 cout << " Listing of the stored entries in";
1661 if (!mode) cout << " order of original entering." << endl;
1662 if (mode<0) cout << " decreasing order of variable : " << i << " (" << fNames[i-1] << ")" << endl;
1663 if (mode>0) cout << " increasing order of variable : " << i << " (" << fNames[i-1] << ")" << endl;
1664 if (mode) cout << " The number between brackets indicates the original data entry number." << endl;
1665
1666 Int_t index=0;
1667 for (Int_t j=0; j<fN; j++)
1668 {
1669 index=fIndices->At(j);
1670
1671 if (index<0 || index>=fN) continue;
1672
1673 cout << " Index : " << (j+1);
1674 if (mode) cout << " (" << (index+1) << ") ";
1675 cout << " " << fNames[0] << "=" << fX->At(index);
1676 if (fDim>1) cout << " " << fNames[1] << "=" << fY->At(index);
1677 if (fDim>2) cout << " " << fNames[2] << "=" << fZ->At(index);
1678 if (fDim>3) cout << " " << fNames[3] << "=" << fT->At(index);
1679 cout << endl;
1680 }
1681}
1682
1683void NcSample::ListOrdered(Int_t mode,TString name)
1684{
1699
1700 Int_t i=GetIndex(name);
1701 ListOrdered(mode,i);
1702}
1703
1704void NcSample::List(Int_t i)
1705{
1712
1713 if (i<1 || i>fDim)
1714 {
1715 cout << " *NcSample::List(i)* Error : Invalid index " << i << endl;
1716 }
1717 else
1718 {
1719 cout << " Variable " << fNames[i-1] << " : N=" << fN;
1720 cout << " Sum=" << fSum[i-1] << " Mean=" << fMean[i-1];
1721 cout << " Deviation(rms)=" << fRMSdev[i-1] << " Sigma=" << fSigma[i-1];
1722 if (!fRemove || fStore)
1723 {
1724 cout << endl;
1725 cout << " Minimum=" << GetMinimum(i) << " Maximum=" << GetMaximum(i);
1726 }
1727 if (fStore)
1728 {
1729 cout << " Median=" << GetMedian(i);
1730 cout << " Spread(w.r.t. median)=" << GetSpread(i,0) << " Spread(w.r.t. mean)=" << GetSpread(i,1);
1731 }
1732 cout << endl;
1733 }
1734}
1735
1736void NcSample::List(Int_t i,Int_t j) const
1737{
1744
1745 if (i<1 || i>fDim || j<1 || j>fDim)
1746 {
1747 cout << " *NcSample::List(i,j)* Error : Invalid index encountered i=" << i << " j=" << j << endl;
1748 }
1749 else
1750 {
1751 cout << " " << fNames[i-1] << "-" << fNames[j-1];
1752 cout << " Correlation(coefficient)=" << fCor[i-1][j-1] << " Covariance=" << fCov[i-1][j-1] << endl;
1753 }
1754}
1755
1756void NcSample::SetStoreMode(Int_t mode,Int_t nmax,Int_t i)
1757{
1795
1796 if (fN)
1797 {
1798 cout << " Storage mode can only be set before first data." << endl;
1799 }
1800 else if ((!mode && nmax) || mode<0 || mode>1 || nmax<0 || abs(i)>fDim)
1801 {
1802 cout << " Inconsistent input : mode=" << mode << " nmax=" << nmax << " i=" << i << endl;
1803 fNmax=0;
1804 fMoveVariable=0;
1805 }
1806 else
1807 {
1808 fStore=mode;
1809 fNmax=nmax;
1810 fMoveVariable=i;
1811 }
1812}
1813
1815{
1821
1822 return fStore;
1823}
1824
1826{
1832
1833 return fNmax;
1834}
1835
1836Double_t NcSample::GetQuantile(Double_t f,Int_t i)
1837{
1854
1855 if (i<1 || i>fDim)
1856 {
1857 cout << " *NcSample::GetQuantile* Error : Invalid index " << i << endl;
1858 return 0;
1859 }
1860
1861 if (!fStore)
1862 {
1863 cout << " *NcSample::GetQuantile* Error : Storage of data entries was not activated." << endl;
1864 return 0;
1865 }
1866
1867 if (fN<=0) return 0;
1868
1869 if (f<0 || f>1) return 0;
1870
1871 Double_t quantile=0;
1872
1873 if (fN==1)
1874 {
1875 if (i==1) quantile=fX->At(0);
1876 if (i==2) quantile=fY->At(0);
1877 if (i==3) quantile=fZ->At(0);
1878 if (i==4) quantile=fT->At(0);
1879 return quantile;
1880 }
1881
1882 if (f==0) return GetMinimum(i);
1883 if (f==1) return GetMaximum(i);
1884
1885 // Order the values of the i-th variable in increasing order
1886 Order(1,i);
1887
1888 quantile=0;
1889 Double_t rindex=double(fN)*f;
1890 Int_t index=int(rindex);
1891 if (fN%2) // Odd number of entries
1892 {
1893 quantile=fArr->At(index);
1894 }
1895 else // Even number of entries
1896 {
1897 quantile=(fArr->At(index-1)+fArr->At(index))/2.;
1898 }
1899 return quantile;
1900}
1901
1902Double_t NcSample::GetQuantile(Double_t f,TString name)
1903{
1920
1921 Int_t i=GetIndex(name);
1922 return GetQuantile(f,i);
1923}
1924
1925Double_t NcSample::GetMedian(Int_t i)
1926{
1943
1944 Double_t median=GetQuantile(0.5,i);
1945 return median;
1946}
1947
1948Double_t NcSample::GetMedian(TString name)
1949{
1966
1967 Double_t median=GetQuantile(0.5,name);
1968 return median;
1969}
1970
1971Double_t NcSample::GetSpread(Int_t i,Int_t model,Double_t vref)
1972{
1992
1993 if (model<0 || model>2)
1994 {
1995 cout << " *NcSample::GetSpread* Error : Unsupported parameter model=" << model << endl;
1996 return -1;
1997 }
1998
1999 if (i<1 || i>fDim)
2000 {
2001 cout << " *NcSample::GetSpread* Error : Invalid index " << i << endl;
2002 return -1;
2003 }
2004
2005 if (!fStore)
2006 {
2007 cout << " *NcSample::GetSpread* Error : Storage of data entries was not activated." << endl;
2008 return -1;
2009 }
2010
2011 if (fN<=1) return -1;
2012
2013 Double_t central=GetMedian(i);
2014 if (model==1) central=GetMean(i);
2015 if (model==2) central=vref;
2016
2017 Double_t spread=0;
2018 for (Int_t j=0; j<fN; j++)
2019 {
2020 spread+=fabs(central-(fArr->At(j)));
2021 }
2022
2023 spread=spread/float(fN);
2024
2025 return spread;
2026}
2027
2028Double_t NcSample::GetSpread(TString name,Int_t model,Double_t vref)
2029{
2049
2050 Int_t i=GetIndex(name);
2051 return GetSpread(i,model,vref);
2052}
2053
2054Double_t NcSample::GetMinimum(Int_t i) const
2055{
2063
2064 if (i<1 || i>fDim)
2065 {
2066 cout << " *NcSample::GetMinimum* Error : Invalid index " << i << endl;
2067 return 0;
2068 }
2069
2070 if (!fRemove) return fMin[i-1];
2071
2072 if (!fStore)
2073 {
2074 cout << " *NcSample::GetMinimum* Error : Storage of data entries was not activated." << endl;
2075 return 0;
2076 }
2077
2078 if (fN<=0) return 0;
2079
2080 Double_t min=0;
2081
2082 if (i==1) min=fX->At(0);
2083 if (i==2) min=fY->At(0);
2084 if (i==3) min=fZ->At(0);
2085
2086 for (Int_t k=1; k<fN; k++)
2087 {
2088 if (i==1 && fX->At(k)<min) min=fX->At(k);
2089 if (i==2 && fY->At(k)<min) min=fY->At(k);
2090 if (i==3 && fZ->At(k)<min) min=fZ->At(k);
2091 }
2092
2093 return min;
2094}
2095
2096Double_t NcSample::GetMinimum(TString name) const
2097{
2105
2106 Int_t i=GetIndex(name);
2107 return GetMinimum(i);
2108}
2109
2110Double_t NcSample::GetMaximum(Int_t i) const
2111{
2119
2120 if (i<1 || i>fDim)
2121 {
2122 cout << " *NcSample::GetMaximum* Error : Invalid index " << i << endl;
2123 return 0;
2124 }
2125
2126 if (!fRemove) return fMax[i-1];
2127
2128 if (!fStore)
2129 {
2130 cout << " *NcSample::GetMaximum* Error : Storage of data entries was not activated." << endl;
2131 return 0;
2132 }
2133
2134 if (fN<=0) return 0;
2135
2136 Double_t max=0;
2137
2138 if (i==1) max=fX->At(0);
2139 if (i==2) max=fY->At(0);
2140 if (i==3) max=fZ->At(0);
2141
2142 for (Int_t k=1; k<fN; k++)
2143 {
2144 if (i==1 && fX->At(k)>max) max=fX->At(k);
2145 if (i==2 && fY->At(k)>max) max=fY->At(k);
2146 if (i==3 && fZ->At(k)>max) max=fZ->At(k);
2147 }
2148
2149 return max;
2150}
2151
2152Double_t NcSample::GetMaximum(TString name) const
2153{
2161
2162 Int_t i=GetIndex(name);
2163 return GetMaximum(i);
2164}
2165
2166Double_t NcSample::GetQuantile(Double_t f,TH1* histo,Int_t mode) const
2167{
2190
2191 if (!histo) return 0;
2192
2193 if (f<0 || f>1) return 0;
2194
2195 Double_t xlow=0;
2196 Double_t xup=0;
2197 Double_t quantile=0;
2198
2199 if (mode==2) // Quantile of Y values
2200 {
2201 NcSample temp;
2202 temp.SetStoreMode(1);
2203 Double_t val=0;
2204 for (Int_t i=1; i<=histo->GetNbinsX(); i++)
2205 {
2206 val=histo->GetBinContent(i);
2207 temp.Enter(val);
2208 }
2209 quantile=temp.GetQuantile(f,1);
2210 }
2211 else // Quantile of X values
2212 {
2213 // Take the average of two quantiles closely around f
2214 // This will enhance the precision for low statistics
2215 Double_t q[2];
2216 Double_t p[2];
2217 p[0]=f-0.01;
2218 p[1]=f+0.01;
2219 if (p[0]<0) p[0]=0;
2220 if (p[0]>1) p[0]=1;
2221 histo->ComputeIntegral();
2222 Int_t nq=histo->GetQuantiles(2,q,p);
2223
2224 if (!nq) return 0;
2225
2226 xlow=q[0];
2227 xup=q[1];
2228 if (mode==1)
2229 {
2230 Int_t mbin=histo->FindBin(q[0]);
2231 xlow=histo->GetBinCenter(mbin);
2232 mbin=histo->FindBin(q[1]);
2233 xup=histo->GetBinCenter(mbin);
2234 }
2235 }
2236
2237 quantile=(xlow+xup)/2.;
2238
2239 return quantile;
2240}
2241
2242Double_t NcSample::GetMedian(TH1* histo,Int_t mode) const
2243{
2256
2257 Double_t median=GetQuantile(0.5,histo,mode);
2258 return median;
2259}
2260
2261Double_t NcSample::GetSpread(TH1* histo,Int_t mode,Int_t model,Double_t vref) const
2262{
2289
2290 if (model<0 || model>2)
2291 {
2292 cout << " *NcSample::GetSpread* Error : Unsupported parameter model=" << model << endl;
2293 return -1;
2294 }
2295
2296 if (!histo) return -1;
2297
2298 Int_t nbins=histo->GetNbinsX();
2299
2300 if (nbins<1) return -1;
2301
2302 Double_t spread=0;
2303
2304 if (mode==2) // Spread in Y values
2305 {
2306 NcSample temp;
2307 temp.SetStoreMode(1);
2308 Double_t val=0;
2309 for (Int_t i=1; i<=nbins; i++)
2310 {
2311 val=histo->GetBinContent(i);
2312 temp.Enter(val);
2313 }
2314 spread=temp.GetSpread(1,model,vref);
2315 }
2316 else // Spread in X values
2317 {
2318 Double_t central=GetMedian(histo,mode);
2319 if (model==1) central=histo->GetMean();
2320 if (model==2) central=vref;
2321 Double_t x=0;
2322 Double_t y=0;
2323 Double_t ysum=0;
2324 for (Int_t jbin=1; jbin<=nbins; jbin++)
2325 {
2326 x=histo->GetBinCenter(jbin);
2327 y=histo->GetBinContent(jbin);
2328 if (y>0)
2329 {
2330 spread+=fabs(x-central)*y;
2331 ysum+=y;
2332 }
2333 }
2334 if (ysum>0) spread=spread/ysum;
2335 }
2336
2337 return spread;
2338}
2339
2340Double_t NcSample::GetEntry(Int_t i,Int_t j,Int_t mode,Int_t k)
2341{
2359
2360 TString name=GetName();
2361
2362 if (!fStore)
2363 {
2364 cout << " *NcSample::GetEntry* Error : Storage mode not activated." << endl;
2365 return 0;
2366 }
2367
2368 if (i<1 || i>fN)
2369 {
2370 cout << " *NcSample::GetEntry* Error : Invalid index number i=" << i;
2371 if (name!="") printf(" for NcSample %-s",name.Data());
2372 printf("\n");
2373 return 0;
2374 }
2375
2376 if (j<1 || j>fDim)
2377 {
2378 cout << " *NcSample::GetEntry* Error : Invalid variable number j=" << j;
2379 if (name!="") printf(" for NcSample %-s",name.Data());
2380 printf("\n");
2381 return 0;
2382 }
2383
2384 if (mode && (k<1 || k>fDim))
2385 {
2386 cout << " *NcSample::GetEntry* Error : Invalid argument k=" << k;
2387 if (name!="") printf(" for NcSample %-s",name.Data());
2388 printf("\n");
2389 return 0;
2390 }
2391
2392 Double_t value=0;
2393
2394 // Determine the entry index in the main arrays.
2395 Int_t index=i-1;
2396
2397 if (mode)
2398 {
2399 Order(mode,k);
2400 index=fIndices->At(i-1);
2401 }
2402
2403 if (j==1) value=fX->At(index);
2404 if (j==2) value=fY->At(index);
2405 if (j==3) value=fZ->At(index);
2406 if (j==4) value=fT->At(index);
2407
2408 return value;
2409}
2410
2411Double_t NcSample::GetEntry(Int_t i,TString nameA,Int_t mode,TString nameB)
2412{
2430
2431 Int_t j=GetIndex(nameA);
2432 Int_t k=GetIndex(nameB);
2433 return GetEntry(i,j,mode,k);
2434}
2435
2436void NcSample::GetSubset(NcSample* s,Int_t ifirst,Int_t ilast,Int_t mode,Int_t k)
2437{
2456
2457 if (!s)
2458 {
2459 cout << " *NcSample::GetSubset* Error : Pointer for output NcSample object is zero." << endl;
2460 return;
2461 }
2462
2463 s->Reset();
2464
2465 if (!fStore)
2466 {
2467 cout << " *NcSample::GetSubset* Error : Storage mode not activated." << endl;
2468 return;
2469 }
2470
2471 if (ifirst<1 || ifirst>fN || ilast>fN || ilast<ifirst)
2472 {
2473 cout << " *NcSample::GetSubset* Error : Invalid input ifirst=" << ifirst << " ilast=" << ilast << endl;
2474 return;
2475 }
2476
2477 if (mode && (k<1 || k>fDim))
2478 {
2479 cout << " *NcSample::GetSubset* Error : Invalid argument k=" << k << endl;
2480 return;
2481 }
2482
2483 s->SetStoreMode();
2484 s->SetNames(fNames[0],fNames[1],fNames[2],fNames[3]);
2485
2486 Double_t* values=new Double_t[fDim];
2487 for (Int_t i=ifirst; i<=ilast; i++)
2488 {
2489 for (Int_t j=1; j<=fDim; j++)
2490 {
2491 values[j-1]=GetEntry(i,j,mode,k);
2492 }
2493 if (fDim==1) s->Enter(values[0]);
2494 if (fDim==2) s->Enter(values[0],values[1]);
2495 if (fDim==3) s->Enter(values[0],values[1],values[2]);
2496 if (fDim==4) s->Enter(values[0],values[1],values[2],values[3]);
2497 }
2498
2499 delete [] values;
2500}
2501
2502NcSample NcSample::GetDtSample(Int_t i,Int_t nc,Int_t store,Int_t nmax,Int_t order)
2503{
2552
2553 // Make "order" value to comply with a single variable sample
2554 if (order>0) order=1;
2555 if (order<0) order=-1;
2556
2557 NcSample sdt;
2558 sdt.SetStoreMode(store,nmax,order);
2559 sdt.SetName("DtSample");
2560 sdt.SetNames("Dt");
2561
2562 if (i<1 || i>GetDimension()) return sdt;
2563
2564 if (nc<1) return sdt;
2565
2566 Int_t nen=GetN();
2567 if (nen<=nc) return sdt;
2568
2569 TString varname=GetVariableName(i);
2570 TString str;
2571 str.Form("Interval sampling for variable %-s between %-i consecutive entries (nc=%-i)",varname.Data(),nc+1,nc);
2572 sdt.SetNameTitle("DtSample",str);
2573
2574 // Fill the dt sample
2575 Double_t t1=0;
2576 Double_t t2=0;
2577 Double_t deltat=0;
2578 for (Int_t ien=1; ien<=nen; ien++)
2579 {
2580 if (ien+nc>nen) break;
2581
2582 t1=GetEntry(ien,i,1,i);
2583 t2=GetEntry(ien+nc,i,1,i);
2584 deltat=fabs(t2-t1);
2585
2586 sdt.Enter(deltat);
2587 }
2588
2589 return sdt;
2590}
2591
2592NcSample NcSample::GetDtSample(TString name,Int_t nc,Int_t store,Int_t nmax,Int_t order)
2593{
2642
2643 Int_t i=GetIndex(name);
2644 NcSample sdt=GetDtSample(i,nc,store,nmax,order);
2645
2646 return sdt;
2647}
2648
2650{
2663
2664 TString s="Sampling Histogram for NcSample ";
2665 s+=GetName();
2666 s+=";Sampling number;";
2667 if (f)
2668 {
2669 TString sf=f->GetExpFormula("p");
2670 sf.ReplaceAll("x",fNames[i-1]);
2671 s+=sf;
2672 }
2673 else
2674 {
2675 s+=fNames[i-1];
2676 }
2677
2678 TH1D hist("",s,fN,0,fN);
2679
2680 if (!fStore)
2681 {
2682 cout << " *NcSample::GetSamplingHistogram* Error : Storage mode has not been activated." << endl;
2683 return hist;
2684 }
2685
2686 if (i<1 || i>fDim)
2687 {
2688 cout << " *NcSample::GetSamplingHistogram* Error : Invalid index encountered i=" << i << endl;
2689 return hist;
2690 }
2691
2692 Double_t y=0;
2693 for (Int_t ip=1; ip<=fN; ip++)
2694 {
2695 y=GetEntry(ip,i);
2696 if (f) y=f->Eval(y);
2697 hist.SetBinContent(ip,y);
2698 }
2699
2700 return hist;
2701}
2702
2703TH1D NcSample::GetSamplingHistogram(Int_t i,TString f)
2704{
2714
2715 TF1 func("func",f);
2716
2717 return GetSamplingHistogram(i,&func);
2718}
2719
2720TH1D NcSample::GetSamplingHistogram(TString nameA,TF1* f)
2721{
2733
2734 Int_t i=GetIndex(nameA);
2735 return GetSamplingHistogram(i,f);
2736}
2737
2738TH1D NcSample::GetSamplingHistogram(TString nameA,TString f)
2739{
2749
2750 TF1 func("func",f);
2751
2752 return GetSamplingHistogram(nameA,&func);
2753}
2754
2755TH1D NcSample::Get1DHistogram(Int_t i,Int_t j,Bool_t sumw2,Int_t nbx,TF1* f)
2756{
2772
2773 TString s="1D Histogram for NcSample ";
2774 s+=GetName();
2775 s+=";";
2776 s+=fNames[i-1];
2777 s+=";Counts";
2778 if (j>0)
2779 {
2780 s+=" weighted by : ";
2781 if (f)
2782 {
2783 TString sf=f->GetExpFormula("p");
2784 sf.ReplaceAll("x",fNames[j-1]);
2785 s+=sf;
2786 }
2787 else
2788 {
2789 s+=fNames[j-1];
2790 }
2791 }
2792
2793 Double_t xlow=GetMinimum(i);
2794 Double_t xup=GetMaximum(i);
2795
2796 Double_t dx=0;
2797 if (nbx) dx=(xup-xlow)/double(nbx);
2798
2799 // Extension to include the maximum value
2800 xup+=1e-6*fabs(dx);
2801
2802 TH1D hist("",s.Data(),nbx,xlow,xup);
2803 hist.Sumw2(sumw2);
2804
2805 if (!fStore)
2806 {
2807 cout << " *NcSample::Get1DHistogram* Error : Storage mode has not been activated." << endl;
2808 return hist;
2809 }
2810
2811 if (i<1 || i>fDim || j>fDim)
2812 {
2813 cout << " *NcSample::Get1DHistogram* Error : Invalid index encountered i=" << i << " j=" << j << endl;
2814 return hist;
2815 }
2816
2817 Double_t x=0;
2818 Double_t y=0;
2819 for (Int_t ip=1; ip<=fN; ip++)
2820 {
2821 x=GetEntry(ip,i);
2822 if (j>0)
2823 {
2824 y=GetEntry(ip,j);
2825 if (f) y=f->Eval(y);
2826 hist.Fill(x,y);
2827 }
2828 else
2829 {
2830 hist.Fill(x);
2831 }
2832 }
2833
2834 return hist;
2835}
2836
2837TH1D NcSample::Get1DHistogram(TString nameA,TString nameB,Bool_t sumw2,Int_t nbx,TF1* f)
2838{
2853
2854 Int_t i=GetIndex(nameA);
2855 Int_t j=GetIndex(nameB);
2856 return Get1DHistogram(i,j,sumw2,nbx,f);
2857}
2858
2859TH2D NcSample::Get2DHistogram(Int_t i,Int_t j,Int_t k,Bool_t sumw2,Int_t nbx,Int_t nby,TF1* f)
2860{
2877
2878 TString s="2D Histogram for NcSample ";
2879 s+=GetName();
2880 s+=";";
2881 s+=fNames[i-1];
2882 s+=";";
2883 s+=fNames[j-1];
2884 s+=";Counts";
2885 if (k>0)
2886 {
2887 s+=" weighted by : ";
2888 if (f)
2889 {
2890 TString sf=f->GetExpFormula("p");
2891 sf.ReplaceAll("x",fNames[k-1]);
2892 s+=sf;
2893 }
2894 else
2895 {
2896 s+=fNames[k-1];
2897 }
2898 }
2899
2900 Double_t xlow=GetMinimum(i);
2901 Double_t xup=GetMaximum(i);
2902 Double_t ylow=GetMinimum(j);
2903 Double_t yup=GetMaximum(j);
2904
2905 Double_t dx=0;
2906 if (nbx) dx=(xup-xlow)/double(nbx);
2907 Double_t dy=0;
2908 if (nby) dy=(yup-ylow)/double(nby);
2909
2910 // Extension to include the maximum values
2911 xup+=1e-6*fabs(dx);
2912 yup+=1e-6*fabs(dy);
2913
2914 TH2D hist("",s.Data(),nbx,xlow,xup,nby,ylow,yup);
2915 hist.Sumw2(sumw2);
2916 hist.SetMarkerStyle(20);
2917 hist.SetMarkerSize(1);
2918
2919 if (!fStore)
2920 {
2921 cout << " *NcSample::Get2DHistogram* Error : Storage mode has not been activated." << endl;
2922 return hist;
2923 }
2924
2925 if (i<1 || i>fDim || j<1 || j>fDim || k>fDim)
2926 {
2927 cout << " *NcSample::Get2DHistogram* Error : Invalid index encountered i=" << i << " j=" << j << " k=" << k << endl;
2928 return hist;
2929 }
2930
2931 Double_t x=0;
2932 Double_t y=0;
2933 Double_t z=0;
2934 for (Int_t ip=1; ip<=fN; ip++)
2935 {
2936 x=GetEntry(ip,i);
2937 y=GetEntry(ip,j);
2938 if (k>0)
2939 {
2940 z=GetEntry(ip,k);
2941 if (f) z=f->Eval(z);
2942 hist.Fill(x,y,z);
2943 }
2944 else
2945 {
2946 hist.Fill(x,y);
2947 }
2948 }
2949
2950 return hist;
2951}
2952
2953TH2D NcSample::Get2DHistogram(TString nameA,TString nameB,TString nameC,Bool_t sumw2,Int_t nbx,Int_t nby,TF1* f)
2954{
2970
2971 Int_t i=GetIndex(nameA);
2972 Int_t j=GetIndex(nameB);
2973 Int_t k=GetIndex(nameC);
2974 return Get2DHistogram(i,j,k,sumw2,nbx,nby,f);
2975}
2976
2977TH3D 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)
2978{
2995
2996 TString s="3D Histogram for NcSample ";
2997 s+=GetName();
2998 if (m>0)
2999 {
3000 s+=" with ";
3001 if (f)
3002 {
3003 TString sf=f->GetExpFormula("p");
3004 sf.ReplaceAll("x",fNames[m-1]);
3005 s+=sf;
3006 }
3007 else
3008 {
3009 s+=fNames[m-1];
3010 }
3011 s+=" as weight";
3012 }
3013 s+=";";
3014 s+=fNames[i-1];
3015 s+=";";
3016 s+=fNames[j-1];
3017 s+=";";
3018 s+=fNames[k-1];
3019
3020 Double_t xlow=GetMinimum(i);
3021 Double_t xup=GetMaximum(i);
3022 Double_t ylow=GetMinimum(j);
3023 Double_t yup=GetMaximum(j);
3024 Double_t zlow=GetMinimum(k);
3025 Double_t zup=GetMaximum(k);
3026
3027 Double_t dx=0;
3028 if (nbx) dx=(xup-xlow)/double(nbx);
3029 Double_t dy=0;
3030 if (nby) dy=(yup-ylow)/double(nby);
3031 Double_t dz=0;
3032 if (nbz) dz=(zup-zlow)/double(nbz);
3033
3034 // Extension to include the maximum values
3035 xup+=1e-6*fabs(dx);
3036 yup+=1e-6*fabs(dy);
3037 zup+=1e-6*fabs(dz);
3038
3039 TH3D hist("",s.Data(),nbx,xlow,xup,nby,ylow,yup,nbz,zlow,zup);
3040 hist.Sumw2(sumw2);
3041 hist.SetMarkerStyle(20);
3042 hist.SetMarkerSize(1);
3043
3044 if (!fStore)
3045 {
3046 cout << " *NcSample::Get3DHistogram* Error : Storage mode has not been activated." << endl;
3047 return hist;
3048 }
3049
3050 if (i<1 || i>fDim || j<1 || j>fDim || k<1 || k>fDim || m>fDim)
3051 {
3052 cout << " *NcSample::Get2DHistogram* Error : Invalid index encountered i=" << i << " j=" << j << " k=" << k << " m=" << m << endl;
3053 return hist;
3054 }
3055
3056 Double_t x=0;
3057 Double_t y=0;
3058 Double_t z=0;
3059 Double_t t=0;
3060 for (Int_t ip=1; ip<=fN; ip++)
3061 {
3062 x=GetEntry(ip,i);
3063 y=GetEntry(ip,j);
3064 z=GetEntry(ip,k);
3065 if (m>0)
3066 {
3067 t=GetEntry(ip,m);
3068 if (f) t=f->Eval(t);
3069 hist.Fill(x,y,z,t);
3070 }
3071 else
3072 {
3073 hist.Fill(x,y,z);
3074 }
3075 }
3076
3077 return hist;
3078}
3079
3080TH3D NcSample::Get3DHistogram(TString nameA,TString nameB,TString nameC,TString nameD,Bool_t sumw2,Int_t nbx,Int_t nby,Int_t nbz,TF1* f)
3081{
3097
3098 Int_t i=GetIndex(nameA);
3099 Int_t j=GetIndex(nameB);
3100 Int_t k=GetIndex(nameC);
3101 Int_t m=GetIndex(nameD);
3102 return Get3DHistogram(i,j,k,m,sumw2,nbx,nby,nbz,f);
3103}
3104
3105TGraph NcSample::GetGraph(Int_t i,TF1* f)
3106{
3119
3120 TGraph gr;
3121 gr.SetName("NcSample");
3122
3123 if (!fStore)
3124 {
3125 cout << " *NcSample::GetGraph* Error : Storage mode has not been activated." << endl;
3126 return gr;
3127 }
3128
3129 if (i<1 || i>fDim)
3130 {
3131 cout << " *NcSample::GetGraph* Error : Invalid index encountered i=" << i << endl;
3132 return gr;
3133 }
3134
3135 Double_t x=0;
3136 Double_t y=0;
3137 for (Int_t ip=0; ip<fN; ip++)
3138 {
3139 x=ip+1;
3140 y=GetEntry(ip+1,i);
3141 if (f) y=f->Eval(y);
3142 gr.SetPoint(ip,x,y);
3143 }
3144
3145 TString s="TGraph for NcSample ";
3146 s+=GetName();
3147 s+=" : X-axis=Sampling number ";
3148 s+=" Y-axis=";
3149 TString sf=fNames[i-1];
3150 if (f)
3151 {
3152 sf=f->GetExpFormula("p");
3153 sf.ReplaceAll("x",fNames[i-1]);
3154 }
3155 s+=sf;
3156 s+=";Sampling number;";
3157 s+=sf;
3158
3159 gr.SetTitle(s.Data());
3160
3161 gr.SetMarkerStyle(20);
3162 gr.SetMarkerSize(1);
3163 gr.SetDrawOption("AP");
3164
3165 return gr;
3166}
3167
3168TGraph NcSample::GetGraph(Int_t i,TString f)
3169{
3179
3180 TF1 func("func",f);
3181
3182 return GetGraph(i,&func);
3183}
3184
3185TGraph NcSample::GetGraph(TString nameA,TF1* f)
3186{
3198
3199 Int_t i=GetIndex(nameA);
3200 return GetGraph(i,f);
3201}
3202
3203TGraph NcSample::GetGraph(Int_t i,Int_t j,TF1* f)
3204{
3217
3218 TGraph gr;
3219 gr.SetName("NcSample");
3220
3221 if (!fStore)
3222 {
3223 cout << " *NcSample::GetGraph* Error : Storage mode has not been activated." << endl;
3224 return gr;
3225 }
3226
3227 if (i<1 || i>fDim || j<1 || j>fDim)
3228 {
3229 cout << " *NcSample::GetGraph* Error : Invalid index encountered i=" << i << " j=" << j << endl;
3230 return gr;
3231 }
3232
3233 Double_t x=0;
3234 Double_t y=0;
3235 for (Int_t ip=0; ip<fN; ip++)
3236 {
3237 x=GetEntry(ip+1,i);
3238 y=GetEntry(ip+1,j);
3239 if (f) y=f->Eval(y);
3240 gr.SetPoint(ip,x,y);
3241 }
3242
3243 TString s="TGraph for NcSample ";
3244 s+=GetName();
3245 s+=" : X-axis=";
3246 s+=fNames[i-1];
3247 s+=" Y-axis=";
3248 TString sf=fNames[j-1];
3249 if (f)
3250 {
3251 sf=f->GetExpFormula("p");
3252 sf.ReplaceAll("x",fNames[j-1]);
3253 }
3254 s+=sf;
3255 s+=";";
3256 s+=fNames[i-1];
3257 s+=";";
3258 s+=sf;
3259
3260 gr.SetTitle(s.Data());
3261
3262 gr.SetMarkerStyle(20);
3263 gr.SetMarkerSize(1);
3264 gr.SetDrawOption("AP");
3265
3266 return gr;
3267}
3268
3269TGraph NcSample::GetGraph(Int_t i,Int_t j,TString f)
3270{
3280
3281 TF1 func("func",f);
3282
3283 return GetGraph(i,j,&func);
3284}
3285
3286TGraph NcSample::GetGraph(TString nameA,TString nameB,TF1* f)
3287{
3299
3300 Int_t i=GetIndex(nameA);
3301 Int_t j=GetIndex(nameB);
3302 return GetGraph(i,j,f);
3303}
3304
3305TGraphErrors NcSample::GetGraphErrors(TGraph* gr,Int_t ix,Int_t iy,TF1* fx,TF1* fy)
3306{
3348
3349 TGraphErrors gre;
3350
3351 if (!gr)
3352 {
3353 cout << " *NcSample::GetGraphErrors* Error : No input Graph is specified." << endl;
3354 return gre;
3355 }
3356
3357 TString name=gr->GetName();
3358 name+=".E";
3359
3360 gre.SetName(name);
3361
3362 if ((ix || iy) && !fStore)
3363 {
3364 cout << " *NcSample::GetGraphErrors* Error : Storage mode has not been activated." << endl;
3365 return gre;
3366 }
3367
3368 if (ix<0 || ix>fDim || iy<0 || iy>fDim)
3369 {
3370 cout << " *NcSample::GetGraphErros* Error : Invalid index encountered ix=" << ix << " iy=" << iy << endl;
3371 return gre;
3372 }
3373
3374 // The number of data points of the input Graph
3375 Int_t np=gr->GetN();
3376
3377 if (!np)
3378 {
3379 cout << " *NcSample::GetGraphErrors* Error : Input Graph does not contain any data points." << endl;
3380 return gre;
3381 }
3382
3383 if ((ix || iy) && np!=fN)
3384 {
3385 cout << " *NcSample::GetGraphErrors* Error : Entries don't match Nsample=" << fN << " Ngraph=" << np << endl;
3386 return gre;
3387 }
3388
3389 Double_t x=0;
3390 Double_t y=0;
3391 Double_t ex=0;
3392 Double_t ey=0;
3393 for (Int_t ip=0; ip<np; ip++)
3394 {
3395 gr->GetPoint(ip,x,y);
3396 if (ix) ex=GetEntry(ip+1,ix);
3397 if (fx)
3398 {
3399 if (!ix)
3400 {
3401 ex=fx->Eval(x);
3402 }
3403 else
3404 {
3405 ex=fx->Eval(ex);
3406 }
3407 }
3408 if (iy) ey=GetEntry(ip+1,iy);
3409 if (fy)
3410 {
3411 if (!iy)
3412 {
3413 ey=fy->Eval(y);
3414 }
3415 else
3416 {
3417 ey=fy->Eval(ey);
3418 }
3419 }
3420 ex=fabs(ex);
3421 ey=fabs(ey);
3422 gre.SetPoint(ip,x,y);
3423 gre.SetPointError(ip,ex,ey);
3424 }
3425
3426 TString sfx="0";
3427 if (ix || fx)
3428 {
3429 sfx="|";
3430 if (!fx)
3431 {
3432 sfx+=fNames[ix-1];
3433 }
3434 else
3435 {
3436 sfx+=fx->GetExpFormula("p");
3437 if (ix) sfx.ReplaceAll("x",fNames[ix-1]);
3438 }
3439 sfx+="|";
3440 }
3441
3442 TString sfy="0";
3443 if (iy || fy)
3444 {
3445 sfy="|";
3446 if (!fy)
3447 {
3448 sfy+=fNames[iy-1];
3449 }
3450 else
3451 {
3452 sfy+=fy->GetExpFormula("p");
3453 if (iy)
3454 {
3455 sfy.ReplaceAll("x",fNames[iy-1]);
3456 }
3457 else
3458 {
3459 sfy.ReplaceAll("x","y");
3460 }
3461 }
3462 sfy+="|";
3463 }
3464
3465 TString s="TGraphErrors for Graph : ";
3466 s+=gr->GetName();
3467 s+=" X-error=";
3468 s+=sfx;
3469 s+=" Y-error=";
3470 s+=sfy;
3471
3472 // Copy the axes titles of the input Graph (if present)
3473 TAxis* axis=0;
3474 axis=gr->GetXaxis();
3475 if (axis)
3476 {
3477 s+=";";
3478 s+=axis->GetTitle();
3479 }
3480 axis=gr->GetYaxis();
3481 if (axis)
3482 {
3483 s+=";";
3484 s+=axis->GetTitle();
3485 }
3486
3487 gre.SetTitle(s.Data());
3488
3489 gre.SetMarkerStyle(20);
3490 gre.SetMarkerSize(0.5);
3491 gre.SetDrawOption("AP");
3492
3493 return gre;
3494}
3495
3496TGraphErrors NcSample::GetGraphErrors(TGraph* gr,TString nameA,TString nameB,TF1* fx,TF1* fy)
3497{
3539
3540 Int_t ix=GetIndex(nameA);
3541 Int_t iy=GetIndex(nameB);
3542
3543 return GetGraphErrors(gr,ix,iy,fx,fy);
3544}
3545
3546TGraphTime* NcSample::GetGraph(Int_t i,Int_t j,Int_t mode,Int_t k,Bool_t smp)
3547{
3587
3588 if (!fStore)
3589 {
3590 cout << " *NcSample::GetGraph* Error : Storage mode has not been activated." << endl;
3591 return 0;
3592 }
3593
3594 if (fN<1)
3595 {
3596 cout << " *NcSample::GetGraph* Error : No data entries are stored." << endl;
3597 return 0;
3598 }
3599
3600 if (i<1 || i>fDim || j<1 || j>fDim || (mode && (k<1 || k>fDim)))
3601 {
3602 cout << " *NcSample::GetGraph* Error : Invalid index encountered i=" << i << " j=" << j << " k=" << k << endl;
3603 return 0;
3604 }
3605
3606 Double_t xlow=GetMinimum(i);
3607 Double_t xup=GetMaximum(i);
3608 Double_t ylow=GetMinimum(j);
3609 Double_t yup=GetMaximum(j);
3610
3611 // Extensions to display the points well within the frame
3612 xlow-=0.1*fabs(xlow);
3613 xup+=0.1*fabs(xup);
3614 ylow-=0.1*fabs(ylow);
3615 yup+=0.1*fabs(yup);
3616
3617 if (fGraphT)
3618 {
3619 delete fGraphT;
3620 fGraphT=0;
3621 }
3622
3623 fGraphT=new TGraphTime(fN,xlow,ylow,xup,yup);
3624 fGraphT->SetName("NcSample");
3625
3626 Double_t x=0;
3627 Double_t y=0;
3628 TMarker* m=0;
3629 Int_t jpstart=0;
3630 for (Int_t istep=0; istep<fN; istep++)
3631 {
3632 if (!smp) jpstart=istep;
3633 for (Int_t jp=jpstart; jp<=istep; jp++)
3634 {
3635 x=GetEntry(jp+1,i,mode,k);
3636 y=GetEntry(jp+1,j,mode,k);
3637 m=new TMarker(x,y,20);
3638 m->SetMarkerSize(1);
3639 fGraphT->Add(m,istep);
3640 }
3641 }
3642
3643 TString s="TGraphTime for NcSample ";
3644 s+=GetName();
3645 s+=";";
3646 s+=fNames[i-1];
3647 s+=";";
3648 s+=fNames[j-1];
3649 fGraphT->SetNameTitle("",s.Data());
3650
3651 return fGraphT;
3652}
3653
3654TGraphTime* NcSample::GetGraph(TString nameA,TString nameB,Int_t mode,TString nameC,Bool_t smp)
3655{
3694
3695 Int_t i=GetIndex(nameA);
3696 Int_t j=GetIndex(nameB);
3697 Int_t k=GetIndex(nameC);
3698 return GetGraph(i,j,mode,k,smp);
3699}
3700
3701TGraph2D NcSample::GetGraph(Int_t i,Int_t j,Int_t k,TF1* f)
3702{
3715
3716 TGraph2D gr;
3717 gr.SetName("NcSample");
3718
3719 if (!fStore)
3720 {
3721 cout << " *NcSample::GetGraph* Error : Storage mode has not been activated." << endl;
3722 return gr;
3723 }
3724
3725 if (fN<1)
3726 {
3727 cout << " *NcSample::GetGraph* Error : No data entries are stored." << endl;
3728 return gr;
3729 }
3730
3731 if (i<1 || i>fDim || j<1 || j>fDim || k<1 || k>fDim)
3732 {
3733 cout << " *NcSample::GetGraph* Error : Invalid index encountered i=" << i << " j=" << j << " k=" << k << endl;
3734 return gr;
3735 }
3736
3737 Double_t x=0;
3738 Double_t y=0;
3739 Double_t z=0;
3740 for (Int_t ip=0; ip<fN; ip++)
3741 {
3742 x=GetEntry(ip+1,i);
3743 y=GetEntry(ip+1,j);
3744 z=GetEntry(ip+1,k);
3745 if (f) z=f->Eval(z);
3746 gr.SetPoint(ip,x,y,z);
3747 }
3748
3749 TString s="TGraph2D for NcSample ";
3750 s+=GetName();
3751 s+=" : X-axis=";
3752 s+=fNames[i-1];
3753 s+=" Y-axis=";
3754 s+=fNames[j-1];
3755 s+=" Z-axis=";
3756 TString sf=fNames[k-1];
3757 if (f)
3758 {
3759 sf=f->GetExpFormula("p");
3760 sf.ReplaceAll("x",fNames[k-1]);
3761 }
3762 s+=sf;
3763 s+=";";
3764 s+=fNames[i-1];
3765 s+=";";
3766 s+=fNames[j-1];
3767 s+=";";
3768 s+=sf;
3769
3770 gr.SetTitle(s.Data());
3771
3772 gr.SetMarkerStyle(20);
3773 gr.SetMarkerSize(1);
3774 gr.SetDrawOption("P");
3775
3776 return gr;
3777}
3778
3779TGraph2D NcSample::GetGraph(Int_t i,Int_t j,Int_t k,TString f)
3780{
3790
3791 TF1 func("func",f);
3792
3793 return GetGraph(i,j,k,&func);
3794}
3795
3796TGraph2D NcSample::GetGraph(TString nameA,TString nameB,TString nameC,TF1* f)
3797{
3809
3810 Int_t i=GetIndex(nameA);
3811 Int_t j=GetIndex(nameB);
3812 Int_t k=GetIndex(nameC);
3813 return GetGraph(i,j,k,f);
3814}
3815
3816TGraph2D NcSample::GetGraph(TString nameA,TString nameB,TString nameC,TString f)
3817{
3826
3827 TF1 func("func",f);
3828
3829 return GetGraph(nameA,nameB,nameC,&func);
3830}
3831
3832TGraph2DErrors NcSample::GetGraph2DErrors(TGraph2D* gr,Int_t ix,Int_t iy,Int_t iz,TF1* fx,TF1* fy,TF1* fz)
3833{
3880
3881 TGraph2DErrors gre;
3882
3883 if (!gr)
3884 {
3885 cout << " *NcSample::GetGraph2DErrors* Error : No input Graph is specified." << endl;
3886 return gre;
3887 }
3888
3889 TString name=gr->GetName();
3890 name+=".E";
3891
3892 gre.SetName(name);
3893
3894 if ((ix || iy || iz) && !fStore)
3895 {
3896 cout << " *NcSample::GetGraph2DErrors* Error : Storage mode has not been activated." << endl;
3897 return gre;
3898 }
3899
3900 if (ix<0 || ix>fDim || iy<0 || iy>fDim || iz<0 || iz>fDim)
3901 {
3902 cout << " *NcSample::GetGraph2DErrors* Error : Invalid index encountered ix=" << ix << " iy=" << iy << " iz=" << iz << endl;
3903 return gre;
3904 }
3905
3906 // The number of data points of the input Graph
3907 Int_t np=gr->GetN();
3908
3909 if (!np)
3910 {
3911 cout << " *NcSample::GetGraph2DErrors* Error : Input Graph does not contain any data points." << endl;
3912 return gre;
3913 }
3914
3915 if ((ix || iy || iz) && np!=fN)
3916 {
3917 cout << " *NcSample::GetGraph2DErrors* Error : Entries don't match Nsample=" << fN << " Ngraph=" << np << endl;
3918 return gre;
3919 }
3920
3921 Double_t* xarr=gr->GetX();
3922 Double_t* yarr=gr->GetY();
3923 Double_t* zarr=gr->GetZ();
3924 Double_t x=0;
3925 Double_t y=0;
3926 Double_t z=0;
3927 Double_t ex=0;
3928 Double_t ey=0;
3929 Double_t ez=0;
3930 for (Int_t ip=0; ip<np; ip++)
3931 {
3932 x=xarr[ip];
3933 y=yarr[ip];
3934 z=zarr[ip];
3935 if (ix) ex=GetEntry(ip+1,ix);
3936 if (fx)
3937 {
3938 if (!ix)
3939 {
3940 ex=fx->Eval(x);
3941 }
3942 else
3943 {
3944 ex=fx->Eval(ex);
3945 }
3946 }
3947 if (iy) ey=GetEntry(ip+1,iy);
3948 if (fy)
3949 {
3950 if (!iy)
3951 {
3952 ey=fy->Eval(y);
3953 }
3954 else
3955 {
3956 ey=fy->Eval(ey);
3957 }
3958 }
3959 if (iz) ez=GetEntry(ip+1,iz);
3960 if (fz)
3961 {
3962 if (!iz)
3963 {
3964 ez=fz->Eval(z);
3965 }
3966 else
3967 {
3968 ez=fz->Eval(ez);
3969 }
3970 }
3971 ex=fabs(ex);
3972 ey=fabs(ey);
3973 ez=fabs(ez);
3974 gre.SetPoint(ip,x,y,z);
3975 gre.SetPointError(ip,ex,ey,ez);
3976 }
3977
3978 TString sfx="0";
3979 if (ix || fx)
3980 {
3981 sfx="|";
3982 if (!fx)
3983 {
3984 sfx+=fNames[ix-1];
3985 }
3986 else
3987 {
3988 sfx+=fx->GetExpFormula("p");
3989 if (ix) sfx.ReplaceAll("x",fNames[ix-1]);
3990 }
3991 sfx+="|";
3992 }
3993
3994 TString sfy="0";
3995 if (iy || fy)
3996 {
3997 sfy="|";
3998 if (!fy)
3999 {
4000 sfy+=fNames[iy-1];
4001 }
4002 else
4003 {
4004 sfy+=fy->GetExpFormula("p");
4005 if (iy)
4006 {
4007 sfy.ReplaceAll("x",fNames[iy-1]);
4008 }
4009 else
4010 {
4011 sfy.ReplaceAll("x","y");
4012 }
4013 }
4014 sfy+="|";
4015 }
4016
4017 TString sfz="0";
4018 if (iz || fz)
4019 {
4020 sfz="|";
4021 if (!fz)
4022 {
4023 sfz+=fNames[iz-1];
4024 }
4025 else
4026 {
4027 sfz+=fz->GetExpFormula("p");
4028 if (iz)
4029 {
4030 sfz.ReplaceAll("x",fNames[iz-1]);
4031 }
4032 else
4033 {
4034 sfz.ReplaceAll("x","z");
4035 }
4036 }
4037 sfz+="|";
4038 }
4039
4040 TString s="TGraphErrors for Graph : ";
4041 s+=gr->GetName();
4042 s+=" X-error=";
4043 s+=sfx;
4044 s+=" Y-error=";
4045 s+=sfy;
4046 s+=" Z-error=";
4047 s+=sfz;
4048
4049 // Copy the axes titles of the input Graph (if present)
4050 TAxis* axis=0;
4051 axis=gr->GetXaxis();
4052 if (axis)
4053 {
4054 s+=";";
4055 s+=axis->GetTitle();
4056 }
4057 axis=gr->GetYaxis();
4058 if (axis)
4059 {
4060 s+=";";
4061 s+=axis->GetTitle();
4062 }
4063 axis=gr->GetZaxis();
4064 if (axis)
4065 {
4066 s+=";";
4067 s+=axis->GetTitle();
4068 }
4069
4070 gre.SetTitle(s.Data());
4071
4072 gre.SetMarkerStyle(20);
4073 gre.SetMarkerSize(0.5);
4074 gre.SetDrawOption("err P");
4075
4076 return gre;
4077}
4078
4079TGraph2DErrors NcSample::GetGraph2DErrors(TGraph2D* gr,TString nameA,TString nameB,TString nameC,TF1* fx,TF1* fy,TF1* fz)
4080{
4127
4128 Int_t ix=GetIndex(nameA);
4129 Int_t iy=GetIndex(nameB);
4130 Int_t iz=GetIndex(nameC);
4131
4132 return GetGraph2DErrors(gr,ix,iy,iz,fx,fy,fz);
4133}
4134
4135TGraphQQ NcSample::GetQQplot(Int_t i,Int_t j,TF1* f)
4136{
4149
4150 TGraphQQ gr;
4151 gr.SetName("NcSample");
4152
4153 if (!f && (j<1 || j>fDim)) return gr;
4154
4155 if (!fStore)
4156 {
4157 cout << " *NcSample::GetQQplot* Error : Storage mode has not been activated." << endl;
4158 return gr;
4159 }
4160
4161 if (fN<1)
4162 {
4163 cout << " *NcSample::GetQQplot* Error : No data entries are stored." << endl;
4164 return gr;
4165 }
4166
4167 if (i<1 || i>fDim || (!f && (j<1 || j>fDim)))
4168 {
4169 cout << " *NcSample::GetQQplot* Error : Invalid index encountered i=" << i << " j=" << j << endl;
4170 return gr;
4171 }
4172
4173 Double_t* arri=0;
4174 if (i==1) arri=fX->GetArray();
4175 if (i==2) arri=fY->GetArray();
4176 if (i==3) arri=fZ->GetArray();
4177 if (i==4) arri=fT->GetArray();
4178
4179 if (!f)
4180 {
4181 Double_t* arrj=0;
4182 if (j==1) arrj=fX->GetArray();
4183 if (j==2) arrj=fY->GetArray();
4184 if (j==3) arrj=fZ->GetArray();
4185 if (j==4) arrj=fT->GetArray();
4186
4187 if (arri && arrj) gr=TGraphQQ(fN,arri,fN,arrj);
4188 }
4189 else
4190 {
4191 if (arri) gr=TGraphQQ(fN,arri,f);
4192 }
4193
4194 TString s="QQ-plot (TGraphQQ) for NcSample ";
4195 s+=GetName();
4196 if (f)
4197 {
4198 s+=" of ";
4199 s+=fNames[i-1];
4200 s+=" versus f(a)=";
4201 TString sf=f->GetExpFormula("p");
4202 sf.ReplaceAll("x","a");
4203 s+=sf;
4204 }
4205 else
4206 {
4207 s+=";";
4208 s+=fNames[i-1];
4209 s+=";";
4210 s+=fNames[j-1];
4211 }
4212
4213 gr.SetTitle(s.Data());
4214
4215 gr.SetMarkerStyle(20);
4216 gr.SetMarkerSize(1);
4217
4218 return gr;
4219}
4220
4221TGraphQQ NcSample::GetQQplot(TString nameA,TString nameB,TF1* f)
4222{
4234
4235 Int_t i=GetIndex(nameA);
4236 Int_t j=GetIndex(nameB);
4237 return GetQQplot(i,j,f);
4238}
4239
4240void NcSample::Load(TGraph* g,Int_t clr)
4241{
4254
4255 if (!g)
4256 {
4257 printf(" *%-s::Load* Error : No TGraph specified ==> No action taken. \n",ClassName());
4258 return;
4259 }
4260
4261 if (!clr && fDim!=2)
4262 {
4263 printf(" *%-s::Load* Error : Dimension %-i does not match a TGraph. \n",ClassName(),fDim);
4264 return;
4265 }
4266
4267 if (clr) Reset();
4268
4269 Int_t npoints=g->GetN();
4270 Double_t* x=g->GetX();
4271 Double_t* y=g->GetY();
4272
4273 if (!x || !y || npoints<1) return;
4274
4275 for (Int_t i=0; i<npoints; i++)
4276 {
4277 Enter(x[i],y[i]);
4278 }
4279}
4280
4281void NcSample::Load(TGraph2D* g,Int_t clr)
4282{
4295
4296 if (!g)
4297 {
4298 printf(" *%-s::Load* Error : No TGraph2D specified ==> No action taken. \n",ClassName());
4299 return;
4300 }
4301
4302 if (!clr && fDim!=3)
4303 {
4304 printf(" *%-s::Load* Error : Dimension %-i does not match a TGraph2D. \n",ClassName(),fDim);
4305 return;
4306 }
4307
4308 if (clr) Reset();
4309
4310 Int_t npoints=g->GetN();
4311 Double_t* x=g->GetX();
4312 Double_t* y=g->GetY();
4313 Double_t* z=g->GetZ();
4314
4315 if (!x || !y || !z || npoints<1) return;
4316
4317 for (Int_t i=0; i<npoints; i++)
4318 {
4319 Enter(x[i],y[i],z[i]);
4320 }
4321}
4322
4323void NcSample::Load(TH1* h,Int_t clr)
4324{
4337
4338 if (!h)
4339 {
4340 printf(" *%-s::Load* Error : No histogram specified ==> No action taken. \n",ClassName());
4341 return;
4342 }
4343
4344 Int_t hdim=h->GetDimension();
4345
4346 if (hdim!=1)
4347 {
4348 printf(" *%-s::Load* Error : Histograms of dimension %-i are not supported. \n",ClassName(),hdim);
4349 return;
4350 }
4351
4352 if (!clr && fDim!=1)
4353 {
4354 printf(" *%-s::Load* Error : Dimension %-i does not match a 1-dimensional histogram. \n",ClassName(),fDim);
4355 return;
4356 }
4357
4358 if (clr) Reset();
4359
4360 Int_t nbins=h->GetNbinsX();
4361
4362 Double_t val=0;
4363 for (Int_t i=1; i<=nbins; i++)
4364 {
4365 val=h->GetBinContent(i);
4366 Enter(val);
4367 }
4368}
4369
4370void NcSample::Load(TArray* arr,Int_t clr)
4371{
4384
4385 if (!arr)
4386 {
4387 printf(" *%-s::Load* Error : No data array specified ==> No action taken. \n",ClassName());
4388 return;
4389 }
4390
4391 if (!clr && fDim!=1)
4392 {
4393 printf(" *%-s::Load* Error : Dimension %-i does not match a 1-dimensional data array. \n",ClassName(),fDim);
4394 return;
4395 }
4396
4397 if (clr) Reset();
4398
4399 Int_t n=arr->GetSize();
4400
4401 Double_t val=0;
4402 for (Int_t i=0; i<n; i++)
4403 {
4404 val=arr->GetAt(i);
4405 Enter(val);
4406 }
4407}
4408
4409Double_t NcSample::GetSNR(Int_t i,Int_t mode,Bool_t dB) const
4410{
4488
4489 if (i<1 || i>fDim || !mode || abs(mode)>4) return -9999;
4490
4491 Double_t snr=-1;
4492 Double_t ymax=GetMaximum(i);
4493 Double_t ymin=GetMinimum(i);
4494 Double_t mean=GetMean(i);
4495 Double_t var=GetVar(i);
4496 Double_t rmsdev=sqrt(var);
4497 Double_t sigma=GetSigma(i,1);
4498 Double_t stdev=rmsdev;
4499 if (mode<0) stdev=sigma;
4500
4501 if (stdev<=0) return -9999;
4502
4504 // SNR of a transient signal //
4506
4507 if (abs(mode)>2)
4508 {
4509 if (abs(mode)==3) // Data are power or RMS amplitudes
4510 {
4511 snr=(ymax-ymin)/stdev;
4512 }
4513 if (abs(mode)==4) // Data are bipolar amplitudes
4514 {
4515 snr=(ymax-ymin)/(2.*stdev);
4516 }
4517
4518 if (dB && snr>0) snr=10.*log10(snr);
4519
4520 return snr;
4521 }
4522
4524 // SNR of a continuous signal //
4526
4527 // Treat the values as observed amplitudes and work in dB scale
4528 Double_t psignal=mean*mean;
4529 Double_t pnoise=stdev*stdev;
4530
4531 if (psignal>0 && pnoise>0)
4532 {
4533 snr=10.*(log10(psignal)-log10(pnoise));
4534 if (abs(mode)==1) snr=snr/2.; // Treat values as observed power
4535 if (!dB) // Convert to the straight ratio
4536 {
4537 snr=snr/10.;
4538 snr=pow(10,snr);
4539 }
4540 }
4541
4542 return snr;
4543}
4544
4545Double_t NcSample::GetSNR(TString name,Int_t mode,Bool_t dB) const
4546{
4623
4624 Int_t i=GetIndex(name);
4625 return GetSNR(i,mode,dB);
4626}
4627
4628Double_t NcSample::GetCV(Int_t i,Int_t mode) const
4629{
4654
4655 if (i<1 || i>fDim || abs(mode)<1 || abs(mode)>2) return -1;
4656
4657 Double_t vmax=GetMaximum(i);
4658 Double_t vmin=GetMinimum(i);
4659 Double_t value=GetMean(i);
4660 if (abs(mode)==2) value=(vmax-vmin)/2.;
4661 Double_t stdev=GetSigma(i,0);
4662 if (mode<0) stdev=GetSigma(i,1);
4663
4664 Double_t cv=-1;
4665
4666 if (value) cv=fabs(stdev/value);
4667
4668 return cv;
4669}
4670
4671Double_t NcSample::GetCV(TString name,Int_t mode) const
4672{
4696
4697 Int_t i=GetIndex(name);
4698 return GetCV(i,mode);
4699}
4700
4701void NcSample::Animation(Int_t i,Int_t j,Int_t mode,Int_t k,Int_t delay,TString opt)
4702{
4728
4729 if (!fStore || fN<1 || i<1 || i>fDim || j<1 || j>fDim || (mode && (k<1 || k>fDim)) || delay<0)
4730 {
4731 cout << " *NcSample::Animation* Inconsistent input data." << endl;
4732 return;
4733 }
4734
4735 if (fCanvas)
4736 {
4737 delete fCanvas;
4738 fCanvas=0;
4739 }
4740
4741 if (fAnimObject)
4742 {
4743 delete fAnimObject;
4744 fAnimObject=0;
4745 }
4746
4747 fCanvas=new TCanvas("fCanvas","Sampling animation");
4748
4749 TGraph* gr=new TGraph();
4750 fAnimObject=gr;
4751
4752 TString s="Sampling animation for NcSample ";
4753 s+=GetName();
4754 gr->SetTitle(s.Data());
4755 gr->SetMarkerStyle(20);
4756 gr->SetMarkerSize(1);
4757
4758 Double_t x=0;
4759 Double_t y=0;
4760 for (Int_t ip=0; ip<fN; ip++)
4761 {
4762 x=GetEntry(ip+1,i,mode,k);
4763 y=GetEntry(ip+1,j,mode,k);
4764 gr->SetPoint(ip,x,y);
4765
4766 if (!ip) gr->Draw(opt.Data());
4767
4768 s="Variable ";
4769 s+=fNames[i-1];
4770 gr->GetXaxis()->SetTitle(s.Data());
4771 s="Variable ";
4772 s+=fNames[j-1];
4773 gr->GetYaxis()->SetTitle(s.Data());
4774
4775 fCanvas->Modified();
4776 fCanvas->Update();
4777
4778 gSystem->Sleep(delay);
4779 }
4780}
4781
4782void NcSample::Animation(TString nameA,TString nameB,Int_t mode,TString nameC,Int_t delay,TString opt)
4783{
4808
4809 Int_t i=GetIndex(nameA);
4810 Int_t j=GetIndex(nameB);
4811 Int_t k=GetIndex(nameC);
4812 Animation(i,j,mode,k,delay,opt);
4813}
4814
4815void NcSample::Animation(Int_t i,Int_t j,Int_t k,Int_t mode,Int_t m,Int_t delay,TString opt)
4816{
4842
4843 if (!fStore || fN<1 || i<1 || i>fDim || j<1 || j>fDim || k<1 || k>fDim || (mode && (m<1 || m>fDim)) || delay<0)
4844 {
4845 cout << " *NcSample::Animation* Inconsistent input data." << endl;
4846 return;
4847 }
4848
4849 if (fCanvas)
4850 {
4851 delete fCanvas;
4852 fCanvas=0;
4853 }
4854
4855 if (fAnimObject)
4856 {
4857 delete fAnimObject;
4858 fAnimObject=0;
4859 }
4860
4861 fCanvas=new TCanvas("fCanvas","Sampling animation");
4862
4863 TGraph2D* gr=new TGraph2D(fN);
4864 fAnimObject=gr;
4865
4866 TString s="Sampling animation for NcSample ";
4867 s+=GetName();
4868 gr->SetTitle(s.Data());
4869 gr->SetMarkerStyle(20);
4870 gr->SetMarkerSize(1);
4871
4872 Double_t x=0;
4873 Double_t y=0;
4874 Double_t z=0;
4875 for (Int_t ip=0; ip<fN; ip++)
4876 {
4877 x=GetEntry(ip+1,i,mode,m);
4878 y=GetEntry(ip+1,j,mode,m);
4879 z=GetEntry(ip+1,k,mode,m);
4880 gr->SetPoint(ip,x,y,z);
4881
4882 if (!ip) gr->Draw(opt.Data());
4883
4884 s="Variable ";
4885 s+=fNames[i-1];
4886 gr->GetXaxis()->SetTitle(s.Data());
4887 s="Variable ";
4888 s+=fNames[j-1];
4889 gr->GetYaxis()->SetTitle(s.Data());
4890 s="Variable ";
4891 s+=fNames[k-1];
4892 gr->GetZaxis()->SetTitle(s.Data());
4893
4894 fCanvas->Modified();
4895 fCanvas->Update();
4896
4897 gSystem->Sleep(delay);
4898 }
4899}
4900
4901void NcSample::Animation(TString nameA,TString nameB,TString nameC,Int_t mode,TString nameD,Int_t delay,TString opt)
4902{
4927
4928 Int_t i=GetIndex(nameA);
4929 Int_t j=GetIndex(nameB);
4930 Int_t k=GetIndex(nameC);
4931 Int_t m=GetIndex(nameD);
4932 Animation(i,j,k,mode,m,delay,opt);
4933}
4934
4935Double_t NcSample::Digitize(Int_t i,Int_t nbits,Double_t vcal,Int_t mode)
4936{
4999
5000 if (mode<0 || mode>3)
5001 {
5002 cout << " *NcSample::Digitize* Inconsistent input mode=" << mode << endl;
5003 return 0;
5004 }
5005
5006 if (!nbits || nbits>60 || nbits<-60 || fabs(vcal)<=0)
5007 {
5008 cout << " *NcSample::Digitize* Inconsistent input nbits=" << nbits << " vcal=" << vcal << endl;
5009 return 0;
5010 }
5011
5012 if ((mode==1 || mode==3) && nbits==1)
5013 {
5014 cout << " *NcSample::Digitize* Inconsistent input nbits=" << nbits << " mode=" << mode << endl;
5015 return 0;
5016 }
5017
5018 Bool_t logmode=kFALSE;
5019 if (nbits<0) logmode=kTRUE;
5020
5021 nbits=abs(nbits);
5022
5023 Long_t nlevels=pow(2,nbits);
5024 Double_t range=fabs(vcal);
5025 if (mode==1 || mode==3) range*=2.;
5026 Double_t step=fabs(vcal);
5027 if (mode==0) step=range/double(nlevels-1);
5028 if (mode==1) step=range/double(nlevels-2);
5029
5030 if (step<=0) return 0;
5031
5032 Long_t nstepsmin=0;
5033 Long_t nstepsmax=nlevels-1;
5034 if ((mode==0 || mode==2) && vcal<0)
5035 {
5036 nstepsmin=-nlevels+1;
5037 nstepsmax=0;
5038 }
5039 if (mode==1 || mode==3)
5040 {
5041 nstepsmin=-nlevels/2;
5042 nstepsmax=nlevels/2-1;
5043 }
5044
5045 Double_t digvalmin=double(nstepsmin)*step;
5046 Double_t digvalmax=double(nstepsmax)*step;
5047
5048 cout << " *NcSample::Digitize* Parameters of the " << nbits << "-bits";
5049 if (logmode) cout << " Log10";
5050 cout << " ADC digitization";
5051 if (i>0 && i<=fDim) cout << " of variable : " << i << " (" << fNames[i-1] << ")";
5052 cout << endl;
5053 TString s="linear";
5054 if (logmode) s="Log10";
5055 if (mode==0 || mode==2)
5056 {
5057 cout << " Digitized " << s << " full scale range : [" << digvalmin << "," << digvalmax << "] Step size : " << step << endl;
5058 }
5059 if (mode==1 || mode==3)
5060 {
5061 cout << " Digitized " << s << " full scale range : [" << (digvalmin+step) << "," << digvalmax << "] Step size : " << step;
5062 cout << " Actual range : [" << digvalmin << "," << digvalmax << "]" << endl;
5063 }
5064
5065 if (logmode)
5066 {
5067 Double_t linvalmin=pow(10,digvalmin);
5068 Double_t linvalmax=pow(10,digvalmax);
5069 if (mode==0 || mode==2)
5070 {
5071 cout << " Digitized linear full scale range : [" << linvalmin << "," << linvalmax << "]" << endl;
5072 }
5073 if (mode==1 || mode==3)
5074 {
5075 cout << " Digitized linear full scale range : [" << (linvalmin*pow(10,step)) << "," << linvalmax << "]";
5076 cout << " Actual range : [" << linvalmin << "," << linvalmax << "]" << endl;
5077 }
5078 }
5079
5080 Double_t retval=step;
5081 if (mode==2)
5082 {
5083 if (vcal<0) retval=digvalmin;
5084 if (vcal>0) retval=digvalmax;
5085 }
5086 if (mode==3) retval=digvalmax;
5087
5088 if (!fStore)
5089 {
5090 cout << endl;
5091 cout << " *NcSample::Digitize* Error : Storage mode has not been activated." << endl;
5092 return retval;
5093 }
5094
5095 Double_t minval=1;
5096 if (i>0 && i<=fDim) minval=GetMinimum(i);
5097
5098 if (logmode && minval<=0)
5099 {
5100 cout << endl;
5101 cout << " *NcSample::Digitize* Non-positive input value(s) for Log10 ADC i=" << i << " minimum=" << minval << endl;
5102 return retval;
5103 }
5104
5105 if (i<1 || i>fDim)
5106 {
5107 cout << endl;
5108 cout << " *NcSample::Digitize* Value i=" << i << " is outside range. Only listing of ADC specs." << endl;
5109 return retval;
5110 }
5111
5112 Double_t val=0;
5113 Long_t nsteps=0;
5114 Double_t digval=0;
5115 for (Int_t j=1; j<=fN; j++)
5116 {
5117 val=GetEntry(j,i);
5118
5119 if (logmode) val=log10(val);
5120
5121 nsteps=val/step;
5122
5123 if (nsteps<nstepsmin) nsteps=nstepsmin;
5124 if (nsteps>nstepsmax) nsteps=nstepsmax;
5125
5126 digval=double(nsteps)*step;
5127
5128 if (logmode) digval=pow(10,digval);
5129
5130 if (i==1) fX->AddAt(digval,j-1);
5131 if (i==2) fY->AddAt(digval,j-1);
5132 if (i==3) fZ->AddAt(digval,j-1);
5133 if (i==4) fT->AddAt(digval,j-1);
5134 }
5135
5136 return retval;
5137}
5138
5139Double_t NcSample::Digitize(TString name,Int_t nbits,Double_t vcal,Int_t mode)
5140{
5203
5204 Int_t i=GetIndex(name);
5205
5206 return Digitize(i,nbits,vcal,mode);
5207}
5208
5209TArrayL64 NcSample::ADC(Int_t nbits,Double_t range,Double_t Vbias,TArray* Vsig,TH1* hist,Int_t B,Int_t C) const
5210{
5293
5294 TArrayL64 arradc(0);
5295 if (hist) hist->Reset();
5296
5297 Int_t nVsig=0;
5298 if (Vsig) nVsig=Vsig->GetSize();
5299
5300 if (nbits<=0 || nbits>60 || !range || fabs(Vbias)>fabs(range) || B<0 || (B && C<1))
5301 {
5302 printf("\n *%-s::ADC* Inconsistent input nbits=%-i range=%-g Vbias=%-g B=%-i C=%-i \n",ClassName(),nbits,range,Vbias,B,C);
5303 return arradc;
5304 }
5305
5306 NcMath math;
5307
5308 Long64_t N=pow(2,nbits); // The number of quantization levels
5309 Long64_t adcmin=0;
5310 Long64_t adcmax=N-1;
5311 Double_t Vref=0;
5312 Double_t Vfs=0;
5313 Double_t LSB=0;
5314
5315 // Floating point version of some parameters
5316 Double_t rN=N;
5317 Double_t rB=B;
5318 if (B==1) rB=exp(1);
5319 Double_t rC=C;
5320 Double_t radcmax=adcmax;
5321
5322 if (range<0) // |range| represents Vref
5323 {
5324 Vref=fabs(range);
5325 LSB=Vref/rN;
5326 Vfs=Vref-LSB;
5327 }
5328 else // range represents Vfs
5329 {
5330 Vfs=range;
5331 LSB=Vfs/radcmax;
5332 Vref=Vfs+LSB;
5333 }
5334
5335 Long64_t ped=0;
5336 Double_t frac=0;
5337 if (B) // Log ADC
5338 {
5339 if (range<0) Vfs=pow(rB,-rC)*pow(rB,radcmax*rC/rN)*Vref;
5340 if (range>0) Vref=pow(rB,rC)*pow(rB,-radcmax*rC/rN)*Vfs;
5341 LSB=Vref*pow(rB,-rC)*(pow(rB,rC/rN)-1.);
5342 frac=Vbias/Vref;
5343 ped=0;
5344 if (frac>0) ped=Long64_t(rN*(math.Log(rB,frac)+rC)/rC);
5345 }
5346
5347 if (LSB<=0 || Vfs<=0)
5348 {
5349 printf("\n *%-s::ADC* Inconsistent parameters : LSB=%-g Vfs=%-g \n",ClassName(),LSB,Vfs);
5350 return arradc;
5351 }
5352
5353 if (!B) ped=Vbias/LSB; // Pedestal value for a linear ADC
5354
5355 Double_t DR=20.*log10(Vfs/LSB);
5356
5357 TString mode="linear";
5358 if (B==1) mode="Log_e";
5359 if (B>1)
5360 {
5361 mode="Log_";
5362 mode+=B;
5363 }
5364
5365 if (!nVsig)
5366 {
5367 printf(" *%-s::ADC* No input data have been provided --> Only the value of adc(Vbias) is returned. \n",ClassName());
5368 if (!B)
5369 {
5370 printf(" Parameters for a %-i-bits %-s ADC with adc=[%-lli,%-lli] : \n",nbits,mode.Data(),adcmin,adcmax);
5371 printf(" Vref=%-g Vfs=%-g LSB=%-g DR=%-g (dB) Vbias=%-g adc(Vbias)=%-lli \n",Vref,Vfs,LSB,DR,Vbias,ped);
5372 }
5373 else
5374 {
5375 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);
5376 printf(" Vref=%-g Vfs=%-g LSB=%-g DR=%-g (dB) Vbias=%-g adc(Vbias)=%-lli \n",Vref,Vfs,LSB,DR,Vbias,ped);
5377 }
5378 arradc.Set(1);
5379 arradc[0]=ped;
5380 return arradc;
5381 }
5382
5383 arradc.Set(nVsig);
5384
5385 if (hist)
5386 {
5387 TString title;
5388 title.Form("%-s %-i-bits %-s ADC with Vfs=%-g LSB=%-g;Sample number;ADC counts",ClassName(),nbits,mode.Data(),Vfs,LSB);
5389 hist->SetBins(nVsig,0,nVsig);
5390 hist->SetMarkerStyle(20);
5391 hist->SetTitle(title);
5392 }
5393
5394 Double_t val=0;
5395 Double_t radcval=0;
5396 Long64_t adcval=0;
5397 for (Int_t j=0; j<nVsig; j++)
5398 {
5399 val=Vbias+Vsig->GetAt(j);
5400
5401 if (B) // Log ADC
5402 {
5403 radcval=0;
5404 frac=val/Vref;
5405 if (frac>0) radcval=(rN/rC)*(math.Log(rB,frac)+rC);
5406 }
5407 else // Linear ADC
5408 {
5409 radcval=val/LSB;
5410 }
5411
5412 adcval=Long64_t(radcval);
5413
5414 // Check for saturation
5415 if (adcval<adcmin) adcval=adcmin;
5416 if (adcval>adcmax) adcval=adcmax;
5417
5418 arradc[j]=adcval;
5419
5420 if (hist) hist->SetBinContent(j+1,adcval);
5421 }
5422
5423 return arradc;
5424}
5425
5426TArrayD NcSample::DAC(Int_t nbits,Double_t range,Double_t Vbias,TArray* adcs,TArray* peds,TH1* hist,Int_t B,Int_t C) const
5427{
5514
5515 TArrayD arrdac(0);
5516 if (hist) hist->Reset();
5517
5518 Int_t nadcs=0;
5519 if (adcs) nadcs=adcs->GetSize();
5520
5521 Int_t npeds=0;
5522 if (peds) npeds=peds->GetSize();
5523
5524 if (nbits<=0 || nbits>60 || !range || fabs(Vbias)>fabs(range) || (peds && npeds<nadcs) || B<0 || (B && C<1))
5525 {
5526 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);
5527 return arrdac;
5528 }
5529
5530 NcMath math;
5531
5532 Long64_t N=pow(2,nbits); // The number of quantization levels
5533 Long64_t adcmin=0;
5534 Long64_t adcmax=N-1;
5535 Double_t Vref=0;
5536 Double_t Vfs=0;
5537 Double_t LSB=0;
5538
5539 // Floating point version of some parameters
5540 Double_t rN=N;
5541 Double_t rB=B;
5542 if (B==1) rB=exp(1);
5543 Double_t rC=C;
5544 Double_t radcmax=adcmax;
5545
5546 if (range<0) // |range| represents Vref
5547 {
5548 Vref=fabs(range);
5549 LSB=Vref/rN;
5550 Vfs=Vref-LSB;
5551 }
5552 else // range represents Vfs
5553 {
5554 Vfs=range;
5555 LSB=Vfs/radcmax;
5556 Vref=Vfs+LSB;
5557 }
5558
5559 Long64_t ped=0;
5560 Double_t frac=0;
5561 if (B) // Log DAC
5562 {
5563 if (range<0) Vfs=pow(rB,-rC)*pow(rB,radcmax*rC/rN)*Vref;
5564 if (range>0) Vref=pow(rB,rC)*pow(rB,-radcmax*rC/rN)*Vfs;
5565 LSB=Vref*pow(rB,-rC)*(pow(rB,rC/rN)-1.);
5566 frac=Vbias/Vref;
5567 ped=0;
5568 if (frac>0) ped=Long64_t(rN*(math.Log(rB,frac)+rC)/rC);
5569 }
5570
5571 if (LSB<=0 || Vfs<=0)
5572 {
5573 printf("\n *%-s::DAC* Inconsistent parameters : LSB=%-g Vfs=%-g \n",ClassName(),LSB,Vfs);
5574 return arrdac;
5575 }
5576
5577 if (!B) ped=Vbias/LSB; // Pedestal value for a linear DAC
5578
5579 Double_t DR=20.*log10(Vfs/LSB);
5580
5581 TString mode="linear";
5582 if (B==1) mode="Log_e";
5583 if (B>1)
5584 {
5585 mode="Log_";
5586 mode+=B;
5587 }
5588
5589 if (!nadcs)
5590 {
5591 printf(" *%-s::DAC* No input data have been provided --> Only the value of adc(Vbias) is returned. \n",ClassName());
5592 if (!B)
5593 {
5594 printf(" Parameters for a %-i-bits %-s DAC with adc=[%-lli,%-lli] : \n",nbits,mode.Data(),adcmin,adcmax);
5595 printf(" Vref=%-g Vfs=%-g LSB=%-g DR=%-g (dB) Vbias=%-g adc(Vbias)=%-lli \n",Vref,Vfs,LSB,DR,Vbias,ped);
5596 }
5597 else
5598 {
5599 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);
5600 printf(" Vref=%-g Vfs=%-g LSB=%-g DR=%-g (dB) Vbias=%-g adc(Vbias)=%-lli \n",Vref,Vfs,LSB,DR,Vbias,ped);
5601 }
5602 arrdac.Set(1);
5603 arrdac[0]=ped;
5604 return arrdac;
5605 }
5606
5607 arrdac.Set(nadcs);
5608
5609 if (hist)
5610 {
5611 TString title;
5612 title.Form("%-s %-i-bits %-s DAC with Vfs=%-g LSB=%-g;Sample number;Amplitude",ClassName(),nbits,mode.Data(),Vfs,LSB);
5613 hist->SetBins(nadcs,0,nadcs);
5614 hist->SetMarkerStyle(20);
5615 hist->SetTitle(title);
5616 }
5617
5618 Long64_t adc=0;
5619 Double_t radc=0;
5620 Double_t dacval=0;
5621 for (Int_t j=0; j<nadcs; j++)
5622 {
5623 adc=adcs->GetAt(j);
5624 radc=adc;
5625
5626 if (B) // Log DAC
5627 {
5628 dacval=Vref*pow(rB,-rC)*pow(rB,radc*rC/rN);
5629 }
5630 else // Linear DAC
5631 {
5632 if (peds)
5633 {
5634 ped=peds->GetAt(j);
5635 adc=adc-ped;
5636 radc=adc;
5637 }
5638 dacval=radc*LSB;
5639 }
5640
5641 // Correct for bias voltage
5642 if (B || (!B && !peds))
5643 {
5644 dacval=dacval-Vbias;
5645 }
5646
5647 arrdac[j]=dacval;
5648
5649 if (hist) hist->SetBinContent(j+1,dacval);
5650 }
5651
5652 return arrdac;
5653}
5654
5655Long64_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)
5656{
5729
5730 TArrayL64 adcarr;
5731 TArrayD dacarr;
5732 if (hist) hist->Reset();
5733
5734 if (!fStore)
5735 {
5736 printf("\n *%-s::Transmit* Error : Storage mode has not been activated. \n",ClassName());
5737 printf(" No digitization is performed. \n");
5738 return -1;
5739 }
5740
5741 if (i<1 || i>fDim)
5742 {
5743 printf("\n *%-s::Transmit* Invalid variable name or index (i=%-i) --> Only listing of ADC specs. \n",ClassName(),i);
5744 adcarr=ADC(nbits,range,Vbias,0,0,B,C);
5745 return adcarr[0];
5746 }
5747
5748 if (!fN)
5749 {
5750 printf("\n *%-s::Transmit* No data available for variable %-s (index=%-i) --> Only listing of ADC specs. \n",ClassName(),fNames[i-1].Data(),i);
5751 adcarr=ADC(nbits,range,Vbias,0,0,B,C);
5752 return adcarr[0];
5753 }
5754
5755 Double_t minval=GetMinimum(i);
5756 Double_t Vin=minval+Vbias;
5757
5758 if (B && Vin<=0)
5759 {
5760 TString mode="Log_e";
5761 if (B>1)
5762 {
5763 mode="Log_";
5764 mode+=B;
5765 }
5766 printf("\n *%-s::Transmit* Non-positive input value(s) for %-s ADC --> No digitization is performed. \n",ClassName(),mode.Data());
5767 printf(" Minimum+Vbias=%-g+%-g=%-g for variable with name %-s (index i=%-i). \n",minval,Vbias,Vin,fNames[i-1].Data(),i);
5768 return -1;
5769 }
5770
5771 // Get the corresponding data array
5772 TArrayD* arrin=0;
5773 if (i==1) arrin=fX;
5774 if (i==2) arrin=fY;
5775 if (i==3) arrin=fZ;
5776 if (i==4) arrin=fT;
5777
5778 // Perform the digitization via the ADC processeor
5779 adcarr=ADC(nbits,range,Vbias,arrin,0,B,C);
5780
5781 // Convert the digital data into analog signals via the DAC processor
5782 dacarr=DAC(nbits,range,Vbias,&adcarr,peds,hist,B,C);
5783
5784 if (hist)
5785 {
5786 TString title=hist->GetTitle();
5787 title.ReplaceAll("DAC","ADC-DAC (Transmit)");
5788 hist->SetTitle(title);
5789 }
5790
5791 Int_t ndac=dacarr.GetSize();
5792 if (ndac<fN)
5793 {
5794 printf("\n *%-s::Transmit* Inconsistent number of entries : Nsamplings=%-i Ndac=%-i --> No digitization is performed. \n",ClassName(),fN,ndac);
5795 return -1;
5796 }
5797
5798 // Replace the values of the i-th variable
5799 Double_t val=0;
5800 for (Int_t j=0; j<fN; j++)
5801 {
5802 val=dacarr[j];
5803 arrin->AddAt(val,j);
5804 }
5805
5806 return -1;
5807}
5808
5809Long64_t NcSample::Transmit(TString name,Int_t nbits,Double_t range,Double_t Vbias,TArray* peds,TH1* hist,Int_t B,Int_t C)
5810{
5884
5885 Int_t i=GetIndex(name);
5886
5887 return Transmit(i,nbits,range,Vbias,peds,hist,B,C);
5888}
5889
5890NcSample NcSample::SampleAndHold(TF1 f,Double_t step,Double_t vmin,Double_t vmax,Int_t loc) const
5891{
5910
5911 NcSample s("SampleAndHold","Error occurred in SampleAndHold");
5912 s.SetStoreMode(1);
5913
5914 if (step<=0 || vmax<=vmin)
5915 {
5916 cout << " *NcSample::SampleAndHold* Error : Invalid input step=" << step << " vmin=" << vmin << " vmax=" << vmax << endl;
5917 return s;
5918 }
5919
5920 TString str="For Function ";
5921 str+=f.GetExpFormula("p");
5922 str+=" with step=%-10.3g";
5923 TString str2=str.Format(str.Data(),step);
5924 s.SetTitle(str2.Data());
5925
5926 // Enter the sampled data into the new sample
5927 Double_t xlow=vmin;
5928 Double_t xval=0;
5929 Double_t yval=0;
5930 while (xlow<=vmax)
5931 {
5932 yval=f.Eval(xlow);
5933 if (loc<0) xval=xlow;
5934 if (!loc) xval=xlow+step/2.;
5935 if (loc>0) xval=xlow+step;
5936 if (xval>vmax) xval=vmax;
5937 s.Enter(xval,yval);
5938
5939 xlow+=step;
5940 }
5941
5942 return s;
5943}
5944
5945NcSample NcSample::SampleAndSum(Int_t i,Double_t step,Int_t loc,Int_t j,Double_t vmin,Double_t vmax)
5946{
5973
5974 NcSample s("SampleAndSum","Error occurred in SampleAndSum");
5975 s.SetStoreMode(1);
5976
5977 if (!fStore)
5978 {
5979 cout << " *NcSample::SampleAndSum* Error : Storage mode has not been activated." << endl;
5980 return s;
5981 }
5982
5983 if (i<1 || i>fDim || j>fDim)
5984 {
5985 cout << " *NcSample::SampleAndSum* Error : Invalid index encountered i=" << i << " j=" << j << endl;
5986 return s;
5987 }
5988
5989 if (step<=0)
5990 {
5991 cout << " *NcSample::SampleAndSum* Error : Invalid step size step=" << step << endl;
5992 return s;
5993 }
5994
5995 TString xname=fNames[i-1];
5996 TString yname="Counts";
5997 if (j>0) yname=fNames[j-1];
5998
5999 s.SetNames(xname,yname);
6000
6001 TString str="For Variable ";
6002 str+=xname;
6003 str+=" with step=%-10.3g";
6004 TString str2=str.Format(str.Data(),step);
6005 s.SetTitle(str2.Data());
6006
6007 // Define a histogram with "step" as binsize
6008 Double_t xmin=GetMinimum(i);
6009 Double_t xmax=GetMaximum(i);
6010
6011 if (vmax>vmin)
6012 {
6013 xmin=vmin;
6014 xmax=vmax;
6015 }
6016
6017 Int_t nbx=(xmax-xmin)/step;
6018 nbx++;
6019
6020 Double_t* bins=new Double_t[nbx+1];
6021 Double_t xlow=xmin;
6022 for (Int_t idx=0; idx<=nbx; idx++)
6023 {
6024 bins[idx]=xlow;
6025 xlow+=step;
6026 }
6027
6028 TH1D hist("","",nbx,bins);
6029
6030 // Fill the histogram with data of the original sample
6031 Double_t xval=0;
6032 Double_t yval=1;
6033 for (Int_t ient=1; ient<=fN; ient++)
6034 {
6035 xval=GetEntry(ient,i);
6036 if (j>0) yval=GetEntry(ient,j);
6037 hist.Fill(xval,yval);
6038 }
6039
6040 // Enter the histgram data into the new sample
6041 Int_t nbins=hist.GetNbinsX();
6042 Double_t binwidth=hist.GetBinWidth(1);
6043 for (Int_t k=1; k<=nbins; k++)
6044 {
6045 if (loc) xval=hist.GetBinLowEdge(k);
6046 if (!loc) xval=hist.GetBinCenter(k);
6047 if (loc>0) xval+=binwidth;
6048 yval=hist.GetBinContent(k);
6049 s.Enter(xval,yval);
6050 }
6051
6052 delete [] bins;
6053 return s;
6054}
6055
6056NcSample NcSample::SampleAndSum(TString nameA,Double_t step,Int_t loc,TString nameB,Double_t vmin,Double_t vmax)
6057{
6083
6084 Int_t i=GetIndex(nameA);
6085 Int_t j=GetIndex(nameB);
6086
6087 return SampleAndSum(i,step,loc,j,vmin,vmax);
6088}
6089
6090TObject* NcSample::Clone(const char* name) const
6091{
6101
6102 NcSample* q=new NcSample(*this);
6103 if (name)
6104 {
6105 if (strlen(name)) q->SetName(name);
6106 }
6107 return q;
6108}
6109
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:991
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:357
void SetNames(TString name1="X", TString name2="Y", TString name3="Z", TString name4="T")
Definition NcSample.cxx:327
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:858
void ListOrdered(Int_t mode, Int_t i)
Double_t fMean[fMaxdim]
Definition NcSample.h:146
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
void SetStoreMode(Int_t mode=1, Int_t nmax=0, Int_t i=0)
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:410
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