NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
NcCalorimeter.cxx
Go to the documentation of this file.
1
31
33
77
78#include "NcCalorimeter.h"
79#include "Riostream.h"
80
81ClassImp(NcCalorimeter); // Class implementation to enable ROOT I/O
82
85{
96
97 fNrows=0;
98 fNcolumns=0;
99 fSwap=0;
100 fMatrix=0;
101 fClusters=0;
102 fHmodules=0;
103 fHclusters=0;
104 fVetos=0;
105 fAttributes=0;
106 fPositions=0;
107}
108
110{
116
117 if (fClusters)
118 {
119 delete fClusters;
120 fClusters=0;
121 }
122 if (fVetos)
123 {
124 delete fVetos;
125 fVetos=0;
126 }
127 if (fHmodules)
128 {
129 delete fHmodules;
130 fHmodules=0;
131 }
132 if (fHclusters)
133 {
134 delete fHclusters;
135 fHclusters=0;
136 }
137 if (fMatrix)
138 {
139 delete fMatrix;
140 fMatrix=0;
141 }
142 if (fPositions)
143 {
144 delete fPositions;
145 fPositions=0;
146 }
147 if (fAttributes)
148 {
149 delete fAttributes;
150 fAttributes=0;
151 }
152}
153
154NcCalorimeter::NcCalorimeter(Int_t nrow,Int_t ncol) : NcDevice()
155{
162
163 fNrows=nrow;
164 fNcolumns=ncol;
165 fClusters=0;
166
167 fSwap=0;
168 fMatrix=0;
169 fPositions=0;
170
171 fAttributes=new TObjArray(nrow);
172 fAttributes->SetOwner();
173
174 // Mark the edge modules
175 for (Int_t row=1; row<=nrow; row++)
176 {
177 NcAttribObj* a=new NcAttribObj();
178 if (row==1 || row==nrow)
179 {
180 for (Int_t col=1; col<=ncol; col++)
181 {
182 a->SetEdgeOn(col);
183 }
184 }
185 else
186 {
187 a->SetEdgeOn(1);
188 a->SetEdgeOn(ncol);
189 }
190 fAttributes->Add(a);
191 }
192
193 fHmodules=0;
194 fHclusters=0;
195
196 fVetos=0;
197}
198
200{
206
207 fClusters=0;
208 fVetos=0;
209
210 fAttributes=0;
211
212 fHmodules=0;
213 fHclusters=0;
214
215 fMatrix=0;
216 fPositions=0;
217
218 fNrows=c.fNrows;
220
221 fSwap=c.fSwap;
222
223 if (c.fPositions)
224 {
225 Int_t nrows=(c.fPositions)->GetMaxRow();
226 Int_t ncols=(c.fPositions)->GetMaxColumn();
227 for (Int_t irow=1; irow<=nrows; irow++)
228 {
229 for (Int_t icol=1; icol<=ncols; icol++)
230 {
231 NcPosition* p=(NcPosition*)(c.fPositions->GetObject(irow,icol));
232 if (p) SetPosition(irow,icol,*p);
233 }
234 }
235 }
236
237 Int_t size=0;
238 if (c.fAttributes) size=c.fAttributes->GetSize();
239 if (size)
240 {
241 fAttributes=new TObjArray(size);
242 fAttributes->SetOwner();
243 for (Int_t ia=0; ia<size; ia++)
244 {
245 NcAttribObj* a=(NcAttribObj*)(c.fAttributes->At(ia));
246 if (a) fAttributes->AddAt(new NcAttribObj(*a),ia);
247 }
248 }
249
250 Int_t n=0;
251 n=c.GetNclusters();
252 if (n)
253 {
254 fClusters=new TObjArray();
255 fClusters->SetOwner();
256 for (Int_t icl=1; icl<=n; icl++)
257 {
258 NcCalcluster* cl=c.GetCluster(icl);
259 if (cl) fClusters->Add(new NcCalcluster(*cl));
260 }
261 }
262
263 n=c.GetNvetos();
264 for (Int_t iv=1; iv<=n; iv++)
265 {
266 NcSignal* s=c.GetVetoSignal(iv);
267 if (s) AddVetoSignal(s);
268 }
269}
270
272{
278
279 Int_t nrows=fNrows;
280 if (!fMatrix) LoadMatrix();
281 if (fMatrix && !nrows) nrows=fMatrix->GetMaxRow();
282 return nrows;
283}
284
286{
292
293 Int_t ncols=fNcolumns;
294 if (!fMatrix) LoadMatrix();
295 if (fMatrix && !ncols) ncols=fMatrix->GetMaxColumn();
296 return ncols;
297}
298
299void NcCalorimeter::SetSignal(Int_t row,Int_t col,Float_t sig)
300{
306
307 // Check for (row,col) boundaries.
308 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
309 {
310 cout << " *NcCalorimeter::SetSignal* row,col : " << row << "," << col
311 << " out of range." << endl;
312 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
313 return;
314 }
315
316 if (!fMatrix) LoadMatrix();
317
318 if (!fMatrix)
319 {
320 fMatrix=new NcObjMatrix();
321 fMatrix->SetSwapMode(fSwap);
322 }
323
324 NcCalmodule* mx=GetModule(row,col);
325 if (mx) // Existing module
326 {
327 mx->SetSignal(sig);
328 }
329 else // Initialise for a new module
330 {
331 NcCalmodule m;
332 m.SetRow(row);
333 m.SetColumn(col);
334 m.SetSignal(sig);
335 NcPosition* r=0;
336 if (fPositions) r=(NcPositionObj*)fPositions->GetObject(row,col);
337 if (r) m.SetPosition(*r);
338 if (fAttributes)
339 {
340 NcAttribObj* a=0;
341 if (row <= fAttributes->GetSize()) a=(NcAttribObj*)fAttributes->At(row-1);
342 if (a)
343 {
344 if (a->GetGainFlag(col)) m.SetGain(a->GetGain(col));
345 if (a->GetOffsetFlag(col)) m.SetOffset(a->GetOffset(col));
346 if (a->GetDeadValue(col)) m.SetDead();
347 if (a->GetEdgeValue(col)) m.SetEdgeValue(a->GetEdgeValue(col));
348 }
349 }
350 AddHit(m);
351 fMatrix->EnterObject(row,col,fHits->Last());
352 }
353}
354
355void NcCalorimeter::AddSignal(Int_t row, Int_t col, Float_t sig)
356{
362
363 // Check for (row,col) boundaries.
364 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
365 {
366 cout << " *NcCalorimeter::AddSignal* row,col : " << row << "," << col
367 << " out of range." << endl;
368 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
369 return;
370 }
371
372 NcCalmodule* m=GetModule(row,col);
373 if (!m) // initialise for new modules
374 {
375 SetSignal(row,col,sig);
376 }
377 else
378 {
379 m->AddSignal(sig);
380 }
381}
382
384{
398
399 if (!mod) return;
400
401 Int_t row=mod->GetRow();
402 Int_t col=mod->GetColumn();
403 Float_t sig=mod->GetSignal();
404
405 // Check for (row,col) boundaries.
406 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
407 {
408 cout << " *NcCalorimeter::AddSignal* row,col : " << row << "," << col
409 << " out of range." << endl;
410 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
411 return;
412 }
413
414 if (!fMatrix) LoadMatrix();
415
416 if (!fMatrix)
417 {
418 fMatrix=new NcObjMatrix();
419 fMatrix->SetSwapMode(fSwap);
420 }
421
422 NcCalmodule* mx=GetModule(row,col);
423 if (!mx) // No module existed yet at this position
424 {
425 NcCalmodule m(*mod);
426 NcPosition* r=0;
427 if (fPositions) r=(NcPositionObj*)fPositions->GetObject(row,col);
428 if (r) m.SetPosition(*r);
429 // Don't take the dead and edge attributes from this module,
430 // but from the calorimeter dbase, if present.
431 m.SetEdgeOff();
432 m.SetAlive();
433 if (fAttributes)
434 {
435 NcAttribObj* a=0;
436 if (row <= fAttributes->GetSize()) a=(NcAttribObj*)fAttributes->At(row-1);
437 if (a)
438 {
439 if (a->GetGainFlag(col)) m.SetGain(a->GetGain(col));
440 if (a->GetOffsetFlag(col)) m.SetOffset(a->GetOffset(col));
441 if (a->GetDeadValue(col)) m.SetDead();
442 if (a->GetEdgeValue(col)) m.SetEdgeValue(a->GetEdgeValue(col));
443 }
444 }
445 AddHit(m);
446 fMatrix->EnterObject(row,col,fHits->Last());
447 }
448 else
449 {
450 mx->AddSignal(sig);
451 }
452}
453
454void NcCalorimeter::Reset(Int_t row,Int_t col)
455{
462
463 // Check for (row,col) boundaries.
464 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
465 {
466 cout << " *NcCalorimeter::Reset* row,col : " << row << "," << col
467 << " out of range." << endl;
468 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
469 return;
470 }
471
472 NcCalmodule* m=GetModule(row,col);
473 if (m)
474 {
475 RemoveHit(m);
476 fMatrix->RemoveObject(row,col);
477 }
478}
479
480void NcCalorimeter::Reset(Int_t mode)
481{
498
499 if (mode<0 || mode>1)
500 {
501 cout << " *NcCalorimeter::Reset* Wrong argument. mode = " << mode << endl;
502 return;
503 }
504
505 NcDevice::Reset(mode);
506
507 if (fClusters)
508 {
509 delete fClusters;
510 fClusters=0;
511 }
512
513 if (fVetos)
514 {
515 delete fVetos;
516 fVetos=0;
517 }
518
519 if (mode==1)
520 {
521 if (fMatrix)
522 {
523 delete fMatrix;
524 fMatrix=0;
525 }
526 if (fPositions)
527 {
528 delete fPositions;
529 fPositions=0;
530 }
531 }
532 else
533 {
534 if (fMatrix) fMatrix->Reset();
535 }
536
537 // Free memory allocated for the various arrays.
538 if (mode==1)
539 {
540 if (fAttributes)
541 {
542 delete fAttributes;
543 fAttributes=0;
544 }
545 if (fHmodules)
546 {
547 delete fHmodules;
548 fHmodules=0;
549 }
550 if (fHclusters)
551 {
552 delete fHclusters;
553 fHclusters=0;
554 }
555 }
556}
557
558Float_t NcCalorimeter::GetSignal(Int_t row,Int_t col,Int_t mode)
559{
578
579 // Check for (row,col) boundaries.
580 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
581 {
582 cout << " *NcCalorimeter::GetSignal* row,col : " << row << "," << col
583 << " out of range." << endl;
584 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
585 return 0;
586 }
587
588 Float_t signal=0;
589 Float_t gain=1;
590 Float_t offset=0;
591 NcCalmodule* m=GetModule(row,col);
592 if (m)
593 {
594 Int_t dead=m->GetDeadValue();
595 if (!dead) signal=m->GetSignal();
596
597 if (mode==0 || dead) return signal;
598
599 // Correct the signal for the gain and offset
600 if (GetGainFlag(row,col))
601 {
602 gain=GetGain(row,col);
603 }
604 else
605 {
606 if (m->GetGainFlag()) gain=m->GetGain();
607 }
608
609 if (GetOffsetFlag(row,col))
610 {
611 offset=GetOffset(row,col);
612 }
613 else
614 {
615 if (m->GetOffsetFlag()) offset=m->GetOffset();
616 }
617
618 if (fabs(gain)>0.)
619 {
620 signal=(signal/gain)-offset;
621 }
622 else
623 {
624 signal=0;
625 }
626 }
627 return signal;
628}
629
630void NcCalorimeter::SetEdgeOn(Int_t row,Int_t col)
631{
637
638 // Check for (row,col) boundaries.
639 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
640 {
641 cout << " *NcCalorimeter::SetEdgeOn* row,col : " << row << "," << col
642 << " out of range." << endl;
643 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
644 return;
645 }
646
647 if (!fAttributes)
648 {
649 fAttributes=new TObjArray(row);
650 fAttributes->SetOwner();
651 }
652 else
653 {
654 if (row > fAttributes->GetSize()) fAttributes->Expand(row);
655 }
656
657 NcAttribObj* a=(NcAttribObj*)fAttributes->At(row-1);
658 if (a)
659 {
660 a->SetEdgeOn(col);
661 }
662 else
663 {
664 a=new NcAttribObj();
665 a->SetEdgeOn(col);
666 fAttributes->AddAt(a,row-1);
667 }
668
669 NcCalmodule* m=GetModule(row,col);
670 if (m) m->SetEdgeOn();
671}
672
673void NcCalorimeter::SetEdgeOff(Int_t row,Int_t col)
674{
680
681 // Check for (row,col) boundaries.
682 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
683 {
684 cout << " *NcCalorimeter::SetEdgeOff* row,col : " << row << "," << col
685 << " out of range." << endl;
686 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
687 return;
688 }
689
690 // Only action on fAttributes in case an attribute is present at (row,col),
691 // since by default a module has edge=0 unless explicitly set otherwise.
692 if (fAttributes)
693 {
694 if (row <= fAttributes->GetSize())
695 {
696 NcAttribObj* a=(NcAttribObj*)fAttributes->At(row-1);
697 if (a) a->SetEdgeOff(col);
698 }
699 }
700
701 NcCalmodule* m=GetModule(row,col);
702 if (m) m->SetEdgeOff();
703}
704
705void NcCalorimeter::SetDead(Int_t row,Int_t col)
706{
712
713 // Check for (row,col) boundaries in case of a fixed size calorimeter
714 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
715 {
716 cout << " *NcCalorimeter::SetDead* row,col : " << row << "," << col
717 << " out of range." << endl;
718 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
719 return;
720 }
721
722 // Make Attributes storage 1 row (and also 1 column) larger than needed
723 // because the 'edge value' of the (future) surrounding modules has
724 // to be updated as well.
725 if (!fAttributes)
726 {
727 fAttributes=new TObjArray(row+1);
728 fAttributes->SetOwner();
729 }
730 else
731 {
732 if (row >= fAttributes->GetSize()) fAttributes->Expand(row+1);
733 }
734
735 NcAttribObj* a=(NcAttribObj*)fAttributes->At(row-1);
736 if (a)
737 {
738 a->SetDead(col);
739 }
740 else
741 {
742 a=new NcAttribObj();
743 a->SetDead(col);
744 fAttributes->AddAt(a,row-1);
745 }
746
747 NcCalmodule* m=GetModule(row,col);
748 if (m) m->SetDead();
749
750 // Increase the 'edge value' of surrounding modules
751 Int_t rlow=row-1;
752 Int_t rup=row+1;
753 Int_t clow=col-1;
754 Int_t cup=col+1;
755
756 if (rlow < 1) rlow=row;
757 if (clow < 1) clow=col;
758
759 for (Int_t i=rlow; i<=rup; i++)
760 {
761 for (Int_t j=clow; j<=cup; j++)
762 {
763 if (i!=row || j!=col) // No increase of edge value for the 'dead' module itself
764 {
765 a=(NcAttribObj*)fAttributes->At(i-1);
766 if (a)
767 {
768 a->IncreaseEdgeValue(j);
769 }
770 else
771 {
772 a=new NcAttribObj();
773 a->SetEdgeOn(j);
774 fAttributes->AddAt(a,i-1);
775 }
776
777 m=GetModule(i,j);
778 if (m) m->IncreaseEdgeValue();
779 }
780 }
781 }
782}
783
784void NcCalorimeter::SetAlive(Int_t row,Int_t col)
785{
791
792 // Check for (row,col) boundaries.
793 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
794 {
795 cout << " *NcCalorimeter::SetAlive* row,col : " << row << "," << col
796 << " out of range." << endl;
797 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
798 return;
799 }
800
801 // Only action on fAttributes in case an attribute is present at (row,col),
802 // since by default a module has dead=0 unless explicitly set otherwise.
803 if (fAttributes)
804 {
805 if (row <= fAttributes->GetSize())
806 {
807 NcAttribObj* a=(NcAttribObj*)fAttributes->At(row-1);
808 if (a) a->SetAlive(col);
809 }
810 }
811
812 NcCalmodule* m=GetModule(row,col);
813 if (m) m->SetAlive();
814
815 // Decrease the 'edge value' of surrounding modules
816 Int_t rlow=row-1;
817 Int_t rup=row+1;
818 Int_t clow=col-1;
819 Int_t cup=col+1;
820
821 if (rlow < 1) rlow=row;
822 if (clow < 1) clow=col;
823
824 for (Int_t i=rlow; i<=rup; i++)
825 {
826 for (Int_t j=clow; j<=cup; j++)
827 {
828 if (i!=row || j!=col) // No decrease of edge value for the 'alive' module itself
829 {
830 if (i <= fAttributes->GetSize())
831 {
832 NcAttribObj* a=(NcAttribObj*)fAttributes->At(i-1);
833 if (a) a->DecreaseEdgeValue(j);
834 }
835 m=GetModule(i,j);
836 if (m) m->DecreaseEdgeValue();
837 }
838 }
839 }
840}
841
842void NcCalorimeter::SetGain(Int_t row,Int_t col,Float_t gain)
843{
850
851 // Check for (row,col) boundaries.
852 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
853 {
854 cout << " *NcCalorimeter::SetGain* row,col : " << row << "," << col
855 << " out of range." << endl;
856 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
857 return;
858 }
859
860 if (!fAttributes)
861 {
862 fAttributes=new TObjArray(row);
863 fAttributes->SetOwner();
864 }
865 else
866 {
867 if (row > fAttributes->GetSize()) fAttributes->Expand(row);
868 }
869
870 NcAttribObj* a=(NcAttribObj*)fAttributes->At(row-1);
871 if (a)
872 {
873 a->SetGain(gain,col);
874 }
875 else
876 {
877 a=new NcAttribObj();
878 a->SetGain(gain,col);
879 fAttributes->AddAt(a,row-1);
880 }
881
882 NcCalmodule* m=GetModule(row,col);
883 if (m) m->SetGain(gain);
884}
885
886void NcCalorimeter::SetOffset(Int_t row,Int_t col,Float_t offset)
887{
894
895 // Check for (row,col) boundaries.
896 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
897 {
898 cout << " *NcCalorimeter::SetOffset* row,col : " << row << "," << col
899 << " out of range." << endl;
900 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
901 return;
902 }
903
904 if (!fAttributes)
905 {
906 fAttributes=new TObjArray(row);
907 fAttributes->SetOwner();
908 }
909 else
910 {
911 if (row > fAttributes->GetSize()) fAttributes->Expand(row);
912 }
913
914 NcAttribObj* a=(NcAttribObj*)fAttributes->At(row-1);
915 if (a)
916 {
917 a->SetOffset(offset,col);
918 }
919 else
920 {
921 a=new NcAttribObj();
922 a->SetOffset(offset,col);
923 fAttributes->AddAt(a,row-1);
924 }
925
926 NcCalmodule* m=GetModule(row,col);
927 if (m) m->SetOffset(offset);
928}
929
930void NcCalorimeter::SetPosition(Int_t row,Int_t col,Float_t* vec,TString f)
931{
937
938 Nc3Vector r;
939 r.SetVector(vec,f);
940 SetPosition(row,col,r);
941}
942
943void NcCalorimeter::SetPosition(Int_t row,Int_t col,Nc3Vector& r)
944{
950
951 // Check for (row,col) boundaries.
952 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
953 {
954 cout << " *NcCalorimeter::SetPosition* row,col : " << row << "," << col
955 << " out of range." << endl;
956 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
957 return;
958 }
959
960 if (!fPositions)
961 {
963 fPositions->SetOwner();
964 fPositions->SetSwapMode(fSwap);
965 }
966
967 NcPositionObj* p=(NcPositionObj*)fPositions->GetObject(row,col);
968
969 if (p)
970 {
971 p->Load(r);
972 }
973 else
974 {
975 p=new NcPositionObj();
976 p->Load(r);
977 fPositions->EnterObject(row,col,p);
978 }
979
980 // Update the position of the calorimeter module itself as well if it exists
981 NcCalmodule* m=GetModule(row,col);
982 if (m) m->SetPosition(r);
983}
984
985Int_t NcCalorimeter::GetEdgeValue(Int_t row,Int_t col)
986{
992
993 // Check for (row,col) boundaries.
994 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
995 {
996 cout << " *NcCalorimeter::GetEdgeValue* row,col : " << row << "," << col
997 << " out of range." << endl;
998 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
999 return 0;
1000 }
1001
1002 Int_t edge=0;
1003
1004 if (fAttributes)
1005 {
1006 if (row <= fAttributes->GetSize())
1007 {
1008 NcAttribObj* a=(NcAttribObj*)fAttributes->At(row-1);
1009 if (a)
1010 {
1011 if (col <= a->GetNcalflags())
1012 {
1013 edge=a->GetEdgeValue(col);
1014 return edge;
1015 }
1016 }
1017 }
1018 }
1019
1020 NcCalmodule* m=GetModule(row,col);
1021 if (m) edge=m->GetEdgeValue();
1022 return edge;
1023}
1024
1025Int_t NcCalorimeter::GetDeadValue(Int_t row,Int_t col)
1026{
1032
1033 // Check for (row,col) boundaries.
1034 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1035 {
1036 cout << " *NcCalorimeter::GetDeadValue* row,col : " << row << "," << col
1037 << " out of range." << endl;
1038 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1039 return 0;
1040 }
1041
1042 Int_t dead=0;
1043
1044 if (fAttributes)
1045 {
1046 if (row <= fAttributes->GetSize())
1047 {
1048 NcAttribObj* a=(NcAttribObj*)fAttributes->At(row-1);
1049 if (a)
1050 {
1051 if (col <= a->GetNcalflags())
1052 {
1053 dead=a->GetDeadValue(col);
1054 return dead;
1055 }
1056 }
1057 }
1058 }
1059
1060 NcCalmodule* m=GetModule(row,col);
1061 if (m) dead=m->GetDeadValue();
1062 return dead;
1063}
1064
1065Int_t NcCalorimeter::GetGainFlag(Int_t row,Int_t col)
1066{
1072
1073 // Check for (row,col) boundaries.
1074 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1075 {
1076 cout << " *NcCalorimeter::GetGainFlag* row,col : " << row << "," << col
1077 << " out of range." << endl;
1078 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1079 return 0;
1080 }
1081
1082 Int_t gf=0;
1083
1084 if (fAttributes)
1085 {
1086 if (row <= fAttributes->GetSize())
1087 {
1088 NcAttribObj* a=(NcAttribObj*)fAttributes->At(row-1);
1089 if (a)
1090 {
1091 if (col <= a->GetNcalflags())
1092 {
1093 gf=a->GetGainFlag(col);
1094 return gf;
1095 }
1096 }
1097 }
1098 }
1099
1100 NcCalmodule* m=GetModule(row,col);
1101 if (m) gf=m->GetGainFlag();
1102 return gf;
1103}
1104
1105Int_t NcCalorimeter::GetOffsetFlag(Int_t row,Int_t col)
1106{
1112
1113 // Check for (row,col) boundaries.
1114 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1115 {
1116 cout << " *NcCalorimeter::GetOffsetFlag* row,col : " << row << "," << col
1117 << " out of range." << endl;
1118 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1119 return 0;
1120 }
1121
1122 Int_t of=0;
1123
1124 if (fAttributes)
1125 {
1126 if (row <= fAttributes->GetSize())
1127 {
1128 NcAttribObj* a=(NcAttribObj*)fAttributes->At(row-1);
1129 if (a)
1130 {
1131 if (col <= a->GetNcalflags())
1132 {
1133 of=a->GetOffsetFlag(col);
1134 return of;
1135 }
1136 }
1137 }
1138 }
1139
1140 NcCalmodule* m=GetModule(row,col);
1141 if (m) of=m->GetOffsetFlag();
1142 return of;
1143}
1144
1145Float_t NcCalorimeter::GetGain(Int_t row,Int_t col)
1146{
1155
1156 // Check for (row,col) boundaries.
1157 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1158 {
1159 cout << " *NcCalorimeter::GetGain* row,col : " << row << "," << col
1160 << " out of range." << endl;
1161 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1162 return 0;
1163 }
1164
1165 Float_t gain=0;
1166
1167 if (fAttributes)
1168 {
1169 if (row <= fAttributes->GetSize())
1170 {
1171 NcAttribObj* a=(NcAttribObj*)fAttributes->At(row-1);
1172 if (a)
1173 {
1174 if (col <= a->GetNcalflags())
1175 {
1176 if (a->GetGainFlag(col))
1177 {
1178 gain=a->GetGain(col);
1179 return gain;
1180 }
1181 }
1182 }
1183 }
1184 }
1185
1186 NcCalmodule* m=GetModule(row,col);
1187 if (m)
1188 {
1189 if (m->GetGainFlag())
1190 {
1191 gain=m->GetGain();
1192 }
1193 }
1194 return gain;
1195}
1196
1197Float_t NcCalorimeter::GetOffset(Int_t row,Int_t col)
1198{
1207
1208 // Check for (row,col) boundaries.
1209 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1210 {
1211 cout << " *NcCalorimeter::GetOffset* row,col : " << row << "," << col
1212 << " out of range." << endl;
1213 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1214 return 0;
1215 }
1216
1217 Float_t offset=0;
1218
1219 if (fAttributes)
1220 {
1221 if (row <= fAttributes->GetSize())
1222 {
1223 NcAttribObj* a=(NcAttribObj*)fAttributes->At(row-1);
1224 if (a)
1225 {
1226 if (col <= a->GetNcalflags())
1227 {
1228 if (a->GetOffsetFlag(col))
1229 {
1230 offset=a->GetOffset(col);
1231 return offset;
1232 }
1233 }
1234 }
1235 }
1236 }
1237
1238 NcCalmodule* m=GetModule(row,col);
1239 if (m)
1240 {
1241 if (m->GetOffsetFlag())
1242 {
1243 offset=m->GetOffset();
1244 }
1245 }
1246 return offset;
1247}
1248
1249void NcCalorimeter::GetPosition(Int_t row,Int_t col,Float_t* vec,TString f)
1250{
1256
1257 vec[0]=0;
1258 vec[1]=0;
1259 vec[2]=0;
1260
1261 NcPosition* p=GetPosition(row,col);
1262 if (p) p->GetVector(vec,f);
1263}
1264
1266{
1272
1273 // Check for (row,col) boundaries.
1274 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1275 {
1276 cout << " *NcCalorimeter::GetPosition* row,col : " << row << "," << col
1277 << " out of range." << endl;
1278 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1279 return 0;
1280 }
1281
1282 NcPositionObj* po=0;
1283 if (fPositions) po=(NcPositionObj*)fPositions->GetObject(row,col);
1284 if (po) return po;
1285
1286 NcCalmodule* m=GetModule(row,col);
1287 return m;
1288}
1289
1290Float_t NcCalorimeter::GetClusteredSignal(Int_t row,Int_t col)
1291{
1297
1298 // Check for (row,col) boundaries.
1299 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1300 {
1301 cout << " *NcCalorimeter::GetClusteredSignal* row,col : " << row << "," << col
1302 << " out of range." << endl;
1303 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1304 return 0;
1305 }
1306
1307 Float_t sig=0;
1308
1309 NcCalmodule* m=GetModule(row,col);
1310 if (m) sig=m->GetClusteredSignal();
1311
1312 return sig;
1313}
1314
1316{
1324
1325 return GetNhits();
1326}
1327
1328void NcCalorimeter::Group(Int_t n,Int_t mode)
1329{
1347
1348 if (mode<1 || mode>2)
1349 {
1350 cout << " *NcCalorimeter::Group* Invalid mode : " << mode << endl;
1351 cout << " Default value mode=1 will be used." << endl;
1352 mode=1;
1353 }
1354
1355 if (fClusters)
1356 {
1357 delete fClusters;
1358 fClusters=0;
1359 }
1360
1361 if (!fMatrix) LoadMatrix();
1362
1363 if (!fMatrix) return;
1364
1365 Int_t nsignals=GetNsignals();
1366 if (nsignals > 0) // Only continue if there are fired modules
1367 {
1368 if (GetNclusters() > 0) Ungroup(); // Restore unclustered situation if needed
1369
1370 // Order the modules with decreasing signal
1371 if (mode==1) SortM();
1372 if (mode==2) SortA();
1373
1374 Int_t nord=0;
1375 if (fOrdered) nord=fOrdered->GetEntries();
1376
1377 // Clustering of modules. Start with the highest signal.
1378 fClusters=new TObjArray();
1379 fClusters->SetOwner();
1380 Int_t row=0;
1381 Int_t col=0;
1382 NcCalcluster* c=0;
1383 for (Int_t i=0; i<nord; i++)
1384 {
1385 NcCalmodule* m=(NcCalmodule*)fOrdered->At(i);
1386 if (!m) continue;
1387
1388 row=m->GetRow(); // row number of cluster center
1389 col=m->GetColumn(); // column number of cluster center
1390
1391 // only use modules not yet used in a cluster
1392 if (m->GetClusteredSignal() > 0.)
1393 {
1394 Int_t edge=GetEdgeValue(row,col);
1395 c=new NcCalcluster();
1396 if (!edge) c->Start(*m); // module to start the cluster if not on edge
1397 if (c->GetNmodules() > 0) // cluster started successfully (no edge)
1398 {
1399 fClusters->Add(c);
1400 AddRing(row,col,n); // add signals of n rings around the center
1401 }
1402 else
1403 {
1404 if (c) delete c;
1405 c=0;
1406 }
1407 }
1408 }
1409 }
1410}
1411
1413{
1443
1444 if (fOrdered)
1445 {
1446 delete fOrdered;
1447 fOrdered=0;
1448 }
1449
1450 Int_t nrows=fMatrix->GetMaxRow();
1451 Int_t ncols=fMatrix->GetMaxColumn();
1452
1453 Float_t signal=0.;
1454 Int_t nord=0;
1455 for (Int_t irow=1; irow<=nrows; irow++) // loop over all modules of the matrix
1456 {
1457 for (Int_t icol=1; icol<=ncols; icol++)
1458 {
1459 NcCalmodule* m=(NcCalmodule*)fMatrix->GetObject(irow,icol);
1460 if (!m) continue;
1461
1462 signal=m->GetSignal(1,1); // get the gain etc... corrected signal
1463 if (signal <= 0.) continue; // only take alive modules with a signal
1464
1465 if (nord == 0) // store the first module with a signal at the first ordered position
1466 {
1467 if (!fOrdered)
1468 {
1469 Int_t nhits=GetNhits();
1470 fOrdered=new TObjArray(nhits);
1471 }
1472 nord++;
1473 fOrdered->AddAt(m,nord-1);
1474 continue;
1475 }
1476
1477 for (Int_t j=0; j<=nord; j++) // put module in the right ordered position
1478 {
1479 if (j == nord) // module has smallest signal seen so far
1480 {
1481 nord++;
1482 fOrdered->AddAt(m,j); // add module at the end
1483 break; // go for next matrix module
1484 }
1485
1486 if (signal < ((NcCalmodule*)fOrdered->At(j))->GetSignal(1,1)) continue;
1487
1488 nord++;
1489 for (Int_t k=nord-1; k>j; k--) // create empty position
1490 {
1491 fOrdered->AddAt(fOrdered->At(k-1),k);
1492 }
1493 fOrdered->AddAt(m,j); // put module at empty position
1494 break; // go for next matrix module
1495 }
1496 }
1497 }
1498}
1499
1501{
1531
1532 SortHits();
1533}
1534
1535void NcCalorimeter::AddRing(Int_t row, Int_t col, Int_t n)
1536{
1545
1546 if (!fMatrix) return;
1547
1548 Int_t nrows=fMatrix->GetMaxRow();
1549 Int_t ncols=fMatrix->GetMaxColumn();
1550
1551 if (n >= 1) // Check if any rings left for recursive calls
1552 {
1553 Float_t signal=GetSignal(row,col,1); // Gain etc... corrected signal of (row,col) module
1554
1555 Int_t lrow=row-1; if (lrow < 1) lrow=1; // row lowerbound for ring
1556 Int_t urow=row+1; if (urow > nrows) urow=nrows; // row upperbound for ring
1557 Int_t lcol=col-1; if (lcol < 1) lcol=1; // col lowerbound for ring
1558 Int_t ucol=col+1; if (ucol > ncols) ucol=ncols; // row upperbound for ring
1559
1560 for (Int_t i=lrow; i<=urow; i++)
1561 {
1562 for (Int_t j=lcol; j<=ucol; j++)
1563 {
1564 // add module(i,j) to cluster if the signal <= signal(row,col)
1565 if (GetSignal(i,j,1) <= signal)
1566 {
1567 NcCalmodule* m=(NcCalmodule*)fMatrix->GetObject(i,j);
1568 if (m) ((NcCalcluster*)fClusters->At(GetNclusters()-1))->Add(*m);
1569 }
1570 AddRing(i,j,n-1); // Go for ring of modules around this (i,j) one
1571 }
1572 }
1573 }
1574}
1575
1577{
1583
1584 Int_t nclu=0;
1585 if (fClusters) nclu=fClusters->GetEntries();
1586 return nclu;
1587}
1588
1590{
1597
1598 if (!fClusters) return 0;
1599
1600 if ((j >= 1) && (j <= GetNclusters()))
1601 {
1602 return (NcCalcluster*)fClusters->At(j-1);
1603 }
1604 else
1605 {
1606 cout << " *NcCalorimeter::GetCluster* cluster number : " << j
1607 << " out of range ==> 0 returned." << endl;
1608 return 0;
1609 }
1610}
1611
1613{
1620
1622 return m;
1623}
1624
1626{
1633
1634 NcCalmodule* m=0;
1635 if (!fMatrix) LoadMatrix();
1636 if (fMatrix) m=(NcCalmodule*)fMatrix->GetObject(row,col);
1637 return m;
1638}
1639
1640TH2F* NcCalorimeter::DrawModules(Float_t thresh,Int_t mode)
1641{
1651
1652 Int_t nrows=fNrows;
1653 Int_t ncols=fNcolumns;
1654
1655 if (!fMatrix) LoadMatrix();
1656
1657 if (fMatrix && !nrows && !ncols)
1658 {
1659 nrows=fMatrix->GetMaxRow();
1660 ncols=fMatrix->GetMaxColumn();
1661 }
1662
1663 if (fHmodules)
1664 {
1665 fHmodules->Reset();
1666 }
1667 else
1668 {
1669 fHmodules=new TH2F("fHmodules","Module signals",
1670 ncols,0.5,float(ncols)+0.5,nrows,0.5,float(nrows)+0.5);
1671
1672 fHmodules->SetDirectory(0); // Suppress global character of histo pointer
1673 }
1674
1675 Int_t nmods=GetNsignals();
1676
1677 Int_t row,col;
1678 Float_t signal;
1679 Int_t dead;
1680 for (Int_t i=1; i<=nmods; i++)
1681 {
1682 NcCalmodule* m=(NcCalmodule*)fMatrix->GetObject(i);
1683 if (m)
1684 {
1685 row=m->GetRow();
1686 col=m->GetColumn();
1687 dead=m->GetDeadValue();
1688 signal=0;
1689 if (!dead) signal=GetSignal(row,col,mode);
1690 if (signal>thresh) fHmodules->Fill(float(col),float(row),signal);
1691 }
1692 }
1693
1694 fHmodules->Draw("lego");
1695 return fHmodules;
1696}
1697
1698TH2F* NcCalorimeter::DrawClusters(Float_t thresh)
1699{
1707
1708 Int_t nrows=fNrows;
1709 Int_t ncols=fNcolumns;
1710
1711 if (!fMatrix) LoadMatrix();
1712
1713 if (fMatrix && !nrows && !ncols)
1714 {
1715 nrows=fMatrix->GetMaxRow();
1716 ncols=fMatrix->GetMaxColumn();
1717 }
1718
1719 if (fHclusters)
1720 {
1721 fHclusters->Reset();
1722 }
1723 else
1724 {
1725 fHclusters=new TH2F("fHclusters","Cluster signals",
1726 ncols,0.5,float(ncols)+0.5,nrows,0.5,float(nrows)+0.5);
1727
1728 fHclusters->SetDirectory(0); // Suppress global character of histo pointer
1729 }
1730
1731 NcCalcluster* c;
1732 Int_t row,col;
1733 Float_t signal;
1734 for (Int_t i=0; i<GetNclusters(); i++)
1735 {
1736 c=(NcCalcluster*)fClusters->At(i);
1737 if (c)
1738 {
1739 row=c->GetRow();
1740 col=c->GetColumn();
1741 signal=c->GetSignal();
1742 if (signal>thresh) fHclusters->Fill(float(col),float(row),signal);
1743 }
1744 }
1745
1746 fHclusters->Draw("lego");
1747 return fHclusters;
1748}
1749
1751{
1757
1758 if (!fMatrix) LoadMatrix();
1759
1760 if (!fMatrix) return;
1761
1762 Int_t nsig=GetNsignals();
1763
1764 Float_t signal=0;
1765 for (Int_t j=1; j<=nsig; j++)
1766 {
1767 NcCalmodule* m=(NcCalmodule*)fMatrix->GetObject(j);
1768 if (m)
1769 {
1770 signal=m->GetSignal();
1771 m->SetClusteredSignal(signal);
1772 }
1773 }
1774}
1775
1777{
1783
1784 if (!fVetos)
1785 {
1786 fVetos=new TObjArray();
1787 fVetos->SetOwner();
1788 }
1789
1790 NcSignal* sx=new NcSignal(s);
1791
1792 fVetos->Add(sx);
1793}
1794
1796{
1802
1803 Int_t nvetos=0;
1804 if (fVetos) nvetos=fVetos->GetEntries();
1805 return nvetos;
1806}
1807
1809{
1816
1817 if (i>0 && i<=GetNvetos())
1818 {
1819 return (NcSignal*)fVetos->At(i-1);
1820 }
1821 else
1822 {
1823 cout << " *NcCalorimeter::GetVetoSignal* Signal number " << i
1824 << " out of range ==> 0 returned." << endl;
1825 return 0;
1826 }
1827}
1828
1830{
1838
1839 if (swap==0 || swap==1)
1840 {
1841 fSwap=swap;
1842 }
1843 else
1844 {
1845 cout << " *NcCalorimeter::SetMatrixSwapMode* Invalid argument : swap = " << swap << endl;
1846 }
1847}
1848
1850{
1857
1858 return fSwap;
1859}
1860
1862{
1868
1869 Int_t nhits=GetNhits();
1870
1871 if (!nhits) return;
1872
1873 fMatrix=new NcObjMatrix();
1874 fMatrix->SetSwapMode(fSwap);
1875
1876 Int_t row=0;
1877 Int_t col=0;
1878 for (Int_t i=1; i<=nhits; i++)
1879 {
1881 if (m)
1882 {
1883 row=m->GetRow();
1884 col=m->GetColumn();
1885 fMatrix->EnterObject(row,col,m);
1886 }
1887 }
1888}
1889
1890TObject* NcCalorimeter::Clone(const char* name) const
1891{
1901
1902 NcCalorimeter* cal=new NcCalorimeter(*this);
1903 if (name)
1904 {
1905 if (strlen(name)) cal->SetName(name);
1906 }
1907 return cal;
1908}
1909
ClassImp(NcCalorimeter)
Handling of 3-vectors in various reference frames.
Definition Nc3Vector.h:15
void SetVector(Double_t *v, TString f, TString u="rad")
virtual void Load(Nc3Vector &q)
void GetVector(Double_t *v, TString f, TString u="rad") const
Float_t GetGain(Int_t j=1) const
Definition NcAttrib.cxx:576
Int_t GetNcalflags() const
Definition NcAttrib.cxx:229
void DecreaseEdgeValue(Int_t j=1)
void SetAlive(Int_t j=1)
Definition NcAttrib.cxx:946
void SetEdgeOn(Int_t j=1)
Int_t GetGainFlag(Int_t j=1) const
Definition NcAttrib.cxx:417
Int_t GetDeadValue(Int_t j=1) const
void SetOffset(Double_t off, Int_t j=1)
Definition NcAttrib.cxx:322
Float_t GetOffset(Int_t j=1) const
Definition NcAttrib.cxx:624
void SetEdgeOff(Int_t j=1)
void SetEdgeValue(Int_t val, Int_t j=1)
Int_t GetOffsetFlag(Int_t j=1) const
Definition NcAttrib.cxx:473
void IncreaseEdgeValue(Int_t j=1)
void SetGain(Double_t gain, Int_t j=1)
Definition NcAttrib.cxx:267
void SetDead(Int_t j=1)
Definition NcAttrib.cxx:886
Int_t GetEdgeValue(Int_t j=1) const
Generic handling of detector signal (calibration) attributes.
Definition NcAttribObj.h:13
Description of a cluster of calorimeter modules.
Int_t GetRow() const
Int_t GetNmodules() const
void Add(NcCalmodule &m)
void Start(NcCalmodule &m)
Int_t GetColumn() const
Description of a module in a calorimeter system.
Definition NcCalmodule.h:11
Float_t GetClusteredSignal() const
Int_t GetRow() const
void SetColumn(Int_t i)
Int_t GetColumn() const
virtual void AddSignal(Double_t sig, Int_t j=1)
void SetRow(Int_t i)
virtual void SetSignal(Double_t sig, Int_t j=1)
void SetClusteredSignal(Double_t val)
Description of a modular calorimeter system.
void SetAlive(Int_t row, Int_t col)
TH2F * fHmodules
! The module 2-D histogram for event display
virtual ~NcCalorimeter()
void SetDead(Int_t row, Int_t col)
TH2F * fHclusters
! The cluster 2-D histogram for event display
Int_t GetNvetos() const
Float_t GetGain(Int_t row, Int_t col)
void SetEdgeOn(Int_t row, Int_t col)
void SetSignal(Int_t row, Int_t col, Float_t s)
void SetEdgeOff(Int_t row, Int_t col)
NcCalcluster * GetCluster(Int_t j) const
TH2F * DrawClusters(Float_t thresh=0.)
Int_t GetNclusters() const
Float_t GetClusteredSignal(Int_t row, Int_t col)
void SetMatrixSwapMode(Int_t swap=1)
TObjArray * fVetos
Float_t GetOffset(Int_t row, Int_t col)
void SetOffset(Int_t row, Int_t col, Float_t o)
Int_t GetNsignals() const
TH2F * DrawModules(Float_t thresh=0., Int_t mode=0)
TObjArray * fAttributes
! Matrix dbase with module attributes (e.g. gain, offset etc...)
TObjArray * fClusters
Int_t GetGainFlag(Int_t row, Int_t col)
NcCalmodule * GetModule(Int_t j) const
void SetGain(Int_t row, Int_t col, Float_t g)
void SetPosition(Int_t row, Int_t col, Float_t *r, TString f)
void AddVetoSignal(NcSignal &s)
Int_t GetOffsetFlag(Int_t row, Int_t col)
Int_t GetMatrixSwapMode() const
virtual Float_t GetSignal(Int_t row, Int_t col=0)
Int_t GetEdgeValue(Int_t row, Int_t col)
void AddSignal(Int_t row, Int_t col, Float_t s)
virtual TObject * Clone(const char *name="") const
void Group(Int_t n=1, Int_t mode=1)
NcObjMatrix * fPositions
! Matrix dbase of module position pointers
NcSignal * GetVetoSignal(Int_t j) const
void AddRing(Int_t row, Int_t col, Int_t n)
Int_t GetDeadValue(Int_t row, Int_t col)
NcObjMatrix * fMatrix
! Matrix lookup table of module pointers
void Reset(Int_t row, Int_t col)
void RemoveHit(NcSignal &s)
Definition NcDevice.cxx:388
void AddHit(NcSignal &s)
Definition NcDevice.cxx:336
TObjArray * fHits
Definition NcDevice.h:56
NcDevice(const char *name="", const char *title="")
Definition NcDevice.cxx:109
TObjArray * fOrdered
! Temp. array to hold the ordered hits
Definition NcDevice.h:57
Int_t GetNhits() const
Definition NcDevice.cxx:437
NcSignal * GetHit(Int_t j) const
Definition NcDevice.cxx:489
virtual void Reset(Int_t mode=0)
Definition NcDevice.cxx:222
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
Handling of a matrix structure of objects.
Definition NcObjMatrix.h:13
NcPosition & GetPosition()
void SetPosition(Double_t *r, TString f, TString u="rad")
Handling of positions in various reference frames.
Generic handling of (extrapolated) detector signals.
Definition NcSignal.h:23
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