NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
NcDevice.cxx
Go to the documentation of this file.
1
31
33
39// By default private copies of the recorded hits will be made.
40// This implies that by default the device will own the registered hits.
41// See the SetHitCopy() memberfunction for further details.
42// An NcDevice object itself has (in addition to hit storage) also the
43// complete functionality of the class NcSignal.
44//
45// Example :
46// =========
47//
48// NcDevice m;
49// // Set user defined status word to indicate e.g. readout electronics version
50// m.SetStatus(100201);
51// m.SetHitCopy(1);
52// m.SetName("OM123");
53//
54// Float_t pos[3]={1,2,3};
55// m.SetPosition(pos,"car");
56//
57// NcSignal s;
58//
59// s.Reset(1);
60// s.SetName("OM123 Hit 1");
61// s.SetSlotName("ADC");
62// s.SetSignal(10);
63// s.SetSlotName("LE",2);
64// s.SetSignal(-100,2);
65// s.SetSlotName("TOT",3);
66// s.SetSignal(-1000,3);
67// m.AddHit(s);
68//
69// s.Reset(1);
70// s.SetName("OM123 Hit 2");
71// s.SetSlotName("ADC");
72// s.SetSignal(11);
73// s.SetSlotName("LE",2);
74// s.SetSignal(-101,2);
75// s.SetSlotName("TOT",3);
76// s.SetSignal(1001,3);
77// m.AddHit(s);
78//
79// s.Reset(1);
80// s.SetName("OM123 Hit 3");
81// s.SetSlotName("ADC");
82// s.SetSignal(12);
83// s.SetSlotName("LE",2);
84// s.SetSignal(-102,2);
85// s.SetSlotName("TOT",3);
86// s.SetSignal(-1002,3);
87// m.AddHit(s);
88//
89// TObjArray* ordered=m.SortHits("TOT");
90// nhits=ordered->GetEntries();
91// for (Int_t i=0; i<nhits; i++)
92// {
93// NcSignal* sx=(NcSignal*)ordered->At(i);
94// if (sx) sx->Data();
95// }
96//
97//--- Author: Nick van Eijndhoven 23-jun-2004 Utrecht University
98//- Modified: Nick van Eijndhoven, IIHE-VUB, Brussel, July 1, 2021 09:27Z
99~~~
100**/
102
103#include "NcDevice.h"
104#include "Riostream.h"
105
106ClassImp(NcDevice); // Class implementation to enable ROOT I/O
107
109NcDevice::NcDevice(const char* name,const char* title) : NcSignal(name,title)
110{
120
121 fStatus=0;
122 fHitCopy=1;
123 fHits=0;
124 fOrdered=0;
125 fMarkers=0;
126}
127
129{
135
136 // Remove backward links to this device from the hits which were not owned by it.
137 // Note : If a hit has been deleted in the meantime the NcSignal destructor has already
138 // automatically removed the corresponding pointer from the storage of this device.
139 if (!fHitCopy)
140 {
141 for (Int_t ih=1; ih<=GetNhits(); ih++)
142 {
143 NcSignal* sx=GetHit(ih);
144 if (sx) sx->ResetLinks(this);
145 }
146 }
147
148 if (fHits)
149 {
150 delete fHits;
151 fHits=0;
152 }
153
154 if (fOrdered)
155 {
156 delete fOrdered;
157 fOrdered=0;
158 }
159
160 if (fMarkers)
161 {
162 delete fMarkers;
163 fMarkers=0;
164 }
165}
166
168{
174
175 fHits=0;
176 fOrdered=0;
177 fMarkers=0;
178
179 fStatus=dev.GetStatus();
180 fHitCopy=dev.GetHitCopy();
181
182 Int_t nhits=dev.GetNhits();
183 if (nhits)
184 {
185 fHits=new TObjArray(nhits);
186 if (fHitCopy) fHits->SetOwner();
187 NcSignal* sx=0;
188 for (Int_t ih=1; ih<=nhits; ih++)
189 {
190 sx=dev.GetHit(ih);
191
192 if (!sx) continue;
193
194 if (fHitCopy)
195 {
196 fHits->Add(sx->Clone());
197 NcSignal* s=(NcSignal*)fHits->Last();
198 s->ResetLinks((NcDevice*)&dev);
199 s->fDevset=kTRUE;
200 s->SetDevice(this);
201 s->fDevset=kFALSE;
202 }
203 else
204 {
205 TArrayI js;
206 TArrayI ks;
207 Int_t nlinks=sx->GetIndices((NcDevice*)&dev,js,ks);
208 Int_t j=0;
209 Int_t k=0;
210 for (Int_t il=0; il<nlinks; il++)
211 {
212 j=js.At(il);
213 k=ks.At(il);
214 sx->SetLink(this,j,k);
215 }
216 fHits->Add(sx);
217 }
218 }
219 }
220}
221
222void NcDevice::Reset(Int_t mode)
223{
232
233 RemoveHits();
234 NcSignal::Reset(mode);
235}
236
238{
251
252 if (!fHits)
253 {
254 if (j==0 || j==1)
255 {
256 fHitCopy=j;
257 }
258 else
259 {
260 cout << "*NcDevice::SetHitCopy* Invalid argument : " << j << endl;
261 }
262 }
263 else
264 {
265 cout << "*NcDevice::SetHitCopy* Storage already contained hits."
266 << " ==> HitCopy mode not changed." << endl;
267 }
268}
269
271{
279
280 return fHitCopy;
281}
282
283void NcDevice::SetOwner(Bool_t own)
284{
307
308 Int_t mode=1;
309 if (!own) mode=0;
310 if (fHits) fHits->SetOwner(own);
311 fHitCopy=mode;
312}
313
314void NcDevice::SetStatus(Int_t word)
315{
321
322 fStatus=word;
323}
324
326{
332
333 return fStatus;
334}
335
337{
352
353 if (!fHits)
354 {
355 fHits=new TObjArray(1);
356 if (fHitCopy) fHits->SetOwner();
357 }
358
359 // Check if this signal is already stored for this device.
360 Int_t nhits=GetNhits();
361 for (Int_t i=0; i<nhits; i++)
362 {
363 if (&s==fHits->At(i)) return;
364 }
365
366 // Check for existing (backward) link to this device.
367 Int_t nlinks=s.GetNlinks(this);
368
369 if (fHitCopy)
370 {
371 fHits->Add(s.Clone());
372 // Remove unnecessary backward link(s) from the various slots
373 // and set the owning link to this device
374 NcSignal* sx=(NcSignal*)fHits->Last();
375 if (nlinks) sx->ResetLinks(this);
376 sx->fDevset=kTRUE;
377 sx->SetDevice(this);
378 sx->fDevset=kFALSE;
379 }
380 else
381 {
382 fHits->Add(&s);
383 // Set (backward) link to this device
384 if (!nlinks) s.AddLink(this);
385 }
386}
387
389{
395
396 if (fHits)
397 {
398 NcSignal* test=(NcSignal*)fHits->Remove(&s);
399 if (test)
400 {
401 fHits->Compress();
402 if (fHitCopy) delete test;
403 }
404 }
405 if (fOrdered)
406 {
407 NcSignal* test=(NcSignal*)fOrdered->Remove(&s);
408 if (test) fOrdered->Compress();
409 }
410}
411
413{
419
420 if (fHits)
421 {
422 delete fHits;
423 fHits=0;
424 }
425 if (fOrdered)
426 {
427 delete fOrdered;
428 fOrdered=0;
429 }
430 if (fMarkers)
431 {
432 delete fMarkers;
433 fMarkers=0;
434 }
435}
436
438{
444
445 Int_t nhits=0;
446 if (fHits) nhits=fHits->GetEntries();
447 return nhits;
448}
449
450Int_t NcDevice::GetNhits(TString name,Int_t mode,Int_t opt) const
451{
466
467 if (!fHits) return 0;
468
469 Int_t nfound=0;
470 TString hitname;
471 Int_t nhits=GetNhits();
472 Int_t flag=0;
473 for (Int_t i=0; i<nhits; i++)
474 {
475 NcSignal* sx=(NcSignal*)fHits->At(i);
476 if (sx)
477 {
478 flag=0;
479 hitname=sx->GetName();
480 if ((!opt && hitname==name) || (opt && hitname.Contains(name.Data()))) flag=1;
481 if (sx->GetSlotIndex(name,opt)) flag=2;
482 if ((mode==0 && flag==1) || (mode==1 && flag==2) || (mode==2 && flag)) nfound++;
483 }
484 }
485
486 return nfound;
487}
488
490{
497
498 if (!fHits) return 0;
499
500 if ((j >= 1) && (j <= GetNhits()))
501 {
502 return (NcSignal*)fHits->At(j-1);
503 }
504 else
505 {
506 return 0;
507 }
508}
509
510NcSignal* NcDevice::GetHit(TString name,Int_t mode,Int_t opt) const
511{
527
528 if (!fHits) return 0;
529
530 TString hitname;
531 Int_t nhits=GetNhits();
532 Int_t flag=0;
533 for (Int_t i=0; i<nhits; i++)
534 {
535 NcSignal* sx=(NcSignal*)fHits->At(i);
536 if (sx)
537 {
538 flag=0;
539 hitname=sx->GetName();
540 if ((!opt && hitname==name) || (opt && hitname.Contains(name.Data()))) flag=1;
541 if (sx->GetSlotIndex(name,opt)) flag=2;
542 if ((mode==0 && flag==1) || (mode==1 && flag==2) || (mode==2 && flag)) return sx;
543 }
544 }
545
546 return 0; // No matching name found
547}
548
550{
556
557 if (!fHits || id<0) return 0;
558
559 NcSignal* sx=0;
560 Int_t sid=0;
561 for (Int_t i=0; i<GetNhits(); i++)
562 {
563 sx=(NcSignal*)fHits->At(i);
564 if (sx)
565 {
566 sid=sx->GetUniqueID();
567 if (id==sid) return sx;
568 }
569 }
570 return 0; // No matching id found
571}
572
574{
580
581 return fHits;
582}
583
584void NcDevice::GetHits(TObjArray& selected,TString name,Int_t mode,Int_t opt,TObjArray* hits) const
585{
614
615 selected.Clear();
616
617 TObjArray* ahits=hits;
618 if (!ahits) ahits=fHits;
619
620 Int_t nhits=0;
621 if (ahits) nhits=ahits->GetEntries();
622
623 if (!ahits || !nhits) return;
624
625 TString hitname;
626 Int_t idx=0;
627 Int_t flag=0; // 0=no match 1=hit name match 2=slot name match 3=both hit and slot name match
628 for (Int_t i=0; i<nhits; i++)
629 {
630 NcSignal* sx=(NcSignal*)ahits->At(i);
631
632 if (!sx) continue;
633
634 flag=0;
635 hitname=sx->GetName();
636 idx=sx->GetSlotIndex(name,opt);
637
638 if ((!opt && hitname==name) || (opt && hitname.Contains(name.Data()))) flag=1;
639
640 if (idx)
641 {
642 if (sx->GetSignalFlag(idx))
643 {
644 if (!flag)
645 {
646 flag=2;
647 }
648 else
649 {
650 flag=3;
651 }
652 }
653 }
654 if ((mode==0 && (flag==1 || flag==3)) || (mode==1 && flag>1) || (mode==2 && flag)) selected.Add(sx);
655 if ((mode==-1 && (flag==0 || flag==2)) || (mode==-2 && flag<2) || (mode==-3 && !flag)) selected.Add(sx);
656 }
657}
658
659void NcDevice::ShowHit(Int_t j,TString f,TString u) const
660{
675
676 if (!j)
677 {
678 Int_t nhits=GetNhits();
679 for (Int_t ih=1; ih<=nhits; ih++)
680 {
681 NcSignal* sx=GetHit(ih);
682 if (sx) sx->Data(f,u);
683 }
684 }
685 else
686 {
687 NcSignal* s=GetHit(j);
688 if (s) s->Data(f,u);
689 }
690}
691
692void NcDevice::Data(TString f,TString u) const
693{
707
708 NcSignal::Data(f,u);
709 Int_t nhits=GetNhits();
710 if (nhits)
711 {
712 cout << " The following " << nhits << " hits are registered : " << endl;
713 ShowHit(0,f,u);
714 }
715 else
716 {
717 cout << " No hits have been registered for this device." << endl;
718 }
719}
720
721void NcDevice::GetExtremes(Float_t& vmin,Float_t& vmax,Int_t idx,TObjArray* hits,Int_t mode,Int_t deadcheck) const
722{
744
745 vmin=0;
746 vmax=0;
747
748 TObjArray* ahits=hits;
749 if (!ahits) ahits=fHits;
750
751 if (idx<=0 || !ahits) return;
752
753 // Take the stored signal value "as is" to ensure identical treatment of dead and alive signals
754 if (!deadcheck) mode=0;
755
756 Int_t nhits=ahits->GetEntries();
757
758 Float_t sig=0;
759 TObject* obj=0;
760 NcSignal* sx=0;
761 for (Int_t i=0; i<nhits; i++)
762 {
763 obj=ahits->At(i);
764 if (!obj) continue;
765 if (!obj->InheritsFrom("NcSignal")) continue;
766 sx=(NcSignal*)obj;
767
768 if (idx > sx->GetNvalues()) continue; // User specified slotindex out of range for this signal
769 if (deadcheck && sx->GetDeadValue(idx)) continue; // Only take alive signals
770
771 sig=sx->GetSignal(idx,mode);
772 if (i==0)
773 {
774 vmin=sig;
775 vmax=sig;
776 }
777 else
778 {
779 if (sig<vmin) vmin=sig;
780 if (sig>vmax) vmax=sig;
781 }
782 }
783}
784
785void NcDevice::GetExtremes(Float_t& vmin,Float_t& vmax,TString name,TObjArray* hits,Int_t mode,Int_t deadcheck) const
786{
807
808 vmin=0;
809 vmax=0;
810
811 TObjArray* ahits=hits;
812 if (!ahits) ahits=fHits;
813
814 if (!ahits) return;
815
816 // Take the stored signal value "as is" to ensure identical treatment of dead and alive signals
817 if (!deadcheck) mode=0;
818
819 Int_t nhits=ahits->GetEntries();
820
821 Int_t idx=0; // The signal slotindex to perform the sorting on
822
823 Float_t sig=0;
824 TObject* obj=0;
825 NcSignal* sx=0;
826 Bool_t first=kTRUE;
827 for (Int_t i=0; i<nhits; i++)
828 {
829 obj=ahits->At(i);
830 if (!obj) continue;
831 if (!obj->InheritsFrom("NcSignal")) continue;
832 sx=(NcSignal*)obj;
833
834 // Obtain the slotindex corresponding to the user selection
835 idx=sx->GetSlotIndex(name);
836 if (!idx) continue;
837
838 if (deadcheck && sx->GetDeadValue(idx)) continue; // Only take alive signals
839
840 sig=sx->GetSignal(idx,mode);
841 if (first)
842 {
843 vmin=sig;
844 vmax=sig;
845 first=kFALSE;
846 }
847 else
848 {
849 if (sig<vmin) vmin=sig;
850 if (sig>vmax) vmax=sig;
851 }
852 }
853}
854
855TObjArray* NcDevice::SortHits(Int_t idx,Int_t mode,TObjArray* hits,Int_t mcal,Int_t deadcheck,TObjArray* ordered)
856{
895
896 if (ordered) ordered->Clear();
897
898 TObjArray* ahits=hits;
899 if (!ahits) ahits=fHits;
900
901 Int_t nhits=0;
902 if (ahits) nhits=ahits->GetEntries();
903
904 if (idx<=0 || abs(mode)!=1 || !ahits || !nhits) return 0;
905
906 if (ordered)
907 {
908 ordered->Expand(nhits);
909 }
910 else
911 {
912 if (fOrdered) delete fOrdered;
913 fOrdered=new TObjArray(nhits);
914 }
915
916 // Take the stored signal value "as is" to ensure identical treatment of dead and alive signals
917 if (!deadcheck) mcal=0;
918
919 TObjArray* arr=0; // Generic sorted array pointer to be used in the logic below
920
921 if (ordered)
922 {
923 arr=ordered;
924 }
925 else
926 {
927 arr=fOrdered;
928 }
929
930 TObject* obj=0;
931 NcSignal* s=0;
932 Int_t nord=0;
933 for (Int_t i=0; i<nhits; i++) // Loop over all hits of the array
934 {
935 obj=ahits->At(i);
936 if (!obj) continue;
937 if (!obj->InheritsFrom("NcSignal")) continue;
938 s=(NcSignal*)obj;
939
940 if (!s) continue;
941
942 if (idx > s->GetNvalues()) continue; // User specified slotindex out of range for this signal
943 if (deadcheck && s->GetDeadValue(idx)) continue; // Only take alive signals
944
945 if (nord == 0) // store the first hit with a signal at the first ordered position
946 {
947 nord++;
948 arr->AddAt(s,nord-1);
949 continue;
950 }
951
952 for (Int_t j=0; j<=nord; j++) // put hit in the right ordered position
953 {
954 if (j == nord) // module has smallest (mode=-1) or largest (mode=1) signal seen so far
955 {
956 nord++;
957 arr->AddAt(s,j); // add hit at the end
958 break; // go for next hit
959 }
960
961 if (mode==-1 && s->GetSignal(idx,mcal) <= ((NcSignal*)arr->At(j))->GetSignal(idx,mcal)) continue;
962 if (mode==1 && s->GetSignal(idx,mcal) >= ((NcSignal*)arr->At(j))->GetSignal(idx,mcal)) continue;
963
964 nord++;
965 for (Int_t k=nord-1; k>j; k--) // create empty position
966 {
967 arr->AddAt(arr->At(k-1),k);
968 }
969 arr->AddAt(s,j); // put hit at empty position
970 break; // go for next hit
971 }
972 }
973
974 if (ordered)
975 {
976 return 0;
977 }
978 else
979 {
980 return fOrdered;
981 }
982}
983
984
984TObjArray* NcDevice::SortHits(TString name,Int_t mode,TObjArray* hits,Int_t mcal,Int_t deadcheck,TObjArray* ordered)
985{
1024
1025 if (ordered) ordered->Clear();
1026
1027 TObjArray* ahits=hits;
1028 if (!ahits) ahits=fHits;
1029
1030 Int_t nhits=0;
1031 if (ahits) nhits=ahits->GetEntries();
1032
1033 if (abs(mode)!=1 || !ahits || !nhits) return 0;
1034
1035 if (ordered)
1036 {
1037 ordered->Expand(nhits);
1038 }
1039 else
1040 {
1041 if (fOrdered) delete fOrdered;
1042 fOrdered=new TObjArray(nhits);
1043 }
1044
1045 Int_t idx=0; // The signal slotindex to perform the sorting on
1046
1047 // Take the stored signal value "as is" to ensure identical treatment of dead and alive signals
1048 if (!deadcheck) mcal=0;
1049
1050
1051 TObjArray* arr=0; // Generic sorted array pointer to be used in the logic below
1052
1053 if (ordered)
1054 {
1055 arr=ordered;
1056 }
1057 else
1058 {
1059 arr=fOrdered;
1060 }
1061
1062 TObject* obj=0;
1063 NcSignal* s=0;
1064 Int_t nord=0;
1065 for (Int_t i=0; i<nhits; i++) // loop over all hits of the array
1066 {
1067 obj=ahits->At(i);
1068 if (!obj) continue;
1069 if (!obj->InheritsFrom("NcSignal")) continue;
1070 s=(NcSignal*)obj;
1071
1072 if (!s) continue;
1073
1074 // Obtain the slotindex corresponding to the user selection
1075 idx=s->GetSlotIndex(name);
1076 if (!idx) continue;
1077
1078 if (deadcheck && s->GetDeadValue(idx)) continue; // only take alive signals
1079
1080 if (nord == 0) // store the first hit with a signal at the first ordered position
1081 {
1082 nord++;
1083 arr->AddAt(s,nord-1);
1084 continue;
1085 }
1086
1087 for (Int_t j=0; j<=nord; j++) // put hit in the right ordered position
1088 {
1089 if (j == nord) // module has smallest (mode=-1) or largest (mode=1) signal seen so far
1090 {
1091 nord++;
1092 arr->AddAt(s,j); // add hit at the end
1093 break; // go for next hit
1094 }
1095
1096 if (mode==-1 && s->GetSignal(idx,mcal) <= ((NcSignal*)arr->At(j))->GetSignal(idx,mcal)) continue;
1097 if (mode==1 && s->GetSignal(idx,mcal) >= ((NcSignal*)arr->At(j))->GetSignal(idx,mcal)) continue;
1098
1099 nord++;
1100 for (Int_t k=nord-1; k>j; k--) // create empty position
1101 {
1102 arr->AddAt(arr->At(k-1),k);
1103 }
1104 arr->AddAt(s,j); // put hit at empty position
1105 break; // go for next hit
1106 }
1107 }
1108
1109 if (ordered)
1110 {
1111 return 0;
1112 }
1113 else
1114 {
1115 return fOrdered;
1116 }
1117}
1118
1119
1119void NcDevice::DisplayHits(Int_t idx,Float_t scale,TObjArray* hits,Int_t dp,Int_t mode,Int_t mcol)
1120{
1153
1154 Int_t thisdev=0; // Indicate whether this is the owning device or not
1155 TObjArray* ahits=hits;
1156 if (!ahits)
1157 {
1158 ahits=fHits;
1159 thisdev=1;
1160 }
1161
1162 if (idx<=0 || !ahits) return;
1163
1164 Int_t nhits=ahits->GetEntries();
1165 if (!nhits) return;
1166
1167 Float_t sigmax=fabs(scale);
1168 if (scale<0)
1169 {
1170 Float_t vmin,vmax;
1171 GetExtremes(vmin,vmax,idx,ahits,mode);
1172 sigmax=fabs(vmax);
1173 if (fabs(vmin)>sigmax) sigmax=fabs(vmin);
1174 }
1175
1176 if (sigmax <=0) return;
1177
1178 if (fMarkers)
1179 {
1180 delete fMarkers;
1181 fMarkers=0;
1182 }
1183 fMarkers=new TObjArray(nhits);
1184 fMarkers->SetOwner();
1185
1186 Float_t pos[3];
1187 GetPosition(pos,"car");
1188
1189 Float_t sig=0;
1190 TObject* obj=0;
1191 NcSignal* sx=0;
1192 for (Int_t ih=0; ih<nhits; ih++)
1193 {
1194 obj=ahits->At(ih);
1195 if (!obj) continue;
1196 if (!obj->InheritsFrom("NcSignal")) continue;
1197 sx=(NcSignal*)obj;
1198
1199 if (!dp)
1200 {
1201 sx->GetPosition(pos,"car");
1202 }
1203 else
1204 {
1205 if (!thisdev)
1206 {
1207 NcDevice* dev=sx->GetDevice();
1208 if (dev) dev->GetPosition(pos,"car");
1209 }
1210 }
1211 sig=sx->GetSignal(idx,mode);
1212
1213 // Skip dead signals
1214 if (fabs(sig) <= 0.) continue;
1215
1216 TPolyMarker3D* m=new TPolyMarker3D();
1217 m->SetMarkerStyle(8);
1218 m->SetMarkerColor(mcol);
1219 m->SetMarkerSize(100.*fabs(sig)/sigmax);
1220 m->SetPoint(0,pos[0],pos[1],pos[2]);
1221 fMarkers->Add(m);
1222 m->Draw();
1223 }
1224}
1225
1226void NcDevice::DisplayHits(TString name,Float_t scale,TObjArray* hits,Int_t dp,Int_t mode,Int_t mcol)
1227{
1262
1263 Int_t thisdev=0; // Indicate whether this is the owning device or not
1264 TObjArray* ahits=hits;
1265 if (!ahits)
1266 {
1267 ahits=fHits;
1268 thisdev=1;
1269 }
1270
1271 if (!ahits) return;
1272
1273 Int_t nhits=ahits->GetEntries();
1274
1275 if (!nhits) return;
1276
1277 Float_t sigmax=fabs(scale);
1278 if (scale<0)
1279 {
1280 Float_t vmin,vmax;
1281 GetExtremes(vmin,vmax,name,ahits,mode);
1282 sigmax=fabs(vmax);
1283 if (fabs(vmin)>sigmax) sigmax=fabs(vmin);
1284 }
1285
1286 if (sigmax <=0) return;
1287
1288 if (fMarkers)
1289 {
1290 delete fMarkers;
1291 fMarkers=0;
1292 }
1293 fMarkers=new TObjArray(nhits);
1294 fMarkers->SetOwner();
1295
1296 Float_t pos[3];
1297 GetPosition(pos,"car");
1298
1299 Int_t idx=0; // The slot index corresponding to the user specified name
1300 Float_t sig=0;
1301 TObject* obj=0;
1302 NcSignal* sx=0;
1303 for (Int_t ih=0; ih<nhits; ih++)
1304 {
1305 obj=ahits->At(ih);
1306 if (!obj) continue;
1307 if (!obj->InheritsFrom("NcSignal")) continue;
1308 sx=(NcSignal*)obj;
1309 idx=sx->GetSlotIndex(name);
1310 if (!idx) continue;
1311 if (!dp)
1312 {
1313 sx->GetPosition(pos,"car");
1314 }
1315 else
1316 {
1317 if (!thisdev)
1318 {
1319 NcDevice* dev=sx->GetDevice();
1320 if (dev) dev->GetPosition(pos,"car");
1321 }
1322 }
1323 sig=sx->GetSignal(idx,mode);
1324
1325 // Skip dead signals
1326 if (fabs(sig) <= 0.) continue;
1327
1328 TPolyMarker3D* m=new TPolyMarker3D();
1329 m->SetMarkerStyle(8);
1330 m->SetMarkerColor(mcol);
1331 m->SetMarkerSize(100.*fabs(sig)/sigmax);
1332 m->SetPoint(0,pos[0],pos[1],pos[2]);
1333 fMarkers->Add(m);
1334 m->Draw();
1335 }
1336}
1337
1338Double_t NcDevice::SumSignals(Int_t idx,Int_t mode,TObjArray* hits)
1339{
1355
1356 TObjArray* ahits=hits;
1357 if (!ahits) ahits=fHits;
1358
1359 Int_t nhits=0;
1360 if (ahits) nhits=ahits->GetEntries();
1361
1362 if (idx<=0 || !ahits || !nhits) return 0;
1363
1364 TObject* obj=0;
1365 NcSignal* s=0;
1366 Double_t sum=0;
1367 for (Int_t i=0; i<nhits; i++) // Loop over all hits of the array
1368 {
1369 obj=ahits->At(i);
1370 if (!obj) continue;
1371 if (!obj->InheritsFrom("NcSignal")) continue;
1372 s=(NcSignal*)obj;
1373
1374 if (!s) continue;
1375
1376 if (idx > s->GetNvalues()) continue; // User specified slotindex out of range for this signal
1377
1378 sum+=s->GetSignal(idx,mode);
1379 }
1380
1381 return sum;
1382}
1383
1384Double_t NcDevice::SumSignals(TString name,Int_t mode,TObjArray* hits)
1385{
1401
1402 TObjArray* ahits=hits;
1403 if (!ahits) ahits=fHits;
1404
1405 Int_t nhits=0;
1406 if (ahits) nhits=ahits->GetEntries();
1407
1408 if (!ahits || !nhits) return 0;
1409
1410 TObject* obj=0;
1411 NcSignal* s=0;
1412 Double_t sum=0;
1413 for (Int_t i=0; i<nhits; i++) // Loop over all hits of the array
1414 {
1415 obj=ahits->At(i);
1416 if (!obj) continue;
1417 if (!obj->InheritsFrom("NcSignal")) continue;
1418 s=(NcSignal*)obj;
1419
1420 if (!s) continue;
1421
1422 sum+=s->GetSignal(name,mode);
1423 }
1424
1425 return sum;
1426}
1427
1428Double_t NcDevice::SlideWindow(TObjArray* hits,Double_t thres,Double_t swin,TString sname,Int_t smode,TString wname,Int_t wmode,Int_t* i1,Int_t* i2) const
1429{
1503
1504 Int_t nhits=0;
1505 if (hits) nhits=hits->GetEntries();
1506
1507 if (!nhits) return 0;
1508
1509 Double_t v1=0;
1510 Double_t v2=0;
1511 Double_t wsize=0;
1512 Double_t sum=0;
1513 Double_t w=1;
1514 Int_t wflag=1;
1515 if (wname=="none") wflag=0;
1516 Int_t ifirst=0;
1517 TObject* obj=0;
1518 NcSignal* sx1=0;
1519 NcSignal* sx2=0;
1520 while (ifirst<nhits)
1521 {
1522 obj=hits->At(ifirst);
1523 if (!(obj->InheritsFrom("NcSignal")))
1524 {
1525 ifirst++;
1526 continue;
1527 }
1528
1529 // The starting signal of this window
1530 sx1=(NcSignal*)obj;
1531 v1=sx1->GetSignal(sname,smode);
1532 if (wflag) w=sx1->GetSignal(wname,wmode);
1533 sum=w;
1534 if (sum>=thres)
1535 {
1536 if (i1) *i1=ifirst;
1537 if (i2) *i2=ifirst;
1538 return v1;
1539 }
1540
1541 // Scan the allowed window size
1542 for (Int_t ilast=ifirst+1; ilast<nhits; ilast++)
1543 {
1544 obj=hits->At(ilast);
1545 if (!(obj->InheritsFrom("NcSignal"))) continue;
1546
1547 sx2=(NcSignal*)obj;
1548 v2=sx2->GetSignal(sname,smode);
1549
1550 wsize=fabs(v2-v1);
1551 if (wsize>swin) break;
1552
1553 if (wflag) w=sx2->GetSignal(wname,wmode);
1554 sum+=w;
1555 if (sum>=thres)
1556 {
1557 if (i1) *i1=ifirst;
1558 if (i2) *i2=ilast;
1559 return v2;
1560 }
1561
1562 }
1563 ifirst++;
1564 sum=0;
1565 }
1566
1567 // No window found to match the selection criteria
1568 if (i1) *i1=-1;
1569 if (i2) *i2=-1;
1570 return 0;
1571}
1572
1573Nc3Vector NcDevice::GetHitPath(TObjArray* hits,Int_t pos) const
1574{
1592
1593 Nc3Vector v;
1594
1595 if (!hits) return v;
1596
1597 Int_t nh=hits->GetEntries();
1598 if (!nh) return v;
1599
1600 NcSignal* s1=(NcSignal*)hits->At(0);
1601 if (!s1) return v;
1602
1603 NcDevice* dev1=s1->GetDevice();
1604 if (pos && !dev1) return v;
1605
1606 // Define the starting hit to be the origin
1607 Nc3Vector r1;
1608 r1.SetZero();
1609
1610 Nc3Vector r2;
1611 Nc3Vector r12;
1612 for (Int_t ih=1; ih<nh; ih++)
1613 {
1614 NcSignal* s2=(NcSignal*)hits->At(ih);
1615 if (!s2) continue;
1616
1617 NcDevice* dev2=s2->GetDevice();
1618 if (pos && !dev2) continue;
1619
1620 if (!pos)
1621 {
1622 r2=(Nc3Vector)s2->GetPosition();
1623 }
1624 else
1625 {
1626 r2=(Nc3Vector)dev2->GetPosition();
1627 }
1628 r12=r2-r1;
1629 v+=r12;
1630
1631 r1=r2;
1632 }
1633
1634 return v;
1635}
1636
1637NcPosition NcDevice::GetCOG(TObjArray* hits,Int_t pos,TString slotname,Int_t mode) const
1638{
1656
1657 NcPosition cog;
1658
1659 if (!hits) return cog;
1660
1661 Int_t nh=hits->GetEntries();
1662 if (!nh) return cog;
1663
1664 Nc3Vector rx;
1665 Nc3Vector rsum;
1666 Float_t w=1;
1667 Double_t wsum=0;
1668 for (Int_t ih=0; ih<nh; ih++)
1669 {
1670 NcSignal* sx=(NcSignal*)hits->At(ih);
1671 if (!sx) continue;
1672
1673 NcDevice* devx=sx->GetDevice();
1674 if (pos && !devx) continue;
1675
1676 if (!pos)
1677 {
1678 rx=(Nc3Vector)sx->GetPosition();
1679 }
1680 else
1681 {
1682 rx=(Nc3Vector)devx->GetPosition();
1683 }
1684
1685 if (slotname != "none")
1686 {
1687 w=fabs(sx->GetSignal(slotname,mode));
1688 rx*=w;
1689 }
1690 rsum+=rx;
1691 wsum+=double(w);
1692 }
1693
1694 if (wsum>0) rsum/=wsum;
1695 cog.SetPosition(rsum);
1696 return cog;
1697}
1698
1699Double_t NcDevice::GetCVAL(TObjArray* hits,TString obsname,TString weightname,Int_t mode,Int_t type) const
1700{
1717
1718 if (type!=1 && type!=2)
1719 {
1720 cout << " *" << ClassName() << "::GetCVAL* Unknown type : " << type << endl;
1721 return 0;
1722 }
1723
1724 if (!hits) return 0;
1725
1726 Int_t nh=hits->GetEntries();
1727 if (!nh) return 0;
1728
1729 Double_t cval=0;
1730
1731 Double_t val=0;
1732 Double_t w=1;
1733 Double_t wsum=0;
1734 NcSample stat;
1735 if (type==1) stat.SetStoreMode();
1736 Int_t iw=0;
1737 for (Int_t ih=0; ih<nh; ih++)
1738 {
1739 NcSignal* sx=(NcSignal*)hits->At(ih);
1740 if (!sx) continue;
1741
1742 val=sx->GetSignal(obsname,mode);
1743
1744 if (weightname != "none") w=fabs(sx->GetSignal(weightname,mode));
1745
1746 if (type==1) // Weighted median
1747 {
1748 iw=TMath::Nint(w);
1749 if (iw<1) iw=1;
1750 for (Int_t i=0; i<iw; i++)
1751 {
1752 stat.Enter(val);
1753 }
1754 }
1755
1756 if (type==2) // Weighted mean
1757 {
1758 val*=w;
1759 stat.Enter(val);
1760 }
1761 wsum+=w;
1762 }
1763
1764 if (type==1) cval=stat.GetMedian(1);
1765
1766 if (type==2)
1767 {
1768 if (wsum>0) cval=stat.GetSum(1)/wsum;
1769 }
1770
1771 return cval;
1772}
1773
1774TObject* NcDevice::Clone(const char* name) const
1775{
1788
1789 NcDevice* dev=new NcDevice(*this);
1790 if (name)
1791 {
1792 if (strlen(name)) dev->SetName(name);
1793 }
1794 return dev;
1795}
1796
ClassImp(NcDevice)
virtual void SetZero()
Int_t GetDeadValue(Int_t j=1) const
Int_t GetSlotIndex(TString name, Int_t opt=0) const
Signal (Hit) handling of a generic device.
Definition NcDevice.h:14
void RemoveHit(NcSignal &s)
Definition NcDevice.cxx:388
void AddHit(NcSignal &s)
Definition NcDevice.cxx:336
TObjArray * GetHits()
Definition NcDevice.cxx:573
TObjArray * fMarkers
! Temp. array to hold the 3D markers for the hit display
Definition NcDevice.h:58
Double_t SumSignals(Int_t idx, Int_t mode=1, TObjArray *hits=0)
TObjArray * fHits
Definition NcDevice.h:56
void RemoveHits()
Definition NcDevice.cxx:412
NcPosition GetCOG(TObjArray *hits, Int_t pos=0, TString slotname="none", Int_t mode=0) const
virtual void Data(TString f="car", TString u="rad") const
Definition NcDevice.cxx:692
Nc3Vector GetHitPath(TObjArray *hits, Int_t pos=0) const
NcDevice(const char *name="", const char *title="")
Definition NcDevice.cxx:109
Double_t SlideWindow(TObjArray *hits, Double_t thres, Double_t swin, TString sname, Int_t smode=0, TString wname="none", Int_t wmode=0, Int_t *i1=0, Int_t *i2=0) const
TObjArray * fOrdered
! Temp. array to hold the ordered hits
Definition NcDevice.h:57
void SetHitCopy(Int_t j)
Definition NcDevice.cxx:237
Int_t GetHitCopy() const
Definition NcDevice.cxx:270
virtual TObject * Clone(const char *name="") const
Int_t fHitCopy
Definition NcDevice.h:55
void DisplayHits(TString name, Float_t scale=-1, TObjArray *hits=0, Int_t dp=0, Int_t mode=1, Int_t mcol=4)
virtual ~NcDevice()
Definition NcDevice.cxx:128
void SetStatus(Int_t word)
Definition NcDevice.cxx:314
Int_t fStatus
Definition NcDevice.h:54
virtual void SetOwner(Bool_t own=kTRUE)
Definition NcDevice.cxx:283
NcSignal * GetIdHit(Int_t id) const
Definition NcDevice.cxx:549
Double_t GetCVAL(TObjArray *hits, TString obsname, TString weightname="none", Int_t mode=0, Int_t type=1) const
Int_t GetNhits() const
Definition NcDevice.cxx:437
NcSignal * GetHit(Int_t j) const
Definition NcDevice.cxx:489
void GetExtremes(Float_t &vmin, Float_t &vmax, Int_t idx=1, TObjArray *hits=0, Int_t mode=1, Int_t deadcheck=1) const
Definition NcDevice.cxx:721
void ShowHit(Int_t j=0, TString f="car", TString u="rad") const
Definition NcDevice.cxx:659
virtual void Reset(Int_t mode=0)
Definition NcDevice.cxx:222
Int_t GetStatus() const
Definition NcDevice.cxx:325
TObjArray * SortHits(TString name, Int_t mode=-1, TObjArray *hits=0, Int_t mcal=1, Int_t deadcheck=1, TObjArray *ordered=0)
Definition NcDevice.cxx:984
void GetPosition(Double_t *r, TString f, TString u="rad", Float_t s=-1) const
NcPosition & GetPosition()
void SetPosition(Double_t *r, TString f, TString u="rad")
Sampling and statistics tools for various multi-dimensional data samples.
Definition NcSample.h:28
Double_t GetMedian(Int_t i)
void Enter(Double_t x)
Definition NcSample.cxx:357
void SetStoreMode(Int_t mode=1, Int_t nmax=0, Int_t i=0)
Double_t GetSum(Int_t i) const
virtual void Reset(Int_t mode=0)
Definition NcSignal.cxx:334
NcDevice * GetDevice() const
Int_t GetNlinks(TObject *obj=0, Int_t j=0) const
virtual TObject * Clone(const char *name="") const
Bool_t fDevset
Definition NcSignal.h:103
Int_t GetIndices(TObject *obj, TArrayI &js, TArrayI &ks) const
void SetDevice(NcDevice *dev)
virtual Float_t GetSignal(Int_t j=1, Int_t mode=0) const
Definition NcSignal.cxx:651
NcSignal(const char *name="", const char *title="")
Definition NcSignal.cxx:155
virtual void Data(TString f="car", TString u="rad") const
Definition NcSignal.cxx:959
Int_t GetNvalues() const
void AddLink(TObject *obj, Int_t j=1)
Int_t GetSignalFlag(Int_t j=1) const
void SetLink(TObject *obj, Int_t j=1, Int_t k=1)
void ResetLinks(TObject *obj, Int_t j=0, Int_t k=0)