REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorHitsEvent.cxx
1/*************************************************************************
2 * This file is part of the REST software framework. *
3 * *
4 * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5 * For more information see http://gifna.unizar.es/trex *
6 * *
7 * REST is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * REST is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have a copy of the GNU General Public License along with *
18 * REST in $REST_PATH/LICENSE. *
19 * If not, see http://www.gnu.org/licenses/. *
20 * For the list of contributors see $REST_PATH/CREDITS. *
21 *************************************************************************/
22
40#include "TRestDetectorHitsEvent.h"
41
42#include "TCanvas.h"
43#include "TRandom.h"
44#include "TRestStringHelper.h"
45#include "TRestTools.h"
46#include "TStyle.h"
47
48using namespace std;
49using namespace TMath;
50
52
66 fHits = new TRestHits();
67
68 fPad = nullptr;
69
70 fXYHitGraph = nullptr;
71 fXZHitGraph = nullptr;
72 fYZHitGraph = nullptr;
73
74 fXYHisto = nullptr;
75 fXZHisto = nullptr;
76 fYZHisto = nullptr;
77
78 fXZHits = nullptr;
79 fYZHits = nullptr;
80 fXYZHits = nullptr;
81
82 fXHisto = nullptr;
83 fYHisto = nullptr;
84 fZHisto = nullptr;
85}
86
91
98void TRestDetectorHitsEvent::AddHit(Double_t x, Double_t y, Double_t z, Double_t en, Double_t t,
99 REST_HitType type) {
100 fHits->AddHit({x, y, z}, en, t, type);
101}
102
108void TRestDetectorHitsEvent::AddHit(const TVector3& position, Double_t energy, Double_t time,
109 REST_HitType type) {
110 fHits->AddHit(position, energy, time, type);
111}
112
118 fHits->RemoveHits();
119
120 if (fXZHits) {
121 delete fXZHits;
122 fXZHits = nullptr;
123 }
124 if (fYZHits) {
125 delete fYZHits;
126 fYZHits = nullptr;
127 }
128 if (fXYZHits) {
129 delete fXYZHits;
130 fXYZHits = nullptr;
131 }
132
133 fXZHits = new TRestHits();
134 fYZHits = new TRestHits();
135 fXYZHits = new TRestHits();
136}
137
138void TRestDetectorHitsEvent::Sort(bool(compareCondition)(const TRestHits::iterator& hit1,
139 const TRestHits::iterator& hit2)) {
140#ifndef __APPLE__
141 if (compareCondition == 0) {
142 // default sort logic: z from smaller to greater
143 std::sort(fHits->begin(), fHits->end(),
144 [](const TRestHits::iterator& hit1, const TRestHits::iterator& hit2) -> bool {
145 return hit1.z() < hit2.z();
146 });
147 } else {
148 std::sort(fHits->begin(), fHits->end(), compareCondition);
149 }
150#else
151 std::cout << "TRestDetectorHitsEvent::Sort is not implemented on MacOs!!" << std::endl;
152 std::cout << "This method implementation should be reviewed for proper operation in Mac" << std::endl;
153#endif
154}
155
156void TRestDetectorHitsEvent::Shuffle(int NLoop) {
157 Int_t nHits = fHits->GetNumberOfHits();
158 if (nHits >= 2) {
159 for (int n = 0; n < NLoop; n++) {
160 Int_t hit1 = (Int_t)(nHits * gRandom->Uniform(0, 1));
161 Int_t hit2 = (Int_t)(nHits * gRandom->Uniform(0, 1));
162
163 fHits->SwapHits(hit1, hit2);
164 }
165 }
166}
167
177
178 for (unsigned int i = 0; i < this->GetNumberOfHits(); i++) {
179 if (GetType(i) == XZ) {
180 fXZHits->AddHit({this->GetX(i), this->GetY(i), this->GetZ(i)}, this->GetEnergy(i),
181 this->GetTime(i), XZ);
182 }
183 }
184
185 return fXZHits;
186}
187
197
198 for (unsigned int i = 0; i < this->GetNumberOfHits(); i++) {
199 if (GetType(i) == YZ) {
200 fYZHits->AddHit({this->GetX(i), this->GetY(i), this->GetZ(i)}, this->GetEnergy(i),
201 this->GetTime(i), YZ);
202 }
203 }
204
205 return fYZHits;
206}
207
217
218 for (unsigned int i = 0; i < this->GetNumberOfHits(); i++) {
219 if (GetType(i) == XYZ) {
220 {
221 fXYZHits->AddHit({this->GetX(i), this->GetY(i), this->GetZ(i)}, this->GetEnergy(i),
222 this->GetTime(i), XYZ);
223 }
224 }
225 }
226
227 return fXYZHits;
228}
229
237Bool_t TRestDetectorHitsEvent::anyHitInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius) {
238 if (fHits->GetNumberOfHitsInsideCylinder(x0, x1, radius) > 0) {
239 return true;
240 }
241
242 return false;
243}
244
252Bool_t TRestDetectorHitsEvent::allHitsInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius) {
253 if ((size_t)fHits->GetNumberOfHitsInsideCylinder(x0, x1, radius) == GetNumberOfHits()) return true;
254
255 return false;
256}
257
266Double_t TRestDetectorHitsEvent::GetEnergyInCylinder(TVector3 x0, TVector3 x1, Double_t radius) {
267 return fHits->GetEnergyInCylinder(x0, x1, radius);
268}
269
278Int_t TRestDetectorHitsEvent::GetNumberOfHitsInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius) {
279 return fHits->GetNumberOfHitsInsideCylinder(x0, x1, radius);
280}
281
290TVector3 TRestDetectorHitsEvent::GetMeanPositionInCylinder(TVector3 x0, TVector3 x1, Double_t radius) {
291 return fHits->GetMeanPositionInCylinder(x0, x1, radius);
292}
293
303Bool_t TRestDetectorHitsEvent::anyHitInsidePrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY,
304 Double_t theta) {
305 if (fHits->GetNumberOfHitsInsidePrism(x0, x1, sizeX, sizeY, theta) > 0) return true;
306
307 return false;
308}
309
319Bool_t TRestDetectorHitsEvent::allHitsInsidePrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY,
320 Double_t theta) {
321 if ((size_t)fHits->GetNumberOfHitsInsidePrism(x0, x1, sizeX, sizeY, theta) == GetNumberOfHits())
322 return true;
323
324 return false;
325}
326
337Double_t TRestDetectorHitsEvent::GetEnergyInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY,
338 Double_t theta) {
339 return fHits->GetEnergyInPrism(x0, x1, sizeX, sizeY, theta);
340}
341
352Int_t TRestDetectorHitsEvent::GetNumberOfHitsInsidePrism(TVector3 x0, TVector3 x1, Double_t sizeX,
353 Double_t sizeY, Double_t theta) {
354 return fHits->GetNumberOfHitsInsidePrism(x0, x1, sizeX, sizeY, theta);
355}
356
367TVector3 TRestDetectorHitsEvent::GetMeanPositionInPrism(TVector3 x0, TVector3 x1, Double_t sizeX,
368 Double_t sizeY, Double_t theta) {
369 return fHits->GetMeanPositionInPrism(x0, x1, sizeX, sizeY, theta);
370}
371
383 Double_t radius) {
384 Double_t rad2 = radius * radius;
385 Double_t hitDistance = rad2;
386
387 Double_t d2, l;
388
389 TVector3 axis = x1 - x0;
390 Double_t cylLength = axis.Mag();
391
392 Int_t nhits = 0;
393 for (unsigned int n = 0; n < GetNumberOfHits(); n++) {
394 if (fHits->isHitNInsideCylinder(n, x0, x1, radius)) {
395 l = axis.Dot(this->GetPosition(n) - x0) / cylLength;
396
397 d2 = rad2 - (this->GetPosition(n) - x0).Mag2() + l * l;
398
399 if (d2 < hitDistance) hitDistance = d2;
400
401 nhits++;
402 }
403 }
404
405 if (nhits == 0) return -1;
406
407 return TMath::Sqrt(hitDistance);
408}
409
421 Double_t radius) {
422 TVector3 axis = x1 - x0;
423 Double_t cylLength = axis.Mag();
424
425 Double_t hitDistance = cylLength;
426 Double_t d = cylLength;
427
428 Int_t nhits = 0;
429 for (unsigned int n = 0; n < GetNumberOfHits(); n++) {
430 if (fHits->isHitNInsideCylinder(n, x0, x1, radius)) {
431 d = cylLength - axis.Dot(this->GetPosition(n) - x0) / cylLength;
432
433 if (d < hitDistance) hitDistance = d;
434
435 nhits++;
436 }
437 }
438
439 if (nhits == 0) return -1;
440
441 return hitDistance;
442}
443
455 Double_t radius) {
456 TVector3 axis = x1 - x0;
457 Double_t cylLength = axis.Mag();
458
459 Double_t hitDistance = cylLength;
460 Double_t d = cylLength;
461
462 Int_t nhits = 0;
463 for (unsigned int n = 0; n < GetNumberOfHits(); n++) {
464 if (fHits->isHitNInsideCylinder(n, x0, x1, radius)) {
465 d = axis.Dot(this->GetPosition(n) - x0) / cylLength;
466
467 if (d < hitDistance) hitDistance = d;
468
469 nhits++;
470 }
471 }
472
473 if (nhits == 0) return -1;
474
475 return hitDistance;
476}
477
491 Double_t sizeX, Double_t sizeY,
492 Double_t theta) {
493 Double_t dX = sizeX / 2;
494 Double_t dY = sizeY / 2;
495
496 Double_t hitDistance = max(dX, dY);
497
498 Double_t d;
499 Int_t nhits = 0;
500 for (unsigned int n = 0; n < GetNumberOfHits(); n++) {
501 if (fHits->isHitNInsidePrism(n, x0, x1, sizeX, sizeY, theta)) {
502 dX = sizeX / 2 - TMath::Abs((this->GetPosition(n) - x0).X());
503 dY = sizeY / 2 - TMath::Abs((this->GetPosition(n) - x0).Y());
504
505 d = min(dX, dY);
506
507 if (d < hitDistance) hitDistance = d;
508
509 nhits++;
510 }
511 }
512
513 if (nhits == 0) return -1;
514
515 return hitDistance;
516}
517
531 Double_t sizeX, Double_t sizeY,
532 Double_t theta) {
533 TVector3 axis = x1 - x0;
534 Double_t prismLength = axis.Mag();
535
536 Double_t hitDistance = prismLength;
537
538 Double_t d;
539 Int_t nhits = 0;
540 for (unsigned int n = 0; n < GetNumberOfHits(); n++) {
541 if (fHits->isHitNInsidePrism(n, x0, x1, sizeX, sizeY, theta)) {
542 d = prismLength - axis.Dot(this->GetPosition(n) - x0) / prismLength;
543
544 if (d < hitDistance) hitDistance = d;
545
546 nhits++;
547 }
548 }
549
550 if (nhits == 0) return -1;
551
552 return hitDistance;
553}
554
568 const TVector3& x1, Double_t sizeX,
569 Double_t sizeY, Double_t theta) {
570 TVector3 axis = x1 - x0;
571 Double_t prismLength = axis.Mag();
572
573 Double_t hitDistance = prismLength;
574
575 Double_t d;
576 Int_t nhits = 0;
577 for (unsigned int n = 0; n < GetNumberOfHits(); n++) {
578 if (fHits->isHitNInsidePrism(n, x0, x1, sizeX, sizeY, theta)) {
579 d = axis.Dot(this->GetPosition(n) - x0) / prismLength;
580
581 if (d < hitDistance) hitDistance = d;
582
583 nhits++;
584 }
585 }
586
587 if (nhits == 0) return -1;
588
589 return hitDistance;
590}
591
616TPad* TRestDetectorHitsEvent::DrawEvent(const TString& option) {
617 vector<TString> optList = Vector_cast<string, TString>(TRestTools::GetOptions((string)option));
618
619 for (unsigned int n = 0; n < optList.size(); n++) {
620 if (optList[n] == "print") this->PrintEvent();
621 }
622
623 optList.erase(std::remove(optList.begin(), optList.end(), "print"), optList.end());
624
626 // which means that it should be extracted from the hit array
627 if (optList.size() == 0) optList.push_back("hist(Cont1,col)[3]");
628
629 if (fPad != nullptr) {
630 delete fPad;
631 fPad = nullptr;
632 }
633
634 fPad = new TPad(this->GetName(), " ", 0, 0, 1, 1);
635 fPad->Divide(3, 2 * optList.size());
636 fPad->Draw();
637
638 Int_t column = 0;
639 for (unsigned int n = 0; n < optList.size(); n++) {
640 string optionStr = (string)optList[n];
641 TString drawEventOption = optList[n];
642
643 // Generating drawOption argument
644 size_t startPos = optionStr.find("(");
645 if (startPos != string::npos) drawEventOption = optList[n](0, startPos);
646
647 // Generating histogram option argument
648 string histOption = "";
649 size_t endPos = optionStr.find(")");
650 if (endPos != string::npos) {
651 TString histOptionTmp = optList[n](startPos + 1, endPos - startPos - 1);
652
653 histOption = (string)histOptionTmp;
654 size_t pos = 0;
655 while ((pos = histOption.find(",", pos)) != string::npos) {
656 histOption.replace(pos, 1, ":");
657 pos = pos + 1;
658 }
659 }
660
661 // Generating histogram pitch argument
662 string pitchOption = "";
663
664 startPos = optionStr.find("[");
665 endPos = optionStr.find("]");
666 Double_t pitch = 0;
667 if (endPos != string::npos) {
668 TString pitchOption = optList[n](startPos + 1, endPos - startPos - 1);
669 pitch = stod((string)pitchOption);
670 }
671
672 if (drawEventOption == "graph") this->DrawGraphs(column);
673
674 if (drawEventOption == "hist") this->DrawHistograms(column, histOption, pitch);
675 }
676
677 return fPad;
678}
679
688 if (fXYHitGraph != nullptr) {
689 delete fXYHitGraph;
690 fXYHitGraph = nullptr;
691 }
692 if (fXZHitGraph != nullptr) {
693 delete fXZHitGraph;
694 fXZHitGraph = nullptr;
695 }
696 if (fYZHitGraph != nullptr) {
697 delete fYZHitGraph;
698 fYZHitGraph = nullptr;
699 }
700
701 vector<vector<Double_t>> xz(2, vector<Double_t>(this->GetNumberOfHits()));
702 vector<vector<Double_t>> yz(2, vector<Double_t>(this->GetNumberOfHits()));
703 vector<vector<Double_t>> xy(2, vector<Double_t>(this->GetNumberOfHits()));
704
705 /* {{{ Creating xz, yz, and xy arrays and initializing graphs */
706 Int_t nXZ = 0;
707 Int_t nYZ = 0;
708 Int_t nXY = 0;
709
710 for (unsigned int nhit = 0; nhit < this->GetNumberOfHits(); nhit++) {
711 Double_t x = fHits->GetX(nhit);
712 Double_t y = fHits->GetY(nhit);
713 Double_t z = fHits->GetZ(nhit);
714 int type = fHits->GetType(nhit);
715
716 if (type % XZ == 0) {
717 xz[0][nXZ] = x;
718 xz[1][nXZ] = z;
719 nXZ++;
720 }
721
722 if (type % YZ == 0) {
723 yz[0][nYZ] = y;
724 yz[1][nYZ] = z;
725 nYZ++;
726 }
727
728 if (type % XY == 0) {
729 xy[0][nXY] = x;
730 xy[1][nXY] = y;
731 nXY++;
732 }
733 }
734
735 fXZHitGraph = new TGraph(nXZ, &xz[0][0], &xz[1][0]);
736 fXZHitGraph->SetMarkerColor(kBlue);
737 fXZHitGraph->SetMarkerSize(0.3);
738 fXZHitGraph->SetMarkerStyle(20);
739
740 fYZHitGraph = new TGraph(nYZ, &yz[0][0], &yz[1][0]);
741 fYZHitGraph->SetMarkerColor(kRed);
742 fYZHitGraph->SetMarkerSize(0.3);
743 fYZHitGraph->SetMarkerStyle(20);
744
745 fXYHitGraph = new TGraph(nXY, &xy[0][0], &xy[1][0]);
746 fXYHitGraph->SetMarkerColor(kBlack);
747 fXYHitGraph->SetMarkerSize(0.3);
748 fXYHitGraph->SetMarkerStyle(20);
749 /* }}} */
750
751 char title[256];
752 sprintf(title, "Event ID %d", this->GetID());
753
754 if (nXZ > 0) {
755 fPad->cd(1 + 3 * column);
756 fXZHitGraph->SetTitle(title);
757 fXZHitGraph->Draw("AP*");
758
759 fXZHitGraph->GetXaxis()->SetTitle("X-axis (mm)");
760 fXZHitGraph->GetYaxis()->SetTitle("Z-axis (mm)");
761 }
762
763 if (nYZ > 0) {
764 fPad->cd(2 + 3 * column);
765 fYZHitGraph->SetTitle(title);
766 fYZHitGraph->Draw("AP");
767
768 fYZHitGraph->GetXaxis()->SetTitle("Y-axis (mm)");
769 fYZHitGraph->GetYaxis()->SetTitle("Z-axis (mm)");
770 }
771
772 if (nXY > 0) {
773 fPad->cd(3 + 3 * column);
774 fXYHitGraph->SetTitle(title);
775 fXYHitGraph->Draw("AP");
776
777 fXYHitGraph->GetXaxis()->SetTitle("X-axis (mm)");
778 fXYHitGraph->GetYaxis()->SetTitle("Y-axis (mm)");
779 }
780
781 column++;
782}
783
798void TRestDetectorHitsEvent::DrawHistograms(Int_t& column, const TString& histOption, double pitch) {
799 std::vector<double> fX, fY, fZ;
800 for (unsigned int i = 0; i < GetNumberOfHits(); i++) {
801 if (GetType(i) % X == 0) fX.emplace_back(GetX(i));
802 if (GetType(i) % Y == 0) fY.emplace_back(GetY(i));
803 if (GetType(i) % Z == 0) fZ.emplace_back(GetZ(i));
804 }
805
806 double maxX, minX, maxY, minY, maxZ, minZ;
807 int nBinsX, nBinsY, nBinsZ;
808 TRestHits::GetBoundaries(fX, maxX, minX, nBinsX);
809 TRestHits::GetBoundaries(fY, maxY, minY, nBinsY);
810 TRestHits::GetBoundaries(fZ, maxZ, minZ, nBinsZ);
811
812 if (pitch > 0) {
813 nBinsX = std::round((maxX - minX) / pitch);
814 nBinsY = std::round((maxY - minY) / pitch);
815 nBinsZ = std::round((maxZ - minZ) / pitch);
816 }
817
818 delete fXYHisto;
819 delete fXZHisto;
820 delete fYZHisto;
821
822 delete fXHisto;
823 delete fYHisto;
824 delete fZHisto;
825
826 fXYHisto = new TH2F("XY", "", nBinsX, minX, maxX, nBinsY, minY, maxY);
827 fXZHisto = new TH2F("XZ", "", nBinsX, minX, maxX, nBinsZ, minZ, maxZ);
828 fYZHisto = new TH2F("YZ", "", nBinsY, minY, maxY, nBinsZ, minZ, maxZ);
829
830 fXHisto = new TH1F("X", "", nBinsX, minX, maxX);
831 fYHisto = new TH1F("Y", "", nBinsY, minY, maxY);
832 fZHisto = new TH1F("Z", "", nBinsZ, minZ, maxZ);
833
834 fXYHisto->SetStats(false);
835 fXZHisto->SetStats(false);
836 fYZHisto->SetStats(false);
837
838 fXHisto->SetStats(false);
839 fYHisto->SetStats(false);
840 fZHisto->SetStats(false);
841
842 Int_t nYZ = 0, nXZ = 0, nXY = 0;
843 Int_t nX = 0, nY = 0, nZ = 0;
844
845 for (unsigned int nhit = 0; nhit < this->GetNumberOfHits(); nhit++) {
846 Double_t x = fHits->GetX(nhit);
847 Double_t y = fHits->GetY(nhit);
848 Double_t z = fHits->GetZ(nhit);
849 Double_t en = fHits->GetEnergy(nhit);
850 int type = fHits->GetType(nhit);
851
852 if (type % XZ == 0) {
853 fXZHisto->Fill(x, z, en);
854 nXZ++;
855 }
856
857 if (type % YZ == 0) {
858 fYZHisto->Fill(y, z, en);
859 nYZ++;
860 }
861
862 if (type % XY == 0) {
863 fXYHisto->Fill(x, y, en);
864 nXY++;
865 }
866
867 if (type % X == 0) {
868 fXHisto->Fill(x);
869 nX++;
870 }
871
872 if (type % Y == 0) {
873 fYHisto->Fill(y);
874 nY++;
875 }
876
877 if (type % Z == 0) {
878 fZHisto->Fill(z);
879 nZ++;
880 }
881 }
882
883 TStyle style;
884 style.SetPalette(1);
885
886 if (nXZ > 0) {
887 fPad->cd(1 + 3 * column);
888 fXZHisto->Draw(histOption);
889 fXZHisto->GetXaxis()->SetTitle("X-axis (mm)");
890 fXZHisto->GetYaxis()->SetTitle("Z-axis (mm)");
891 fXZHisto->GetYaxis()->SetTitleSize(1.4 * fXZHisto->GetYaxis()->GetTitleSize());
892 fXZHisto->GetXaxis()->SetTitleSize(1.4 * fXZHisto->GetXaxis()->GetTitleSize());
893 fXZHisto->GetYaxis()->SetLabelSize(1.25 * fXZHisto->GetYaxis()->GetLabelSize());
894 fXZHisto->GetXaxis()->SetLabelSize(1.25 * fXZHisto->GetXaxis()->GetLabelSize());
895 fXZHisto->GetYaxis()->SetTitleOffset(1);
896 }
897
898 if (nYZ > 0) {
899 fPad->cd(2 + 3 * column);
900 fYZHisto->Draw(histOption);
901 fYZHisto->GetXaxis()->SetTitle("Y-axis (mm)");
902 fYZHisto->GetYaxis()->SetTitle("Z-axis (mm)");
903 fYZHisto->GetYaxis()->SetTitleSize(1.4 * fYZHisto->GetYaxis()->GetTitleSize());
904 fYZHisto->GetXaxis()->SetTitleSize(1.4 * fYZHisto->GetXaxis()->GetTitleSize());
905 fYZHisto->GetYaxis()->SetLabelSize(1.25 * fYZHisto->GetYaxis()->GetLabelSize());
906 fYZHisto->GetXaxis()->SetLabelSize(1.25 * fYZHisto->GetXaxis()->GetLabelSize());
907 fYZHisto->GetYaxis()->SetTitleOffset(1);
908 }
909
910 if (nXY > 0) {
911 fPad->cd(3 + 3 * column);
912 fXYHisto->Draw(histOption);
913 fXYHisto->GetXaxis()->SetTitle("X-axis (mm)");
914 fXYHisto->GetYaxis()->SetTitle("Y-axis (mm)");
915 fXYHisto->GetYaxis()->SetTitleSize(1.4 * fXYHisto->GetYaxis()->GetTitleSize());
916 fXYHisto->GetXaxis()->SetTitleSize(1.4 * fXYHisto->GetXaxis()->GetTitleSize());
917 fXYHisto->GetYaxis()->SetLabelSize(1.25 * fXYHisto->GetYaxis()->GetLabelSize());
918 fXYHisto->GetXaxis()->SetLabelSize(1.25 * fXYHisto->GetXaxis()->GetLabelSize());
919 fXYHisto->GetYaxis()->SetTitleOffset(1);
920 }
921
922 column++;
923
924 if (nX > 0) {
925 fPad->cd(1 + 3 * column);
926 fXHisto->Draw(histOption);
927 fXHisto->GetXaxis()->SetTitle("X-axis (mm)");
928 fXHisto->GetYaxis()->SetTitle("Number of events");
929 fXHisto->GetYaxis()->SetTitleSize(1.4 * fXHisto->GetYaxis()->GetTitleSize());
930 fXHisto->GetXaxis()->SetTitleSize(1.4 * fXHisto->GetXaxis()->GetTitleSize());
931 fXHisto->GetYaxis()->SetLabelSize(1.25 * fXHisto->GetYaxis()->GetLabelSize());
932 fXHisto->GetXaxis()->SetLabelSize(1.25 * fXHisto->GetXaxis()->GetLabelSize());
933 fXHisto->GetYaxis()->SetTitleOffset(1);
934 }
935
936 if (nY > 0) {
937 fPad->cd(2 + 3 * column);
938 fYHisto->Draw(histOption);
939 fYHisto->GetXaxis()->SetTitle("Y-axis (mm)");
940 fYHisto->GetYaxis()->SetTitle("Number of events");
941 fYHisto->GetYaxis()->SetTitleSize(1.4 * fYHisto->GetYaxis()->GetTitleSize());
942 fYHisto->GetXaxis()->SetTitleSize(1.4 * fYHisto->GetXaxis()->GetTitleSize());
943 fYHisto->GetYaxis()->SetLabelSize(1.25 * fYHisto->GetYaxis()->GetLabelSize());
944 fYHisto->GetXaxis()->SetLabelSize(1.25 * fYHisto->GetXaxis()->GetLabelSize());
945 fYHisto->GetYaxis()->SetTitleOffset(1);
946 }
947
948 if (nZ > 0) {
949 fPad->cd(3 + 3 * column);
950 fZHisto->Draw(histOption);
951 fZHisto->GetXaxis()->SetTitle("Z-axis (mm)");
952 fZHisto->GetYaxis()->SetTitle("Number of events");
953 fZHisto->GetYaxis()->SetTitleSize(1.4 * fYHisto->GetYaxis()->GetTitleSize());
954 fZHisto->GetXaxis()->SetTitleSize(1.4 * fYHisto->GetXaxis()->GetTitleSize());
955 fZHisto->GetYaxis()->SetLabelSize(1.25 * fYHisto->GetYaxis()->GetLabelSize());
956 fZHisto->GetXaxis()->SetLabelSize(1.25 * fYHisto->GetXaxis()->GetLabelSize());
957 fZHisto->GetYaxis()->SetTitleOffset(1);
958 }
959
960 column++;
961}
962
963void TRestDetectorHitsEvent::PrintEvent(Int_t nHits) const {
965
966 cout << "Total energy : " << GetTotalEnergy() << endl;
967 cout << "Mean position : ( " << GetMeanPositionX() << " , " << GetMeanPositionY() << " , "
968 << GetMeanPositionZ() << " ) " << endl;
969 cout << "Number of hits : " << fHits->GetNumberOfHits() << endl;
970 if (nHits != -1) {
971 cout << "+++++++++++++++++++++++" << endl;
972 cout << "Printing only the first " << nHits << " hits" << endl;
973 }
974
975 fHits->PrintHits(nHits);
976}
977
989TH2F* TRestDetectorHitsEvent::GetXYHistogram(std::vector<float> ranges, Double_t pitch, Double_t border) {
990 double maxX, minX, maxY, minY;
991 int nBinsX, nBinsY;
992
993 if (ranges.size() == 6) {
994 nBinsX = ranges[0];
995 minX = ranges[1];
996 maxX = ranges[2];
997
998 nBinsY = ranges[3];
999 minY = ranges[4];
1000 maxY = ranges[5];
1001 } else {
1002 std::vector<double> x, y, en;
1003
1004 for (unsigned int i = 0; i < GetNumberOfHits(); i++) {
1005 if (GetType(i) % X == 0) x.emplace_back(GetX(i));
1006 if (GetType(i) % Y == 0) y.emplace_back(GetY(i));
1007 }
1008
1009 if (x.empty() && y.empty()) {
1010 std::cout << "TRestDetectorHitsEvent::GetXYHistogram. Empty histogram!" << std::endl;
1011 return nullptr;
1012 }
1013
1014 TRestHits::GetBoundaries(x, maxX, minX, nBinsX);
1015 TRestHits::GetBoundaries(y, maxY, minY, nBinsY);
1016
1017 maxX += border;
1018 minX -= border;
1019
1020 maxY += border;
1021 minY -= border;
1022
1023 if (pitch > 0) {
1024 nBinsX = std::round((maxX - minX) / pitch);
1025 nBinsY = std::round((maxY - minY) / pitch);
1026 }
1027 }
1028
1029 delete fXYHisto;
1030 fXYHisto = new TH2F("XY", "", nBinsX, minX, maxX, nBinsY, minY, maxY);
1031 fXYHisto->SetStats(false);
1032
1033 Int_t nXY = 0;
1034
1035 for (unsigned int nhit = 0; nhit < this->GetNumberOfHits(); nhit++) {
1036 Double_t x = fHits->GetX(nhit);
1037 Double_t y = fHits->GetY(nhit);
1038 Double_t en = fHits->GetEnergy(nhit);
1039 int type = fHits->GetType(nhit);
1040
1041 if (type % XY == 0 || type % XYZ == 0) {
1042 fXYHisto->Fill(x, y, en);
1043 nXY++;
1044 }
1045 }
1046
1047 TStyle style;
1048 style.SetPalette(1);
1049
1050 if (nXY > 0) {
1051 fXYHisto->Draw("col");
1052 fXYHisto->Draw("cont3 same");
1053 fXYHisto->GetXaxis()->SetTitle("X-axis (mm)");
1054 fXYHisto->GetYaxis()->SetTitle("Y-axis (mm)");
1055 fXYHisto->GetYaxis()->SetTitleSize(1.4 * fXYHisto->GetYaxis()->GetTitleSize());
1056 fXYHisto->GetXaxis()->SetTitleSize(1.4 * fXYHisto->GetXaxis()->GetTitleSize());
1057 fXYHisto->GetYaxis()->SetLabelSize(1.25 * fXYHisto->GetYaxis()->GetLabelSize());
1058 fXYHisto->GetXaxis()->SetLabelSize(1.25 * fXYHisto->GetXaxis()->GetLabelSize());
1059 fXYHisto->GetYaxis()->SetTitleOffset(1);
1060 }
1061
1062 return fXYHisto;
1063}
1064
1076TH2F* TRestDetectorHitsEvent::GetXZHistogram(std::vector<float> ranges, Double_t pitch, Double_t border) {
1077 double maxX, minX, maxZ, minZ;
1078 int nBinsX, nBinsZ;
1079
1080 if (ranges.size() == 6) {
1081 nBinsX = ranges[0];
1082 minX = ranges[1];
1083 maxX = ranges[2];
1084
1085 nBinsZ = ranges[3];
1086 minZ = ranges[4];
1087 maxZ = ranges[5];
1088 } else {
1089 std::vector<double> x, z;
1090
1091 for (unsigned int i = 0; i < GetNumberOfHits(); i++) {
1092 if (GetType(i) % X == 0) x.emplace_back(GetX(i));
1093 if (GetType(i) % Z == 0) z.emplace_back(GetZ(i));
1094 }
1095
1096 if (x.empty() || z.empty()) {
1097 std::cout << "TRestDetectorHitsEvent::GetXZHistogram. Empty histogram!" << std::endl;
1098 return nullptr;
1099 }
1100
1101 TRestHits::GetBoundaries(x, maxX, minX, nBinsX);
1102 TRestHits::GetBoundaries(z, maxZ, minZ, nBinsZ);
1103
1104 maxX += border;
1105 minX -= border;
1106
1107 maxZ += border;
1108 minZ -= border;
1109
1110 if (pitch > 0) {
1111 nBinsX = std::round((maxX - minX) / pitch);
1112 nBinsZ = std::round((maxZ - minZ) / pitch);
1113 }
1114 }
1115
1116 delete fXZHisto;
1117 fXZHisto = new TH2F("XZ", "", nBinsX, minX, maxX, nBinsZ, minZ, maxZ);
1118 fXZHisto->SetStats(false);
1119
1120 Int_t nXZ = 0;
1121
1122 for (unsigned int nhit = 0; nhit < this->GetNumberOfHits(); nhit++) {
1123 Double_t x = fHits->GetX(nhit);
1124 Double_t z = fHits->GetZ(nhit);
1125 Double_t en = fHits->GetEnergy(nhit);
1126 int type = fHits->GetType(nhit);
1127
1128 if (type % XZ == 0 || type % XYZ == 0) {
1129 fXZHisto->Fill(x, z, en);
1130 nXZ++;
1131 }
1132 }
1133
1134 TStyle style;
1135 style.SetPalette(1);
1136
1137 if (nXZ > 0) {
1138 fXZHisto->Draw("col");
1139 fXZHisto->Draw("cont3 same");
1140 fXZHisto->GetXaxis()->SetTitle("X-axis (mm)");
1141 fXZHisto->GetYaxis()->SetTitle("Z-axis (mm)");
1142 fXZHisto->GetYaxis()->SetTitleSize(1.4 * fXZHisto->GetYaxis()->GetTitleSize());
1143 fXZHisto->GetXaxis()->SetTitleSize(1.4 * fXYHisto->GetXaxis()->GetTitleSize());
1144 fXZHisto->GetYaxis()->SetLabelSize(1.25 * fXYHisto->GetYaxis()->GetLabelSize());
1145 fXZHisto->GetXaxis()->SetLabelSize(1.25 * fXYHisto->GetXaxis()->GetLabelSize());
1146 fXZHisto->GetYaxis()->SetTitleOffset(1);
1147 }
1148
1149 return fXZHisto;
1150}
1151
1163TH2F* TRestDetectorHitsEvent::GetYZHistogram(std::vector<float> ranges, Double_t pitch, Double_t border) {
1164 double maxY, minY, maxZ, minZ;
1165 int nBinsY, nBinsZ;
1166
1167 if (ranges.size() == 6) {
1168 nBinsY = ranges[0];
1169 minY = ranges[1];
1170 maxY = ranges[2];
1171
1172 nBinsZ = ranges[3];
1173 minZ = ranges[4];
1174 maxZ = ranges[5];
1175 } else {
1176 std::vector<double> y, z, en;
1177
1178 for (unsigned int i = 0; i < GetNumberOfHits(); i++) {
1179 if (GetType(i) % Y == 0) y.emplace_back(GetY(i));
1180 if (GetType(i) % Z == 0) z.emplace_back(GetZ(i));
1181 }
1182
1183 if (y.empty() || z.empty()) {
1184 std::cout << "TRestDetectorHitsEvent::GetYZHistogram. Empty histogram!" << std::endl;
1185 return nullptr;
1186 }
1187
1188 TRestHits::GetBoundaries(y, maxY, minY, nBinsY);
1189 TRestHits::GetBoundaries(z, maxZ, minZ, nBinsZ);
1190
1191 maxY += border;
1192 minY -= border;
1193
1194 maxZ += border;
1195 minZ -= border;
1196
1197 if (pitch > 0) {
1198 nBinsY = std::round((maxY - minZ) / pitch);
1199 nBinsZ = std::round((maxZ - minZ) / pitch);
1200 }
1201 }
1202
1203 delete fYZHisto;
1204 fYZHisto = new TH2F("YZ", "", nBinsY, minY, maxY, nBinsZ, minZ, maxZ);
1205 fYZHisto->SetStats(false);
1206
1207 Int_t nYZ = 0;
1208
1209 for (unsigned int nhit = 0; nhit < this->GetNumberOfHits(); nhit++) {
1210 Double_t y = fHits->GetY(nhit);
1211 Double_t z = fHits->GetZ(nhit);
1212 Double_t en = fHits->GetEnergy(nhit);
1213 int type = fHits->GetType(nhit);
1214
1215 if (type % YZ == 0 || type % XYZ == 0) {
1216 fYZHisto->Fill(y, z, en);
1217 nYZ++;
1218 }
1219 }
1220
1221 TStyle style;
1222 style.SetPalette(1);
1223
1224 if (nYZ > 0) {
1225 fYZHisto->Draw("col");
1226 fYZHisto->Draw("cont3 same");
1227 fYZHisto->GetXaxis()->SetTitle("Y-axis (mm)");
1228 fYZHisto->GetYaxis()->SetTitle("Z-axis (mm)");
1229 fYZHisto->GetYaxis()->SetTitleSize(1.4 * fYZHisto->GetYaxis()->GetTitleSize());
1230 fYZHisto->GetXaxis()->SetTitleSize(1.4 * fYZHisto->GetXaxis()->GetTitleSize());
1231 fYZHisto->GetYaxis()->SetLabelSize(1.25 * fYZHisto->GetYaxis()->GetLabelSize());
1232 fYZHisto->GetXaxis()->SetLabelSize(1.25 * fYZHisto->GetXaxis()->GetLabelSize());
1233 fYZHisto->GetYaxis()->SetTitleOffset(1);
1234 }
1235
1236 return fYZHisto;
1237}
TH2F * GetXZHistogram(std::vector< float > ranges, Double_t pitch=3, Double_t border=5)
This method draws the hits found on XY as a TH2F and it returns the generated histogram.
TRestHits * GetXYZHits()
This method collects all hits which are compatible with a XYZ hit.
virtual void PrintEvent() const
TVector3 GetMeanPositionInCylinder(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the mean position of the hits found inside the cylinder volume given by argument.
TRestHits * GetXZHits()
This method collects all hits which are compatible with a XZ-projected hit.
Double_t GetClosestHitInsideDistanceToCylinderTop(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the distance to the cylinder top face from the closest hit contained inside the c...
void DrawGraphs(Int_t &column)
This method draw the hits events as a graph.
TH1F * fZHisto
An auxiliary TH1F histogram to visualize hits on Z-projection.
TPad * DrawEvent(const TString &option="")
This method draws the hits event structure into a TPad.
Double_t GetX(int n) const
Returns the X-coordinate of hit entry n in mm.
TH2F * fXYHisto
An auxiliary TH2F histogram to visualize hits on XY-projection.
Double_t GetClosestHitInsideDistanceToPrismBottom(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the distance to the prism bottom face from the closest hit contained inside the p...
Int_t GetNumberOfHitsInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the total number hits found inside the cylinder volume given by argument.
TH2F * GetXYHistogram(std::vector< float > ranges, Double_t pitch=3, Double_t border=5)
This method draws the hits found on XY as a TH2F and it returns the generated histogram.
Bool_t anyHitInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius)
This method returns true if at least 1 hit is found inside the cylinder volume given by argument.
TH2F * fYZHisto
An auxiliary TH2F histogram to visualize hits on YZ-projection.
Bool_t allHitsInsidePrism(TVector3 x0, TVector3 x1, Double_t sX, Double_t sY, Double_t theta)
This method returns true if all hits are found inside the prism volume given by argument.
void DrawHistograms(Int_t &column, const TString &histOption="", double pitch=0)
This method draw the hits events as an histogram.
Double_t GetEnergyInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the total integrated energy of all hits found inside the prism volume given by ar...
Double_t GetClosestHitInsideDistanceToCylinderWall(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the distance to the cylinder wall from the closest hit contained inside the cylin...
TGraph * fYZHitGraph
An auxiliary TGraph pointer to visualize hits on YZ-projection.
Double_t GetY(int n) const
Returns the Y-coordinate of hit entry n in mm.
Double_t GetZ(int n) const
Returns the Z-coordinate of hit entry n in mm.
TRestHits * fHits
The hits structure that is is saved to disk.
TRestHits * fXZHits
An auxiliary TRestHits structure to register hits on XZ projection.
TH2F * fXZHisto
An auxiliary TH2F histogram to visualize hits on XZ-projection.
TRestDetectorHitsEvent()
TRestDetectorHitsEvent default constructor.
Int_t GetNumberOfHitsInsidePrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the total number of hits found inside the prism volume given by argument.
Double_t GetClosestHitInsideDistanceToCylinderBottom(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the distance to the cylinder bottom face from the closest hit contained inside th...
TH1F * fYHisto
An auxiliary TH1F histogram to visualize hits on Y-projection.
TRestHits * fXYZHits
An auxiliary TRestHits structure to register hits on XYZ projection.
TVector3 GetMeanPositionInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the mean position of all hits found inside the prism volume given by argument.
Bool_t allHitsInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius)
This method returns true if all hits are contained inside the cylinder volume given by argument.
Double_t GetEnergyInCylinder(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the total integrated energy of all hits found inside the cylinder volume given by...
void AddHit(Double_t x, Double_t y, Double_t z, Double_t en, Double_t t=0, REST_HitType type=XYZ)
Adds a new hit to this event.
TRestHits * GetYZHits()
This method collects all hits which are compatible with a YZ-projected hit.
TGraph * fXZHitGraph
An auxiliary TGraph pointer to visualize hits on XZ-projection.
TH2F * GetYZHistogram(std::vector< float > ranges, Double_t pitch=3, Double_t border=5)
This method draws the hits found on YZ as a TH2F and it returns the generated histogram.
TH1F * fXHisto
An auxiliary TH1F histogram to visualize hits on X-projection.
Double_t GetClosestHitInsideDistanceToPrismTop(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the distance to the prism top face from the closest hit contained inside the pris...
Bool_t anyHitInsidePrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns true if at least 1 hit is found inside the prism volume given by argument.
virtual void Initialize()
Removes all hits from this event, and clears all auxiliar variables.
TGraph * fXYHitGraph
An auxiliary TGraph pointer to visualize hits on XY-projection.
Double_t GetClosestHitInsideDistanceToPrismWall(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the distance to the prism wall from the closest hit contained inside the prism vo...
~TRestDetectorHitsEvent()
TRestDetectorHitsEvent default destructor.
TRestHits * fYZHits
An auxiliary TRestHits structure to register hits on YZ projection.
virtual void PrintEvent() const
Definition: TRestEvent.cxx:187
virtual void Initialize()=0
Definition: TRestEvent.cxx:73
It saves a 3-coordinate position and an energy for each punctual deposition.
Definition: TRestHits.h:39
Int_t GetNumberOfHitsInsidePrism(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines the total number of hits contained inside a prisma delimited between x0 and y0 vertex,...
Definition: TRestHits.cxx:216
virtual void RemoveHits()
It removes all hits inside the class.
Definition: TRestHits.cxx:371
TVector3 GetMeanPositionInCylinder(const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines the mean position using the hits contained inside a cylinder with a given radius and de...
Definition: TRestHits.cxx:1169
static void GetBoundaries(std::vector< double > &val, double &max, double &min, int &nBins, double offset=10)
TODO This method is not using any TRestHits member. This probably means that it should be placed some...
Definition: TRestHits.cxx:738
Double_t GetEnergyInCylinder(const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines the total energy contained inside a cylinder with a given radius and delimited between ...
Definition: TRestHits.cxx:262
Bool_t isHitNInsidePrism(Int_t n, const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines if hit n is contained inside a prisma delimited between x0 and y0 vertex,...
Definition: TRestHits.cxx:176
Double_t GetEnergyInPrism(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines the total hit energy contained inside a prisma delimited between x0 and y0 vertex,...
Definition: TRestHits.cxx:200
void AddHit(const TVector3 &position, Double_t energy, Double_t time=0, REST_HitType type=XYZ)
Adds a new hit to the list of hits using a TVector3.
Definition: TRestHits.cxx:345
Int_t GetNumberOfHitsInsideCylinder(const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines the total number of hits contained inside a cylinder with a given radius and delimited ...
Definition: TRestHits.cxx:283
Bool_t isHitNInsideCylinder(Int_t n, const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines if hit n is contained inside a cylinder with a given radius and delimited between x0 an...
Definition: TRestHits.cxx:230
TVector3 GetMeanPositionInPrism(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines the mean position of hits contained inside a prisma delimited between x0 and x1 vertex,...
Definition: TRestHits.cxx:1095
virtual void SwapHits(Int_t i, Int_t j)
It exchanges hits n and m affecting to the ordering of the hits inside the list of hits.
Definition: TRestHits.cxx:478
virtual void PrintHits(Int_t nHits=-1) const
It prints on screen the first nHits from the list.
Definition: TRestHits.cxx:1380
static std::vector< std::string > GetOptions(std::string optionsStr)
Returns all the options in an option string.
Definition: TRestTools.cxx:86