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 <algorithm>
43#include <array>
44#include <numeric>
45#include <vector>
46
47#include "TCanvas.h"
48#include "TColor.h"
49#include "TH3F.h"
50#include "TPolyLine3D.h"
51#include "TPolyMarker3D.h"
52#include "TRandom.h"
53#include "TRestStringHelper.h"
54#include "TRestTools.h"
55#include "TStyle.h"
56
57using namespace std;
58using namespace TMath;
59
61
75 fHits = new TRestHits();
76
77 fPad = nullptr;
78
79 fXYHitGraph = nullptr;
80 fXZHitGraph = nullptr;
81 fYZHitGraph = nullptr;
82
83 fXYHisto = nullptr;
84 fXZHisto = nullptr;
85 fYZHisto = nullptr;
86
87 fXZHits = nullptr;
88 fYZHits = nullptr;
89 fXYZHits = nullptr;
90
91 fXHisto = nullptr;
92 fYHisto = nullptr;
93 fZHisto = nullptr;
94}
95
100 delete fHits;
101 delete fXZHits;
102 delete fYZHits;
103 delete fXYZHits;
104
105 delete fXYHitGraph;
106 delete fXZHitGraph;
107 delete fYZHitGraph;
108
109 delete fXYHisto;
110 delete fXZHisto;
111 delete fYZHisto;
112
113 delete fXHisto;
114 delete fYHisto;
115 delete fZHisto;
116}
117
124void TRestDetectorHitsEvent::AddHit(Double_t x, Double_t y, Double_t z, Double_t en, Double_t t,
125 REST_HitType type) {
126 fHits->AddHit({x, y, z}, en, t, type);
127}
128
134void TRestDetectorHitsEvent::AddHit(const TVector3& position, Double_t energy, Double_t time,
135 REST_HitType type) {
136 fHits->AddHit(position, energy, time, type);
137}
138
144 fHits->RemoveHits();
145
146 if (fXZHits) {
147 delete fXZHits;
148 fXZHits = nullptr;
149 }
150 if (fYZHits) {
151 delete fYZHits;
152 fYZHits = nullptr;
153 }
154 if (fXYZHits) {
155 delete fXYZHits;
156 fXYZHits = nullptr;
157 }
158
159 fXZHits = new TRestHits();
160 fYZHits = new TRestHits();
161 fXYZHits = new TRestHits();
162}
163
164void TRestDetectorHitsEvent::Sort(bool(compareCondition)(const TRestHits::iterator& hit1,
165 const TRestHits::iterator& hit2)) {
166 // std::sort is not applied directly on TRestHits::iterator since it is a proxy iterator
167 // that does not fulfil all the random-access iterator requirements, and recent libc++
168 // versions (macOS) refuse to compile it. Instead, we sort a list of hit indices using the
169 // same comparison, and then we apply the resulting permutation using TRestHits::SwapHits.
170 // The result is the same on all platforms (hits with equal values keep their order).
171 const int nHits = static_cast<int>(fHits->GetNumberOfHits());
172 if (nHits < 2) return;
173
174 std::vector<int> order(nHits);
175 std::iota(order.begin(), order.end(), 0);
176
177 if (compareCondition == 0) {
178 // default sort logic: z from smaller to greater
179 std::stable_sort(order.begin(), order.end(),
180 [this](int a, int b) { return fHits->GetZ(a) < fHits->GetZ(b); });
181 } else {
182 std::stable_sort(order.begin(), order.end(), [this, compareCondition](int a, int b) {
183 return compareCondition(TRestHits::iterator(fHits, a), TRestHits::iterator(fHits, b));
184 });
185 }
186
187 // Apply the permutation: the hit originally at order[i] must end up at position i
188 std::vector<int> where(nHits); // where[original index] = current position
189 std::vector<int> at(nHits); // at[current position] = original index
190 std::iota(where.begin(), where.end(), 0);
191 std::iota(at.begin(), at.end(), 0);
192 for (int i = 0; i < nHits; i++) {
193 const int orig = order[i];
194 const int p = where[orig];
195 if (p == i) continue;
196 fHits->SwapHits(i, p);
197 const int displaced = at[i];
198 at[i] = orig;
199 at[p] = displaced;
200 where[orig] = i;
201 where[displaced] = p;
202 }
203}
204
205void TRestDetectorHitsEvent::Shuffle(int NLoop) {
206 Int_t nHits = fHits->GetNumberOfHits();
207 if (nHits >= 2) {
208 for (int n = 0; n < NLoop; n++) {
209 Int_t hit1 = (Int_t)(nHits * gRandom->Uniform(0, 1));
210 Int_t hit2 = (Int_t)(nHits * gRandom->Uniform(0, 1));
211
212 fHits->SwapHits(hit1, hit2);
213 }
214 }
215}
216
226
227 for (unsigned int i = 0; i < this->GetNumberOfHits(); i++) {
228 if (GetType(i) == XZ) {
229 fXZHits->AddHit({this->GetX(i), this->GetY(i), this->GetZ(i)}, this->GetEnergy(i),
230 this->GetTime(i), XZ);
231 }
232 }
233
234 return fXZHits;
235}
236
246
247 for (unsigned int i = 0; i < this->GetNumberOfHits(); i++) {
248 if (GetType(i) == YZ) {
249 fYZHits->AddHit({this->GetX(i), this->GetY(i), this->GetZ(i)}, this->GetEnergy(i),
250 this->GetTime(i), YZ);
251 }
252 }
253
254 return fYZHits;
255}
256
266
267 for (unsigned int i = 0; i < this->GetNumberOfHits(); i++) {
268 if (GetType(i) == XYZ) {
269 {
270 fXYZHits->AddHit({this->GetX(i), this->GetY(i), this->GetZ(i)}, this->GetEnergy(i),
271 this->GetTime(i), XYZ);
272 }
273 }
274 }
275
276 return fXYZHits;
277}
278
286Bool_t TRestDetectorHitsEvent::anyHitInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius) {
287 if (fHits->GetNumberOfHitsInsideCylinder(x0, x1, radius) > 0) {
288 return true;
289 }
290
291 return false;
292}
293
301Bool_t TRestDetectorHitsEvent::allHitsInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius) {
302 if ((size_t)fHits->GetNumberOfHitsInsideCylinder(x0, x1, radius) == GetNumberOfHits()) return true;
303
304 return false;
305}
306
315Double_t TRestDetectorHitsEvent::GetEnergyInCylinder(TVector3 x0, TVector3 x1, Double_t radius) {
316 return fHits->GetEnergyInCylinder(x0, x1, radius);
317}
318
327Int_t TRestDetectorHitsEvent::GetNumberOfHitsInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius) {
328 return fHits->GetNumberOfHitsInsideCylinder(x0, x1, radius);
329}
330
339TVector3 TRestDetectorHitsEvent::GetMeanPositionInCylinder(TVector3 x0, TVector3 x1, Double_t radius) {
340 return fHits->GetMeanPositionInCylinder(x0, x1, radius);
341}
342
352Bool_t TRestDetectorHitsEvent::anyHitInsidePrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY,
353 Double_t theta) {
354 if (fHits->GetNumberOfHitsInsidePrism(x0, x1, sizeX, sizeY, theta) > 0) return true;
355
356 return false;
357}
358
368Bool_t TRestDetectorHitsEvent::allHitsInsidePrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY,
369 Double_t theta) {
370 if ((size_t)fHits->GetNumberOfHitsInsidePrism(x0, x1, sizeX, sizeY, theta) == GetNumberOfHits())
371 return true;
372
373 return false;
374}
375
386Double_t TRestDetectorHitsEvent::GetEnergyInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY,
387 Double_t theta) {
388 return fHits->GetEnergyInPrism(x0, x1, sizeX, sizeY, theta);
389}
390
401Int_t TRestDetectorHitsEvent::GetNumberOfHitsInsidePrism(TVector3 x0, TVector3 x1, Double_t sizeX,
402 Double_t sizeY, Double_t theta) {
403 return fHits->GetNumberOfHitsInsidePrism(x0, x1, sizeX, sizeY, theta);
404}
405
416TVector3 TRestDetectorHitsEvent::GetMeanPositionInPrism(TVector3 x0, TVector3 x1, Double_t sizeX,
417 Double_t sizeY, Double_t theta) {
418 return fHits->GetMeanPositionInPrism(x0, x1, sizeX, sizeY, theta);
419}
420
432 Double_t radius) {
433 Double_t rad2 = radius * radius;
434 Double_t hitDistance = rad2;
435
436 Double_t d2, l;
437
438 TVector3 axis = x1 - x0;
439 Double_t cylLength = axis.Mag();
440
441 Int_t nhits = 0;
442 for (unsigned int n = 0; n < GetNumberOfHits(); n++) {
443 if (fHits->isHitNInsideCylinder(n, x0, x1, radius)) {
444 l = axis.Dot(this->GetPosition(n) - x0) / cylLength;
445
446 d2 = rad2 - (this->GetPosition(n) - x0).Mag2() + l * l;
447
448 if (d2 < hitDistance) hitDistance = d2;
449
450 nhits++;
451 }
452 }
453
454 if (nhits == 0) return -1;
455
456 return TMath::Sqrt(hitDistance);
457}
458
470 Double_t radius) {
471 TVector3 axis = x1 - x0;
472 Double_t cylLength = axis.Mag();
473
474 Double_t hitDistance = cylLength;
475 Double_t d = cylLength;
476
477 Int_t nhits = 0;
478 for (unsigned int n = 0; n < GetNumberOfHits(); n++) {
479 if (fHits->isHitNInsideCylinder(n, x0, x1, radius)) {
480 d = cylLength - axis.Dot(this->GetPosition(n) - x0) / cylLength;
481
482 if (d < hitDistance) hitDistance = d;
483
484 nhits++;
485 }
486 }
487
488 if (nhits == 0) return -1;
489
490 return hitDistance;
491}
492
504 Double_t radius) {
505 TVector3 axis = x1 - x0;
506 Double_t cylLength = axis.Mag();
507
508 Double_t hitDistance = cylLength;
509 Double_t d = cylLength;
510
511 Int_t nhits = 0;
512 for (unsigned int n = 0; n < GetNumberOfHits(); n++) {
513 if (fHits->isHitNInsideCylinder(n, x0, x1, radius)) {
514 d = axis.Dot(this->GetPosition(n) - x0) / cylLength;
515
516 if (d < hitDistance) hitDistance = d;
517
518 nhits++;
519 }
520 }
521
522 if (nhits == 0) return -1;
523
524 return hitDistance;
525}
526
540 Double_t sizeX, Double_t sizeY,
541 Double_t theta) {
542 Double_t dX = sizeX / 2;
543 Double_t dY = sizeY / 2;
544
545 Double_t hitDistance = max(dX, dY);
546
547 Double_t d;
548 Int_t nhits = 0;
549 for (unsigned int n = 0; n < GetNumberOfHits(); n++) {
550 if (fHits->isHitNInsidePrism(n, x0, x1, sizeX, sizeY, theta)) {
551 dX = sizeX / 2 - TMath::Abs((this->GetPosition(n) - x0).X());
552 dY = sizeY / 2 - TMath::Abs((this->GetPosition(n) - x0).Y());
553
554 d = min(dX, dY);
555
556 if (d < hitDistance) hitDistance = d;
557
558 nhits++;
559 }
560 }
561
562 if (nhits == 0) return -1;
563
564 return hitDistance;
565}
566
580 Double_t sizeX, Double_t sizeY,
581 Double_t theta) {
582 TVector3 axis = x1 - x0;
583 Double_t prismLength = axis.Mag();
584
585 Double_t hitDistance = prismLength;
586
587 Double_t d;
588 Int_t nhits = 0;
589 for (unsigned int n = 0; n < GetNumberOfHits(); n++) {
590 if (fHits->isHitNInsidePrism(n, x0, x1, sizeX, sizeY, theta)) {
591 d = prismLength - axis.Dot(this->GetPosition(n) - x0) / prismLength;
592
593 if (d < hitDistance) hitDistance = d;
594
595 nhits++;
596 }
597 }
598
599 if (nhits == 0) return -1;
600
601 return hitDistance;
602}
603
617 const TVector3& x1, Double_t sizeX,
618 Double_t sizeY, Double_t theta) {
619 TVector3 axis = x1 - x0;
620 Double_t prismLength = axis.Mag();
621
622 Double_t hitDistance = prismLength;
623
624 Double_t d;
625 Int_t nhits = 0;
626 for (unsigned int n = 0; n < GetNumberOfHits(); n++) {
627 if (fHits->isHitNInsidePrism(n, x0, x1, sizeX, sizeY, theta)) {
628 d = axis.Dot(this->GetPosition(n) - x0) / prismLength;
629
630 if (d < hitDistance) hitDistance = d;
631
632 nhits++;
633 }
634 }
635
636 if (nhits == 0) return -1;
637
638 return hitDistance;
639}
640
665TPad* TRestDetectorHitsEvent::DrawEvent(const TString& option) {
666 vector<TString> optList = Vector_cast<string, TString>(TRestTools::GetOptions((string)option));
667
668 for (unsigned int n = 0; n < optList.size(); n++) {
669 if (optList[n] == "print") this->PrintEvent();
670 }
671
672 optList.erase(std::remove(optList.begin(), optList.end(), "print"), optList.end());
673
675 // which means that it should be extracted from the hit array
676 if (optList.size() == 0) optList.push_back("hist(Cont1,col)");
677
678 if (fPad != nullptr) {
679 delete fPad;
680 fPad = nullptr;
681 }
682
683 fPad = new TPad(this->GetName(), " ", 0, 0, 1, 1);
684 fPad->Divide(3, 2 * optList.size());
685 fPad->Draw();
686
687 // Give each sub-pad enough margin so the axis titles (in particular the bottom-row
688 // x-axis titles and the wider 2-digit y-axis labels) are not clipped at the edges.
689 for (int i = 1; i <= 6 * (int)optList.size(); i++) {
690 fPad->cd(i);
691 gPad->SetBottomMargin(0.13);
692 gPad->SetLeftMargin(0.15);
693 }
694
695 Int_t column = 0;
696 for (unsigned int n = 0; n < optList.size(); n++) {
697 string optionStr = (string)optList[n];
698 TString drawEventOption = optList[n];
699
700 // Generating drawOption argument
701 size_t startPos = optionStr.find("(");
702 if (startPos != string::npos) drawEventOption = optList[n](0, startPos);
703
704 // Generating histogram option argument
705 string histOption = "";
706 size_t endPos = optionStr.find(")");
707 if (endPos != string::npos) {
708 TString histOptionTmp = optList[n](startPos + 1, endPos - startPos - 1);
709
710 histOption = (string)histOptionTmp;
711 size_t pos = 0;
712 while ((pos = histOption.find(",", pos)) != string::npos) {
713 histOption.replace(pos, 1, ":");
714 pos = pos + 1;
715 }
716 }
717
718 // Generating histogram pitch argument
719 string pitchOption = "";
720
721 startPos = optionStr.find("[");
722 endPos = optionStr.find("]");
723 Double_t pitch = 0;
724 if (endPos != string::npos) {
725 TString pitchOption = optList[n](startPos + 1, endPos - startPos - 1);
726 pitch = stod((string)pitchOption);
727 }
728
729 if (drawEventOption == "graph") this->DrawGraphs(column);
730
731 if (drawEventOption == "hist") this->DrawHistograms(column, histOption, pitch);
732 }
733
734 return fPad;
735}
736
745 if (fXYHitGraph != nullptr) {
746 delete fXYHitGraph;
747 fXYHitGraph = nullptr;
748 }
749 if (fXZHitGraph != nullptr) {
750 delete fXZHitGraph;
751 fXZHitGraph = nullptr;
752 }
753 if (fYZHitGraph != nullptr) {
754 delete fYZHitGraph;
755 fYZHitGraph = nullptr;
756 }
757
758 vector<vector<Double_t>> xz(2, vector<Double_t>(this->GetNumberOfHits()));
759 vector<vector<Double_t>> yz(2, vector<Double_t>(this->GetNumberOfHits()));
760 vector<vector<Double_t>> xy(2, vector<Double_t>(this->GetNumberOfHits()));
761
762 /* {{{ Creating xz, yz, and xy arrays and initializing graphs */
763 Int_t nXZ = 0;
764 Int_t nYZ = 0;
765 Int_t nXY = 0;
766
767 for (unsigned int nhit = 0; nhit < this->GetNumberOfHits(); nhit++) {
768 Double_t x = fHits->GetX(nhit);
769 Double_t y = fHits->GetY(nhit);
770 Double_t z = fHits->GetZ(nhit);
771 int type = fHits->GetType(nhit);
772
773 if (type % XZ == 0) {
774 xz[0][nXZ] = x;
775 xz[1][nXZ] = z;
776 nXZ++;
777 }
778
779 if (type % YZ == 0) {
780 yz[0][nYZ] = y;
781 yz[1][nYZ] = z;
782 nYZ++;
783 }
784
785 if (type % XY == 0) {
786 xy[0][nXY] = x;
787 xy[1][nXY] = y;
788 nXY++;
789 }
790 }
791
792 fXZHitGraph = new TGraph(nXZ, &xz[0][0], &xz[1][0]);
793 fXZHitGraph->SetMarkerColor(kBlue);
794 fXZHitGraph->SetMarkerSize(0.3);
795 fXZHitGraph->SetMarkerStyle(20);
796
797 fYZHitGraph = new TGraph(nYZ, &yz[0][0], &yz[1][0]);
798 fYZHitGraph->SetMarkerColor(kRed);
799 fYZHitGraph->SetMarkerSize(0.3);
800 fYZHitGraph->SetMarkerStyle(20);
801
802 fXYHitGraph = new TGraph(nXY, &xy[0][0], &xy[1][0]);
803 fXYHitGraph->SetMarkerColor(kBlack);
804 fXYHitGraph->SetMarkerSize(0.3);
805 fXYHitGraph->SetMarkerStyle(20);
806 /* }}} */
807
808 char title[256];
809 sprintf(title, "Event ID %d", this->GetID());
810
811 if (nXZ > 0) {
812 fPad->cd(1 + 3 * column);
813 fXZHitGraph->SetTitle(title);
814 fXZHitGraph->Draw("AP*");
815
816 fXZHitGraph->GetXaxis()->SetTitle("X-axis (mm)");
817 fXZHitGraph->GetYaxis()->SetTitle("Z-axis (mm)");
818 }
819
820 if (nYZ > 0) {
821 fPad->cd(2 + 3 * column);
822 fYZHitGraph->SetTitle(title);
823 fYZHitGraph->Draw("AP");
824
825 fYZHitGraph->GetXaxis()->SetTitle("Y-axis (mm)");
826 fYZHitGraph->GetYaxis()->SetTitle("Z-axis (mm)");
827 }
828
829 if (nXY > 0) {
830 fPad->cd(3 + 3 * column);
831 fXYHitGraph->SetTitle(title);
832 fXYHitGraph->Draw("AP");
833
834 fXYHitGraph->GetXaxis()->SetTitle("X-axis (mm)");
835 fXYHitGraph->GetYaxis()->SetTitle("Y-axis (mm)");
836 }
837
838 column++;
839}
840
855void TRestDetectorHitsEvent::DrawHistograms(Int_t& column, const TString& histOption, double pitch) {
856 std::vector<double> fX, fY, fZ;
857 for (unsigned int i = 0; i < GetNumberOfHits(); i++) {
858 if (GetType(i) % X == 0) fX.emplace_back(GetX(i));
859 if (GetType(i) % Y == 0) fY.emplace_back(GetY(i));
860 if (GetType(i) % Z == 0) fZ.emplace_back(GetZ(i));
861 }
862
863 double maxX, minX, maxY, minY, maxZ, minZ;
864 int nBinsX, nBinsY, nBinsZ;
865 // GetBoundaries reads dist.front()/back(), which is undefined for an empty projection
866 // (e.g. an event with no hits of a given type). Guard it so DrawEvent never crashes.
867 auto getBoundaries = [](std::vector<double>& v, double& mx, double& mn, int& nb) {
868 if (v.empty()) {
869 mn = -1;
870 mx = 1;
871 nb = 1;
872 return;
873 }
874 TRestHits::GetBoundaries(v, mx, mn, nb);
875 };
876 getBoundaries(fX, maxX, minX, nBinsX);
877 getBoundaries(fY, maxY, minY, nBinsY);
878 getBoundaries(fZ, maxZ, minZ, nBinsZ);
879
880 if (pitch > 0) {
881 nBinsX = std::round((maxX - minX) / pitch);
882 nBinsY = std::round((maxY - minY) / pitch);
883 nBinsZ = std::round((maxZ - minZ) / pitch);
884 }
885
886 // A histogram needs at least one bin; ensure we never request 0 bins for a degenerate
887 // event (all hits sharing a coordinate, or a sub-pitch extent when a pitch is given).
888 nBinsX = std::max(1, nBinsX);
889 nBinsY = std::max(1, nBinsY);
890 nBinsZ = std::max(1, nBinsZ);
891
892 delete fXYHisto;
893 fXYHisto = nullptr;
894 delete fXZHisto;
895 fXZHisto = nullptr;
896 delete fYZHisto;
897 fYZHisto = nullptr;
898
899 delete fXHisto;
900 fXHisto = nullptr;
901 delete fYHisto;
902 fYHisto = nullptr;
903 delete fZHisto;
904 fZHisto = nullptr;
905
906 fXYHisto = new TH2F("XY", "", nBinsX, minX, maxX, nBinsY, minY, maxY);
907 fXYHisto->SetDirectory(nullptr);
908 fXZHisto = new TH2F("XZ", "", nBinsX, minX, maxX, nBinsZ, minZ, maxZ);
909 fXZHisto->SetDirectory(nullptr);
910 fYZHisto = new TH2F("YZ", "", nBinsY, minY, maxY, nBinsZ, minZ, maxZ);
911 fYZHisto->SetDirectory(nullptr);
912
913 fXHisto = new TH1F("X", "", nBinsX, minX, maxX);
914 fXHisto->SetDirectory(nullptr);
915 fYHisto = new TH1F("Y", "", nBinsY, minY, maxY);
916 fYHisto->SetDirectory(nullptr);
917 fZHisto = new TH1F("Z", "", nBinsZ, minZ, maxZ);
918 fZHisto->SetDirectory(nullptr);
919
920 fXYHisto->SetStats(false);
921 fXZHisto->SetStats(false);
922 fYZHisto->SetStats(false);
923
924 fXHisto->SetStats(false);
925 fYHisto->SetStats(false);
926 fZHisto->SetStats(false);
927
928 Int_t nYZ = 0, nXZ = 0, nXY = 0;
929 Int_t nX = 0, nY = 0, nZ = 0;
930
931 for (unsigned int nhit = 0; nhit < this->GetNumberOfHits(); nhit++) {
932 Double_t x = fHits->GetX(nhit);
933 Double_t y = fHits->GetY(nhit);
934 Double_t z = fHits->GetZ(nhit);
935 Double_t en = fHits->GetEnergy(nhit);
936 int type = fHits->GetType(nhit);
937
938 if (type % XZ == 0) {
939 fXZHisto->Fill(x, z, en);
940 nXZ++;
941 }
942
943 if (type % YZ == 0) {
944 fYZHisto->Fill(y, z, en);
945 nYZ++;
946 }
947
948 if (type % XY == 0) {
949 fXYHisto->Fill(x, y, en);
950 nXY++;
951 }
952
953 if (type % X == 0) {
954 fXHisto->Fill(x);
955 nX++;
956 }
957
958 if (type % Y == 0) {
959 fYHisto->Fill(y);
960 nY++;
961 }
962
963 if (type % Z == 0) {
964 fZHisto->Fill(z);
965 nZ++;
966 }
967 }
968
969 TStyle style;
970 style.SetPalette(1);
971
972 if (nXZ > 0) {
973 fPad->cd(1 + 3 * column);
974 fXZHisto->Draw(histOption);
975 fXZHisto->GetXaxis()->SetTitle("X-axis (mm)");
976 fXZHisto->GetYaxis()->SetTitle("Z-axis (mm)");
977 fXZHisto->GetYaxis()->SetTitleSize(1.4 * fXZHisto->GetYaxis()->GetTitleSize());
978 fXZHisto->GetXaxis()->SetTitleSize(1.4 * fXZHisto->GetXaxis()->GetTitleSize());
979 fXZHisto->GetYaxis()->SetLabelSize(1.25 * fXZHisto->GetYaxis()->GetLabelSize());
980 fXZHisto->GetXaxis()->SetLabelSize(1.25 * fXZHisto->GetXaxis()->GetLabelSize());
981 fXZHisto->GetYaxis()->SetTitleOffset(1);
982 }
983
984 if (nYZ > 0) {
985 fPad->cd(2 + 3 * column);
986 fYZHisto->Draw(histOption);
987 fYZHisto->GetXaxis()->SetTitle("Y-axis (mm)");
988 fYZHisto->GetYaxis()->SetTitle("Z-axis (mm)");
989 fYZHisto->GetYaxis()->SetTitleSize(1.4 * fYZHisto->GetYaxis()->GetTitleSize());
990 fYZHisto->GetXaxis()->SetTitleSize(1.4 * fYZHisto->GetXaxis()->GetTitleSize());
991 fYZHisto->GetYaxis()->SetLabelSize(1.25 * fYZHisto->GetYaxis()->GetLabelSize());
992 fYZHisto->GetXaxis()->SetLabelSize(1.25 * fYZHisto->GetXaxis()->GetLabelSize());
993 fYZHisto->GetYaxis()->SetTitleOffset(1);
994 }
995
996 if (nXY > 0) {
997 fPad->cd(3 + 3 * column);
998 fXYHisto->Draw(histOption);
999 fXYHisto->GetXaxis()->SetTitle("X-axis (mm)");
1000 fXYHisto->GetYaxis()->SetTitle("Y-axis (mm)");
1001 fXYHisto->GetYaxis()->SetTitleSize(1.4 * fXYHisto->GetYaxis()->GetTitleSize());
1002 fXYHisto->GetXaxis()->SetTitleSize(1.4 * fXYHisto->GetXaxis()->GetTitleSize());
1003 fXYHisto->GetYaxis()->SetLabelSize(1.25 * fXYHisto->GetYaxis()->GetLabelSize());
1004 fXYHisto->GetXaxis()->SetLabelSize(1.25 * fXYHisto->GetXaxis()->GetLabelSize());
1005 fXYHisto->GetYaxis()->SetTitleOffset(1);
1006 } else {
1007 // When there is no XY projection (a strip readout, where hits are XZ/YZ) the pad is
1008 // otherwise empty, so we use it for a 3D view of the event. A strip hit has one
1009 // undetermined coordinate, so it is drawn as a line spanning that axis (XZ -> line
1010 // along Y, YZ -> along X, XY -> along Z), colored by energy. An XZ and a YZ line
1011 // cross in 3D where they share the same Z; that crossing (x_from_XZ, y_from_YZ, z)
1012 // is the reconstructed hit position, so we highlight it with a marker, which sketches
1013 // the event in 3D. (With several strips at the same Z these crossings also include
1014 // ambiguous "ghost" combinations, inherent to strip readouts.) All objects are owned
1015 // by the pad (kCanDelete) so they are freed when fPad is recreated on next DrawEvent.
1016 fPad->cd(3 + 3 * column);
1017
1018 TH3F* frame = new TH3F("XYZframe", "3D hits;X-axis (mm);Y-axis (mm);Z-axis (mm)", 1, minX, maxX, 1,
1019 minY, maxY, 1, minZ, maxZ);
1020 frame->SetDirectory(nullptr);
1021 frame->SetStats(false);
1022 frame->SetBit(kCanDelete);
1023 frame->Draw();
1024
1025 Double_t eMin = 1e9, eMax = -1e9;
1026 for (unsigned int nhit = 0; nhit < GetNumberOfHits(); nhit++) {
1027 Double_t e = fHits->GetEnergy(nhit);
1028 if (e < eMin) eMin = e;
1029 if (e > eMax) eMax = e;
1030 }
1031 const Int_t nColors = TColor::GetNumberOfColors();
1032 auto energyColor = [&](Double_t e) {
1033 Int_t ci = (eMax > eMin) ? (Int_t)((e - eMin) / (eMax - eMin) * (nColors - 1)) : 0;
1034 return TColor::GetColorPalette(ci);
1035 };
1036
1037 std::vector<std::array<Double_t, 3>> xzHits; // {x, z, energy}
1038 std::vector<std::array<Double_t, 3>> yzHits; // {y, z, energy}
1039 for (unsigned int nhit = 0; nhit < GetNumberOfHits(); nhit++) {
1040 Double_t x = fHits->GetX(nhit);
1041 Double_t y = fHits->GetY(nhit);
1042 Double_t z = fHits->GetZ(nhit);
1043 Double_t en = fHits->GetEnergy(nhit);
1044 int type = fHits->GetType(nhit);
1045 bool hasX = (type % X == 0);
1046 bool hasY = (type % Y == 0);
1047
1048 TPolyLine3D* line = new TPolyLine3D(2);
1049 if (!hasX) { // undetermined X (e.g. YZ hit): line along X
1050 line->SetPoint(0, minX, y, z);
1051 line->SetPoint(1, maxX, y, z);
1052 yzHits.push_back({y, z, en});
1053 } else if (!hasY) { // undetermined Y (e.g. XZ hit): line along Y
1054 line->SetPoint(0, x, minY, z);
1055 line->SetPoint(1, x, maxY, z);
1056 xzHits.push_back({x, z, en});
1057 } else { // undetermined Z (e.g. XY hit): line along Z
1058 line->SetPoint(0, x, y, minZ);
1059 line->SetPoint(1, x, y, maxZ);
1060 }
1061 line->SetLineColor(energyColor(en));
1062 line->SetBit(kCanDelete);
1063 line->Draw();
1064 }
1065
1066 // Highlight the XZ/YZ crossings (same Z) -> reconstructed 3D positions of the event.
1067 const Double_t zTol = 0.05 * (maxZ - minZ);
1068 for (const auto& xz : xzHits) {
1069 for (const auto& yz : yzHits) {
1070 if (std::abs(xz[1] - yz[1]) > zTol) continue;
1071 TPolyMarker3D* marker = new TPolyMarker3D(1);
1072 marker->SetPoint(0, xz[0], yz[0], 0.5 * (xz[1] + yz[1]));
1073 marker->SetMarkerStyle(20);
1074 marker->SetMarkerSize(1.2);
1075 marker->SetMarkerColor(energyColor(0.5 * (xz[2] + yz[2])));
1076 marker->SetBit(kCanDelete);
1077 marker->Draw();
1078 }
1079 }
1080 }
1081
1082 column++;
1083
1084 if (nX > 0) {
1085 fPad->cd(1 + 3 * column);
1086 fXHisto->Draw(histOption);
1087 fXHisto->GetXaxis()->SetTitle("X-axis (mm)");
1088 fXHisto->GetYaxis()->SetTitle("Number of events");
1089 fXHisto->GetYaxis()->SetTitleSize(1.4 * fXHisto->GetYaxis()->GetTitleSize());
1090 fXHisto->GetXaxis()->SetTitleSize(1.4 * fXHisto->GetXaxis()->GetTitleSize());
1091 fXHisto->GetYaxis()->SetLabelSize(1.25 * fXHisto->GetYaxis()->GetLabelSize());
1092 fXHisto->GetXaxis()->SetLabelSize(1.25 * fXHisto->GetXaxis()->GetLabelSize());
1093 fXHisto->GetYaxis()->SetTitleOffset(1);
1094 }
1095
1096 if (nY > 0) {
1097 fPad->cd(2 + 3 * column);
1098 fYHisto->Draw(histOption);
1099 fYHisto->GetXaxis()->SetTitle("Y-axis (mm)");
1100 fYHisto->GetYaxis()->SetTitle("Number of events");
1101 fYHisto->GetYaxis()->SetTitleSize(1.4 * fYHisto->GetYaxis()->GetTitleSize());
1102 fYHisto->GetXaxis()->SetTitleSize(1.4 * fYHisto->GetXaxis()->GetTitleSize());
1103 fYHisto->GetYaxis()->SetLabelSize(1.25 * fYHisto->GetYaxis()->GetLabelSize());
1104 fYHisto->GetXaxis()->SetLabelSize(1.25 * fYHisto->GetXaxis()->GetLabelSize());
1105 fYHisto->GetYaxis()->SetTitleOffset(1);
1106 }
1107
1108 if (nZ > 0) {
1109 fPad->cd(3 + 3 * column);
1110 fZHisto->Draw(histOption);
1111 fZHisto->GetXaxis()->SetTitle("Z-axis (mm)");
1112 fZHisto->GetYaxis()->SetTitle("Number of events");
1113 fZHisto->GetYaxis()->SetTitleSize(1.4 * fYHisto->GetYaxis()->GetTitleSize());
1114 fZHisto->GetXaxis()->SetTitleSize(1.4 * fYHisto->GetXaxis()->GetTitleSize());
1115 fZHisto->GetYaxis()->SetLabelSize(1.25 * fYHisto->GetYaxis()->GetLabelSize());
1116 fZHisto->GetXaxis()->SetLabelSize(1.25 * fYHisto->GetXaxis()->GetLabelSize());
1117 fZHisto->GetYaxis()->SetTitleOffset(1);
1118 }
1119
1120 column++;
1121}
1122
1123void TRestDetectorHitsEvent::PrintEvent(Int_t nHits) const {
1125
1126 cout << "Total energy : " << GetTotalEnergy() << endl;
1127 cout << "Mean position : ( " << GetMeanPositionX() << " , " << GetMeanPositionY() << " , "
1128 << GetMeanPositionZ() << " ) " << endl;
1129 cout << "Number of hits : " << fHits->GetNumberOfHits() << endl;
1130 if (nHits != -1) {
1131 cout << "+++++++++++++++++++++++" << endl;
1132 cout << "Printing only the first " << nHits << " hits" << endl;
1133 }
1134
1135 fHits->PrintHits(nHits);
1136}
1137
1149TH2F* TRestDetectorHitsEvent::GetXYHistogram(std::vector<float> ranges, Double_t pitch, Double_t border) {
1150 double maxX, minX, maxY, minY;
1151 int nBinsX, nBinsY;
1152
1153 if (ranges.size() == 6) {
1154 nBinsX = ranges[0];
1155 minX = ranges[1];
1156 maxX = ranges[2];
1157
1158 nBinsY = ranges[3];
1159 minY = ranges[4];
1160 maxY = ranges[5];
1161 } else {
1162 std::vector<double> x, y, en;
1163
1164 for (unsigned int i = 0; i < GetNumberOfHits(); i++) {
1165 if (GetType(i) % X == 0) x.emplace_back(GetX(i));
1166 if (GetType(i) % Y == 0) y.emplace_back(GetY(i));
1167 }
1168
1169 if (x.empty() && y.empty()) {
1170 std::cout << "TRestDetectorHitsEvent::GetXYHistogram. Empty histogram!" << std::endl;
1171 return nullptr;
1172 }
1173
1174 TRestHits::GetBoundaries(x, maxX, minX, nBinsX);
1175 TRestHits::GetBoundaries(y, maxY, minY, nBinsY);
1176
1177 maxX += border;
1178 minX -= border;
1179
1180 maxY += border;
1181 minY -= border;
1182
1183 if (pitch > 0) {
1184 nBinsX = std::round((maxX - minX) / pitch);
1185 nBinsY = std::round((maxY - minY) / pitch);
1186 }
1187 }
1188
1189 delete fXYHisto;
1190 fXYHisto = nullptr;
1191 fXYHisto = new TH2F("XY", "", nBinsX, minX, maxX, nBinsY, minY, maxY);
1192 fXYHisto->SetDirectory(nullptr);
1193 fXYHisto->SetStats(false);
1194
1195 Int_t nXY = 0;
1196
1197 for (unsigned int nhit = 0; nhit < this->GetNumberOfHits(); nhit++) {
1198 Double_t x = fHits->GetX(nhit);
1199 Double_t y = fHits->GetY(nhit);
1200 Double_t en = fHits->GetEnergy(nhit);
1201 int type = fHits->GetType(nhit);
1202
1203 if (type % XY == 0 || type % XYZ == 0) {
1204 fXYHisto->Fill(x, y, en);
1205 nXY++;
1206 }
1207 }
1208
1209 TStyle style;
1210 style.SetPalette(1);
1211
1212 if (nXY > 0) {
1213 fXYHisto->Draw("col");
1214 fXYHisto->Draw("cont3 same");
1215 fXYHisto->GetXaxis()->SetTitle("X-axis (mm)");
1216 fXYHisto->GetYaxis()->SetTitle("Y-axis (mm)");
1217 fXYHisto->GetYaxis()->SetTitleSize(1.4 * fXYHisto->GetYaxis()->GetTitleSize());
1218 fXYHisto->GetXaxis()->SetTitleSize(1.4 * fXYHisto->GetXaxis()->GetTitleSize());
1219 fXYHisto->GetYaxis()->SetLabelSize(1.25 * fXYHisto->GetYaxis()->GetLabelSize());
1220 fXYHisto->GetXaxis()->SetLabelSize(1.25 * fXYHisto->GetXaxis()->GetLabelSize());
1221 fXYHisto->GetYaxis()->SetTitleOffset(1);
1222 }
1223
1224 return fXYHisto;
1225}
1226
1238TH2F* TRestDetectorHitsEvent::GetXZHistogram(std::vector<float> ranges, Double_t pitch, Double_t border) {
1239 double maxX, minX, maxZ, minZ;
1240 int nBinsX, nBinsZ;
1241
1242 if (ranges.size() == 6) {
1243 nBinsX = ranges[0];
1244 minX = ranges[1];
1245 maxX = ranges[2];
1246
1247 nBinsZ = ranges[3];
1248 minZ = ranges[4];
1249 maxZ = ranges[5];
1250 } else {
1251 std::vector<double> x, z;
1252
1253 for (unsigned int i = 0; i < GetNumberOfHits(); i++) {
1254 if (GetType(i) % X == 0) x.emplace_back(GetX(i));
1255 if (GetType(i) % Z == 0) z.emplace_back(GetZ(i));
1256 }
1257
1258 if (x.empty() || z.empty()) {
1259 std::cout << "TRestDetectorHitsEvent::GetXZHistogram. Empty histogram!" << std::endl;
1260 return nullptr;
1261 }
1262
1263 TRestHits::GetBoundaries(x, maxX, minX, nBinsX);
1264 TRestHits::GetBoundaries(z, maxZ, minZ, nBinsZ);
1265
1266 maxX += border;
1267 minX -= border;
1268
1269 maxZ += border;
1270 minZ -= border;
1271
1272 if (pitch > 0) {
1273 nBinsX = std::round((maxX - minX) / pitch);
1274 nBinsZ = std::round((maxZ - minZ) / pitch);
1275 }
1276 }
1277
1278 delete fXZHisto;
1279 fXZHisto = nullptr;
1280 fXZHisto = new TH2F("XZ", "", nBinsX, minX, maxX, nBinsZ, minZ, maxZ);
1281 fXZHisto->SetDirectory(nullptr);
1282 fXZHisto->SetStats(false);
1283
1284 Int_t nXZ = 0;
1285
1286 for (unsigned int nhit = 0; nhit < this->GetNumberOfHits(); nhit++) {
1287 Double_t x = fHits->GetX(nhit);
1288 Double_t z = fHits->GetZ(nhit);
1289 Double_t en = fHits->GetEnergy(nhit);
1290 int type = fHits->GetType(nhit);
1291
1292 if (type % XZ == 0 || type % XYZ == 0) {
1293 fXZHisto->Fill(x, z, en);
1294 nXZ++;
1295 }
1296 }
1297
1298 TStyle style;
1299 style.SetPalette(1);
1300
1301 if (nXZ > 0) {
1302 fXZHisto->Draw("col");
1303 fXZHisto->Draw("cont3 same");
1304 fXZHisto->GetXaxis()->SetTitle("X-axis (mm)");
1305 fXZHisto->GetYaxis()->SetTitle("Z-axis (mm)");
1306 fXZHisto->GetYaxis()->SetTitleSize(1.4 * fXZHisto->GetYaxis()->GetTitleSize());
1307 fXZHisto->GetXaxis()->SetTitleSize(1.4 * fXYHisto->GetXaxis()->GetTitleSize());
1308 fXZHisto->GetYaxis()->SetLabelSize(1.25 * fXYHisto->GetYaxis()->GetLabelSize());
1309 fXZHisto->GetXaxis()->SetLabelSize(1.25 * fXYHisto->GetXaxis()->GetLabelSize());
1310 fXZHisto->GetYaxis()->SetTitleOffset(1);
1311 }
1312
1313 return fXZHisto;
1314}
1315
1327TH2F* TRestDetectorHitsEvent::GetYZHistogram(std::vector<float> ranges, Double_t pitch, Double_t border) {
1328 double maxY, minY, maxZ, minZ;
1329 int nBinsY, nBinsZ;
1330
1331 if (ranges.size() == 6) {
1332 nBinsY = ranges[0];
1333 minY = ranges[1];
1334 maxY = ranges[2];
1335
1336 nBinsZ = ranges[3];
1337 minZ = ranges[4];
1338 maxZ = ranges[5];
1339 } else {
1340 std::vector<double> y, z, en;
1341
1342 for (unsigned int i = 0; i < GetNumberOfHits(); i++) {
1343 if (GetType(i) % Y == 0) y.emplace_back(GetY(i));
1344 if (GetType(i) % Z == 0) z.emplace_back(GetZ(i));
1345 }
1346
1347 if (y.empty() || z.empty()) {
1348 std::cout << "TRestDetectorHitsEvent::GetYZHistogram. Empty histogram!" << std::endl;
1349 return nullptr;
1350 }
1351
1352 TRestHits::GetBoundaries(y, maxY, minY, nBinsY);
1353 TRestHits::GetBoundaries(z, maxZ, minZ, nBinsZ);
1354
1355 maxY += border;
1356 minY -= border;
1357
1358 maxZ += border;
1359 minZ -= border;
1360
1361 if (pitch > 0) {
1362 nBinsY = std::round((maxY - minZ) / pitch);
1363 nBinsZ = std::round((maxZ - minZ) / pitch);
1364 }
1365 }
1366
1367 delete fYZHisto;
1368 fYZHisto = nullptr;
1369 fYZHisto = new TH2F("YZ", "", nBinsY, minY, maxY, nBinsZ, minZ, maxZ);
1370 fYZHisto->SetDirectory(nullptr);
1371 fYZHisto->SetStats(false);
1372
1373 Int_t nYZ = 0;
1374
1375 for (unsigned int nhit = 0; nhit < this->GetNumberOfHits(); nhit++) {
1376 Double_t y = fHits->GetY(nhit);
1377 Double_t z = fHits->GetZ(nhit);
1378 Double_t en = fHits->GetEnergy(nhit);
1379 int type = fHits->GetType(nhit);
1380
1381 if (type % YZ == 0 || type % XYZ == 0) {
1382 fYZHisto->Fill(y, z, en);
1383 nYZ++;
1384 }
1385 }
1386
1387 TStyle style;
1388 style.SetPalette(1);
1389
1390 if (nYZ > 0) {
1391 fYZHisto->Draw("col");
1392 fYZHisto->Draw("cont3 same");
1393 fYZHisto->GetXaxis()->SetTitle("Y-axis (mm)");
1394 fYZHisto->GetYaxis()->SetTitle("Z-axis (mm)");
1395 fYZHisto->GetYaxis()->SetTitleSize(1.4 * fYZHisto->GetYaxis()->GetTitleSize());
1396 fYZHisto->GetXaxis()->SetTitleSize(1.4 * fYZHisto->GetXaxis()->GetTitleSize());
1397 fYZHisto->GetYaxis()->SetLabelSize(1.25 * fYZHisto->GetYaxis()->GetLabelSize());
1398 fYZHisto->GetXaxis()->SetLabelSize(1.25 * fYZHisto->GetXaxis()->GetLabelSize());
1399 fYZHisto->GetYaxis()->SetTitleOffset(1);
1400 }
1401
1402 return fYZHisto;
1403}
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:720